Unify data/power layout, confirm disable, round.
Share consistent layout between data usage and battery usage. Show confirmation dialog before disabling mobile data. Round warning/limit sweep values to match displayed label. Suppress fade when switching data usage tabs. Bug: 5208510, 5058157, 5038589, 5252816 Change-Id: I3c76f3397445d2d3b173666a41672871df4c61af
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -20,70 +20,46 @@ import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.Preference;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Custom preference for displaying power consumption as a bar and an icon on the left for the
|
||||
* subsystem/app type.
|
||||
*
|
||||
* 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 {
|
||||
|
||||
private Drawable mIcon;
|
||||
private PercentageBar mGauge;
|
||||
private double mValue;
|
||||
private BatterySipper mInfo;
|
||||
private double mPercent;
|
||||
private int mProgress;
|
||||
private CharSequence mProgressText;
|
||||
|
||||
public PowerGaugePreference(Context context, Drawable icon, BatterySipper info) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.preference_powergauge);
|
||||
mIcon = icon;
|
||||
mGauge = new PercentageBar();
|
||||
mGauge.bar = context.getResources().getDrawable(R.drawable.app_gauge);
|
||||
setLayoutResource(R.layout.app_percentage_item);
|
||||
setIcon(icon);
|
||||
mInfo = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the gauge in percentage (0 - 100)
|
||||
* @param percent
|
||||
*/
|
||||
void setGaugeValue(double percent) {
|
||||
mValue = percent;
|
||||
mGauge.percent = mValue;
|
||||
}
|
||||
|
||||
void setPercent(double percent) {
|
||||
mPercent = percent;
|
||||
public void setPercent(double percentOfMax, double percentOfTotal) {
|
||||
mProgress = (int) Math.ceil(percentOfMax);
|
||||
mProgressText = getContext().getResources().getString(
|
||||
R.string.percentage, (int) Math.ceil(percentOfTotal));
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
BatterySipper getInfo() {
|
||||
return mInfo;
|
||||
}
|
||||
|
||||
void setPowerIcon(Drawable icon) {
|
||||
mIcon = icon;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
|
||||
ImageView appIcon = (ImageView) view.findViewById(R.id.appIcon);
|
||||
if (mIcon == null) {
|
||||
mIcon = getContext().getResources().getDrawable(android.R.drawable.sym_def_app_icon);
|
||||
}
|
||||
appIcon.setImageDrawable(mIcon);
|
||||
final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
|
||||
progress.setProgress(mProgress);
|
||||
|
||||
ImageView appGauge = (ImageView) view.findViewById(R.id.appGauge);
|
||||
appGauge.setImageDrawable(mGauge);
|
||||
|
||||
TextView percentView = (TextView) view.findViewById(R.id.percent);
|
||||
percentView.setText((int) (Math.ceil(mPercent)) + "%");
|
||||
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||
text1.setText(mProgressText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.DisplaySettings;
|
||||
@@ -116,7 +117,6 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
|
||||
private ViewGroup mControlsParent;
|
||||
private long mStartTime;
|
||||
private DrainType mDrainType;
|
||||
private PercentageBar mGauge;
|
||||
private Drawable mAppIcon;
|
||||
private double mNoCoverage; // Percentage of time that there was no coverage
|
||||
|
||||
@@ -181,30 +181,29 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
|
||||
}
|
||||
|
||||
// Set the description
|
||||
String summary = getDescriptionForDrainType();
|
||||
((TextView)mRootView.findViewById(R.id.summary)).setText(summary);
|
||||
|
||||
final TextView summary = (TextView) mRootView.findViewById(android.R.id.summary);
|
||||
summary.setText(getDescriptionForDrainType());
|
||||
summary.setVisibility(View.VISIBLE);
|
||||
|
||||
mTypes = args.getIntArray(EXTRA_DETAIL_TYPES);
|
||||
mValues = args.getDoubleArray(EXTRA_DETAIL_VALUES);
|
||||
|
||||
mTitleView = (TextView)mRootView.findViewById(R.id.name);
|
||||
mTitleView = (TextView) mRootView.findViewById(android.R.id.title);
|
||||
mTitleView.setText(mTitle);
|
||||
((TextView)mRootView.findViewById(R.id.battery_percentage))
|
||||
.setText(String.format("%d%%", percentage));
|
||||
|
||||
final TextView text1 = (TextView)mRootView.findViewById(android.R.id.text1);
|
||||
text1.setText(getString(R.string.percentage, percentage));
|
||||
|
||||
mTwoButtonsPanel = (ViewGroup)mRootView.findViewById(R.id.two_buttons_panel);
|
||||
mForceStopButton = (Button)mRootView.findViewById(R.id.left_button);
|
||||
mReportButton = (Button)mRootView.findViewById(R.id.right_button);
|
||||
mForceStopButton.setEnabled(false);
|
||||
|
||||
ImageView gaugeImage = (ImageView)mRootView.findViewById(R.id.gauge);
|
||||
mGauge = new PercentageBar();
|
||||
mGauge.percent = gaugeValue;
|
||||
mGauge.bar = getResources().getDrawable(R.drawable.app_gauge);
|
||||
gaugeImage.setImageDrawable(mGauge);
|
||||
|
||||
ImageView iconImage = (ImageView)mRootView.findViewById(R.id.icon);
|
||||
iconImage.setImageDrawable(mAppIcon);
|
||||
final ProgressBar progress = (ProgressBar) mRootView.findViewById(android.R.id.progress);
|
||||
progress.setProgress(gaugeValue);
|
||||
|
||||
final ImageView icon = (ImageView) mRootView.findViewById(android.R.id.icon);
|
||||
icon.setImageDrawable(mAppIcon);
|
||||
|
||||
mDetailsParent = (ViewGroup)mRootView.findViewById(R.id.details);
|
||||
mControlsParent = (ViewGroup)mRootView.findViewById(R.id.controls);
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.IntentFilter;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.BatteryStats.Uid;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -382,12 +381,11 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
|
||||
final double percentOfTotal = ((sipper.getSortValue() / mTotalPower) * 100);
|
||||
if (percentOfTotal < 1) continue;
|
||||
PowerGaugePreference pref = new PowerGaugePreference(getActivity(), sipper.getIcon(), sipper);
|
||||
double percentOfMax = (sipper.getSortValue() * 100) / mMaxPower;
|
||||
final double percentOfMax = (sipper.getSortValue() * 100) / mMaxPower;
|
||||
sipper.percent = percentOfTotal;
|
||||
pref.setTitle(sipper.name);
|
||||
pref.setPercent(percentOfTotal);
|
||||
pref.setOrder(Integer.MAX_VALUE - (int) sipper.getSortValue()); // Invert the order
|
||||
pref.setGaugeValue(percentOfMax);
|
||||
pref.setPercent(percentOfMax, percentOfTotal);
|
||||
if (sipper.uidObj != null) {
|
||||
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
|
||||
}
|
||||
@@ -771,8 +769,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
|
||||
(PowerGaugePreference) findPreference(
|
||||
Integer.toString(bs.uidObj.getUid()));
|
||||
if (pgp != null) {
|
||||
pgp.setPowerIcon(bs.icon);
|
||||
pgp.setPercent(bs.percent);
|
||||
pgp.setIcon(bs.icon);
|
||||
pgp.setTitle(bs.name);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user