Merge "Show default description only if description and html description are empty" into rvc-dev

This commit is contained in:
Jason Hsu
2020-04-21 09:41:15 +00:00
committed by Android (Google) Code Review
3 changed files with 17 additions and 24 deletions

View File

@@ -307,11 +307,7 @@ public class AccessibilitySettings extends DashboardFragment {
return context.getText(R.string.accessibility_description_state_stopped); return context.getText(R.string.accessibility_description_state_stopped);
} }
final String description = info.loadDescription(context.getPackageManager()); return info.loadDescription(context.getPackageManager());
return TextUtils.isEmpty(description)
? context.getText(R.string.accessibility_service_default_description)
: description;
} }
static boolean isRampingRingerEnabled(final Context context) { static boolean isRampingRingerEnabled(final Context context) {
@@ -460,7 +456,7 @@ public class AccessibilitySettings extends DashboardFragment {
} }
/** /**
* Update the order of perferences in the category by matching their preference * Update the order of preferences in the category by matching their preference
* key with the string array of preference order which is defined in the xml. * key with the string array of preference order which is defined in the xml.
* *
* @param categoryKey The key of the category need to update the order * @param categoryKey The key of the category need to update the order
@@ -708,10 +704,9 @@ public class AccessibilitySettings extends DashboardFragment {
CharSequence title, CharSequence summary, int imageRes, String htmlDescription, CharSequence title, CharSequence summary, int imageRes, String htmlDescription,
ComponentName componentName) { ComponentName componentName) {
final Bundle extras = preference.getExtras(); final Bundle extras = preference.getExtras();
extras.putString(EXTRA_PREFERENCE_KEY, prefKey); extras.putString(EXTRA_PREFERENCE_KEY, prefKey);
extras.putString(EXTRA_TITLE, title.toString()); extras.putCharSequence(EXTRA_TITLE, title);
extras.putString(EXTRA_SUMMARY, summary.toString()); extras.putCharSequence(EXTRA_SUMMARY, summary);
extras.putParcelable(EXTRA_COMPONENT_NAME, componentName); extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
extras.putInt(EXTRA_ANIMATED_IMAGE_RES, imageRes); extras.putInt(EXTRA_ANIMATED_IMAGE_RES, imageRes);
extras.putString(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, htmlDescription); extras.putString(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, htmlDescription);

View File

@@ -83,6 +83,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected ComponentName mComponentName; protected ComponentName mComponentName;
protected CharSequence mPackageName; protected CharSequence mPackageName;
protected Uri mImageUri; protected Uri mImageUri;
private CharSequence mDescription;
protected CharSequence mHtmlDescription; protected CharSequence mHtmlDescription;
// Used to restore the edit dialog status. // Used to restore the edit dialog status.
protected int mUserShortcutTypesCache = UserShortcutType.EMPTY; protected int mUserShortcutTypesCache = UserShortcutType.EMPTY;
@@ -190,7 +191,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
groupCategory.addPreference(mSettingsPreference); groupCategory.addPreference(mSettingsPreference);
} }
if (mHtmlDescription != null) { if (!TextUtils.isEmpty(mHtmlDescription)) {
final PreferenceCategory introductionCategory = new PreferenceCategory( final PreferenceCategory introductionCategory = new PreferenceCategory(
getPrefContext()); getPrefContext());
final CharSequence title = getString(R.string.accessibility_introduction_title, final CharSequence title = getString(R.string.accessibility_introduction_title,
@@ -205,6 +206,16 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
htmlTextPreference.setSelectable(false); htmlTextPreference.setSelectable(false);
introductionCategory.addPreference(htmlTextPreference); introductionCategory.addPreference(htmlTextPreference);
} }
if (!TextUtils.isEmpty(mDescription)) {
createFooterPreference(mDescription);
}
if (TextUtils.isEmpty(mHtmlDescription) && TextUtils.isEmpty(mDescription)) {
final CharSequence defaultDescription = getText(
R.string.accessibility_service_default_description);
createFooterPreference(defaultDescription);
}
} }
@Override @Override
@@ -364,9 +375,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Summary. // Summary.
if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) { if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
final CharSequence summary = arguments.getCharSequence( mDescription = arguments.getCharSequence(AccessibilitySettings.EXTRA_SUMMARY);
AccessibilitySettings.EXTRA_SUMMARY);
createFooterPreference(summary);
} }
// Settings html description. // Settings html description.

View File

@@ -214,17 +214,6 @@ public class AccessibilitySettingsTest {
assertThat(description).isEqualTo(DEFAULT_DESCRIPTION); assertThat(description).isEqualTo(DEFAULT_DESCRIPTION);
} }
@Test
public void getServiceDescription_noDescription_showsDefaultString() {
doReturn(EMPTY_STRING).when(mServiceInfo).loadDescription(any());
final CharSequence description = AccessibilitySettings.getServiceDescription(mContext,
mServiceInfo, SERVICE_ENABLED);
assertThat(description).isEqualTo(
mContext.getString(R.string.accessibility_service_default_description));
}
@Test @Test
public void createAccessibilityServicePreferenceList_hasOneInfo_containsSameKey() { public void createAccessibilityServicePreferenceList_hasOneInfo_containsSameKey() {
final String key = DUMMY_COMPONENT_NAME.flattenToString(); final String key = DUMMY_COMPONENT_NAME.flattenToString();