New identity creation
This commit is contained in:
BIN
res/drawable-hdpi/ic_device_access_new_account.png
Normal file
BIN
res/drawable-hdpi/ic_device_access_new_account.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
res/drawable-mdpi/ic_device_access_new_account.png
Normal file
BIN
res/drawable-mdpi/ic_device_access_new_account.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
res/drawable-xhdpi/ic_device_access_new_account.png
Normal file
BIN
res/drawable-xhdpi/ic_device_access_new_account.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -31,12 +31,20 @@
|
||||
android:hint="@string/description"
|
||||
android:inputType="text" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/default_identity"
|
||||
<Spinner
|
||||
android:id="@+id/crypto_impl"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/description"
|
||||
android:layout_below="@+id/description"
|
||||
android:visibility="gone" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/default_identity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/crypto_impl"
|
||||
android:layout_below="@+id/crypto_impl"
|
||||
android:text="@string/default_identity" />
|
||||
|
||||
<TextView
|
||||
|
||||
10
res/menu/settings.xml
Normal file
10
res/menu/settings.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_new_identity"
|
||||
android:icon="@drawable/ic_device_access_new_account"
|
||||
android:title="@string/new_identity"
|
||||
android:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
||||
@@ -61,6 +61,7 @@
|
||||
<string name="password_changed">Password changed successfully</string>
|
||||
|
||||
<string name="pref_title_identities">Identities</string>
|
||||
<string name="new_identity">New identity</string>
|
||||
<string name="public_name">Public name</string>
|
||||
<string name="description">Description</string>
|
||||
<string name="default_identity">Default identity</string>
|
||||
|
||||
@@ -16,8 +16,11 @@ public class EditIdentityActivity extends ActionBarActivity implements
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
EditIdentityFragment f = EditIdentityFragment.newInstance(
|
||||
getIntent().getExtras().getString(EditIdentityFragment.IDENTITY_KEY));
|
||||
String key = null;
|
||||
Bundle args = getIntent().getExtras();
|
||||
if (args != null)
|
||||
key = args.getString(EditIdentityFragment.IDENTITY_KEY);
|
||||
EditIdentityFragment f = EditIdentityFragment.newInstance(key);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.edit_identity_frag, f).commit();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package i2p.bote.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.List;
|
||||
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.R;
|
||||
import i2p.bote.StatusListener;
|
||||
import i2p.bote.crypto.CryptoFactory;
|
||||
import i2p.bote.crypto.CryptoImplementation;
|
||||
import i2p.bote.email.EmailIdentity;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.util.BoteHelper;
|
||||
@@ -24,8 +27,10 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class EditIdentityFragment extends Fragment {
|
||||
@@ -60,11 +65,15 @@ public class EditIdentityFragment extends Fragment {
|
||||
// instance of this fragment after rotation.
|
||||
static final String IDENTITY_WAITER_TAG = "identityWaiterTask";
|
||||
|
||||
static final int DEFAULT_CRYPTO_IMPL = 2;
|
||||
|
||||
private String mKey;
|
||||
private FragmentManager mFM;
|
||||
MenuItem mSave;
|
||||
EditText mNameField;
|
||||
EditText mDescField;
|
||||
Spinner mCryptoField;
|
||||
int mDefaultPos;
|
||||
CheckBox mDefaultField;
|
||||
TextView mError;
|
||||
|
||||
@@ -104,20 +113,30 @@ public class EditIdentityFragment extends Fragment {
|
||||
mDefaultField = (CheckBox) view.findViewById(R.id.default_identity);
|
||||
mError = (TextView) view.findViewById(R.id.error);
|
||||
|
||||
try {
|
||||
EmailIdentity identity = BoteHelper.getIdentity(mKey);
|
||||
mNameField.setText(identity.getPublicName());
|
||||
mDescField.setText(identity.getDescription());
|
||||
mDefaultField.setChecked(identity.isDefault());
|
||||
} catch (PasswordException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
} catch (GeneralSecurityException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
if (mKey == null) {
|
||||
// Show the encryption choice field
|
||||
mCryptoField = (Spinner) view.findViewById(R.id.crypto_impl);
|
||||
CryptoAdapter adapter = new CryptoAdapter(getActivity());
|
||||
mCryptoField.setAdapter(adapter);
|
||||
mCryptoField.setSelection(mDefaultPos);
|
||||
mCryptoField.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
// Load the identity to edit
|
||||
try {
|
||||
EmailIdentity identity = BoteHelper.getIdentity(mKey);
|
||||
mNameField.setText(identity.getPublicName());
|
||||
mDescField.setText(identity.getDescription());
|
||||
mDefaultField.setChecked(identity.isDefault());
|
||||
} catch (PasswordException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
} catch (GeneralSecurityException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +158,10 @@ public class EditIdentityFragment extends Fragment {
|
||||
String description = mDescField.getText().toString();
|
||||
boolean setDefault = mDefaultField.isChecked();
|
||||
|
||||
int cryptoImplId = -1;
|
||||
if (mKey == null)
|
||||
cryptoImplId = ((CryptoImplementation) mCryptoField.getSelectedItem()).getId();
|
||||
|
||||
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(mNameField.getWindowToken(), 0);
|
||||
|
||||
@@ -146,8 +169,8 @@ public class EditIdentityFragment extends Fragment {
|
||||
mError.setText("");
|
||||
|
||||
IdentityWaiterFrag f = IdentityWaiterFrag.newInstance(
|
||||
false,
|
||||
-1,
|
||||
(mKey == null ? true : false),
|
||||
cryptoImplId,
|
||||
mKey,
|
||||
publicName,
|
||||
description,
|
||||
@@ -177,6 +200,40 @@ public class EditIdentityFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private class CryptoAdapter extends ArrayAdapter<CryptoImplementation> {
|
||||
public CryptoAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_spinner_item);
|
||||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
|
||||
List<CryptoImplementation> instances = CryptoFactory.getInstances();
|
||||
mDefaultPos = 0;
|
||||
for (CryptoImplementation instance : instances) {
|
||||
add(instance);
|
||||
if (instance.getId() == DEFAULT_CRYPTO_IMPL)
|
||||
mDefaultPos = getPosition(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getView(position, convertView, parent);
|
||||
setViewText(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView (int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getDropDownView(position, convertView, parent);
|
||||
setViewText(v, position);
|
||||
return v;
|
||||
}
|
||||
|
||||
private void setViewText(View v, int position) {
|
||||
TextView text = (TextView) v.findViewById(android.R.id.text1);
|
||||
text.setText(getItem(position).getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static class IdentityWaiterFrag extends TaskFragment<Object, String, String> {
|
||||
static final String CREATE_NEW = "create_new";
|
||||
static final String CRYPTO_IMPL_ID = "crypto_impl_id";
|
||||
@@ -268,7 +325,6 @@ public class EditIdentityFragment extends Fragment {
|
||||
publishProgress(status);
|
||||
}
|
||||
};
|
||||
lsnr.updateStatus("Saving identity");
|
||||
try {
|
||||
BoteHelper.createOrModifyIdentity(
|
||||
(Boolean) params[0],
|
||||
@@ -277,7 +333,9 @@ public class EditIdentityFragment extends Fragment {
|
||||
(String) params[3],
|
||||
(String) params[4],
|
||||
(String) params[5],
|
||||
(Boolean) params[6]);
|
||||
(Boolean) params[6],
|
||||
lsnr);
|
||||
lsnr.updateStatus("Saving identity");
|
||||
I2PBote.getInstance().getIdentities().save();
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -23,6 +23,8 @@ import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
@@ -102,6 +104,26 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu
|
||||
getMenuInflater().inflate(R.menu.settings, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_new_identity:
|
||||
Intent ni = new Intent(this, EditIdentityActivity.class);
|
||||
startActivity(ni);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return SettingsFragment.class.getName().equals(fragmentName);
|
||||
|
||||
Reference in New Issue
Block a user