]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Add a preference to control opening of intents in new tabs. https://redmine.stoutner...
authorSoren Stoutner <soren@stoutner.com>
Tue, 23 Apr 2019 21:31:30 +0000 (14:31 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 23 Apr 2019 21:31:30 +0000 (14:31 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java
app/src/main/res/drawable/tab.xml [deleted file]
app/src/main/res/drawable/tab_disabled_dark.xml [new file with mode: 0644]
app/src/main/res/drawable/tab_disabled_light.xml [new file with mode: 0644]
app/src/main/res/drawable/tab_enabled_dark.xml [new file with mode: 0644]
app/src/main/res/drawable/tab_enabled_light.xml [new file with mode: 0644]
app/src/main/res/menu/webview_navigation_menu.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index e3adab232ba16b4d74a0b2cf9030ae8b3c0836e1..ed0259f21c2805179ec03f36b85c41e19d86e89c 100644 (file)
@@ -812,8 +812,13 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
             // Sets the new intent as the activity intent, which replaces the one that originally started the app.
             setIntent(intent);
 
-            // Add a new tab.
-            addTab(null);
+            // Get the shared preferences.
+            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+            if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+                // Add a new tab.
+                addTab(null);
+            }
 
             // Create a URL string.
             String url;
@@ -1075,7 +1080,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         // Only show Ad Consent if this is the free flavor.
         adConsentMenuItem.setVisible(BuildConfig.FLAVOR.contentEquals("free"));
 
-        // Get the shared preference values.
+        // Get the shared preferences.
         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
 
         // Get the dark theme and app bar preferences..
index 4001345b14037b1497f734f58b6e30b4b1b42c2f..35956e94aae28a95d9b9bed8791dfcf052ef2caa 100644 (file)
@@ -56,44 +56,45 @@ public class SettingsFragment extends PreferenceFragment {
         savedPreferences = getPreferenceScreen().getSharedPreferences();
 
         // Get handles for the preferences.
-        final Preference javaScriptPreference = findPreference("javascript");
-        final Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
-        final Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
-        final Preference domStoragePreference = findPreference("dom_storage");
-        final Preference saveFormDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
-        final Preference userAgentPreference = findPreference("user_agent");
-        final Preference customUserAgentPreference = findPreference("custom_user_agent");
-        final Preference incognitoModePreference = findPreference("incognito_mode");
-        final Preference doNotTrackPreference = findPreference("do_not_track");
-        final Preference allowScreenshotsPreference = findPreference("allow_screenshots");
-        final Preference easyListPreference = findPreference("easylist");
-        final Preference easyPrivacyPreference = findPreference("easyprivacy");
-        final Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
-        final Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
-        final Preference ultraPrivacyPreference = findPreference("ultraprivacy");
-        final Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
-        final Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot");
-        final Preference torHomepagePreference = findPreference("tor_homepage");
-        final Preference torSearchPreference = findPreference("tor_search");
-        final Preference torSearchCustomURLPreference = findPreference("tor_search_custom_url");
-        final Preference searchPreference = findPreference("search");
-        final Preference searchCustomURLPreference = findPreference("search_custom_url");
-        final Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
-        final Preference hideAppBarPreference = findPreference("hide_app_bar");
-        final Preference clearEverythingPreference = findPreference("clear_everything");
-        final Preference clearCookiesPreference = findPreference("clear_cookies");
-        final Preference clearDomStoragePreference = findPreference("clear_dom_storage");
-        final Preference clearFormDataPreference = findPreference("clear_form_data");  // The clear form data preference can be removed once the minimum API >= 26.
-        final Preference clearCachePreference = findPreference("clear_cache");
-        final Preference homepagePreference = findPreference("homepage");
-        final Preference fontSizePreference = findPreference("font_size");
-        final Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
-        final Preference scrollAppBarPreference = findPreference("scroll_app_bar");
-        final Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
-        final Preference downloadWithExternalAppPreference = findPreference("download_with_external_app");
-        final Preference darkThemePreference = findPreference("dark_theme");
-        final Preference nightModePreference = findPreference("night_mode");
-        final Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
+        Preference javaScriptPreference = findPreference("javascript");
+        Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
+        Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
+        Preference domStoragePreference = findPreference("dom_storage");
+        Preference saveFormDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
+        Preference userAgentPreference = findPreference("user_agent");
+        Preference customUserAgentPreference = findPreference("custom_user_agent");
+        Preference incognitoModePreference = findPreference("incognito_mode");
+        Preference doNotTrackPreference = findPreference("do_not_track");
+        Preference allowScreenshotsPreference = findPreference("allow_screenshots");
+        Preference easyListPreference = findPreference("easylist");
+        Preference easyPrivacyPreference = findPreference("easyprivacy");
+        Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
+        Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
+        Preference ultraPrivacyPreference = findPreference("ultraprivacy");
+        Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
+        Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot");
+        Preference torHomepagePreference = findPreference("tor_homepage");
+        Preference torSearchPreference = findPreference("tor_search");
+        Preference torSearchCustomURLPreference = findPreference("tor_search_custom_url");
+        Preference searchPreference = findPreference("search");
+        Preference searchCustomURLPreference = findPreference("search_custom_url");
+        Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
+        Preference hideAppBarPreference = findPreference("hide_app_bar");
+        Preference clearEverythingPreference = findPreference("clear_everything");
+        Preference clearCookiesPreference = findPreference("clear_cookies");
+        Preference clearDomStoragePreference = findPreference("clear_dom_storage");
+        Preference clearFormDataPreference = findPreference("clear_form_data");  // The clear form data preference can be removed once the minimum API >= 26.
+        Preference clearCachePreference = findPreference("clear_cache");
+        Preference homepagePreference = findPreference("homepage");
+        Preference fontSizePreference = findPreference("font_size");
+        Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
+        Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
+        Preference scrollAppBarPreference = findPreference("scroll_app_bar");
+        Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
+        Preference downloadWithExternalAppPreference = findPreference("download_with_external_app");
+        Preference darkThemePreference = findPreference("dark_theme");
+        Preference nightModePreference = findPreference("night_mode");
+        Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
 
         // Set dependencies.
         torHomepagePreference.setDependency("proxy_through_orbot");
@@ -105,7 +106,7 @@ public class SettingsFragment extends PreferenceFragment {
         String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
 
         // Get booleans that are used in multiple places from the preferences.
-        final boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
+        boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
         boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false);
         boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies", false);
         boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
@@ -114,7 +115,7 @@ public class SettingsFragment extends PreferenceFragment {
         boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
         boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
         boolean darkTheme = savedPreferences.getBoolean("dark_theme", false);
-        final boolean nightMode = savedPreferences.getBoolean("night_mode", false);
+        boolean nightMode = savedPreferences.getBoolean("night_mode", false);
 
         // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
         thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
@@ -140,7 +141,7 @@ public class SettingsFragment extends PreferenceFragment {
         LayoutInflater inflater = getActivity().getLayoutInflater();
         // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the `bare_webview` will not be displayed.
         @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
-        final WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
+        WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
 
         // Get the user agent arrays.
         ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
@@ -603,6 +604,21 @@ public class SettingsFragment extends PreferenceFragment {
             clearCachePreference.setIcon(R.drawable.cache_warning);
         }
 
+        // Set the open intents in new tab preference icon.
+        if (savedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+            if (darkTheme) {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_dark);
+            } else {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_light);
+            }
+        } else {
+            if (darkTheme) {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_dark);
+            } else {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_light);
+            }
+        }
+
         // Set the swipe to refresh preference icon.
         if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
             if (darkTheme) {
@@ -1413,6 +1429,23 @@ public class SettingsFragment extends PreferenceFragment {
                     fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%%");
                     break;
 
+                case "open_intents_in_new_tab":
+                    // Update the icon.
+                    if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+                        if (darkTheme) {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_dark);
+                        } else {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_light);
+                        }
+                    } else {
+                        if (darkTheme) {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_dark);
+                        } else {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_light);
+                        }
+                    }
+                    break;
+
                 case "swipe_to_refresh":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
