mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Use TextInputLayout from the Design Support Library to display errors
This commit is contained in:
@@ -6,8 +6,9 @@ dependencies {
|
||||
compile fileTree(dir: '../briar-core/libs', include: '*.jar')
|
||||
compile project(':briar-core')
|
||||
compile fileTree(dir: 'libs', include: '*.jar')
|
||||
compile 'com.android.support:design:23.1.1'
|
||||
compile 'com.android.support:recyclerview-v7:23.1.1'
|
||||
compile "com.android.support:support-v4:23.1.1"
|
||||
compile "com.android.support:appcompat-v7:23.1.1"
|
||||
compile "com.android.support:design:23.1.1"
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@@ -23,12 +24,19 @@
|
||||
android:text="@string/choose_nickname"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/nickname_entry"
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/nickname_entry_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text|textCapWords"
|
||||
android:maxLines="1"/>
|
||||
app:errorEnabled="true">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/nickname_entry"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text|textCapWords"
|
||||
android:maxLines="1"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -37,12 +45,19 @@
|
||||
android:text="@string/choose_password"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_entry"
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/password_entry_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"/>
|
||||
app:errorEnabled="true">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_entry"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -51,12 +66,19 @@
|
||||
android:text="@string/confirm_password"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_confirm"
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/password_confirm_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"/>
|
||||
app:errorEnabled="true">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_confirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<org.briarproject.android.util.StrengthMeter
|
||||
android:id="@+id/strength_meter"
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
@@ -17,6 +18,7 @@ import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.StrengthMeter;
|
||||
import org.briarproject.api.android.ReferenceManager;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
@@ -55,6 +57,9 @@ OnEditorActionListener {
|
||||
|
||||
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||
@Inject private PasswordStrengthEstimator strengthEstimator;
|
||||
@InjectView(R.id.nickname_entry_wrapper) TextInputLayout nicknameEntryWrapper;
|
||||
@InjectView(R.id.password_entry_wrapper) TextInputLayout passwordEntryWrapper;
|
||||
@InjectView(R.id.password_confirm_wrapper) TextInputLayout passwordConfirmationWrapper;
|
||||
@InjectView(R.id.nickname_entry) EditText nicknameEntry;
|
||||
@InjectView(R.id.password_entry) EditText passwordEntry;
|
||||
@InjectView(R.id.password_confirm) EditText passwordConfirmation;
|
||||
@@ -99,7 +104,7 @@ OnEditorActionListener {
|
||||
|
||||
private void enableOrDisableContinueButton() {
|
||||
if (progress == null) return; // Not created yet
|
||||
if (passwordEntry.getText().length() > 0 && passwordEntry.hasFocus())
|
||||
if (passwordEntry.getText().length() > 0)
|
||||
strengthMeter.setVisibility(VISIBLE);
|
||||
else strengthMeter.setVisibility(INVISIBLE);
|
||||
String nickname = nicknameEntry.getText().toString();
|
||||
@@ -109,12 +114,12 @@ OnEditorActionListener {
|
||||
boolean passwordsMatch = firstPassword.equals(secondPassword);
|
||||
float strength = strengthEstimator.estimateStrength(firstPassword);
|
||||
strengthMeter.setStrength(strength);
|
||||
if (nicknameLength > MAX_AUTHOR_NAME_LENGTH)
|
||||
nicknameEntry.setError(getString(R.string.name_too_long));
|
||||
if (firstPassword.length() > 0 && strength < WEAK)
|
||||
passwordEntry.setError(getString(R.string.password_too_weak));
|
||||
if (secondPassword.length() > 0 && !passwordsMatch)
|
||||
passwordConfirmation.setError(getString(R.string.passwords_do_not_match));
|
||||
AndroidUtils.setError(nicknameEntryWrapper, getString(R.string.name_too_long),
|
||||
nicknameLength > MAX_AUTHOR_NAME_LENGTH);
|
||||
AndroidUtils.setError(passwordEntryWrapper, getString(R.string.password_too_weak),
|
||||
firstPassword.length() > 0 && strength < WEAK);
|
||||
AndroidUtils.setError(passwordConfirmationWrapper, getString(R.string.passwords_do_not_match),
|
||||
secondPassword.length() > 0 && !passwordsMatch);
|
||||
createAccountButton.setEnabled(nicknameLength > 0
|
||||
&& nicknameLength <= MAX_AUTHOR_NAME_LENGTH
|
||||
&& passwordsMatch && strength >= WEAK);
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.android.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -23,4 +24,12 @@ public class AndroidUtils {
|
||||
}
|
||||
return Collections.unmodifiableList(abis);
|
||||
}
|
||||
|
||||
public static void setError(TextInputLayout til, String error, boolean condition) {
|
||||
if (condition) {
|
||||
if (til.getError() == null)
|
||||
til.setError(error);
|
||||
} else
|
||||
til.setError(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user