From eb1b762a76f7c3abf42e6aeef08cdb320939fca5 Mon Sep 17 00:00:00 2001 From: Veeti Paananen Date: Sun, 22 Dec 2013 04:44:31 +0200 Subject: [PATCH] Improve password caching notification UI & UX On Jelly Bean and above: - Use the standard notification style for a better and consistent visual appearance - Use the JB notification actions API for the locking action - Use a lower notification priority to prioritize other notifications over TextSecure On ICS: - Use the existing custom notification layout Everywhere: - Allow opening the app itself from the notification - Simplify strings: don't talk about a "cached passphrase" but about the app being "unlocked"/"locked" --- res/layout/key_caching_notification.xml | 2 +- res/values/strings.xml | 8 +-- .../securesms/service/KeyCachingService.java | 53 ++++++++++++++----- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/res/layout/key_caching_notification.xml b/res/layout/key_caching_notification.xml index 54ad1af22..4f316b24c 100644 --- a/res/layout/key_caching_notification.xml +++ b/res/layout/key_caching_notification.xml @@ -28,7 +28,7 @@ android:singleLine="true" android:fadingEdge="horizontal" android:ellipsize="marquee" - android:text="@string/KeyCachingService_textsecure_passphrase_cached" + android:text="@string/KeyCachingService_textsecure_passphrase_cached_with_lock" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index cf9f18830..23be050ce 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -246,8 +246,10 @@ Importing Text Messages - TextSecure Passphrase Cached - Passphrase Cached + Touch to open. + Touch to open, or touch the lock to close. + TextSecure is unlocked + Lock with passphrase %d new messages @@ -547,7 +549,7 @@ New Message Settings - Clear Passphrase + Lock Mark All Read diff --git a/src/org/thoughtcrime/securesms/service/KeyCachingService.java b/src/org/thoughtcrime/securesms/service/KeyCachingService.java index e24026c9e..c31bdc3ac 100644 --- a/src/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/src/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -190,15 +190,29 @@ public class KeyCachingService extends Service { private void foregroundServiceModern() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); - RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification); - Intent intent = new Intent(this, KeyCachingService.class); - intent.setAction(PASSPHRASE_EXPIRED_EVENT); - PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); - remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, pendingIntent); + builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached)); + builder.setContentText(getString(R.string.KeyCachingService_textsecure_passphrase_cached)); + builder.setSmallIcon(R.drawable.icon_cached); + builder.setWhen(0); + builder.setPriority(Notification.PRIORITY_LOW); + + builder.addAction(R.drawable.ic_menu_lock_holo_dark, getString(R.string.KeyCachingService_lock), buildLockIntent()); + builder.setContentIntent(buildLaunchIntent()); + + stopForeground(true); + startForeground(SERVICE_RUNNING_ID, builder.build()); + } + + private void foregroundServiceICS() { + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification); + + remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, buildLockIntent()); builder.setSmallIcon(R.drawable.icon_cached); builder.setContent(remoteViews); + builder.setContentIntent(buildLaunchIntent()); stopForeground(true); startForeground(SERVICE_RUNNING_ID, builder.build()); @@ -208,14 +222,11 @@ public class KeyCachingService extends Service { Notification notification = new Notification(R.drawable.icon_cached, getString(R.string.KeyCachingService_textsecure_passphrase_cached), System.currentTimeMillis()); - Intent intent = new Intent(this, RoutingActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); notification.setLatestEventInfo(getApplicationContext(), getString(R.string.KeyCachingService_passphrase_cached), getString(R.string.KeyCachingService_textsecure_passphrase_cached), - launchIntent); + buildLaunchIntent()); + notification.tickerText = null; stopForeground(true); startForeground(SERVICE_RUNNING_ID, notification); @@ -227,8 +238,13 @@ public class KeyCachingService extends Service { return; } - if (Build.VERSION.SDK_INT >= 11) foregroundServiceModern(); - else foregroundServiceLegacy(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + foregroundServiceModern(); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + foregroundServiceICS(); + } else { + foregroundServiceLegacy(); + } } private void broadcastNewSecret() { @@ -246,6 +262,19 @@ public class KeyCachingService extends Service { .getBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false); } + private PendingIntent buildLockIntent() { + Intent intent = new Intent(this, KeyCachingService.class); + intent.setAction(PASSPHRASE_EXPIRED_EVENT); + PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); + return pendingIntent; + } + + private PendingIntent buildLaunchIntent() { + Intent intent = new Intent(this, RoutingActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); + return launchIntent; + } @Override public IBinder onBind(Intent arg0) {