From d93692414ad6baa014230328f8135256de26017d Mon Sep 17 00:00:00 2001 From: Daniël van den Berg Date: Mon, 17 Oct 2016 13:00:58 +0200 Subject: Added the ability to make an invisible password visible using a button, and added some rough translations. (#230) --- .../java/com/zeapo/pwdstore/crypto/PgpHandler.java | 56 +++++++++++++++++++--- app/src/main/res/layout/decrypt_layout.xml | 9 ++++ app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 5 ++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 66 insertions(+), 6 deletions(-) (limited to 'app/src') 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 65f7fd9f..f137a2b8 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -17,11 +17,14 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; +import android.text.method.PasswordTransformationMethod; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; +import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -475,6 +478,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { case OpenPgpApi.RESULT_CODE_SUCCESS: { // encrypt/decrypt/sign/verify + final TextView textViewPassword = (TextView) findViewById(R.id.crypto_password_show); if (requestCode == REQUEST_CODE_DECRYPT_AND_VERIFY && os != null) { try { if (returnToCiphertextField) { @@ -485,11 +489,21 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne findViewById(R.id.crypto_container).setVisibility(View.VISIBLE); Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); - String[] passContent = os.toString("UTF-8").split("\n"); - ((TextView) findViewById(R.id.crypto_password_show)) + final String[] passContent = os.toString("UTF-8").split("\n"); + textViewPassword .setTypeface(monoTypeface); - ((TextView) findViewById(R.id.crypto_password_show)) - .setText(showPassword?passContent[0]:"********"); + textViewPassword + .setText(passContent[0]); + + Button toggleVisibilityButton = (Button) findViewById(R.id.crypto_password_toggle_show); + toggleVisibilityButton.setVisibility(showPassword?View.GONE:View.VISIBLE); + textViewPassword.setTransformationMethod(showPassword?null:new HoldToShowPasswordTransformation(toggleVisibilityButton, new Runnable() { + @Override + public void run() { + textViewPassword + .setText(passContent[0]); + } + })); decodedPassword = passContent[0]; String extraContent = os.toString("UTF-8").replaceFirst(".*\n", ""); @@ -559,9 +573,9 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); String[] passContent = os.toString("UTF-8").split("\n"); - ((TextView) findViewById(R.id.crypto_password_show)) + textViewPassword .setTypeface(monoTypeface); - ((TextView) findViewById(R.id.crypto_password_show)) + textViewPassword .setText(passContent[0]); decodedPassword = passContent[0]; @@ -757,6 +771,36 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne } + private class HoldToShowPasswordTransformation extends PasswordTransformationMethod implements View.OnTouchListener { + private final Runnable onToggle; + private boolean shown = false; + + private HoldToShowPasswordTransformation(Button button, Runnable onToggle) { + this.onToggle = onToggle; + button.setOnTouchListener(this); + } + + @Override + public CharSequence getTransformation(CharSequence charSequence, View view) { + return shown ? charSequence : super.getTransformation("12345", view); + } + + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + shown = true; + onToggle.run(); + break; + case MotionEvent.ACTION_UP: + shown = false; + onToggle.run(); + break; + } + return false; + } + } + private void setTimer() { // If a task already exist, let it finish without clearing the clipboard if (delayTask != null) { diff --git a/app/src/main/res/layout/decrypt_layout.xml b/app/src/main/res/layout/decrypt_layout.xml index 6c8fc1ff..0c7850d8 100644 --- a/app/src/main/res/layout/decrypt_layout.xml +++ b/app/src/main/res/layout/decrypt_layout.xml @@ -105,6 +105,15 @@ android:layout_row="1" android:layout_column="0" android:layout_columnSpan="3"/> + +