summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src
diff options
context:
space:
mode:
authorMichael Bestas <mikeioannina@gmail.com>2015-09-26 01:30:34 +0300
committerMichael Bestas <mikeioannina@cyanogenmod.org>2016-01-17 13:29:00 -0800
commitf15ce7a7a91008b18556f37e311b44c5a0da0448 (patch)
tree8e7c5943b60cb2937315c86b5171383f5cff5893 /packages/SystemUI/src
parenta7e5f923a651e519c8d55fbcf71ef26740b61e0e (diff)
downloadframeworks_base-f15ce7a7a91008b18556f37e311b44c5a0da0448.zip
frameworks_base-f15ce7a7a91008b18556f37e311b44c5a0da0448.tar.gz
frameworks_base-f15ce7a7a91008b18556f37e311b44c5a0da0448.tar.bz2
SystemUI: Add battery saver tile (1/2)
* To be displayed on devices without perf profiles Change-Id: Iff6920a0bb78e36e44590c1db880afcdcc6f78b3
Diffstat (limited to 'packages/SystemUI/src')
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java116
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java4
2 files changed, 120 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java
new file mode 100644
index 0000000..37d8d73
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BatterySaverTile.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.qs.tiles;
+
+import android.content.Context;
+import android.content.Intent;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.PowerManager;
+import android.provider.Settings;
+
+import com.android.systemui.qs.QSTile;
+import com.android.systemui.R;
+
+import cyanogenmod.power.PerformanceManager;
+
+import org.cyanogenmod.internal.logging.CMMetricsLogger;
+
+/** Quick settings tile: Battery saver **/
+public class BatterySaverTile extends QSTile<QSTile.BooleanState> {
+
+ private static final Intent BATTERY_SETTINGS = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
+
+ private final PowerManager mPm;
+ private final PerformanceManager mPerformanceManager;
+ private boolean mListening;
+
+ public BatterySaverTile(Host host) {
+ super(host);
+ mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+ mPerformanceManager = PerformanceManager.getInstance(mContext);
+ }
+
+ @Override
+ protected BooleanState newTileState() {
+ return new BooleanState();
+ }
+
+ @Override
+ public void handleClick() {
+ mPm.setPowerSaveMode(!mState.value);
+ refreshState();
+ }
+
+ @Override
+ public void handleLongClick() {
+ mHost.startActivityDismissingKeyguard(BATTERY_SETTINGS);
+ }
+
+ @Override
+ protected void handleUpdateState(BooleanState state, Object arg) {
+ state.value = mPm.isPowerSaveMode();
+ state.visible = mPerformanceManager.getNumberOfProfiles() == 0;
+ state.label = mContext.getString(R.string.quick_settings_battery_saver_label);
+ if (state.value) {
+ state.icon = ResourceIcon.get(R.drawable.ic_qs_battery_saver_on);
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_battery_saver_on);
+ } else {
+ state.icon = ResourceIcon.get(R.drawable.ic_qs_battery_saver_off);
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_battery_saver_off);
+ }
+ }
+
+ @Override
+ protected String composeChangeAnnouncement() {
+ if (mState.value) {
+ return mContext.getString(
+ R.string.accessibility_quick_settings_battery_saver_changed_on);
+ } else {
+ return mContext.getString(
+ R.string.accessibility_quick_settings_battery_saver_changed_off);
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return CMMetricsLogger.TILE_BATTERY_SAVER;
+ }
+
+ private ContentObserver mObserver = new ContentObserver(mHandler) {
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ refreshState();
+ }
+ };
+
+ @Override
+ public void setListening(boolean listening) {
+ if (mListening == listening) return;
+ mListening = listening;
+
+ if (listening) {
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE),
+ false, mObserver);
+ } else {
+ mContext.getContentResolver().unregisterContentObserver(mObserver);
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
index 76f55ce..0e6382a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
@@ -40,6 +40,7 @@ import com.android.systemui.qs.QSTile;
import com.android.systemui.qs.tiles.AdbOverNetworkTile;
import com.android.systemui.qs.tiles.AirplaneModeTile;
import com.android.systemui.qs.tiles.AmbientDisplayTile;
+import com.android.systemui.qs.tiles.BatterySaverTile;
import com.android.systemui.qs.tiles.BluetoothTile;
import com.android.systemui.qs.tiles.CastTile;
import com.android.systemui.qs.tiles.CellularTile;
@@ -361,6 +362,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
else if (tileSpec.equals("ambient_display")) return new AmbientDisplayTile(this);
else if (tileSpec.equals("live_display")) return new LiveDisplayTile(this);
else if (tileSpec.equals("heads_up")) return new HeadsUpTile(this);
+ else if (tileSpec.equals("battery_saver")) return new BatterySaverTile(this);
else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
else throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
}
@@ -448,6 +450,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
else if (spec.equals("ambient_display")) return R.string.quick_settings_ambient_display_label;
else if (spec.equals("live_display")) return R.string.live_display_title;
else if (spec.equals("heads_up")) return R.string.quick_settings_heads_up_label;
+ else if (spec.equals("battery_saver")) return R.string.quick_settings_battery_saver_label;
return 0;
}
@@ -477,6 +480,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
else if (spec.equals("ambient_display")) return R.drawable.ic_qs_ambientdisplay_on;
else if (spec.equals("live_display")) return R.drawable.ic_livedisplay_auto;
else if (spec.equals("heads_up")) return R.drawable.ic_qs_heads_up_on;
+ else if (spec.equals("heads_up")) return R.drawable.ic_qs_battery_saver_on;
return 0;
}