X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FMainWebViewActivity.java;h=077aa49b06e665b4c3cb7cafa72481f7ca3ebe44;hb=ac6db897f8e99a28a7e2d916238fbdf7a021ac55;hp=25b70df8a098ec271ae6d1d1e1e803997fe1212b;hpb=e1867a88b6aa53cc1adf63c95960ee02c81fc2ff;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index 25b70df8..077aa49b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -62,6 +62,7 @@ import android.view.inputmethod.InputMethodManager; import android.webkit.CookieManager; import android.webkit.DownloadListener; import android.webkit.SslErrorHandler; +import android.webkit.WebBackForwardList; import android.webkit.WebChromeClient; import android.webkit.WebStorage; import android.webkit.WebView; @@ -84,7 +85,7 @@ import java.util.Map; // We need to use AppCompatActivity from android.support.v7.app.AppCompatActivity to have access to the SupportActionBar until the minimum API is >= 21. public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener, - SslCertificateError.SslCertificateErrorListener, DownloadFile.DownloadFileListener, DownloadImage.DownloadImageListener { + SslCertificateError.SslCertificateErrorListener, DownloadFile.DownloadFileListener, DownloadImage.DownloadImageListener, UrlHistory.UrlHistoryListener { // `appBar` is public static so it can be accessed from `OrbotProxyHelper`. // It is also used in `onCreate()`, `onOptionsItemSelected()`, and `closeFindOnPage()`. @@ -283,7 +284,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Create the navigation drawer. drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); - // The `DrawerTitle` identifies the drawer in accessibility mode. + // `DrawerTitle` identifies the drawer in accessibility mode. drawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.navigation_drawer)); // Listen for touches on the navigation menu. @@ -294,6 +295,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation final Menu navigationMenu = navigationView.getMenu(); final MenuItem navigationBackMenuItem = navigationMenu.getItem(1); final MenuItem navigationForwardMenuItem = navigationMenu.getItem(2); + final MenuItem navigationHistoryMenuItem = navigationMenu.getItem(3); // The `DrawerListener` allows us to update the Navigation Menu. drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { @@ -311,9 +313,13 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation @Override public void onDrawerStateChanged(int newState) { - // Update the back and forward menu items every time the drawer opens. + // Update the `Back`, `Forward`, and `History` menu items every time the drawer opens. navigationBackMenuItem.setEnabled(mainWebView.canGoBack()); navigationForwardMenuItem.setEnabled(mainWebView.canGoForward()); + navigationHistoryMenuItem.setEnabled((mainWebView.canGoBack() || mainWebView.canGoForward())); + + // Hide the keyboard so we can see the navigation menu. `0` indicates no additional flags. + inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0); } }); @@ -875,7 +881,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation return true; case R.id.addToHomescreen: - // Show the `CreateHomeScreenShortcut` `AlertDialog` and name this instance `@string/create_shortcut`. + // Show the `CreateHomeScreenShortcut` `AlertDialog` and name this instance `R.string.create_shortcut`. AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcut(); createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.create_shortcut)); @@ -926,6 +932,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } break; + case R.id.history: + // Gte the `WebBackForwardList`. + WebBackForwardList webBackForwardList = mainWebView.copyBackForwardList(); + + // Show the `UrlHistory` `AlertDialog` and name this instance `R.string.history`. `this` is the `Context`. + AppCompatDialogFragment urlHistoryDialogFragment = UrlHistory.loadBackForwardList(this, webBackForwardList); + urlHistoryDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.history)); + break; + case R.id.bookmarks: // Launch BookmarksActivity. Intent bookmarksIntent = new Intent(this, BookmarksActivity.class); @@ -1267,6 +1282,18 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation sslErrorHandler.proceed(); } + @Override + public void onUrlHistoryEntrySelected(int moveBackOrForwardSteps) { + // Load the history entry. + mainWebView.goBackOrForward(moveBackOrForwardSteps); + } + + @Override + public void onClearHistory() { + // Clear the history. + mainWebView.clearHistory(); + } + // Override onBackPressed to handle the navigation drawer and mainWebView. @Override public void onBackPressed() { @@ -1288,6 +1315,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation @Override public void onPause() { + // Pause `mainWebView`. + mainWebView.onPause(); + mainWebView.pauseTimers(); + // We need to pause the adView or it will continue to consume resources in the background on the free flavor. BannerAd.pauseAd(adView); @@ -1298,6 +1329,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation public void onResume() { super.onResume(); + // Resume `mainWebView`. + mainWebView.resumeTimers(); + mainWebView.onResume(); + // We need to resume the adView for the free flavor. BannerAd.resumeAd(adView); } @@ -1358,7 +1393,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation mainWebView.loadUrl(formattedUrlString, customHeaders); - // Hides the keyboard so we can see the webpage. `0` indicates no additional flags. + // Hide the keyboard so we can see the webpage. `0` indicates no additional flags. inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0); } @@ -1387,7 +1422,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation Toolbar appBarToolbar = (Toolbar) findViewById(R.id.appBar); appBarToolbar.setVisibility(View.VISIBLE); - // Hides the keyboard so we can see the webpage. `0` indicates no additional flags. + // Hide the keyboard so we can see the webpage. `0` indicates no additional flags. inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0); }