Add content description string for '<1%'.
Bug: 322855583 Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage Change-Id: I704a591ab4cba21644e86457c2dd1000ceecc291
This commit is contained in:
@@ -6108,6 +6108,8 @@
|
|||||||
<string name="battery_usage_spinner_view_by_systems">View by systems</string>
|
<string name="battery_usage_spinner_view_by_systems">View by systems</string>
|
||||||
<!-- [CHAR_LIMIT=NONE] Less than some percentage, e.g. < 1% -->
|
<!-- [CHAR_LIMIT=NONE] Less than some percentage, e.g. < 1% -->
|
||||||
<string name="battery_usage_less_than_percent">< <xliff:g id="percentage">%1$s</xliff:g></string>
|
<string name="battery_usage_less_than_percent">< <xliff:g id="percentage">%1$s</xliff:g></string>
|
||||||
|
<!-- [CHAR_LIMIT=NONE] Accessibility content description for less than some percentage, e.g. less than 1% -->
|
||||||
|
<string name="battery_usage_less_than_percent_content_description">less than <xliff:g id="percentage">%1$s</xliff:g></string>
|
||||||
<!-- Process Stats strings -->
|
<!-- Process Stats strings -->
|
||||||
<skip />
|
<skip />
|
||||||
<!-- Description of battery information footer text. [CHAR LIMIT=NONE] -->
|
<!-- Description of battery information footer text. [CHAR LIMIT=NONE] -->
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
@VisibleForTesting FooterPreference mFooterPreference;
|
@VisibleForTesting FooterPreference mFooterPreference;
|
||||||
@VisibleForTesting BatteryDiffData mBatteryDiffData;
|
@VisibleForTesting BatteryDiffData mBatteryDiffData;
|
||||||
@VisibleForTesting String mPercentLessThanThresholdText;
|
@VisibleForTesting String mPercentLessThanThresholdText;
|
||||||
|
@VisibleForTesting String mPercentLessThanThresholdContentDescription;
|
||||||
@VisibleForTesting boolean mIsHighlightSlot;
|
@VisibleForTesting boolean mIsHighlightSlot;
|
||||||
@VisibleForTesting int mAnomalyKeyNumber;
|
@VisibleForTesting int mAnomalyKeyNumber;
|
||||||
@VisibleForTesting String mAnomalyEntryKey;
|
@VisibleForTesting String mAnomalyEntryKey;
|
||||||
@@ -202,10 +203,14 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
mSpinnerPreference = screen.findPreference(SPINNER_PREFERENCE_KEY);
|
mSpinnerPreference = screen.findPreference(SPINNER_PREFERENCE_KEY);
|
||||||
mAppListPreferenceGroup = screen.findPreference(APP_LIST_PREFERENCE_KEY);
|
mAppListPreferenceGroup = screen.findPreference(APP_LIST_PREFERENCE_KEY);
|
||||||
mFooterPreference = screen.findPreference(FOOTER_PREFERENCE_KEY);
|
mFooterPreference = screen.findPreference(FOOTER_PREFERENCE_KEY);
|
||||||
|
final String formatPercentage =
|
||||||
|
Utils.formatPercentage(BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD, false);
|
||||||
mPercentLessThanThresholdText =
|
mPercentLessThanThresholdText =
|
||||||
|
mPrefContext.getString(R.string.battery_usage_less_than_percent, formatPercentage);
|
||||||
|
mPercentLessThanThresholdContentDescription =
|
||||||
mPrefContext.getString(
|
mPrefContext.getString(
|
||||||
R.string.battery_usage_less_than_percent,
|
R.string.battery_usage_less_than_percent_content_description,
|
||||||
Utils.formatPercentage(BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD, false));
|
formatPercentage);
|
||||||
|
|
||||||
mAppListPreferenceGroup.setOrderingAsAdded(false);
|
mAppListPreferenceGroup.setOrderingAsAdded(false);
|
||||||
mSpinnerPreference.initializeSpinner(
|
mSpinnerPreference.initializeSpinner(
|
||||||
@@ -394,12 +399,15 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setPreferencePercentage(PowerGaugePreference preference, BatteryDiffEntry entry) {
|
void setPreferencePercentage(PowerGaugePreference preference, BatteryDiffEntry entry) {
|
||||||
preference.setPercentage(
|
if (entry.getPercentage() < BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD) {
|
||||||
entry.getPercentage() < BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD
|
preference.setPercentage(mPercentLessThanThresholdText);
|
||||||
? mPercentLessThanThresholdText
|
preference.setPercentageContentDescription(mPercentLessThanThresholdContentDescription);
|
||||||
: Utils.formatPercentage(
|
} else {
|
||||||
entry.getPercentage() + entry.getAdjustPercentageOffset(),
|
preference.setPercentage(
|
||||||
/* round= */ true));
|
Utils.formatPercentage(
|
||||||
|
entry.getPercentage() + entry.getAdjustPercentageOffset(),
|
||||||
|
/* round= */ true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge.batteryusage;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -47,6 +48,7 @@ public class PowerGaugePreference extends AppPreference {
|
|||||||
private BatteryDiffEntry mBatteryDiffEntry;
|
private BatteryDiffEntry mBatteryDiffEntry;
|
||||||
private CharSequence mContentDescription;
|
private CharSequence mContentDescription;
|
||||||
private CharSequence mProgress;
|
private CharSequence mProgress;
|
||||||
|
private CharSequence mProgressContentDescription;
|
||||||
private boolean mShowAnomalyIcon;
|
private boolean mShowAnomalyIcon;
|
||||||
|
|
||||||
public PowerGaugePreference(
|
public PowerGaugePreference(
|
||||||
@@ -87,6 +89,13 @@ public class PowerGaugePreference extends AppPreference {
|
|||||||
/** Sets the percentage to show. */
|
/** Sets the percentage to show. */
|
||||||
public void setPercentage(CharSequence percentage) {
|
public void setPercentage(CharSequence percentage) {
|
||||||
mProgress = percentage;
|
mProgress = percentage;
|
||||||
|
mProgressContentDescription = percentage;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the content description of the percentage. */
|
||||||
|
public void setPercentageContentDescription(CharSequence contentDescription) {
|
||||||
|
mProgressContentDescription = contentDescription;
|
||||||
notifyChanged();
|
notifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +142,9 @@ public class PowerGaugePreference extends AppPreference {
|
|||||||
|
|
||||||
final TextView subtitle = (TextView) view.findViewById(R.id.widget_summary);
|
final TextView subtitle = (TextView) view.findViewById(R.id.widget_summary);
|
||||||
subtitle.setText(mProgress);
|
subtitle.setText(mProgress);
|
||||||
|
if (!TextUtils.isEmpty(mProgressContentDescription)) {
|
||||||
|
subtitle.setContentDescription(mProgressContentDescription);
|
||||||
|
}
|
||||||
if (mShowAnomalyIcon) {
|
if (mShowAnomalyIcon) {
|
||||||
subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
||||||
R.drawable.ic_warning_24dp, 0, 0, 0);
|
R.drawable.ic_warning_24dp, 0, 0, 0);
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public final class BatteryUsageBreakdownControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setPreferencePercent_lessThanThreshold_expectedFormat() {
|
public void setPreferencePercent_lessThanThreshold_expectedFormat() {
|
||||||
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
|
final PowerGaugePreference pref = spy(new PowerGaugePreference(mContext));
|
||||||
final BatteryDiffEntry batteryDiffEntry =
|
final BatteryDiffEntry batteryDiffEntry =
|
||||||
createBatteryDiffEntry(
|
createBatteryDiffEntry(
|
||||||
/* isSystem= */ true,
|
/* isSystem= */ true,
|
||||||
@@ -282,15 +282,18 @@ public final class BatteryUsageBreakdownControllerTest {
|
|||||||
batteryDiffEntry.mConsumePower = 0.8;
|
batteryDiffEntry.mConsumePower = 0.8;
|
||||||
batteryDiffEntry.setTotalConsumePower(100);
|
batteryDiffEntry.setTotalConsumePower(100);
|
||||||
mBatteryUsageBreakdownController.mPercentLessThanThresholdText = "< 1%";
|
mBatteryUsageBreakdownController.mPercentLessThanThresholdText = "< 1%";
|
||||||
|
mBatteryUsageBreakdownController.mPercentLessThanThresholdContentDescription =
|
||||||
|
"test content description";
|
||||||
|
|
||||||
mBatteryUsageBreakdownController.setPreferencePercentage(pref, batteryDiffEntry);
|
mBatteryUsageBreakdownController.setPreferencePercentage(pref, batteryDiffEntry);
|
||||||
|
|
||||||
assertThat(pref.getPercentage()).isEqualTo("< 1%");
|
assertThat(pref.getPercentage()).isEqualTo("< 1%");
|
||||||
|
verify(pref).setPercentageContentDescription("test content description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setPreferencePercent_greaterThanThreshold_expectedFormat() {
|
public void setPreferencePercent_greaterThanThreshold_expectedFormat() {
|
||||||
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
|
final PowerGaugePreference pref = spy(new PowerGaugePreference(mContext));
|
||||||
final BatteryDiffEntry batteryDiffEntry =
|
final BatteryDiffEntry batteryDiffEntry =
|
||||||
createBatteryDiffEntry(
|
createBatteryDiffEntry(
|
||||||
/* isSystem= */ true,
|
/* isSystem= */ true,
|
||||||
@@ -301,10 +304,13 @@ public final class BatteryUsageBreakdownControllerTest {
|
|||||||
batteryDiffEntry.mConsumePower = 16;
|
batteryDiffEntry.mConsumePower = 16;
|
||||||
batteryDiffEntry.setTotalConsumePower(100);
|
batteryDiffEntry.setTotalConsumePower(100);
|
||||||
mBatteryUsageBreakdownController.mPercentLessThanThresholdText = "< 1%";
|
mBatteryUsageBreakdownController.mPercentLessThanThresholdText = "< 1%";
|
||||||
|
mBatteryUsageBreakdownController.mPercentLessThanThresholdContentDescription =
|
||||||
|
"test content description";
|
||||||
|
|
||||||
mBatteryUsageBreakdownController.setPreferencePercentage(pref, batteryDiffEntry);
|
mBatteryUsageBreakdownController.setPreferencePercentage(pref, batteryDiffEntry);
|
||||||
|
|
||||||
assertThat(pref.getPercentage()).isEqualTo("16%");
|
assertThat(pref.getPercentage()).isEqualTo("16%");
|
||||||
|
verify(pref, never()).setPercentageContentDescription(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -101,4 +101,13 @@ public class PowerGaugePreferenceTest {
|
|||||||
assertThat(mPreferenceViewHolder.findViewById(android.R.id.title).getContentDescription())
|
assertThat(mPreferenceViewHolder.findViewById(android.R.id.title).getContentDescription())
|
||||||
.isEqualTo(CONTENT_DESCRIPTION);
|
.isEqualTo(CONTENT_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnBindViewHolder_bindPercentageContentDescription() {
|
||||||
|
mPowerGaugePreference.setPercentageContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
mPowerGaugePreference.onBindViewHolder(mPreferenceViewHolder);
|
||||||
|
|
||||||
|
assertThat(mPreferenceViewHolder.findViewById(R.id.widget_summary).getContentDescription())
|
||||||
|
.isEqualTo(CONTENT_DESCRIPTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user