Skip to content

Commit

Permalink
MainActivity: show password on input focus
Browse files Browse the repository at this point in the history
  • Loading branch information
bk138 committed Jun 12, 2023
1 parent c7e1249 commit 9043e44
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/src/main/java/net/christianbeier/droidvnc_ng/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
Expand Down Expand Up @@ -259,16 +261,30 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
SharedPreferences.Editor ed = prefs.edit();
ed.putString(Constants.PREFS_KEY_SETTINGS_PASSWORD, charSequence.toString());
ed.apply();
// only save new value if it differs from the default
if(!charSequence.toString().equals(mDefaults.getPassword())) {
SharedPreferences.Editor ed = prefs.edit();
ed.putString(Constants.PREFS_KEY_SETTINGS_PASSWORD, charSequence.toString());
ed.apply();
}
}

@Override
public void afterTextChanged(Editable editable) {

}
});
// show/hide password on focus change. NB that this triggers onTextChanged above, so we have
// to take special precautions there.
password.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
password.setTransformationMethod(new SingleLineTransformationMethod());
} else {
password.setTransformationMethod(new PasswordTransformationMethod());
}
// move cursor to end of text
password.setSelection(password.getText().length());
});

final SwitchMaterial startOnBoot = findViewById(R.id.settings_start_on_boot);
startOnBoot.setChecked(prefs.getBoolean(Constants.PREFS_KEY_SETTINGS_START_ON_BOOT, true));
Expand Down

0 comments on commit 9043e44

Please sign in to comment.