mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
added proxy type
This commit is contained in:
parent
1087d231de
commit
0da4b054e6
@ -96,12 +96,7 @@ public final class Constants {
|
|||||||
public static final String USE_TOR_PROXY = "useTorProxy";
|
public static final String USE_TOR_PROXY = "useTorProxy";
|
||||||
public static final String PROXY_HOST = "proxyHost";
|
public static final String PROXY_HOST = "proxyHost";
|
||||||
public static final String PROXY_PORT = "proxyPort";
|
public static final String PROXY_PORT = "proxyPort";
|
||||||
}
|
public static final String PROXY_TYPE = "proxyType";
|
||||||
|
|
||||||
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 class Defaults {
|
public static final class Defaults {
|
||||||
|
@ -22,12 +22,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.*;
|
||||||
import android.preference.EditTextPreference;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
import android.preference.PreferenceFragment;
|
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -279,6 +274,7 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
private CheckBoxPreference mUseNormalProxy;
|
private CheckBoxPreference mUseNormalProxy;
|
||||||
private EditTextPreference mProxyHost;
|
private EditTextPreference mProxyHost;
|
||||||
private EditTextPreference mProxyPort;
|
private EditTextPreference mProxyPort;
|
||||||
|
private ListPreference mProxyType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -291,10 +287,12 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY);
|
mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY);
|
||||||
mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST);
|
mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST);
|
||||||
mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT);
|
mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT);
|
||||||
|
mProxyType = (ListPreference) findPreference(Constants.Pref.PROXY_TYPE);
|
||||||
|
|
||||||
initializeUseTorPref();
|
initializeUseTorPref();
|
||||||
initializeUseNormalProxyPref();
|
initializeUseNormalProxyPref();
|
||||||
initialiseEditTextPreferences();
|
initializeEditTextPreferences();
|
||||||
|
initializeProxyTypePreference();
|
||||||
|
|
||||||
if (mUseTor.isChecked()) disableNormalProxyPrefs();
|
if (mUseTor.isChecked()) disableNormalProxyPrefs();
|
||||||
else if (mUseNormalProxy.isChecked()) disableUseTorPrefs();
|
else if (mUseNormalProxy.isChecked()) disableUseTorPrefs();
|
||||||
@ -341,7 +339,7 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialiseEditTextPreferences() {
|
private void initializeEditTextPreferences() {
|
||||||
mProxyHost.setSummary(mProxyHost.getText());
|
mProxyHost.setSummary(mProxyHost.getText());
|
||||||
mProxyPort.setSummary(mProxyPort.getText());
|
mProxyPort.setSummary(mProxyPort.getText());
|
||||||
|
|
||||||
@ -390,17 +388,32 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private void disableNormalProxyPrefs() {
|
||||||
mUseNormalProxy.setChecked(false);
|
mUseNormalProxy.setChecked(false);
|
||||||
mUseNormalProxy.setEnabled(false);
|
mUseNormalProxy.setEnabled(false);
|
||||||
mProxyHost.setEnabled(false);
|
mProxyHost.setEnabled(false);
|
||||||
mProxyPort.setEnabled(false);
|
mProxyPort.setEnabled(false);
|
||||||
|
mProxyType.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableNormalProxyPrefs() {
|
private void enableNormalProxyPrefs() {
|
||||||
mUseNormalProxy.setEnabled(true);
|
mUseNormalProxy.setEnabled(true);
|
||||||
mProxyHost.setEnabled(true);
|
mProxyHost.setEnabled(true);
|
||||||
mProxyPort.setEnabled(true);
|
mProxyPort.setEnabled(true);
|
||||||
|
mProxyType.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableUseTorPrefs() {
|
private void disableUseTorPrefs() {
|
||||||
|
@ -21,9 +21,12 @@ package org.sufficientlysecure.keychain.util;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Constants.Pref;
|
import org.sufficientlysecure.keychain.Constants.Pref;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
|
||||||
|
import java.net.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
@ -35,6 +38,7 @@ import java.util.Vector;
|
|||||||
public class Preferences {
|
public class Preferences {
|
||||||
private static Preferences sPreferences;
|
private static Preferences sPreferences;
|
||||||
private SharedPreferences mSharedPreferences;
|
private SharedPreferences mSharedPreferences;
|
||||||
|
private Resources mResources;
|
||||||
|
|
||||||
public static synchronized Preferences getPreferences(Context context) {
|
public static synchronized Preferences getPreferences(Context context) {
|
||||||
return getPreferences(context, false);
|
return getPreferences(context, false);
|
||||||
@ -51,6 +55,7 @@ public class Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Preferences(Context context) {
|
private Preferences(Context context) {
|
||||||
|
mResources = context.getResources();
|
||||||
updateSharedPreferences(context);
|
updateSharedPreferences(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +229,8 @@ public class Preferences {
|
|||||||
return mSharedPreferences.getBoolean(Pref.ENCRYPT_FILENAMES, true);
|
return mSharedPreferences.getBoolean(Pref.ENCRYPT_FILENAMES, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// proxy preference functions start here
|
||||||
|
|
||||||
public boolean getUseNormalProxy() {
|
public boolean getUseNormalProxy() {
|
||||||
return mSharedPreferences.getBoolean(Constants.Pref.USE_NORMAL_PROXY, false);
|
return mSharedPreferences.getBoolean(Constants.Pref.USE_NORMAL_PROXY, false);
|
||||||
}
|
}
|
||||||
@ -256,13 +263,16 @@ public class Preferences {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* we store port as String for easy interfacing with EditTextPreference, but return it as an integer
|
* we store port as String for easy interfacing with EditTextPreference, but return it as an integer
|
||||||
|
*
|
||||||
* @return port number of proxy
|
* @return port number of proxy
|
||||||
*/
|
*/
|
||||||
public int getProxyPort() {
|
public int getProxyPort() {
|
||||||
return Integer.parseInt(mSharedPreferences.getString(Pref.PROXY_PORT, "-1"));
|
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
|
* we store port as String for easy interfacing with EditTextPreference, but return it as an integer
|
||||||
|
*
|
||||||
* @param port proxy port
|
* @param port proxy port
|
||||||
*/
|
*/
|
||||||
public void setProxyPort(String port) {
|
public void setProxyPort(String port) {
|
||||||
@ -271,6 +281,22 @@ public class Preferences {
|
|||||||
editor.commit();
|
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() {
|
public CloudSearchPrefs getCloudSearchPrefs() {
|
||||||
return new CloudSearchPrefs(mSharedPreferences.getBoolean(Pref.SEARCH_KEYSERVER, true),
|
return new CloudSearchPrefs(mSharedPreferences.getBoolean(Pref.SEARCH_KEYSERVER, true),
|
||||||
mSharedPreferences.getBoolean(Pref.SEARCH_KEYBASE, true),
|
mSharedPreferences.getBoolean(Pref.SEARCH_KEYBASE, true),
|
||||||
|
@ -29,6 +29,14 @@
|
|||||||
<item>28800</item>
|
<item>28800</item>
|
||||||
<item>-1</item>
|
<item>-1</item>
|
||||||
</string-array>
|
</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">
|
<string-array name="rsa_key_size_spinner_values" translatable="false">
|
||||||
<item>@string/key_size_2048</item>
|
<item>@string/key_size_2048</item>
|
||||||
<item>@string/key_size_4096</item>
|
<item>@string/key_size_4096</item>
|
||||||
|
@ -167,14 +167,20 @@
|
|||||||
<string name="pref_keybase_summary">"Search keys on keybase.io"</string>
|
<string name="pref_keybase_summary">"Search keys on keybase.io"</string>
|
||||||
|
|
||||||
<!-- Proxy Preferences -->
|
<!-- Proxy Preferences -->
|
||||||
<string name="pref_proxy_non">"Don't use a proxy"</string>
|
<string name="pref_proxy_tor_label">"Enable Tor"</string>
|
||||||
<string name="pref_proxy_tor">"Enable Tor"</string>
|
|
||||||
<string name="pref_proxy_tor_summary">"Requires Orbot to be installed"</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_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_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_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="user_id_no_name">"<no name>"</string>
|
||||||
<string name="none">"<none>"</string>
|
<string name="none">"<none>"</string>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="useTorProxy"
|
android:key="useTorProxy"
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:title="@string/pref_proxy_tor"
|
android:title="@string/pref_proxy_tor_label"
|
||||||
android:summary="@string/pref_proxy_tor_summary" />
|
android:summary="@string/pref_proxy_tor_summary" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="useNormalProxy"
|
android:key="useNormalProxy"
|
||||||
@ -13,7 +13,7 @@
|
|||||||
android:key="proxyHost"
|
android:key="proxyHost"
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:defaultValue="127.0.0.1"
|
android:defaultValue="127.0.0.1"
|
||||||
android:title="@string/pref_proxy_host"
|
android:title="@string/pref_proxy_host_label"
|
||||||
android:cursorVisible="true"
|
android:cursorVisible="true"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:inputType="textEmailAddress"/>
|
android:inputType="textEmailAddress"/>
|
||||||
@ -21,7 +21,14 @@
|
|||||||
android:key="proxyPort"
|
android:key="proxyPort"
|
||||||
android:defaultValue="8118"
|
android:defaultValue="8118"
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:title="@string/pref_proxy_port"
|
android:title="@string/pref_proxy_port_label"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:inputType="number" />
|
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>
|
</PreferenceScreen>
|
||||||
|
Loading…
Reference in New Issue
Block a user