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:
@@ -17,6 +17,7 @@
|
|||||||
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:paddingLeft="@*android:dimen/preference_item_padding_side"
|
android:paddingLeft="@*android:dimen/preference_item_padding_side"
|
||||||
android:paddingRight="@*android:dimen/preference_item_padding_side"
|
android:paddingRight="@*android:dimen/preference_item_padding_side"
|
||||||
android:paddingTop="8dip"
|
android:paddingTop="8dip"
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
android:id="@android:id/icon"
|
android:id="@android:id/icon"
|
||||||
android:layout_width="48dip"
|
android:layout_width="48dip"
|
||||||
android:layout_height="48dip"
|
android:layout_height="48dip"
|
||||||
android:layout_rowSpan="2"
|
android:layout_rowSpan="3"
|
||||||
android:layout_marginRight="8dip"
|
android:layout_marginRight="8dip"
|
||||||
android:scaleType="centerInside" />
|
android:scaleType="centerInside" />
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@
|
|||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@android:id/summary"
|
android:id="@android:id/text1"
|
||||||
android:layout_marginLeft="8dip"
|
android:layout_marginLeft="8dip"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
@@ -54,4 +55,12 @@
|
|||||||
android:progressDrawable="@drawable/data_usage_bar"
|
android:progressDrawable="@drawable/data_usage_bar"
|
||||||
style="?android:attr/progressBarStyleHorizontal" />
|
style="?android:attr/progressBarStyleHorizontal" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/summary"
|
||||||
|
android:layout_columnSpan="2"
|
||||||
|
android:layout_gravity="fill_horizontal"
|
||||||
|
android:layout_marginTop="4dip"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
</GridLayout>
|
</GridLayout>
|
@@ -26,66 +26,7 @@
|
|||||||
android:paddingBottom="5dip"
|
android:paddingBottom="5dip"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<include layout="@layout/app_percentage_item" />
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:paddingLeft="12dip"
|
|
||||||
android:paddingRight="?android:attr/scrollbarSize">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/icon"
|
|
||||||
android:layout_width="48dip"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="6dip"
|
|
||||||
android:layout_gravity="center" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="8dip"
|
|
||||||
android:layout_marginTop="2dip"
|
|
||||||
android:layout_marginBottom="6dip"
|
|
||||||
android:layout_weight="1">
|
|
||||||
|
|
||||||
<TextView android:id="@+id/name"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:layout_marginTop="2dip"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_toLeftOf="@+id/battery_percentage"
|
|
||||||
android:ellipsize="marquee"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
|
||||||
<TextView android:id="@+id/battery_percentage"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignBottom="@+id/name"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textStyle="bold"/>
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/gauge"
|
|
||||||
android:background="#80404040"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_marginTop="5dip"
|
|
||||||
android:layout_below="@id/battery_percentage"
|
|
||||||
android:layout_gravity="center_vertical" />
|
|
||||||
<TextView android:id="@+id/summary"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignLeft="@id/gauge"
|
|
||||||
android:layout_below="@id/gauge"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
/>
|
|
||||||
</RelativeLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!-- Force stop and report buttons -->
|
<!-- Force stop and report buttons -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@@ -3470,6 +3470,8 @@ found in the list of installed applications.</string>
|
|||||||
<!-- Label for data usage occuring while application in background. [CHAR LIMIT=48] -->
|
<!-- Label for data usage occuring while application in background. [CHAR LIMIT=48] -->
|
||||||
<string name="data_usage_label_background">Background</string>
|
<string name="data_usage_label_background">Background</string>
|
||||||
|
|
||||||
|
<!-- Body of dialog shown to request confirmation that mobile data will be disabled. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="data_usage_disable_mobile">Disable mobile data?</string>
|
||||||
<!-- Checkbox label that will disable mobile network data connection when user-defined limit is reached. [CHAR LIMIT=32] -->
|
<!-- Checkbox label that will disable mobile network data connection when user-defined limit is reached. [CHAR LIMIT=32] -->
|
||||||
<string name="data_usage_disable_mobile_limit">Disable mobile data at limit</string>
|
<string name="data_usage_disable_mobile_limit">Disable mobile data at limit</string>
|
||||||
<!-- Checkbox label that will disable 4G network data connection when user-defined limit is reached. [CHAR LIMIT=32] -->
|
<!-- Checkbox label that will disable 4G network data connection when user-defined limit is reached. [CHAR LIMIT=32] -->
|
||||||
@@ -3675,4 +3677,7 @@ found in the list of installed applications.</string>
|
|||||||
<!-- Button label for cancelling the new-password operation and retaining the user's previous full-backup password -->
|
<!-- Button label for cancelling the new-password operation and retaining the user's previous full-backup password -->
|
||||||
<string name="backup_pw_cancel_button_text">Cancel</string>
|
<string name="backup_pw_cancel_button_text">Cancel</string>
|
||||||
|
|
||||||
|
<!-- Representation of a numerical percentage. [CHAR LIMIT=8] -->
|
||||||
|
<string name="percentage"><xliff:g id="number" example="30">%d</xliff:g>%%</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -153,7 +153,8 @@ public class DataUsageSummary extends Fragment {
|
|||||||
private static final String TAB_WIFI = "wifi";
|
private static final String TAB_WIFI = "wifi";
|
||||||
private static final String TAB_ETHERNET = "ethernet";
|
private static final String TAB_ETHERNET = "ethernet";
|
||||||
|
|
||||||
private static final String TAG_CONFIRM_ROAMING = "confirmRoaming";
|
private static final String TAG_CONFIRM_DATA_DISABLE = "confirmDataDisable";
|
||||||
|
private static final String TAG_CONFIRM_DATA_ROAMING = "confirmDataRoaming";
|
||||||
private static final String TAG_CONFIRM_LIMIT = "confirmLimit";
|
private static final String TAG_CONFIRM_LIMIT = "confirmLimit";
|
||||||
private static final String TAG_CYCLE_EDITOR = "cycleEditor";
|
private static final String TAG_CYCLE_EDITOR = "cycleEditor";
|
||||||
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
|
private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
|
||||||
@@ -485,6 +486,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
final LayoutTransition chartTransition = buildLayoutTransition();
|
final LayoutTransition chartTransition = buildLayoutTransition();
|
||||||
chartTransition.setStartDelay(LayoutTransition.APPEARING, 0);
|
chartTransition.setStartDelay(LayoutTransition.APPEARING, 0);
|
||||||
chartTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
|
chartTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
|
||||||
|
chartTransition.setAnimator(LayoutTransition.DISAPPEARING, null);
|
||||||
mChart.setLayoutTransition(chartTransition);
|
mChart.setLayoutTransition(chartTransition);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -595,7 +597,6 @@ public class DataUsageSummary extends Fragment {
|
|||||||
if (TAB_MOBILE.equals(currentTab)) {
|
if (TAB_MOBILE.equals(currentTab)) {
|
||||||
setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_mobile);
|
setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_mobile);
|
||||||
setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_mobile_limit);
|
setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_mobile_limit);
|
||||||
mDataEnabled.setChecked(mConnService.getMobileDataEnabled());
|
|
||||||
mTemplate = buildTemplateMobileAll(getActiveSubscriberId(context));
|
mTemplate = buildTemplateMobileAll(getActiveSubscriberId(context));
|
||||||
|
|
||||||
} else if (TAB_3G.equals(currentTab)) {
|
} else if (TAB_3G.equals(currentTab)) {
|
||||||
@@ -799,6 +800,28 @@ public class DataUsageSummary extends Fragment {
|
|||||||
updatePolicy(false);
|
updatePolicy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local cache of value, used to work around delay when
|
||||||
|
* {@link ConnectivityManager#setMobileDataEnabled(boolean)} is async.
|
||||||
|
*/
|
||||||
|
private Boolean mMobileDataEnabled;
|
||||||
|
|
||||||
|
private boolean isMobileDataEnabled() {
|
||||||
|
if (mMobileDataEnabled != null) {
|
||||||
|
// TODO: deprecate and remove this once enabled flag is on policy
|
||||||
|
return mMobileDataEnabled;
|
||||||
|
} else {
|
||||||
|
return mConnService.getMobileDataEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMobileDataEnabled(boolean enabled) {
|
||||||
|
if (LOGD) Log.d(TAG, "setMobileDataEnabled()");
|
||||||
|
mConnService.setMobileDataEnabled(enabled);
|
||||||
|
mMobileDataEnabled = enabled;
|
||||||
|
updatePolicy(false);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isNetworkPolicyModifiable(NetworkPolicy policy) {
|
private boolean isNetworkPolicyModifiable(NetworkPolicy policy) {
|
||||||
return policy != null && isBandwidthControlEnabled() && mDataEnabled.isChecked();
|
return policy != null && isBandwidthControlEnabled() && mDataEnabled.isChecked();
|
||||||
}
|
}
|
||||||
@@ -888,6 +911,13 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move enabled state directly into policy
|
||||||
|
if (TAB_MOBILE.equals(mCurrentTab)) {
|
||||||
|
mBinding = true;
|
||||||
|
mDataEnabled.setChecked(isMobileDataEnabled());
|
||||||
|
mBinding = false;
|
||||||
|
}
|
||||||
|
|
||||||
final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate);
|
final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate);
|
||||||
if (isNetworkPolicyModifiable(policy)) {
|
if (isNetworkPolicyModifiable(policy)) {
|
||||||
mDisableAtLimitView.setVisibility(View.VISIBLE);
|
mDisableAtLimitView.setVisibility(View.VISIBLE);
|
||||||
@@ -979,15 +1009,18 @@ public class DataUsageSummary extends Fragment {
|
|||||||
if (mBinding) return;
|
if (mBinding) return;
|
||||||
|
|
||||||
final boolean dataEnabled = isChecked;
|
final boolean dataEnabled = isChecked;
|
||||||
mDataEnabled.setChecked(dataEnabled);
|
|
||||||
|
|
||||||
final String currentTab = mCurrentTab;
|
final String currentTab = mCurrentTab;
|
||||||
if (TAB_MOBILE.equals(currentTab)) {
|
if (TAB_MOBILE.equals(currentTab)) {
|
||||||
mConnService.setMobileDataEnabled(dataEnabled);
|
if (dataEnabled) {
|
||||||
|
setMobileDataEnabled(true);
|
||||||
|
} else {
|
||||||
|
// disabling data; show confirmation dialog which eventually
|
||||||
|
// calls setMobileDataEnabled() once user confirms.
|
||||||
|
ConfirmDataDisableFragment.show(DataUsageSummary.this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rebind policy to match radio state
|
updatePolicy(false);
|
||||||
updatePolicy(true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1358,14 +1391,14 @@ public class DataUsageSummary extends Fragment {
|
|||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
||||||
R.layout.data_usage_item, parent, false);
|
R.layout.app_percentage_item, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context context = parent.getContext();
|
final Context context = parent.getContext();
|
||||||
|
|
||||||
final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon);
|
final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon);
|
||||||
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
|
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
|
||||||
final TextView summary = (TextView) convertView.findViewById(android.R.id.summary);
|
final TextView text1 = (TextView) convertView.findViewById(android.R.id.text1);
|
||||||
final ProgressBar progress = (ProgressBar) convertView.findViewById(
|
final ProgressBar progress = (ProgressBar) convertView.findViewById(
|
||||||
android.R.id.progress);
|
android.R.id.progress);
|
||||||
|
|
||||||
@@ -1374,7 +1407,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
|
|
||||||
icon.setImageDrawable(detail.icon);
|
icon.setImageDrawable(detail.icon);
|
||||||
title.setText(detail.label);
|
title.setText(detail.label);
|
||||||
summary.setText(Formatter.formatFileSize(context, item.total));
|
text1.setText(Formatter.formatFileSize(context, item.total));
|
||||||
|
|
||||||
final int percentTotal = mLargest != 0 ? (int) (item.total * 100 / mLargest) : 0;
|
final int percentTotal = mLargest != 0 ? (int) (item.total * 100 / mLargest) : 0;
|
||||||
progress.setProgress(percentTotal);
|
progress.setProgress(percentTotal);
|
||||||
@@ -1544,6 +1577,38 @@ public class DataUsageSummary extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dialog to request user confirmation before disabling data.
|
||||||
|
*/
|
||||||
|
public static class ConfirmDataDisableFragment extends DialogFragment {
|
||||||
|
public static void show(DataUsageSummary parent) {
|
||||||
|
final ConfirmDataDisableFragment dialog = new ConfirmDataDisableFragment();
|
||||||
|
dialog.setTargetFragment(parent, 0);
|
||||||
|
dialog.show(parent.getFragmentManager(), TAG_CONFIRM_DATA_DISABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final Context context = getActivity();
|
||||||
|
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setMessage(R.string.data_usage_disable_mobile);
|
||||||
|
|
||||||
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
final DataUsageSummary target = (DataUsageSummary) getTargetFragment();
|
||||||
|
if (target != null) {
|
||||||
|
// TODO: extend to modify policy enabled flag.
|
||||||
|
target.setMobileDataEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(android.R.string.cancel, null);
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog to request user confirmation before setting
|
* Dialog to request user confirmation before setting
|
||||||
* {@link Settings.Secure#DATA_ROAMING}.
|
* {@link Settings.Secure#DATA_ROAMING}.
|
||||||
@@ -1552,7 +1617,7 @@ public class DataUsageSummary extends Fragment {
|
|||||||
public static void show(DataUsageSummary parent) {
|
public static void show(DataUsageSummary parent) {
|
||||||
final ConfirmDataRoamingFragment dialog = new ConfirmDataRoamingFragment();
|
final ConfirmDataRoamingFragment dialog = new ConfirmDataRoamingFragment();
|
||||||
dialog.setTargetFragment(parent, 0);
|
dialog.setTargetFragment(parent, 0);
|
||||||
dialog.show(parent.getFragmentManager(), TAG_CONFIRM_ROAMING);
|
dialog.show(parent.getFragmentManager(), TAG_CONFIRM_DATA_ROAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -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.graphics.drawable.Drawable;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom preference for displaying power consumption as a bar and an icon on the left for the
|
* Custom preference for displaying power consumption as a bar and an icon on
|
||||||
* subsystem/app type.
|
* the left for the subsystem/app type.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PowerGaugePreference extends Preference {
|
public class PowerGaugePreference extends Preference {
|
||||||
|
|
||||||
private Drawable mIcon;
|
|
||||||
private PercentageBar mGauge;
|
|
||||||
private double mValue;
|
|
||||||
private BatterySipper mInfo;
|
private BatterySipper mInfo;
|
||||||
private double mPercent;
|
private int mProgress;
|
||||||
|
private CharSequence mProgressText;
|
||||||
|
|
||||||
public PowerGaugePreference(Context context, Drawable icon, BatterySipper info) {
|
public PowerGaugePreference(Context context, Drawable icon, BatterySipper info) {
|
||||||
super(context);
|
super(context);
|
||||||
setLayoutResource(R.layout.preference_powergauge);
|
setLayoutResource(R.layout.app_percentage_item);
|
||||||
mIcon = icon;
|
setIcon(icon);
|
||||||
mGauge = new PercentageBar();
|
|
||||||
mGauge.bar = context.getResources().getDrawable(R.drawable.app_gauge);
|
|
||||||
mInfo = info;
|
mInfo = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setPercent(double percentOfMax, double percentOfTotal) {
|
||||||
* Sets the width of the gauge in percentage (0 - 100)
|
mProgress = (int) Math.ceil(percentOfMax);
|
||||||
* @param percent
|
mProgressText = getContext().getResources().getString(
|
||||||
*/
|
R.string.percentage, (int) Math.ceil(percentOfTotal));
|
||||||
void setGaugeValue(double percent) {
|
notifyChanged();
|
||||||
mValue = percent;
|
|
||||||
mGauge.percent = mValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPercent(double percent) {
|
|
||||||
mPercent = percent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BatterySipper getInfo() {
|
BatterySipper getInfo() {
|
||||||
return mInfo;
|
return mInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPowerIcon(Drawable icon) {
|
|
||||||
mIcon = icon;
|
|
||||||
notifyChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view) {
|
protected void onBindView(View view) {
|
||||||
super.onBindView(view);
|
super.onBindView(view);
|
||||||
|
|
||||||
ImageView appIcon = (ImageView) view.findViewById(R.id.appIcon);
|
final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
|
||||||
if (mIcon == null) {
|
progress.setProgress(mProgress);
|
||||||
mIcon = getContext().getResources().getDrawable(android.R.drawable.sym_def_app_icon);
|
|
||||||
}
|
|
||||||
appIcon.setImageDrawable(mIcon);
|
|
||||||
|
|
||||||
ImageView appGauge = (ImageView) view.findViewById(R.id.appGauge);
|
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||||
appGauge.setImageDrawable(mGauge);
|
text1.setText(mProgressText);
|
||||||
|
|
||||||
TextView percentView = (TextView) view.findViewById(R.id.percent);
|
|
||||||
percentView.setText((int) (Math.ceil(mPercent)) + "%");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.DisplaySettings;
|
import com.android.settings.DisplaySettings;
|
||||||
@@ -116,7 +117,6 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
|
|||||||
private ViewGroup mControlsParent;
|
private ViewGroup mControlsParent;
|
||||||
private long mStartTime;
|
private long mStartTime;
|
||||||
private DrainType mDrainType;
|
private DrainType mDrainType;
|
||||||
private PercentageBar mGauge;
|
|
||||||
private Drawable mAppIcon;
|
private Drawable mAppIcon;
|
||||||
private double mNoCoverage; // Percentage of time that there was no coverage
|
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
|
// Set the description
|
||||||
String summary = getDescriptionForDrainType();
|
final TextView summary = (TextView) mRootView.findViewById(android.R.id.summary);
|
||||||
((TextView)mRootView.findViewById(R.id.summary)).setText(summary);
|
summary.setText(getDescriptionForDrainType());
|
||||||
|
summary.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
mTypes = args.getIntArray(EXTRA_DETAIL_TYPES);
|
mTypes = args.getIntArray(EXTRA_DETAIL_TYPES);
|
||||||
mValues = args.getDoubleArray(EXTRA_DETAIL_VALUES);
|
mValues = args.getDoubleArray(EXTRA_DETAIL_VALUES);
|
||||||
|
|
||||||
mTitleView = (TextView)mRootView.findViewById(R.id.name);
|
mTitleView = (TextView) mRootView.findViewById(android.R.id.title);
|
||||||
mTitleView.setText(mTitle);
|
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);
|
mTwoButtonsPanel = (ViewGroup)mRootView.findViewById(R.id.two_buttons_panel);
|
||||||
mForceStopButton = (Button)mRootView.findViewById(R.id.left_button);
|
mForceStopButton = (Button)mRootView.findViewById(R.id.left_button);
|
||||||
mReportButton = (Button)mRootView.findViewById(R.id.right_button);
|
mReportButton = (Button)mRootView.findViewById(R.id.right_button);
|
||||||
mForceStopButton.setEnabled(false);
|
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);
|
final ProgressBar progress = (ProgressBar) mRootView.findViewById(android.R.id.progress);
|
||||||
iconImage.setImageDrawable(mAppIcon);
|
progress.setProgress(gaugeValue);
|
||||||
|
|
||||||
|
final ImageView icon = (ImageView) mRootView.findViewById(android.R.id.icon);
|
||||||
|
icon.setImageDrawable(mAppIcon);
|
||||||
|
|
||||||
mDetailsParent = (ViewGroup)mRootView.findViewById(R.id.details);
|
mDetailsParent = (ViewGroup)mRootView.findViewById(R.id.details);
|
||||||
mControlsParent = (ViewGroup)mRootView.findViewById(R.id.controls);
|
mControlsParent = (ViewGroup)mRootView.findViewById(R.id.controls);
|
||||||
|
@@ -23,7 +23,6 @@ import android.content.IntentFilter;
|
|||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.BatteryStats.Uid;
|
import android.os.BatteryStats.Uid;
|
||||||
import android.os.BatteryManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@@ -382,12 +381,11 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
|
|||||||
final double percentOfTotal = ((sipper.getSortValue() / mTotalPower) * 100);
|
final double percentOfTotal = ((sipper.getSortValue() / mTotalPower) * 100);
|
||||||
if (percentOfTotal < 1) continue;
|
if (percentOfTotal < 1) continue;
|
||||||
PowerGaugePreference pref = new PowerGaugePreference(getActivity(), sipper.getIcon(), sipper);
|
PowerGaugePreference pref = new PowerGaugePreference(getActivity(), sipper.getIcon(), sipper);
|
||||||
double percentOfMax = (sipper.getSortValue() * 100) / mMaxPower;
|
final double percentOfMax = (sipper.getSortValue() * 100) / mMaxPower;
|
||||||
sipper.percent = percentOfTotal;
|
sipper.percent = percentOfTotal;
|
||||||
pref.setTitle(sipper.name);
|
pref.setTitle(sipper.name);
|
||||||
pref.setPercent(percentOfTotal);
|
|
||||||
pref.setOrder(Integer.MAX_VALUE - (int) sipper.getSortValue()); // Invert the order
|
pref.setOrder(Integer.MAX_VALUE - (int) sipper.getSortValue()); // Invert the order
|
||||||
pref.setGaugeValue(percentOfMax);
|
pref.setPercent(percentOfMax, percentOfTotal);
|
||||||
if (sipper.uidObj != null) {
|
if (sipper.uidObj != null) {
|
||||||
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
|
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
|
||||||
}
|
}
|
||||||
@@ -771,8 +769,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
|
|||||||
(PowerGaugePreference) findPreference(
|
(PowerGaugePreference) findPreference(
|
||||||
Integer.toString(bs.uidObj.getUid()));
|
Integer.toString(bs.uidObj.getUid()));
|
||||||
if (pgp != null) {
|
if (pgp != null) {
|
||||||
pgp.setPowerIcon(bs.icon);
|
pgp.setIcon(bs.icon);
|
||||||
pgp.setPercent(bs.percent);
|
|
||||||
pgp.setTitle(bs.name);
|
pgp.setTitle(bs.name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -35,8 +35,11 @@ public interface ChartAxis {
|
|||||||
/** Convert screen point into raw value. */
|
/** Convert screen point into raw value. */
|
||||||
public long convertToValue(float point);
|
public long convertToValue(float point);
|
||||||
|
|
||||||
/** Build label that describes given raw value. */
|
/**
|
||||||
public void buildLabel(Resources res, SpannableStringBuilder builder, long value);
|
* Build label that describes given raw value. If the label is rounded for
|
||||||
|
* display, return the rounded value.
|
||||||
|
*/
|
||||||
|
public long buildLabel(Resources res, SpannableStringBuilder builder, long value);
|
||||||
|
|
||||||
/** Return list of tick points for drawing a grid. */
|
/** Return list of tick points for drawing a grid. */
|
||||||
public float[] getTickPoints();
|
public float[] getTickPoints();
|
||||||
|
@@ -27,7 +27,6 @@ import android.text.SpannableStringBuilder;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -334,11 +333,11 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getWarningBytes() {
|
public long getWarningBytes() {
|
||||||
return mSweepWarning.getValue();
|
return mSweepWarning.getLabelValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLimitBytes() {
|
public long getLimitBytes() {
|
||||||
return mSweepLimit.getValue();
|
return mSweepLimit.getLabelValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getStatsStart() {
|
private long getStatsStart() {
|
||||||
@@ -433,9 +432,10 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
||||||
// TODO: convert to better string
|
// TODO: convert to better string
|
||||||
builder.replace(0, builder.length(), Long.toString(value));
|
builder.replace(0, builder.length(), Long.toString(value));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@@ -493,16 +493,19 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
private static final Object sSpanUnit = new Object();
|
private static final Object sSpanUnit = new Object();
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
||||||
|
|
||||||
float result = value;
|
|
||||||
final CharSequence unit;
|
final CharSequence unit;
|
||||||
|
float result = value;
|
||||||
|
long labelValue = 1;
|
||||||
if (result <= 100 * MB_IN_BYTES) {
|
if (result <= 100 * MB_IN_BYTES) {
|
||||||
unit = res.getText(com.android.internal.R.string.megabyteShort);
|
unit = res.getText(com.android.internal.R.string.megabyteShort);
|
||||||
result /= MB_IN_BYTES;
|
result /= MB_IN_BYTES;
|
||||||
|
labelValue = MB_IN_BYTES;
|
||||||
} else {
|
} else {
|
||||||
unit = res.getText(com.android.internal.R.string.gigabyteShort);
|
unit = res.getText(com.android.internal.R.string.gigabyteShort);
|
||||||
result /= GB_IN_BYTES;
|
result /= GB_IN_BYTES;
|
||||||
|
labelValue = GB_IN_BYTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CharSequence size;
|
final CharSequence size;
|
||||||
@@ -511,11 +514,14 @@ public class ChartDataUsageView extends ChartView {
|
|||||||
} else {
|
} else {
|
||||||
size = String.format("%.0f", result);
|
size = String.format("%.0f", result);
|
||||||
}
|
}
|
||||||
|
labelValue *= Float.parseFloat(size.toString());
|
||||||
|
|
||||||
final int[] sizeBounds = findOrCreateSpan(builder, sSpanSize, "^1");
|
final int[] sizeBounds = findOrCreateSpan(builder, sSpanSize, "^1");
|
||||||
builder.replace(sizeBounds[0], sizeBounds[1], size);
|
builder.replace(sizeBounds[0], sizeBounds[1], size);
|
||||||
final int[] unitBounds = findOrCreateSpan(builder, sSpanUnit, "^2");
|
final int[] unitBounds = findOrCreateSpan(builder, sSpanUnit, "^2");
|
||||||
builder.replace(unitBounds[0], unitBounds[1], unit);
|
builder.replace(unitBounds[0], unitBounds[1], unit);
|
||||||
|
|
||||||
|
return labelValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@@ -67,6 +67,7 @@ public class ChartSweepView extends View {
|
|||||||
|
|
||||||
private ChartAxis mAxis;
|
private ChartAxis mAxis;
|
||||||
private long mValue;
|
private long mValue;
|
||||||
|
private long mLabelValue;
|
||||||
|
|
||||||
private long mValidAfter;
|
private long mValidAfter;
|
||||||
private long mValidBefore;
|
private long mValidBefore;
|
||||||
@@ -226,7 +227,7 @@ public class ChartSweepView extends View {
|
|||||||
|
|
||||||
private void invalidateLabel() {
|
private void invalidateLabel() {
|
||||||
if (mLabelTemplate != null && mAxis != null) {
|
if (mLabelTemplate != null && mAxis != null) {
|
||||||
mAxis.buildLabel(getResources(), mLabelTemplate, mValue);
|
mLabelValue = mAxis.buildLabel(getResources(), mLabelTemplate, mValue);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,6 +266,10 @@ public class ChartSweepView extends View {
|
|||||||
return mValue;
|
return mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLabelValue() {
|
||||||
|
return mLabelValue;
|
||||||
|
}
|
||||||
|
|
||||||
public float getPoint() {
|
public float getPoint() {
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
return mAxis.convertToPoint(mValue);
|
return mAxis.convertToPoint(mValue);
|
||||||
|
@@ -52,8 +52,8 @@ public class InvertedChartAxis implements ChartAxis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
|
||||||
mWrapped.buildLabel(res, builder, value);
|
return mWrapped.buildLabel(res, builder, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
Reference in New Issue
Block a user