Add button to toggle passphrase visibility

closes #3776
// FREEBIE
This commit is contained in:
Carlin 2015-07-24 03:16:45 +12:00 committed by Moxie Marlinspike
parent 5a29c61dac
commit 927aac2c4a
20 changed files with 81 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,019 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

View file

@ -32,7 +32,40 @@
android:layout_marginRight="50dp"
android:singleLine="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
android:paddingRight="40dp"/>
<org.thoughtcrime.securesms.components.AnimatingToggle
android:id="@+id/button_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/passphrase_edit"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:gravity="center">
<ImageButton android:id="@+id/passphrase_visibility"
android:src="?ic_visibility"
android:background="@drawable/touch_highlight_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:layout_centerVertical="true" />
<ImageButton android:id="@+id/passphrase_visibility_off"
android:src="?ic_visibility_off"
android:background="@drawable/touch_highlight_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:layout_centerVertical="true" />
</org.thoughtcrime.securesms.components.AnimatingToggle>
<ImageButton android:id="@+id/ok_button"
android:src="?ic_arrow_forward"

View file

@ -23,6 +23,8 @@
<attr name="centered_app_title_color" format="reference|color" />
<attr name="ic_arrow_forward" format="reference" />
<attr name="ic_visibility" format="reference" />
<attr name="ic_visibility_off" format="reference" />
<attr name="conversation_background" format="reference|color"/>
<attr name="conversation_editor_background" format="reference|color"/>

View file

@ -46,6 +46,8 @@
<item name="centered_app_title_color">#55000000</item>
<item name="ic_arrow_forward">@drawable/ic_arrow_forward_light</item>
<item name="lockscreen_watermark">@drawable/lockscreen_watermark_light</item>
<item name="ic_visibility">@drawable/ic_visibility_grey600_24dp</item>
<item name="ic_visibility_off">@drawable/ic_visibility_off_grey600_24dp</item>
</style>
<style name="TextSecure.DarkIntroTheme" parent="@style/Theme.AppCompat">
@ -57,6 +59,8 @@
<item name="ic_arrow_forward">@drawable/ic_arrow_forward_dark</item>
<item name="lockscreen_watermark">@drawable/lockscreen_watermark_dark</item>
<item name="android:windowBackground">@color/black</item>
<item name="ic_visibility">@drawable/ic_visibility_white_24dp</item>
<item name="ic_visibility_off">@drawable/ic_visibility_off_white_24dp</item>
</style>
<style name="PopupAnimation" parent="@android:style/Animation">

View file

@ -20,6 +20,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.text.Editable;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
@ -36,6 +37,7 @@ import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import org.thoughtcrime.securesms.components.AnimatingToggle;
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.util.DynamicIntroTheme;
@ -52,7 +54,10 @@ public class PassphrasePromptActivity extends PassphraseActivity {
private DynamicIntroTheme dynamicTheme = new DynamicIntroTheme();
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
private EditText passphraseText;
private EditText passphraseText;
private ImageButton showButton;
private ImageButton hideButton;
private AnimatingToggle visibilityToggle;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -116,18 +121,36 @@ public class PassphrasePromptActivity extends PassphraseActivity {
}
}
private void setPassphraseVisibility(boolean visibility) {
int cursorPosition = passphraseText.getSelectionStart();
if (visibility) {
passphraseText.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
passphraseText.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
passphraseText.setSelection(cursorPosition);
}
private void initializeResources() {
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.centered_app_title);
ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
passphraseText = (EditText) findViewById(R.id.passphrase_edit);
showButton = (ImageButton) findViewById(R.id.passphrase_visibility);
hideButton = (ImageButton) findViewById(R.id.passphrase_visibility_off);
visibilityToggle = (AnimatingToggle) findViewById(R.id.button_toggle);
passphraseText = (EditText) findViewById(R.id.passphrase_edit);
SpannableString hint = new SpannableString(" " + getString(R.string.PassphrasePromptActivity_enter_passphrase));
hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
passphraseText.setHint(hint);
okButton.setOnClickListener(new OkButtonClickListener());
showButton.setOnClickListener(new ShowButtonOnClickListener());
hideButton.setOnClickListener(new HideButtonOnClickListener());
passphraseText.setOnEditorActionListener(new PassphraseActionListener());
passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
EditorInfo.IME_ACTION_DONE);
@ -159,6 +182,22 @@ public class PassphrasePromptActivity extends PassphraseActivity {
}
}
private class ShowButtonOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
visibilityToggle.display(hideButton);
setPassphraseVisibility(true);
}
}
private class HideButtonOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
visibilityToggle.display(showButton);
setPassphraseVisibility(false);
}
}
@Override
protected void cleanup() {
this.passphraseText.setText("");