From 11f7d386b000bbfa565828a0f6cd54b765209874 Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Wed, 28 Feb 2018 14:18:00 +0100 Subject: [PATCH] Finish the initial intro screen --- README.md | 1 + .../Activities/IntroScreenActivity.java | 60 +++++++++++++++++-- .../flocke/andotp/Utilities/Settings.java | 4 ++ app/src/main/res/raw/licenses.xml | 6 ++ app/src/main/res/values/strings_intro.xml | 9 ++- 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a68b053d..44faed6f 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ So make sure you have a **current backup** before switching! * [Apache Commons Codec](https://commons.apache.org/proper/commons-codec/) * [Expandable Layout](https://github.com/AAkira/ExpandableLayout) * [LicensesDialog](https://github.com/PSDev/LicensesDialog) + * [material-intro](https://github.com/heinrichreimer/material-intro) * [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar) * [OpenPGP API library](https://github.com/open-keychain/openpgp-api) * [VNTNumberPickerPreference](https://github.com/vanniktech/VNTNumberPickerPreference) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java index 82447f58..2909d033 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/IntroScreenActivity.java @@ -30,10 +30,12 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.TextInputEditText; import android.support.design.widget.TextInputLayout; +import android.support.v4.view.ViewPager; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; import android.text.method.PasswordTransformationMethod; +import android.util.Log; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; @@ -45,6 +47,7 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; +import android.widget.Toast; import com.heinrichreimersoftware.materialintro.app.IntroActivity; import com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener; @@ -63,6 +66,21 @@ public class IntroScreenActivity extends IntroActivity { private EncryptionFragment encryptionFragment; private AuthenticationFragment authenticationFragment; + private void saveSettings() { + Constants.EncryptionType encryptionType = encryptionFragment.getEncryptionType(); + Constants.AuthMethod authMethod = authenticationFragment.getAuthMethod(); + + settings.setEncryption(encryptionType); + settings.setAuthMethod(authMethod); + + if (authMethod == Constants.AuthMethod.PASSWORD || authMethod == Constants.AuthMethod.PIN) { + String password = authenticationFragment.getPassword(); + settings.setAuthCredentials(password); + } + + settings.setFirstTimeWarningShown(true); + } + @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -75,7 +93,6 @@ public class IntroScreenActivity extends IntroActivity { @Override public void onEncryptionChanged(Constants.EncryptionType newEncryptionType) { authenticationFragment.updateEncryptionType(newEncryptionType); - settings.setEncryption(newEncryptionType); } }); @@ -84,7 +101,6 @@ public class IntroScreenActivity extends IntroActivity { addSlide(new SimpleSlide.Builder() .title(R.string.intro_slide1_title) .description(R.string.intro_slide1_desc) - .image(R.mipmap.ic_launcher) .background(R.color.colorPrimary) .backgroundDark(R.color.colorPrimaryDark) .canGoBackward(false) @@ -107,6 +123,15 @@ public class IntroScreenActivity extends IntroActivity { .build() ); + addSlide(new SimpleSlide.Builder() + .title(R.string.intro_slide4_title) + .description(R.string.intro_slide4_desc) + .background(R.color.colorPrimary) + .backgroundDark(R.color.colorPrimaryDark) + .scrollable(false) + .build() + ); + addOnNavigationBlockedListener(new OnNavigationBlockedListener() { @Override public void onNavigationBlocked(int position, int direction) { @@ -114,12 +139,27 @@ public class IntroScreenActivity extends IntroActivity { authenticationFragment.flashWarning(); } }); + + addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageSelected(int position) { + if (position == 3) + saveSettings(); + } + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + } + + @Override + public void onPageScrollStateChanged(int state) { + } + }); } @Override public void onBackPressed() { - if (getCurrentSlidePosition() != 0) - super.onBackPressed(); + // We don't want users to quit the intro screen and end up in an uninitialized state } public static class EncryptionFragment extends SlideFragment { @@ -145,6 +185,10 @@ public class IntroScreenActivity extends IntroActivity { selectionMapping.put(i, Constants.EncryptionType.valueOf(encValues[i].toUpperCase())); } + public Constants.EncryptionType getEncryptionType() { + return selectionMapping.get(selection.getSelectedItemPosition()); + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -258,6 +302,14 @@ public class IntroScreenActivity extends IntroActivity { } } + public Constants.AuthMethod getAuthMethod() { + return selectionMapping.get(selection.getSelectedItemPosition()); + } + + public String getPassword() { + return passwordInput.getText().toString(); + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java index 6d4d6285..fc6ce363 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java @@ -220,6 +220,10 @@ public class Settings { return AuthMethod.valueOf(authString.toUpperCase()); } + public void setAuthMethod(AuthMethod authMethod) { + setString(R.string.settings_key_auth, authMethod.name().toLowerCase()); + } + public void removeAuthPasswordHash() { remove(R.string.settings_key_auth_password_hash); } diff --git a/app/src/main/res/raw/licenses.xml b/app/src/main/res/raw/licenses.xml index acdbd880..b31a3b12 100644 --- a/app/src/main/res/raw/licenses.xml +++ b/app/src/main/res/raw/licenses.xml @@ -12,6 +12,12 @@ Copyright (C) 2015 A.Akira Apache Software License 2.0 + + material-intro + https://github.com/heinrichreimer/material-intro + Copyright (c) 2017 Jan Heinrich Reimer + MIT License + MaterialProgressBar https://github.com/DreaminginCodeZH/MaterialProgressBar diff --git a/app/src/main/res/values/strings_intro.xml b/app/src/main/res/values/strings_intro.xml index be84c295..1f70620c 100644 --- a/app/src/main/res/values/strings_intro.xml +++ b/app/src/main/res/values/strings_intro.xml @@ -1,7 +1,8 @@ - Welcome to andOTP - This wizard will guide you through the initial setup. + Let\'s get started + This wizard will guide you through the initial setup of andOTP. + Don\'t worry, you can still change any of the options later in the Settings. To ensure the security of your accounts andOTP only stores them in encrypted data files. Here you can choose which method of encryption will be used. @@ -28,4 +29,8 @@ Please set a PIN to continue! Please confirm your password to continue! Please confirm your PIN to continue! + + Finished + Your settings have been saved, you are all set to use andOTP + now! \ No newline at end of file