From 1721149776151ec0c8da209a71207d4338b3a307 Mon Sep 17 00:00:00 2001 From: prati0100 Date: Fri, 15 Jul 2016 00:54:29 +0530 Subject: [PATCH 1/2] Added swipe down to refresh --- .../activity/BaseFacebookWebViewActivity.java | 26 +++++++++++++++++++ app/src/main/res/layout/main_layout.xml | 20 +++++++++----- app/src/main/res/values/colors.xml | 5 ++++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java b/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java index 63f6532..fd9ad87 100644 --- a/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java +++ b/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java @@ -36,6 +36,7 @@ import android.os.Bundle; import android.os.Environment; import android.support.annotation.NonNull; +import android.support.v4.widget.SwipeRefreshLayout; import android.text.TextUtils; import android.view.ContextMenu; import android.view.KeyEvent; @@ -112,6 +113,7 @@ public abstract class BaseFacebookWebViewActivity extends Activity implements protected WebSettings mWebSettings = null; protected ValueCallback mUploadMessage = null; protected ValueCallback mUploadMessageLollipop = null; + protected SwipeRefreshLayout mSwipeRefreshLayout = null; private boolean mCreatingActivity = true; private String mPendingImageUrlToSave = null; @@ -169,6 +171,14 @@ public void onCreate(Bundle savedInstanceState) { mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); + mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout); + //Sets the different colors the loading indicator will show + mSwipeRefreshLayout.setColorSchemeResources( + R.color.swipe_color_1, R.color.swipe_color_2, + R.color.swipe_color_3, R.color.swipe_color_4); + + setOnSwipeListener(); + // Set the database path for this WebView so that // HTML5 Storage API works properly mWebSettings.setAppCacheEnabled(true); @@ -365,6 +375,18 @@ protected void jumpToTop() { loadNewPage("javascript:window.scrollTo(0,0);"); } + /** + * Sets swiping listener for the swipe refresh layout + */ + private void setOnSwipeListener() { + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refreshCurrentPage(); + } + }); + } + /** * Used to change the geolocation flag. * @@ -537,6 +559,10 @@ public void onProgressChanged(WebView view, int progress) { // Hide the progress bar as soon as it goes over 85% if (progress >= 85) { mProgressBar.setVisibility(View.GONE); + + //Checks if the swipe refresh indicator is active. Turns off if it is + if(mSwipeRefreshLayout.isRefreshing()) + mSwipeRefreshLayout.setRefreshing(false); } } diff --git a/app/src/main/res/layout/main_layout.xml b/app/src/main/res/layout/main_layout.xml index bce0f7b..98c0cf3 100644 --- a/app/src/main/res/layout/main_layout.xml +++ b/app/src/main/res/layout/main_layout.xml @@ -27,14 +27,20 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + + android:layout_width="match_parent" + android:id="@+id/swiperefreshlayout" > + + + #ff293c68 #738ffe + #33B5E5 + #99CC00 + #FFBB33 + #FF4444 + \ No newline at end of file From 9eb35a64f761fbea3bbc3cc00fa36d579fa16a38 Mon Sep 17 00:00:00 2001 From: Pratyush Yadav Date: Sat, 25 Feb 2017 16:48:11 +0530 Subject: [PATCH 2/2] Wrapped if statement in curly braces --- .../fbwrapper/activity/BaseFacebookWebViewActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java b/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java index fd9ad87..aefaae3 100644 --- a/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java +++ b/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java @@ -561,8 +561,9 @@ public void onProgressChanged(WebView view, int progress) { mProgressBar.setVisibility(View.GONE); //Checks if the swipe refresh indicator is active. Turns off if it is - if(mSwipeRefreshLayout.isRefreshing()) + if(mSwipeRefreshLayout.isRefreshing()) { mSwipeRefreshLayout.setRefreshing(false); + } } }