Split the string resource id for non-generic accessibility preference.

- Keep the accessibility settings strings the same as in U.

Bug: 289425138
Test: manual
Test: atest
Change-Id: Iddbbfe627c93529d2421e153094a30628229c4bc
This commit is contained in:
Chun-Ku Lin
2023-08-01 23:54:08 +00:00
parent 524643a6c8
commit b65108ba1b
17 changed files with 81 additions and 452 deletions

View File

@@ -4816,7 +4816,7 @@
<!-- List of synonyms used in the settings search bar to find the "Audio Description. [CHAR LIMIT=NONE] --> <!-- List of synonyms used in the settings search bar to find the "Audio Description. [CHAR LIMIT=NONE] -->
<string name="keywords_audio_description">audio description, audio, description, low vision,</string> <string name="keywords_audio_description">audio description, audio, description, low vision,</string>
<!-- Preference's shortcut when enabled. [CHAR LIMIT=NONE] --> <!-- Shows when the shortcut of an accessibility feature is turned on. The accessibility feature could refer to any accessibility feature installed on the device. [CHAR LIMIT=NONE] -->
<string name="accessibility_summary_shortcut_enabled">Shortcut on</string> <string name="accessibility_summary_shortcut_enabled">Shortcut on</string>
<!-- Preference's shortcut when disabled. [CHAR LIMIT=NONE] --> <!-- Preference's shortcut when disabled. [CHAR LIMIT=NONE] -->
<string name="accessibility_summary_shortcut_disabled">Off</string> <string name="accessibility_summary_shortcut_disabled">Off</string>
@@ -12246,15 +12246,18 @@
<!-- Warning message when we try to dock an app not supporting multiple instances split into multiple sides [CHAR LIMIT=NONE] --> <!-- Warning message when we try to dock an app not supporting multiple instances split into multiple sides [CHAR LIMIT=NONE] -->
<string name="dock_multi_instances_not_supported_text">"This app can only be opened in 1 window"</string> <string name="dock_multi_instances_not_supported_text">"This app can only be opened in 1 window"</string>
<!-- The accessibility features state summary, indicating whether the service is turned on, whether the shortcut is turned on. The last part of the summary is the short summary of the feature. --> <!-- Shown when an accessibility feature is turned on. Note: for gendered languages, suggest to translate as "Feature on" because the accessibility feature it refers to can be in any gender. [CHAR LIMIT=NONE] -->
<string name="accessibility_feature_full_state_summary"><xliff:g example="Service on" id="state">%1$s</xliff:g> / <xliff:g example="Shortcut on" id="shortcut_state">%2$s</xliff:g> / <xliff:g example="Speak items on screen" id="service_summary">%3$s</xliff:g></string> <string name="generic_accessibility_service_on">On</string>
<!-- Label representing that a generic Accessibility Service is turned on. --> <!-- Shown when an accessibility feature is turned off. Note: for gendered languages, suggest to translate as "Feature off" because the accessibility feature it refers to can be in any gender. [CHAR LIMIT=NONE] -->
<string name="generic_accessibility_service_on">Service on</string> <string name="generic_accessibility_service_off">Off</string>
<!-- Label representing that a generic Accessibility Service is turned off. --> <!-- Shows when the shortcut of an accessibility feature is turned off. The "off" refers to the state of "shortcut". Note: for gendered languages, suggest to translate as "Shortcut off". [CHAR LIMIT=NONE] -->
<string name="generic_accessibility_service_off">Service off</string> <string name="generic_accessibility_feature_shortcut_off">Off</string>
<!-- Label representing that an accessibility feature's shortcut is turned off --> <!--
<string name="generic_accessibility_feature_shortcut_off">Shortcut off</string> Summary for the disabled state of the accessibility shortcut.
<!-- Summary for the disabled state of the accessibility shortcut. This is shown as a summary for "[Service] shortcut", where "off" refers to the state of "shortcut". --> This is shown as a summary for "[Service] shortcut" from the string resource accessibility_shortcut_title,
where "off" refers to the state of "shortcut" and
should match the same gender as the noun used in the string accessibility_shortcut_title.
-->
<string name="accessibility_shortcut_state_off">Off</string> <string name="accessibility_shortcut_state_off">Off</string>
<!-- Representing daltonizer (color filter) feature is turned on --> <!-- Representing daltonizer (color filter) feature is turned on -->

