Use HTML text preference for rich content

Implements for Color Correction, Color Inversion, and Magnify

Bug: 148837311
Test: Manual test
Change-Id: I5e5b311b6ae8e42cca3ef9048c8b8b0de52d13bc
This commit is contained in:
menghanli
2020-02-10 13:58:24 +08:00
parent 764e05ddfe
commit 5638acbc82
10 changed files with 46 additions and 81 deletions

View File

@@ -4822,7 +4822,7 @@
<!-- Short summary for nav bar Magnification. Tells the user that this feature allows the user to magnify the screen using a button in the nav bar --> <!-- Short summary for nav bar Magnification. Tells the user that this feature allows the user to magnify the screen using a button in the nav bar -->
<string name="accessibility_screen_magnification_navbar_short_summary">Tap a button to zoom</string> <string name="accessibility_screen_magnification_navbar_short_summary">Tap a button to zoom</string>
<!-- Summary for the accessibility preference screen to enable screen magnification gestures. [CHAR LIMIT=none] --> <!-- Summary for the accessibility preference screen to enable screen magnification gestures. [CHAR LIMIT=none] -->
<string name="accessibility_screen_magnification_summary">Quickly zoom in on the screen to see content more clearly.\n\n<b>To zoom in:</b>\n\t1. Use shortcut to start magnification\n\t2. Tap the screen\n\t3. Drag 2 fingers to move around screen\n\t4. Pinch with 2 fingers to adjust zoom\n\t5. Use shortcut to stop magnification</string> <string name="accessibility_screen_magnification_summary"><![CDATA[Quickly zoom in on the screen to see content more clearly.<br/><br/><b>To zoom in:</b><br/>\t1. Use shortcut to start magnification<br/>\t2. Tap the screen<br/>\t3. Drag 2 fingers to move around screen<br/>\t4. Pinch with 2 fingers to adjust zoom<br/>\t5. Use shortcut to stop magnification<br/><br/><b>To zoom in temporarily:</b><br/>\t1. Use shortcut to start magnification<br/>\t2. Touch & hold anywhere on the screen<br/>\t3. Drag finger to move around screen<br/>\t4. Lift finger to stop magnification]]></string>
<!-- Summary for the accessibility preference screen to enable screen magnification via the nav bar. [CHAR LIMIT=none] --> <!-- Summary for the accessibility preference screen to enable screen magnification via the nav bar. [CHAR LIMIT=none] -->
<string name="accessibility_screen_magnification_navbar_summary">When magnification is turned on, you can zoom in on your screen.\n\n<b>To zoom</b>, start magnification, then tap anywhere on the screen.\n<ul><li>Drag 2 or more fingers to scroll</li>\n<li>Pinch 2 or more fingers to adjust zoom</li></ul>\n\n<b>To zoom temporarily</b>, start magnification, then touch &amp; hold anywhere on the screen.\n<ul><li>Drag to move around the screen</li>\n<li>Lift finger to zoom out</li></ul>\n\nYou cant zoom in on the keyboard or navigation bar.</string> <string name="accessibility_screen_magnification_navbar_summary">When magnification is turned on, you can zoom in on your screen.\n\n<b>To zoom</b>, start magnification, then tap anywhere on the screen.\n<ul><li>Drag 2 or more fingers to scroll</li>\n<li>Pinch 2 or more fingers to adjust zoom</li></ul>\n\n<b>To zoom temporarily</b>, start magnification, then touch &amp; hold anywhere on the screen.\n<ul><li>Drag to move around the screen</li>\n<li>Lift finger to zoom out</li></ul>\n\nYou cant zoom in on the keyboard or navigation bar.</string>
<!-- Title for the Accessibility tutorial dialog in Accessibility service with button. [CHAR LIMIT=50] --> <!-- Title for the Accessibility tutorial dialog in Accessibility service with button. [CHAR LIMIT=50] -->
@@ -4932,7 +4932,7 @@
<!-- Used in the accessibility service settings to control turning display color inversion on/off entirely. [CHAR LIMIT=NONE] --> <!-- Used in the accessibility service settings to control turning display color inversion on/off entirely. [CHAR LIMIT=NONE] -->
<string name="accessibility_display_inversion_switch_title">Use color inversion</string> <string name="accessibility_display_inversion_switch_title">Use color inversion</string>
<!-- Subtitle for the accessibility preference to configure display color inversion. [CHAR LIMIT=NONE] --> <!-- Subtitle for the accessibility preference to configure display color inversion. [CHAR LIMIT=NONE] -->
<string name="accessibility_display_inversion_preference_subtitle">Color inversion turns light screens dark. This helps people who are sensitive to bright light see the screen more easily.\n\nNote: Dark colors will turn light. Colors will change in media and images. You can also use Dark theme (Settings > Display).</string> <string name="accessibility_display_inversion_preference_subtitle"><![CDATA[Color inversion turns light screens dark. This helps people who are sensitive to bright light see the screen more easily.<br/><br/>Note: Dark colors will turn light. Colors will change in media and images. You can also use Dark theme (Settings > Display).]]></string>
<!-- Title for accessibility preference for configuring feature that performs click action soon after mouse/trackpad pointer stops moving. [CHAR LIMIT=NONE] --> <!-- Title for accessibility preference for configuring feature that performs click action soon after mouse/trackpad pointer stops moving. [CHAR LIMIT=NONE] -->
<string name="accessibility_autoclick_preference_title">Auto click (dwell timing)</string> <string name="accessibility_autoclick_preference_title">Auto click (dwell timing)</string>
<!-- Footer text to explain what autoclick does --> <!-- Footer text to explain what autoclick does -->

