]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
Fix the navigation drawer after exiting a full screen video. https://redmine.stoutne...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / MainWebViewActivity.java
index f10c2e45f561d0640f50fc92c22b4e4addbdcfac..ca0cc89c5409fe5d0b81997598c8f3ba48813560 100644 (file)
@@ -27,12 +27,15 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.design.widget.NavigationView;
 import android.support.design.widget.Snackbar;
+import android.support.v4.content.ContextCompat;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v4.widget.SwipeRefreshLayout;
@@ -201,11 +204,27 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, supportAppBar, R.string.open_navigation, R.string.close_navigation);
 
         mainWebView.setWebViewClient(new WebViewClient() {
-            // shouldOverrideUrlLoading makes this WebView the default handler for URLs inside the app, so that links are not kicked out to other apps.
+            // shouldOverrideUrlLoading makes this `WebView` the default handler for URLs inside the app, so that links are not kicked out to other apps.
             @Override
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
-                mainWebView.loadUrl(url);
-                return true;
+                // Use an external email program if the link begins with "mailto:".
+                if (url.startsWith("mailto:")) {
+                    // We use `ACTION_SENDTO` instead of `ACTION_SEND` so that only email programs are launched.
+                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
+
+                    // Parse the url and set it as the data for the `Intent`.
+                    emailIntent.setData(Uri.parse(url));
+
+                    // `FLAG_ACTIVITY_NEW_TASK` opens the email program in a new task instead as part of Privacy Browser.
+                    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+                    // Make it so.
+                    startActivity(emailIntent);
+                    return true;
+                } else {  // Load the URL in Privacy Browser.
+                    mainWebView.loadUrl(url);
+                    return true;
+                }
             }
 
             // Update the URL in urlTextBox when the page starts to load.
@@ -413,6 +432,14 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Load the initial website.
         mainWebView.loadUrl(formattedUrlString);
 
+        // Load the default favorite icon if it is null.
+        if (favoriteIcon == null) {
+            // We have to use `ContextCompat` until API >= 21.
+            Drawable favoriteIconDrawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.world);
+            BitmapDrawable favoriteIconBitmapDrawable = (BitmapDrawable) favoriteIconDrawable;
+            favoriteIcon = favoriteIconBitmapDrawable.getBitmap();
+        }
+
         // Initialize AdView for the free flavor and request an ad.  If this is not the free flavor BannerAd.requestAd() does nothing.
         adView = findViewById(R.id.adView);
         BannerAd.requestAd(adView);