mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
add preferences, use them where applicable
This commit is contained in:
parent
86192e39d9
commit
e83a5311ae
@ -115,6 +115,11 @@
|
||||
android:label="@string/title_mailInbox"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
||||
|
||||
<activity
|
||||
android:name=".PreferencesActivity"
|
||||
android:label="@string/title_preferences"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
||||
|
||||
<provider
|
||||
android:name="org.thialfihar.android.apg.provider.DataProvider"
|
||||
android:authorities="org.thialfihar.android.apg.provider" />
|
||||
|
@ -65,14 +65,15 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView android:id="@+id/label_algorithm"
|
||||
android:text="@string/label_algorithm"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
<TextView
|
||||
android:id="@+id/label_algorithm"
|
||||
android:text="@string/label_algorithm"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/algorithm"
|
||||
@ -219,33 +220,37 @@
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView android:id="@+id/label_pass_phrase"
|
||||
android:text="@string/label_pass_phrase"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
<TextView
|
||||
android:id="@+id/label_pass_phrase"
|
||||
android:text="@string/label_pass_phrase"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<EditText android:id="@+id/pass_phrase"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:inputType="textPassword"/>
|
||||
<EditText
|
||||
android:id="@+id/pass_phrase"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:inputType="textPassword"/>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView android:id="@+id/label_pass_phrase_again"
|
||||
android:text="@string/label_pass_phrase_again"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
<TextView
|
||||
android:id="@+id/label_pass_phrase_again"
|
||||
android:text="@string/label_pass_phrase_again"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<EditText android:id="@+id/pass_phrase_again"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:inputType="textPassword"/>
|
||||
<EditText
|
||||
android:id="@+id/pass_phrase_again"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:inputType="textPassword"/>
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
114
res/layout/preferences.xml
Normal file
114
res/layout/preferences.xml
Normal file
@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="5dip"
|
||||
android:layout_marginRight="?android:attr/scrollbarSize">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/section_defaults"
|
||||
android:text="@string/section_defaults"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1dip"
|
||||
android:background="?android:attr/listDivider"
|
||||
android:layout_marginBottom="5dip"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_encryption_algorithm"
|
||||
android:text="@string/label_encryption_algorithm"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/encryption_algorithm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_hash_algorithm"
|
||||
android:text="@string/label_hash_algorithm"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/hash_algorithm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_ascii_armour"
|
||||
android:text="@string/label_ascii_armour"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/ascii_armour"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@ -28,6 +28,7 @@
|
||||
<string name="title_authentification">Authentification</string>
|
||||
<string name="title_createKey">Create Key</string>
|
||||
<string name="title_editKey">Edit Key</string>
|
||||
<string name="title_preferences">Preferences</string>
|
||||
|
||||
<string name="section_userIds">User IDs</string>
|
||||
<string name="section_keys">Keys</string>
|
||||
@ -49,6 +50,7 @@
|
||||
<string name="menu_addAccount">Add GMail Account</string>
|
||||
<string name="menu_managePublicKeys">Manage Public Keys</string>
|
||||
<string name="menu_manageSecretKeys">Manage Secret Keys</string>
|
||||
<string name="menu_preferences">Settings</string>
|
||||
|
||||
<string name="no_keys_selected">Select</string>
|
||||
<string name="one_key_selected">1 Selected</string>
|
||||
@ -65,6 +67,11 @@
|
||||
<string name="label_select_public_keys">Public Key(s)</string>
|
||||
<string name="label_use_pass_phrase">Use Pass Phrase</string>
|
||||
|
||||
<string name="label_encryption_algorithm">Encryption Algorithm</string>
|
||||
<string name="label_hash_algorithm">Hash Algorithm</string>
|
||||
|
||||
<string name="section_defaults">Defaults</string>
|
||||
|
||||
<string name="sign_only">Sign only</string>
|
||||
<string name="encrypt_only">Encrypt only</string>
|
||||
<string name="sign_and_encrypt">Sign and Encrypt</string>
|
||||
|
@ -1175,7 +1175,7 @@ public class Apg {
|
||||
long encryptionKeyIds[], long signatureKeyId,
|
||||
String signaturePassPhrase,
|
||||
ProgressDialogUpdater progress,
|
||||
int symmetricAlgorithm,
|
||||
int symmetricAlgorithm, int hashAlgorithm,
|
||||
String passPhrase)
|
||||
throws IOException, GeneralException, PGPException, NoSuchProviderException,
|
||||
NoSuchAlgorithmException, SignatureException {
|
||||
@ -1251,7 +1251,7 @@ public class Apg {
|
||||
progress.setProgress("preparing signature...", 30, 100);
|
||||
signatureGenerator =
|
||||
new PGPSignatureGenerator(signingKey.getPublicKey().getAlgorithm(),
|
||||
HashAlgorithmTags.SHA1,
|
||||
hashAlgorithm,
|
||||
new BouncyCastleProvider());
|
||||
signatureGenerator.initSign(PGPSignature.BINARY_DOCUMENT, signaturePrivateKey);
|
||||
String userId = getMainUserId(getMasterKey(signingKeyRing));
|
||||
|
@ -16,12 +16,16 @@
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
|
||||
import org.bouncycastle2.bcpg.HashAlgorithmTags;
|
||||
import org.bouncycastle2.openpgp.PGPEncryptedData;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -34,6 +38,7 @@ public class BaseActivity extends Activity
|
||||
private Thread mRunningThread = null;
|
||||
|
||||
private long mSecretKeyId = 0;
|
||||
protected static SharedPreferences mPreferences = null;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
@ -46,6 +51,9 @@ public class BaseActivity extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (mPreferences == null) {
|
||||
mPreferences = getPreferences(MODE_PRIVATE);
|
||||
}
|
||||
Apg.initialize(this);
|
||||
}
|
||||
|
||||
@ -245,4 +253,46 @@ public class BaseActivity extends Activity
|
||||
public long getSecretKeyId() {
|
||||
return mSecretKeyId;
|
||||
}
|
||||
|
||||
public int getDefaultEncryptionAlgorithm() {
|
||||
return mPreferences.getInt(Constants.pref.default_encryption_algorithm,
|
||||
PGPEncryptedData.AES_256);
|
||||
}
|
||||
|
||||
public void setDefaultEncryptionAlgorithm(int value) {
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(Constants.pref.default_encryption_algorithm, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public int getDefaultHashAlgorithm() {
|
||||
return mPreferences.getInt(Constants.pref.default_hash_algorithm,
|
||||
HashAlgorithmTags.SHA256);
|
||||
}
|
||||
|
||||
public void setDefaultHashAlgorithm(int value) {
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(Constants.pref.default_hash_algorithm, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getDefaultAsciiArmour() {
|
||||
return mPreferences.getBoolean(Constants.pref.default_ascii_armour, false);
|
||||
}
|
||||
|
||||
public void setDefaultAsciiArmour(boolean value) {
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(Constants.pref.default_ascii_armour, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean hasSeenChangeLog() {
|
||||
return mPreferences.getBoolean(Constants.pref.has_seen_change_log, false);
|
||||
}
|
||||
|
||||
public void setHasSeenChangeLog(boolean value) {
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(Constants.pref.has_seen_change_log, value);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
@ -25,5 +25,8 @@ public final class Constants {
|
||||
|
||||
public static final class pref {
|
||||
public static final String has_seen_change_log = "seenChangeLogDialog" + Apg.VERSION;
|
||||
public static final String default_encryption_algorithm = "defaultEncryptionAlgorithm";
|
||||
public static final String default_hash_algorithm = "defaultHashAlgorithm";
|
||||
public static final String default_ascii_armour = "defaultAsciiArmour";
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ public class EncryptFileActivity extends BaseActivity {
|
||||
setContentView(R.layout.encrypt_file);
|
||||
|
||||
mAsciiArmour = (CheckBox) findViewById(R.id.ascii_armour);
|
||||
mAsciiArmour.setChecked(getDefaultAsciiArmour());
|
||||
|
||||
// asymmetric tab
|
||||
mSelectKeysButton = (Button) findViewById(R.id.btn_selectEncryptKeys);
|
||||
@ -138,7 +139,7 @@ public class EncryptFileActivity extends BaseActivity {
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mAlgorithm.setAdapter(adapter);
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == PGPEncryptedData.AES_256) {
|
||||
if (choices[i].getId() == getDefaultEncryptionAlgorithm()) {
|
||||
mAlgorithm.setSelection(i);
|
||||
break;
|
||||
}
|
||||
@ -331,6 +332,7 @@ public class EncryptFileActivity extends BaseActivity {
|
||||
mEncryptionKeyIds, getSecretKeyId(),
|
||||
Apg.getPassPhrase(), this,
|
||||
((Choice) mAlgorithm.getSelectedItem()).getId(),
|
||||
getDefaultHashAlgorithm(),
|
||||
passPhrase);
|
||||
|
||||
out.close();
|
||||
|
@ -25,7 +25,6 @@ import java.security.SignatureException;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.bouncycastle2.bcpg.HashAlgorithmTags;
|
||||
import org.bouncycastle2.openpgp.PGPEncryptedData;
|
||||
import org.bouncycastle2.openpgp.PGPException;
|
||||
import org.bouncycastle2.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle2.openpgp.PGPPublicKeyRing;
|
||||
@ -202,10 +201,11 @@ public class EncryptMessageActivity extends BaseActivity {
|
||||
if (encryptIt) {
|
||||
Apg.encrypt(in, out, true, mEncryptionKeyIds, getSecretKeyId(),
|
||||
Apg.getPassPhrase(), this,
|
||||
PGPEncryptedData.AES_256, null);
|
||||
getDefaultEncryptionAlgorithm(), getDefaultHashAlgorithm(),
|
||||
null);
|
||||
} else {
|
||||
Apg.signText(in, out, getSecretKeyId(),
|
||||
Apg.getPassPhrase(), HashAlgorithmTags.SHA256, this);
|
||||
Apg.getPassPhrase(), getDefaultHashAlgorithm(), this);
|
||||
}
|
||||
data.putString("message", new String(out.toByteArray()));
|
||||
} catch (IOException e) {
|
||||
|
@ -30,6 +30,7 @@ public final class Id {
|
||||
public static final int manage_secret_keys = 0x21070005;
|
||||
public static final int import_keys = 0x21070006;
|
||||
public static final int export_keys = 0x21070007;
|
||||
public static final int preferences = 0x21070008;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,28 +67,28 @@ public class MainActivity extends BaseActivity {
|
||||
encryptMessageButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startEncryptMessageActivity();
|
||||
startActivity(new Intent(MainActivity.this, EncryptMessageActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
decryptMessageButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startDecryptMessageActivity();
|
||||
startActivity(new Intent(MainActivity.this, DecryptMessageActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
encryptFileButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startEncryptFileActivity();
|
||||
startActivity(new Intent(MainActivity.this, EncryptFileActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
decryptFileButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startDecryptFileActivity();
|
||||
startActivity(new Intent(MainActivity.this, DecryptFileActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
@ -105,14 +105,14 @@ public class MainActivity extends BaseActivity {
|
||||
cursor.moveToFirst();
|
||||
int nameIndex = cursor.getColumnIndex(Accounts.NAME);
|
||||
String accountName = cursor.getString(nameIndex);
|
||||
startMailListActivity(accountName);
|
||||
startActivity(new Intent(MainActivity.this, MailListActivity.class)
|
||||
.putExtra("account", accountName));
|
||||
}
|
||||
}
|
||||
});
|
||||
registerForContextMenu(mAccounts);
|
||||
|
||||
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
|
||||
if (!prefs.getBoolean(Constants.pref.has_seen_change_log, false)) {
|
||||
if (!hasSeenChangeLog()) {
|
||||
showDialog(Id.dialog.change_log);
|
||||
}
|
||||
}
|
||||
@ -248,10 +248,7 @@ public class MainActivity extends BaseActivity {
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
MainActivity.this.removeDialog(Id.dialog.change_log);
|
||||
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(Constants.pref.has_seen_change_log, true);
|
||||
editor.commit();
|
||||
setHasSeenChangeLog(true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -268,13 +265,15 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(0, Id.menu.option.manage_public_keys, 0, R.string.menu_managePublicKeys)
|
||||
menu.add(0, Id.menu.option.preferences, 0, R.string.menu_preferences)
|
||||
.setIcon(android.R.drawable.ic_menu_preferences);
|
||||
menu.add(1, Id.menu.option.manage_public_keys, 1, R.string.menu_managePublicKeys)
|
||||
.setIcon(android.R.drawable.ic_menu_manage);
|
||||
menu.add(0, Id.menu.option.manage_secret_keys, 1, R.string.menu_manageSecretKeys)
|
||||
menu.add(1, Id.menu.option.manage_secret_keys, 2, R.string.menu_manageSecretKeys)
|
||||
.setIcon(android.R.drawable.ic_menu_manage);
|
||||
menu.add(1, Id.menu.option.create, 2, R.string.menu_addAccount)
|
||||
menu.add(2, Id.menu.option.create, 3, R.string.menu_addAccount)
|
||||
.setIcon(android.R.drawable.ic_menu_add);
|
||||
menu.add(1, Id.menu.option.about, 3, R.string.menu_about)
|
||||
menu.add(2, Id.menu.option.about, 4, R.string.menu_about)
|
||||
.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
return true;
|
||||
}
|
||||
@ -293,12 +292,17 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
case Id.menu.option.manage_public_keys: {
|
||||
startPublicKeyManager();
|
||||
startActivity(new Intent(this, PublicKeyListActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
case Id.menu.option.manage_secret_keys: {
|
||||
startSecretKeyManager();
|
||||
startActivity(new Intent(this, SecretKeyListActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
case Id.menu.option.preferences: {
|
||||
startActivity(new Intent(this, PreferencesActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -338,33 +342,6 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void startPublicKeyManager() {
|
||||
startActivity(new Intent(this, PublicKeyListActivity.class));
|
||||
}
|
||||
|
||||
public void startSecretKeyManager() {
|
||||
startActivity(new Intent(this, SecretKeyListActivity.class));
|
||||
}
|
||||
|
||||
public void startEncryptMessageActivity() {
|
||||
startActivity(new Intent(this, EncryptMessageActivity.class));
|
||||
}
|
||||
|
||||
public void startDecryptMessageActivity() {
|
||||
startActivity(new Intent(this, DecryptMessageActivity.class));
|
||||
}
|
||||
|
||||
public void startEncryptFileActivity() {
|
||||
startActivity(new Intent(this, EncryptFileActivity.class));
|
||||
}
|
||||
|
||||
public void startDecryptFileActivity() {
|
||||
startActivity(new Intent(this, DecryptFileActivity.class));
|
||||
}
|
||||
|
||||
public void startMailListActivity(String account) {
|
||||
startActivity(new Intent(this, MailListActivity.class).putExtra("account", account));
|
||||
}
|
||||
|
||||
private static class AccountListAdapter extends CursorAdapter {
|
||||
private LayoutInflater minflater;
|
||||
|
124
src/org/thialfihar/android/apg/PreferencesActivity.java
Normal file
124
src/org/thialfihar/android/apg/PreferencesActivity.java
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
|
||||
import org.bouncycastle2.bcpg.HashAlgorithmTags;
|
||||
import org.bouncycastle2.openpgp.PGPEncryptedData;
|
||||
import org.thialfihar.android.apg.utils.Choice;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
|
||||
public class PreferencesActivity extends BaseActivity {
|
||||
private Spinner mEncryptionAlgorithm = null;
|
||||
private Spinner mHashAlgorithm = null;
|
||||
private CheckBox mAsciiArmour = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.preferences);
|
||||
|
||||
mEncryptionAlgorithm = (Spinner) findViewById(R.id.encryption_algorithm);
|
||||
mHashAlgorithm = (Spinner) findViewById(R.id.hash_algorithm);
|
||||
mAsciiArmour = (CheckBox) findViewById(R.id.ascii_armour);
|
||||
|
||||
mAsciiArmour.setChecked(getDefaultAsciiArmour());
|
||||
|
||||
Choice choices[] = {
|
||||
new Choice(PGPEncryptedData.AES_128, "AES 128"),
|
||||
new Choice(PGPEncryptedData.AES_192, "AES 192"),
|
||||
new Choice(PGPEncryptedData.AES_256, "AES 256"),
|
||||
new Choice(PGPEncryptedData.BLOWFISH, "Blowfish"),
|
||||
new Choice(PGPEncryptedData.TWOFISH, "Twofish"),
|
||||
new Choice(PGPEncryptedData.CAST5, "CAST5"),
|
||||
new Choice(PGPEncryptedData.DES, "DES"),
|
||||
new Choice(PGPEncryptedData.TRIPLE_DES, "Triple DES"),
|
||||
new Choice(PGPEncryptedData.IDEA, "IDEA"),
|
||||
};
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mEncryptionAlgorithm.setAdapter(adapter);
|
||||
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == getDefaultEncryptionAlgorithm()) {
|
||||
mEncryptionAlgorithm.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mEncryptionAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
||||
setDefaultEncryptionAlgorithm(((Choice) mEncryptionAlgorithm.getSelectedItem()).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapter) {
|
||||
// nothing to do
|
||||
}
|
||||
});
|
||||
|
||||
Choice choices2[] = {
|
||||
new Choice(HashAlgorithmTags.MD5, "MD5"),
|
||||
new Choice(HashAlgorithmTags.RIPEMD160, "RIPEMD160"),
|
||||
new Choice(HashAlgorithmTags.SHA1, "SHA1"),
|
||||
new Choice(HashAlgorithmTags.SHA224, "SHA224"),
|
||||
new Choice(HashAlgorithmTags.SHA256, "SHA256"),
|
||||
new Choice(HashAlgorithmTags.SHA384, "SHA384"),
|
||||
new Choice(HashAlgorithmTags.SHA512, "SHA512"),
|
||||
};
|
||||
adapter = new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices2);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mHashAlgorithm.setAdapter(adapter);
|
||||
|
||||
for (int i = 0; i < choices2.length; ++i) {
|
||||
if (choices2[i].getId() == getDefaultHashAlgorithm()) {
|
||||
mHashAlgorithm.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mHashAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
||||
setDefaultHashAlgorithm(((Choice) mHashAlgorithm.getSelectedItem()).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapter) {
|
||||
// nothing to do
|
||||
}
|
||||
});
|
||||
|
||||
mAsciiArmour.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setDefaultAsciiArmour(mAsciiArmour.isChecked());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user