diff options
Diffstat (limited to 'OpenKeychain/src')
6 files changed, 75 insertions, 15 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java index 048fbf327..045ef347c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java @@ -98,12 +98,7 @@ public final class Constants { public static final String USE_TOR_PROXY = "useTorProxy"; public static final String PROXY_HOST = "proxyHost"; public static final String PROXY_PORT = "proxyPort"; - } - - public static final class ProxyOrbot { - public static final String PROXY_HOST = "127.0.0.1"; - public static final int PROXY_HTTP_PORT = 8118; - public static final int PROXY_SOCKS_PORT = 9050; + public static final String PROXY_TYPE = "proxyType"; } public static final class Defaults { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index a49eb731d..383a542ff 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -217,6 +217,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { private CheckBoxPreference mUseNormalProxy; private EditTextPreference mProxyHost; private EditTextPreference mProxyPort; + private ListPreference mProxyType; @Override public void onCreate(Bundle savedInstanceState) { @@ -229,10 +230,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity { mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY); mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST); mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT); + mProxyType = (ListPreference) findPreference(Constants.Pref.PROXY_TYPE); initializeUseTorPref(); initializeUseNormalProxyPref(); - initialiseEditTextPreferences(); + initializeEditTextPreferences(); + initializeProxyTypePreference(); if (mUseTor.isChecked()) disableNormalProxyPrefs(); else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); @@ -279,7 +282,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); } - private void initialiseEditTextPreferences() { + private void initializeEditTextPreferences() { mProxyHost.setSummary(mProxyHost.getText()); mProxyPort.setSummary(mProxyPort.getText()); @@ -328,17 +331,32 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); } + private void initializeProxyTypePreference() { + mProxyType.setSummary(mProxyType.getEntry()); + + mProxyType.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + CharSequence entry = mProxyType.getEntries()[mProxyType.findIndexOfValue((String) newValue)]; + mProxyType.setSummary(entry); + return true; + } + }); + } + private void disableNormalProxyPrefs() { mUseNormalProxy.setChecked(false); mUseNormalProxy.setEnabled(false); mProxyHost.setEnabled(false); mProxyPort.setEnabled(false); + mProxyType.setEnabled(false); } private void enableNormalProxyPrefs() { mUseNormalProxy.setEnabled(true); mProxyHost.setEnabled(true); mProxyPort.setEnabled(true); + mProxyType.setEnabled(true); } private void disableUseTorPrefs() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java index 80f0500c6..6a7d6d3eb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java @@ -21,9 +21,12 @@ package org.sufficientlysecure.keychain.util; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Resources; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants.Pref; +import org.sufficientlysecure.keychain.R; +import java.net.Proxy; import java.util.ArrayList; import java.util.Arrays; import java.util.ListIterator; @@ -35,6 +38,7 @@ import java.util.Vector; public class Preferences { private static Preferences sPreferences; private SharedPreferences mSharedPreferences; + private Resources mResources; public static synchronized Preferences getPreferences(Context context) { return getPreferences(context, false); @@ -51,6 +55,7 @@ public class Preferences { } private Preferences(Context context) { + mResources = context.getResources(); updateSharedPreferences(context); } @@ -228,6 +233,8 @@ public class Preferences { return mSharedPreferences.getBoolean(Pref.ENCRYPT_FILENAMES, true); } + // proxy preference functions start here + public boolean getUseNormalProxy() { return mSharedPreferences.getBoolean(Constants.Pref.USE_NORMAL_PROXY, false); } @@ -260,13 +267,16 @@ public class Preferences { /** * we store port as String for easy interfacing with EditTextPreference, but return it as an integer + * * @return port number of proxy */ public int getProxyPort() { return Integer.parseInt(mSharedPreferences.getString(Pref.PROXY_PORT, "-1")); } + /** * we store port as String for easy interfacing with EditTextPreference, but return it as an integer + * * @param port proxy port */ public void setProxyPort(String port) { @@ -275,6 +285,22 @@ public class Preferences { editor.commit(); } + public Proxy.Type getProxyType() { + final String typeHttp = mResources.getString(R.string.pref_proxy_type_value_http); + final String typeSocks = mResources.getString(R.string.pref_proxy_type_value_socks); + + String type = mSharedPreferences.getString(Pref.PROXY_TYPE, typeHttp); + + if(type.equals(typeHttp)) return Proxy.Type.HTTP; + else if(type.equals(typeSocks)) return Proxy.Type.SOCKS; + else { // shouldn't happen + Log.e(Constants.TAG, "Invalid Proxy Type in preferences"); + return null; + } + } + + // proxy preference functions ends here + public CloudSearchPrefs getCloudSearchPrefs() { return new CloudSearchPrefs(mSharedPreferences.getBoolean(Pref.SEARCH_KEYSERVER, true), mSharedPreferences.getBoolean(Pref.SEARCH_KEYBASE, true), diff --git a/OpenKeychain/src/main/res/values/arrays.xml b/OpenKeychain/src/main/res/values/arrays.xml index 44bbe00cc..241f530d8 100644 --- a/OpenKeychain/src/main/res/values/arrays.xml +++ b/OpenKeychain/src/main/res/values/arrays.xml @@ -29,6 +29,14 @@ <item>28800</item> <item>-1</item> </string-array> + <string-array name="pref_proxy_type_entries" translatable="false"> + <item>@string/pref_proxy_type_choice_http</item> + <item>@string/pref_proxy_type_choice_socks</item> + </string-array> + <string-array name="pref_proxy_type_values" translatable="false"> + <item>@string/pref_proxy_type_value_http</item> + <item>@string/pref_proxy_type_value_socks</item> + </string-array> <string-array name="rsa_key_size_spinner_values" translatable="false"> <item>@string/key_size_2048</item> <item>@string/key_size_4096</item> diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index defa7d2a5..d8499ed06 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -174,14 +174,20 @@ <string name="pref_keybase_summary">"Search keys on keybase.io"</string> <!-- Proxy Preferences --> - <string name="pref_proxy_non">"Don't use a proxy"</string> - <string name="pref_proxy_tor">"Enable Tor"</string> + <string name="pref_proxy_tor_label">"Enable Tor"</string> <string name="pref_proxy_tor_summary">"Requires Orbot to be installed"</string> <string name="pref_proxy_normal">"Enable other proxy"</string> - <string name="pref_proxy_host">"Proxy Host"</string> + <string name="pref_proxy_host_label">"Proxy Host"</string> <string name="pref_proxy_host_err_invalid">"Proxy host cannot be empty"</string> - <string name="pref_proxy_port">"Proxy Port"</string> + <string name="pref_proxy_port_label">"Proxy Port"</string> <string name="pref_proxy_port_err_invalid">"Invalid port number entered"</string> + <string name="pref_proxy_type_label">"Proxy Type"</string> + + <!-- proxy type choices --> + <string name="pref_proxy_type_choice_http">"HTTP"</string> + <string name="pref_proxy_type_choice_socks">"SOCKS"</string> + <string name="pref_proxy_type_value_http">"proxyHttp"</string> + <string name="pref_proxy_type_value_socks">"proxySocks"</string> <string name="user_id_no_name">"<no name>"</string> <string name="none">"<none>"</string> diff --git a/OpenKeychain/src/main/res/xml/proxy_prefs.xml b/OpenKeychain/src/main/res/xml/proxy_prefs.xml index e77ac6d71..ab9c5a3e3 100644 --- a/OpenKeychain/src/main/res/xml/proxy_prefs.xml +++ b/OpenKeychain/src/main/res/xml/proxy_prefs.xml @@ -3,7 +3,7 @@ <CheckBoxPreference android:key="useTorProxy" android:persistent="true" - android:title="@string/pref_proxy_tor" + android:title="@string/pref_proxy_tor_label" android:summary="@string/pref_proxy_tor_summary" /> <CheckBoxPreference android:key="useNormalProxy" @@ -13,7 +13,7 @@ android:key="proxyHost" android:persistent="true" android:defaultValue="127.0.0.1" - android:title="@string/pref_proxy_host" + android:title="@string/pref_proxy_host_label" android:cursorVisible="true" android:textCursorDrawable="@null" android:inputType="textEmailAddress"/> @@ -21,7 +21,14 @@ android:key="proxyPort" android:defaultValue="8118" android:persistent="true" - android:title="@string/pref_proxy_port" + android:title="@string/pref_proxy_port_label" android:textCursorDrawable="@null" android:inputType="number" /> + <ListPreference + android:entries="@array/pref_proxy_type_entries" + android:entryValues="@array/pref_proxy_type_values" + android:defaultValue="@string/pref_proxy_type_value_http" + android:key="proxyType" + android:persistent="true" + android:title="@string/pref_proxy_type_label" /> </PreferenceScreen> |