diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
2 files changed, 32 insertions, 7 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java index d82bf28a7..30a48e63e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java @@ -26,6 +26,7 @@ import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.EditText; @@ -42,6 +43,7 @@ public class CreateKeyInputFragment extends Fragment { AutoCompleteTextView mNameEdit; AutoCompleteTextView mEmailEdit; EditText mPassphraseEdit; + EditText mPassphraseEditAgain; View mCreateButton; public static final String ARG_NAME = "name"; @@ -69,7 +71,7 @@ public class CreateKeyInputFragment extends Fragment { mNameEdit = (AutoCompleteTextView) view.findViewById(R.id.name); mEmailEdit = (AutoCompleteTextView) view.findViewById(R.id.email); mPassphraseEdit = (EditText) view.findViewById(R.id.passphrase); - // TODO: second passphrase field + mPassphraseEditAgain = (EditText) view.findViewById(R.id.passphrase_again); mCreateButton = view.findViewById(R.id.create_key_button); // initial values @@ -149,7 +151,8 @@ public class CreateKeyInputFragment extends Fragment { private void createKeyCheck() { if (isEditTextNotEmpty(getActivity(), mNameEdit) && isEditTextNotEmpty(getActivity(), mEmailEdit) - && isEditTextNotEmpty(getActivity(), mPassphraseEdit)) { + && isEditTextNotEmpty(getActivity(), mPassphraseEdit) + && areEditTextsEqual(getActivity(), mPassphraseEdit, mPassphraseEditAgain)) { CreateKeyFinalFragment frag = CreateKeyFinalFragment.newInstance( @@ -157,10 +160,24 @@ public class CreateKeyInputFragment extends Fragment { mEmailEdit.getText().toString(), mPassphraseEdit.getText().toString() ); + + hideKeyboard(); mCreateKeyActivity.loadFragment(null, frag, CreateKeyActivity.ANIM_TO_RIGHT); } } + private void hideKeyboard() { + InputMethodManager inputManager = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + + //check if no view has focus: + View v = getActivity().getCurrentFocus(); + if (v == null) + return; + + inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); + } + /** * Checks if text of given EditText is not empty. If it is empty an error is * set and the EditText gets the focus. @@ -182,4 +199,17 @@ public class CreateKeyInputFragment extends Fragment { return output; } + private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) { + boolean output = true; + if (!editText1.getText().toString().equals(editText2.getText().toString())) { + editText2.setError(context.getString(R.string.create_key_passphrases_not_equal)); + editText2.requestFocus(); + output = false; + } else { + editText2.setError(null); + } + + return output; + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 7981b717e..0a7fd6aee 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -121,11 +121,6 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor return frag; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - /** * Creates dialog */ |