]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
Round the corners of the URL background. Implements https://redmine.stoutner.com...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.java
index 08aa9eb21f074639b376f62f7e9e00694e0273f1..2ca1f0fb52d7d700a62c150a79e79cf873fab57a 100644 (file)
@@ -1152,6 +1152,14 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 mainWebView.getSettings().setTextZoom(200);
                 return true;
 
+            case R.id.share:
+                Intent shareIntent = new Intent();
+                shareIntent.setAction(Intent.ACTION_SEND);
+                shareIntent.putExtra(Intent.EXTRA_TEXT, urlTextBox.getText().toString());
+                shareIntent.setType("text/plain");
+                startActivity(Intent.createChooser(shareIntent, "Share URL"));
+                return true;
+
             case R.id.find_on_page:
                 // Hide the URL app bar.
                 supportAppBar.setVisibility(View.GONE);
@@ -1175,20 +1183,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 }, 200);
                 return true;
 
-            case R.id.share:
-                Intent shareIntent = new Intent();
-                shareIntent.setAction(Intent.ACTION_SEND);
-                shareIntent.putExtra(Intent.EXTRA_TEXT, urlTextBox.getText().toString());
-                shareIntent.setType("text/plain");
-                startActivity(Intent.createChooser(shareIntent, "Share URL"));
-                return true;
-
-            case R.id.addToHomescreen:
-                // Show the `CreateHomeScreenShortcutDialog` `AlertDialog` and name this instance `R.string.create_shortcut`.
-                AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcutDialog();
-                createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.create_shortcut));
-
-                //Everything else will be handled by `CreateHomeScreenShortcutDialog` and the associated listener below.
+            case R.id.refresh:
+                mainWebView.reload();
                 return true;
 
             case R.id.print:
@@ -1202,8 +1198,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 printManager.print(getResources().getString(R.string.privacy_browser_web_page), printDocumentAdapter, null);
                 return true;
 
-            case R.id.refresh:
-                mainWebView.reload();
+            case R.id.addToHomescreen:
+                // Show the `CreateHomeScreenShortcutDialog` `AlertDialog` and name this instance `R.string.create_shortcut`.
+                AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcutDialog();
+                createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.create_shortcut));
+
+                //Everything else will be handled by `CreateHomeScreenShortcutDialog` and the associated listener below.
                 return true;
 
             default:
@@ -1831,7 +1831,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         mainWebView.loadUrl(url, customHeaders);
     }
 
-    // We have to use the deprecated `.getColor()` until the minimum API >= 23.
+    // We have to use the deprecated `.getDrawable()` until the minimum API >= 21.
     @SuppressWarnings("deprecation")
     private void applyDomainSettings(String url) {
         // Parse the URL into a URI.
@@ -1874,12 +1874,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
             boolean hostHasDomainSettings = false;
             String domainNameInDatabase = null;
 
-            // Check all the subdomains of `hostname` against the list of domains in `domainCursor`.
+            // Check the hostname.
+            if (domainSettingsSet.contains(hostname)) {
+                hostHasDomainSettings = true;
+                domainNameInDatabase = hostname;
+            }
+
+            // Check all the subdomains of `hostname` against wildcard domains in `domainCursor`.
             while (hostname.contains(".") && !hostHasDomainSettings) {  // Stop checking if we run out of  `.` or if we already know that `hostHasDomainSettings` is `true`.
-                if (domainSettingsSet.contains(hostname)) {  // Check the host name.
-                    hostHasDomainSettings = true;
-                    domainNameInDatabase = hostname;
-                } else if (domainSettingsSet.contains("*." + hostname)) {  // Check the host name prepended by `*.`.
+                if (domainSettingsSet.contains("*." + hostname)) {  // Check the host name prepended by `*.`.
                     hostHasDomainSettings = true;
                     domainNameInDatabase = "*." + hostname;
                 }
@@ -1928,8 +1931,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                     mainWebView.getSettings().setUserAgentString(userAgentString);
                 }
 
-                // Set a green background on `urlTextBox` to indicate that custom domain settings are being used.  We have to use the deprecated `.getColor()` until the minimum API >= 23.
-                urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.green_100));
+                // Set a green background on `urlTextBox` to indicate that custom domain settings are being used.  We have to use the deprecated `.getDrawable()` until the minimum API >= 21.
+                urlAppBarFrameLayout.setBackground(getResources().getDrawable(R.drawable.url_bar_background_green));
             } else {  // The URL we are loading does not have custom domain settings.  Load the defaults.
                 // Get the shared preference values.  `this` references the current context.
                 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
@@ -1974,8 +1977,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                         break;
                 }
 
-                // Set a transparent background on `urlTextBox`.  We have to use the deprecated `.getColor()` until the minimum API >= 23.
-                urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.transparent));
+                // Set a transparent background on `urlTextBox`.  We have to use the deprecated `.getDrawable()` until the minimum API >= 21.
+                urlAppBarFrameLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.url_bar_background_transparent));
             }
 
             // Close `domainsDatabaseHelper`.