From 828458a749772bd036f9e2747bd9f6bf9c468691 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 11 Nov 2015 20:16:58 -0700 Subject: [PATCH] Remove swipe to refresh and add app bar scrolling (which appear to not be compatible when using a webview). Add a refresh menu entry. --- .idea/dictionaries/soren.xml | 1 + app/app.iml | 10 ++--- app/build.gradle | 4 +- .../com/stoutner/privacybrowser/Webview.java | 43 ++++++------------- app/src/main/res/layout/activity_webview.xml | 25 ++++++----- app/src/main/res/menu/menu_webview.xml | 6 +++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 4 +- 8 files changed, 42 insertions(+), 52 deletions(-) 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 @@ duckduckgo + webview \ 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 @@ - - + + @@ -90,8 +90,8 @@ - - - + + + \ 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 @@ - - + + android:layout_height="match_parent" + android:nestedScrollingEnabled="true" > - + + - + 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" /> + + Home + Refresh Back Forward 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 @@ -- 2.45.2