From 81aeaac4229700db3255a6d6c02a8bda18b403e6 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 12 Feb 2016 22:18:43 -0700 Subject: [PATCH] Rename the activities. --- app/src/main/AndroidManifest.xml | 8 ++-- .../stoutner/privacybrowser/AboutDialog.java | 2 +- .../CreateHomeScreenShortcut.java | 2 +- ...nWebView.java => MainWebViewActivity.java} | 44 +++++++++++++------ .../{Settings.java => SettingsActivity.java} | 6 ++- app/src/main/res/menu/menu_webview.xml | 2 +- 6 files changed, 41 insertions(+), 23 deletions(-) rename app/src/main/java/com/stoutner/privacybrowser/{MainWebView.java => MainWebViewActivity.java} (95%) rename app/src/main/java/com/stoutner/privacybrowser/{Settings.java => SettingsActivity.java} (76%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5c5adf6e..bcf0270f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,7 +37,7 @@ @@ -58,14 +58,14 @@ + android:parentActivityName=".MainWebViewActivity" > + android:value=".MainWebViewActivity" /> diff --git a/app/src/main/java/com/stoutner/privacybrowser/AboutDialog.java b/app/src/main/java/com/stoutner/privacybrowser/AboutDialog.java index 44d3ac08..a488d0d0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/AboutDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/AboutDialog.java @@ -56,7 +56,7 @@ public class AboutDialog extends AppCompatDialogFragment { // shouldOverrideUrlLoading lets us close AboutDialog when a link is touched. Otherwise the dialog covers the website that loads beneath in Privacy Browser. @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - MainWebView.mainWebView.loadUrl(url); + MainWebViewActivity.mainWebView.loadUrl(url); alertDialog.dismiss(); return true; } diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java index 0d437e28..ac8b5284 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java @@ -60,7 +60,7 @@ public class CreateHomeScreenShortcut extends AppCompatDialogFragment { @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { // Create a drawable version of the favorite icon. - Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebView.favoriteIcon); + Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); // Use AlertDialog.Builder to create the AlertDialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java similarity index 95% rename from app/src/main/java/com/stoutner/privacybrowser/MainWebView.java rename to app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index daaa58a8..5d230733 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -23,9 +23,6 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.app.DownloadManager; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; @@ -43,6 +40,7 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.webkit.CookieManager; import android.webkit.DownloadListener; @@ -61,7 +59,7 @@ import java.net.URL; import java.net.URLEncoder; // 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 MainWebView extends AppCompatActivity implements CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener { +public class MainWebViewActivity extends AppCompatActivity implements CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener { // favoriteIcon is public static so it can be accessed from CreateHomeScreenShortcut. public static Bitmap favoriteIcon; // mainWebView is public static so it can be accessed from AboutDialog. It is also used in onCreate(), onOptionsItemSelected(), and loadUrlFromTextBox(). @@ -95,10 +93,17 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled. @SuppressLint("SetJavaScriptEnabled") protected void onCreate(Bundle savedInstanceState) { + // Window.FEATURE_ACTION_BAR_OVERLAY must be enabled to set the app bar to HideOnContentScroll. It must be set before any content is added to the activity. + if (Build.VERSION.SDK_INT >= 11) { + requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); + } + super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); - Toolbar toolbar = (Toolbar) findViewById(R.id.appBar); - setSupportActionBar(toolbar); + + // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21. + Toolbar supportAppBar = (Toolbar) findViewById(R.id.appBar); + setSupportActionBar(supportAppBar); final FrameLayout fullScreenVideoFrameLayout = (FrameLayout) findViewById(R.id.fullScreenVideoFrameLayout); final Activity mainWebViewActivity = this; @@ -108,6 +113,13 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh mainWebView = (WebView) findViewById(R.id.mainWebView); if (appBar != null) { + /* TODO Enable app bar scrolling. + // Scroll the app bar, but only if the API supports overlay mode (>= 11). + if (Build.VERSION.SDK_INT >= 11) { + appBar.setHideOnContentScrollEnabled(true); + } + */ + // Remove the title from the app bar. appBar.setDisplayShowTitleEnabled(false); @@ -572,8 +584,8 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh return true; case R.id.settings: - // Start the Settings activity. - Intent intent = new Intent(this, Settings.class); + // Launch SettingsActivity. + Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); return true; @@ -588,18 +600,22 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh WebStorage domStorage = WebStorage.getInstance(); domStorage.deleteAllData(); - // Clear cookies. - if (Build.VERSION.SDK_INT < 21) { - cookieManager.removeAllCookie(); - } else { + // Clear cookies. The commands changed slightly in API 21. + if (Build.VERSION.SDK_INT >= 21) { cookieManager.removeAllCookies(null); + } else { + cookieManager.removeAllCookie(); } // Destroy the internal state of the webview. mainWebView.destroy(); - // Close Privacy Browser. - finish(); + // Close Privacy Browser. finishAndRemoveTask also removes Privacy Browser from the recent app list. + if (Build.VERSION.SDK_INT >= 21) { + finishAndRemoveTask(); + } else { + finish(); + } return true; default: diff --git a/app/src/main/java/com/stoutner/privacybrowser/Settings.java b/app/src/main/java/com/stoutner/privacybrowser/SettingsActivity.java similarity index 76% rename from app/src/main/java/com/stoutner/privacybrowser/Settings.java rename to app/src/main/java/com/stoutner/privacybrowser/SettingsActivity.java index a1044a68..287237be 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/Settings.java +++ b/app/src/main/java/com/stoutner/privacybrowser/SettingsActivity.java @@ -21,10 +21,12 @@ package com.stoutner.privacybrowser; import android.os.Bundle; import android.preference.PreferenceActivity; +import android.support.v7.widget.Toolbar; -public class Settings extends PreferenceActivity { +// Once the minimum API is >= 11 we can switch from the deprecated PreferenceActivity to using a PreferenceFragment. +public class SettingsActivity extends PreferenceActivity { @Override - // Once the minimum API is >= 11 we can switch from the deprecated PreferenceActivity to using a PreferenceFragment. + // Until minumum API is >= 11 we needs to use the deprecated addPreferenceFromResource from PreferenceActivity. @SuppressWarnings("deprecation") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/res/menu/menu_webview.xml b/app/src/main/res/menu/menu_webview.xml index 92bd7c2f..eb964bf9 100644 --- a/app/src/main/res/menu/menu_webview.xml +++ b/app/src/main/res/menu/menu_webview.xml @@ -22,7 +22,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - tools:context=".MainWebView"> + tools:context=".MainWebViewActivity">