diff --git a/res/layout/power_usage_details.xml b/res/layout/power_usage_details.xml index 8aa625f669e..ea7cfb34698 100644 --- a/res/layout/power_usage_details.xml +++ b/res/layout/power_usage_details.xml @@ -22,55 +22,70 @@ android:id="@+id/all_details" android:layout_width="fill_parent" android:layout_height="fill_parent" - android:paddingRight="6dip" android:paddingTop="5dip" android:paddingBottom="5dip" android:orientation="vertical"> - - + android:minHeight="?android:attr/listPreferredItemHeight" + android:orientation="horizontal" + android:gravity="center_vertical" + android:paddingLeft="12dip" + android:paddingRight="?android:attr/scrollbarSize"> - - + android:layout_marginRight="6dip" + android:layout_gravity="center" /> + + + - + android:textAppearance="?android:attr/textAppearanceMedium"/> - - - - - - + android:singleLine="true" + android:layout_alignParentRight="true" + android:layout_alignBottom="@+id/name" + android:layout_gravity="bottom" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textStyle="bold"/> + + + + Battery use since reset - Use duration - %1$s + %1$s since unplugged + + Device awake time + + WiFi on time + + WiFi on time %1$s" - " %2$s"%%" @@ -1705,6 +1711,9 @@ found in the list of installed applications. Bluetooth settings + + Battery used by voice calls + Battery used when phone is idle @@ -1747,7 +1756,12 @@ found in the list of installed applications. Usage totals Refresh - + + + Android OS + + Mediaserver + Speech synthesis diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml index 450e438c435..b49b1409f59 100644 --- a/res/xml/power_usage_summary.xml +++ b/res/xml/power_usage_summary.xml @@ -15,7 +15,6 @@ --> - + android:title="@string/battery_since_unplugged" + android:key="app_list"> diff --git a/src/com/android/settings/fuelgauge/PercentageBar.java b/src/com/android/settings/fuelgauge/PercentageBar.java new file mode 100644 index 00000000000..1c4478bf49e --- /dev/null +++ b/src/com/android/settings/fuelgauge/PercentageBar.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 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.fuelgauge; + +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.PixelFormat; +import android.graphics.drawable.Drawable; + +/** + * A drawable for drawing a bar with a background. + */ +class PercentageBar extends Drawable { + + Drawable bar; + double percent; + int lastWidth = -1; + + @Override + public void draw(Canvas canvas) { + if (lastWidth == -1) { + lastWidth = getBarWidth(); + bar.setBounds(0, 0, lastWidth, bar.getIntrinsicHeight()); + } + bar.draw(canvas); + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + @Override + public void setAlpha(int alpha) { + // Ignore + } + + @Override + public void setColorFilter(ColorFilter cf) { + // Ignore + } + + private int getBarWidth() { + int width = (int) ((this.getBounds().width() * percent) / 100); + int intrinsicWidth = bar.getIntrinsicWidth(); + return Math.max(width, intrinsicWidth); + } + + @Override + public int getIntrinsicHeight() { + return bar.getIntrinsicHeight(); + } +} diff --git a/src/com/android/settings/fuelgauge/PowerGaugePreference.java b/src/com/android/settings/fuelgauge/PowerGaugePreference.java index 5778b39bce3..68f294c39d2 100644 --- a/src/com/android/settings/fuelgauge/PowerGaugePreference.java +++ b/src/com/android/settings/fuelgauge/PowerGaugePreference.java @@ -37,7 +37,7 @@ import com.android.settings.fuelgauge.PowerUsageSummary.BatterySipper; public class PowerGaugePreference extends Preference { private Drawable mIcon; - private GaugeDrawable mGauge; + private PercentageBar mGauge; private double mValue; private BatterySipper mInfo; private double mPercent; @@ -46,7 +46,7 @@ public class PowerGaugePreference extends Preference { super(context); setLayoutResource(R.layout.preference_powergauge); mIcon = icon; - mGauge = new GaugeDrawable(); + mGauge = new PercentageBar(); mGauge.bar = context.getResources().getDrawable(R.drawable.app_gauge); mInfo = info; } @@ -90,44 +90,4 @@ public class PowerGaugePreference extends Preference { percentView.setText((int) (Math.ceil(mPercent)) + "%"); } - static class GaugeDrawable extends Drawable { - Drawable bar; - double percent; - int lastWidth = -1; - - @Override - public void draw(Canvas canvas) { - if (lastWidth == -1) { - lastWidth = getBarWidth(); - bar.setBounds(0, 0, lastWidth, bar.getIntrinsicHeight()); - } - bar.draw(canvas); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public void setAlpha(int alpha) { - // Ignore - } - - @Override - public void setColorFilter(ColorFilter cf) { - // Ignore - } - - private int getBarWidth() { - int width = (int) ((this.getBounds().width() * percent) / 100); - int intrinsicWidth = bar.getIntrinsicWidth(); - return Math.max(width, intrinsicWidth); - } - - @Override - public int getIntrinsicHeight() { - return bar.getIntrinsicHeight(); - } - } } diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java index e36a8bc776d..e78e0411e71 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java +++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java @@ -27,10 +27,12 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.provider.Settings; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageView; import android.widget.TextView; import com.android.settings.InstalledAppDetails; @@ -48,6 +50,17 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener APP } + // Note: Must match the sequence of the DrainType + private static int[] sDrainTypeDesciptions = new int[] { + R.string.battery_desc_standby, + R.string.battery_desc_radio, + R.string.battery_desc_voice, + R.string.battery_desc_wifi, + R.string.battery_desc_bluetooth, + R.string.battery_desc_display, + R.string.battery_desc_apps + }; + public static final int ACTION_DISPLAY_SETTINGS = 1; public static final int ACTION_WIFI_SETTINGS = 2; public static final int ACTION_BLUETOOTH_SETTINGS = 3; @@ -59,16 +72,18 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener public static final String EXTRA_TITLE = "title"; public static final String EXTRA_PERCENT = "percent"; + public static final String EXTRA_GAUGE = "gauge"; public static final String EXTRA_UID = "uid"; public static final String EXTRA_USAGE_SINCE = "since"; public static final String EXTRA_USAGE_DURATION = "duration"; - public static final String EXTRA_DETAIL_TYPES = "types"; - public static final String EXTRA_DETAIL_VALUES = "values"; - public static final String EXTRA_DRAIN_TYPE = "drainType"; + public static final String EXTRA_DETAIL_TYPES = "types"; // Array of usage types (cpu, gps, etc) + public static final String EXTRA_DETAIL_VALUES = "values"; // Array of doubles + public static final String EXTRA_DRAIN_TYPE = "drainType"; // DrainType + public static final String EXTRA_ICON_PACKAGE = "iconPackage"; // String + public static final String EXTRA_ICON_ID = "iconId"; // Int private static final boolean DEBUG = true; private String mTitle; - private double mPercentage; private int mUsageSince; private int[] mTypes; private int mUid; @@ -79,6 +94,8 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener private DrainType mDrainType; private int mAction1; private int mAction2; + private PercentageBar mGauge; + private Drawable mAppIcon; private static final String TAG = "PowerUsageDetail"; private Button mButton1; @@ -106,20 +123,51 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener private void createDetails() { final Intent intent = getIntent(); mTitle = intent.getStringExtra(EXTRA_TITLE); - mPercentage = intent.getDoubleExtra(EXTRA_PERCENT, -1); + final int percentage = intent.getIntExtra(EXTRA_PERCENT, 1); + final int gaugeValue = intent.getIntExtra(EXTRA_GAUGE, 1); mUsageSince = intent.getIntExtra(EXTRA_USAGE_SINCE, USAGE_SINCE_UNPLUGGED); mUid = intent.getIntExtra(EXTRA_UID, 0); mDrainType = (DrainType) intent.getSerializableExtra(EXTRA_DRAIN_TYPE); + String iconPackage = intent.getStringExtra(EXTRA_ICON_PACKAGE); + int iconId = intent.getIntExtra(EXTRA_ICON_ID, 0); + if (!TextUtils.isEmpty(iconPackage)) { + try { + final PackageManager pm = getPackageManager(); + ApplicationInfo ai = pm.getPackageInfo(iconPackage, 0).applicationInfo; + if (ai != null) { + mAppIcon = ai.loadIcon(pm); + } + } catch (NameNotFoundException nnfe) { + // Use default icon + } + } else if (iconId != 0) { + mAppIcon = getResources().getDrawable(iconId); + } + if (mAppIcon == null) { + mAppIcon = getPackageManager().getDefaultActivityIcon(); + } + // Set the description + String summary = getDescriptionForDrainType(); + ((TextView)findViewById(R.id.summary)).setText(summary); + mTypes = intent.getIntArrayExtra(EXTRA_DETAIL_TYPES); mValues = intent.getDoubleArrayExtra(EXTRA_DETAIL_VALUES); mTitleView = (TextView) findViewById(R.id.name); mTitleView.setText(mTitle); - // TODO: I18N ((TextView)findViewById(R.id.battery_percentage)) - .setText(String.format("%3.2f%% of battery usage since last unplugged", mPercentage)); + .setText(String.format("%d%%", percentage)); + ImageView gaugeImage = (ImageView) findViewById(R.id.gauge); + mGauge = new PercentageBar(); + mGauge.percent = gaugeValue; + mGauge.bar = getResources().getDrawable(R.drawable.app_gauge); + gaugeImage.setImageDrawable(mGauge); + + ImageView iconImage = (ImageView) findViewById(R.id.icon); + iconImage.setImageDrawable(mAppIcon); + mDetailsParent = (ViewGroup) findViewById(R.id.details); LayoutInflater inflater = getLayoutInflater(); if (mTypes != null && mValues != null) { @@ -181,7 +229,7 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener mAction1 = 0; mAction2 = 0; PackageManager pm = getPackageManager(); - String[] packages = pm.getPackagesForUid(mUid); + String[] packages = pm.getPackagesForUid(uid); PackageInfo pi = null; try { pi = packages != null ? pm.getPackageInfo(packages[0], 0) : null; @@ -189,12 +237,14 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener ApplicationInfo ai = pi != null? pi.applicationInfo : null; boolean isSystem = ai != null? (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0 : false; - if (uid == 0 || !isSystem) { + if (uid < 1000 || !isSystem) { switch (mDrainType) { case APP: //label1 = getString(R.string.battery_action_stop); - label2 = getString(R.string.battery_action_app_details); - mAction2 = ACTION_APP_DETAILS; + if (packages != null) { + label2 = getString(R.string.battery_action_app_details); + mAction2 = ACTION_APP_DETAILS; + } break; case SCREEN: label2 = getString(R.string.battery_action_display); @@ -246,7 +296,7 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener } private void fillPackagesSection(int uid) { - if (uid == 0) { + if (uid < 1) { removePackagesSection(); return; } @@ -283,4 +333,8 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener } } } + + private String getDescriptionForDrainType() { + return getResources().getString(sDrainTypeDesciptions[mDrainType.ordinal()]); + } } diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index b8919eefe14..d36dce77511 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -85,14 +85,19 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { private PowerProfile mPowerProfile; - private HashMap mNameCache = new HashMap(); - private HashMap mIconCache = new HashMap(); + private HashMap mUidCache = new HashMap(); /** Queue for fetching name and icon for an application */ private ArrayList mRequestQueue = new ArrayList(); private Thread mRequestThread; private boolean mAbort; + static class UidToDetail { + String name; + String packageName; + Drawable icon; + } + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -126,7 +131,12 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { BatterySipper sipper = pgp.getInfo(); Intent intent = new Intent(this, PowerUsageDetail.class); intent.putExtra(PowerUsageDetail.EXTRA_TITLE, sipper.name); - intent.putExtra(PowerUsageDetail.EXTRA_PERCENT, sipper.getSortValue() * 100 / mTotalPower); + intent.putExtra(PowerUsageDetail.EXTRA_PERCENT, (int) + Math.ceil(sipper.getSortValue() * 100 / mTotalPower)); + intent.putExtra(PowerUsageDetail.EXTRA_GAUGE, (int) + Math.ceil(sipper.getSortValue() * 100 / mMaxPower)); + intent.putExtra(PowerUsageDetail.EXTRA_ICON_PACKAGE, sipper.defaultPackageName); + intent.putExtra(PowerUsageDetail.EXTRA_ICON_ID, sipper.iconId); if (sipper.uidObj != null) { intent.putExtra(PowerUsageDetail.EXTRA_UID, sipper.uidObj.getUid()); } @@ -266,7 +276,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { private void updateStatsPeriod(long duration) { String durationString = Utils.formatElapsedTime(this, duration / 1000); String label = getString(R.string.battery_stats_duration, durationString); - mAppListGroup.setTitle(label); + setTitle(label); } private void processAppUsage() { @@ -475,8 +485,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { addWiFiUsage(uSecNow); addBluetoothUsage(uSecNow); addIdleUsage(uSecNow); // Not including cellular idle power - //addRadioUsage(uSecNow); // Cannot include this because airplane mode is not tracked yet - // and we don't know if the radio is currently running on 2/3G. + addRadioUsage(uSecNow); } private void addEntry(String label, DrainType drainType, long time, int iconId, double power) { @@ -484,6 +493,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { mTotalPower += power; BatterySipper bs = new BatterySipper(label, drainType, iconId, null, new double[] {power}); bs.usageTime = time; + bs.iconId = iconId; mUsageList.add(bs); } @@ -503,6 +513,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { class BatterySipper implements Comparable { String name; Drawable icon; + int iconId; // For passing to the detail screen. Uid uidObj; double value; double[] values; @@ -512,6 +523,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { long gpsTime; long cpuFgTime; double percent; + String defaultPackageName; BatterySipper(String label, DrainType drainType, int iconId, Uid uid, double[] values) { this.values = values; @@ -548,20 +560,28 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { void getQuickNameIconForUid(Uid uidObj) { final int uid = uidObj.getUid(); final String uidString = Integer.toString(uid); - if (mNameCache.containsKey(uidString)) { - name = mNameCache.get(uidString); - icon = mIconCache.get(uidString); + if (mUidCache.containsKey(uidString)) { + UidToDetail utd = mUidCache.get(uidString); + defaultPackageName = utd.packageName; + name = utd.name; + icon = utd.icon; return; } PackageManager pm = getPackageManager(); final Drawable defaultActivityIcon = pm.getDefaultActivityIcon(); String[] packages = pm.getPackagesForUid(uid); + icon = pm.getDefaultActivityIcon(); if (packages == null) { - name = Integer.toString(uid); + //name = Integer.toString(uid); + if (uid == 0) { + name = getResources().getString(R.string.process_kernel_label); + } else if (name.equals("mediaserver")) { + name = getResources().getString(R.string.process_mediaserver_label); + } + return; } else { //name = packages[0]; } - icon = pm.getDefaultActivityIcon(); synchronized (mRequestQueue) { mRequestQueue.add(this); } @@ -596,6 +616,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { packageLabels[i] = label.toString(); } if (ai.icon != 0) { + defaultPackageName = packages[i]; icon = ai.loadIcon(pm); break; } @@ -617,6 +638,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { if (nm != null) { name = nm.toString(); if (pi.applicationInfo.icon != 0) { + defaultPackageName = pkgName; icon = pi.applicationInfo.loadIcon(pm); } break; @@ -627,8 +649,11 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable { } } final String uidString = Integer.toString(uidObj.getUid()); - mNameCache.put(uidString, name); - mIconCache.put(uidString, icon); + UidToDetail utd = new UidToDetail(); + utd.name = name; + utd.icon = icon; + utd.packageName = defaultPackageName; + mUidCache.put(uidString, utd); mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_NAME_ICON, this)); } }