View File

@@ -34,7 +34,7 @@
android:persistent="false" android:persistent="false"
android:title="@string/one_handed_title" android:title="@string/one_handed_title"
settings:searchable="false" settings:searchable="false"
settings:controller="com.android.settings.accessibility.OneHandedPreferenceController"/> settings:controller="com.android.settings.gestures.OneHandedEnablePreferenceController"/>
<SwitchPreference <SwitchPreference
android:key="toggle_power_button_ends_call_preference" android:key="toggle_power_button_ends_call_preference"

View File

@@ -251,69 +251,29 @@ public class AccessibilitySettings extends DashboardFragment {
return context.getText(R.string.accessibility_summary_state_stopped); return context.getText(R.string.accessibility_summary_state_stopped);
} }
final CharSequence serviceState;
final int fragmentType = AccessibilityUtil.getAccessibilityServiceFragmentType(info); final int fragmentType = AccessibilityUtil.getAccessibilityServiceFragmentType(info);
final ComponentName componentName = new ComponentName(
info.getResolveInfo().serviceInfo.packageName,
info.getResolveInfo().serviceInfo.name);
final boolean shortcutEnabled = AccessibilityUtil.getUserShortcutTypesFromSettings(
context, componentName) != AccessibilityUtil.UserShortcutType.EMPTY;
// Example shortcutState: "Shortcut on"
CharSequence shortcutState = shortcutEnabled
? context.getText(R.string.accessibility_summary_shortcut_enabled)
: context.getText(R.string.generic_accessibility_feature_shortcut_off);
// Example serviceSummary: "Control device via large menu"
final CharSequence serviceSummary = info.loadSummary(context.getPackageManager());
if (fragmentType == AccessibilityServiceFragmentType.INVISIBLE_TOGGLE) { if (fragmentType == AccessibilityServiceFragmentType.INVISIBLE_TOGGLE) {
// Example result: "Shortcut on / Control device via large menu" final ComponentName componentName = new ComponentName(
return TextUtils.isEmpty(serviceSummary) info.getResolveInfo().serviceInfo.packageName,
? shortcutState info.getResolveInfo().serviceInfo.name);
: context.getString( final boolean shortcutEnabled = AccessibilityUtil.getUserShortcutTypesFromSettings(
R.string.preference_summary_default_combination, shortcutState, context, componentName) != AccessibilityUtil.UserShortcutType.EMPTY;
serviceSummary); serviceState = shortcutEnabled
? context.getText(R.string.accessibility_summary_shortcut_enabled)
: context.getText(R.string.generic_accessibility_feature_shortcut_off);
} else { } else {
// Example serviceState: "Service on" serviceState = serviceEnabled
CharSequence serviceState = serviceEnabled
? context.getText(R.string.generic_accessibility_service_on) ? context.getText(R.string.generic_accessibility_service_on)
: context.getText(R.string.generic_accessibility_service_off); : context.getText(R.string.generic_accessibility_service_off);
// Example result: "Service on / Shortcut on / Speak items on screen"
return TextUtils.isEmpty(serviceSummary)
? context.getString(
R.string.preference_summary_default_combination,
serviceState, shortcutState)
: context.getString(
R.string.accessibility_feature_full_state_summary, serviceState,
shortcutState, serviceSummary);
} }
}
/** final CharSequence serviceSummary = info.loadSummary(context.getPackageManager());
* Returns the summary for the current shortcut state of the accessibility app final String stateSummaryCombo = context.getString(
* captured in the {@link AccessibilityShortcutInfo}
*/
public static CharSequence getA11yShortcutInfoPreferenceSummary(
Context context, AccessibilityShortcutInfo info) {
boolean shortcutEnabled = AccessibilityUtil.getUserShortcutTypesFromSettings(
context, info.getComponentName()) != AccessibilityUtil.UserShortcutType.EMPTY;
// Example shortcutState: "Shortcut on"
CharSequence shortcutState = shortcutEnabled
? context.getText(R.string.accessibility_summary_shortcut_enabled)
: context.getText(R.string.generic_accessibility_feature_shortcut_off);
// Example serviceSummary: "Convert speech to text"
CharSequence serviceSummary = info.loadSummary(context.getPackageManager());
// Example result: "Shortcut on / Convert speech to text"
return TextUtils.isEmpty(serviceSummary)
? shortcutState
: context.getString(
R.string.preference_summary_default_combination, R.string.preference_summary_default_combination,
shortcutState, serviceSummary); serviceState, serviceSummary);
return TextUtils.isEmpty(serviceSummary) ? serviceState : stateSummaryCombo;
} }
/** /**

View File

@@ -40,8 +40,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.StringJoiner; import java.util.StringJoiner;
@@ -290,41 +288,6 @@ public final class AccessibilityUtil {
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString()); Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
} }
/**
* Returns the full status with a feature summary.
* For example, "$(feature on) / Shortcut on / Speak items on screen".
*
* @param context The current context.
* @param componentName The component name in Settings to query
* if the shortcut turned on.
* @param settingsSecureKey One of the key defined in
* {@link Settings.Secure}.
* @param featureOnTextId The string resource id representing the feature is turned on.
* @param featureOffTextId The string resource id representing the feature is turned off.
* @param featureSummaryId The string resource id of the feature summary.
*/
static CharSequence getFeatureFullStateSummary(
Context context, @NonNull ComponentName componentName,
String settingsSecureKey,
@StringRes int featureOnTextId, @StringRes int featureOffTextId,
@StringRes int featureSummaryId) {
boolean shortcutEnabled = getUserShortcutTypesFromSettings(context, componentName)
!= AccessibilityUtil.UserShortcutType.EMPTY;
boolean featureEnabled = Settings.Secure.getInt(context.getContentResolver(),
settingsSecureKey, AccessibilityUtil.State.OFF) == AccessibilityUtil.State.ON;
return context.getString(
R.string.accessibility_feature_full_state_summary,
featureEnabled
? context.getString(featureOnTextId)
: context.getString(featureOffTextId),
shortcutEnabled
? context.getString(R.string.accessibility_summary_shortcut_enabled)
: context.getString(R.string.generic_accessibility_feature_shortcut_off),
context.getString(featureSummaryId)
);
}
/** /**
* Returns if component name existed in one of {@code shortcutTypes} string in Settings. * Returns if component name existed in one of {@code shortcutTypes} string in Settings.
* *

View File

@@ -16,8 +16,6 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME;
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
@@ -36,11 +34,10 @@ public class ColorInversionPreferenceController extends BasePreferenceController
@Override @Override
public CharSequence getSummary() { public CharSequence getSummary() {
return AccessibilityUtil.getFeatureFullStateSummary( return AccessibilityUtil.getSummary(
mContext, COLOR_INVERSION_COMPONENT_NAME, mContext,
DISPLAY_INVERSION_ENABLED, DISPLAY_INVERSION_ENABLED,
R.string.color_inversion_state_on, R.string.color_inversion_state_off, R.string.color_inversion_state_on, R.string.color_inversion_state_off);
R.string.color_inversion_feature_summary);
} }
@Override @Override

View File

@@ -16,8 +16,6 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
@@ -40,10 +38,9 @@ public class DaltonizerPreferenceController extends BasePreferenceController {
@Override @Override
public CharSequence getSummary() { public CharSequence getSummary() {
return AccessibilityUtil.getFeatureFullStateSummary( return AccessibilityUtil.getSummary(
mContext, DALTONIZER_COMPONENT_NAME, mContext,
DALTONIZER_ENABLED, DALTONIZER_ENABLED,
R.string.daltonizer_state_on, R.string.daltonizer_state_off, R.string.daltonizer_state_on, R.string.daltonizer_state_off);
R.string.daltonizer_feature_summary);
} }
} }

View File

@@ -20,12 +20,10 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import java.util.List; import java.util.List;
@@ -56,16 +54,5 @@ public class LiveCaptionPreferenceController extends BasePreferenceController {
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
preference.setIntent(LIVE_CAPTION_INTENT); preference.setIntent(LIVE_CAPTION_INTENT);
boolean enabled = Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ODI_CAPTIONS_ENABLED, AccessibilityUtil.State.OFF)
== AccessibilityUtil.State.ON;
CharSequence serviceState = mContext.getText(enabled
? R.string.live_caption_enabled : R.string.live_caption_disabled);
preference.setSummary(
mContext.getString(
R.string.preference_summary_default_combination,
serviceState, mContext.getText(R.string.live_caption_summary)));
} }
} }

View File

@@ -1,44 +0,0 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.accessibility;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.gestures.OneHandedEnablePreferenceController;
import com.android.settings.gestures.OneHandedSettingsUtils;
/**
* OneHandedPreferenceController is the same as {@link OneHandedEnablePreferenceController} excepts
* that the summary shown on the preference item would include the short description of One-handed
* mode, so that the UI representation is consistent with other items on Accessibility Settings
*/
public final class OneHandedPreferenceController extends OneHandedEnablePreferenceController {
public OneHandedPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public CharSequence getSummary() {
return mContext.getString(
R.string.preference_summary_default_combination,
mContext.getText(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)
? R.string.gesture_setting_on : R.string.gesture_setting_off),
mContext.getText(R.string.one_handed_mode_intro_text));
}
}

