From 8f89d3c5ef3625bec2dd8a99fae255f5c6f46636 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 5 May 2016 20:04:05 -0700 Subject: [PATCH] Create preference to disable swipe to refresh when not desired. Remove -standard and -free from flavor version names. --- app/build.gradle | 2 -- .../privacybrowser/MainWebViewActivity.java | 15 ++++++++++++++- .../stoutner/privacybrowser/SettingsFragment.java | 9 +++++++++ app/src/main/res/menu/menu_options.xml | 6 ++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/preferences.xml | 6 ++++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 03805931..dffcddd9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,12 +43,10 @@ android { productFlavors { standard { applicationId "com.stoutner.privacybrowser.standard" - versionName "1.4-standard" } free { applicationId "com.stoutner.privacybrowser.free" - versionName "1.4-free" } } } diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index bcbdd9f3..99fef852 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -84,6 +84,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation public static boolean domStorageEnabled; // homepage is public static so it can be accessed from SettingsFragment. It is also used in onCreate() and onOptionsItemSelected(). public static String homepage; + // swipeToRefresh is public static so it can be accessed from SettingsFragment. It is also used in onCreate(). + public static SwipeRefreshLayout swipeToRefresh; + // swipeToRefreshEnabled is public static so it can be accessed from SettingsFragment. It is also used in onCreate(). + public static boolean swipeToRefreshEnabled; // drawerToggle is used in onCreate(), onPostCreate(), onConfigurationChanged(), onNewIntent(), and onNavigationItemSelected(). private ActionBarDrawerToggle drawerToggle; @@ -115,7 +119,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation final View adView = findViewById(R.id.adView); // Implement swipe to refresh - final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); + swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); swipeToRefresh.setColorSchemeResources(R.color.blue); swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -303,6 +307,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Hide zoom controls. mainWebView.getSettings().setDisplayZoomControls(false); + // Initialize the default preference values the first time the program is run. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); @@ -333,6 +338,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Set homepage initial status. homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com"); + // Set swipe to refresh initial status. The default is true. + swipeToRefreshEnabled = savedPreferences.getBoolean("swipe_to_refresh_enabled", true); + swipeToRefresh.setEnabled(swipeToRefreshEnabled); + + // Get the intent information that started the app. final Intent intent = getIntent(); @@ -592,6 +602,9 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below. return true; + case R.id.refresh: + mainWebView.reload(); + default: return super.onOptionsItemSelected(menuItem); } diff --git a/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java index 9f11cb5f..35021b3e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/SettingsFragment.java @@ -143,6 +143,13 @@ public class SettingsFragment extends PreferenceFragment { MainWebViewActivity.homepage = sharedPreferences.getString("homepage", "https://www.duckduckgo.com"); return; + case "swipe_to_refresh_enabled": + // Set swipeToRefreshEnabled to the new state. The default is true. + MainWebViewActivity.swipeToRefreshEnabled = sharedPreferences.getBoolean("swipe_to_refresh_enabled", true); + + // Update swipeRefreshLayout to match the new state. + MainWebViewActivity.swipeToRefresh.setEnabled(MainWebViewActivity.swipeToRefreshEnabled); + // If no match, do nothing. default: } @@ -153,6 +160,8 @@ public class SettingsFragment extends PreferenceFragment { savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener); } + // It is necessary to reregister the listener on every resume or it will randomly stop working for the user because apps can be paused and resumed at any time, + // even when they are in the foreground. @Override public void onResume() { super.onResume(); diff --git a/app/src/main/res/menu/menu_options.xml b/app/src/main/res/menu/menu_options.xml index 038b364f..5655644a 100644 --- a/app/src/main/res/menu/menu_options.xml +++ b/app/src/main/res/menu/menu_options.xml @@ -74,4 +74,10 @@ android:title="@string/add_to_home_screen" android:orderInCategory="80" app:showAsAction="never" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2805c5db..efc7e659 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -62,6 +62,7 @@ Clear DOM Storage Share Add to Home Screen + Refresh Shortcut name @@ -84,6 +85,8 @@ that allows websites to store larger and more complex types of information, like pictures, on your device. General Settings Homepage + Swipe to refresh + Some websites don\'t work well if swipe to refresh is enabled. About Privacy Browser diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index bc300f00..747778e7 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -58,5 +58,11 @@ android:defaultValue="https://www.duckduckgo.com" android:inputType="textUri" android:singleLine="true" /> + + \ No newline at end of file -- 2.45.2