Merge "Help talkback to read the hyphen of time frame '{day}{time}-{time}' in PreferenceCategory Title." into main
This commit is contained in:
@@ -87,6 +87,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
@VisibleForTesting PreferenceGroup mAppListPreferenceGroup;
|
||||
@VisibleForTesting FooterPreference mFooterPreference;
|
||||
@VisibleForTesting BatteryDiffData mBatteryDiffData;
|
||||
@VisibleForTesting String mBatteryUsageBreakdownTitleLastFullChargeText;
|
||||
@VisibleForTesting String mPercentLessThanThresholdText;
|
||||
@VisibleForTesting String mPercentLessThanThresholdContentDescription;
|
||||
@VisibleForTesting boolean mIsHighlightSlot;
|
||||
@@ -147,9 +148,10 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
|
||||
private void logPreferenceClickedMetrics(BatteryDiffEntry entry) {
|
||||
final int attribution = SettingsEnums.OPEN_BATTERY_USAGE;
|
||||
final int action = entry.isSystemEntry()
|
||||
? SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM
|
||||
: SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM;
|
||||
final int action =
|
||||
entry.isSystemEntry()
|
||||
? SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM
|
||||
: SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM;
|
||||
final int pageId = SettingsEnums.OPEN_BATTERY_USAGE;
|
||||
final String packageName =
|
||||
TextUtils.isEmpty(entry.getPackageName())
|
||||
@@ -203,6 +205,9 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
mSpinnerPreference = screen.findPreference(SPINNER_PREFERENCE_KEY);
|
||||
mAppListPreferenceGroup = screen.findPreference(APP_LIST_PREFERENCE_KEY);
|
||||
mFooterPreference = screen.findPreference(FOOTER_PREFERENCE_KEY);
|
||||
mBatteryUsageBreakdownTitleLastFullChargeText =
|
||||
mPrefContext.getString(
|
||||
R.string.battery_usage_breakdown_title_since_last_full_charge);
|
||||
final String formatPercentage =
|
||||
Utils.formatPercentage(BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD, false);
|
||||
mPercentLessThanThresholdText =
|
||||
@@ -254,6 +259,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
void handleBatteryUsageUpdated(
|
||||
BatteryDiffData slotUsageData,
|
||||
String slotTimestamp,
|
||||
String accessibilitySlotTimestamp,
|
||||
boolean isAllUsageDataEmpty,
|
||||
boolean isHighlightSlot,
|
||||
Optional<AnomalyEventWrapper> optionalAnomalyEventWrapper) {
|
||||
@@ -276,18 +282,24 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
: null;
|
||||
}
|
||||
|
||||
showCategoryTitle(slotTimestamp);
|
||||
showCategoryTitle(slotTimestamp, accessibilitySlotTimestamp);
|
||||
showSpinnerAndAppList();
|
||||
showFooterPreference(isAllUsageDataEmpty);
|
||||
}
|
||||
|
||||
private void showCategoryTitle(String slotTimestamp) {
|
||||
mRootPreference.setTitle(
|
||||
private void showCategoryTitle(String slotTimestamp, String accessibilitySlotTimestamp) {
|
||||
final String displayTitle =
|
||||
slotTimestamp == null
|
||||
? mPrefContext.getString(
|
||||
R.string.battery_usage_breakdown_title_since_last_full_charge)
|
||||
? mBatteryUsageBreakdownTitleLastFullChargeText
|
||||
: mPrefContext.getString(
|
||||
R.string.battery_usage_breakdown_title_for_slot, slotTimestamp));
|
||||
R.string.battery_usage_breakdown_title_for_slot, slotTimestamp);
|
||||
final String accessibilityTitle =
|
||||
accessibilitySlotTimestamp == null
|
||||
? mBatteryUsageBreakdownTitleLastFullChargeText
|
||||
: mPrefContext.getString(
|
||||
R.string.battery_usage_breakdown_title_for_slot,
|
||||
accessibilitySlotTimestamp);
|
||||
mRootPreference.setTitle(Utils.createAccessibleSequence(displayTitle, accessibilityTitle));
|
||||
mRootPreference.setVisible(true);
|
||||
}
|
||||
|
||||
|
@@ -242,9 +242,14 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
||||
final String slotInformation =
|
||||
mBatteryChartPreferenceController.getSlotInformation(
|
||||
/* isAccessibilityText= */ false);
|
||||
final String accessibilitySlotInformation =
|
||||
mBatteryChartPreferenceController.getSlotInformation(
|
||||
/* isAccessibilityText= */ true);
|
||||
final BatteryDiffData slotUsageData = mBatteryUsageMap.get(dailyIndex).get(hourlyIndex);
|
||||
mScreenOnTimeController.handleSceenOnTimeUpdated(
|
||||
slotUsageData != null ? slotUsageData.getScreenOnTime() : 0L, slotInformation);
|
||||
mScreenOnTimeController.handleScreenOnTimeUpdated(
|
||||
slotUsageData != null ? slotUsageData.getScreenOnTime() : 0L,
|
||||
slotInformation,
|
||||
accessibilitySlotInformation);
|
||||
// Hide card tips if the related highlight slot was clicked.
|
||||
if (isAppsAnomalyEventFocused()) {
|
||||
mBatteryTipsController.acceptTipsCard();
|
||||
@@ -252,6 +257,7 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
||||
mBatteryUsageBreakdownController.handleBatteryUsageUpdated(
|
||||
slotUsageData,
|
||||
slotInformation,
|
||||
accessibilitySlotInformation,
|
||||
isBatteryUsageMapNullOrEmpty(),
|
||||
isAppsAnomalyEventFocused(),
|
||||
mHighlightEventWrapper);
|
||||
|
@@ -27,6 +27,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
|
||||
@@ -45,6 +46,7 @@ public class ScreenOnTimeController extends BasePreferenceController {
|
||||
@VisibleForTesting Context mPrefContext;
|
||||
@VisibleForTesting PreferenceCategory mRootPreference;
|
||||
@VisibleForTesting TextViewPreference mScreenOnTimeTextPreference;
|
||||
@VisibleForTesting String mScreenTimeCategoryLastFullChargeText;
|
||||
|
||||
public ScreenOnTimeController(Context context) {
|
||||
super(context, ROOT_PREFERENCE_KEY);
|
||||
@@ -61,25 +63,34 @@ public class ScreenOnTimeController extends BasePreferenceController {
|
||||
mPrefContext = screen.getContext();
|
||||
mRootPreference = screen.findPreference(ROOT_PREFERENCE_KEY);
|
||||
mScreenOnTimeTextPreference = screen.findPreference(SCREEN_ON_TIME_TEXT_PREFERENCE_KEY);
|
||||
mScreenTimeCategoryLastFullChargeText =
|
||||
mPrefContext.getString(R.string.screen_time_category_last_full_charge);
|
||||
}
|
||||
|
||||
void handleSceenOnTimeUpdated(Long screenOnTime, String slotTimestamp) {
|
||||
void handleScreenOnTimeUpdated(
|
||||
Long screenOnTime, String slotTimestamp, String accessibilitySlotTimestamp) {
|
||||
if (screenOnTime == null) {
|
||||
mRootPreference.setVisible(false);
|
||||
mScreenOnTimeTextPreference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
showCategoryTitle(slotTimestamp);
|
||||
showCategoryTitle(slotTimestamp, accessibilitySlotTimestamp);
|
||||
showScreenOnTimeText(screenOnTime);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void showCategoryTitle(String slotTimestamp) {
|
||||
mRootPreference.setTitle(
|
||||
void showCategoryTitle(String slotTimestamp, String accessibilitySlotTimestamp) {
|
||||
final String displayTitle =
|
||||
slotTimestamp == null
|
||||
? mPrefContext.getString(R.string.screen_time_category_last_full_charge)
|
||||
? mScreenTimeCategoryLastFullChargeText
|
||||
: mPrefContext.getString(
|
||||
R.string.screen_time_category_for_slot, slotTimestamp));
|
||||
R.string.screen_time_category_for_slot, slotTimestamp);
|
||||
final String accessibilityTitle =
|
||||
accessibilitySlotTimestamp == null
|
||||
? mScreenTimeCategoryLastFullChargeText
|
||||
: mPrefContext.getString(
|
||||
R.string.screen_time_category_for_slot, accessibilitySlotTimestamp);
|
||||
mRootPreference.setTitle(Utils.createAccessibleSequence(displayTitle, accessibilityTitle));
|
||||
mRootPreference.setVisible(true);
|
||||
}
|
||||
|
||||
|
@@ -25,9 +25,13 @@ import static org.mockito.Mockito.verify;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.LocaleList;
|
||||
import android.text.SpannableString;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -45,6 +49,7 @@ public final class ScreenOnTimeControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private ScreenOnTimeController mScreenOnTimeController;
|
||||
private ArgumentCaptor<SpannableString> mStringCaptor;
|
||||
|
||||
@Mock private PreferenceCategory mRootPreference;
|
||||
@Mock private TextViewPreference mScreenOnTimeTextPreference;
|
||||
@@ -56,6 +61,7 @@ public final class ScreenOnTimeControllerTest {
|
||||
org.robolectric.shadows.ShadowSettings.set24HourTimeFormat(false);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mStringCaptor = ArgumentCaptor.forClass(SpannableString.class);
|
||||
final Resources resources = spy(mContext.getResources());
|
||||
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
|
||||
doReturn(resources).when(mContext).getResources();
|
||||
@@ -63,12 +69,14 @@ public final class ScreenOnTimeControllerTest {
|
||||
mScreenOnTimeController.mPrefContext = mContext;
|
||||
mScreenOnTimeController.mRootPreference = mRootPreference;
|
||||
mScreenOnTimeController.mScreenOnTimeTextPreference = mScreenOnTimeTextPreference;
|
||||
mScreenOnTimeController.mScreenTimeCategoryLastFullChargeText =
|
||||
resources.getString(R.string.screen_time_category_last_full_charge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleSceenOnTimeUpdated_nullScreenOnTime_hideAllPreference() {
|
||||
mScreenOnTimeController.handleSceenOnTimeUpdated(
|
||||
/* screenOnTime= */ null, "Friday 12:00 to now");
|
||||
public void handleScreenOnTimeUpdated_nullScreenOnTime_hideAllPreference() {
|
||||
mScreenOnTimeController.handleScreenOnTimeUpdated(
|
||||
/* screenOnTime= */ null, "Friday 12:00 - now", "Friday 12:00 to now");
|
||||
|
||||
verify(mRootPreference).setVisible(false);
|
||||
verify(mScreenOnTimeTextPreference).setVisible(false);
|
||||
@@ -76,18 +84,32 @@ public final class ScreenOnTimeControllerTest {
|
||||
|
||||
@Test
|
||||
public void showCategoryTitle_null_sinceLastFullCharge() {
|
||||
mScreenOnTimeController.showCategoryTitle(null);
|
||||
mScreenOnTimeController.showCategoryTitle(null, null);
|
||||
|
||||
verify(mRootPreference).setTitle("Screen time since last full charge");
|
||||
verify(mRootPreference).setTitle(mStringCaptor.capture());
|
||||
verify(mRootPreference).setVisible(true);
|
||||
assertThat(mStringCaptor.getValue().toString())
|
||||
.isEqualTo(
|
||||
Utils.createAccessibleSequence(
|
||||
mScreenOnTimeController
|
||||
.mScreenTimeCategoryLastFullChargeText,
|
||||
mScreenOnTimeController
|
||||
.mScreenTimeCategoryLastFullChargeText)
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showCategoryTitle_notNull_slotTimestamp() {
|
||||
mScreenOnTimeController.showCategoryTitle("Friday 12:00 to now");
|
||||
mScreenOnTimeController.showCategoryTitle("Friday 12:00 - now", "Friday 12:00 to now");
|
||||
|
||||
verify(mRootPreference).setTitle("Screen time for Friday 12:00 to now");
|
||||
verify(mRootPreference).setTitle(mStringCaptor.capture());
|
||||
verify(mRootPreference).setVisible(true);
|
||||
assertThat(mStringCaptor.getValue().toString())
|
||||
.isEqualTo(
|
||||
Utils.createAccessibleSequence(
|
||||
"Screen time for Friday 12:00 - now",
|
||||
"Screen time for Friday 12:00 to now")
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user