summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSite Mao <sitem@codeaurora.org>2015-07-16 10:56:31 -0700
committerjrizzoli <joey@cyanogenmoditalia.it>2015-08-28 13:15:46 +0200
commit61b68216caea48308968c75c5497bcf7793a871e (patch)
tree2d527a908f7da844561915ff24c66a901a8ebc1d /src
parent1ad7c5753de76e1cfaf78289e4f2b05e12c77855 (diff)
downloadandroid_packages_apps_Gello-61b68216caea48308968c75c5497bcf7793a871e.tar.gz
android_packages_apps_Gello-61b68216caea48308968c75c5497bcf7793a871e.tar.bz2
android_packages_apps_Gello-61b68216caea48308968c75c5497bcf7793a871e.zip
Add notification to power save mode
Add small notification when mode is toggled and also disable web refiner and edge navigation. Change-Id: I166897c0e396b53884e05dac8189f049f34851f7
Diffstat (limited to 'src')
-rw-r--r--src/com/android/browser/BaseUi.java7
-rw-r--r--src/com/android/browser/Tab.java7
-rw-r--r--src/com/android/browser/preferences/AdvancedPreferencesFragment.java4
-rw-r--r--src/com/android/browser/preferences/GeneralPreferencesFragment.java29
4 files changed, 40 insertions, 7 deletions
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<List<Integer>>() {
@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.
*/