Fix battery usage screen issues
Tint icons properly
Bug: 21077770
Show better icons for wifi and bt (remove the old ones)
Bug: 21172936
Also add a way to show fake items in power list for testing.
Change-Id: I6b6804673a68190ebc3f2ea32802e30811a7f5b2
diff --git a/res/drawable-hdpi/ic_settings_bluetooth2_alpha.png b/res/drawable-hdpi/ic_settings_bluetooth2_alpha.png
deleted file mode 100644
index 9dbc509..0000000
--- a/res/drawable-hdpi/ic_settings_bluetooth2_alpha.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_bluetooth_alpha.png b/res/drawable-hdpi/ic_settings_bluetooth_alpha.png
index a21982e..9dbc509 100644
--- a/res/drawable-hdpi/ic_settings_bluetooth_alpha.png
+++ b/res/drawable-hdpi/ic_settings_bluetooth_alpha.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_wifi_alpha.png b/res/drawable-hdpi/ic_settings_wifi_alpha.png
deleted file mode 100644
index a21982e..0000000
--- a/res/drawable-hdpi/ic_settings_wifi_alpha.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_bluetooth2_alpha.png b/res/drawable-mdpi/ic_settings_bluetooth2_alpha.png
deleted file mode 100644
index f51e5ca..0000000
--- a/res/drawable-mdpi/ic_settings_bluetooth2_alpha.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_bluetooth_alpha.png b/res/drawable-mdpi/ic_settings_bluetooth_alpha.png
index 31be004..f51e5ca 100644
--- a/res/drawable-mdpi/ic_settings_bluetooth_alpha.png
+++ b/res/drawable-mdpi/ic_settings_bluetooth_alpha.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_wifi_alpha.png b/res/drawable-mdpi/ic_settings_wifi_alpha.png
deleted file mode 100644
index 31be004..0000000
--- a/res/drawable-mdpi/ic_settings_wifi_alpha.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_settings_bluetooth2_alpha.png b/res/drawable-xhdpi/ic_settings_bluetooth2_alpha.png
deleted file mode 100644
index a3e09db..0000000
--- a/res/drawable-xhdpi/ic_settings_bluetooth2_alpha.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_settings_bluetooth_alpha.png b/res/drawable-xhdpi/ic_settings_bluetooth_alpha.png
index cee4e67..a3e09db 100644
--- a/res/drawable-xhdpi/ic_settings_bluetooth_alpha.png
+++ b/res/drawable-xhdpi/ic_settings_bluetooth_alpha.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_settings_wifi_alpha.png b/res/drawable-xhdpi/ic_settings_wifi_alpha.png
deleted file mode 100644
index cee4e67..0000000
--- a/res/drawable-xhdpi/ic_settings_wifi_alpha.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_settings_bluetooth2_alpha.png b/res/drawable-xxhdpi/ic_settings_bluetooth_alpha.png
similarity index 100%
rename from res/drawable-xxhdpi/ic_settings_bluetooth2_alpha.png
rename to res/drawable-xxhdpi/ic_settings_bluetooth_alpha.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_settings_bluetooth2_alpha.png b/res/drawable-xxxhdpi/ic_settings_bluetooth_alpha.png
similarity index 100%
rename from res/drawable-xxxhdpi/ic_settings_bluetooth2_alpha.png
rename to res/drawable-xxxhdpi/ic_settings_bluetooth_alpha.png
Binary files differ
diff --git a/res/drawable/ic_settings_bluetooth2.xml b/res/drawable/ic_settings_bluetooth2.xml
deleted file mode 100644
index df0f866..0000000
--- a/res/drawable/ic_settings_bluetooth2.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 The Android Open Source 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.
--->
-
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/ic_settings_bluetooth2_alpha"
- android:tint="?android:attr/colorAccent" />
-
diff --git a/res/drawable/ic_settings_wifi.xml b/res/drawable/ic_settings_wifi.xml
deleted file mode 100644
index 9b58909..0000000
--- a/res/drawable/ic_settings_wifi.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 The Android Open Source 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.
--->
-
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/ic_settings_wifi_alpha"
- android:tint="?android:attr/colorAccent" />
-
diff --git a/res/xml/dashboard_categories.xml b/res/xml/dashboard_categories.xml
index 5b8c243..ebddd78 100644
--- a/res/xml/dashboard_categories.xml
+++ b/res/xml/dashboard_categories.xml
@@ -36,7 +36,7 @@
android:id="@+id/bluetooth_settings"
android:title="@string/bluetooth_settings_title"
android:fragment="com.android.settings.bluetooth.BluetoothSettings"
- android:icon="@drawable/ic_settings_bluetooth2"
+ android:icon="@drawable/ic_settings_bluetooth"
/>
<!-- SIM Cards -->
diff --git a/src/com/android/settings/TintablePreference.java b/src/com/android/settings/TintablePreference.java
new file mode 100644
index 0000000..3c56b1e
--- /dev/null
+++ b/src/com/android/settings/TintablePreference.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2015 The Android Open Source 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.settings;
+
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.ImageView;
+
+public class TintablePreference extends Preference {
+
+ private int mTintColor;
+
+ public TintablePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setTint(int color) {
+ mTintColor = color;
+ notifyChanged();
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ super.onBindView(view);
+
+ if (mTintColor != 0) {
+ ((ImageView) view.findViewById(R.id.icon)).setImageTintList(
+ ColorStateList.valueOf(mTintColor));
+ }
+ }
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index 7bdc1a6..b36d2ea 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -222,7 +222,7 @@
data.className = BluetoothSettings.class.getName();
data.title = mCachedDevice.getName();
data.screenTitle = context.getResources().getString(R.string.bluetooth_settings);
- data.iconResId = R.drawable.ic_settings_bluetooth2;
+ data.iconResId = R.drawable.ic_settings_bluetooth;
data.enabled = true;
Index.getInstance(context).updateFromSearchIndexableData(data);
@@ -268,6 +268,6 @@
return R.drawable.ic_bt_headset_hfp;
}
}
- return R.drawable.ic_settings_bluetooth2;
+ return R.drawable.ic_settings_bluetooth;
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index cf06fe7..4113b9e 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -488,7 +488,7 @@
com.android.settings.bluetooth.Utils.updateSearchIndex(activity,
BluetoothSettings.class.getName(), device.getName(),
context.getResources().getString(R.string.bluetooth_settings),
- R.drawable.ic_settings_bluetooth2, false);
+ R.drawable.ic_settings_bluetooth, false);
}
});
diff --git a/src/com/android/settings/fuelgauge/BatteryEntry.java b/src/com/android/settings/fuelgauge/BatteryEntry.java
index be7c657..bfae578 100644
--- a/src/com/android/settings/fuelgauge/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/BatteryEntry.java
@@ -146,7 +146,7 @@
break;
case WIFI:
name = context.getResources().getString(R.string.power_wifi);
- iconId = R.drawable.ic_settings_wifi;
+ iconId = R.drawable.ic_settings_wireless;
break;
case BLUETOOTH:
name = context.getResources().getString(R.string.power_bluetooth);
diff --git a/src/com/android/settings/fuelgauge/PowerGaugePreference.java b/src/com/android/settings/fuelgauge/PowerGaugePreference.java
index 97012e4..e80f492 100644
--- a/src/com/android/settings/fuelgauge/PowerGaugePreference.java
+++ b/src/com/android/settings/fuelgauge/PowerGaugePreference.java
@@ -25,13 +25,14 @@
import android.widget.TextView;
import com.android.settings.R;
+import com.android.settings.TintablePreference;
import com.android.settings.Utils;
/**
* Custom preference for displaying power consumption as a bar and an icon on
* the left for the subsystem/app type.
*/
-public class PowerGaugePreference extends Preference {
+public class PowerGaugePreference extends TintablePreference {
private BatteryEntry mInfo;
private int mProgress;
private CharSequence mProgressText;
@@ -39,7 +40,7 @@
public PowerGaugePreference(Context context, Drawable icon, CharSequence contentDescription,
BatteryEntry info) {
- super(context);
+ super(context, null);
setLayoutResource(R.layout.preference_app_percentage);
setIcon(icon != null ? icon : new ColorDrawable(0));
mInfo = info;
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 3576ee2..1fe59e9 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -28,6 +28,7 @@
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
+import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -35,12 +36,14 @@
import com.android.internal.logging.MetricsLogger;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.PowerProfile;
+import com.android.internal.os.BatterySipper.DrainType;
import com.android.settings.HelpUtils;
import com.android.settings.R;
import com.android.settings.Settings.HighPowerApplicationsActivity;
import com.android.settings.SettingsActivity;
import com.android.settings.applications.ManageApplications;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -51,6 +54,8 @@
private static final boolean DEBUG = false;
+ private static final boolean USE_FAKE_DATA = false;
+
static final String TAG = "PowerUsageSummary";
private static final String KEY_APP_LIST = "app_list";
@@ -184,18 +189,25 @@
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
- if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP) {
- final List<BatterySipper> usageList = mStatsHelper.getUsageList();
+ TypedValue value = new TypedValue();
+ getContext().getTheme().resolveAttribute(android.R.attr.colorControlNormal, value, true);
+ int colorControl = getContext().getColor(value.resourceId);
- final int dischargeAmount = stats != null ? stats.getDischargeAmount(mStatsType) : 0;
+ if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
+ final List<BatterySipper> usageList = USE_FAKE_DATA ? getFakeStats()
+ : mStatsHelper.getUsageList();
+
+ final int dischargeAmount = USE_FAKE_DATA ? 5000
+ : stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
final BatterySipper sipper = usageList.get(i);
if ((sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP) {
continue;
}
+ double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower();
final double percentOfTotal =
- ((sipper.totalPowerMah / mStatsHelper.getTotalPower()) * dischargeAmount);
+ ((sipper.totalPowerMah / totalPower) * dischargeAmount);
if (((int) (percentOfTotal + .5)) < 1) {
continue;
}
@@ -243,6 +255,9 @@
if (sipper.uidObj != null) {
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
}
+ if (sipper.drainType != DrainType.APP && sipper.drainType != DrainType.USER) {
+ pref.setTint(colorControl);
+ }
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() > (MAX_ITEMS_TO_LIST + 1)) {
@@ -257,6 +272,19 @@
BatteryEntry.startRequestQueue();
}
+ private static List<BatterySipper> getFakeStats() {
+ ArrayList<BatterySipper> stats = new ArrayList<>();
+ float use = 5;
+ for (DrainType type : DrainType.values()) {
+ if (type == DrainType.APP) {
+ continue;
+ }
+ stats.add(new BatterySipper(type, null, use));
+ use += 5;
+ }
+ return stats;
+ }
+
Handler mHandler = new Handler() {
@Override
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 8aba203..6a324ac 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -91,7 +91,7 @@
Ranking.getRankForClassName(BluetoothSettings.class.getName()),
NO_DATA_RES_ID,
BluetoothSettings.class.getName(),
- R.drawable.ic_settings_bluetooth2));
+ R.drawable.ic_settings_bluetooth));
sResMap.put(SimSettings.class.getName(),
new SearchIndexableResource(