aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-12-22 01:46:11 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2015-12-22 01:46:11 +0100
commit35e16b75b243fd301642bbf1572f85ebbef1c161 (patch)
tree48b57091a666775e3f37f4ec9dca65013260866d
parent6c25cb19270b70eb8dd20f9731b3b65cbc198f11 (diff)
downloadopen-keychain-35e16b75b243fd301642bbf1572f85ebbef1c161.tar.gz
open-keychain-35e16b75b243fd301642bbf1572f85ebbef1c161.tar.bz2
open-keychain-35e16b75b243fd301642bbf1572f85ebbef1c161.zip
Follow notification style guidelines, dismiss permission notification on click
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java14
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java9
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/NotificationUtils.java50
3 files changed, 9 insertions, 64 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
index 387347986..2985c2030 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
@@ -19,8 +19,6 @@ package org.sufficientlysecure.keychain.service;
import android.accounts.Account;
import android.accounts.AccountManager;
-import android.app.Activity;
-import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
@@ -29,18 +27,16 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
-import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceActivity;
import android.provider.ContactsContract;
import android.support.v4.app.NotificationCompat;
-import android.widget.Toast;
+import android.support.v4.app.NotificationManagerCompat;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.SettingsActivity;
-import org.sufficientlysecure.keychain.ui.util.NotificationUtils;
import org.sufficientlysecure.keychain.util.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
@@ -86,14 +82,14 @@ public class ContactSyncAdapterService extends Service {
);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ContactSyncAdapterService.this)
+ .setAutoCancel(true)
.setSmallIcon(R.drawable.ic_stat_notify_24dp)
- .setLargeIcon(NotificationUtils.getBitmap(R.mipmap.ic_launcher, getBaseContext()))
+ .setColor(getResources().getColor(R.color.primary))
.setContentTitle(getString(R.string.sync_notification_permission_required_title))
.setContentText(getString(R.string.sync_notification_permission_required_text))
.setContentIntent(resultPendingIntent);
- NotificationManager mNotifyMgr =
- (NotificationManager) ContactSyncAdapterService.this.getSystemService(Activity.NOTIFICATION_SERVICE);
- mNotifyMgr.notify(NOTIFICATION_ID_SYNC_SETTINGS, mBuilder.build());
+ NotificationManagerCompat.from(ContactSyncAdapterService.this)
+ .notify(NOTIFICATION_ID_SYNC_SETTINGS, mBuilder.build());
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
index 67c295b6d..73da3aff9 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
@@ -18,8 +18,6 @@
package org.sufficientlysecure.keychain.service;
-import java.util.Date;
-
import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
@@ -44,11 +42,12 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
-import org.sufficientlysecure.keychain.ui.util.NotificationUtils;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.Preferences;
+import java.util.Date;
+
/**
* This service runs in its own process, but is available to all other processes as the main
* passphrase cache. Use the static methods addCachedPassphrase and getCachedPassphrase for
@@ -473,7 +472,7 @@ public class PassphraseCacheService extends Service {
private Notification getNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_stat_notify_24dp)
- .setLargeIcon(NotificationUtils.getBitmap(R.mipmap.ic_launcher, getBaseContext()))
+ .setColor(getResources().getColor(R.color.primary))
.setContentTitle(getResources().getQuantityString(R.plurals.passp_cache_notif_n_keys,
mPassphraseCache.size(), mPassphraseCache.size()))
.setContentText(getString(R.string.passp_cache_notif_touch_to_clear));
@@ -504,7 +503,7 @@ public class PassphraseCacheService extends Service {
// Add clear PI action below text
builder.addAction(
- R.drawable.abc_ic_clear_mtrl_alpha,
+ R.drawable.ic_close_white_24dp,
getString(R.string.passp_cache_notif_clear),
clearCachePi
);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/NotificationUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/NotificationUtils.java
deleted file mode 100644
index 40ff92a1c..000000000
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/NotificationUtils.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.sufficientlysecure.keychain.ui.util;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-
-public class NotificationUtils {
-
- // from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android
- public static Bitmap getBitmap(int resId, Context context) {
- int mLargeIconWidth = (int) context.getResources().getDimension(
- android.R.dimen.notification_large_icon_width);
- int mLargeIconHeight = (int) context.getResources().getDimension(
- android.R.dimen.notification_large_icon_height);
- Drawable d;
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
- // noinspection deprecation (can't help it at this api level)
- d = context.getResources().getDrawable(resId);
- } else {
- d = context.getDrawable(resId);
- }
- if (d == null) {
- return null;
- }
- Bitmap b = Bitmap.createBitmap(mLargeIconWidth, mLargeIconHeight, Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(b);
- d.setBounds(0, 0, mLargeIconWidth, mLargeIconHeight);
- d.draw(c);
- return b;
- }
-}