diff --git a/briar-android/res/layout/activity_setup.xml b/briar-android/res/layout/activity_setup.xml new file mode 100644 index 0000000000000000000000000000000000000000..0285356113c9568c3692836035342bb512190940 --- /dev/null +++ b/briar-android/res/layout/activity_setup.xml @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="utf-8"?> +<ScrollView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:orientation="vertical" + android:paddingBottom="@dimen/margin_activity_vertical" + android:paddingEnd="@dimen/margin_activity_horizontal" + android:paddingLeft="@dimen/margin_activity_horizontal" + android:paddingRight="@dimen/margin_activity_horizontal" + android:paddingStart="@dimen/margin_activity_horizontal" + android:paddingTop="@dimen/margin_activity_vertical"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:text="@string/choose_nickname" + android:textSize="18sp"/> + + <EditText + android:id="@+id/nickname_entry" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="text|textCapWords" + android:maxLines="1"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:text="@string/choose_password" + android:textSize="18sp"/> + + <EditText + android:id="@+id/password_entry" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="textPassword" + android:maxLines="1"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:text="@string/confirm_password" + android:textSize="18sp"/> + + <EditText + android:id="@+id/password_confirm" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="textPassword" + android:maxLines="1"/> + + <org.briarproject.android.util.StrengthMeter + android:id="@+id/strength_meter" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="invisible"/> + + <Button + android:id="@+id/create_account" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:enabled="false" + android:text="@string/create_account_button"/> + + <ProgressBar + android:id="@+id/progress_wheel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:indeterminate="true" + android:visibility="gone"/> + </LinearLayout> +</ScrollView> \ No newline at end of file diff --git a/briar-android/src/org/briarproject/android/SetupActivity.java b/briar-android/src/org/briarproject/android/SetupActivity.java index d0af6bb60857f278ef6945503344a4d87791db2a..56d61e8c27130eeea24a9d29f6319c415e8a50c6 100644 --- a/briar-android/src/org/briarproject/android/SetupActivity.java +++ b/briar-android/src/org/briarproject/android/SetupActivity.java @@ -4,20 +4,19 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; 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; import android.widget.ProgressBar; -import android.widget.ScrollView; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import org.briarproject.R; -import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.StrengthMeter; import org.briarproject.api.android.ReferenceManager; import org.briarproject.api.crypto.CryptoComponent; @@ -35,22 +34,16 @@ import java.util.logging.Logger; import javax.inject.Inject; +import roboguice.inject.InjectView; + import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static android.text.InputType.TYPE_CLASS_TEXT; -import static android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; -import static android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; -import static android.view.Gravity.CENTER; -import static android.view.Gravity.CENTER_HORIZONTAL; import static android.view.View.GONE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static android.view.WindowManager.LayoutParams.FLAG_SECURE; import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY; -import static android.widget.LinearLayout.VERTICAL; import static java.util.logging.Level.INFO; import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS; -import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; -import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP; import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK; import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; @@ -62,11 +55,12 @@ OnEditorActionListener { @Inject @CryptoExecutor private Executor cryptoExecutor; @Inject private PasswordStrengthEstimator strengthEstimator; - private EditText nicknameEntry = null; - private EditText passwordEntry = null, passwordConfirmation = null; - private StrengthMeter strengthMeter = null; - private Button createAccountButton = null; - private ProgressBar progress = null; + @InjectView(R.id.nickname_entry) EditText nicknameEntry; + @InjectView(R.id.password_entry) EditText passwordEntry; + @InjectView(R.id.password_confirm) EditText passwordConfirmation; + @InjectView(R.id.strength_meter) StrengthMeter strengthMeter; + @InjectView(R.id.create_account) Button createAccountButton; + @InjectView(R.id.progress_wheel) ProgressBar progress; // Fields that are accessed from background threads must be volatile @Inject private volatile CryptoComponent crypto; @@ -77,99 +71,30 @@ OnEditorActionListener { @Override public void onCreate(Bundle state) { super.onCreate(state); + setContentView(R.layout.activity_setup); if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE); - LinearLayout layout = new LinearLayout(this); - layout.setLayoutParams(MATCH_MATCH); - layout.setOrientation(VERTICAL); - layout.setGravity(CENTER_HORIZONTAL); - int pad = LayoutUtils.getPadding(this); - layout.setPadding(pad, pad, pad, pad); - - TextView chooseNickname = new TextView(this); - chooseNickname.setGravity(CENTER); - chooseNickname.setTextSize(18); - chooseNickname.setText(R.string.choose_nickname); - layout.addView(chooseNickname); - - nicknameEntry = new EditText(this) { + TextWatcher tw = new TextWatcher() { @Override - protected void onTextChanged(CharSequence text, int start, - int lengthBefore, int lengthAfter) { - enableOrDisableContinueButton(); + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } - }; - nicknameEntry.setId(1); - nicknameEntry.setMaxLines(1); - int inputType = TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_CAP_WORDS; - nicknameEntry.setInputType(inputType); - layout.addView(nicknameEntry); - - TextView choosePassword = new TextView(this); - choosePassword.setGravity(CENTER); - choosePassword.setTextSize(18); - choosePassword.setPadding(0, pad, 0, 0); - choosePassword.setText(R.string.choose_password); - layout.addView(choosePassword); - passwordEntry = new EditText(this) { @Override - protected void onTextChanged(CharSequence text, int start, - int lengthBefore, int lengthAfter) { + public void onTextChanged(CharSequence s, int start, int before, int count) { enableOrDisableContinueButton(); } - }; - passwordEntry.setId(2); - passwordEntry.setMaxLines(1); - inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD; - passwordEntry.setInputType(inputType); - layout.addView(passwordEntry); - - TextView confirmPassword = new TextView(this); - confirmPassword.setGravity(CENTER); - confirmPassword.setTextSize(18); - confirmPassword.setPadding(0, pad, 0, 0); - confirmPassword.setText(R.string.confirm_password); - layout.addView(confirmPassword); - passwordConfirmation = new EditText(this) { @Override - protected void onTextChanged(CharSequence text, int start, - int lengthBefore, int lengthAfter) { - enableOrDisableContinueButton(); + public void afterTextChanged(Editable s) { } }; - passwordConfirmation.setId(3); - passwordConfirmation.setMaxLines(1); - inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD; - passwordConfirmation.setInputType(inputType); - passwordConfirmation.setOnEditorActionListener(this); - layout.addView(passwordConfirmation); - strengthMeter = new StrengthMeter(this); - strengthMeter.setPadding(pad, pad, pad, pad); - strengthMeter.setVisibility(INVISIBLE); - layout.addView(strengthMeter); - - createAccountButton = new Button(this); - createAccountButton.setLayoutParams(WRAP_WRAP); - createAccountButton.setText(R.string.create_account_button); - createAccountButton.setEnabled(false); + nicknameEntry.addTextChangedListener(tw); + passwordEntry.addTextChangedListener(tw); + passwordConfirmation.addTextChangedListener(tw); + passwordConfirmation.setOnEditorActionListener(this); createAccountButton.setOnClickListener(this); - layout.addView(createAccountButton); - - progress = new ProgressBar(this); - progress.setLayoutParams(WRAP_WRAP); - progress.setPadding(0, pad, 0, 0); - progress.setIndeterminate(true); - progress.setVisibility(GONE); - layout.addView(progress); - - ScrollView scroll = new ScrollView(this); - scroll.addView(layout); - - setContentView(scroll); } private void enableOrDisableContinueButton() {