Merge "Support settings activity for accessibility shortcut target" into rvc-dev am: 6820d68e25

Change-Id: I0dec303c9db9058e8f879f5cd6764ab1c3f8d5d0
This commit is contained in:
Automerger Merge Worker
2020-03-04 12:32:12 +00:00
5 changed files with 37 additions and 2 deletions

View File

@@ -90,6 +90,12 @@ public final class AccessibilityShortcutInfo {
*/ */
private final int mHtmlDescriptionRes; private final int mHtmlDescriptionRes;
/**
* The accessibility shortcut target setting activity's name, used by the system
* settings to launch the setting activity of this accessibility shortcut target.
*/
private String mSettingsActivityName;
/** /**
* Creates a new instance. * Creates a new instance.
* *
@@ -142,6 +148,9 @@ public final class AccessibilityShortcutInfo {
mHtmlDescriptionRes = asAttributes.getResourceId( mHtmlDescriptionRes = asAttributes.getResourceId(
com.android.internal.R.styleable.AccessibilityShortcutTarget_htmlDescription, com.android.internal.R.styleable.AccessibilityShortcutTarget_htmlDescription,
0); 0);
// Get settings activity name
mSettingsActivityName = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityShortcutTarget_settingsActivity);
asAttributes.recycle(); asAttributes.recycle();
if (mDescriptionResId == 0 || mSummaryResId == 0) { if (mDescriptionResId == 0 || mSummaryResId == 0) {
@@ -237,6 +246,16 @@ public final class AccessibilityShortcutInfo {
return TextUtils.isEmpty(htmlDescription) ? null : getFilteredHtmlText(htmlDescription); return TextUtils.isEmpty(htmlDescription) ? null : getFilteredHtmlText(htmlDescription);
} }
/**
* The settings activity name.
*
* @return The settings activity name.
*/
@Nullable
public String getSettingsActivityName() {
return mSettingsActivityName;
}
/** /**
* Gets string resource by the given activity and resource id. * Gets string resource by the given activity and resource id.
*/ */

View File

@@ -4940,12 +4940,15 @@ public class Intent implements Parcelable, Cloneable {
* android:description="@string/shortcut_target_description" * android:description="@string/shortcut_target_description"
* android:summary="@string/shortcut_target_summary" * android:summary="@string/shortcut_target_summary"
* android:animatedImageDrawable="@drawable/shortcut_target_animated_image" * android:animatedImageDrawable="@drawable/shortcut_target_animated_image"
* android:htmlDescription="@string/shortcut_target_html_description" /> * android:htmlDescription="@string/shortcut_target_html_description"
* android:settingsActivity="com.example.android.shortcut.target.SettingsActivity" />
* </pre> * </pre>
* <p> * <p>
* Both description and summary are necessary. The system will ignore the accessibility * Both description and summary are necessary. The system will ignore the accessibility
* shortcut target if they are missing. The animated image and html description are supported * shortcut target if they are missing. The animated image and html description are supported
* to help users understand how to use the shortcut target. * to help users understand how to use the shortcut target. The settings activity is a
* component name that allows the user to modify the settings for this accessibility shortcut
* target.
* </p> * </p>
*/ */
@SdkConstant(SdkConstantType.INTENT_CATEGORY) @SdkConstant(SdkConstantType.INTENT_CATEGORY)

View File

@@ -3796,6 +3796,9 @@
<!-- Html description of the target of accessibility shortcut purpose or behavior, to help <!-- Html description of the target of accessibility shortcut purpose or behavior, to help
users understand how the target of accessibility shortcut can help them. --> users understand how the target of accessibility shortcut can help them. -->
<attr name="htmlDescription" format="reference"/> <attr name="htmlDescription" format="reference"/>
<!-- Component name of an activity that allows the user to modify the settings for this
target of accessibility shortcut. -->
<attr name="settingsActivity" />
</declare-styleable> </declare-styleable>
<!-- Use <code>print-service</code> as the root tag of the XML resource that <!-- Use <code>print-service</code> as the root tag of the XML resource that

View File

@@ -21,4 +21,5 @@
android:summary="@string/accessibility_shortcut_summary" android:summary="@string/accessibility_shortcut_summary"
android:animatedImageDrawable="@drawable/bitmap_drawable" android:animatedImageDrawable="@drawable/bitmap_drawable"
android:htmlDescription="@string/accessibility_shortcut_html_description" android:htmlDescription="@string/accessibility_shortcut_html_description"
android:settingsActivity="com.example.shortcut.target.SettingsActivity"
/> />

View File

@@ -48,6 +48,9 @@ import java.util.List;
@SmallTest @SmallTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class AccessibilityShortcutInfoTest { public class AccessibilityShortcutInfoTest {
private static final String SETTINGS_ACTIVITY_NAME =
"com.example.shortcut.target.SettingsActivity";
private Context mTargetContext; private Context mTargetContext;
private PackageManager mPackageManager; private PackageManager mPackageManager;
private ComponentName mComponentName; private ComponentName mComponentName;
@@ -105,6 +108,12 @@ public class AccessibilityShortcutInfoTest {
mShortcutInfo.loadHtmlDescription(mPackageManager), is(htmlDescription)); mShortcutInfo.loadHtmlDescription(mPackageManager), is(htmlDescription));
} }
@Test
public void testSettingsActivity() {
assertThat("Settings Activity is not correct",
mShortcutInfo.getSettingsActivityName(), is(SETTINGS_ACTIVITY_NAME));
}
@Test @Test
public void testEquals() { public void testEquals() {
assertTrue(mShortcutInfo.equals(mShortcutInfo)); assertTrue(mShortcutInfo.equals(mShortcutInfo));