Notification: follow design guidelines, fix #1313

This commit is contained in:
Dominik Schürmann
2015-06-24 13:08:37 +02:00
parent 8cd7e29540
commit 74cef32d25
2 changed files with 38 additions and 52 deletions

View File

@@ -493,13 +493,11 @@ public class PassphraseCacheService extends Service {
private Notification getNotification() { private Notification getNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) builder.setSmallIcon(R.drawable.ic_stat_notify_24dp)
.setLargeIcon(getBitmap(R.drawable.ic_launcher, getBaseContext())) .setLargeIcon(getBitmap(R.drawable.ic_launcher, getBaseContext()))
.setContentTitle(getString(R.string.app_name)) .setContentTitle(getResources().getQuantityString(R.plurals.passp_cache_notif_n_keys,
.setContentText(String.format(getString(R.string.passp_cache_notif_n_keys), mPassphraseCache.size(), mPassphraseCache.size()))
mPassphraseCache.size())); .setContentText(getString(R.string.passp_cache_notif_click_to_clear));
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
@@ -513,39 +511,24 @@ public class PassphraseCacheService extends Service {
// Moves the big view style object into the notification object. // Moves the big view style object into the notification object.
builder.setStyle(inboxStyle); builder.setStyle(inboxStyle);
// Add purging action
Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class);
intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR); intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR);
PendingIntent clearCachePi = PendingIntent.getService(
getApplicationContext(),
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
// Add cache clear PI to normal touch
builder.setContentIntent(clearCachePi);
// Add clear PI action below text
builder.addAction( builder.addAction(
R.drawable.abc_ic_clear_mtrl_alpha, R.drawable.abc_ic_clear_mtrl_alpha,
getString(R.string.passp_cache_notif_clear), getString(R.string.passp_cache_notif_clear),
PendingIntent.getService( clearCachePi
getApplicationContext(),
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
)
); );
} else {
// Fallback, since expandable notifications weren't available back then
builder.setSmallIcon(R.drawable.ic_stat_notify)
.setLargeIcon(getBitmap(R.drawable.ic_launcher, getBaseContext()))
.setContentTitle(String.format(getString(R.string.passp_cache_notif_n_keys),
mPassphraseCache.size()))
.setContentText(getString(R.string.passp_cache_notif_click_to_clear));
Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class);
intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR);
builder.setContentIntent(
PendingIntent.getService(
getApplicationContext(),
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
)
);
}
return builder.build(); return builder.build();
} }

View File

@@ -1221,9 +1221,12 @@
<string name="msg_export_log_success">"Log exported successfully!"</string> <string name="msg_export_log_success">"Log exported successfully!"</string>
<!-- PassphraseCache --> <!-- PassphraseCache -->
<string name="passp_cache_notif_click_to_clear">"Click to clear cached passwords"</string> <string name="passp_cache_notif_click_to_clear">"Touch to clear password cache."</string>
<string name="passp_cache_notif_n_keys">"OpenKeychain has cached %d passwords"</string> <plurals name="passp_cache_notif_n_keys">
<string name="passp_cache_notif_keys">"Cached Passwords:"</string> <item quantity="one">"%d password cached"</item>
<item quantity="other">"%d passwords cached"</item>
</plurals>
<string name="passp_cache_notif_keys">"Cached passwords"</string>
<string name="passp_cache_notif_clear">"Clear Cache"</string> <string name="passp_cache_notif_clear">"Clear Cache"</string>
<string name="passp_cache_notif_pwd">"Password"</string> <string name="passp_cache_notif_pwd">"Password"</string>