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:
@@ -251,69 +251,29 @@ public class AccessibilitySettings extends DashboardFragment {
|
||||
return context.getText(R.string.accessibility_summary_state_stopped);
|
||||
}
|
||||
|
||||
final CharSequence serviceState;
|
||||
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) {
|
||||
// Example result: "Shortcut on / Control device via large menu"
|
||||
return TextUtils.isEmpty(serviceSummary)
|
||||
? shortcutState
|
||||
: context.getString(
|
||||
R.string.preference_summary_default_combination, shortcutState,
|
||||
serviceSummary);
|
||||
final ComponentName componentName = new ComponentName(
|
||||
info.getResolveInfo().serviceInfo.packageName,
|
||||
info.getResolveInfo().serviceInfo.name);
|
||||
final boolean shortcutEnabled = AccessibilityUtil.getUserShortcutTypesFromSettings(
|
||||
context, componentName) != AccessibilityUtil.UserShortcutType.EMPTY;
|
||||
serviceState = shortcutEnabled
|
||||
? context.getText(R.string.accessibility_summary_shortcut_enabled)
|
||||
: context.getText(R.string.generic_accessibility_feature_shortcut_off);
|
||||
} else {
|
||||
// Example serviceState: "Service on"
|
||||
CharSequence serviceState = serviceEnabled
|
||||
serviceState = serviceEnabled
|
||||
? context.getText(R.string.generic_accessibility_service_on)
|
||||
: 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary for the current shortcut state of the accessibility app
|
||||
* 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(
|
||||
final CharSequence serviceSummary = info.loadSummary(context.getPackageManager());
|
||||
final String stateSummaryCombo = context.getString(
|
||||
R.string.preference_summary_default_combination,
|
||||
shortcutState, serviceSummary);
|
||||
serviceState, serviceSummary);
|
||||
|
||||
return TextUtils.isEmpty(serviceSummary) ? serviceState : stateSummaryCombo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -40,8 +40,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.StringJoiner;
|
||||
@@ -290,41 +288,6 @@ public final class AccessibilityUtil {
|
||||
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.
|
||||
*
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -36,11 +34,10 @@ public class ColorInversionPreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return AccessibilityUtil.getFeatureFullStateSummary(
|
||||
mContext, COLOR_INVERSION_COMPONENT_NAME,
|
||||
return AccessibilityUtil.getSummary(
|
||||
mContext,
|
||||
DISPLAY_INVERSION_ENABLED,
|
||||
R.string.color_inversion_state_on, R.string.color_inversion_state_off,
|
||||
R.string.color_inversion_feature_summary);
|
||||
R.string.color_inversion_state_on, R.string.color_inversion_state_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -40,10 +38,9 @@ public class DaltonizerPreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return AccessibilityUtil.getFeatureFullStateSummary(
|
||||
mContext, DALTONIZER_COMPONENT_NAME,
|
||||
return AccessibilityUtil.getSummary(
|
||||
mContext,
|
||||
DALTONIZER_ENABLED,
|
||||
R.string.daltonizer_state_on, R.string.daltonizer_state_off,
|
||||
R.string.daltonizer_feature_summary);
|
||||
R.string.daltonizer_state_on, R.string.daltonizer_state_off);
|
||||
}
|
||||
}
|
||||
|
@@ -20,12 +20,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
@@ -56,16 +54,5 @@ public class LiveCaptionPreferenceController extends BasePreferenceController {
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
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)));
|
||||
}
|
||||
}
|
@@ -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));
|
||||
}
|
||||
}
|
@@ -159,8 +159,7 @@ public class RestrictedPreferenceHelper {
|
||||
|
||||
final String key = componentName.flattenToString();
|
||||
final CharSequence title = activityInfo.loadLabel(mPm);
|
||||
final CharSequence summary =
|
||||
AccessibilitySettings.getA11yShortcutInfoPreferenceSummary(mContext, info);
|
||||
final String summary = info.loadSummary(mPm);
|
||||
final String fragment =
|
||||
LaunchAccessibilityActivityPreferenceFragment.class.getName();
|
||||
|
||||
|
@@ -762,12 +762,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
*/
|
||||
public static CharSequence getServiceSummary(Context context) {
|
||||
// Get the user shortcut type from settings provider.
|
||||
int shortcutType = getUserShortcutTypeFromSettings(context);
|
||||
return context.getString(
|
||||
R.string.preference_summary_default_combination,
|
||||
shortcutType != AccessibilityUtil.UserShortcutType.EMPTY
|
||||
? context.getString(R.string.accessibility_summary_shortcut_enabled)
|
||||
: context.getString(R.string.generic_accessibility_feature_shortcut_off),
|
||||
context.getText(R.string.magnification_feature_summary));
|
||||
final int uerShortcutType = getUserShortcutTypeFromSettings(context);
|
||||
return (uerShortcutType != AccessibilityUtil.UserShortcutType.EMPTY)
|
||||
? context.getText(R.string.accessibility_summary_shortcut_enabled)
|
||||
: context.getText(R.string.generic_accessibility_feature_shortcut_off);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user