Merge pull request #23 from jbaiter/copy-on-show

Add option to automatically copy password to clipboard after decryption
This commit is contained in:
Mohamed Zenadi 2014-10-29 12:38:11 +01:00
commit 021bec9f92
6 changed files with 25 additions and 12 deletions

View file

@ -145,15 +145,19 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
finish(); finish();
return true; return true;
case R.id.copy_password: case R.id.copy_password:
ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", ((TextView) findViewById(R.id.crypto_password_show)).getText()); copyToClipBoard();
clipboard.setPrimaryClip(clip);
showToast("Password copied to clipboard, you have "
+ Integer.parseInt(settings.getString("general_show_time", "45"))
+ " seconds to paste it somewhere.");
} }
return super.onOptionsItemSelected(item); 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) { public void handleClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.crypto_show_button: case R.id.crypto_show_button:
@ -313,8 +317,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS: { case OpenPgpApi.RESULT_CODE_SUCCESS: {
showToast("SUCCESS");
// encrypt/decrypt/sign/verify // encrypt/decrypt/sign/verify
if (requestCode == REQUEST_CODE_DECRYPT_AND_VERIFY && os != null) { if (requestCode == REQUEST_CODE_DECRYPT_AND_VERIFY && os != null) {
try { try {
@ -336,6 +338,9 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
.setText(extraContent); .setText(extraContent);
} }
new DelayShow().execute(); new DelayShow().execute();
if (settings.getBoolean("copy_on_decrypt", true)) {
copyToClipBoard();
}
} else { } else {
showToast(os.toString()); showToast(os.toString());
} }

View file

@ -1,8 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.AgpIntentsActivity" > tools:context="com.zeapo.pwdstore.AgpIntentsActivity" >
<item android:id="@+id/action_settings" <item android:id="@+id/action_settings"
android:title="@string/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:orderInCategory="100"
android:showAsAction="never" /> pwstore:showAsAction="never" />
</menu> </menu>

View file

@ -1,8 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.GitHandler" > tools:context="com.zeapo.pwdstore.GitHandler" >
<item android:id="@+id/user_pref" <item android:id="@+id/user_pref"
android:title="@string/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:orderInCategory="100"
android:showAsAction="never" /> pwstore:showAsAction="never" />
</menu> </menu>

View file

@ -1,9 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context="com.zeapo.pwdstore.crypto.PgpHandler" > tools:context="com.zeapo.pwdstore.crypto.PgpHandler" >
<item android:title="Copy password" <item android:title="Copy password"
android:icon="@drawable/ico_copy" android:icon="@drawable/ico_copy"
android:showAsAction="ifRoom" pwstore:showAsAction="ifRoom"
android:id="@+id/copy_password" android:id="@+id/copy_password"
/> />
</menu> </menu>

View file

@ -1,10 +1,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context=".pwdstore" > tools:context=".pwdstore" >
<item android:id="@+id/menu_add_password" <item android:id="@+id/menu_add_password"
android:icon="@drawable/ico_add" android:icon="@drawable/ico_add"
android:showAsAction="always" pwstore:showAsAction="always"
android:title="New password"/> android:title="New password"/>
<!--<item android:id="@+id/menu_add_category"--> <!--<item android:id="@+id/menu_add_category"-->
@ -17,7 +18,7 @@
<item android:id="@+id/refresh" <item android:id="@+id/refresh"
android:title="Refresh list" android:title="Refresh list"
android:showAsAction="never" pwstore:showAsAction="never"
android:icon="@drawable/ico_sync"/> android:icon="@drawable/ico_sync"/>
<item android:id="@+id/user_pref" <item android:id="@+id/user_pref"

View file

@ -30,5 +30,9 @@
android:dialogTitle="Set the time you want the password to be in clipboard" 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:summary="Set the time you want the password to be in clipboard"
android:hint="45" android:key="general_show_time" /> 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> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>