summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2015-12-10 18:10:18 -0800
committerDanesh M <daneshm90@gmail.com>2015-12-10 18:10:18 -0800
commit699d345030efb8b8d081ea68e000edc19c1a4860 (patch)
tree91f9d5832e06946711a50128ac97ccf4c88eae20
parentd37c80a8844445ed6ae4952af2c8fa893c4dc5b6 (diff)
downloadframeworks_base-699d345030efb8b8d081ea68e000edc19c1a4860.zip
frameworks_base-699d345030efb8b8d081ea68e000edc19c1a4860.tar.gz
frameworks_base-699d345030efb8b8d081ea68e000edc19c1a4860.tar.bz2
SystemUI : port performance profile toggle
Change-Id: Ife1e7c62d36cddf1dcd17d5538d0e6c8ea27bee3
-rw-r--r--packages/SystemUI/res/drawable/ic_qs_perf_profile.xml34
-rw-r--r--packages/SystemUI/res/values/cm_arrays.xml18
-rw-r--r--packages/SystemUI/res/values/cm_strings.xml24
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/PerfProfileTile.java226
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java3
5 files changed, 305 insertions, 0 deletions
diff --git a/packages/SystemUI/res/drawable/ic_qs_perf_profile.xml b/packages/SystemUI/res/drawable/ic_qs_perf_profile.xml
new file mode 100644
index 0000000..2ce5d1f
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_qs_perf_profile.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="64dp"
+ android:width="64dp"
+ android:viewportHeight="48"
+ android:viewportWidth="48">
+
+ <group
+ android:name="base_gauge">
+
+ <path android:pathData="M24,8c8.8,0,16,7.2,16,16s-7.2,16-16,16S8,32.8,8,24S15.2,8,24,8 M24,4C13,4,4,13,4,24s9,20,20,20s20-9,20-20S35,4,24,4
+ L24,4z M24,20c-2.2,0-4,1.8-4,4s1.8,4,4,4s4-1.8,4-4S26.2,20,24,20z M32.5,13.5c-1.1,0-2,0.9-2,2s0.9,2,2,2c1.1,0,2-0.9,2-2
+ S33.6,13.5,32.5,13.5z M15.5,13.5c-1.1,0-2,0.9-2,2s0.9,2,2,2s2-0.9,2-2S16.6,13.5,15.5,13.5z M15.5,30.5c-1.1,0-2,0.9-2,2
+ c0,1.1,0.9,2,2,2s2-0.9,2-2C17.5,31.4,16.6,30.5,15.5,30.5z"
+
+ android:fillColor="#FFFFFFFF"/>
+
+ </group>
+
+ <group
+ android:name="needle"
+ android:pivotX="24"
+ android:pivotY="24"
+ android:rotation="-135">
+
+ <path
+ android:strokeColor="#FFFFFFFF"
+ android:strokeWidth="4"
+ android:strokeLineCap="round"
+ android:pathData="M 24,24 h 12"/>
+ </group>
+
+
+</vector> \ No newline at end of file
diff --git a/packages/SystemUI/res/values/cm_arrays.xml b/packages/SystemUI/res/values/cm_arrays.xml
index cabf612..9bd31f0 100644
--- a/packages/SystemUI/res/values/cm_arrays.xml
+++ b/packages/SystemUI/res/values/cm_arrays.xml
@@ -36,4 +36,22 @@
<item>W</item> <!-- West -->
<item>NW</item> <!-- North west -->
</string-array>
+
+ <!-- Performance profiles description-->
+ <string-array name="perf_profile_description" translatable="false">
+ <item>@string/accessibility_quick_settings_perf_profile_pwrsv</item>
+ <item>@string/accessibility_quick_settings_perf_profile_bias_power</item>
+ <item>@string/accessibility_quick_settings_perf_profile_bal</item>
+ <item>@string/accessibility_quick_settings_perf_profile_bias_perf</item>
+ <item>@string/accessibility_quick_settings_perf_profile_perf</item>
+ </string-array>
+
+ <!-- Performance profiles announcement-->
+ <string-array name="perf_profile_announcement" translatable="false">
+ <item>@string/accessibility_quick_settings_perf_profile_changed_pwrsv</item>
+ <item>@string/accessibility_quick_settings_perf_profile_changed_bias_power</item>
+ <item>@string/accessibility_quick_settings_perf_profile_changed_bal</item>
+ <item>@string/accessibility_quick_settings_perf_profile_changed_bias_perf</item>
+ <item>@string/accessibility_quick_settings_perf_profile_changed_perf</item>
+ </string-array>
</resources>
diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml
index af767a7..03b9a47 100644
--- a/packages/SystemUI/res/values/cm_strings.xml
+++ b/packages/SystemUI/res/values/cm_strings.xml
@@ -129,4 +129,28 @@
<!-- Announcement made when the screen timeout tile changes (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_quick_settings_screen_timeout_changed">Screen timeout changed to <xliff:g id="timeout" example="30 seconds">%s</xliff:g>.</string>
+ <string name="qs_tile_performance">Battery mode</string>
+
+ <!-- Content description of the battery mode tile in quick settings when on, power save mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_pwrsv">Battery mode: power save mode.</string>
+ <!-- Content description of the battery mode tile in quick settings when on, balanced mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_bal">Battery mode: balanced mode.</string>
+ <!-- Content description of the battery mode tile in quick settings when on, performance mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_perf">Battery mode: performance mode.</string>
+ <!-- Content description of the battery mode tile in quick settings when on, efficiency mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_bias_power">Battery mode: efficiency mode.</string>
+ <!-- Content description of the battery mode tile in quick settings when on, quick mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_bias_perf">Battery mode: quick mode.</string>
+
+ <!-- Announcement made when the battery mode tile changes to power save (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_changed_pwrsv">Battery mode changed to power save mode.</string>
+ <!-- Announcement made when the battery mode tile changes to balanced (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_changed_bal">Battery mode changed to balanced mode.</string>
+ <!-- Announcement made when the battery mode tile changes to performance (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_changed_perf">Battery mode changed to performance mode.</string>
+ <!-- Announcement made when the battery mode tile changes to efficiency (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_changed_bias_power">Battery mode changed to efficiency mode.</string>
+ <!-- Announcement made when the battery mode tile changes to quick (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_perf_profile_changed_bias_perf">Battery mode changed to quick mode.</string>
+ <string name="quick_settings_performance_profile_detail_title">Battery mode</string>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/PerfProfileTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/PerfProfileTile.java
new file mode 100644
index 0000000..f3c811e
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/PerfProfileTile.java
@@ -0,0 +1,226 @@
+/*
+ * 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.content.res.Resources;
+import android.database.ContentObserver;
+import android.os.Handler;
+import android.os.PowerManager;
+import android.provider.Settings;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import com.android.internal.logging.MetricsConstants;
+import com.android.systemui.R;
+import com.android.systemui.qs.QSDetailItemsList;
+import com.android.systemui.qs.QSTile;
+
+import org.cyanogenmod.internal.util.QSUtils;
+
+import cyanogenmod.app.StatusBarPanelCustomTile;
+import cyanogenmod.power.PerformanceManager;
+import cyanogenmod.providers.CMSettings;
+
+public class PerfProfileTile extends QSTile<PerfProfileTile.ProfileState> {
+
+ private static final Intent BATTERY_SETTINGS = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
+
+ private final String[] mEntries;
+ private final String[] mDescriptionEntries;
+ private final String[] mAnnouncementEntries;
+ private final String[] mPerfProfileValues;
+ private final Icon mIcon;
+
+ private final PowerManager mPm;
+ private final PerformanceManager mPerformanceManager;
+ private boolean mListening;
+
+ private PerformanceProfileObserver mObserver;
+
+ public PerfProfileTile(Host host) {
+ super(host);
+ mObserver = new PerformanceProfileObserver(mHandler);
+ mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+ mPerformanceManager = PerformanceManager.getInstance(mContext);
+
+ Resources res = mContext.getResources();
+
+ mPerfProfileValues = res.getStringArray(org.cyanogenmod.platform.internal.R.array.perf_profile_values);
+
+ mEntries = res.getStringArray(org.cyanogenmod.platform.internal.R.array.perf_profile_entries);
+ mDescriptionEntries = res.getStringArray(R.array.perf_profile_description);
+ mAnnouncementEntries = res.getStringArray(R.array.perf_profile_announcement);
+
+ mIcon = ResourceIcon.get(R.drawable.ic_qs_perf_profile);
+ }
+
+ @Override
+ protected ProfileState newTileState() {
+ return new ProfileState();
+ }
+
+ @Override
+ protected void handleClick() {
+ showDetail(true);
+ }
+
+ @Override
+ public DetailAdapter getDetailAdapter() {
+ return new PerfProfileDetailAdapter();
+ }
+
+ @Override
+ protected void handleLongClick() {
+ mHost.startActivityDismissingKeyguard(BATTERY_SETTINGS);
+ }
+
+ @Override
+ protected void handleUpdateState(ProfileState state, Object arg) {
+ state.visible = mPerformanceManager.getNumberOfProfiles() > 0;
+ state.profile = arg == null ? getCurrentProfileIndex() : (Integer) arg;
+ state.label = mEntries[state.profile];
+ state.icon = mIcon;
+ state.contentDescription = mDescriptionEntries[state.profile];
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsConstants.DONT_TRACK_ME_BRO;
+ }
+
+ @Override
+ protected String composeChangeAnnouncement() {
+ return mAnnouncementEntries[getCurrentProfileIndex()];
+ }
+
+ @Override
+ public void setListening(boolean listening) {
+ if (mListening == listening) return;
+ mListening = listening;
+ if (listening) {
+ mObserver.startObserving();
+ } else {
+ mObserver.endObserving();
+ }
+ }
+
+ private class PerformanceProfileObserver extends ContentObserver {
+ public PerformanceProfileObserver(Handler handler) {
+ super(handler);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ refreshState(getCurrentProfileIndex());
+ }
+
+ public void startObserving() {
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(CMSettings.Secure.PERFORMANCE_PROFILE),
+ false, this);
+ }
+
+ public void endObserving() {
+ mContext.getContentResolver().unregisterContentObserver(this);
+ }
+ }
+
+ private int getCurrentProfileIndex() {
+ return mPerformanceManager.getPowerProfile();
+ }
+
+ private void changeToProfile(int profileIndex) {
+ mPerformanceManager.setPowerProfile(profileIndex); // content observer will notify
+ }
+
+ public static class ProfileState extends QSTile.State {
+ public int profile;
+
+ @Override
+ public boolean copyTo(State other) {
+ final ProfileState o = (ProfileState) other;
+ final boolean changed = profile != o.profile;
+ return super.copyTo(other) || changed;
+ }
+
+ @Override
+ protected StringBuilder toStringBuilder() {
+ final StringBuilder rt = super.toStringBuilder();
+ rt.insert(rt.length() - 1, ",profile=" + profile);
+ return rt;
+ }
+ }
+
+ private class PerfProfileDetailAdapter implements DetailAdapter,
+ AdapterView.OnItemClickListener {
+ private QSDetailItemsList mItems;
+
+ @Override
+ public int getTitle() {
+ return R.string.quick_settings_performance_profile_detail_title;
+ }
+
+ @Override
+ public Boolean getToggleState() {
+ return null;
+ }
+
+ @Override
+ public Intent getSettingsIntent() {
+ return BATTERY_SETTINGS;
+ }
+
+ @Override
+ public StatusBarPanelCustomTile getCustomTile() {
+ return null;
+ }
+
+ @Override
+ public void setToggleState(boolean state) {
+ // noop
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsConstants.DONT_TRACK_ME_BRO;
+ }
+
+ @Override
+ public View createDetailView(Context context, View convertView, ViewGroup parent) {
+ mItems = QSDetailItemsList.convertOrInflate(context, convertView, parent);
+ ArrayAdapter adapter = new ArrayAdapter<String>(mContext,
+ android.R.layout.simple_list_item_single_choice, mEntries);
+ ListView listView = mItems.getListView();
+ listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ listView.setAdapter(adapter);
+ listView.setOnItemClickListener(this);
+ listView.setDivider(null);
+ listView.setItemChecked(getCurrentProfileIndex(), true);
+ return mItems;
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ changeToProfile(position);
+ }
+ }
+}
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 bdf39e4..eff9b0a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
@@ -51,6 +51,7 @@ import com.android.systemui.qs.tiles.HotspotTile;
import com.android.systemui.qs.tiles.IntentTile;
import com.android.systemui.qs.tiles.LocationTile;
import com.android.systemui.qs.tiles.NfcTile;
+import com.android.systemui.qs.tiles.PerfProfileTile;
import com.android.systemui.qs.tiles.ProfilesTile;
import com.android.systemui.qs.tiles.RotationLockTile;
import com.android.systemui.qs.tiles.ScreenTimeoutTile;
@@ -344,6 +345,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
else if (tileSpec.equals("volume_panel")) return new VolumeTile(this);
else if (tileSpec.equals("usb_tether")) return new UsbTetherTile(this);
else if (tileSpec.equals("screen_timeout")) return new ScreenTimeoutTile(this);
+ else if (tileSpec.equals("performance")) return new PerfProfileTile(this);
else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
else throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
}
@@ -422,6 +424,7 @@ public class QSTileHost implements QSTile.Host, Tunable {
else if (spec.equals("volume_panel")) return R.string.quick_settings_volume_panel_label;
else if (spec.equals("usb_tether")) return R.string.quick_settings_usb_tether_label;
else if (spec.equals("screen_timeout")) return R.string.quick_settings_screen_timeout_detail_title;
+ else if (spec.equals("performance")) return R.string.qs_tile_performance;
return 0;
}