drawables: add disabled notification icon (#384)

Adds a disabled state for the notification icon, and uses it where needed. Also switches to using vector-based icons instead of PNGs.

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
pull/386/head
Andrea Gottardo 7 months ago committed by GitHub
parent b615eb38b4
commit 82c17a4d1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -131,7 +131,7 @@ class App : Application(), libtailscale.AppContext {
fun setWantRunning(wantRunning: Boolean) {
val callback: (Result<Ipn.Prefs>) -> Unit = { result ->
result.fold(
onSuccess = { },
onSuccess = {},
onFailure = { error ->
Log.d("TAG", "Set want running: failed to update preferences: ${error.message}")
})
@ -181,7 +181,6 @@ class App : Application(), libtailscale.AppContext {
startService(intent)
}
// encryptToPref a byte array of data using the Jetpack Security
// library and writes it to a global encrypted preference store.
@Throws(IOException::class, GeneralSecurityException::class)
@ -215,26 +214,17 @@ class App : Application(), libtailscale.AppContext {
QuickToggleService.setReady(this, ready)
Log.d("App", "Set Tile Ready: $ready")
val action = if (ready) IPNReceiver.INTENT_DISCONNECT_VPN else IPNReceiver.INTENT_CONNECT_VPN
val intent = Intent(this, IPNReceiver::class.java).apply {
this.action = action
}
val pendingIntent : PendingIntent = PendingIntent.getBroadcast(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
if (ready){
val intent = Intent(this, IPNReceiver::class.java).apply { this.action = action }
val pendingIntent: PendingIntent =
PendingIntent.getBroadcast(
this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
if (ready) {
startVPN()
}
val notificationMessage = if (ready) getString(R.string.connected) else getString(R.string.not_connected)
val notificationMessage =
if (ready) getString(R.string.connected) else getString(R.string.not_connected)
notify(
"Tailscale",
notificationMessage,
STATUS_CHANNEL_ID,
pendingIntent,
STATUS_NOTIFICATION_ID
)
"Tailscale", notificationMessage, ready, STATUS_CHANNEL_ID, pendingIntent, STATUS_NOTIFICATION_ID)
}
fun getHostname(): String {
@ -337,7 +327,8 @@ class App : Application(), libtailscale.AppContext {
}
val pending: PendingIntent =
PendingIntent.getActivity(this, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT)
notify(getString(R.string.file_notification), msg, FILE_CHANNEL_ID, pending, FILE_NOTIFICATION_ID)
notify(
getString(R.string.file_notification), msg, true, FILE_CHANNEL_ID, pending, FILE_NOTIFICATION_ID)
}
fun createNotificationChannel(id: String?, name: String?, importance: Int) {
@ -346,10 +337,18 @@ class App : Application(), libtailscale.AppContext {
nm.createNotificationChannel(channel)
}
fun notify(title: String?, message: String?, channel: String, intent: PendingIntent?, notificationID: Int) {
fun notify(
title: String?,
message: String?,
usesEnabledIcon: Boolean,
channel: String,
intent: PendingIntent?,
notificationID: Int
) {
val icon = if (usesEnabledIcon) R.drawable.ic_notification else R.drawable.ic_notification_disabled
val builder: NotificationCompat.Builder =
NotificationCompat.Builder(this, channel)
.setSmallIcon(R.drawable.ic_notification)
.setSmallIcon(icon)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 641 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

@ -0,0 +1,38 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M0,12.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M37.5,12.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M75,12.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M-0,50a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"/>
<path
android:pathData="M37.5,50a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"/>
<path
android:pathData="M75,50a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"/>
<path
android:pathData="M-0,87.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M37.5,87.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"/>
<path
android:pathData="M75,87.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
</vector>

@ -0,0 +1,46 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M0,12.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M37.5,12.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M75,12.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M-0,50a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:strokeAlpha="0.4"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M37.5,50a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:strokeAlpha="0.4"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M75,50a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:strokeAlpha="0.4"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M-0,87.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M37.5,87.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:strokeAlpha="0.4"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
<path
android:pathData="M75,87.5a12.5,12.5 0,1 0,25 0a12.5,12.5 0,1 0,-25 0z"
android:fillColor="#000000"
android:fillAlpha="0.4"/>
</vector>
Loading…
Cancel
Save