diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/thialfihar/android/apg/BaseActivity.java | 20 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/Constants.java | 1 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/MailListActivity.java | 3 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/Preferences.java | 10 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/PreferencesActivity.java | 39 |
5 files changed, 71 insertions, 2 deletions
diff --git a/src/org/thialfihar/android/apg/BaseActivity.java b/src/org/thialfihar/android/apg/BaseActivity.java index 17fe3b0c8..4a0360b25 100644 --- a/src/org/thialfihar/android/apg/BaseActivity.java +++ b/src/org/thialfihar/android/apg/BaseActivity.java @@ -17,6 +17,7 @@ package org.thialfihar.android.apg; import java.io.File; +import java.util.Locale; import android.app.Activity; import android.app.AlertDialog; @@ -25,6 +26,7 @@ import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.res.Configuration; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -60,6 +62,7 @@ public class BaseActivity extends Activity super.onCreate(savedInstanceState); mPreferences = Preferences.getPreferences(this); + setLanguage(this, mPreferences.getLanguage()); Apg.initialize(this); @@ -378,4 +381,21 @@ public class BaseActivity extends Activity protected String getDeleteFile() { return mDeleteFile; } + + public static void setLanguage(Context context, String language) + { + Locale locale; + if (language == null || language.equals("")) + { + locale = Locale.getDefault(); + } + else + { + locale = new Locale(language); + } + Configuration config = new Configuration(); + config.locale = locale; + context.getResources().updateConfiguration(config, + context.getResources().getDisplayMetrics()); + } } diff --git a/src/org/thialfihar/android/apg/Constants.java b/src/org/thialfihar/android/apg/Constants.java index 4e818b0b9..0a819a509 100644 --- a/src/org/thialfihar/android/apg/Constants.java +++ b/src/org/thialfihar/android/apg/Constants.java @@ -31,5 +31,6 @@ public final class Constants { public static final String default_message_compression = "defaultMessageCompression"; public static final String default_file_compression = "defaultFileCompression"; public static final String pass_phrase_cache_ttl = "passPhraseCacheTtl"; + public static final String language = "language"; } } diff --git a/src/org/thialfihar/android/apg/MailListActivity.java b/src/org/thialfihar/android/apg/MailListActivity.java index c4de68e91..2becaad3c 100644 --- a/src/org/thialfihar/android/apg/MailListActivity.java +++ b/src/org/thialfihar/android/apg/MailListActivity.java @@ -80,6 +80,9 @@ public class MailListActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { + Preferences prefs = Preferences.getPreferences(this); + BaseActivity.setLanguage(this, prefs.getLanguage()); + super.onCreate(savedInstanceState); mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); diff --git a/src/org/thialfihar/android/apg/Preferences.java b/src/org/thialfihar/android/apg/Preferences.java index 50489dc89..cf5470f2a 100644 --- a/src/org/thialfihar/android/apg/Preferences.java +++ b/src/org/thialfihar/android/apg/Preferences.java @@ -23,6 +23,16 @@ public class Preferences { mSharedPreferences = context.getSharedPreferences("APG.main", Context.MODE_PRIVATE); } + public String getLanguage() { + return mSharedPreferences.getString(Constants.pref.language, ""); + } + + public void setLanguage(String value) { + SharedPreferences.Editor editor = mSharedPreferences.edit(); + editor.putString(Constants.pref.language, value); + editor.commit(); + } + public int getPassPhraseCacheTtl() { int ttl = mSharedPreferences.getInt(Constants.pref.pass_phrase_cache_ttl, 180); // fix the value if it was set to "never" in previous versions, which currently is not diff --git a/src/org/thialfihar/android/apg/PreferencesActivity.java b/src/org/thialfihar/android/apg/PreferencesActivity.java index c8778c780..6e7e6f657 100644 --- a/src/org/thialfihar/android/apg/PreferencesActivity.java +++ b/src/org/thialfihar/android/apg/PreferencesActivity.java @@ -16,15 +16,21 @@ package org.thialfihar.android.apg; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Vector; + import org.bouncycastle2.bcpg.HashAlgorithmTags; import org.bouncycastle2.openpgp.PGPEncryptedData; import android.os.Bundle; import android.preference.CheckBoxPreference; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity { + private ListPreference mLanguage = null; private IntegerListPreference mPassPhraseCacheTtl = null; private IntegerListPreference mEncryptionAlgorithm = null; private IntegerListPreference mHashAlgorithm = null; @@ -35,12 +41,41 @@ public class PreferencesActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mPreferences = Preferences.getPreferences(this); + BaseActivity.setLanguage(this, mPreferences.getLanguage()); + super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.apg_preferences); + mLanguage = (ListPreference) findPreference(Constants.pref.language); + Vector<CharSequence> entryVector = new Vector<CharSequence>(Arrays.asList(mLanguage.getEntries())); + Vector<CharSequence> entryValueVector = new Vector<CharSequence>(Arrays.asList(mLanguage.getEntryValues())); + String supportedLanguages[] = getResources().getStringArray(R.array.supported_languages); + HashSet<String> supportedLanguageSet = new HashSet<String>(Arrays.asList(supportedLanguages)); + for (int i = entryVector.size() - 1; i > -1; --i) + { + if (!supportedLanguageSet.contains(entryValueVector.get(i))) + { + entryVector.remove(i); + entryValueVector.remove(i); + } + } + CharSequence dummy[] = new CharSequence[0]; + mLanguage.setEntries(entryVector.toArray(dummy)); + mLanguage.setEntryValues(entryValueVector.toArray(dummy)); + mLanguage.setValue(mPreferences.getLanguage()); + mLanguage.setSummary(mLanguage.getEntry()); + mLanguage.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() + { + public boolean onPreferenceChange(Preference preference, Object newValue) + { + mLanguage.setValue(newValue.toString()); + mLanguage.setSummary(mLanguage.getEntry()); + mPreferences.setLanguage(newValue.toString()); + return false; + } + }); + mPassPhraseCacheTtl = (IntegerListPreference) findPreference(Constants.pref.pass_phrase_cache_ttl); mPassPhraseCacheTtl.setValue("" + mPreferences.getPassPhraseCacheTtl()); mPassPhraseCacheTtl.setSummary(mPassPhraseCacheTtl.getEntry()); |