2010-07-16 16:13:12 -04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-04-14 10:18:06 -04:00
|
|
|
package org.thialfihar.android.apg.ui;
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2011-11-03 17:15:31 -04:00
|
|
|
import org.spongycastle.bcpg.HashAlgorithmTags;
|
|
|
|
import org.spongycastle.openpgp.PGPEncryptedData;
|
2012-04-14 10:18:06 -04:00
|
|
|
import org.thialfihar.android.apg.Constants;
|
|
|
|
import org.thialfihar.android.apg.Id;
|
2012-06-20 08:27:45 -04:00
|
|
|
import org.thialfihar.android.apg.helper.Preferences;
|
2012-04-14 10:18:06 -04:00
|
|
|
import org.thialfihar.android.apg.ui.widget.IntegerListPreference;
|
|
|
|
import org.thialfihar.android.apg.R;
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-11 19:12:19 -04:00
|
|
|
import com.actionbarsherlock.app.ActionBar;
|
|
|
|
import com.actionbarsherlock.app.SherlockPreferenceActivity;
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
|
|
|
|
2010-08-17 17:49:34 -04:00
|
|
|
import android.content.Intent;
|
2010-07-16 16:13:12 -04:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.CheckBoxPreference;
|
|
|
|
import android.preference.Preference;
|
2010-08-17 17:49:34 -04:00
|
|
|
import android.preference.PreferenceScreen;
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-11 19:12:19 -04:00
|
|
|
public class PreferencesActivity extends SherlockPreferenceActivity {
|
2010-07-16 16:13:12 -04:00
|
|
|
private IntegerListPreference mPassPhraseCacheTtl = null;
|
|
|
|
private IntegerListPreference mEncryptionAlgorithm = null;
|
|
|
|
private IntegerListPreference mHashAlgorithm = null;
|
|
|
|
private IntegerListPreference mMessageCompression = null;
|
|
|
|
private IntegerListPreference mFileCompression = null;
|
|
|
|
private CheckBoxPreference mAsciiArmour = null;
|
2010-07-27 18:41:50 -04:00
|
|
|
private CheckBoxPreference mForceV3Signatures = null;
|
2010-08-17 17:49:34 -04:00
|
|
|
private PreferenceScreen mKeyServerPreference = null;
|
2010-07-16 16:13:12 -04:00
|
|
|
private Preferences mPreferences;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
mPreferences = Preferences.getPreferences(this);
|
2010-07-18 03:19:57 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-11 19:12:19 -04:00
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
2012-06-20 07:49:57 -04:00
|
|
|
actionBar.setHomeButtonEnabled(true);
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-11 19:12:19 -04:00
|
|
|
addPreferencesFromResource(R.xml.apg_preferences);
|
2010-07-18 03:19:57 -04:00
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mPassPhraseCacheTtl = (IntegerListPreference) findPreference(Constants.pref.PASS_PHRASE_CACHE_TTL);
|
2010-07-16 16:13:12 -04:00
|
|
|
mPassPhraseCacheTtl.setValue("" + mPreferences.getPassPhraseCacheTtl());
|
|
|
|
mPassPhraseCacheTtl.setSummary(mPassPhraseCacheTtl.getEntry());
|
2012-03-11 19:12:19 -04:00
|
|
|
mPassPhraseCacheTtl
|
|
|
|
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
mPassPhraseCacheTtl.setValue(newValue.toString());
|
|
|
|
mPassPhraseCacheTtl.setSummary(mPassPhraseCacheTtl.getEntry());
|
|
|
|
mPreferences.setPassPhraseCacheTtl(Integer.parseInt(newValue.toString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mEncryptionAlgorithm = (IntegerListPreference) findPreference(Constants.pref.DEFAULT_ENCRYPTION_ALGORITHM);
|
2012-03-11 19:12:19 -04:00
|
|
|
int valueIds[] = { PGPEncryptedData.AES_128, PGPEncryptedData.AES_192,
|
|
|
|
PGPEncryptedData.AES_256, PGPEncryptedData.BLOWFISH, PGPEncryptedData.TWOFISH,
|
|
|
|
PGPEncryptedData.CAST5, PGPEncryptedData.DES, PGPEncryptedData.TRIPLE_DES,
|
|
|
|
PGPEncryptedData.IDEA, };
|
|
|
|
String entries[] = { "AES-128", "AES-192", "AES-256", "Blowfish", "Twofish", "CAST5",
|
|
|
|
"DES", "Triple DES", "IDEA", };
|
2010-07-16 16:13:12 -04:00
|
|
|
String values[] = new String[valueIds.length];
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
values[i] = "" + valueIds[i];
|
|
|
|
}
|
|
|
|
mEncryptionAlgorithm.setEntries(entries);
|
|
|
|
mEncryptionAlgorithm.setEntryValues(values);
|
|
|
|
mEncryptionAlgorithm.setValue("" + mPreferences.getDefaultEncryptionAlgorithm());
|
|
|
|
mEncryptionAlgorithm.setSummary(mEncryptionAlgorithm.getEntry());
|
2012-03-11 19:12:19 -04:00
|
|
|
mEncryptionAlgorithm
|
|
|
|
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
mEncryptionAlgorithm.setValue(newValue.toString());
|
|
|
|
mEncryptionAlgorithm.setSummary(mEncryptionAlgorithm.getEntry());
|
|
|
|
mPreferences.setDefaultEncryptionAlgorithm(Integer.parseInt(newValue
|
|
|
|
.toString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mHashAlgorithm = (IntegerListPreference) findPreference(Constants.pref.DEFAULT_HASH_ALGORITHM);
|
2012-03-11 19:12:19 -04:00
|
|
|
valueIds = new int[] { HashAlgorithmTags.MD5, HashAlgorithmTags.RIPEMD160,
|
|
|
|
HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA224, HashAlgorithmTags.SHA256,
|
|
|
|
HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, };
|
|
|
|
entries = new String[] { "MD5", "RIPEMD-160", "SHA-1", "SHA-224", "SHA-256", "SHA-384",
|
|
|
|
"SHA-512", };
|
2010-07-16 16:13:12 -04:00
|
|
|
values = new String[valueIds.length];
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
values[i] = "" + valueIds[i];
|
|
|
|
}
|
|
|
|
mHashAlgorithm.setEntries(entries);
|
|
|
|
mHashAlgorithm.setEntryValues(values);
|
|
|
|
mHashAlgorithm.setValue("" + mPreferences.getDefaultHashAlgorithm());
|
|
|
|
mHashAlgorithm.setSummary(mHashAlgorithm.getEntry());
|
2012-03-11 19:12:19 -04:00
|
|
|
mHashAlgorithm.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2010-07-16 16:13:12 -04:00
|
|
|
mHashAlgorithm.setValue(newValue.toString());
|
|
|
|
mHashAlgorithm.setSummary(mHashAlgorithm.getEntry());
|
|
|
|
mPreferences.setDefaultHashAlgorithm(Integer.parseInt(newValue.toString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mMessageCompression = (IntegerListPreference) findPreference(Constants.pref.DEFAULT_MESSAGE_COMPRESSION);
|
2012-03-11 19:12:19 -04:00
|
|
|
valueIds = new int[] { Id.choice.compression.none, Id.choice.compression.zip,
|
|
|
|
Id.choice.compression.zlib, Id.choice.compression.bzip2, };
|
2010-07-16 16:13:12 -04:00
|
|
|
entries = new String[] {
|
|
|
|
getString(R.string.choice_none) + " (" + getString(R.string.fast) + ")",
|
|
|
|
"ZIP (" + getString(R.string.fast) + ")",
|
|
|
|
"ZLIB (" + getString(R.string.fast) + ")",
|
2012-03-11 19:12:19 -04:00
|
|
|
"BZIP2 (" + getString(R.string.very_slow) + ")", };
|
2010-07-16 16:13:12 -04:00
|
|
|
values = new String[valueIds.length];
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
values[i] = "" + valueIds[i];
|
|
|
|
}
|
|
|
|
mMessageCompression.setEntries(entries);
|
|
|
|
mMessageCompression.setEntryValues(values);
|
|
|
|
mMessageCompression.setValue("" + mPreferences.getDefaultMessageCompression());
|
|
|
|
mMessageCompression.setSummary(mMessageCompression.getEntry());
|
2012-03-11 19:12:19 -04:00
|
|
|
mMessageCompression
|
|
|
|
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
mMessageCompression.setValue(newValue.toString());
|
|
|
|
mMessageCompression.setSummary(mMessageCompression.getEntry());
|
|
|
|
mPreferences.setDefaultMessageCompression(Integer.parseInt(newValue
|
|
|
|
.toString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-07-16 16:13:12 -04:00
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mFileCompression = (IntegerListPreference) findPreference(Constants.pref.DEFAULT_FILE_COMPRESSION);
|
2010-07-16 16:13:12 -04:00
|
|
|
mFileCompression.setEntries(entries);
|
|
|
|
mFileCompression.setEntryValues(values);
|
|
|
|
mFileCompression.setValue("" + mPreferences.getDefaultFileCompression());
|
|
|
|
mFileCompression.setSummary(mFileCompression.getEntry());
|
2012-03-11 19:12:19 -04:00
|
|
|
mFileCompression.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2010-07-16 16:13:12 -04:00
|
|
|
mFileCompression.setValue(newValue.toString());
|
|
|
|
mFileCompression.setSummary(mFileCompression.getEntry());
|
|
|
|
mPreferences.setDefaultFileCompression(Integer.parseInt(newValue.toString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mAsciiArmour = (CheckBoxPreference) findPreference(Constants.pref.DEFAULT_ASCII_ARMOUR);
|
2010-07-16 16:13:12 -04:00
|
|
|
mAsciiArmour.setChecked(mPreferences.getDefaultAsciiArmour());
|
2012-03-11 19:12:19 -04:00
|
|
|
mAsciiArmour.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
mAsciiArmour.setChecked((Boolean) newValue);
|
|
|
|
mPreferences.setDefaultAsciiArmour((Boolean) newValue);
|
2010-07-16 16:13:12 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-07-27 18:41:50 -04:00
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mForceV3Signatures = (CheckBoxPreference) findPreference(Constants.pref.FORCE_V3_SIGNATURES);
|
2010-07-27 18:41:50 -04:00
|
|
|
mForceV3Signatures.setChecked(mPreferences.getForceV3Signatures());
|
2012-03-11 19:12:19 -04:00
|
|
|
mForceV3Signatures
|
|
|
|
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
mForceV3Signatures.setChecked((Boolean) newValue);
|
|
|
|
mPreferences.setForceV3Signatures((Boolean) newValue);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-08-17 17:49:34 -04:00
|
|
|
|
2012-03-09 12:43:10 -05:00
|
|
|
mKeyServerPreference = (PreferenceScreen) findPreference(Constants.pref.KEY_SERVERS);
|
2010-08-17 17:49:34 -04:00
|
|
|
String servers[] = mPreferences.getKeyServers();
|
2012-03-11 19:12:19 -04:00
|
|
|
mKeyServerPreference.setSummary(getResources().getString(R.string.nKeyServers,
|
|
|
|
servers.length));
|
|
|
|
mKeyServerPreference
|
|
|
|
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent intent = new Intent(PreferencesActivity.this,
|
2012-06-20 07:49:57 -04:00
|
|
|
PreferencesKeyServerActivity.class);
|
2012-06-20 08:55:36 -04:00
|
|
|
intent.putExtra(PreferencesKeyServerActivity.EXTRA_KEY_SERVERS,
|
|
|
|
mPreferences.getKeyServers());
|
2012-03-11 19:12:19 -04:00
|
|
|
startActivityForResult(intent, Id.request.key_server_preference);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-08-17 17:49:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
switch (requestCode) {
|
2012-03-11 19:12:19 -04:00
|
|
|
case Id.request.key_server_preference: {
|
|
|
|
if (resultCode == RESULT_CANCELED || data == null) {
|
|
|
|
return;
|
2010-08-17 17:49:34 -04:00
|
|
|
}
|
2012-06-20 08:55:36 -04:00
|
|
|
String servers[] = data
|
|
|
|
.getStringArrayExtra(PreferencesKeyServerActivity.EXTRA_KEY_SERVERS);
|
2012-03-11 19:12:19 -04:00
|
|
|
mPreferences.setKeyServers(servers);
|
|
|
|
mKeyServerPreference.setSummary(getResources().getString(R.string.nKeyServers,
|
|
|
|
servers.length));
|
|
|
|
break;
|
|
|
|
}
|
2010-08-17 17:49:34 -04:00
|
|
|
|
2012-03-11 19:12:19 -04:00
|
|
|
default: {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-17 17:49:34 -04:00
|
|
|
}
|
2010-07-16 16:13:12 -04:00
|
|
|
}
|
|
|
|
|
2012-03-11 19:12:19 -04:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
|
|
|
case android.R.id.home:
|
2012-06-20 07:49:57 -04:00
|
|
|
// app icon in Action Bar clicked; go home
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
2012-03-11 19:12:19 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|