View File

@@ -31,17 +31,4 @@
settings:allowDividerBelow="true" settings:allowDividerBelow="true"
settings:searchable="false" /> settings:searchable="false" />
<PreferenceCategory
android:key="color_inversion_footer_category">
<com.android.settingslib.widget.FooterPreference
android:key="color_inversion_footer"
android:persistent="false"
android:selectable="false"
settings:allowDividerAbove="false"
android:title="@string/accessibility_display_inversion_preference_subtitle"
settings:searchable="false" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -52,16 +52,4 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:key="daltonizer_footer_category">
<com.android.settingslib.widget.FooterPreference
android:key="daltonizer_footer"
android:persistent="false"
android:selectable="false"
settings:allowDividerAbove="false"
android:title="@string/accessibility_display_daltonizer_preference_subtitle"
settings:searchable="false" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -92,8 +92,8 @@ public class MagnificationGesturesPreferenceController extends TogglePreferenceC
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED); Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES, extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
R.string.accessibility_screen_magnification_gestures_title); R.string.accessibility_screen_magnification_gestures_title);
extras.putInt(AccessibilitySettings.EXTRA_SUMMARY_RES, extras.putCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION,
R.string.accessibility_screen_magnification_summary); context.getText(R.string.accessibility_screen_magnification_summary));
extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID, extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
R.raw.accessibility_screen_magnification); R.raw.accessibility_screen_magnification);
} }

View File

@@ -55,8 +55,8 @@ public class MagnificationNavbarPreferenceController extends TogglePreferenceCon
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED); Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES, extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
R.string.accessibility_screen_magnification_navbar_title); R.string.accessibility_screen_magnification_navbar_title);
extras.putInt(AccessibilitySettings.EXTRA_SUMMARY_RES, extras.putCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION,
R.string.accessibility_screen_magnification_navbar_summary); mContext.getText(R.string.accessibility_screen_magnification_navbar_summary));
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked()); extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked());
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW); extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
} }

View File

@@ -330,9 +330,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends
.appendPath(String.valueOf(animatedImageRes)) .appendPath(String.valueOf(animatedImageRes))
.build(); .build();
// Settings html description.
mHtmlDescription = arguments.getCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION);
// Get Accessibility service name. // Get Accessibility service name.
mPackageName = getAccessibilityServiceInfo().getResolveInfo().loadLabel( mPackageName = getAccessibilityServiceInfo().getResolveInfo().loadLabel(
getPackageManager()); getPackageManager());

