diff --git a/app/src/main/java/com/keepassdroid/EntryActivity.java b/app/src/main/java/com/keepassdroid/EntryActivity.java index 64f38a986..71be3a62c 100644 --- a/app/src/main/java/com/keepassdroid/EntryActivity.java +++ b/app/src/main/java/com/keepassdroid/EntryActivity.java @@ -69,6 +69,8 @@ import java.util.Timer; import java.util.TimerTask; import java.util.UUID; +import static com.keepassdroid.settings.PrefsUtil.isClipboardNotificationsEnable; + public class EntryActivity extends LockCloseHideActivity { public static final String KEY_ENTRY = "entry"; public static final String KEY_REFRESH_POS = "refresh_pos"; @@ -153,7 +155,6 @@ public class EntryActivity extends LockCloseHideActivity { Intent i = getIntent(); UUID uuid = Types.bytestoUUID(i.getByteArrayExtra(KEY_ENTRY)); mPos = i.getIntExtra(KEY_REFRESH_POS, -1); - assert(uuid != null); mEntry = db.pm.entries.get(uuid); if (mEntry == null) { @@ -171,37 +172,41 @@ public class EntryActivity extends LockCloseHideActivity { fillData(false); setupEditButtons(); - - // Notification Manager - mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - - if ( mEntry.getPassword().length() > 0 ) { - // only show notification if password is available - Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password); - mNM.notify(NOTIFY_PASSWORD, password); - } - - if ( mEntry.getUsername().length() > 0 ) { - // only show notification if username is available - Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username); - mNM.notify(NOTIFY_USERNAME, username); - } + + // If notifications enabled in settings + if (isClipboardNotificationsEnable(getApplicationContext())) { + // Notification Manager + mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + + if (mEntry.getPassword().length() > 0) { + // only show notification if password is available + Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password); + mNM.notify(NOTIFY_PASSWORD, password); + } + + if (mEntry.getUsername().length() > 0) { + // only show notification if username is available + Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username); + mNM.notify(NOTIFY_USERNAME, username); + } + } mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - - if ( action.equals(Intents.COPY_USERNAME) ) { - String username = mEntry.getUsername(); - if ( username.length() > 0 ) { - timeoutCopyToClipboard(username); - } - } else if ( action.equals(Intents.COPY_PASSWORD) ) { - String password = new String(mEntry.getPassword()); - if ( password.length() > 0 ) { - timeoutCopyToClipboard(new String(mEntry.getPassword())); + if ( action != null) { + if (action.equals(Intents.COPY_USERNAME)) { + String username = mEntry.getUsername(); + if (username.length() > 0) { + timeoutCopyToClipboard(username); + } + } else if (action.equals(Intents.COPY_PASSWORD)) { + String password = mEntry.getPassword(); + if (password.length() > 0) { + timeoutCopyToClipboard(password); + } } } } diff --git a/app/src/main/java/com/keepassdroid/settings/PrefsUtil.java b/app/src/main/java/com/keepassdroid/settings/PrefsUtil.java index 8fd094594..58fa32a0a 100644 --- a/app/src/main/java/com/keepassdroid/settings/PrefsUtil.java +++ b/app/src/main/java/com/keepassdroid/settings/PrefsUtil.java @@ -49,4 +49,10 @@ public class PrefsUtil { ctx.getResources() .getStringArray(R.array.list_password_generator_options_default_values)))); } + + public static boolean isClipboardNotificationsEnable(Context ctx) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); + return prefs.getBoolean(ctx.getString(R.string.clipboard_notifications_key), + ctx.getResources().getBoolean(R.bool.clipboard_notifications_default)); + } } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 6e2b3f88d..9b4da6533 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -206,6 +206,8 @@ Définir la taille par défaut du mot de passe généré Caractères de mot de passe Définir les caractères par défaut du générateur de mot de passe + Notifications du presse-papiers + Activer les notifications du presse-papiers pour copier le nom d\'utilisateur et le mot de passe 30 secondes diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index dfca8a73e..26180f6a0 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -52,6 +52,7 @@ timeout_key storage_access_framework_key setting_style_key + clipboard_notifications_key true true @@ -59,6 +60,7 @@ true true false + true 300000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 80fc69262..f28c8b79b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -206,6 +206,8 @@ Set the default size of the generated password Password characters Set the default password generator characters + Clipboard Notifications + Enable clipboard notifications to copy username and password 30 seconds diff --git a/app/src/main/res/xml/app_preferences.xml b/app/src/main/res/xml/app_preferences.xml index 58b2aa71f..0d3fa6f6c 100644 --- a/app/src/main/res/xml/app_preferences.xml +++ b/app/src/main/res/xml/app_preferences.xml @@ -49,6 +49,11 @@ android:defaultValue="@bool/saf_default" android:title="@string/use_saf_title" android:key="@string/saf_key"/> +