View File

@@ -159,8 +159,7 @@ public class RestrictedPreferenceHelper {
final String key = componentName.flattenToString(); final String key = componentName.flattenToString();
final CharSequence title = activityInfo.loadLabel(mPm); final CharSequence title = activityInfo.loadLabel(mPm);
final CharSequence summary = final String summary = info.loadSummary(mPm);
AccessibilitySettings.getA11yShortcutInfoPreferenceSummary(mContext, info);
final String fragment = final String fragment =
LaunchAccessibilityActivityPreferenceFragment.class.getName(); LaunchAccessibilityActivityPreferenceFragment.class.getName();

View File

@@ -762,12 +762,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
*/ */
public static CharSequence getServiceSummary(Context context) { public static CharSequence getServiceSummary(Context context) {
// Get the user shortcut type from settings provider. // Get the user shortcut type from settings provider.
int shortcutType = getUserShortcutTypeFromSettings(context); final int uerShortcutType = getUserShortcutTypeFromSettings(context);
return context.getString( return (uerShortcutType != AccessibilityUtil.UserShortcutType.EMPTY)
R.string.preference_summary_default_combination, ? context.getText(R.string.accessibility_summary_shortcut_enabled)
shortcutType != AccessibilityUtil.UserShortcutType.EMPTY : context.getText(R.string.generic_accessibility_feature_shortcut_off);
? context.getString(R.string.accessibility_summary_shortcut_enabled)
: context.getString(R.string.generic_accessibility_feature_shortcut_off),
context.getText(R.string.magnification_feature_summary));
} }
} }

