]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Implement SwipeToRefresh for real this time.
authorSoren Stoutner <soren@stoutner.com>
Thu, 18 Feb 2016 05:08:48 +0000 (22:08 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 18 Feb 2016 05:08:48 +0000 (22:08 -0700)
12 files changed:
.idea/dictionaries/soren.xml
app/app.iml
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
app/src/main/res/layout/activity_webview.xml
app/src/main/res/layout/url_bar.xml
app/src/main/res/menu/menu_webview.xml
app/src/main/res/values-v11/styles.xml [new file with mode: 0644]
app/src/main/res/values/colors.xml
app/src/main/res/values/styles.xml
app/src/main/res/xml/preferences.xml

index 03413eaa50e94ae2e6e13c3377a52fb87a04ea01..db1251c78a21a42106df1f81bc153f7d6d081d22 100644 (file)
@@ -2,6 +2,7 @@
   <dictionary name="soren">
     <words>
       <w>duckduckgo</w>
+      <w>privacybrowser</w>
       <w>rehide</w>
       <w>rehides</w>
       <w>soren</w>
index c752c86a839ede0fad62db22af07b24cef1aed9f..41cbfa77da6e42f35f77ed30285f8161595b18de 100644 (file)
@@ -71,6 +71,8 @@
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.1.1/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
     </content>
     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
     <orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
     <orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
+    <orderEntry type="library" exported="" name="design-23.1.1" level="project" />
     <orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
   </component>
 </module>
\ No newline at end of file
index b5963c25c906b083c2497e2f012aaf4085200ba1..f741400ba6a7ef18876bcd319141f5fea6db7fdb 100644 (file)
@@ -23,4 +23,6 @@ android {
 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:23.1.1'
+    compile 'com.android.support:design:23.1.1'
+    compile 'com.android.support:support-v4:23.1.1'
 }
index bcf0270f8f22aee9c4cc08f080eb7a6f81c84f6b..febfeaf636afaf302b900819a2ca3959159eefd9 100644 (file)
@@ -26,6 +26,7 @@
     <!-- Required to create homescreen shortcuts. -->
     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 
+    <!-- on API >= 23, app data is automatically backed up to Google cloud servers unless android:allowBackup="false" and android:fullBackupContent="false" is set. -->
     <application
         android:allowBackup="false"
         android:fullBackupContent="false"
@@ -40,7 +41,8 @@
             android:name=".MainWebViewActivity"
             android:configChanges="orientation|screenSize"
             android:label="@string/privacy_browser"
-            android:launchMode="singleTask">
+            android:launchMode="singleTask"
+            android:theme="@style/AppTheme.NoActionBar">
 
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
index 5d2307338092869f09aa82b47f3a7f3273772dfd..7f49a6cd9083047d6a09a446d76a16a67c3a4789 100644 (file)
@@ -31,6 +31,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.v4.app.DialogFragment;
+import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.app.AppCompatDialogFragment;
@@ -40,7 +41,6 @@ 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;
@@ -90,14 +90,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
     private EditText urlTextBox;
 
     @Override
-    // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.
+    // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.  The whole premise of Privacy Browser is built around an understanding of these dangers.
     @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);
 
@@ -110,19 +105,19 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
         // 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 (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);
+        // Implement swipe to refresh
+        final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
+        swipeToRefresh.setColorSchemeResources(R.color.blue);
+        swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+            @Override
+            public void onRefresh() {
+                mainWebView.reload();
             }
-            */
+        });
 
-            // Remove the title from the app bar.
-            appBar.setDisplayShowTitleEnabled(false);
+        mainWebView = (WebView) findViewById(R.id.mainWebView);
 
+        if (appBar != null) {
             // 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);
@@ -189,6 +184,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                         progressBar.setVisibility(View.VISIBLE);
                     } else {
                         progressBar.setVisibility(View.GONE);
+
+                        //Stop the SwipeToRefresh indicator if it is running
+                        swipeToRefresh.setRefreshing(false);
                     }
                 }
             }
@@ -340,6 +338,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
 
         // Load the website.
         mainWebView.loadUrl(formattedUrlString);
