]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
Move `Refresh` to the bottom of the main options menu. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.java
index 25e61890f907c1f0f04659016dec1a0d82e9e793..01978f46869684e9111240c737353deffa8f65c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2015-2017 Soren Stoutner <soren@stoutner.com>.
  *
  * Download cookie code contributed 2017 Hendrik Knackstedt.  Copyright assigned to Soren Stoutner <soren@stoutner.com>.
  *
@@ -568,8 +568,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
             @SuppressWarnings("deprecation")
             @Override
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
-                // Use an external email program if the link begins with `mailto:`.
-                if (url.startsWith("mailto:")) {
+                if (url.startsWith("mailto:")) {  // Load the URL in an external email program because it begins with `mailto:`.
                     // We use `ACTION_SENDTO` instead of `ACTION_SEND` so that only email programs are launched.
                     Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
 
@@ -581,10 +580,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
                     // Make it so.
                     startActivity(emailIntent);
+
+                    // Returning `true` indicates the application is handling the URL.
                     return true;
                 } else {  // Load the URL in Privacy Browser.
-                    loadUrl(url);
-                    return true;
+                    // Apply the domain settings for the new URL.
+                    applyDomainSettings(url);
+
+                    // Returning `false` causes the current `WebView` to handle the URL and prevents it from adding redirects to the history list.
+                    return false;
                 }
             }
 
@@ -822,6 +826,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Hide zoom controls.
         mainWebView.getSettings().setDisplayZoomControls(false);
 
+        // Set `mainWebView` to use a wide viewport.  Otherwise, some web pages will be scrunched and some content will render outside the screen.
+        mainWebView.getSettings().setUseWideViewPort(true);
+
+        // Set `mainWebView` to load in overview mode (zoomed out to the maximum width).
+        mainWebView.getSettings().setLoadWithOverviewMode(true);
+
         // Initialize cookieManager.
         cookieManager = CookieManager.getInstance();
 
@@ -1226,10 +1236,21 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 return true;
 
             case R.id.share:
+                // Setup the share string.
+                String shareString;
+                if (webViewTitle != null) {
+                    shareString = webViewTitle + " – " + urlTextBox.getText().toString();
+                } else {
+                    shareString = urlTextBox.getText().toString();
+                }
+
+                // Create the share intent.
                 Intent shareIntent = new Intent();
                 shareIntent.setAction(Intent.ACTION_SEND);
-                shareIntent.putExtra(Intent.EXTRA_TEXT, urlTextBox.getText().toString());
+                shareIntent.putExtra(Intent.EXTRA_TEXT, shareString);
                 shareIntent.setType("text/plain");
+
+                // Make it so.
                 startActivity(Intent.createChooser(shareIntent, "Share URL"));
                 return true;
 
@@ -1256,10 +1277,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 }, 200);
                 return true;
 
-            case R.id.refresh:
-                mainWebView.reload();
-                return true;
-
             case R.id.print:
                 // Get a `PrintManager` instance.
                 PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
@@ -1279,6 +1296,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 //Everything else will be handled by `CreateHomeScreenShortcutDialog` and the associated listener below.
                 return true;
 
+            case R.id.refresh:
+                mainWebView.reload();
+                return true;
+
             default:
                 // Don't consume the event.
                 return super.onOptionsItemSelected(menuItem);
@@ -1860,7 +1881,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         String unformattedUrlString = urlTextBox.getText().toString().trim();
 
         // Check to see if `unformattedUrlString` is a valid URL.  Otherwise, convert it into a search.
-        if ((Patterns.WEB_URL.matcher(unformattedUrlString).matches()) || (unformattedUrlString.contains("localhost"))) {
+        if ((Patterns.WEB_URL.matcher(unformattedUrlString).matches()) || (unformattedUrlString.startsWith("http://")) || (unformattedUrlString.startsWith("https://"))) {
             // Add `http://` at the beginning if it is missing.  Otherwise the app will segfault.
             if (!unformattedUrlString.startsWith("http")) {
                 unformattedUrlString = "http://" + unformattedUrlString;
@@ -2133,7 +2154,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false);
         boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false);
         boolean proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false);
-        fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("enable_full_screen_browsing_mode", false);
+        fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("full_screen_browsing_mode", false);
         hideSystemBarsOnFullscreen = sharedPreferences.getBoolean("hide_system_bars", false);
         translucentNavigationBarOnFullscreen = sharedPreferences.getBoolean("translucent_navigation_bar", true);
         swipeToRefreshEnabled = sharedPreferences.getBoolean("swipe_to_refresh", false);