View File

@@ -200,7 +200,7 @@ public class AccessibilitySettingsTest {
} }
@Test @Test
public void getServiceSummary_enableServiceShortcutOn_showsServiceEnabledShortcutOn() { public void getServiceSummary_enableServiceShortcutOnWithEmptyDescription_showsServiceEnabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any()); doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true); setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -208,27 +208,23 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_ENABLED).toString(); mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.generic_accessibility_service_on));
mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled)));
} }
@Test @Test
public void getServiceSummary_enableServiceShortcutOff_showsServiceEnabledShortcutOff() { public void getServiceSummary_enableServiceShortcutOffWithEmptyDescription_showsServiceEnabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any()); doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), false); setShortcutEnabled(mServiceInfo.getComponentName(), false);
String summary = AccessibilitySettings.getServiceSummary(mContext, String summary = AccessibilitySettings.getServiceSummary(
mServiceInfo, SERVICE_ENABLED).toString(); mContext, mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.generic_accessibility_service_on));
mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off)));
} }
@Test @Test
public void getServiceSummary_disableServiceShortcutOff_showsDisabledShortcutOff() { public void getServiceSummary_disableServiceShortcutOffWithEmptyDescription_showsServiceDisabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any()); doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), false); setShortcutEnabled(mServiceInfo.getComponentName(), false);
@@ -236,13 +232,11 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString(); mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.generic_accessibility_service_off));
mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off)));
} }
@Test @Test
public void getServiceSummary_disableServiceShortcutOn_showsDisabledShortcutOn() { public void getServiceSummary_disableServiceShortcutOnWithEmptyDescription_showsServiceDisabled() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any()); doReturn(EMPTY_STRING).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true); setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -250,13 +244,11 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString(); mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.generic_accessibility_service_off));
mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled)));
} }
@Test @Test
public void getServiceSummary_enableServiceShortcutOffAndHasSummary_showsEnabledShortcutOffSummary() { public void getServiceSummary_enableServiceShortcutOffAndHasSummary_showsEnabledSummary() {
setShortcutEnabled(mServiceInfo.getComponentName(), false); setShortcutEnabled(mServiceInfo.getComponentName(), false);
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any()); doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
@@ -264,14 +256,13 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_ENABLED).toString(); mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_on), mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
DEFAULT_SUMMARY)); DEFAULT_SUMMARY));
} }
@Test @Test
public void getServiceSummary_enableServiceShortcutOnAndHasSummary_showsEnabledShortcutOnSummary() { public void getServiceSummary_enableServiceShortcutOnAndHasSummary_showsEnabledSummary() {
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any()); doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true); setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -279,14 +270,13 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_ENABLED).toString(); mServiceInfo, SERVICE_ENABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_on), mContext.getString(R.string.generic_accessibility_service_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
DEFAULT_SUMMARY)); DEFAULT_SUMMARY));
} }
@Test @Test
public void getServiceSummary_disableServiceShortcutOnAndHasSummary_showsDisabledShortcutOnSummary() { public void getServiceSummary_disableServiceShortcutOnAndHasSummary_showsDisabledSummary() {
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any()); doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
setShortcutEnabled(mServiceInfo.getComponentName(), true); setShortcutEnabled(mServiceInfo.getComponentName(), true);
@@ -294,14 +284,13 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString(); mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_off), mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
DEFAULT_SUMMARY)); DEFAULT_SUMMARY));
} }
@Test @Test
public void getServiceSummary_disableServiceShortcutOffAndHasSummary_showsDisabledShortcutOffSummary() { public void getServiceSummary_disableServiceShortcutOffAndHasSummary_showsDisabledSummary() {
setShortcutEnabled(mServiceInfo.getComponentName(), false); setShortcutEnabled(mServiceInfo.getComponentName(), false);
doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any()); doReturn(DEFAULT_SUMMARY).when(mServiceInfo).loadSummary(any());
@@ -309,9 +298,8 @@ public class AccessibilitySettingsTest {
mServiceInfo, SERVICE_DISABLED).toString(); mServiceInfo, SERVICE_DISABLED).toString();
assertThat(summary).isEqualTo( assertThat(summary).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_service_off), mContext.getString(R.string.generic_accessibility_service_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
DEFAULT_SUMMARY)); DEFAULT_SUMMARY));
} }
@@ -336,36 +324,6 @@ public class AccessibilitySettingsTest {
assertThat(description).isEqualTo(DEFAULT_DESCRIPTION); assertThat(description).isEqualTo(DEFAULT_DESCRIPTION);
} }
@Test
public void getA11yShortcutInfoPreferenceSummary_shortcutOn_showsShortcutOnSummary() {
doReturn(DEFAULT_SUMMARY).when(mShortcutInfo).loadSummary(any());
setShortcutEnabled(COMPONENT_NAME, true);
String summary = AccessibilitySettings.getA11yShortcutInfoPreferenceSummary(
mContext,
mShortcutInfo).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
DEFAULT_SUMMARY));
}
@Test
public void getA11yShortcutInfoPreferenceSummary_shortcutOff_showsShortcutOffSummary() {
doReturn(DEFAULT_SUMMARY).when(mShortcutInfo).loadSummary(any());
setShortcutEnabled(COMPONENT_NAME, false);
String summary = AccessibilitySettings.getA11yShortcutInfoPreferenceSummary(
mContext,
mShortcutInfo).toString();
assertThat(summary).isEqualTo(
mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
DEFAULT_SUMMARY));
}
@Test @Test
@Config(shadows = {ShadowFragment.class, ShadowUserManager.class}) @Config(shadows = {ShadowFragment.class, ShadowUserManager.class})
public void onCreate_haveRegisterToSpecificUrisAndActions() { public void onCreate_haveRegisterToSpecificUrisAndActions() {

View File

@@ -248,82 +248,6 @@ public final class AccessibilityUtilTest {
MOCK_COMPONENT_NAME.flattenToString()); MOCK_COMPONENT_NAME.flattenToString());
} }
@Test
public void getFeatureFullStateSummary_featureOffShortcutOff_showsOffShortcutOffAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, false);
clearShortcuts();
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
@Test
public void getFeatureFullStateSummary_featureOnShortcutOff_showsOnShortcutOffAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, true);
clearShortcuts();
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
@Test
public void getFeatureFullStateSummary_featureOffShortcutOn_showsOffShortcutOnAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, false);
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
@Test
public void getFeatureFullStateSummary_featureOnShortcutOn_showsOnShortcutOnAndSummary() {
setSettingsFeatureEnabled(PLACEHOLDER_SETTING_FEATURE, true);
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
String expectedText = mContext.getString(
R.string.accessibility_feature_full_state_summary,
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mContext.getString(R.string.color_inversion_feature_summary));
String observerText = AccessibilityUtil.getFeatureFullStateSummary(
mContext, MOCK_COMPONENT_NAME,
PLACEHOLDER_SETTING_FEATURE,
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
R.string.color_inversion_feature_summary).toString();
assertThat(observerText).isEqualTo(expectedText);
}
private AccessibilityServiceInfo getMockAccessibilityServiceInfo() { private AccessibilityServiceInfo getMockAccessibilityServiceInfo() {
final ApplicationInfo applicationInfo = new ApplicationInfo(); final ApplicationInfo applicationInfo = new ApplicationInfo();
final ServiceInfo serviceInfo = new ServiceInfo(); final ServiceInfo serviceInfo = new ServiceInfo();

View File

@@ -52,51 +52,39 @@ public class ColorInversionPreferenceControllerTest {
} }
@Test @Test
public void getSummary_enabledColorInversionShortcutOff_shouldReturnOnShortcutOffSummary() { public void getSummary_enabledColorInversionShortcutOff_shouldReturnOnSummary() {
setColorInversionEnabled(true); setColorInversionEnabled(true);
setColorInversionShortcutEnabled(false); setColorInversionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.color_inversion_state_on));
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mColorInversionSummary));
} }
@Test @Test
public void getSummary_enabledColorInversionShortcutOn_shouldReturnOnShortcutOnSummary() { public void getSummary_enabledColorInversionShortcutOn_shouldReturnOnSummary() {
setColorInversionEnabled(true); setColorInversionEnabled(true);
setColorInversionShortcutEnabled(true); setColorInversionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.color_inversion_state_on));
mContext.getString(R.string.color_inversion_state_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mColorInversionSummary));
} }
@Test @Test
public void getSummary_disabledColorInversionShortcutOff_shouldReturnOffShortcutOffSummary() { public void getSummary_disabledColorInversionShortcutOff_shouldReturnOffSummary() {
setColorInversionEnabled(false); setColorInversionEnabled(false);
setColorInversionShortcutEnabled(false); setColorInversionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.color_inversion_state_off));
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mColorInversionSummary));
} }
@Test @Test
public void getSummary_disabledColorInversionShortcutOn_shouldReturnOffShortcutOnSummary() { public void getSummary_disabledColorInversionShortcutOn_shouldReturnOffSummary() {
setColorInversionEnabled(false); setColorInversionEnabled(false);
setColorInversionShortcutEnabled(true); setColorInversionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.color_inversion_state_off));
mContext.getString(R.string.color_inversion_state_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mColorInversionSummary));
} }
private void setColorInversionShortcutEnabled(boolean enabled) { private void setColorInversionShortcutEnabled(boolean enabled) {

View File

@@ -50,51 +50,39 @@ public class DaltonizerPreferenceControllerTest {
} }
@Test @Test
public void getSummary_enabledColorCorrectionShortcutOff_shouldReturnOnShortcutOffSummary() { public void getSummary_enabledColorCorrectionShortcutOff_shouldReturnOnSummary() {
setColorCorrectionEnabled(true); setColorCorrectionEnabled(true);
setColorCorrectionShortcutEnabled(false); setColorCorrectionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.daltonizer_state_on));
mContext.getString(R.string.daltonizer_state_on),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mDaltonizerSummary));
} }
@Test @Test
public void getSummary_enabledColorCorrectionShortcutOn_shouldReturnOnShortcutOnSummary() { public void getSummary_enabledColorCorrectionShortcutOn_shouldReturnOnSummary() {
setColorCorrectionEnabled(true); setColorCorrectionEnabled(true);
setColorCorrectionShortcutEnabled(true); setColorCorrectionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.daltonizer_state_on));
mContext.getString(R.string.daltonizer_state_on),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mDaltonizerSummary));
} }
@Test @Test
public void getSummary_disabledColorCorrectionShortcutOff_shouldReturnOffShortcutOffSummary() { public void getSummary_disabledColorCorrectionShortcutOff_shouldReturnOffSummary() {
setColorCorrectionEnabled(false); setColorCorrectionEnabled(false);
setColorCorrectionShortcutEnabled(false); setColorCorrectionShortcutEnabled(false);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.daltonizer_state_off));
mContext.getString(R.string.daltonizer_state_off),
mContext.getString(R.string.generic_accessibility_feature_shortcut_off),
mDaltonizerSummary));
} }
@Test @Test
public void getSummary_disabledColorCorrectionShortcutOn_shouldReturnOffShortcutOnSummary() { public void getSummary_disabledColorCorrectionShortcutOn_shouldReturnOffSummary() {
setColorCorrectionEnabled(false); setColorCorrectionEnabled(false);
setColorCorrectionShortcutEnabled(true); setColorCorrectionShortcutEnabled(true);
assertThat(mController.getSummary().toString()).isEqualTo( assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.accessibility_feature_full_state_summary, mContext.getString(R.string.daltonizer_state_off));
mContext.getString(R.string.daltonizer_state_off),
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mDaltonizerSummary));
} }
private void setColorCorrectionEnabled(boolean enabled) { private void setColorCorrectionEnabled(boolean enabled) {

View File

@@ -51,6 +51,7 @@ public class LiveCaptionPreferenceControllerTest {
mContext = ApplicationProvider.getApplicationContext(); mContext = ApplicationProvider.getApplicationContext();
mController = new LiveCaptionPreferenceController(mContext, "test_key"); mController = new LiveCaptionPreferenceController(mContext, "test_key");
mLiveCaptionPreference = new Preference(mContext); mLiveCaptionPreference = new Preference(mContext);
mLiveCaptionPreference.setSummary(R.string.live_caption_summary);
} }
@Test @Test
@@ -78,10 +79,7 @@ public class LiveCaptionPreferenceControllerTest {
mController.updateState(mLiveCaptionPreference); mController.updateState(mLiveCaptionPreference);
assertThat(mLiveCaptionPreference.getSummary().toString()).isEqualTo( assertThat(mLiveCaptionPreference.getSummary().toString()).isEqualTo(
mContext.getString( mContext.getString(R.string.live_caption_summary)
R.string.preference_summary_default_combination,
mContext.getString(R.string.live_caption_enabled),
mContext.getText(R.string.live_caption_summary))
); );
} }
@@ -92,10 +90,7 @@ public class LiveCaptionPreferenceControllerTest {
mController.updateState(mLiveCaptionPreference); mController.updateState(mLiveCaptionPreference);
assertThat(mLiveCaptionPreference.getSummary()).isEqualTo( assertThat(mLiveCaptionPreference.getSummary()).isEqualTo(
mContext.getString( mContext.getString(R.string.live_caption_summary)
R.string.preference_summary_default_combination,
mContext.getString(R.string.live_caption_disabled),
mContext.getText(R.string.live_caption_summary))
); );
} }

View File

@@ -494,28 +494,23 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
} }
@Test @Test
public void getSummary_magnificationEnabled_returnShortcutOnWithSummary() { public void getSummary_magnificationEnabled_returnShortcutOn() {
setMagnificationTripleTapEnabled(true); setMagnificationTripleTapEnabled(true);
assertThat( assertThat(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString())
.isEqualTo( .isEqualTo(
mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.accessibility_summary_shortcut_enabled));
mContext.getString(R.string.accessibility_summary_shortcut_enabled),
mContext.getText(R.string.magnification_feature_summary)));
} }
@Test @Test
public void getSummary_magnificationDisabled_returnShortcutOffWithSummary() { public void getSummary_magnificationDisabled_returnShortcutOff() {
setMagnificationTripleTapEnabled(false); setMagnificationTripleTapEnabled(false);
assertThat( assertThat(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString())
.isEqualTo( .isEqualTo(
mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.generic_accessibility_feature_shortcut_off));
mContext.getString(
R.string.generic_accessibility_feature_shortcut_off),
mContext.getText(R.string.magnification_feature_summary)));
} }
private void putStringIntoSettings(String key, String componentName) { private void putStringIntoSettings(String key, String componentName) {

View File

@@ -1,78 +0,0 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.gestures.OneHandedSettingsUtils;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public final class OneHandedPreferenceControllerTest {
private Context mContext;
private OneHandedPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new OneHandedPreferenceController(mContext, "one_handed");
}
@Test
public void getSummary_oneHandedEnabled_showsOnWithSummary() {
OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true);
// R.string.gesture_setting_on
String gestureSettingOn = ResourcesUtils.getResourcesString(mContext, "gesture_setting_on");
// R.string.one_handed_mode_intro_text
String oneHandedModeIntroText = ResourcesUtils.getResourcesString(mContext,
"one_handed_mode_intro_text");
// expect: On / $(summary)
assertThat(mController.getSummary().toString()).isEqualTo(
// R.string.preference_summary_default_combination
ResourcesUtils.getResourcesString(mContext,
"preference_summary_default_combination", gestureSettingOn,
oneHandedModeIntroText));
}
@Test
public void getSummary_oneHandedDisabled_showsOffWithSummary() {
OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, false);
// R.string.gesture_setting_off
String gestureSettingOff = ResourcesUtils.getResourcesString(mContext,
"gesture_setting_off");
// R.string.one_handed_mode_intro_text
String oneHandedModeIntroText = ResourcesUtils.getResourcesString(mContext,
"one_handed_mode_intro_text");
// expect: Off / $(summary)
assertThat(mController.getSummary().toString()).isEqualTo(
// R.string.preference_summary_default_combination
ResourcesUtils.getResourcesString(mContext,
"preference_summary_default_combination", gestureSettingOff,
oneHandedModeIntroText));
}
}