From: Soren Stoutner Date: Sun, 13 Jan 2019 00:03:39 +0000 (-0700) Subject: Create an `Open with App` menu item. https://redmine.stoutner.com/issues/336 X-Git-Tag: v2.16~9 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff_plain;h=5241a83576c30f1fbb6f3527dfb0849b1b81d876 Create an `Open with App` menu item. https://redmine.stoutner.com/issues/336 --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 411972bb..83fff5ab 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -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: diff --git a/app/src/main/res/menu/webview_options_menu.xml b/app/src/main/res/menu/webview_options_menu.xml index b7760ed2..acf69eaf 100644 --- a/app/src/main/res/menu/webview_options_menu.xml +++ b/app/src/main/res/menu/webview_options_menu.xml @@ -324,49 +324,64 @@ android:orderInCategory="970" app:showAsAction="never" /> + + + + - - + android:orderInCategory="1000" + app:showAsAction="never" > - + + - + + + + + View Source Share Share URL + Open with App + Open with Browser Find on Page Print Privacy Browser Web Page