added proxy type
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user