View File

@@ -29,8 +29,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.android.settings.R; import com.android.settings.R;
@@ -45,7 +43,6 @@ import java.util.List;
public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment { public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED; private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
private static final String CATEGORY_FOOTER_KEY = "color_inversion_footer_category";
private static final int DIALOG_ID_EDIT_SHORTCUT = 1; private static final int DIALOG_ID_EDIT_SHORTCUT = 1;
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver; private SettingsContentObserver mSettingsContentObserver;
@@ -91,7 +88,8 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
mComponentName = COLOR_INVERSION_COMPONENT_NAME; mComponentName = COLOR_INVERSION_COMPONENT_NAME;
mPackageName = getString(R.string.accessibility_display_inversion_preference_title); mPackageName = getText(R.string.accessibility_display_inversion_preference_title);
mHtmlDescription = getText(R.string.accessibility_display_inversion_preference_subtitle);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1); final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED); enableServiceFeatureKeys.add(ENABLED);
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) { mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@@ -103,17 +101,6 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
return super.onCreateView(inflater, container, savedInstanceState); return super.onCreateView(inflater, container, savedInstanceState);
} }
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false);
final PreferenceCategory footerCategory = preferenceScreen.findPreference(
CATEGORY_FOOTER_KEY);
footerCategory.setOrder(Integer.MAX_VALUE);
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();

View File

@@ -32,7 +32,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
@@ -50,8 +49,8 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
implements DaltonizerRadioButtonPreferenceController.OnChangeListener { implements DaltonizerRadioButtonPreferenceController.OnChangeListener {
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED; private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
private static final String CATEGORY_FOOTER_KEY = "daltonizer_footer_category"; private static final String KEY_PREVIEW = "daltonizer_preview";
private static final String CATEGORY_MODE_KEY = "daltonizer_mode_category"; private static final String KEY_CATEGORY_MODE = "daltonizer_mode_category";
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>(); private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver; private SettingsContentObserver mSettingsContentObserver;
@@ -82,7 +81,8 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
mComponentName = DALTONIZER_COMPONENT_NAME; mComponentName = DALTONIZER_COMPONENT_NAME;
mPackageName = getString(R.string.accessibility_display_daltonizer_preference_title); mPackageName = getText(R.string.accessibility_display_daltonizer_preference_title);
mHtmlDescription = getText(R.string.accessibility_display_daltonizer_preference_subtitle);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1); final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED); enableServiceFeatureKeys.add(ENABLED);
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) { mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@@ -97,16 +97,32 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
updatePreferenceOrder();
}
/** Customizes the order by preference key. */
private List<String> getPreferenceOrderList() {
List<String> lists = new ArrayList<>();
lists.add(KEY_PREVIEW);
lists.add(KEY_USE_SERVICE_PREFERENCE);
lists.add(KEY_CATEGORY_MODE);
lists.add(KEY_GENERAL_CATEGORY);
lists.add(KEY_INTRODUCTION_CATEGORY);
return lists;
}
private void updatePreferenceOrder() {
List<String> lists = getPreferenceOrderList();
final PreferenceScreen preferenceScreen = getPreferenceScreen(); final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false); preferenceScreen.setOrderingAsAdded(false);
final PreferenceCategory modeCategory = preferenceScreen.findPreference( final int size = lists.size();
CATEGORY_MODE_KEY); for (int i = 0; i < size; i++) {
modeCategory.setOrder(Integer.MAX_VALUE - 1); final Preference preference = preferenceScreen.findPreference(lists.get(i));
if (preference != null) {
final PreferenceCategory footerCategory = preferenceScreen.findPreference( preference.setOrder(i);
CATEGORY_FOOTER_KEY); }
footerCategory.setOrder(Integer.MAX_VALUE); }
} }
@Override @Override

