]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java
Implement Orbot proxy support. Fixes https://redmine.stoutner.com/issues/26.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / SettingsFragment.java
index 4eef49c2fa7a529d087c3b7ff7669837eafe2ff8..60e250b2241f0337f86251cf64b8e4d27ba13fe2 100644 (file)
@@ -20,6 +20,7 @@
 package com.stoutner.privacybrowser;
 
 import android.annotation.SuppressLint;
+import android.app.Activity;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
@@ -91,12 +92,12 @@ public class SettingsFragment extends PreferenceFragment {
         javaScriptDisabledSearchCustomURLPreference.setEnabled(javaScriptDisabledSearchString.equals("Custom URL"));
 
 
-        // Set the JavaScript-enabed searchURL as the summary text for the JavaScript-enabled search preference when the preference screen is loaded.
+        // Set the JavaScript-enabled searchURL as the summary text for the JavaScript-enabled search preference when the preference screen is loaded.
         // The default is "https://duckduckgo.com/?q=".
         final Preference javaScriptEnabledSearchPreference = findPreference("javascript_enabled_search");
         String javaScriptEnabledSearchString = savedPreferences.getString("javascript_enabled_search", "https://duckduckgo.com/?q=");
         if (javaScriptEnabledSearchString.equals("Custom URL")) {
-            // If set to "Custom URL", use R.string.custom_url, which will be tgranslated, instead of the array value, which will not.
+            // If set to "Custom URL", use R.string.custom_url, which will be translated, instead of the array value, which will not.
             javaScriptEnabledSearchPreference.setSummary(R.string.custom_url);
         } else {
             // Set the array value as the summary text.
@@ -173,9 +174,6 @@ public class SettingsFragment extends PreferenceFragment {
                         if (Build.VERSION.SDK_INT >= 21) {
                             MainWebViewActivity.cookieManager.setAcceptThirdPartyCookies(MainWebViewActivity.mainWebView, MainWebViewActivity.thirdPartyCookiesEnabled);
                         }
-
-                        // Update the privacy icons.
-                        MainWebViewActivity.updatePrivacyIcons(MainWebViewActivity.privacyBrowserActivity);
                         break;
 
                     case "dom_storage_enabled":
@@ -244,6 +242,17 @@ public class SettingsFragment extends PreferenceFragment {
                         MainWebViewActivity.mainWebView.getSettings().setUserAgentString(sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"));
                         break;
 
+                    case "proxy_through_orbot":
+                        // Get a handle for `settingsActivity`.
+                        Activity settingsActivity = getActivity();
+
+                        // Update the proxy.  The default is `false`
+                        if (sharedPreferences.getBoolean("proxy_through_orbot", false)) {  // Orbot proxies on localhost port 8118.
+                            OrbotProxyHelper.setProxy(MainWebViewActivity.privacyBrowserContext, settingsActivity, "localhost", "8118");
+                        } else {  // Disable the proxy by setting the host to `null` and the port to `0`.
+                            OrbotProxyHelper.setProxy(MainWebViewActivity.privacyBrowserContext, settingsActivity, "", "0");
+                        }
+
                     case "javascript_disabled_search":
                         String newJavaScriptDisabledSearchString = sharedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q=");
                         if (newJavaScriptDisabledSearchString.equals("Custom URL")) {