@@ -1510,7 +1543,7 @@ public class SettingsFragment extends PreferenceFragment {
                         System.exit(0);
                     };
 
-                    // Restart the activity after 100 milliseconds, so that the app has enought time to save the change to the preference.
+                    // Restart the activity after 100 milliseconds, so that the app has enough time to save the change to the preference.
                     changeThemeRestartHandler.postDelayed(changeThemeRestartRunnable, 100);
                     break;
 
diff --git a/app/src/main/res/drawable/tab.xml b/app/src/main/res/drawable/tab.xml
deleted file mode 100644 (file)
index de04901..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<!-- `tab.xml` comes from the Android Material icon set, where it is called `tab`.  It is released under the Apache License 2.0. -->
-
-<!-- `tools:ignore="VectorRaster"` removes the lint warning about `android:autoMirrored="true"` not applying to API < 21. -->
-<vector
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:height="24dp"
-    android:width="24dp"
-    android:viewportHeight="24.0"
-    android:viewportWidth="24.0"
-    android:autoMirrored="true"
-    tools:ignore="VectorRaster" >
-
-    <!-- A hard coded color must be used until the minimum API >= 21.  Then `@color` can be used. -->
-    <path
-        android:fillColor="#FF000000"
-        android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19L3,19L3,5h10v4h8v10z" />
-</vector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_disabled_dark.xml b/app/src/main/res/drawable/tab_disabled_dark.xml
new file mode 100644 (file)
index 0000000..fa382a2
--- /dev/null
@@ -0,0 +1,18 @@
+<!-- `tab_disabled_dark.xml` comes from the Android Material icon set, where it is called `tab`.  It is released under the Apache License 2.0. -->
+
+<!-- `tools:ignore="VectorRaster"` removes the lint warning about `android:autoMirrored="true"` not applying to API < 21. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0"
+    android:autoMirrored="true"
+    tools:ignore="VectorRaster" >
+
+    <!-- A hard coded color must be used until the minimum API >= 21.  Then `@color` can be used. -->
+    <path
+        android:fillColor="#FF9E9E9E"
+        android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19L3,19L3,5h10v4h8v10z" />
+</vector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_disabled_light.xml b/app/src/main/res/drawable/tab_disabled_light.xml
new file mode 100644 (file)
index 0000000..16962a7
--- /dev/null
@@ -0,0 +1,18 @@
+<!-- `tab_disabled_light.xml` comes from the Android Material icon set, where it is called `tab`.  It is released under the Apache License 2.0. -->
+
+<!-- `tools:ignore="VectorRaster"` removes the lint warning about `android:autoMirrored="true"` not applying to API < 21. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0"
+    android:autoMirrored="true"
+    tools:ignore="VectorRaster" >
+
+    <!-- A hard coded color must be used until the minimum API >= 21.  Then `@color` can be used. -->
+    <path
+        android:fillColor="#FF757575"
+        android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19L3,19L3,5h10v4h8v10z" />
+</vector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_enabled_dark.xml b/app/src/main/res/drawable/tab_enabled_dark.xml
new file mode 100644 (file)
index 0000000..23f55db
--- /dev/null
@@ -0,0 +1,18 @@
+<!-- `tab_enabled_dark.xml` comes from the Android Material icon set, where it is called `tab`.  It is released under the Apache License 2.0. -->
+
+<!-- `tools:ignore="VectorRaster"` removes the lint warning about `android:autoMirrored="true"` not applying to API < 21. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0"
+    android:autoMirrored="true"
+    tools:ignore="VectorRaster" >
+
+    <!-- A hard coded color must be used until the minimum API >= 21.  Then `@color` can be used. -->
+    <path
+        android:fillColor="#FF1E88E5"
+        android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19L3,19L3,5h10v4h8v10z" />
+</vector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_enabled_light.xml b/app/src/main/res/drawable/tab_enabled_light.xml
new file mode 100644 (file)
index 0000000..6fbdb81
--- /dev/null
@@ -0,0 +1,18 @@
+<!-- `tab_enabled_light.xml` comes from the Android Material icon set, where it is called `tab`.  It is released under the Apache License 2.0. -->
+
+<!-- `tools:ignore="VectorRaster"` removes the lint warning about `android:autoMirrored="true"` not applying to API < 21. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0"
+    android:autoMirrored="true"
+    tools:ignore="VectorRaster" >
+
+    <!-- A hard coded color must be used until the minimum API >= 21.  Then `@color` can be used. -->
+    <path
+        android:fillColor="#FF1565C0"
+        android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19L3,19L3,5h10v4h8v10z" />
+</vector>
\ No newline at end of file
index 6181453cfc234e1113943294547dcfaff77b26eb..8563d516df847d0dbd65065ec5eacb877013408b 100644 (file)
@@ -24,7 +24,7 @@
     <item
         android:id="@+id/close_tab"
         android:title="@string/close_tab"
