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=96380b3d9b90ed7724d73ef47caae82a49858782;hp=7f91e043e9aa648bf8699b22143f143b17295807;hb=75f7274fb8f3d161f632dc22daea406a881ffeb0;hpb=3f3b7c8fbe988fe730a5fbb53169489566655595 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 7f91e043..96380b3d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -390,6 +390,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook @Override protected void onNewIntent(Intent intent) { + // Run the default commands. + super.onNewIntent(intent); + // Replace the intent that started the app with this one. setIntent(intent); @@ -874,6 +877,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook MenuItem selectedFontSizeMenuItem; // Prepare the font size title and current size menu item. + //noinspection DuplicateBranchesInSwitch switch (fontSize) { case 25: fontSizeTitle = getString(R.string.font_size) + " - " + getString(R.string.twenty_five_percent); @@ -1811,9 +1815,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the previous entry URL. String previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() - 1).getUrl(); - // Reset the current domain name so that navigation works if third-party requests are blocked. - currentWebView.resetCurrentDomainName(); - // Apply the domain settings. applyDomainSettings(currentWebView, previousUrl, false, false); @@ -1830,9 +1831,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the next entry URL. String nextUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() + 1).getUrl(); - // Reset the current domain name so that navigation works if third-party requests are blocked. - currentWebView.resetCurrentDomainName(); - // Apply the domain settings. applyDomainSettings(currentWebView, nextUrl, false, false); @@ -1983,7 +1981,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { // Run the default commands. super.onConfigurationChanged(newConfig); @@ -2039,7 +2037,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add an Open in New Tab entry. menu.add(R.string.open_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { - // Load the link URL in a new tab. + // Load the link URL in a new tab and move to it. + addNewTab(linkUrl, true); + + // Consume the event. + return true; + }); + + // Add an Open in Background entry. + menu.add(R.string.open_in_background).setOnMenuItemClickListener((MenuItem item) -> { + // Load the link URL in a new tab but do not move to it. addNewTab(linkUrl, false); // Consume the event. @@ -2167,7 +2174,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add an Open in New Tab entry. menu.add(R.string.open_image_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { // Load the image in a new tab. - addNewTab(imageUrl, false); + addNewTab(imageUrl, true); // Consume the event. return true; @@ -2273,7 +2280,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add an Open in New Tab entry. menu.add(R.string.open_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { - // Load the link URL in a new tab. + // Load the link URL in a new tab and move to it. + addNewTab(linkUrl, true); + + // Consume the event. + return true; + }); + + // Add an Open in Background entry. + menu.add(R.string.open_in_background).setOnMenuItemClickListener((MenuItem item) -> { + // Lod the link URL in a new tab but do not move to it. addNewTab(linkUrl, false); // Consume the event. @@ -2282,8 +2298,8 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add an Open Image in New Tab entry. menu.add(R.string.open_image_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { - // Load the image in a new tab. - addNewTab(imageUrl, false); + // Load the image in a new tab and move to it. + addNewTab(imageUrl, true); // Consume the event. return true; @@ -2374,9 +2390,15 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get a handle for the bookmarks list view. ListView bookmarksListView = findViewById(R.id.bookmarks_drawer_listview); + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + // Get the views from the dialog fragment. - EditText createBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext); - EditText createBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext); + EditText createBookmarkNameEditText = dialog.findViewById(R.id.create_bookmark_name_edittext); + EditText createBookmarkUrlEditText = dialog.findViewById(R.id.create_bookmark_url_edittext); // Extract the strings from the edit texts. String bookmarkNameString = createBookmarkNameEditText.getText().toString(); @@ -2412,10 +2434,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get a handle for the bookmarks list view. ListView bookmarksListView = findViewById(R.id.bookmarks_drawer_listview); + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + // Get handles for the views in the dialog fragment. - EditText createFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext); - RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton); - ImageView folderIconImageView = dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon); + EditText createFolderNameEditText = dialog.findViewById(R.id.create_folder_name_edittext); + RadioButton defaultFolderIconRadioButton = dialog.findViewById(R.id.create_folder_default_icon_radiobutton); + ImageView folderIconImageView = dialog.findViewById(R.id.create_folder_default_icon); // Get new folder name string. String folderNameString = createFolderNameEditText.getText().toString(); @@ -2468,10 +2496,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook @Override public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, Bitmap favoriteIconBitmap) { - // Get handles for the views from `dialogFragment`. - EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext); - EditText editBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext); - RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton); + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + + // Get handles for the views from the dialog. + EditText editBookmarkNameEditText = dialog.findViewById(R.id.edit_bookmark_name_edittext); + EditText editBookmarkUrlEditText = dialog.findViewById(R.id.edit_bookmark_url_edittext); + RadioButton currentBookmarkIconRadioButton = dialog.findViewById(R.id.edit_bookmark_current_icon_radiobutton); // Store the bookmark strings. String bookmarkNameString = editBookmarkNameEditText.getText().toString(); @@ -2503,11 +2537,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook @Override public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedFolderDatabaseId, Bitmap favoriteIconBitmap) { + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + // Get handles for the views from `dialogFragment`. - EditText editFolderNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext); - RadioButton currentFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton); - RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton); - ImageView defaultFolderIconImageView = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_imageview); + EditText editFolderNameEditText = dialog.findViewById(R.id.edit_folder_name_edittext); + RadioButton currentFolderIconRadioButton = dialog.findViewById(R.id.edit_folder_current_icon_radiobutton); + RadioButton defaultFolderIconRadioButton = dialog.findViewById(R.id.edit_folder_default_icon_radiobutton); + ImageView defaultFolderIconImageView = dialog.findViewById(R.id.edit_folder_default_icon_imageview); // Get the new folder name. String newFolderNameString = editFolderNameEditText.getText().toString(); @@ -2675,8 +2715,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook downloadRequest.addRequestHeader("Cookie", cookies); } + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + // Get the file name from the dialog fragment. - EditText downloadImageNameEditText = dialogFragment.getDialog().findViewById(R.id.download_image_name); + EditText downloadImageNameEditText = dialog.findViewById(R.id.download_image_name); String imageName = downloadImageNameEditText.getText().toString(); // Specify the download location. @@ -2730,8 +2776,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook downloadRequest.addRequestHeader("Cookie", cookies); } - // Get the file name from the dialog fragment. - EditText downloadFileNameEditText = dialogFragment.getDialog().findViewById(R.id.download_file_name); + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + + // Get the file name from the dialog. + EditText downloadFileNameEditText = dialog.findViewById(R.id.download_file_name); String fileName = downloadFileNameEditText.getText().toString(); // Specify the download location. @@ -2783,6 +2835,77 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Load the new folder. loadBookmarksFolder(); } + } else if (displayingFullScreenVideo) { // A full screen video is shown. + // Get a handle for the layouts. + FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout); + RelativeLayout mainContentRelativeLayout = findViewById(R.id.main_content_relativelayout); + FrameLayout fullScreenVideoFrameLayout = findViewById(R.id.full_screen_video_framelayout); + + // Re-enable the screen timeout. + fullScreenVideoFrameLayout.setKeepScreenOn(false); + + // Unset the full screen video flag. + displayingFullScreenVideo = false; + + // Remove all the views from the full screen video frame layout. + fullScreenVideoFrameLayout.removeAllViews(); + + // Hide the full screen video frame layout. + fullScreenVideoFrameLayout.setVisibility(View.GONE); + + // Enable the sliding drawers. + drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); + + // Show the main content relative layout. + mainContentRelativeLayout.setVisibility(View.VISIBLE); + + // Apply the appropriate full screen mode flags. + if (fullScreenBrowsingModeEnabled && inFullScreenBrowsingMode) { // Privacy Browser is currently in full screen browsing mode. + // Hide the app bar if specified. + if (hideAppBar) { + // Get handles for the views. + LinearLayout tabsLinearLayout = findViewById(R.id.tabs_linearlayout); + ActionBar actionBar = getSupportActionBar(); + + // Remove the incorrect lint warning below that the action bar might be null. + assert actionBar != null; + + // Hide the tab linear layout. + tabsLinearLayout.setVisibility(View.GONE); + + // Hide the action bar. + actionBar.hide(); + } + + // Hide the banner ad in the free flavor. + if (BuildConfig.FLAVOR.contentEquals("free")) { + AdHelper.hideAd(findViewById(R.id.adview)); + } + + // Remove the translucent status flag. This is necessary so the root frame layout can fill the entire screen. + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + + /* Hide the system bars. + * SYSTEM_UI_FLAG_FULLSCREEN hides the status bar at the top of the screen. + * SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN makes the root frame layout fill the area that is normally reserved for the status bar. + * SYSTEM_UI_FLAG_HIDE_NAVIGATION hides the navigation bar on the bottom or right of the screen. + * SYSTEM_UI_FLAG_IMMERSIVE_STICKY makes the status and navigation bars translucent and automatically re-hides them after they are shown. + */ + rootFrameLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + } else { // Switch to normal viewing mode. + // Remove the `SYSTEM_UI` flags from the root frame layout. + rootFrameLayout.setSystemUiVisibility(0); + + // Add the translucent status flag. + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + } + + // Reload the ad for the free flavor if not in full screen mode. + if (BuildConfig.FLAVOR.contentEquals("free") && !inFullScreenBrowsingMode) { + // Reload the ad. + AdHelper.loadAd(findViewById(R.id.adview), getApplicationContext(), getString(R.string.ad_unit_id)); + } } else if (currentWebView.canGoBack()) { // There is at least one item in the current WebView history. // Get the current web back forward list. WebBackForwardList webBackForwardList = currentWebView.copyBackForwardList(); @@ -2790,9 +2913,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the previous entry URL. String previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() - 1).getUrl(); - // Reset the current domain name so that navigation works if third-party requests are blocked. - currentWebView.resetCurrentDomainName(); - // Apply the domain settings. applyDomainSettings(currentWebView, previousUrl, false, false); @@ -2802,8 +2922,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Close the current tab. closeCurrentTab(); } else { // There isn't anything to do in Privacy Browser. - // Run the default commands. - super.onBackPressed(); + // Close Privacy Browser. `finishAndRemoveTask()` also removes Privacy Browser from the recent app list. + if (Build.VERSION.SDK_INT >= 21) { + finishAndRemoveTask(); + } else { + finish(); + } // Manually kill Privacy Browser. Otherwise, it is glitchy when restarted. System.exit(0); @@ -2813,6 +2937,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Process the results of a file browse. @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + // Run the default commands. + super.onActivityResult(requestCode, resultCode, data); + // Run the commands that correlate to the specified request code. switch (requestCode) { case FILE_UPLOAD_REQUEST_CODE: @@ -2834,17 +2961,23 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get a handle for the save webpage image dialog. Dialog saveWebpageImageDialog = saveWebpageImageDialogFragment.getDialog(); + // Remove the incorrect lint warning below that the dialog might be null. + assert saveWebpageImageDialog != null; + // Get a handle for the file name edit text. EditText fileNameEditText = saveWebpageImageDialog.findViewById(R.id.file_name_edittext); // Instantiate the file name helper. FileNameHelper fileNameHelper = new FileNameHelper(); - // Convert the file name URI to a file name path. - String fileNamePath = fileNameHelper.convertUriToFileNamePath(data.getData()); + // Get the file path if it isn't null. + if (data.getData() != null) { + // Convert the file name URI to a file name path. + String fileNamePath = fileNameHelper.convertUriToFileNamePath(data.getData()); - // Set the file name path as the text of the file name edit text. - fileNameEditText.setText(fileNamePath); + // Set the file name path as the text of the file name edit text. + fileNameEditText.setText(fileNamePath); + } } } break; @@ -2974,8 +3107,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook @Override public void onSaveWebpageImage(DialogFragment dialogFragment) { + // Get the dialog. + Dialog dialog = dialogFragment.getDialog(); + + // Remove the incorrect lint warning below that the dialog might be null. + assert dialog != null; + // Get a handle for the file name edit text. - EditText fileNameEditText = dialogFragment.getDialog().findViewById(R.id.file_name_edittext); + EditText fileNameEditText = dialog.findViewById(R.id.file_name_edittext); // Get the file path string. saveWebsiteImageFilePath = fileNameEditText.getText().toString(); @@ -3616,9 +3755,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook @Override public void navigateHistory(String url, int steps) { - // Reset the current domain name so that navigation works if third-party requests are blocked. - currentWebView.resetCurrentDomainName(); - // Apply the domain settings. applyDomainSettings(currentWebView, url, false, false); @@ -3634,9 +3770,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the previous entry URL. String previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() - 1).getUrl(); - // Reset the current domain name so that navigation works if third-party requests are blocked. - currentWebView.resetCurrentDomainName(); - // Apply the domain settings. applyDomainSettings(currentWebView, previousUrl, false, false); @@ -5252,6 +5385,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Show the full screen video frame layout. fullScreenVideoFrameLayout.setVisibility(View.VISIBLE); + + // Disable the screen timeout while the video is playing. YouTube does this automatically, but not all other videos do. + fullScreenVideoFrameLayout.setKeepScreenOn(true); } // Exit full screen video. @@ -5260,6 +5396,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get a handle for the full screen video frame layout. FrameLayout fullScreenVideoFrameLayout = findViewById(R.id.full_screen_video_framelayout); + // Re-enable the screen timeout. + fullScreenVideoFrameLayout.setKeepScreenOn(false); + // Unset the full screen video flag. displayingFullScreenVideo = false;