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
This commit is contained in:
Jason Monk
2015-06-02 13:03:24 -04:00
parent b8df8a29bf
commit f2819e0ead
21 changed files with 88 additions and 54 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 419 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 419 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 758 B

After

Width:  |  Height:  |  Size: 758 B

View File

Before

Width:  |  Height:  |  Size: 932 B

After

Width:  |  Height:  |  Size: 932 B

View File

@@ -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" />

View File

@@ -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" />

View File

@@ -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 -->

View File

@@ -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));
}
}
}

View File

@@ -222,7 +222,7 @@ public final class BluetoothDevicePreference extends Preference implements
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 @@ public final class BluetoothDevicePreference extends Preference implements
return R.drawable.ic_bt_headset_hfp;
}
}
return R.drawable.ic_settings_bluetooth2;
return R.drawable.ic_settings_bluetooth;
}
}

View File

@@ -488,7 +488,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
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);
}
});

View File

@@ -146,7 +146,7 @@ public class BatteryEntry {
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);

View File

@@ -25,13 +25,14 @@ import android.widget.ProgressBar;
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 class PowerGaugePreference extends Preference {
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;

View File

@@ -28,6 +28,7 @@ import android.preference.Preference;
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 android.view.MenuItem;
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 @@ public class PowerUsageSummary extends PowerUsageBase {
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 @@ public class PowerUsageSummary extends PowerUsageBase {
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 @@ public class PowerUsageSummary extends PowerUsageBase {
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 @@ public class PowerUsageSummary extends PowerUsageBase {
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

View File

@@ -91,7 +91,7 @@ public final class SearchIndexableResources {
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(