mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +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_password">Choose 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="passwords_do_not_match">Passwords do not match</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_SINGLE_TOP;
|
||||
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
@@ -18,6 +19,7 @@ import roboguice.activity.RoboActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
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) {
|
||||
if(enterPassword == null || continueButton == null || progress == null)
|
||||
return;
|
||||
if(progress == null) return; // Not created yet
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((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 org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
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 java.util.Arrays;
|
||||
@@ -170,11 +171,12 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
|
||||
}
|
||||
|
||||
private void enableOrDisableContinueButton() {
|
||||
if(continueButton == null) return; // Not created yet
|
||||
if(progress == null) return; // Not created yet
|
||||
if(passwordEntry.getText().length() > 0)
|
||||
strengthMeter.setVisibility(VISIBLE);
|
||||
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[] secondPassword = getChars(passwordConfirmation.getText());
|
||||
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 < secondPassword.length; i++) secondPassword[i] = 0;
|
||||
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("");
|
||||
} else if(secondPassword.length == 0 || passwordsMatch) {
|
||||
if(strength < PasswordStrengthEstimator.WEAK)
|
||||
@@ -193,8 +197,9 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
|
||||
} else {
|
||||
feedback.setText("");
|
||||
}
|
||||
boolean valid = nicknameNotEmpty && passwordsMatch && strength >= WEAK;
|
||||
continueButton.setEnabled(valid);
|
||||
continueButton.setEnabled(nicknameLength > 0
|
||||
&& nicknameLength <= MAX_AUTHOR_NAME_LENGTH
|
||||
&& passwordsMatch && strength >= WEAK);
|
||||
}
|
||||
|
||||
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.View.GONE;
|
||||
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.VERTICAL;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
@@ -69,7 +68,6 @@ import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.EditText;
|
||||
@@ -419,9 +417,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
createMessage(StringUtils.toUtf8(message), timestamp);
|
||||
Toast.makeText(this, R.string.message_sent_toast, LENGTH_SHORT).show();
|
||||
content.setText("");
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
hideSoftKeyboard();
|
||||
}
|
||||
|
||||
private long getMinTimestampForNewMessage() {
|
||||
|
||||
@@ -6,7 +6,6 @@ import static android.view.Gravity.CENTER;
|
||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||
import static android.view.View.GONE;
|
||||
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.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Level.INFO;
|
||||
@@ -39,7 +38,6 @@ import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -62,6 +60,7 @@ SelectContactsDialog.Listener {
|
||||
private RadioButton visibleToAll = null, visibleToSome = null;
|
||||
private Button createButton = null;
|
||||
private ProgressBar progress = null;
|
||||
private TextView feedback = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile GroupFactory groupFactory;
|
||||
@@ -114,6 +113,11 @@ SelectContactsDialog.Listener {
|
||||
radioGroup.addView(visibleToSome);
|
||||
layout.addView(radioGroup);
|
||||
|
||||
feedback = new TextView(this);
|
||||
feedback.setGravity(CENTER);
|
||||
feedback.setPadding(0, pad, 0, pad);
|
||||
layout.addView(feedback);
|
||||
|
||||
createButton = new Button(this);
|
||||
createButton.setLayoutParams(WRAP_WRAP);
|
||||
createButton.setText(R.string.create_button);
|
||||
@@ -130,26 +134,25 @@ SelectContactsDialog.Listener {
|
||||
}
|
||||
|
||||
private void enableOrDisableCreateButton() {
|
||||
if(createButton == null) return; // Activity not created yet
|
||||
boolean nameNotEmpty = nameEntry.getText().length() > 0;
|
||||
if(progress == null) return; // Not created yet
|
||||
boolean nameValid = validateName();
|
||||
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) {
|
||||
validateName();
|
||||
hideSoftKeyboard();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateName() {
|
||||
if(nameEntry.getText().length() == 0) return false;
|
||||
byte[] b = StringUtils.toUtf8(nameEntry.getText().toString());
|
||||
if(b.length > MAX_GROUP_NAME_LENGTH) return false;
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
return true;
|
||||
int length = StringUtils.toUtf8(nameEntry.getText().toString()).length;
|
||||
if(length > MAX_GROUP_NAME_LENGTH) {
|
||||
feedback.setText(R.string.name_too_long);
|
||||
return false;
|
||||
}
|
||||
feedback.setText("");
|
||||
return length > 0;
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
@@ -159,7 +162,8 @@ SelectContactsDialog.Listener {
|
||||
if(contacts == null) loadContacts();
|
||||
else displayContacts();
|
||||
} else if(view == createButton) {
|
||||
if(!validateName()) return; // FIXME: Show feedback
|
||||
hideSoftKeyboard();
|
||||
if(!validateName()) return;
|
||||
createButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
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.View.GONE;
|
||||
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.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Level.INFO;
|
||||
@@ -37,7 +36,6 @@ import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -56,6 +54,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
private EditText nicknameEntry = null;
|
||||
private Button createButton = null;
|
||||
private ProgressBar progress = null;
|
||||
private TextView feedback = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile CryptoComponent crypto;
|
||||
@@ -82,8 +81,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
@Override
|
||||
protected void onTextChanged(CharSequence text, int start,
|
||||
int lengthBefore, int lengthAfter) {
|
||||
if(createButton != null)
|
||||
createButton.setEnabled(getText().length() > 0);
|
||||
enableOrDisableCreateButton();
|
||||
}
|
||||
};
|
||||
nicknameEntry.setId(1);
|
||||
@@ -93,6 +91,11 @@ implements OnEditorActionListener, OnClickListener {
|
||||
nicknameEntry.setOnEditorActionListener(this);
|
||||
layout.addView(nicknameEntry);
|
||||
|
||||
feedback = new TextView(this);
|
||||
feedback.setGravity(CENTER);
|
||||
feedback.setPadding(0, pad, 0, pad);
|
||||
layout.addView(feedback);
|
||||
|
||||
createButton = new Button(this);
|
||||
createButton.setLayoutParams(WRAP_WRAP);
|
||||
createButton.setText(R.string.create_button);
|
||||
@@ -109,29 +112,35 @@ implements OnEditorActionListener, OnClickListener {
|
||||
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) {
|
||||
validateNickname();
|
||||
hideSoftKeyboard();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateNickname() {
|
||||
if(nicknameEntry.getText().length() == 0) return false;
|
||||
byte[] b = StringUtils.toUtf8(nicknameEntry.getText().toString());
|
||||
if(b.length > MAX_AUTHOR_NAME_LENGTH) return false;
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
return true;
|
||||
String nickname = nicknameEntry.getText().toString();
|
||||
int length = StringUtils.toUtf8(nickname).length;
|
||||
if(length > MAX_AUTHOR_NAME_LENGTH) {
|
||||
feedback.setText(R.string.name_too_long);
|
||||
return false;
|
||||
}
|
||||
feedback.setText("");
|
||||
return length > 0;
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(!validateNickname()) return; // FIXME: Show feedback
|
||||
final String nickname = nicknameEntry.getText().toString();
|
||||
hideSoftKeyboard();
|
||||
if(!validateNickname()) return;
|
||||
// Replace the button with a progress bar
|
||||
createButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
// Create the identity in a background thread
|
||||
final String nickname = nicknameEntry.getText().toString();
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
|
||||
Reference in New Issue
Block a user