From 8eb10e4220959d9fbf00406a3c645d96cc286dae Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Wed, 28 Feb 2018 11:14:20 +0100 Subject: [PATCH] Third part of the authentication screen (still WIP) TODO: * Actually save everything * Hand stuff over to the main activity on finish --- app/src/main/AndroidManifest.xml | 2 +- ...Activity.java => IntroScreenActivity.java} | 110 +++++++++++++++++- .../andotp/Activities/MainActivity.java | 37 +----- .../layout/component_intro_authentication.xml | 4 +- app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings_intro.xml | 4 + 6 files changed, 116 insertions(+), 43 deletions(-) rename app/src/main/java/org/shadowice/flocke/andotp/Activities/{MainIntroActivity.java => IntroScreenActivity.java} (68%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 32edd74a..9f822063 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,7 +36,7 @@ android:parentActivityName=".Activities.MainActivity" android:theme="@style/AppTheme.NoActionBar" /> adapterView, View view, int i, long l) { Constants.AuthMethod authMethod = selectionMapping.get(i); - if (authMethod == Constants.AuthMethod.PASSWORD || authMethod == Constants.AuthMethod.PIN) { + if (authMethod == Constants.AuthMethod.PASSWORD) { credentialsLayout.setVisibility(View.VISIBLE); + + passwordLayout.setHint(getString(R.string.settings_hint_password)); + passwordConfirm.setHint(R.string.settings_hint_password_confirm); + + passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + + passwordInput.setTransformationMethod(new PasswordTransformationMethod()); + passwordConfirm.setTransformationMethod(new PasswordTransformationMethod()); + + minLength = Constants.AUTH_MIN_PASSWORD_LENGTH; + lengthWarning = getString(R.string.settings_label_short_password, minLength); + noPasswordWarning = getString(R.string.intro_slide3_warn_no_password); + confirmPasswordWarning = getString(R.string.intro_slide3_warn_confirm_password); + + if (getIntroActivity().getCurrentSlidePosition() == slidePos) { + passwordInput.requestFocus(); + UIHelper.showKeyboard(getContext(), passwordInput); + } + } else if (authMethod == Constants.AuthMethod.PIN) { + credentialsLayout.setVisibility(View.VISIBLE); + + passwordLayout.setHint(getString(R.string.settings_hint_pin)); + passwordConfirm.setHint(R.string.settings_hint_pin_confirm); + + passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); + passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); + + passwordInput.setTransformationMethod(new PasswordTransformationMethod()); + passwordConfirm.setTransformationMethod(new PasswordTransformationMethod()); + + minLength = Constants.AUTH_MIN_PIN_LENGTH; + lengthWarning = getString(R.string.settings_label_short_pin, minLength); + noPasswordWarning = getString(R.string.intro_slide3_warn_no_pin); + confirmPasswordWarning = getString(R.string.intro_slide3_warn_confirm_pin); + + if (getIntroActivity().getCurrentSlidePosition() == slidePos) { + passwordInput.requestFocus(); + UIHelper.showKeyboard(getContext(), passwordInput); + } } else { credentialsLayout.setVisibility(View.INVISIBLE); + + UIHelper.hideKeyboard(getIntroActivity(), root); } updateNavigation(); @@ -282,7 +366,23 @@ public class MainIntroActivity extends IntroActivity { String password = passwordInput.getText().toString(); String confirm = passwordConfirm.getText().toString(); - return ! password.isEmpty() && ! confirm.isEmpty() && confirm.equals(password); + if (! password.isEmpty()) { + if (password.length() < minLength) { + displayWarning(lengthWarning); + return false; + } else { + if (! confirm.isEmpty() && confirm.equals(password)) { + hideWarning(); + return true; + } else { + displayWarning(confirmPasswordWarning); + return false; + } + } + } else { + displayWarning(noPasswordWarning); + return false; + } } else if (authMethod == Constants.AuthMethod.DEVICE) { KeyguardManager km = (KeyguardManager) getContext().getSystemService(KEYGUARD_SERVICE); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index 5a02dd98..be3b30f4 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -44,7 +44,6 @@ import android.support.v7.widget.helper.ItemTouchHelper; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.WindowManager; import android.view.animation.LinearInterpolator; import android.widget.AdapterView; @@ -103,42 +102,8 @@ public class MainActivity extends BaseActivity .initiateScan(); } - /*private void showFirstTimeWarning() { - ViewGroup container = findViewById(R.id.main_content); - View msgView = getLayoutInflater().inflate(R.layout.dialog_database_encryption, container, false); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.dialog_title_encryption) - .setView(msgView) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - settings.setFirstTimeWarningShown(true); - updateEncryption(null); - } - }) - .setNegativeButton(R.string.button_settings, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - settings.setFirstTimeWarningShown(true); - - Intent settingsIntent = new Intent(getBaseContext(), SettingsActivity.class); - startActivityForResult(settingsIntent, Constants.INTENT_MAIN_SETTINGS); - } - }) - .setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialogInterface) { - settings.setFirstTimeWarningShown(true); - updateEncryption(null); - } - }) - .create() - .show(); - }*/ - private void showFirstTimeWarning() { - Intent introIntent = new Intent(this, MainIntroActivity.class); + Intent introIntent = new Intent(this, IntroScreenActivity.class); startActivityForResult(introIntent, Constants.INTENT_MAIN_INTRO); } diff --git a/app/src/main/res/layout/component_intro_authentication.xml b/app/src/main/res/layout/component_intro_authentication.xml index 5f0d65f8..4a06732a 100644 --- a/app/src/main/res/layout/component_intro_authentication.xml +++ b/app/src/main/res/layout/component_intro_authentication.xml @@ -39,10 +39,12 @@ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9bcf5cef..b6cae957 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -11,6 +11,8 @@ #003087 #009cde + #b71c1c + #ffe0e0e0 #212121 diff --git a/app/src/main/res/values/strings_intro.xml b/app/src/main/res/values/strings_intro.xml index 00028d49..be84c295 100644 --- a/app/src/main/res/values/strings_intro.xml +++ b/app/src/main/res/values/strings_intro.xml @@ -24,4 +24,8 @@ Here you can setup an authentication to lock andOTP. Since you have chosen Password / PIN as encryption method you need to set either a password or a PIN to proceed. + Please set a password to continue! + Please set a PIN to continue! + Please confirm your password to continue! + Please confirm your PIN to continue! \ No newline at end of file