import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDialogFragment;
+import android.support.v7.widget.Toolbar;
import android.util.Patterns;
import android.view.KeyEvent;
import android.view.Menu;
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 {
// favoriteIcon is public static so it can be accessed from CreateHomeScreenShortcut.
public static Bitmap favoriteIcon;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
+ Toolbar toolbar = (Toolbar) findViewById(R.id.appBar);
+ setSupportActionBar(toolbar);
final FrameLayout fullScreenVideoFrameLayout = (FrameLayout) findViewById(R.id.fullScreenVideoFrameLayout);
final Activity mainWebViewActivity = this;
- final ActionBar actionBar = getSupportActionBar();
+ // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21.
+ final ActionBar appBar = getSupportActionBar();
mainWebView = (WebView) findViewById(R.id.mainWebView);
- if (actionBar != null) {
- // Remove the title from the action bar.
- actionBar.setDisplayShowTitleEnabled(false);
+ if (appBar != null) {
+ // Remove the title from the app bar.
+ appBar.setDisplayShowTitleEnabled(false);
- // Add the custom app_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar.
- actionBar.setCustomView(R.layout.app_bar);
- actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+ // Add the custom url_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar.
+ appBar.setCustomView(R.layout.url_bar);
+ appBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// Set the "go" button on the keyboard to load the URL in urlTextBox.
- urlTextBox = (EditText) actionBar.getCustomView().findViewById(R.id.urlTextBox);
+ urlTextBox = (EditText) appBar.getCustomView().findViewById(R.id.urlTextBox);
urlTextBox.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button, load the URL.
// Update the progress bar when a page is loading.
@Override
public void onProgressChanged(WebView view, int progress) {
- // Make sure that actionBar is not null.
- if (actionBar != null) {
- ProgressBar progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar);
+ // Make sure that appBar is not null.
+ if (appBar != null) {
+ ProgressBar progressBar = (ProgressBar) appBar.getCustomView().findViewById(R.id.progressBar);
progressBar.setProgress(progress);
if (progress < 100) {
progressBar.setVisibility(View.VISIBLE);
// Save a copy of the favorite icon for use if a shortcut is added to the home screen.
favoriteIcon = icon;
- // Place the favorite icon in the actionBar if it is not null.
- if (actionBar != null) {
- ImageView imageViewFavoriteIcon = (ImageView) actionBar.getCustomView().findViewById(R.id.favoriteIcon);
+ // Place the favorite icon in the appBar if it is not null.
+ if (appBar != null) {
+ ImageView imageViewFavoriteIcon = (ImageView) appBar.getCustomView().findViewById(R.id.favoriteIcon);
imageViewFavoriteIcon.setImageBitmap(Bitmap.createScaledBitmap(icon, 64, 64, true));
}
}
// Enter full screen video
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
- if (actionBar != null) {
- actionBar.hide();
+ if (appBar != null) {
+ appBar.hide();
}
fullScreenVideoFrameLayout.addView(view);
// Exit full screen video
public void onHideCustomView() {
- if (actionBar != null) {
- actionBar.show();
+ if (appBar != null) {
+ appBar.show();
}
mainWebView.setVisibility(View.VISIBLE);
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright 2015 Soren Stoutner <soren@stoutner.com>.
+ Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
This file is part of Privacy Browser <https://privacybrowser.stoutner.com/>.
<RelativeLayout
android:id="@+id/rootRelativeLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <WebView
- android:id="@+id/mainWebView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:focusable="true"
- android:focusableInTouchMode="true" />
-
- <!-- fullScreenVideoFrameLayout is used to display full screen videos. It is initially android:visibility="gone" to hide it from view. -->
- <FrameLayout
- android:id="@+id/fullScreenVideoFrameLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone"
- android:background="#000000" />
-
+ android:layout_height="match_parent" >
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/appBar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:background="?attr/colorPrimary"
+ android:elevation="4dp"
+ android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
+ app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
+
+ <WebView
+ android:id="@+id/mainWebView"
+ android:layout_below="@id/appBar"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:focusable="true"
+ android:focusableInTouchMode="true" />
+
+ <!-- fullScreenVideoFrameLayout is used to display full screen videos. It is initially android:visibility="gone" to hide it from view. -->
+ <FrameLayout
+ android:id="@+id/fullScreenVideoFrameLayout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone"
+ android:background="@color/black" />
</RelativeLayout>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
- Copyright 2015 Soren Stoutner <soren@stoutner.com>.
-
- This file is part of Privacy Browser <https://privacybrowser.stoutner.com/>.
-
- Privacy Browser is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Privacy Browser is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>. -->
-
-<!-- FrameLayout lets the ProgressBar float on top of urlTextBox. -->
-<FrameLayout
- android:id="@+id/addressBarFrameLayout"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <LinearLayout
- android:id="@+id/addressBarLinearLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
-
- <!-- Set the program icon as the initial favoriteIcon. -->
- <ImageView
- android:id="@+id/favoriteIcon"
- android:src="@drawable/ic_language_black_24dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:contentDescription="@string/favorite_icon"/>
-
- <!-- android:imeOptions="actionGo" sets the keyboard to have a "go" key instead of a "new line" key. -->
- <!-- android:inputType="textUri" disables spell check in the EditText and changes the "go" key from a check mark to an arrow. -->
- <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
- <EditText
- android:id="@+id/urlTextBox"
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:imeOptions="actionGo"
- android:inputType="textUri" />
- </LinearLayout>
-
- <!-- android:max changes the maximum ProgressBar value from 10000 to 100 to match progress percentage. -->
- <!-- android:layout_height="2dp" works best for API 23 "Marshmallow", but "3dp" is required for visibility on API <= 22. -->
- <ProgressBar
- android:id="@+id/progressBar"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="fill_parent"
- android:layout_height="3dp"
- android:layout_gravity="bottom"
- android:max="100"
- android:progressTint="#FF0097FF"
- android:progressBackgroundTint="#FFFFFFFF"
- android:visibility="gone" />
-</FrameLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright 2015 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser <https://privacybrowser.stoutner.com/>.
+
+ Privacy Browser is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Privacy Browser is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>. -->
+
+<!-- FrameLayout lets the ProgressBar float on top of urlTextBox. -->
+<FrameLayout
+ android:id="@+id/addressBarFrameLayout"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:id="@+id/addressBarLinearLayout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <!-- Set the program icon as the initial favoriteIcon. -->
+ <ImageView
+ android:id="@+id/favoriteIcon"
+ android:src="@drawable/ic_language_black_24dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:contentDescription="@string/favorite_icon"/>
+
+ <!-- android:imeOptions="actionGo" sets the keyboard to have a "go" key instead of a "new line" key. -->
+ <!-- android:inputType="textUri" disables spell check in the EditText and changes the "go" key from a check mark to an arrow. -->
+ <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
+ <EditText
+ android:id="@+id/urlTextBox"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:imeOptions="actionGo"
+ android:inputType="textUri" />
+ </LinearLayout>
+
+ <!-- android:max changes the maximum ProgressBar value from 10000 to 100 to match progress percentage. -->
+ <!-- android:layout_height="2dp" works best for API 23 "Marshmallow", but "3dp" is required for visibility on API <= 22. -->
+ <ProgressBar
+ android:id="@+id/progressBar"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="3dp"
+ android:layout_gravity="bottom"
+ android:max="100"
+ android:progressTint="@color/light_blue"
+ android:progressBackgroundTint="@color/white"
+ android:visibility="gone" />
+</FrameLayout>
\ No newline at end of file
<!-- These color resources are hardcoded for vector drawables. Once the minimum API is >= 22 we can remove the hardcoded colors and reference these entries. -->
<resources>
+ <color name="black">#FF000000</color>
+ <color name="light_blue">#FF0091EA</color>
<color name="green">#FF64DD17</color>
<color name="red">#FFD50000</color>
+ <color name="white">#FFFFFFFF</color>
<color name="yellow">#FFFFD600</color>
</resources>
\ No newline at end of file
<resources>
- <!-- Base application theme. -->
- <style name="AppTheme" parent="Theme.AppCompat.Light">
- <!-- Customize style here. -->
+ <!-- We want to use .NoActionBar so that we can set a SupportActionBar. -->
+ <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
+ <item name="colorAccent">@color/light_blue</item>
</style>
</resources>