mirror of
https://github.com/gsantner/dandelion
synced 2024-12-25 20:38:05 +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.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
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.AppCompatActivity;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
|
@ -70,7 +69,6 @@ import android.webkit.WebChromeClient;
|
|||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -183,6 +181,8 @@ public class MainActivity extends AppCompatActivity
|
|||
if(!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
|
||||
Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if(appSettings.wasProxyEnabled()) {
|
||||
resetProxy();
|
||||
}
|
||||
|
||||
setupWebView(savedInstanceState);
|
||||
|
@ -1033,8 +1033,7 @@ public class MainActivity extends AppCompatActivity
|
|||
} catch (Exception e) { /*Nothing we can do*/ }
|
||||
|
||||
appSettings.setProxyEnabled(true);
|
||||
appSettings.setProxyHost(host);
|
||||
appSettings.setProxyPort(port);
|
||||
appSettings.setProxyWasEnabled(true);
|
||||
|
||||
StrictMode.setThreadPolicy(old);
|
||||
webView.reload();
|
||||
|
@ -1045,11 +1044,14 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
private boolean setProxy() {
|
||||
Log.d(App.TAG, "Enable Proxy");
|
||||
return setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
|
||||
}
|
||||
|
||||
private void resetProxy() {
|
||||
Log.d(App.TAG, "Reset Proxy");
|
||||
appSettings.setProxyEnabled(false);
|
||||
appSettings.setProxyWasEnabled(false);
|
||||
|
||||
//Temporary change thread policy
|
||||
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
|
||||
|
@ -1059,9 +1061,7 @@ public class MainActivity extends AppCompatActivity
|
|||
NetCipher.clearProxy();
|
||||
try{
|
||||
WebkitProxy.resetProxy(MainActivity.class.getName(), this);
|
||||
} catch (Exception e) {
|
||||
//Nothing we can do.
|
||||
}
|
||||
} catch (Exception e) {/*Nothing*/}
|
||||
|
||||
StrictMode.setThreadPolicy(old);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
|
@ -28,10 +29,13 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
addPreferencesFromResource(R.xml.preferences);
|
||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
setPreferenceSummaries();
|
||||
SharedPreferences preferences = getPreferenceScreen().getSharedPreferences();
|
||||
preferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
||||
preferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
||||
}
|
||||
|
||||
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) {
|
||||
EditTextPreference p = (EditTextPreference) findPreference(key);
|
||||
p.setSummary(p.getText());
|
||||
|
|
|
@ -74,9 +74,10 @@ public class AppSettings {
|
|||
public static final String PODDOMAIN = "podDomain";
|
||||
public static final String PODUSERPROFILE_ASPECTS = "podUserProfile_aspects";
|
||||
public static final String IS_LOAD_DESKTOP_PAGE = "pref_key_desktop_mode";
|
||||
public static final String PROXY_ENABLED = "isProxyEnabled";
|
||||
public static final String PROXY_HOST = "proxyHost";
|
||||
public static final String PROXY_PORT = "proxyPort";
|
||||
public static final String PROXY_ENABLED = "pref_key_proxy_enabled";
|
||||
public static final String PROXY_WAS_ENABLED = "wasProxyEnabled";
|
||||
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);
|
||||
}
|
||||
|
||||
public void setProxyHost(String host) {
|
||||
setString(prefApp, PREF.PROXY_HOST, host);
|
||||
public boolean wasProxyEnabled() {
|
||||
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, "");
|
||||
}
|
||||
|
||||
public void setProxyPort(int port) {
|
||||
setInt(prefApp, PREF.PROXY_PORT, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default value: 0
|
||||
* @return proxy port
|
||||
*/
|
||||
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