mirror of
https://github.com/gsantner/dandelion
synced 2024-11-25 05:42:10 +01:00
Connected proxy settings to SettingsActivity.
This commit is contained in:
parent
414b314649
commit
e532cbc215
3 changed files with 29 additions and 19 deletions
|
@ -34,7 +34,6 @@ import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
@ -50,12 +49,12 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.ActionMenuView;
|
import android.support.v7.widget.ActionMenuView;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -70,7 +69,6 @@ import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
@ -183,6 +181,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
if(!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
|
if(!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
|
||||||
Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed,Toast.LENGTH_SHORT).show();
|
Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed,Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
} else if(appSettings.wasProxyEnabled()) {
|
||||||
|
resetProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupWebView(savedInstanceState);
|
setupWebView(savedInstanceState);
|
||||||
|
@ -1033,8 +1033,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
} catch (Exception e) { /*Nothing we can do*/ }
|
} catch (Exception e) { /*Nothing we can do*/ }
|
||||||
|
|
||||||
appSettings.setProxyEnabled(true);
|
appSettings.setProxyEnabled(true);
|
||||||
appSettings.setProxyHost(host);
|
appSettings.setProxyWasEnabled(true);
|
||||||
appSettings.setProxyPort(port);
|
|
||||||
|
|
||||||
StrictMode.setThreadPolicy(old);
|
StrictMode.setThreadPolicy(old);
|
||||||
webView.reload();
|
webView.reload();
|
||||||
|
@ -1045,11 +1044,14 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setProxy() {
|
private boolean setProxy() {
|
||||||
|
Log.d(App.TAG, "Enable Proxy");
|
||||||
return setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
|
return setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetProxy() {
|
private void resetProxy() {
|
||||||
|
Log.d(App.TAG, "Reset Proxy");
|
||||||
appSettings.setProxyEnabled(false);
|
appSettings.setProxyEnabled(false);
|
||||||
|
appSettings.setProxyWasEnabled(false);
|
||||||
|
|
||||||
//Temporary change thread policy
|
//Temporary change thread policy
|
||||||
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
|
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
|
||||||
|
@ -1059,9 +1061,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
NetCipher.clearProxy();
|
NetCipher.clearProxy();
|
||||||
try{
|
try{
|
||||||
WebkitProxy.resetProxy(MainActivity.class.getName(), this);
|
WebkitProxy.resetProxy(MainActivity.class.getName(), this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {/*Nothing*/}
|
||||||
//Nothing we can do.
|
|
||||||
}
|
|
||||||
|
|
||||||
StrictMode.setThreadPolicy(old);
|
StrictMode.setThreadPolicy(old);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
@ -28,10 +29,13 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
setPreferenceSummaries();
|
setPreferenceSummaries();
|
||||||
|
SharedPreferences preferences = getPreferenceScreen().getSharedPreferences();
|
||||||
|
preferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
||||||
|
preferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPreferenceSummaries() {
|
private void setPreferenceSummaries() {
|
||||||
String[] editTextKeys = new String[]{"pref_key_proxy_host", "pref_key_proxy_port"};
|
String[] editTextKeys = new String[]{AppSettings.PREF.PROXY_HOST, AppSettings.PREF.PROXY_PORT};
|
||||||
for(String key : editTextKeys) {
|
for(String key : editTextKeys) {
|
||||||
EditTextPreference p = (EditTextPreference) findPreference(key);
|
EditTextPreference p = (EditTextPreference) findPreference(key);
|
||||||
p.setSummary(p.getText());
|
p.setSummary(p.getText());
|
||||||
|
|
|
@ -74,9 +74,10 @@ public class AppSettings {
|
||||||
public static final String PODDOMAIN = "podDomain";
|
public static final String PODDOMAIN = "podDomain";
|
||||||
public static final String PODUSERPROFILE_ASPECTS = "podUserProfile_aspects";
|
public static final String PODUSERPROFILE_ASPECTS = "podUserProfile_aspects";
|
||||||
public static final String IS_LOAD_DESKTOP_PAGE = "pref_key_desktop_mode";
|
public static final String IS_LOAD_DESKTOP_PAGE = "pref_key_desktop_mode";
|
||||||
public static final String PROXY_ENABLED = "isProxyEnabled";
|
public static final String PROXY_ENABLED = "pref_key_proxy_enabled";
|
||||||
public static final String PROXY_HOST = "proxyHost";
|
public static final String PROXY_WAS_ENABLED = "wasProxyEnabled";
|
||||||
public static final String PROXY_PORT = "proxyPort";
|
public static final String PROXY_HOST = "pref_key_proxy_host";
|
||||||
|
public static final String PROXY_PORT = "pref_key_proxy_port";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,8 +177,12 @@ public class AppSettings {
|
||||||
return prefApp.getBoolean(PREF.PROXY_ENABLED, false);
|
return prefApp.getBoolean(PREF.PROXY_ENABLED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxyHost(String host) {
|
public boolean wasProxyEnabled() {
|
||||||
setString(prefApp, PREF.PROXY_HOST, host);
|
return prefApp.getBoolean(PREF.PROXY_WAS_ENABLED, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyWasEnabled(boolean b) {
|
||||||
|
prefApp.edit().putBoolean(PREF.PROXY_WAS_ENABLED, b).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,15 +193,16 @@ public class AppSettings {
|
||||||
return prefApp.getString(PREF.PROXY_HOST, "");
|
return prefApp.getString(PREF.PROXY_HOST, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxyPort(int port) {
|
|
||||||
setInt(prefApp, PREF.PROXY_PORT, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default value: 0
|
* Default value: 0
|
||||||
* @return proxy port
|
* @return proxy port
|
||||||
*/
|
*/
|
||||||
public int getProxyPort() {
|
public int getProxyPort() {
|
||||||
return prefApp.getInt(PREF.PROXY_PORT, 0);
|
try {
|
||||||
|
return Integer.parseInt(prefApp.getString(PREF.PROXY_PORT, "0"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
prefApp.edit().putString(PREF.PROXY_PORT, "0").apply();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue