Second part of the authentication slide (still WIP)

This commit is contained in:
Jakob Nixdorf 2018-02-28 08:19:23 +01:00
parent 14a7e2c174
commit ebc1c971ef
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 181 additions and 72 deletions

View file

@ -1,15 +1,22 @@
package org.shadowice.flocke.andotp.Activities;
import android.app.KeyguardManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputEditText;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
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.SlideFragment;
@ -91,6 +98,14 @@ public class MainIntroActivity extends IntroActivity {
encryptionChangedCallback = cb;
}
private void generateSelectionMapping() {
String[] encValues = getResources().getStringArray(R.array.settings_values_encryption);
selectionMapping = new SparseArray<>();
for (int i = 0; i < encValues.length; i++)
selectionMapping.put(i, Constants.EncryptionType.valueOf(encValues[i].toUpperCase()));
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -99,11 +114,7 @@ public class MainIntroActivity extends IntroActivity {
selection = root.findViewById(R.id.introEncryptionSelection);
desc = root.findViewById(R.id.introEncryptionDesc);
String[] encValues = getResources().getStringArray(R.array.settings_values_encryption);
selectionMapping = new SparseArray<>();
for (int i = 0; i < encValues.length; i++)
selectionMapping.put(i, Constants.EncryptionType.valueOf(encValues[i].toUpperCase()));
generateSelectionMapping();
selection.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
@ -137,6 +148,10 @@ public class MainIntroActivity extends IntroActivity {
private TextView desc = null;
private Spinner selection = null;
private TextView authWarnings = null;
private LinearLayout credentialsLayout = null;
private TextInputEditText passwordInput = null;
private EditText passwordConfirm = null;
private SparseArray<Constants.AuthMethod> selectionMapping;
@ -159,6 +174,27 @@ public class MainIntroActivity extends IntroActivity {
}
}
private void generateSelectionMapping() {
Constants.AuthMethod[] authValues = Constants.AuthMethod.values();
selectionMapping = new SparseArray<>();
for (int i = 0; i < authValues.length; i++)
selectionMapping.put(i, authValues[i]);
}
private void displayWarning(int resId) {
displayWarning(getString(resId));
}
private void displayWarning(String warning) {
authWarnings.setVisibility(View.VISIBLE);
authWarnings.setText(warning);
}
private void hideWarning() {
authWarnings.setVisibility(View.GONE);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -166,14 +202,14 @@ public class MainIntroActivity extends IntroActivity {
desc = root.findViewById(R.id.introAuthDesc);
selection = root.findViewById(R.id.introAuthSelection);
authWarnings = root.findViewById(R.id.introAuthWarnings);
credentialsLayout = root.findViewById(R.id.introCredentialsLayout);
passwordInput = root.findViewById(R.id.introPasswordEdit);
passwordConfirm = root.findViewById(R.id.introPasswordConfirm);
Constants.AuthMethod[] authValues = Constants.AuthMethod.values();
String[] authEntries = getResources().getStringArray(R.array.settings_entries_auth);
selectionMapping = new SparseArray<>();
for (int i = 0; i < authValues.length; i++)
selectionMapping.put(i, authValues[i]);
generateSelectionMapping();
final String[] authEntries = getResources().getStringArray(R.array.settings_entries_auth);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getIntroActivity(), android.R.layout.simple_spinner_item, authEntries) {
@Override
public boolean isEnabled(int position){
@ -198,7 +234,74 @@ public class MainIntroActivity extends IntroActivity {
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selection.setAdapter(spinnerArrayAdapter);
selection.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Constants.AuthMethod authMethod = selectionMapping.get(i);
if (authMethod == Constants.AuthMethod.PASSWORD || authMethod == Constants.AuthMethod.PIN) {
credentialsLayout.setVisibility(View.VISIBLE);
} else {
credentialsLayout.setVisibility(View.INVISIBLE);
}
updateNavigation();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
updateNavigation();
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
}
};
passwordInput.addTextChangedListener(textWatcher);
passwordConfirm.addTextChangedListener(textWatcher);
return root;
}
@Override
public boolean canGoForward() {
Constants.AuthMethod authMethod = selectionMapping.get(selection.getSelectedItemPosition());
if (authMethod == Constants.AuthMethod.PIN || authMethod == Constants.AuthMethod.PASSWORD) {
String password = passwordInput.getText().toString();
String confirm = passwordConfirm.getText().toString();
return ! password.isEmpty() && ! confirm.isEmpty() && confirm.equals(password);
} else if (authMethod == Constants.AuthMethod.DEVICE) {
KeyguardManager km = (KeyguardManager) getContext().getSystemService(KEYGUARD_SERVICE);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
displayWarning(R.string.settings_toast_auth_device_pre_lollipop);
return false;
} else if (! km.isKeyguardSecure()) {
displayWarning(R.string.settings_toast_auth_device_not_secure);
return false;
}
hideWarning();
return true;
} else {
hideWarning();
return true;
}
}
}
}

View file

@ -1,79 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:padding="@dimen/activity_margin_large">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textStyle="bold"
android:text="@string/settings_title_auth" />
<TextView
android:id="@+id/introAuthDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/intro_slide3_desc_keystore"/>
<Spinner
android:id="@+id/introAuthSelection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin_large"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:entries="@array/settings_entries_auth" />
android:overScrollMode="never">
<LinearLayout
android:id="@+id/introCredentialsLayout"
android:visibility="invisible"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/activity_margin_large"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin">
<android.support.design.widget.TextInputLayout
android:id="@+id/introPasswordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_hint_password"
app:passwordToggleEnabled="true" >
<android.support.design.widget.TextInputEditText
android:id="@+id/introPasswordEdit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<EditText
android:id="@+id/introPasswordConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_hint_password_confirm"
android:inputType="textPassword" />
android:layout_gravity="center"
android:gravity="center"
android:padding="@dimen/activity_margin_large">
<TextView
android:id="@+id/introPasswordToShortWarning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textStyle="bold"
android:text="@string/settings_title_auth" />
<TextView
android:id="@+id/introAuthDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/intro_slide3_desc_keystore"/>
<Spinner
android:id="@+id/introAuthSelection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin_large"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:entries="@array/settings_entries_auth" />
<TextView
android:id="@+id/introAuthWarnings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:visibility="gone"
android:textAlignment="center"
android:text="@string/settings_label_short_password" />
android:textStyle="bold" />
<LinearLayout
android:id="@+id/introCredentialsLayout"
android:visibility="invisible"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/activity_margin_large"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin">
<android.support.design.widget.TextInputLayout
android:id="@+id/introPasswordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_hint_password"
app:passwordToggleEnabled="true" >
<android.support.design.widget.TextInputEditText
android:id="@+id/introPasswordEdit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<EditText
android:id="@+id/introPasswordConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_hint_password_confirm"
android:inputType="textPassword" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>