]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Create an `Open with App` menu item. https://redmine.stoutner.com/issues/336
authorSoren Stoutner <soren@stoutner.com>
Sun, 13 Jan 2019 00:03:39 +0000 (17:03 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sun, 13 Jan 2019 00:03:39 +0000 (17:03 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/res/menu/webview_options_menu.xml
app/src/main/res/values/strings.xml

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;
 
+            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.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();
 
@@ -2884,56 +2902,40 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 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`.
-                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.
-                openWithIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                openWithAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
                 // Show the chooser.
-                startActivity(Intent.createChooser(openWithIntent, getString(R.string.open_with)));
+                startActivity(Intent.createChooser(openWithAppIntent, getString(R.string.open_with)));
                 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;
 
-            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:
index b7760ed2d2a5aa7519d120f8e6bcafb14a554a92..acf69eaf287d82bf3788802928182823555e4869 100644 (file)
                 android:orderInCategory="970"
                 app:showAsAction="never" />
 
+            <item
+                android:id="@+id/find_on_page"
+                android:title="@string/find_on_page"
+                android:orderInCategory="980"
+                app:showAsAction="never|collapseActionView" />
+
+            <item
+                android:id="@+id/add_to_homescreen"
+                android:title="@string/add_to_home_screen"
+                android:orderInCategory="990"
+                app:showAsAction="never" />
+
             <item
                 android:id="@+id/view_source"
                 android:title="@string/view_source"
-                android:orderInCategory="980"
+                android:orderInCategory="999"
                 app:showAsAction="never" />
         </menu>
     </item>
 
-    <item
-        android:id="@+id/proxy_through_orbot"
-        android:title="@string/proxy_through_orbot"
-        android:orderInCategory="1000"
-        android:checkable="true"
-        app:showAsAction="never" />
-
     <item
         android:id="@+id/share"
         android:title="@string/share"
-        android:orderInCategory="1100"
-        app:showAsAction="never" />
+        android:orderInCategory="1000"
+        app:showAsAction="never" >
 
-    <item
-        android:id="@+id/open_with"
-        android:title="@string/open_with"
-        android:orderInCategory="1200"
-        app:showAsAction="never" />
+        <menu>
+            <item
+                android:id="@+id/share_url"
+                android:title="@string/share_url"
+                android:orderInCategory="1010"
+                app:showAsAction="never" />
 
-    <item
-        android:id="@+id/find_on_page"
-        android:title="@string/find_on_page"
-        android:orderInCategory="1300"
-        app:showAsAction="never|collapseActionView" />
+            <item
+                android:id="@+id/open_with_app"
+                android:title="@string/open_with_app"
+                android:orderInCategory="1020"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/open_with_browser"
+                android:title="@string/open_with_browser"
+                android:orderInCategory="1030"
+                app:showAsAction="never" />
+        </menu>
+    </item>
 
     <item
-        android:id="@+id/add_to_homescreen"
-        android:title="@string/add_to_home_screen"
-        android:orderInCategory="1400"
+        android:id="@+id/proxy_through_orbot"
+        android:title="@string/proxy_through_orbot"
+        android:orderInCategory="1100"
+        android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/refresh"
         android:title="@string/refresh"
-        android:orderInCategory="1500"
+        android:orderInCategory="1200"
         app:showAsAction="never" />
 
     <item
index 4d7f2a12ebd50700b5b8786bad813ba6330de316..b37c1a0d354168d8bf6b7f928bbab6fc25093451 100644 (file)
         <string name="view_source">View Source</string>
     <string name="share">Share</string>
         <string name="share_url">Share URL</string>
+        <string name="open_with_app">Open with App</string>
+        <string name="open_with_browser">Open with Browser</string>
     <string name="find_on_page">Find on Page</string>
     <string name="print">Print</string>
         <string name="privacy_browser_web_page">Privacy Browser Web Page</string>