summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorDaniƫl van den Berg <danielvandenberg95@gmail.com>2016-10-17 13:00:58 +0200
committerMohamed Zenadi <zeapo@users.noreply.github.com>2016-10-17 13:00:58 +0200
commitd93692414ad6baa014230328f8135256de26017d (patch)
tree25ebf1e5f9fd768e980e34c37cc11d8e40600b59 /app/src/main/java
parent0bab911033787d96a64755e544cc8831bc9c0114 (diff)
Added the ability to make an invisible password visible using a button, and added some rough translations. (#230)
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java56
1 files changed, 50 insertions, 6 deletions
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) {