X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=4fc10372eab493e85799eb831b7400a63aa2ecc4;hp=182a23f9ab62664d0f5ea0a7cdf379aaeacc2bef;hb=774c5c4de0adb1bcfd6474f18d203c197d594782;hpb=657cff27042eeaf0a2445e0c911b4a766cab73df 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 182a23f9..4fc10372 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -2131,48 +2131,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); - // Add a Cancel entry, which by default closes the context menu. - menu.add(R.string.cancel); - break; - - case WebView.HitTestResult.EMAIL_TYPE: - // Get the target URL. - linkUrl = hitTestResult.getExtra(); - - // Set the target URL as the title of the `ContextMenu`. - menu.setHeaderTitle(linkUrl); - - // Add a Write Email entry. - menu.add(R.string.write_email).setOnMenuItemClickListener(item -> { - // 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("mailto:" + linkUrl)); - - // `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); - - // Consume the event. - return true; - }); - - // Add a Copy Email Address entry. - menu.add(R.string.copy_email_address).setOnMenuItemClickListener(item -> { - // Save the email address in a `ClipData`. - ClipData srcEmailTypeClipData = ClipData.newPlainText(getString(R.string.email_address), linkUrl); - - // Set the `ClipData` as the clipboard's primary clip. - clipboardManager.setPrimaryClip(srcEmailTypeClipData); - - // Consume the event. - return true; - }); - - // Add a `Cancel` entry, which by default closes the `ContextMenu`. + // Add an empty Cancel entry, which by default closes the context menu. menu.add(R.string.cancel); break; @@ -2193,6 +2152,24 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); + // Add an Open with App entry. + menu.add(R.string.open_with_app).setOnMenuItemClickListener((MenuItem item) -> { + // Open the image URL with an external app. + openWithApp(imageUrl); + + // Consume the event. + return true; + }); + + // Add an Open with Browser entry. + menu.add(R.string.open_with_browser).setOnMenuItemClickListener((MenuItem item) -> { + // Open the image URL with an external browser. + openWithBrowser(imageUrl); + + // Consume the event. + return true; + }); + // Add a View Image entry. menu.add(R.string.view_image).setOnMenuItemClickListener(item -> { // Load the image in the current tab. @@ -2227,25 +2204,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); - // Add an Open with App entry. - menu.add(R.string.open_with_app).setOnMenuItemClickListener((MenuItem item) -> { - // Open the image URL with an external app. - openWithApp(imageUrl); - - // Consume the event. - return true; - }); - - // Add an Open with Browser entry. - menu.add(R.string.open_with_browser).setOnMenuItemClickListener((MenuItem item) -> { - // Open the image URL with an external browser. - openWithBrowser(imageUrl); - - // Consume the event. - return true; - }); - - // Add a Cancel entry, which by default closes the context menu. + // Add an empty Cancel entry, which by default closes the context menu. menu.add(R.string.cancel); break; @@ -2296,6 +2255,24 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); + // Add an Open with App entry. + menu.add(R.string.open_with_app).setOnMenuItemClickListener((MenuItem item) -> { + // Open the link URL with an external app. + openWithApp(linkUrl); + + // Consume the event. + return true; + }); + + // Add an Open with Browser entry. + menu.add(R.string.open_with_browser).setOnMenuItemClickListener((MenuItem item) -> { + // Open the link URL with an external browser. + openWithBrowser(linkUrl); + + // Consume the event. + return true; + }); + // Add a View Image entry. menu.add(R.string.view_image).setOnMenuItemClickListener((MenuItem item) -> { // View the image in the current tab. @@ -2305,18 +2282,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); - // Add a Copy URL entry. - menu.add(R.string.copy_url).setOnMenuItemClickListener((MenuItem item) -> { - // Save the link URL in a clip data. - ClipData srcImageAnchorTypeClipData = ClipData.newPlainText(getString(R.string.url), linkUrl); - - // Set the clip data as the clipboard's primary clip. - clipboardManager.setPrimaryClip(srcImageAnchorTypeClipData); - - // Consume the event. - return true; - }); - + // Add a Save Image entry. menu.add(R.string.save_image).setOnMenuItemClickListener((MenuItem item) -> { // Instantiate the save dialog. DialogFragment saveDialogFragment = SaveDialog.saveUrl(StoragePermissionDialog.SAVE_URL, imageUrl, currentWebView.getSettings().getUserAgentString(), @@ -2329,6 +2295,19 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); + // Add a Copy URL entry. + menu.add(R.string.copy_url).setOnMenuItemClickListener((MenuItem item) -> { + // Save the link URL in a clip data. + ClipData srcImageAnchorTypeClipData = ClipData.newPlainText(getString(R.string.url), linkUrl); + + // Set the clip data as the clipboard's primary clip. + clipboardManager.setPrimaryClip(srcImageAnchorTypeClipData); + + // Consume the event. + return true; + }); + + // Add a Save URL entry. menu.add(R.string.save_url).setOnMenuItemClickListener((MenuItem item) -> { // Instantiate the save dialog. DialogFragment saveDialogFragment = SaveDialog.saveUrl(StoragePermissionDialog.SAVE_URL, linkUrl, currentWebView.getSettings().getUserAgentString(), @@ -2341,25 +2320,48 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return true; }); - // Add an Open with App entry. - menu.add(R.string.open_with_app).setOnMenuItemClickListener((MenuItem item) -> { - // Open the link URL with an external app. - openWithApp(linkUrl); + // Add an empty Cancel entry, which by default closes the context menu. + menu.add(R.string.cancel); + break; + + case WebView.HitTestResult.EMAIL_TYPE: + // Get the target URL. + linkUrl = hitTestResult.getExtra(); + + // Set the target URL as the title of the `ContextMenu`. + menu.setHeaderTitle(linkUrl); + + // Add a Write Email entry. + menu.add(R.string.write_email).setOnMenuItemClickListener(item -> { + // 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("mailto:" + linkUrl)); + + // `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); // Consume the event. return true; }); - // Add an Open with Browser entry. - menu.add(R.string.open_with_browser).setOnMenuItemClickListener((MenuItem item) -> { - // Open the link URL with an external browser. - openWithBrowser(linkUrl); + // Add a Copy Email Address entry. + menu.add(R.string.copy_email_address).setOnMenuItemClickListener(item -> { + // Save the email address in a `ClipData`. + ClipData srcEmailTypeClipData = ClipData.newPlainText(getString(R.string.email_address), linkUrl); + + // Set the `ClipData` as the clipboard's primary clip. + clipboardManager.setPrimaryClip(srcEmailTypeClipData); // Consume the event. return true; }); - // Add a cancel entry, which by default closes the context menu. + // Add an empty Cancel entry, which by default closes the context menu. menu.add(R.string.cancel); break; }