+
+        // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it.
+        mainWebView.requestFocus();
     }
 
     @Override
@@ -563,10 +564,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                 mainWebView.loadUrl(homepage);
                 return true;
 
-            case R.id.refresh:
-                mainWebView.reload();
-                return true;
-
             case R.id.back:
                 mainWebView.goBack();
                 return true;
index f50c39956a040b144652346e8038e0b82028b638..d90adc7c4ceba0b679f350adee7a4b68a2c2fa00 100644 (file)
   along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
 
 <!-- Setting the layout root to be focusableInTouchMode prevents urlTextBox from stealing focus on launch and opening the keyboard. -->
-<RelativeLayout
-    android:id="@+id/rootRelativeLayout"
+<android.support.design.widget.CoordinatorLayout
+    android:id="@+id/rootCoordinatorLayout"
     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="com.stoutner.privacybrowser.MainWebViewActivity"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:focusable="true"
     android:focusableInTouchMode="true" >
 
-    <android.support.v7.widget.Toolbar
-        android:id="@+id/appBar"
+    <android.support.design.widget.AppBarLayout
+        android:id="@+id/appBarLayout"
         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_height="wrap_content"
+        android:theme="@style/AppTheme.AppBarOverlay" >
+
+        <android.support.v7.widget.Toolbar
+            android:id="@+id/appBar"
+            android:layout_width="match_parent"
+            android:layout_height="?attr/actionBarSize"
+            android:background="?attr/colorPrimary"
+            app:popupTheme="@style/AppTheme.PopupOverlay" />
+    </android.support.design.widget.AppBarLayout>
+
+    <!-- android:layout_martinTop="?attr/actionBarSize" moves the SwipeRefreshLayout below the AppBarLayout, which otherwise would cover the top of the WebView. -->
+    <android.support.v4.widget.SwipeRefreshLayout
+        android:id="@+id/swipeRefreshLayout"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:focusable="true"
-        android:focusableInTouchMode="true" />
+        android:layout_marginTop="?attr/actionBarSize">
+
+        <!-- Google does not currently want to support hiding the AppBar on scroll for a WebView child with the Support Toolbar.  https://code.google.com/p/android/issues/detail?id=200394 -->
+        <WebView
+            android:id="@+id/mainWebView"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:focusable="true"
+            android:focusableInTouchMode="true"/>
+
+    </android.support.v4.widget.SwipeRefreshLayout>
 
     <!-- fullScreenVideoFrameLayout is used to display full screen videos.  It is initially android:visibility="gone" to hide it from view. -->
     <FrameLayout
@@ -51,4 +68,4 @@
         android:layout_height="match_parent"
         android:visibility="gone"
         android:background="@color/black" />
-</RelativeLayout>
+</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
index 2363375bf0a0c087825f949375dbee9e04fcc958..b5fd028f427be4118fa433742d925809dd639221 100644 (file)
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
+    <!-- RelativeLayout is used instead of a LinearLayout because supportAppBar does not let android:layout_weight="1" to cause urlTextBox to fill all the available space. -->
     <RelativeLayout
         android:id="@+id/addressBarRelativeLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
 
         <!-- Set the program icon as the initial favoriteIcon. -->
-        <!-- layout_width and layout_height of 28dp matches the appBar icons. -->
+        <!-- layout_width and layout_height of 26dp matches the AppBar icons. -->
         <ImageView
             android:id="@+id/favoriteIcon"
             android:src="@drawable/ic_language_black_24dp"
-            android:layout_width="28dp"
-            android:layout_height="28dp"
+            android:layout_width="26dp"
+            android:layout_height="26dp"
             android:layout_centerVertical="true"
             android:contentDescription="@string/favorite_icon"/>
 
@@ -62,7 +63,8 @@
         android:layout_height="3dp"
         android:layout_gravity="bottom"
         android:max="100"
-        android:progressTint="@color/light_blue"
+        android:progressTint="@color/blue"
         android:progressBackgroundTint="@color/white"
         android:visibility="gone" />
+
 </FrameLayout>
