Finish the initial intro screen

This commit is contained in:
Jakob Nixdorf 2018-02-28 14:18:00 +01:00
parent 670bc31a54
commit 11f7d386b0
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
5 changed files with 74 additions and 6 deletions

View file

@ -128,6 +128,7 @@ So make sure you have a **current backup** before switching!
* [Apache Commons Codec](https://commons.apache.org/proper/commons-codec/) * [Apache Commons Codec](https://commons.apache.org/proper/commons-codec/)
* [Expandable Layout](https://github.com/AAkira/ExpandableLayout) * [Expandable Layout](https://github.com/AAkira/ExpandableLayout)
* [LicensesDialog](https://github.com/PSDev/LicensesDialog) * [LicensesDialog](https://github.com/PSDev/LicensesDialog)
* [material-intro](https://github.com/heinrichreimer/material-intro)
* [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar) * [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar)
* [OpenPGP API library](https://github.com/open-keychain/openpgp-api) * [OpenPGP API library](https://github.com/open-keychain/openpgp-api)
* [VNTNumberPickerPreference](https://github.com/vanniktech/VNTNumberPickerPreference) * [VNTNumberPickerPreference](https://github.com/vanniktech/VNTNumberPickerPreference)

View file

@ -30,10 +30,12 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.TextInputEditText; import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout; import android.support.design.widget.TextInputLayout;
import android.support.v4.view.ViewPager;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -45,6 +47,7 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.heinrichreimersoftware.materialintro.app.IntroActivity; import com.heinrichreimersoftware.materialintro.app.IntroActivity;
import com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener; import com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener;
@ -63,6 +66,21 @@ public class IntroScreenActivity extends IntroActivity {
private EncryptionFragment encryptionFragment; private EncryptionFragment encryptionFragment;
private AuthenticationFragment authenticationFragment; 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){ @Override protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -75,7 +93,6 @@ public class IntroScreenActivity extends IntroActivity {
@Override @Override
public void onEncryptionChanged(Constants.EncryptionType newEncryptionType) { public void onEncryptionChanged(Constants.EncryptionType newEncryptionType) {
authenticationFragment.updateEncryptionType(newEncryptionType); authenticationFragment.updateEncryptionType(newEncryptionType);
settings.setEncryption(newEncryptionType);
} }
}); });
@ -84,7 +101,6 @@ public class IntroScreenActivity extends IntroActivity {
addSlide(new SimpleSlide.Builder() addSlide(new SimpleSlide.Builder()
.title(R.string.intro_slide1_title) .title(R.string.intro_slide1_title)
.description(R.string.intro_slide1_desc) .description(R.string.intro_slide1_desc)
.image(R.mipmap.ic_launcher)
.background(R.color.colorPrimary) .background(R.color.colorPrimary)
.backgroundDark(R.color.colorPrimaryDark) .backgroundDark(R.color.colorPrimaryDark)
.canGoBackward(false) .canGoBackward(false)
@ -107,6 +123,15 @@ public class IntroScreenActivity extends IntroActivity {
.build() .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() { addOnNavigationBlockedListener(new OnNavigationBlockedListener() {
@Override @Override
public void onNavigationBlocked(int position, int direction) { public void onNavigationBlocked(int position, int direction) {
@ -114,12 +139,27 @@ public class IntroScreenActivity extends IntroActivity {
authenticationFragment.flashWarning(); 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 @Override
public void onBackPressed() { public void onBackPressed() {
if (getCurrentSlidePosition() != 0) // We don't want users to quit the intro screen and end up in an uninitialized state
super.onBackPressed();
} }
public static class EncryptionFragment extends SlideFragment { public static class EncryptionFragment extends SlideFragment {
@ -145,6 +185,10 @@ public class IntroScreenActivity extends IntroActivity {
selectionMapping.put(i, Constants.EncryptionType.valueOf(encValues[i].toUpperCase())); selectionMapping.put(i, Constants.EncryptionType.valueOf(encValues[i].toUpperCase()));
} }
public Constants.EncryptionType getEncryptionType() {
return selectionMapping.get(selection.getSelectedItemPosition());
}
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { 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 @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {

View file

@ -220,6 +220,10 @@ public class Settings {
return AuthMethod.valueOf(authString.toUpperCase()); return AuthMethod.valueOf(authString.toUpperCase());
} }
public void setAuthMethod(AuthMethod authMethod) {
setString(R.string.settings_key_auth, authMethod.name().toLowerCase());
}
public void removeAuthPasswordHash() { public void removeAuthPasswordHash() {
remove(R.string.settings_key_auth_password_hash); remove(R.string.settings_key_auth_password_hash);
} }

View file

@ -12,6 +12,12 @@
<copyright>Copyright (C) 2015 A.Akira</copyright> <copyright>Copyright (C) 2015 A.Akira</copyright>
<license>Apache Software License 2.0</license> <license>Apache Software License 2.0</license>
</notice> </notice>
<notice>
<name>material-intro</name>
<url>https://github.com/heinrichreimer/material-intro</url>
<copyright>Copyright (c) 2017 Jan Heinrich Reimer</copyright>
<license>MIT License</license>
</notice>
<notice> <notice>
<name>MaterialProgressBar</name> <name>MaterialProgressBar</name>
<url>https://github.com/DreaminginCodeZH/MaterialProgressBar</url> <url>https://github.com/DreaminginCodeZH/MaterialProgressBar</url>

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="intro_slide1_title">Welcome to andOTP</string> <string name="intro_slide1_title">Let\'s get started</string>
<string name="intro_slide1_desc">This wizard will guide you through the initial setup.</string> <string name="intro_slide1_desc">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 <b>Settings</b>.</string>
<string name="intro_slide2_desc">To ensure the security of your accounts andOTP only stores them <string name="intro_slide2_desc">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.</string> in encrypted data files. Here you can choose which method of encryption will be used.</string>
@ -28,4 +29,8 @@
<string name="intro_slide3_warn_no_pin">Please set a PIN to continue!</string> <string name="intro_slide3_warn_no_pin">Please set a PIN to continue!</string>
<string name="intro_slide3_warn_confirm_password">Please confirm your password to continue!</string> <string name="intro_slide3_warn_confirm_password">Please confirm your password to continue!</string>
<string name="intro_slide3_warn_confirm_pin">Please confirm your PIN to continue!</string> <string name="intro_slide3_warn_confirm_pin">Please confirm your PIN to continue!</string>
<string name="intro_slide4_title">Finished</string>
<string name="intro_slide4_desc">Your settings have been saved, you are all set to use andOTP
now!</string>
</resources> </resources>