From 61b68216caea48308968c75c5497bcf7793a871e Mon Sep 17 00:00:00 2001 From: Site Mao Date: Thu, 16 Jul 2015 10:56:31 -0700 Subject: Add notification to power save mode Add small notification when mode is toggled and also disable web refiner and edge navigation. Change-Id: I166897c0e396b53884e05dac8189f049f34851f7 --- src/com/android/browser/BaseUi.java | 7 +++++- src/com/android/browser/Tab.java | 7 +++--- .../preferences/AdvancedPreferencesFragment.java | 4 +-- .../preferences/GeneralPreferencesFragment.java | 29 ++++++++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index 3682d69a..3a05724b 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -446,7 +446,7 @@ public abstract class BaseUi implements UI { } public void refreshEdgeSwipeController(View container) { - if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) { + if (isUiLowPowerMode()) { return; } @@ -696,6 +696,11 @@ public abstract class BaseUi implements UI { return false; } + public static boolean isUiLowPowerMode() { + return BrowserCommandLine.hasSwitch("ui-low-power-mode") || + BrowserSettings.getInstance().isPowerSaveModeEnabled(); + } + // ------------------------------------------------------------------------- protected void updateNavigationState(Tab tab) { diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 0a4bc346..a4cc47fe 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -643,7 +643,7 @@ class Tab implements PictureListener { @Override public void beforeNavigation(WebView view, String url) { mTouchIconUrl = null; - if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) { + if (BaseUi.isUiLowPowerMode()) { return; } @@ -677,7 +677,7 @@ class Tab implements PictureListener { @Override public void onHistoryItemCommit(WebView view, int index) { - if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) { + if (BaseUi.isUiLowPowerMode()) { return; } @@ -1414,8 +1414,7 @@ class Tab implements PictureListener { // save the WebView to call destroy() after detach it from the tab final WebView webView = mMainView; setWebView(null); - if (!mWebViewDestroyedByMemoryMonitor && - !BrowserCommandLine.hasSwitch("ui-low-power-mode")) { + if (!mWebViewDestroyedByMemoryMonitor && !BaseUi.isUiLowPowerMode()) { // Tabs can be reused with new instance of WebView so delete the snapshots webView.getSnapshotIds(new ValueCallback>() { @Override diff --git a/src/com/android/browser/preferences/AdvancedPreferencesFragment.java b/src/com/android/browser/preferences/AdvancedPreferencesFragment.java index fa73abc7..0a5fa64b 100644 --- a/src/com/android/browser/preferences/AdvancedPreferencesFragment.java +++ b/src/com/android/browser/preferences/AdvancedPreferencesFragment.java @@ -30,13 +30,13 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.util.Log; +import com.android.browser.BaseUi; import com.android.browser.BrowserActivity; import com.android.browser.BrowserSettings; import com.android.browser.DownloadHandler; import com.android.browser.PreferenceKeys; import com.android.browser.R; -import org.codeaurora.swe.BrowserCommandLine; import org.codeaurora.swe.PermissionsServiceFactory; public class AdvancedPreferencesFragment @@ -77,7 +77,7 @@ public class AdvancedPreferencesFragment (ListPreference) mFragment.findPreference("edge_swiping_action"); edgeSwipePref.setOnPreferenceChangeListener(this); - if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) { + if (BaseUi.isUiLowPowerMode()) { edgeSwipePref.setEnabled(false); } else { String[] options = mFragment.getResources().getStringArray( diff --git a/src/com/android/browser/preferences/GeneralPreferencesFragment.java b/src/com/android/browser/preferences/GeneralPreferencesFragment.java index f3128e24..09355a5c 100644 --- a/src/com/android/browser/preferences/GeneralPreferencesFragment.java +++ b/src/com/android/browser/preferences/GeneralPreferencesFragment.java @@ -31,15 +31,18 @@ import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; import android.text.InputType; import android.text.TextUtils; import android.util.Log; +import android.view.Gravity; import android.view.KeyEvent; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; +import android.widget.Toast; import com.android.browser.AutoFillSettingsFragment; import com.android.browser.BrowserSettings; @@ -50,6 +53,8 @@ import com.android.browser.homepages.HomeProvider; import com.android.browser.mdm.AutoFillRestriction; import com.android.browser.mdm.SearchEngineRestriction; +import org.codeaurora.swe.PermissionsServiceFactory; + public class GeneralPreferencesFragment extends SWEPreferenceFragment implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener { @@ -65,6 +70,7 @@ public class GeneralPreferencesFragment extends SWEPreferenceFragment static final String OTHER = "other"; static final String PREF_HOMEPAGE_PICKER = "homepage_picker"; + static final String PREF_POWERSAVE = "powersave_enabled"; String[] mChoices, mValues; String mCurrentPage; @@ -93,6 +99,9 @@ public class GeneralPreferencesFragment extends SWEPreferenceFragment PreferenceKeys.PREF_AUTOFILL_PROFILE); autofill.setOnPreferenceClickListener(this); + SwitchPreference powersave = (SwitchPreference) findPreference(PREF_POWERSAVE); + powersave.setOnPreferenceChangeListener(this); + final Bundle arguments = getArguments(); if (arguments != null && arguments.getBoolean("LowPower")) { LowPowerDialogFragment fragment = LowPowerDialogFragment.newInstance(); @@ -153,6 +162,14 @@ public class GeneralPreferencesFragment extends SWEPreferenceFragment return false; } + if (pref.getKey().equals(PREF_POWERSAVE)) { + BrowserSettings settings = BrowserSettings.getInstance(); + settings.setPowerSaveModeEnabled((Boolean)objValue); + PermissionsServiceFactory.setDefaultPermissions( + PermissionsServiceFactory.PermissionType.WEBREFINER, !(Boolean)objValue); + showPowerSaveInfo((Boolean) objValue); + } + return true; } @@ -244,6 +261,18 @@ public class GeneralPreferencesFragment extends SWEPreferenceFragment return false; } + void showPowerSaveInfo(boolean toggle) { + String toastInfo; + if (toggle) + toastInfo = getActivity().getResources().getString(R.string.powersave_dialog_on); + else + toastInfo = getActivity().getResources().getString(R.string.powersave_dialog_off); + + Toast toast = Toast.makeText(getActivity(), toastInfo, Toast.LENGTH_SHORT); + toast.setGravity(Gravity.CENTER, 0, 0); + toast.show(); + } + /* Add this class to manage AlertDialog lifecycle. */ -- cgit v1.2.3