Support username/password copy notifications.

This commit is contained in:
Brian Pellin committed 2009-11-15 22:01:05 -06:00
1 parent 8897c07ec7
commit 7325aaa276
7 files changed
+82 -12

No files matched your search

+2 -1
View File
@@ -31,7 +31,8 @@
<string name="app_name">KeePassDroid</string>
<string name="cancel">Cancel</string>
<string name="ClearClipboard">Clipboard cleared.</string>
<string name="current_group">Current Group: </string>
<string name="copy_username">Copy username to clipboard</string>
<string name="copy_password">Copy password to clipboard</string>
<string name="current_group_root">Current Group: Root</string>
<string name="disclaimer_formal">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.</string>
<string name="donate_url"><![CDATA[https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8246230]]></string>
+66
View File
@@ -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() {
@@ -19,8 +19,6 @@
*/
package com.keepassdroid;
import android.os.Bundle;
import com.android.keepass.KeePass;
import com.keepassdroid.app.App;
@@ -1,7 +1,5 @@
package com.keepassdroid;
import android.os.Bundle;
import com.android.keepass.KeePass;
import com.keepassdroid.app.App;
@@ -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";
}
@@ -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
+2 -2
View File
@@ -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;