mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Merge branch '395-convert-createidentityactivity-to-xml' into 'master'
Turn the UI of `CreateIdentityActivity` into XML Closes #395 See merge request !194
This commit is contained in:
52
briar-android/res/layout/activity_create_identity.xml
Normal file
52
briar-android/res/layout/activity_create_identity.xml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
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"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="@dimen/margin_activity_horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/choose_nickname"
|
||||||
|
android:textSize="@dimen/text_size_large"/>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/nicknameInputLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:errorEnabled="true">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/nicknameEntry"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
android:maxLines="1"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/createIdentityButton"
|
||||||
|
style="@style/BriarButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:enabled="false"
|
||||||
|
android:text="@string/create_identity_button"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
style="?android:attr/progressBarStyleLarge"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -2,12 +2,14 @@ package org.briarproject.android.identity;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.TextInputLayout;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
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.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
@@ -16,7 +18,7 @@ import android.widget.Toast;
|
|||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.ActivityComponent;
|
import org.briarproject.android.ActivityComponent;
|
||||||
import org.briarproject.android.BriarActivity;
|
import org.briarproject.android.BriarActivity;
|
||||||
import org.briarproject.android.util.LayoutUtils;
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.CryptoExecutor;
|
import org.briarproject.api.crypto.CryptoExecutor;
|
||||||
import org.briarproject.api.crypto.KeyPair;
|
import org.briarproject.api.crypto.KeyPair;
|
||||||
@@ -31,18 +33,11 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.text.InputType.TYPE_CLASS_TEXT;
|
|
||||||
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
|
||||||
import static android.view.Gravity.CENTER;
|
|
||||||
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.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;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
|
||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
|
|
||||||
public class CreateIdentityActivity extends BriarActivity
|
public class CreateIdentityActivity extends BriarActivity
|
||||||
@@ -55,10 +50,10 @@ public class CreateIdentityActivity extends BriarActivity
|
|||||||
@CryptoExecutor
|
@CryptoExecutor
|
||||||
protected Executor cryptoExecutor;
|
protected Executor cryptoExecutor;
|
||||||
|
|
||||||
|
private TextInputLayout nicknameInput;
|
||||||
private EditText nicknameEntry;
|
private EditText nicknameEntry;
|
||||||
private Button createIdentityButton;
|
private Button createIdentityButton;
|
||||||
private ProgressBar progress;
|
private ProgressBar progress;
|
||||||
private TextView feedback;
|
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject
|
@Inject
|
||||||
@@ -71,52 +66,32 @@ public class CreateIdentityActivity extends BriarActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
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);
|
setContentView(R.layout.activity_create_identity);
|
||||||
chooseNickname.setGravity(CENTER);
|
|
||||||
chooseNickname.setTextSize(18);
|
|
||||||
chooseNickname.setText(R.string.choose_nickname);
|
|
||||||
layout.addView(chooseNickname);
|
|
||||||
|
|
||||||
nicknameEntry = new EditText(this) {
|
nicknameInput = (TextInputLayout) findViewById(R.id.nicknameInputLayout);
|
||||||
|
nicknameEntry = (EditText) findViewById(R.id.nicknameEntry);
|
||||||
|
nicknameEntry.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
protected void onTextChanged(CharSequence text, int start,
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||||
int lengthBefore, int lengthAfter) {
|
int after) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before,
|
||||||
|
int count) {
|
||||||
enableOrDisableCreateButton();
|
enableOrDisableCreateButton();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
nicknameEntry.setId(1);
|
@Override
|
||||||
nicknameEntry.setMaxLines(1);
|
public void afterTextChanged(Editable s) {}
|
||||||
int inputType = TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_CAP_WORDS;
|
});
|
||||||
nicknameEntry.setInputType(inputType);
|
|
||||||
nicknameEntry.setOnEditorActionListener(this);
|
nicknameEntry.setOnEditorActionListener(this);
|
||||||
layout.addView(nicknameEntry);
|
|
||||||
|
|
||||||
feedback = new TextView(this);
|
createIdentityButton = (Button) findViewById(R.id.createIdentityButton);
|
||||||
feedback.setGravity(CENTER);
|
if (createIdentityButton != null)
|
||||||
feedback.setPadding(0, pad, 0, pad);
|
createIdentityButton.setOnClickListener(this);
|
||||||
layout.addView(feedback);
|
|
||||||
|
|
||||||
createIdentityButton = new Button(this);
|
progress = (ProgressBar) findViewById(R.id.progressBar);
|
||||||
createIdentityButton.setLayoutParams(WRAP_WRAP);
|
|
||||||
createIdentityButton.setText(R.string.create_identity_button);
|
|
||||||
createIdentityButton.setEnabled(false);
|
|
||||||
createIdentityButton.setOnClickListener(this);
|
|
||||||
layout.addView(createIdentityButton);
|
|
||||||
|
|
||||||
progress = new ProgressBar(this);
|
|
||||||
progress.setLayoutParams(WRAP_WRAP);
|
|
||||||
progress.setIndeterminate(true);
|
|
||||||
progress.setVisibility(GONE);
|
|
||||||
layout.addView(progress);
|
|
||||||
|
|
||||||
setContentView(layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,10 +114,11 @@ public class CreateIdentityActivity extends BriarActivity
|
|||||||
String nickname = nicknameEntry.getText().toString();
|
String nickname = nicknameEntry.getText().toString();
|
||||||
int length = StringUtils.toUtf8(nickname).length;
|
int length = StringUtils.toUtf8(nickname).length;
|
||||||
if (length > MAX_AUTHOR_NAME_LENGTH) {
|
if (length > MAX_AUTHOR_NAME_LENGTH) {
|
||||||
feedback.setText(R.string.name_too_long);
|
String str = getString(R.string.name_too_long);
|
||||||
|
AndroidUtils.setError(nicknameInput, str, true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
feedback.setText("");
|
AndroidUtils.setError(nicknameInput, null, false);
|
||||||
return length > 0;
|
return length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +145,7 @@ public class CreateIdentityActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void storeLocalAuthor(final LocalAuthor a) {
|
private void storeLocalAuthor(final LocalAuthor a) {
|
||||||
runOnDbThread(new Runnable() {
|
dbController.runOnDbThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user