Support for changing passwords
This commit is contained in:
@@ -29,6 +29,9 @@
|
||||
<activity
|
||||
android:name="i2p.bote.SettingsActivity"
|
||||
android:parentActivityName="i2p.bote.EmailListActivity" />
|
||||
<activity
|
||||
android:name="i2p.bote.SetPasswordActivity"
|
||||
android:parentActivityName="i2p.bote.SettingsActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
62
res/layout/activity_set_password.xml
Normal file
62
res/layout/activity_set_password.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="10dp"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/old_password"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_old"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textPassword" >
|
||||
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_password"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_new"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/confirm_new_password"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_confirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/submit_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="OK" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/error"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/error_color" />
|
||||
|
||||
</LinearLayout>
|
||||
23
res/layout/dialog_password.xml
Normal file
23
res/layout/dialog_password.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="5dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/enter_password"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/passwordInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword" >
|
||||
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -2,4 +2,5 @@
|
||||
<resources>
|
||||
<color name="uva_color">#c31756</color>
|
||||
<color name="default_color">#111</color>
|
||||
<color name="error_color">#f00</color>
|
||||
</resources>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<string name="email_sent">Sent:</string>
|
||||
<string name="email_received">Received:</string>
|
||||
|
||||
<string name="pref_title_change_password">Change password</string>
|
||||
<string name="pref_title_general">General</string>
|
||||
<string name="pref_title_autoMail">Auto-check mail</string>
|
||||
<string name="pref_title_checkInterval">Check interval</string>
|
||||
@@ -45,4 +46,8 @@
|
||||
<string name="pref_summ_maxDelay">%s minutes</string>
|
||||
<string name="pref_title_i2cp_host">I2CP host</string>
|
||||
<string name="pref_title_i2cp_port">I2CP port</string>
|
||||
|
||||
<string name="old_password">Old password:</string>
|
||||
<string name="new_password">New password:</string>
|
||||
<string name="confirm_new_password">Confirm new password:</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<Preference android:title="@string/pref_title_change_password" >
|
||||
<intent
|
||||
android:targetClass="i2p.bote.SetPasswordActivity"
|
||||
android:targetPackage="i2p.bote" />
|
||||
</Preference>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_title_general" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
|
||||
76
src/i2p/bote/SetPasswordActivity.java
Normal file
76
src/i2p/bote/SetPasswordActivity.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package i2p.bote;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SetPasswordActivity extends ActionBarActivity {
|
||||
TextView error;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_set_password);
|
||||
|
||||
// Enable ActionBar app icon to behave as action to go back
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
final EditText oldField = (EditText) findViewById(R.id.password_old);
|
||||
final EditText newField = (EditText) findViewById(R.id.password_new);
|
||||
final EditText confirmField = (EditText) findViewById(R.id.password_confirm);
|
||||
final Button b = (Button) findViewById(R.id.submit_password);
|
||||
error = (TextView) findViewById(R.id.error);
|
||||
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String oldPassword = oldField.getText().toString();
|
||||
String newPassword = newField.getText().toString();
|
||||
String confirmNewPassword = confirmField.getText().toString();
|
||||
|
||||
I2PBote.getInstance().changePasswordAsync(
|
||||
oldPassword.getBytes(),
|
||||
newPassword.getBytes(),
|
||||
confirmNewPassword.getBytes());
|
||||
|
||||
new PasswordWaiter().execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class PasswordWaiter extends AsyncTask<Void, Void, String> {
|
||||
private final ProgressDialog dialog = new ProgressDialog(SetPasswordActivity.this);
|
||||
|
||||
protected void onPreExecute() {
|
||||
dialog.setMessage("Changing password...");
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
protected String doInBackground(Void... params) {
|
||||
try {
|
||||
I2PBote.getInstance().waitForPasswordChange();
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
cancel(false);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onCancelled(String result) {
|
||||
error.setText(result);
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
protected void onPostExecute(String result) {
|
||||
dialog.dismiss();
|
||||
// Password changed successfully
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user