From 5b4d95aed14b9206438285326ff1562b8864808c Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 17 Feb 2016 22:08:48 -0700 Subject: [PATCH] Implement SwipeToRefresh for real this time. --- .idea/dictionaries/soren.xml | 1 + app/app.iml | 4 ++ app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 4 +- .../privacybrowser/MainWebViewActivity.java | 39 +++++++-------- app/src/main/res/layout/activity_webview.xml | 49 +++++++++++++------ app/src/main/res/layout/url_bar.xml | 10 ++-- app/src/main/res/menu/menu_webview.xml | 10 +--- app/src/main/res/values-v11/styles.xml | 30 ++++++++++++ app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/styles.xml | 15 ++++-- app/src/main/res/xml/preferences.xml | 9 ++-- 12 files changed, 116 insertions(+), 59 deletions(-) create mode 100644 app/src/main/res/values-v11/styles.xml diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml index 03413eaa..db1251c7 100644 --- a/.idea/dictionaries/soren.xml +++ b/.idea/dictionaries/soren.xml @@ -2,6 +2,7 @@ duckduckgo + privacybrowser rehide rehides soren diff --git a/app/app.iml b/app/app.iml index c752c86a..41cbfa77 100644 --- a/app/app.iml +++ b/app/app.iml @@ -71,6 +71,8 @@ + + @@ -87,8 +89,10 @@ + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b5963c25..f741400b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bcf0270f..febfeaf6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,6 +26,7 @@ + + android:launchMode="singleTask" + android:theme="@style/AppTheme.NoActionBar"> diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index 5d230733..7f49a6cd 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -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; diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml index f50c3995..d90adc7c 100644 --- a/app/src/main/res/layout/activity_webview.xml +++ b/app/src/main/res/layout/activity_webview.xml @@ -19,30 +19,47 @@ along with Privacy Browser. If not, see . --> - - - - + + + + + + + android:layout_marginTop="?attr/actionBarSize"> + + + + + - + \ No newline at end of file diff --git a/app/src/main/res/layout/url_bar.xml b/app/src/main/res/layout/url_bar.xml index 2363375b..b5fd028f 100644 --- a/app/src/main/res/layout/url_bar.xml +++ b/app/src/main/res/layout/url_bar.xml @@ -25,18 +25,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> + - + @@ -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" /> + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_webview.xml b/app/src/main/res/menu/menu_webview.xml index eb964bf9..7ff39ecc 100644 --- a/app/src/main/res/menu/menu_webview.xml +++ b/app/src/main/res/menu/menu_webview.xml @@ -89,22 +89,16 @@ android:orderInCategory="91" app:showAsAction="never" /> - - diff --git a/app/src/main/res/values-v11/styles.xml b/app/src/main/res/values-v11/styles.xml new file mode 100644 index 00000000..716ca043 --- /dev/null +++ b/app/src/main/res/values-v11/styles.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 8fe826ff..34a87076 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -21,7 +21,7 @@ #FF000000 - #FF0091EA + #1e88e5 #FF64DD17 #FFD50000 #FFFFFFFF diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a68cd81e..35530837 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -20,13 +20,20 @@ - - + + +