2012-03-09 10:27:29 -05:00
|
|
|
package org.apg;
|
2010-06-17 09:23:07 -04:00
|
|
|
|
2011-11-03 17:15:31 -04:00
|
|
|
import org.spongycastle.bcpg.HashAlgorithmTags;
|
|
|
|
import org.spongycastle.openpgp.PGPEncryptedData;
|
2010-06-17 09:23:07 -04:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
2011-11-03 17:15:31 -04:00
|
|
|
import java.util.Vector;
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
public class Preferences {
|
|
|
|
private static Preferences mPreferences;
|
|
|
|
private SharedPreferences mSharedPreferences;
|
|
|
|
|
2010-12-30 08:39:46 -05:00
|
|
|
public static synchronized Preferences getPreferences(Context context) {
|
|
|
|
return getPreferences(context, false);
|
|
|
|
}
|
2012-03-09 10:27:29 -05:00
|
|
|
|
|
|
|
public static synchronized Preferences getPreferences(Context context, boolean force_new) {
|
2010-12-30 08:39:46 -05:00
|
|
|
if (mPreferences == null || force_new) {
|
2010-06-17 09:23:07 -04:00
|
|
|
mPreferences = new Preferences(context);
|
|
|
|
}
|
|
|
|
return mPreferences;
|
|
|
|
}
|
|
|
|
|
2012-03-09 10:27:29 -05:00
|
|
|
private Preferences(Context context) {
|
2010-06-17 09:23:07 -04:00
|
|
|
mSharedPreferences = context.getSharedPreferences("APG.main", Context.MODE_PRIVATE);
|
|
|
|
}
|
|
|
|
|
2010-07-18 03:19:57 -04:00
|
|
|
public String getLanguage() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getString(Constants.pref.LANGUAGE, "");
|
2010-07-18 03:19:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setLanguage(String value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putString(Constants.pref.LANGUAGE, value);
|
2010-07-18 03:19:57 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
public int getPassPhraseCacheTtl() {
|
2012-03-09 12:43:10 -05:00
|
|
|
int ttl = mSharedPreferences.getInt(Constants.pref.PASS_PHRASE_CACHE_TTL, 180);
|
2010-06-17 09:23:07 -04:00
|
|
|
// fix the value if it was set to "never" in previous versions, which currently is not
|
|
|
|
// supported
|
|
|
|
if (ttl == 0) {
|
|
|
|
ttl = 180;
|
|
|
|
}
|
|
|
|
return ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPassPhraseCacheTtl(int value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putInt(Constants.pref.PASS_PHRASE_CACHE_TTL, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDefaultEncryptionAlgorithm() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getInt(Constants.pref.DEFAULT_ENCRYPTION_ALGORITHM,
|
2012-03-09 10:27:29 -05:00
|
|
|
PGPEncryptedData.AES_256);
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultEncryptionAlgorithm(int value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putInt(Constants.pref.DEFAULT_ENCRYPTION_ALGORITHM, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDefaultHashAlgorithm() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getInt(Constants.pref.DEFAULT_HASH_ALGORITHM,
|
2012-03-09 10:27:29 -05:00
|
|
|
HashAlgorithmTags.SHA256);
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultHashAlgorithm(int value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putInt(Constants.pref.DEFAULT_HASH_ALGORITHM, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDefaultMessageCompression() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getInt(Constants.pref.DEFAULT_MESSAGE_COMPRESSION,
|
2012-03-09 10:27:29 -05:00
|
|
|
Id.choice.compression.zlib);
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultMessageCompression(int value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putInt(Constants.pref.DEFAULT_MESSAGE_COMPRESSION, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDefaultFileCompression() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getInt(Constants.pref.DEFAULT_FILE_COMPRESSION,
|
2012-03-09 10:27:29 -05:00
|
|
|
Id.choice.compression.none);
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultFileCompression(int value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putInt(Constants.pref.DEFAULT_FILE_COMPRESSION, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getDefaultAsciiArmour() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getBoolean(Constants.pref.DEFAULT_ASCII_ARMOUR, false);
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultAsciiArmour(boolean value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putBoolean(Constants.pref.DEFAULT_ASCII_ARMOUR, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2010-07-27 18:41:50 -04:00
|
|
|
public boolean getForceV3Signatures() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getBoolean(Constants.pref.FORCE_V3_SIGNATURES, false);
|
2010-07-27 18:41:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setForceV3Signatures(boolean value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putBoolean(Constants.pref.FORCE_V3_SIGNATURES, value);
|
2010-07-27 18:41:50 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2010-06-17 09:23:07 -04:00
|
|
|
public boolean hasSeenChangeLog(String version) {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getBoolean(Constants.pref.HAS_SEEN_CHANGE_LOG + version, false);
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setHasSeenChangeLog(String version, boolean value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putBoolean(Constants.pref.HAS_SEEN_CHANGE_LOG + version, value);
|
2010-06-17 09:23:07 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
2010-07-24 12:30:38 -04:00
|
|
|
|
|
|
|
public boolean hasSeenHelp() {
|
2012-03-09 12:43:10 -05:00
|
|
|
return mSharedPreferences.getBoolean(Constants.pref.HAS_SEEN_HELP, false);
|
2010-07-24 12:30:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setHasSeenHelp(boolean value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putBoolean(Constants.pref.HAS_SEEN_HELP, value);
|
2010-07-24 12:30:38 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
2010-08-17 17:49:34 -04:00
|
|
|
|
|
|
|
public String[] getKeyServers() {
|
2012-03-09 12:43:10 -05:00
|
|
|
String rawData = mSharedPreferences.getString(Constants.pref.KEY_SERVERS,
|
|
|
|
Constants.defaults.KEY_SERVERS);
|
2010-08-17 17:49:34 -04:00
|
|
|
Vector<String> servers = new Vector<String>();
|
|
|
|
String chunks[] = rawData.split(",");
|
|
|
|
for (int i = 0; i < chunks.length; ++i) {
|
|
|
|
String tmp = chunks[i].trim();
|
|
|
|
if (tmp.length() > 0) {
|
|
|
|
servers.add(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return servers.toArray(chunks);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setKeyServers(String[] value) {
|
|
|
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
|
|
|
String rawData = "";
|
|
|
|
for (int i = 0; i < value.length; ++i) {
|
|
|
|
String tmp = value[i].trim();
|
|
|
|
if (tmp.length() == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!"".equals(rawData)) {
|
|
|
|
rawData += ",";
|
|
|
|
}
|
|
|
|
rawData += tmp;
|
|
|
|
}
|
2012-03-09 12:43:10 -05:00
|
|
|
editor.putString(Constants.pref.KEY_SERVERS, rawData);
|
2010-08-17 17:49:34 -04:00
|
|
|
editor.commit();
|
|
|
|
}
|
2010-06-17 09:23:07 -04:00
|
|
|
}
|