]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
Create an `Open with App` menu item. https://redmine.stoutner.com/issues/336
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.java
index 411972bbf60507190701e7ecc16b1350ed0fc9a7..83fff5abda6fc75d2cabd607bb513b7f500b5e66 100644 (file)
@@ -2857,21 +2857,39 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 printManager.print(getString(R.string.privacy_browser_web_page), printDocumentAdapter, null);
                 return true;
 
                 printManager.print(getString(R.string.privacy_browser_web_page), printDocumentAdapter, null);
                 return true;
 
+            case R.id.find_on_page:
+                // Hide the URL app bar.
+                supportAppBar.setVisibility(View.GONE);
+
+                // Show the Find on Page `RelativeLayout`.
+                findOnPageLinearLayout.setVisibility(View.VISIBLE);
+
+                // Display the keyboard.  We have to wait 200 ms before running the command to work around a bug in Android.
+                // http://stackoverflow.com/questions/5520085/android-show-softkeyboard-with-showsoftinput-is-not-working
+                findOnPageEditText.postDelayed(() -> {
+                    // Set the focus on `findOnPageEditText`.
+                    findOnPageEditText.requestFocus();
+
+                    // Display the keyboard.  `0` sets no input flags.
+                    inputMethodManager.showSoftInput(findOnPageEditText, 0);
+                }, 200);
+                return true;
+
+            case R.id.add_to_homescreen:
+                // Show the alert dialog.
+                AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcutDialog();
+                createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getString(R.string.create_shortcut));
+
+                //Everything else will be handled by the alert dialog and the associated listener below.
+                return true;
+
             case R.id.view_source:
                 // Launch the View Source activity.
                 Intent viewSourceIntent = new Intent(this, ViewSourceActivity.class);
                 startActivity(viewSourceIntent);
                 return true;
 
             case R.id.view_source:
                 // Launch the View Source activity.
                 Intent viewSourceIntent = new Intent(this, ViewSourceActivity.class);
                 startActivity(viewSourceIntent);
                 return true;
 
-            case R.id.proxy_through_orbot:
-                // Toggle the proxy through Orbot variable.
-                proxyThroughOrbot = !proxyThroughOrbot;
-
-                // Apply the proxy through Orbot settings.
-                applyProxyThroughOrbot(true);
-                return true;
-
-            case R.id.share:
+            case R.id.share_url:
                 // Setup the share string.
                 String shareString = webViewTitle + " – " + urlTextBox.getText().toString();
 
                 // Setup the share string.
                 String shareString = webViewTitle + " – " + urlTextBox.getText().toString();
 
@@ -2884,56 +2902,40 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 startActivity(Intent.createChooser(shareIntent, getString(R.string.share_url)));
                 return true;
 
                 startActivity(Intent.createChooser(shareIntent, getString(R.string.share_url)));
                 return true;
 
-            case R.id.open_with:
-                // Convert the URL to an URI.
-                Uri shareUri = Uri.parse(formattedUrlString);
-
-                // Get the host.
-                String shareHost = shareUri.getHost();
-
+            case R.id.open_with_app:
                 // Create the open with intent with `ACTION_VIEW`.
                 // Create the open with intent with `ACTION_VIEW`.
-                Intent openWithIntent = new Intent(Intent.ACTION_VIEW);
-
-                // Set the data based on the host.
-                if ((shareHost != null) && (shareHost.endsWith("youtube.com") || shareHost.equals("play.google.com") || shareHost.equals("f-droid.org"))) {  // Handle App URLs.
-                    // Set the URI but not the MIME type.  This should open all available apps.
-                    openWithIntent.setData(shareUri);
-                } else {  // Handle a generic URL.
-                    // Set the URI and the MIME type.  `"text/html"` should load browser options.
-                    openWithIntent.setDataAndType(shareUri, "text/html");
-                }
+                Intent openWithAppIntent = new Intent(Intent.ACTION_VIEW);
+
+                // Set the URI but not the MIME type.  This should open all available apps.
+                openWithAppIntent.setData(Uri.parse(formattedUrlString));
 
                 // Flag the intent to open in a new task.
 
                 // Flag the intent to open in a new task.
-                openWithIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                openWithAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
                 // Show the chooser.
 
                 // Show the chooser.
-                startActivity(Intent.createChooser(openWithIntent, getString(R.string.open_with)));
+                startActivity(Intent.createChooser(openWithAppIntent, getString(R.string.open_with)));
                 return true;
 
                 return true;
 
-            case R.id.find_on_page:
-                // Hide the URL app bar.
-                supportAppBar.setVisibility(View.GONE);
+            case R.id.open_with_browser:
+                // Create the open with intent with `ACTION_VIEW`.
+                Intent openWithBrowserIntent = new Intent(Intent.ACTION_VIEW);
 
 
-                // Show the Find on Page `RelativeLayout`.
-                findOnPageLinearLayout.setVisibility(View.VISIBLE);
+                // Set the URI and the MIME type.  `"text/html"` should load browser options.
+                openWithBrowserIntent.setDataAndType(Uri.parse(formattedUrlString), "text/html");
 
 
-                // Display the keyboard.  We have to wait 200 ms before running the command to work around a bug in Android.
-                // http://stackoverflow.com/questions/5520085/android-show-softkeyboard-with-showsoftinput-is-not-working
-                findOnPageEditText.postDelayed(() -> {
-                    // Set the focus on `findOnPageEditText`.
-                    findOnPageEditText.requestFocus();
+                // Flag the intent to open in a new task.
+                openWithBrowserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
 
-                    // Display the keyboard.  `0` sets no input flags.
-                    inputMethodManager.showSoftInput(findOnPageEditText, 0);
-                }, 200);
+                // Show the chooser.
+                startActivity(Intent.createChooser(openWithBrowserIntent, getString(R.string.open_with)));
                 return true;
 
                 return true;
 
-            case R.id.add_to_homescreen:
-                // Show the `CreateHomeScreenShortcutDialog` `AlertDialog` and name this instance `R.string.create_shortcut`.
-                AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcutDialog();
-                createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getString(R.string.create_shortcut));
+            case R.id.proxy_through_orbot:
+                // Toggle the proxy through Orbot variable.
+                proxyThroughOrbot = !proxyThroughOrbot;
 
 
-                //Everything else will be handled by `CreateHomeScreenShortcutDialog` and the associated listener below.
+                // Apply the proxy through Orbot settings.
+                applyProxyThroughOrbot(true);
                 return true;
 
             case R.id.refresh:
                 return true;
 
             case R.id.refresh: