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