\ No newline at end of file
index eb964bf980f8f4cc8c4b138cd6378391abdb57c9..7ff39ecc4d299d23ec591ed8d8b71bfe222d8b59 100644 (file)
                 android:orderInCategory="91"
                 app:showAsAction="never" />
 
-            <item
-                android:id="@+id/refresh"
-                android:title="@string/refresh"
-                android:orderInCategory="92"
-                app:showAsAction="never" />
-
             <item
                 android:id="@+id/back"
                 android:title="@string/back"
-                android:orderInCategory="93"
+                android:orderInCategory="92"
                 app:showAsAction="never" />
 
             <item
                 android:id="@+id/forward"
                 android:title="@string/forward"
-                android:orderInCategory="94"
+                android:orderInCategory="93"
                 app:showAsAction="never" />
         </menu>
     </item>
diff --git a/app/src/main/res/values-v11/styles.xml b/app/src/main/res/values-v11/styles.xml
new file mode 100644 (file)
index 0000000..716ca04
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Copyright 2016 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/>. -->
+
+<resources>
+
+    <!-- android:actionBarSize is supported by API >= 11.  actionBarSize is for older versions. -->
+    <!-- The default actionBarSize is 56dp.  53dp is the smallest that doesn't cause the urlTextBox to scroll vertically with a font size of Huge. -->
+    <style name="AppTheme" parent="Theme.AppCompat.Light">
+        <item name="colorAccent">@color/blue</item>
+        <item name="android:actionBarSize">53dp</item>
+    </style>
+
+</resources>
\ No newline at end of file
index 8fe826ff91d8b33c29c9580d4e8ff08ecf3789d1..34a87076828c4d56bab40b793a6bcbace3a41c7f 100644 (file)
@@ -21,7 +21,7 @@
 <!-- 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="blue">#1e88e5</color>
     <color name="green">#FF64DD17</color>
     <color name="red">#FFD50000</color>
     <color name="white">#FFFFFFFF</color>
index a68cd81e1aef02258837ede585f57e0098cb91a0..35530837ea149313a73c69ea1e3ea8f539e69ef1 100644 (file)
 
 <resources>
 
-    <!-- We want to use .NoActionBar so that we can set a SupportActionBar. -->
     <!-- android:actionBarSize is supported by API >= 11.  actionBarSize is for older versions. -->
     <!-- The default actionBarSize is 56dp.  53dp is the smallest that doesn't cause the urlTextBox to scroll vertically with a font size of Huge. -->
-    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
-        <item name="colorAccent">@color/light_blue</item>
-        <item name="android:actionBarSize">53dp</item>
+    <style name="AppTheme" parent="Theme.AppCompat.Light">
+        <item name="colorAccent">@color/blue</item>
         <item name="actionBarSize">53dp</item>
     </style>
 
+    <style name="AppTheme.NoActionBar">
+        <item name="windowActionBar">false</item>
+        <item name="windowNoTitle">true</item>
+    </style>
+
+    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar" />
+
+    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
+
 </resources>
index 97965a5b66b05db2ace2d92e0976c80eab6b8c61..b56f932464784eb0040b654f4711e38cd931f972 100644 (file)
         android:key="privacy_settings"
         android:title="@string/privacy_settings" >
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="javascript_enabled"
             android:title="@string/javascript_preference"
             android:summary="@string/javascript_preference_summary"
             android:defaultValue="false" />
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="dom_storage_enabled"
             android:title="@string/dom_storage_preference"
             android:summary="@string/dom_storage_preference_summary"
             android:defaultValue="false" />
 
-        <CheckBoxPreference
+        <SwitchPreference
             android:key="cookies_enabled"
             android:title="@string/cookies_preference"
             android:summary="@string/cookies_preference_summary"
@@ -50,6 +50,7 @@
             android:key="homepage"
             android:title="@string/homepage_preference"
             android:summary="@string/homepage_preference_summary"
-            android:defaultValue="https://www.duckduckgo.com" />
+            android:defaultValue="https://www.duckduckgo.com"
+            android:singleLine="true"/>
     </PreferenceCategory>
 </PreferenceScreen>
\ No newline at end of file