Skip to content

Commit

Permalink
Merge pull request #23 from jbaiter/copy-on-show
Browse files Browse the repository at this point in the history
Add option to automatically copy password to clipboard after decryption
  • Loading branch information
zeapo committed Oct 29, 2014
2 parents ad81e9b + 741ce31 commit 021bec9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
19 changes: 12 additions & 7 deletions app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
case R.id.copy_password:
ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", ((TextView) findViewById(R.id.crypto_password_show)).getText());
clipboard.setPrimaryClip(clip);
showToast("Password copied to clipboard, you have "
+ Integer.parseInt(settings.getString("general_show_time", "45"))
+ " seconds to paste it somewhere.");
copyToClipBoard();
}
return super.onOptionsItemSelected(item);
}

public void copyToClipBoard() {
ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", ((TextView) findViewById(R.id.crypto_password_show)).getText());
clipboard.setPrimaryClip(clip);
showToast("Password copied to clipboard, you have "
+ Integer.parseInt(settings.getString("general_show_time", "45"))
+ " seconds to paste it somewhere.");
}

public void handleClick(View view) {
switch (view.getId()) {
case R.id.crypto_show_button:
Expand Down Expand Up @@ -313,8 +317,6 @@ public void onReturn(Intent result) {

switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS: {
showToast("SUCCESS");

// encrypt/decrypt/sign/verify
if (requestCode == REQUEST_CODE_DECRYPT_AND_VERIFY && os != null) {
try {
Expand All @@ -336,6 +338,9 @@ public void onReturn(Intent result) {
.setText(extraContent);
}
new DelayShow().execute();
if (settings.getBoolean("copy_on_decrypt", true)) {
copyToClipBoard();
}
} else {
showToast(os.toString());
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/menu/agp_intents.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.AgpIntentsActivity" >
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
pwstore:showAsAction="never" />
</menu>
3 changes: 2 additions & 1 deletion app/src/main/res/menu/git_clone.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.GitHandler" >
<item android:id="@+id/user_pref"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
pwstore:showAsAction="never" />
</menu>
3 changes: 2 additions & 1 deletion app/src/main/res/menu/pgp_handler.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.crypto.PgpHandler" >
<item android:title="Copy password"
android:icon="@drawable/ico_copy"
android:showAsAction="ifRoom"
pwstore:showAsAction="ifRoom"
android:id="@+id/copy_password"
/>
</menu>
5 changes: 3 additions & 2 deletions app/src/main/res/menu/pwdstore.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context=".pwdstore" >

<item android:id="@+id/menu_add_password"
android:icon="@drawable/ico_add"
android:showAsAction="always"
pwstore:showAsAction="always"
android:title="New password"/>

<!--<item android:id="@+id/menu_add_category"-->
Expand All @@ -17,7 +18,7 @@

<item android:id="@+id/refresh"
android:title="Refresh list"
android:showAsAction="never"
pwstore:showAsAction="never"
android:icon="@drawable/ico_sync"/>

<item android:id="@+id/user_pref"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
android:dialogTitle="Set the time you want the password to be in clipboard"
android:summary="Set the time you want the password to be in clipboard"
android:hint="45" android:key="general_show_time" />
<CheckBoxPreference android:title="Automatically Copy Password"
android:dialogTitle="Automatically copy the password to the clipboard after decryption was successful."
android:summary="Automatically copy the password to the clipboard after decryption was successful."
android:key="copy_on_decrypt" android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 021bec9

Please sign in to comment.