Fix randomly showing anomaly icon

Sometimes PowerGaugePreference will show anomaly icon when they
shouldn't. I think it is because PreferenceViewHolder has cache
about the previous data.

This cl fixes it by setting compound drawable as 0 when
showAnomalyIcon is false.

Bug: 36924669
Test: RunSettingsRoboTests
Change-Id: I5ea0dc307aafcce386c84963e618d1213de5ec19
This commit is contained in:
jackqdyulei
2017-05-04 18:02:14 -07:00
parent 5a24c1b84c
commit 3bd2420911
2 changed files with 14 additions and 2 deletions

View File

@@ -111,8 +111,9 @@ public class PowerGaugePreference extends TintablePreference {
if (mShowAnomalyIcon) {
subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_warning_24dp, 0,
0, 0);
} else {
subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 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);
titleView.setContentDescription(mContentDescription);

View File

@@ -82,7 +82,7 @@ public class PowerGaugePreferenceTest {
}
@Test
public void testOnBindViewHolder_bindAnomalyIcon() {
public void testOnBindViewHolder_showAnomaly_bindAnomalyIcon() {
mPowerGaugePreference.shouldShowAnomalyIcon(true);
mPowerGaugePreference.onBindViewHolder(mPreferenceViewHolder);
@@ -92,6 +92,17 @@ public class PowerGaugePreferenceTest {
assertThat(drawables[0]).isInstanceOf(VectorDrawable.class);
}
@Test
public void testOnBindViewHolder_notShowAnomaly_bindAnomalyIcon() {
mPowerGaugePreference.shouldShowAnomalyIcon(false);
mPowerGaugePreference.onBindViewHolder(mPreferenceViewHolder);
final Drawable[] drawables = ((TextView) mPreferenceViewHolder.findViewById(
R.id.widget_summary)).getCompoundDrawablesRelative();
assertThat(drawables[0]).isNull();
}
@Test
public void testOnBindViewHolder_bindContentDescription() {
mPowerGaugePreference.setContentDescription(CONTENT_DESCRIPTION);