diff --git a/res/values/strings.xml b/res/values/strings.xml
index 951ccf550..1e86bc76b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -31,7 +31,8 @@
KeePassDroid
Cancel
Clipboard cleared.
- Current Group:
+ Copy username to clipboard
+ Copy password to clipboard
Current Group: Root
KeePassDroid Copyright 2009 Brian Pellin comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under the conditions of the GPL version 2 or later.
diff --git a/src/com/keepassdroid/EntryActivity.java b/src/com/keepassdroid/EntryActivity.java
index b295b8bbb..39f16fc76 100644
--- a/src/com/keepassdroid/EntryActivity.java
+++ b/src/com/keepassdroid/EntryActivity.java
@@ -29,9 +29,14 @@ import org.phoneid.keepassj2me.PwEntry;
import org.phoneid.keepassj2me.Types;
import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.text.method.PasswordTransformationMethod;
@@ -45,6 +50,7 @@ import android.widget.Toast;
import com.android.keepass.KeePass;
import com.android.keepass.R;
import com.keepassdroid.app.App;
+import com.keepassdroid.intents.Intents;
public class EntryActivity extends LockCloseActivity {
public static final String KEY_ENTRY = "entry";
@@ -59,6 +65,9 @@ public class EntryActivity extends LockCloseActivity {
private static final long CLIP_CLEAR_TIME = 5 * 60 * 1000;
+ public static final int NOTIFY_USERNAME = 1;
+ public static final int NOTIFY_PASSWORD = 2;
+
public static void Launch(Activity act, PwEntry pw, int pos) {
Intent i = new Intent(act, EntryActivity.class);
@@ -72,6 +81,8 @@ public class EntryActivity extends LockCloseActivity {
private Timer mTimer = new Timer();
private boolean mShowPassword = false;
private int mPos;
+ private NotificationManager mNM;
+ private BroadcastReceiver mIntentReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -110,6 +121,61 @@ public class EntryActivity extends LockCloseActivity {
}
});
+
+ // Notification Manager
+ mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+
+ Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
+ mNM.notify(NOTIFY_PASSWORD, password);
+
+ 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.username;
+ if ( username.length() > 0 ) {
+ timeoutCopyToClipboard(mEntry.username);
+ }
+ } else if ( action.equals(Intents.COPY_PASSWORD) ) {
+ String password = new String(mEntry.getPassword());
+ if ( password.length() > 0 ) {
+ timeoutCopyToClipboard(new String(mEntry.getPassword()));
+ }
+ }
+ }
+ };
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intents.COPY_USERNAME);
+ filter.addAction(Intents.COPY_PASSWORD);
+ registerReceiver(mIntentReceiver, filter);
+ }
+
+ @Override
+ protected void onDestroy() {
+ unregisterReceiver(mIntentReceiver);
+
+ mNM.cancelAll();
+
+ super.onDestroy();
+ }
+
+ private Notification getNotification(String intentText, int descResId) {
+ String desc = getString(descResId);
+ Notification notify = new Notification(R.drawable.keepassdroid_launcher, desc, System.currentTimeMillis());
+
+ Intent intent = new Intent(intentText);
+ PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
+
+ notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending);
+
+ return notify;
}
private void fillData() {
diff --git a/src/com/keepassdroid/LockCloseActivity.java b/src/com/keepassdroid/LockCloseActivity.java
index 85baca165..16da99b54 100644
--- a/src/com/keepassdroid/LockCloseActivity.java
+++ b/src/com/keepassdroid/LockCloseActivity.java
@@ -19,8 +19,6 @@
*/
package com.keepassdroid;
-import android.os.Bundle;
-
import com.android.keepass.KeePass;
import com.keepassdroid.app.App;
diff --git a/src/com/keepassdroid/LockCloseListActivity.java b/src/com/keepassdroid/LockCloseListActivity.java
index 5743f6a7d..8d93ba98d 100644
--- a/src/com/keepassdroid/LockCloseListActivity.java
+++ b/src/com/keepassdroid/LockCloseListActivity.java
@@ -1,7 +1,5 @@
package com.keepassdroid;
-import android.os.Bundle;
-
import com.android.keepass.KeePass;
import com.keepassdroid.app.App;
diff --git a/src/com/keepassdroid/intents/TimeoutIntents.java b/src/com/keepassdroid/intents/Intents.java
similarity index 76%
rename from src/com/keepassdroid/intents/TimeoutIntents.java
rename to src/com/keepassdroid/intents/Intents.java
index 2fd305a6f..51910c445 100644
--- a/src/com/keepassdroid/intents/TimeoutIntents.java
+++ b/src/com/keepassdroid/intents/Intents.java
@@ -18,6 +18,9 @@
*
*/package com.keepassdroid.intents;
-public class TimeoutIntents {
- public static final String TIMEOUT = "com.android.keepassdroid.timeout";
+public class Intents {
+ public static final String TIMEOUT = "com.keepassdroid.timeout";
+
+ public static final String COPY_USERNAME = "com.keepassdroid.copy_username";
+ public static final String COPY_PASSWORD = "com.keepassdroid.copy_password";
}
diff --git a/src/com/keepassdroid/services/TimeoutService.java b/src/com/keepassdroid/services/TimeoutService.java
index 140049995..77e477442 100644
--- a/src/com/keepassdroid/services/TimeoutService.java
+++ b/src/com/keepassdroid/services/TimeoutService.java
@@ -19,6 +19,7 @@
*/
package com.keepassdroid.services;
+import android.app.NotificationManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -29,7 +30,7 @@ import android.os.IBinder;
import android.util.Log;
import com.keepassdroid.app.App;
-import com.keepassdroid.intents.TimeoutIntents;
+import com.keepassdroid.intents.Intents;
public class TimeoutService extends Service {
private static final String TAG = "KeePassDroid Timer";
@@ -44,14 +45,14 @@ public class TimeoutService extends Service {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if ( action.equals(TimeoutIntents.TIMEOUT) ) {
+ if ( action.equals(Intents.TIMEOUT) ) {
timeout(context);
}
}
};
IntentFilter filter = new IntentFilter();
- filter.addAction(TimeoutIntents.TIMEOUT);
+ filter.addAction(Intents.TIMEOUT);
registerReceiver(mIntentReceiver, filter);
}
@@ -59,6 +60,9 @@ public class TimeoutService extends Service {
private void timeout(Context context) {
Log.d(TAG, "Timeout");
App.setShutdown();
+
+ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ nm.cancelAll();
}
@Override
diff --git a/src/com/keepassdroid/timers/Timeout.java b/src/com/keepassdroid/timers/Timeout.java
index 17ea179d2..6507cec55 100644
--- a/src/com/keepassdroid/timers/Timeout.java
+++ b/src/com/keepassdroid/timers/Timeout.java
@@ -6,7 +6,7 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
-import com.keepassdroid.intents.TimeoutIntents;
+import com.keepassdroid.intents.Intents;
public class Timeout {
private static final int REQUEST_ID = 0;
@@ -14,7 +14,7 @@ public class Timeout {
private static String TAG = "KeePass Timeout";
private static PendingIntent buildIntent(Context ctx) {
- Intent intent = new Intent(TimeoutIntents.TIMEOUT);
+ Intent intent = new Intent(Intents.TIMEOUT);
PendingIntent sender = PendingIntent.getBroadcast(ctx, REQUEST_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
return sender;