mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Show feedback when nickname or forum name is too long. Bug #45.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
<string name="choose_nickname">Choose your nickname:</string>
|
<string name="choose_nickname">Choose your nickname:</string>
|
||||||
<string name="choose_password">Choose your password:</string>
|
<string name="choose_password">Choose your password:</string>
|
||||||
<string name="confirm_password">Confirm your password:</string>
|
<string name="confirm_password">Confirm your password:</string>
|
||||||
|
<string name="name_too_long">Name is too long</string>
|
||||||
<string name="password_too_weak">Password is too weak</string>
|
<string name="password_too_weak">Password is too weak</string>
|
||||||
<string name="passwords_do_not_match">Passwords do not match</string>
|
<string name="passwords_do_not_match">Passwords do not match</string>
|
||||||
<string name="enter_password">Enter your password:</string>
|
<string name="enter_password">Enter your password:</string>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.android;
|
|||||||
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
||||||
|
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -18,6 +19,7 @@ import roboguice.activity.RoboActivity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
public class BriarActivity extends RoboActivity {
|
public class BriarActivity extends RoboActivity {
|
||||||
|
|
||||||
@@ -130,4 +132,9 @@ public class BriarActivity extends RoboActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void hideSoftKeyboard() {
|
||||||
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||||
|
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,8 +121,7 @@ public class PasswordActivity extends RoboActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void validatePassword(final byte[] encrypted, Editable e) {
|
private void validatePassword(final byte[] encrypted, Editable e) {
|
||||||
if(enterPassword == null || continueButton == null || progress == null)
|
if(progress == null) return; // Not created yet
|
||||||
return;
|
|
||||||
// Hide the soft keyboard
|
// Hide the soft keyboard
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import static android.widget.LinearLayout.VERTICAL;
|
|||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||||
|
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK;
|
import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -170,11 +171,12 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableOrDisableContinueButton() {
|
private void enableOrDisableContinueButton() {
|
||||||
if(continueButton == null) return; // Not created yet
|
if(progress == null) return; // Not created yet
|
||||||
if(passwordEntry.getText().length() > 0)
|
if(passwordEntry.getText().length() > 0)
|
||||||
strengthMeter.setVisibility(VISIBLE);
|
strengthMeter.setVisibility(VISIBLE);
|
||||||
else strengthMeter.setVisibility(INVISIBLE);
|
else strengthMeter.setVisibility(INVISIBLE);
|
||||||
boolean nicknameNotEmpty = nicknameEntry.getText().length() > 0;
|
String nickname = nicknameEntry.getText().toString();
|
||||||
|
int nicknameLength = StringUtils.toUtf8(nickname).length;
|
||||||
char[] firstPassword = getChars(passwordEntry.getText());
|
char[] firstPassword = getChars(passwordEntry.getText());
|
||||||
char[] secondPassword = getChars(passwordConfirmation.getText());
|
char[] secondPassword = getChars(passwordConfirmation.getText());
|
||||||
boolean passwordsMatch = Arrays.equals(firstPassword, secondPassword);
|
boolean passwordsMatch = Arrays.equals(firstPassword, secondPassword);
|
||||||
@@ -182,7 +184,9 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
|
|||||||
for(int i = 0; i < firstPassword.length; i++) firstPassword[i] = 0;
|
for(int i = 0; i < firstPassword.length; i++) firstPassword[i] = 0;
|
||||||
for(int i = 0; i < secondPassword.length; i++) secondPassword[i] = 0;
|
for(int i = 0; i < secondPassword.length; i++) secondPassword[i] = 0;
|
||||||
strengthMeter.setStrength(strength);
|
strengthMeter.setStrength(strength);
|
||||||
if(firstPassword.length == 0) {
|
if(nicknameLength > MAX_AUTHOR_NAME_LENGTH) {
|
||||||
|
feedback.setText(R.string.name_too_long);
|
||||||
|
} else if(firstPassword.length == 0) {
|
||||||
feedback.setText("");
|
feedback.setText("");
|
||||||
} else if(secondPassword.length == 0 || passwordsMatch) {
|
} else if(secondPassword.length == 0 || passwordsMatch) {
|
||||||
if(strength < PasswordStrengthEstimator.WEAK)
|
if(strength < PasswordStrengthEstimator.WEAK)
|
||||||
@@ -193,8 +197,9 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
|
|||||||
} else {
|
} else {
|
||||||
feedback.setText("");
|
feedback.setText("");
|
||||||
}
|
}
|
||||||
boolean valid = nicknameNotEmpty && passwordsMatch && strength >= WEAK;
|
continueButton.setEnabled(nicknameLength > 0
|
||||||
continueButton.setEnabled(valid);
|
&& nicknameLength <= MAX_AUTHOR_NAME_LENGTH
|
||||||
|
&& passwordsMatch && strength >= WEAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
private char[] getChars(Editable e) {
|
private char[] getChars(Editable e) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import static android.view.Gravity.CENTER;
|
|||||||
import static android.view.Gravity.CENTER_VERTICAL;
|
import static android.view.Gravity.CENTER_VERTICAL;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
import static android.widget.LinearLayout.VERTICAL;
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
@@ -69,7 +68,6 @@ import android.os.Bundle;
|
|||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@@ -419,9 +417,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
createMessage(StringUtils.toUtf8(message), timestamp);
|
createMessage(StringUtils.toUtf8(message), timestamp);
|
||||||
Toast.makeText(this, R.string.message_sent_toast, LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.message_sent_toast, LENGTH_SHORT).show();
|
||||||
content.setText("");
|
content.setText("");
|
||||||
// Hide the soft keyboard
|
hideSoftKeyboard();
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
|
||||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getMinTimestampForNewMessage() {
|
private long getMinTimestampForNewMessage() {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import static android.view.Gravity.CENTER;
|
|||||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
|
||||||
import static android.widget.LinearLayout.VERTICAL;
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
@@ -39,7 +38,6 @@ import android.os.Bundle;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -62,6 +60,7 @@ SelectContactsDialog.Listener {
|
|||||||
private RadioButton visibleToAll = null, visibleToSome = null;
|
private RadioButton visibleToAll = null, visibleToSome = null;
|
||||||
private Button createButton = null;
|
private Button createButton = null;
|
||||||
private ProgressBar progress = null;
|
private ProgressBar progress = null;
|
||||||
|
private TextView feedback = null;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile GroupFactory groupFactory;
|
@Inject private volatile GroupFactory groupFactory;
|
||||||
@@ -114,6 +113,11 @@ SelectContactsDialog.Listener {
|
|||||||
radioGroup.addView(visibleToSome);
|
radioGroup.addView(visibleToSome);
|
||||||
layout.addView(radioGroup);
|
layout.addView(radioGroup);
|
||||||
|
|
||||||
|
feedback = new TextView(this);
|
||||||
|
feedback.setGravity(CENTER);
|
||||||
|
feedback.setPadding(0, pad, 0, pad);
|
||||||
|
layout.addView(feedback);
|
||||||
|
|
||||||
createButton = new Button(this);
|
createButton = new Button(this);
|
||||||
createButton.setLayoutParams(WRAP_WRAP);
|
createButton.setLayoutParams(WRAP_WRAP);
|
||||||
createButton.setText(R.string.create_button);
|
createButton.setText(R.string.create_button);
|
||||||
@@ -130,26 +134,25 @@ SelectContactsDialog.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableOrDisableCreateButton() {
|
private void enableOrDisableCreateButton() {
|
||||||
if(createButton == null) return; // Activity not created yet
|
if(progress == null) return; // Not created yet
|
||||||
boolean nameNotEmpty = nameEntry.getText().length() > 0;
|
boolean nameValid = validateName();
|
||||||
boolean visibilitySelected = radioGroup.getCheckedRadioButtonId() != -1;
|
boolean visibilitySelected = radioGroup.getCheckedRadioButtonId() != -1;
|
||||||
createButton.setEnabled(nameNotEmpty && visibilitySelected);
|
createButton.setEnabled(nameValid && visibilitySelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: What is this for?
|
|
||||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||||
validateName();
|
hideSoftKeyboard();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateName() {
|
private boolean validateName() {
|
||||||
if(nameEntry.getText().length() == 0) return false;
|
int length = StringUtils.toUtf8(nameEntry.getText().toString()).length;
|
||||||
byte[] b = StringUtils.toUtf8(nameEntry.getText().toString());
|
if(length > MAX_GROUP_NAME_LENGTH) {
|
||||||
if(b.length > MAX_GROUP_NAME_LENGTH) return false;
|
feedback.setText(R.string.name_too_long);
|
||||||
// Hide the soft keyboard
|
return false;
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
}
|
||||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
feedback.setText("");
|
||||||
return true;
|
return length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@@ -159,7 +162,8 @@ SelectContactsDialog.Listener {
|
|||||||
if(contacts == null) loadContacts();
|
if(contacts == null) loadContacts();
|
||||||
else displayContacts();
|
else displayContacts();
|
||||||
} else if(view == createButton) {
|
} else if(view == createButton) {
|
||||||
if(!validateName()) return; // FIXME: Show feedback
|
hideSoftKeyboard();
|
||||||
|
if(!validateName()) return;
|
||||||
createButton.setVisibility(GONE);
|
createButton.setVisibility(GONE);
|
||||||
progress.setVisibility(VISIBLE);
|
progress.setVisibility(VISIBLE);
|
||||||
String name = nameEntry.getText().toString();
|
String name = nameEntry.getText().toString();
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import static android.view.Gravity.CENTER;
|
|||||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
|
||||||
import static android.widget.LinearLayout.VERTICAL;
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
@@ -37,7 +36,6 @@ import android.os.Bundle;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -56,6 +54,7 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
private EditText nicknameEntry = null;
|
private EditText nicknameEntry = null;
|
||||||
private Button createButton = null;
|
private Button createButton = null;
|
||||||
private ProgressBar progress = null;
|
private ProgressBar progress = null;
|
||||||
|
private TextView feedback = null;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile CryptoComponent crypto;
|
@Inject private volatile CryptoComponent crypto;
|
||||||
@@ -82,8 +81,7 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
@Override
|
@Override
|
||||||
protected void onTextChanged(CharSequence text, int start,
|
protected void onTextChanged(CharSequence text, int start,
|
||||||
int lengthBefore, int lengthAfter) {
|
int lengthBefore, int lengthAfter) {
|
||||||
if(createButton != null)
|
enableOrDisableCreateButton();
|
||||||
createButton.setEnabled(getText().length() > 0);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
nicknameEntry.setId(1);
|
nicknameEntry.setId(1);
|
||||||
@@ -93,6 +91,11 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
nicknameEntry.setOnEditorActionListener(this);
|
nicknameEntry.setOnEditorActionListener(this);
|
||||||
layout.addView(nicknameEntry);
|
layout.addView(nicknameEntry);
|
||||||
|
|
||||||
|
feedback = new TextView(this);
|
||||||
|
feedback.setGravity(CENTER);
|
||||||
|
feedback.setPadding(0, pad, 0, pad);
|
||||||
|
layout.addView(feedback);
|
||||||
|
|
||||||
createButton = new Button(this);
|
createButton = new Button(this);
|
||||||
createButton.setLayoutParams(WRAP_WRAP);
|
createButton.setLayoutParams(WRAP_WRAP);
|
||||||
createButton.setText(R.string.create_button);
|
createButton.setText(R.string.create_button);
|
||||||
@@ -109,29 +112,35 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: What is this for?
|
private void enableOrDisableCreateButton() {
|
||||||
|
if(progress == null) return; // Not created yet
|
||||||
|
createButton.setEnabled(validateNickname());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||||
validateNickname();
|
hideSoftKeyboard();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNickname() {
|
private boolean validateNickname() {
|
||||||
if(nicknameEntry.getText().length() == 0) return false;
|
String nickname = nicknameEntry.getText().toString();
|
||||||
byte[] b = StringUtils.toUtf8(nicknameEntry.getText().toString());
|
int length = StringUtils.toUtf8(nickname).length;
|
||||||
if(b.length > MAX_AUTHOR_NAME_LENGTH) return false;
|
if(length > MAX_AUTHOR_NAME_LENGTH) {
|
||||||
// Hide the soft keyboard
|
feedback.setText(R.string.name_too_long);
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
return false;
|
||||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
}
|
||||||
return true;
|
feedback.setText("");
|
||||||
|
return length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(!validateNickname()) return; // FIXME: Show feedback
|
hideSoftKeyboard();
|
||||||
final String nickname = nicknameEntry.getText().toString();
|
if(!validateNickname()) return;
|
||||||
// Replace the button with a progress bar
|
// Replace the button with a progress bar
|
||||||
createButton.setVisibility(GONE);
|
createButton.setVisibility(GONE);
|
||||||
progress.setVisibility(VISIBLE);
|
progress.setVisibility(VISIBLE);
|
||||||
// Create the identity in a background thread
|
// Create the identity in a background thread
|
||||||
|
final String nickname = nicknameEntry.getText().toString();
|
||||||
cryptoExecutor.execute(new Runnable() {
|
cryptoExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||||
|
|||||||
Reference in New Issue
Block a user