Prettify passphrase dialog, it no longer resizes on unlocking the key

This commit is contained in:
Dominik Schürmann 2015-03-03 22:27:14 +01:00
parent 5a4fc0a071
commit 188559bbcd
2 changed files with 43 additions and 33 deletions

View File

@ -149,6 +149,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
public static class PassphraseDialogFragment extends DialogFragment implements TextView.OnEditorActionListener { public static class PassphraseDialogFragment extends DialogFragment implements TextView.OnEditorActionListener {
private EditText mPassphraseEditText; private EditText mPassphraseEditText;
private TextView mPassphraseText;
private View mInput, mProgress; private View mInput, mProgress;
private CanonicalizedSecretKeyRing mSecretRing = null; private CanonicalizedSecretKeyRing mSecretRing = null;
@ -167,7 +168,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
// if the dialog is displayed from the application class, design is missing // if the dialog is displayed from the application class, design is missing
// hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
ContextThemeWrapper theme = new ContextThemeWrapper(activity, ContextThemeWrapper theme = new ContextThemeWrapper(activity,
R.style.Theme_AppCompat_Light); R.style.Theme_AppCompat_Light_Dialog);
mSubKeyId = getArguments().getLong(EXTRA_SUBKEY_ID); mSubKeyId = getArguments().getLong(EXTRA_SUBKEY_ID);
mServiceIntent = getArguments().getParcelable(EXTRA_DATA); mServiceIntent = getArguments().getParcelable(EXTRA_DATA);
@ -176,13 +177,30 @@ public class PassphraseDialogActivity extends FragmentActivity {
alert.setTitle(R.string.title_unlock); alert.setTitle(R.string.title_unlock);
LayoutInflater inflater = LayoutInflater.from(theme);
View view = inflater.inflate(R.layout.passphrase_dialog, null);
alert.setView(view);
mPassphraseText = (TextView) view.findViewById(R.id.passphrase_text);
mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase);
mInput = view.findViewById(R.id.input);
mProgress = view.findViewById(R.id.progress);
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
String userId; String userId;
CanonicalizedSecretKey.SecretKeyType keyType = CanonicalizedSecretKey.SecretKeyType.PASSPHRASE; CanonicalizedSecretKey.SecretKeyType keyType = CanonicalizedSecretKey.SecretKeyType.PASSPHRASE;
String message;
if (mSubKeyId == Constants.key.symmetric || mSubKeyId == Constants.key.none) { if (mSubKeyId == Constants.key.symmetric || mSubKeyId == Constants.key.none) {
alert.setMessage(R.string.passphrase_for_symmetric_encryption); message = getString(R.string.passphrase_for_symmetric_encryption);
} else { } else {
String message;
try { try {
ProviderHelper helper = new ProviderHelper(activity); ProviderHelper helper = new ProviderHelper(activity);
mSecretRing = helper.getCanonicalizedSecretKeyRing( mSecretRing = helper.getCanonicalizedSecretKeyRing(
@ -228,33 +246,16 @@ public class PassphraseDialogActivity extends FragmentActivity {
alert.setCancelable(false); alert.setCancelable(false);
return alert.create(); return alert.create();
} }
alert.setMessage(message);
} }
LayoutInflater inflater = LayoutInflater.from(theme); mPassphraseText.setText(message);
View view = inflater.inflate(R.layout.passphrase_dialog, null);
alert.setView(view);
mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase);
mInput = view.findViewById(R.id.input);
mProgress = view.findViewById(R.id.progress);
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
if (keyType == CanonicalizedSecretKey.SecretKeyType.PATTERN) { if (keyType == CanonicalizedSecretKey.SecretKeyType.PATTERN) {
// start pattern dialog and show progress circle here... // start pattern dialog and show progress circle here...
// Intent patternActivity = new Intent(getActivity(), LockPatternActivity.class); // Intent patternActivity = new Intent(getActivity(), LockPatternActivity.class);
// patternActivity.putExtra(LockPatternActivity.EXTRA_PATTERN, "123"); // patternActivity.putExtra(LockPatternActivity.EXTRA_PATTERN, "123");
// startActivityForResult(patternActivity, REQUEST_CODE_ENTER_PATTERN); // startActivityForResult(patternActivity, REQUEST_CODE_ENTER_PATTERN);
mInput.setVisibility(View.GONE); mInput.setVisibility(View.INVISIBLE);
mProgress.setVisibility(View.VISIBLE); mProgress.setVisibility(View.VISIBLE);
} else { } else {
// Hack to open keyboard. // Hack to open keyboard.
@ -322,7 +323,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
return; return;
} }
mInput.setVisibility(View.GONE); mInput.setVisibility(View.INVISIBLE);
mProgress.setVisibility(View.VISIBLE); mProgress.setVisibility(View.VISIBLE);
positive.setEnabled(false); positive.setEnabled(false);
@ -364,7 +365,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
mPassphraseEditText.setText(""); mPassphraseEditText.setText("");
mPassphraseEditText.setError(getString(R.string.wrong_passphrase)); mPassphraseEditText.setError(getString(R.string.wrong_passphrase));
mInput.setVisibility(View.VISIBLE); mInput.setVisibility(View.VISIBLE);
mProgress.setVisibility(View.GONE); mProgress.setVisibility(View.INVISIBLE);
positive.setEnabled(true); positive.setEnabled(true);
return; return;
} }

View File

@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="16dp" android:paddingTop="16dp"
android:paddingRight="16dp" android:paddingBottom="16dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:id="@+id/input"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical">
android:id="@+id/input">
<TextView
android:id="@+id/passphrase_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:text="@string/enter_passphrase" />
<EditText <EditText
android:id="@+id/passphrase_passphrase" android:id="@+id/passphrase_passphrase"
@ -26,11 +35,12 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/progress"
android:layout_centerInParent="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:id="@+id/progress" android:visibility="invisible">
android:visibility="gone">
<ProgressBar <ProgressBar
style="?android:attr/progressBarStyle" style="?android:attr/progressBarStyle"
@ -42,11 +52,10 @@
style="?android:attr/textAppearanceMedium" style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:padding="4dp" android:padding="4dp"
android:text="@string/label_unlock" android:text="@string/label_unlock"
android:layout_gravity="center_vertical" /> android:layout_gravity="center_vertical" />
</LinearLayout> </LinearLayout>
</LinearLayout> </RelativeLayout>