Add anomaly icon for PowerGaugePreference

When the app contains anomaly, we should show anomaly icon(triangle
alert).

This cl also extracts a new method refreshAppListGroup from refreshUi.
New method is used to only refresh appListGroup. Reason for this action:

1. Improve performance(partial refresh)
2. We init AnomalyLoader in refreshUi, invoke refreshUi in
onLoadFinish will create infinite loop.

Bug: 36924669
Test: RunSettingsRoboTests
Change-Id: If54c89349e21763ca714123ac6ae884bd0f6a377
This commit is contained in:
jackqdyulei
2017-05-01 13:03:49 -07:00
parent b45a9fe0a9
commit 4cb19e74b3
5 changed files with 185 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -41,6 +42,7 @@ public class PowerGaugePreference extends TintablePreference {
private BatteryEntry mInfo;
private CharSequence mContentDescription;
private CharSequence mProgress;
private boolean mShowAnomalyIcon;
public PowerGaugePreference(Context context, Drawable icon, CharSequence contentDescription,
BatteryEntry info) {
@@ -63,6 +65,7 @@ public class PowerGaugePreference extends TintablePreference {
mInfo = info;
mContentDescription = contentDescription;
mIconSize = context.getResources().getDimensionPixelSize(R.dimen.app_icon_size);
mShowAnomalyIcon = false;
}
public void setContentDescription(String name) {
@@ -88,6 +91,11 @@ public class PowerGaugePreference extends TintablePreference {
return mProgress;
}
public void shouldShowAnomalyIcon(boolean showAnomalyIcon) {
mShowAnomalyIcon = showAnomalyIcon;
notifyChanged();
}
BatteryEntry getInfo() {
return mInfo;
}
@@ -98,6 +106,12 @@ public class PowerGaugePreference extends TintablePreference {
ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
icon.setLayoutParams(new LinearLayout.LayoutParams(mIconSize, mIconSize));
final TextView subtitle = (TextView) view.findViewById(R.id.widget_summary);
subtitle.setText(mProgress);
if (mShowAnomalyIcon) {
subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_warning_24dp, 0,
0, 0);
}
((TextView) view.findViewById(R.id.widget_summary)).setText(mProgress);
if (mContentDescription != null) {
final TextView titleView = (TextView) view.findViewById(android.R.id.title);