From 6665c0b2e98c6599d8c66854e97ceb08958dab56 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Tue, 25 Aug 2015 21:02:11 -0400 Subject: [PATCH] Password editing: action bar edit button replaces decrypt view with encrypt view --- .../com/zeapo/pwdstore/crypto/PgpHandler.java | 42 +++++++++++++++++- .../main/res/drawable-hdpi/ic_action_edit.png | Bin 0 -> 214 bytes .../main/res/drawable-mdpi/ic_action_edit.png | Bin 0 -> 165 bytes .../res/drawable-xhdpi/ic_action_edit.png | Bin 0 -> 241 bytes .../res/drawable-xxhdpi/ic_action_edit.png | Bin 0 -> 304 bytes app/src/main/res/menu/pgp_handler.xml | 5 +++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_action_edit.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_edit.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_edit.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_edit.png diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index b744c4a07..fa46fb3ca 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -56,6 +56,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne SharedPreferences settings; private Activity activity; ClipboardManager clipboard; + AsyncTask delayShowTask; private boolean registered; @@ -137,10 +138,46 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne return true; case R.id.copy_password: copyToClipBoard(); + break; + case R.id.edit_password: + editPassword(); + if (delayShowTask != null) { + delayShowTask.cancel(true); + delayShowTask = null; + } } return super.onOptionsItemSelected(item); } + public void editPassword() { + + if (findViewById(R.id.crypto_container).getVisibility() != View.VISIBLE) + return; + + CharSequence category = ((TextView) findViewById(R.id.crypto_password_category)).getText(); + CharSequence file = ((TextView) findViewById(R.id.crypto_password_file)).getText(); + CharSequence password = ((TextView) findViewById(R.id.crypto_password_show)).getText(); + CharSequence extra = ((TextView) findViewById(R.id.crypto_extra_show)).getText(); + + setContentView(R.layout.encrypt_layout); + Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); + ((EditText) findViewById(R.id.crypto_password_edit)).setTypeface(monoTypeface); + ((EditText) findViewById(R.id.crypto_extra_edit)).setTypeface(monoTypeface); + + ((TextView) findViewById(R.id.crypto_password_category)).setText(category); + ((TextView) findViewById(R.id.crypto_password_file_edit)).setText(file); + ((EditText) findViewById(R.id.crypto_password_edit)).setText(password); + ((EditText) findViewById(R.id.crypto_extra_edit)).setText(extra); + + // the original intent was to decrypt so FILE_PATH will have the file, not enclosing dir + // PgpCallback expects the dir when encrypting + String filePath = getIntent().getExtras().getString("FILE_PATH"); + String directoryPath = filePath.substring(0, filePath.lastIndexOf(File.separator)); + Intent intent = new Intent(this, PgpHandler.class); + intent.putExtra("FILE_PATH", directoryPath); + setIntent(intent); + } + public void copyToClipBoard() { if (findViewById(R.id.crypto_password_show) == null) @@ -248,6 +285,9 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne if (showPassword) { publishProgress(current); } + if (isCancelled()) { + return false; + } } return true; } @@ -361,7 +401,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne copyToClipBoard(); } - new DelayShow().execute(); + delayShowTask = new DelayShow().execute(); if (!showPassword) { activity.setResult(RESULT_CANCELED); activity.finish(); diff --git a/app/src/main/res/drawable-hdpi/ic_action_edit.png b/app/src/main/res/drawable-hdpi/ic_action_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..3ecfd46f15a12428c8b172ebe94547c4ab59255b GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8LpTu&FrkcwMxuUK<67znUjnB%lT zoOSjO>jray$uJw$FFVMU;3(SEsNVV` zY0pZ=3oE8p__*1#52{6WCQLy}71A z^UjP{%xC@x1hXWnn6M?T5oq1$VC;1(TE5wU%_Uvsiq|WdbN}v4kacX7^^;%MKMUwk N22WQ%mvv4FO#mGTPZj_G literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_action_edit.png b/app/src/main/res/drawable-mdpi/ic_action_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..efad93e52e9bd997aec50ba3750e30beb116e44c GIT binary patch literal 165 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+i98VX=kcwN$2@+Kg_J9Ac|NpmV z;J?TA96oAc&PVGdUZ@}Y5}^>ueD%XLiQ|9%%Clen^me~?-P5>$?ao_51Xjx|Qk^y- zdBRlThZ6o?Q|jd-p2|(pELRqpvP6?TOTpK2Qrr9gcRRh0Ezy*ZVPIH1?c-FDiM+f( Pdl@`k{an^LB{Ts5+$cVy literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_action_edit.png b/app/src/main/res/drawable-xhdpi/ic_action_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..559aac98782bc96a8de4914ec59abdb147ef10b7 GIT binary patch literal 241 zcmV7i+YHfV)t0$1_X4YV2}h+a;DAlkjR2R(-bzcaw^58u5}WV0<` zNKxU9D>fQF!voz4L1Mrw5??$&ffL-36K7B2!a2@9n0Rt-|H2`VC|OVIPt@4*evX@{ z5pzH0I5C?~oqs<}92NX1q2aqkuH;3xH@@fZ|Kpo=^NI1(`Q3{7HlXF(fR_IexKa3E rfW-#_Jl-2%@}2;fcLHqQW}CPVemtixx@SbJ00000NkvXXu0mjf!uVzI literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_edit.png b/app/src/main/res/drawable-xxhdpi/ic_action_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..29046d95c1a0fe4585564c0ba5be4c90566767e7 GIT binary patch literal 304 zcmV-00nh%4P)OLs%FK&w(s@CJQaJeUcC>U>Osb8N>Te@D(##%q9tAjLjsZ zNc~`PobkpBCuANtOWg3SLhgxUPik>&Nu3-!QZL7fgdJj;koE(l%p2*bH9Kn|>8Ul! zcWgwYhu&t%NC(YDA0`!8=)OB~QZez4bv}drBoj_Q$&AxYnw*nIIBn9_n$sfLbM#1J zPD5IG;y4&(a>)4`&Xt^zI2UrrAxFrm$Qg-Kl0%MDP7U(KsX@LtKY&W5qop&B5EK+o zy3RNPP*6U2JL3$1g2i`$FHQs$jDAd=aTsH4?tK8x^ctzY2~S}F0000 +