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