View File

@@ -79,7 +79,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected CharSequence mHtmlDescription; protected CharSequence mHtmlDescription;
private static final String ANCHOR_TAG = "a"; private static final String ANCHOR_TAG = "a";
private static final String DRAWABLE_FOLDER = "drawable"; private static final String DRAWABLE_FOLDER = "drawable";
protected static final String KEY_GENERAL_CATEGORY = "categories"; protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
protected static final String KEY_GENERAL_CATEGORY = "general_categories";
protected static final String KEY_INTRODUCTION_CATEGORY = "introduction_categories";
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
@@ -146,6 +148,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
mToggleServiceDividerSwitchPreference = new DividerSwitchPreference(getPrefContext()); mToggleServiceDividerSwitchPreference = new DividerSwitchPreference(getPrefContext());
mToggleServiceDividerSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
preferenceScreen.addPreference(mToggleServiceDividerSwitchPreference); preferenceScreen.addPreference(mToggleServiceDividerSwitchPreference);
onProcessArguments(getArguments()); onProcessArguments(getArguments());
@@ -177,6 +180,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
getPrefContext()); getPrefContext());
final CharSequence title = getString(R.string.accessibility_introduction_title, final CharSequence title = getString(R.string.accessibility_introduction_title,
mPackageName); mPackageName);
introductionCategory.setKey(KEY_INTRODUCTION_CATEGORY);
introductionCategory.setTitle(title); introductionCategory.setTitle(title);
preferenceScreen.addPreference(introductionCategory); preferenceScreen.addPreference(introductionCategory);
@@ -358,6 +362,12 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
AccessibilitySettings.EXTRA_SUMMARY); AccessibilitySettings.EXTRA_SUMMARY);
createFooterPreference(summary); createFooterPreference(summary);
} }
// Settings html description.
if (arguments.containsKey(AccessibilitySettings.EXTRA_HTML_DESCRIPTION)) {
mHtmlDescription = arguments.getCharSequence(
AccessibilitySettings.EXTRA_HTML_DESCRIPTION);
}
} }
private Drawable getDrawableFromUri(Uri imageUri) { private Drawable getDrawableFromUri(Uri imageUri) {

View File

@@ -83,8 +83,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static final char COMPONENT_NAME_SEPARATOR = ':'; private static final char COMPONENT_NAME_SEPARATOR = ':';
private static final TextUtils.SimpleStringSplitter sStringColonSplitter = private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR); new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
protected Preference mConfigWarningPreference;
protected VideoPreference mVideoPreference; protected VideoPreference mVideoPreference;
protected class VideoPreference extends Preference { protected class VideoPreference extends Preference {
@@ -192,12 +190,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
initShortcutPreference(); initShortcutPreference();
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
mConfigWarningPreference = new Preference(getPrefContext());
mConfigWarningPreference.setSelectable(false);
mConfigWarningPreference.setPersistent(false);
mConfigWarningPreference.setVisible(false);
preferenceScreen.addPreference(mConfigWarningPreference);
} }
@Override @Override
@@ -219,7 +211,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
videoView.start(); videoView.start();
} }
updateConfigurationWarningIfNeeded();
updateShortcutPreferenceData(); updateShortcutPreferenceData();
updateShortcutPreference(); updateShortcutPreference();
} }
@@ -428,7 +419,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
: DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL); : DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL);
} }
MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled); MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled);
updateConfigurationWarningIfNeeded();
} }
@Override @Override
@@ -496,16 +486,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
} }
private void updateConfigurationWarningIfNeeded() {
final CharSequence warningMessage =
MagnificationPreferenceFragment.getConfigurationWarningStringForSecureSettingsKey(
mPreferenceKey, getPrefContext());
if (warningMessage != null) {
mConfigWarningPreference.setSummary(warningMessage);
}
mConfigWarningPreference.setVisible(warningMessage != null);
}
@VisibleForTesting @VisibleForTesting
static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) { static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) { if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {