2010-04-28 19:35:11 -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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.thialfihar.android.apg;
|
|
|
|
|
|
|
|
import org.bouncycastle2.bcpg.HashAlgorithmTags;
|
|
|
|
import org.bouncycastle2.openpgp.PGPEncryptedData;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
2010-06-17 09:23:07 -04:00
|
|
|
import android.preference.CheckBoxPreference;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
|
|
|
|
public class PreferencesActivity extends PreferenceActivity {
|
|
|
|
private IntegerListPreference mPassPhraseCacheTtl = null;
|
|
|
|
private IntegerListPreference mEncryptionAlgorithm = null;
|
|
|
|
private IntegerListPreference mHashAlgorithm = null;
|
|
|
|
private IntegerListPreference mMessageCompression = null;
|
|
|
|
private IntegerListPreference mFileCompression = null;
|
|
|
|
private CheckBoxPreference mAsciiArmour = null;
|
|
|
|
private Preferences mPreferences;
|
2010-04-28 19:35:11 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2010-05-15 12:09:49 -04:00
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mPreferences = Preferences.getPreferences(this);
|
2010-05-15 12:09:49 -04:00
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
addPreferencesFromResource(R.xml.apg_preferences);
|
2010-05-15 12:09:49 -04:00
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mPassPhraseCacheTtl = (IntegerListPreference) findPreference(Constants.pref.pass_phrase_cache_ttl);
|
|
|
|
mPassPhraseCacheTtl.setValue("" + mPreferences.getPassPhraseCacheTtl());
|
|
|
|
mPassPhraseCacheTtl.setSummary(mPassPhraseCacheTtl.getEntry());
|
|
|
|
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()));
|
|
|
|
BaseActivity.startCacheService(PreferencesActivity.this, mPreferences);
|
|
|
|
return false;
|
2010-05-15 12:09:49 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mEncryptionAlgorithm = (IntegerListPreference) findPreference(Constants.pref.default_encryption_algorithm);
|
|
|
|
int valueIds[] = {
|
|
|
|
PGPEncryptedData.AES_128, PGPEncryptedData.AES_192, PGPEncryptedData.AES_256,
|
|
|
|
PGPEncryptedData.BLOWFISH, PGPEncryptedData.TWOFISH, PGPEncryptedData.CAST5,
|
|
|
|
PGPEncryptedData.DES, PGPEncryptedData.TRIPLE_DES, PGPEncryptedData.IDEA,
|
2010-04-28 19:35:11 -04:00
|
|
|
};
|
2010-06-17 09:23:07 -04:00
|
|
|
String entries[] = {
|
|
|
|
"AES-128", "AES-192", "AES-256",
|
|
|
|
"Blowfish", "Twofish", "CAST5",
|
|
|
|
"DES", "Triple DES", "IDEA",
|
2010-04-28 19:35:11 -04:00
|
|
|
};
|
2010-06-17 09:23:07 -04:00
|
|
|
String values[] = new String[valueIds.length];
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
values[i] = "" + valueIds[i];
|
2010-04-28 19:35:11 -04:00
|
|
|
}
|
2010-06-17 09:23:07 -04:00
|
|
|
mEncryptionAlgorithm.setEntries(entries);
|
|
|
|
mEncryptionAlgorithm.setEntryValues(values);
|
|
|
|
mEncryptionAlgorithm.setValue("" + mPreferences.getDefaultEncryptionAlgorithm());
|
|
|
|
mEncryptionAlgorithm.setSummary(mEncryptionAlgorithm.getEntry());
|
|
|
|
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-04-28 19:35:11 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mHashAlgorithm = (IntegerListPreference) findPreference(Constants.pref.default_hash_algorithm);
|
|
|
|
valueIds = new int[] {
|
|
|
|
HashAlgorithmTags.MD5, HashAlgorithmTags.RIPEMD160, HashAlgorithmTags.SHA1,
|
|
|
|
HashAlgorithmTags.SHA224, HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA384,
|
|
|
|
HashAlgorithmTags.SHA512,
|
2010-05-16 10:20:17 -04:00
|
|
|
};
|
2010-06-17 09:23:07 -04:00
|
|
|
entries = new String[] {
|
|
|
|
"MD5", "RIPEMD-160", "SHA-1",
|
|
|
|
"SHA-224", "SHA-256", "SHA-384",
|
|
|
|
"SHA-512",
|
|
|
|
};
|
|
|
|
values = new String[valueIds.length];
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
values[i] = "" + valueIds[i];
|
2010-05-16 10:20:17 -04:00
|
|
|
}
|
2010-06-17 09:23:07 -04:00
|
|
|
mHashAlgorithm.setEntries(entries);
|
|
|
|
mHashAlgorithm.setEntryValues(values);
|
|
|
|
mHashAlgorithm.setValue("" + mPreferences.getDefaultHashAlgorithm());
|
|
|
|
mHashAlgorithm.setSummary(mHashAlgorithm.getEntry());
|
|
|
|
mHashAlgorithm.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
|
|
|
|
{
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue)
|
|
|
|
{
|
|
|
|
mHashAlgorithm.setValue(newValue.toString());
|
|
|
|
mHashAlgorithm.setSummary(mHashAlgorithm.getEntry());
|
|
|
|
mPreferences.setDefaultHashAlgorithm(Integer.parseInt(newValue.toString()));
|
|
|
|
return false;
|
2010-05-16 10:20:17 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mMessageCompression = (IntegerListPreference) findPreference(Constants.pref.default_message_compression);
|
|
|
|
valueIds = new int[] {
|
2010-07-05 09:22:03 -04:00
|
|
|
Id.choice.compression.none,
|
|
|
|
Id.choice.compression.zip,
|
|
|
|
Id.choice.compression.zlib,
|
|
|
|
Id.choice.compression.bzip2,
|
2010-05-16 10:20:17 -04:00
|
|
|
};
|
2010-06-17 09:23:07 -04:00
|
|
|
entries = new String[] {
|
2010-07-05 09:22:03 -04:00
|
|
|
getString(R.string.choice_none) + " (" + getString(R.string.fast) + ")",
|
|
|
|
"ZIP (" + getString(R.string.fast) + ")",
|
|
|
|
"ZLIB (" + getString(R.string.fast) + ")",
|
|
|
|
"BZIP2 (" + getString(R.string.very_slow) + ")",
|
2010-06-17 09:23:07 -04:00
|
|
|
};
|
|
|
|
values = new String[valueIds.length];
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
values[i] = "" + valueIds[i];
|
2010-05-16 10:20:17 -04:00
|
|
|
}
|
2010-06-17 09:23:07 -04:00
|
|
|
mMessageCompression.setEntries(entries);
|
|
|
|
mMessageCompression.setEntryValues(values);
|
|
|
|
mMessageCompression.setValue("" + mPreferences.getDefaultMessageCompression());
|
|
|
|
mMessageCompression.setSummary(mMessageCompression.getEntry());
|
|
|
|
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-05-16 10:20:17 -04:00
|
|
|
}
|
2010-06-17 09:23:07 -04:00
|
|
|
});
|
2010-05-16 10:20:17 -04:00
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mFileCompression = (IntegerListPreference) findPreference(Constants.pref.default_file_compression);
|
|
|
|
mFileCompression.setEntries(entries);
|
|
|
|
mFileCompression.setEntryValues(values);
|
|
|
|
mFileCompression.setValue("" + mPreferences.getDefaultFileCompression());
|
|
|
|
mFileCompression.setSummary(mFileCompression.getEntry());
|
|
|
|
mFileCompression.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
|
|
|
|
{
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue)
|
|
|
|
{
|
|
|
|
mFileCompression.setValue(newValue.toString());
|
|
|
|
mFileCompression.setSummary(mFileCompression.getEntry());
|
|
|
|
mPreferences.setDefaultFileCompression(Integer.parseInt(newValue.toString()));
|
|
|
|
return false;
|
2010-05-16 10:20:17 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
mAsciiArmour = (CheckBoxPreference) findPreference(Constants.pref.default_ascii_armour);
|
|
|
|
mAsciiArmour.setChecked(mPreferences.getDefaultAsciiArmour());
|
|
|
|
mAsciiArmour.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
|
|
|
|
{
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue)
|
|
|
|
{
|
|
|
|
mAsciiArmour.setChecked((Boolean)newValue);
|
|
|
|
mPreferences.setDefaultAsciiArmour((Boolean)newValue);
|
|
|
|
return false;
|
2010-04-28 19:35:11 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|