From: Soren Stoutner <soren@stoutner.com>
Date: Thu, 12 Nov 2015 03:16:58 +0000 (-0700)
Subject: Remove swipe to refresh and add app bar scrolling (which appear to not be compatible... 
X-Git-Tag: v1.0~31
X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=828458a749772bd036f9e2747bd9f6bf9c468691;p=PrivacyBrowserAndroid.git

Remove swipe to refresh and add app bar scrolling (which appear to not be compatible when using a webview).  Add a refresh menu entry.
---

diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml
index 750cd221..5c98ab4c 100644
--- a/.idea/dictionaries/soren.xml
+++ b/.idea/dictionaries/soren.xml
@@ -2,6 +2,7 @@
   <dictionary name="soren">
     <words>
       <w>duckduckgo</w>
+      <w>webview</w>
     </words>
   </dictionary>
 </component>
\ No newline at end of file
diff --git a/app/app.iml b/app/app.iml
index 84d6657d..c4326d48 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -71,8 +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/dex-cache" />
-      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
-      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
@@ -90,8 +90,8 @@
     </content>
     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
-    <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
-    <orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
+    <orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
+    <orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
+    <orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
   </component>
 </module>
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 5fb35bdb..1f926caa 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
 
 android {
     compileSdkVersion 23
-    buildToolsVersion "23.0.1"
+    buildToolsVersion "23.0.2"
 
     defaultConfig {
         applicationId "com.stoutner.privacybrowser"
@@ -21,5 +21,5 @@ android {
 
 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
-    compile 'com.android.support:appcompat-v7:23.0.1'
+    compile 'com.android.support:appcompat-v7:23.1.0'
 }
diff --git a/app/src/main/java/com/stoutner/privacybrowser/Webview.java b/app/src/main/java/com/stoutner/privacybrowser/Webview.java
index 7b0cf306..ff718ff9 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/Webview.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/Webview.java
@@ -6,16 +6,14 @@ import android.content.Intent;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Bundle;
-import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+import android.support.v7.app.AppCompatDelegate;
 import android.util.Patterns;
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
-import android.view.ViewTreeObserver;
-import android.view.Window;
 import android.view.inputmethod.InputMethodManager;
 import android.webkit.WebChromeClient;
 import android.webkit.WebView;
@@ -33,10 +31,9 @@ public class Webview extends AppCompatActivity {
     static String formattedUrlString;
     static WebView mainWebView;
     static ProgressBar progressBar;
-    static SwipeRefreshLayout swipeToRefresh;
     static EditText urlTextBox;
     static ImageView favoriteIcon;
-    static final String homepage = "https://www.duckduckgo.com";
+    static final String homepage = "https://www.google.com/";
 
     // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.
     @SuppressLint("SetJavaScriptEnabled")
@@ -44,9 +41,12 @@ public class Webview extends AppCompatActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+
+        // FEATURE_ACTION_BAR_OVERLAY is required to scroll the actionBar.
+        supportRequestWindowFeature(AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR_OVERLAY);
+
         setContentView(R.layout.activity_webview);
 
-        swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayoutContainer);
         mainWebView = (WebView) findViewById(R.id.mainWebView);
 
         final ActionBar actionBar = getSupportActionBar();
@@ -63,30 +63,10 @@ public class Webview extends AppCompatActivity {
             urlTextBox = (EditText) actionBar.getCustomView().findViewById(R.id.urlTextBox);
             progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar);
 
-            // TODO actionBar.setHideOnContentScrollEnabled(true);
+            // Scroll the actionBar.
+            actionBar.setHideOnContentScrollEnabled(true);
         }
 
-        // Implement swipe down to refresh.
-        swipeToRefresh.setColorSchemeColors(0xFF0097FF);
-        swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
-            @Override
-            public void onRefresh() {
-                mainWebView.loadUrl(formattedUrlString);
-            }
-        });
-
-        // Only enable swipeToRefresh if is mainWebView is scrolled to the top.
-        mainWebView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
-            @Override
-            public void onScrollChanged() {
-                if (mainWebView.getScrollY() == 0) {
-                    swipeToRefresh.setEnabled(true);
-                } else {
-                    swipeToRefresh.setEnabled(false);
-                }
-            }
-        });
-
         mainWebView.setWebViewClient(new WebViewClient() {
 
             // setWebViewClient makes this WebView the default handler for URLs inside the app, so that links are not kicked out to other apps.
@@ -121,9 +101,6 @@ public class Webview extends AppCompatActivity {
                     progressBar.setVisibility(View.VISIBLE);
                 } else {
                     progressBar.setVisibility(View.GONE);
-
-                    // Stop the refreshing indicator if it is running.
-                    swipeToRefresh.setRefreshing(false);
                 }
             }
 
@@ -202,6 +179,10 @@ public class Webview extends AppCompatActivity {
                 mainWebView.loadUrl(homepage);
                 break;
 
+            case R.id.refresh:
+                mainWebView.loadUrl(formattedUrlString);
+                break;
+
             case R.id.back:
                 mainWebView.goBack();
                 break;
diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml
index 2e968f3d..d085905f 100644
--- a/app/src/main/res/layout/activity_webview.xml
+++ b/app/src/main/res/layout/activity_webview.xml
@@ -1,15 +1,18 @@
-<!-- SwipeRefreshLayout allows the user to swipe down to refresh. -->
-<android.support.v4.widget.SwipeRefreshLayout
-    android:id="@+id/swipeRefreshLayoutContainer"
+<!-- nextedScrollingEnabled is required to enable scrolling of the actionBar. -->
+<ScrollView
+    android:id="@+id/scrollView"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:nestedScrollingEnabled="true" >
 
-    <WebView
-        android:id="@+id/mainWebView"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:focusable="true"
-        android:focusableInTouchMode="true"/>
+        <!-- layout_marginTop is required to force the top of the website below the overlayed actionBar. -->
+        <WebView
+            android:id="@+id/mainWebView"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:focusable="true"
+            android:focusableInTouchMode="true"
+            android:layout_marginTop="?attr/actionBarSize"/>
 
-</android.support.v4.widget.SwipeRefreshLayout>
+</ScrollView>
diff --git a/app/src/main/res/menu/menu_webview.xml b/app/src/main/res/menu/menu_webview.xml
index fddbcc68..a2feb873 100644
--- a/app/src/main/res/menu/menu_webview.xml
+++ b/app/src/main/res/menu/menu_webview.xml
@@ -11,6 +11,12 @@
         android:icon="@drawable/ic_home_black_24dp"
         app:showAsAction="never" />
 
+    <item
+        android:id="@+id/refresh"
+        android:title="@string/refresh"
+        android:orderInCategory="200"
+        app:showAsAction="never" />
+
     <item
         android:id="@+id/back"
         android:title="@string/back"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a87e46d4..71142ba8 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -7,6 +7,7 @@
 
     <!-- Menu. -->
     <string name="home">Home</string>
+    <string name="refresh">Refresh</string>
     <string name="back">Back</string>
     <string name="forward">Forward</string>
 
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 8ccbef5c..dc7da63b 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -2,9 +2,7 @@
 
     <!-- Base application theme. -->
     <style name="AppTheme" parent="Theme.AppCompat.Light">
-        <!-- TODO windowActionBarOverlay is necessary for scrolling the app bar.
-        <item name="android:windowActionBarOverlay">true</item>
-        <item name="windowActionBarOverlay">true</item> -->
+        <!-- Customize style here. -->
     </style>
 
 </resources>