-        android:icon="@drawable/tab"
+        android:icon="@drawable/tab_enabled_light"
         android:orderInCategory="10" />
 
     <item
index 147a7155729e157d2fb4328fab1614fb23a4c51e..03c9347d21ad8f2bf69b9a5e40bf326ac77aeef3 100644 (file)
                 <item>175</item>
                 <item>200</item>
             </string-array>
+        <string name="open_intents_in_new_tab">Open intents in new tab</string>
+        <string name="open_intents_in_new_tab_summary">Intents are links sent from other apps.</string>
         <string name="swipe_to_refresh">Swipe to refresh</string>
         <string name="swipe_to_refresh_summary">Some websites don’t work well if swipe to refresh is enabled.</string>
         <string name="scroll_app_bar">Scroll the app bar</string>
index 6176de6067347fe73c455b332f9d33770a8c0daf..af3e7a50d204ef57960795deb41c9a81f5662193 100644 (file)
             android:defaultValue="@string/font_size_default_value"
             android:icon="?attr/fontSizeIcon" />
 
+        <SwitchPreference
+            android:key="open_intents_in_new_tab"
+            android:title="@string/open_intents_in_new_tab"
+            android:summary="@string/open_intents_in_new_tab_summary"
+            android:defaultValue="true" />
+
         <SwitchPreference
             android:key="swipe_to_refresh"
             android:title="@string/swipe_to_refresh"