From 649b2fb00af4344e247b314b69fbcbcefae8751f Mon Sep 17 00:00:00 2001 From: Rhed Jao Date: Fri, 7 Feb 2020 18:56:56 +0800 Subject: Support rich content for accessibility shortcut target Two attributes are added in AccessibilityShortcutInfo: - animatedImageDrawable - htmlDescription Bug: 148929247 Test: atest AccessibilityShortcutInfoTest Change-Id: Ibf41775cbfee0fdd946541bbae45ac088d11d693 --- .../AccessibilityShortcutInfo.java | 37 ++++++++++++++++++++++ core/java/android/content/Intent.java | 7 ++-- core/res/res/values/attrs.xml | 6 ++++ core/tests/coretests/res/values/strings.xml | 3 ++ .../xml/accessibility_shortcut_test_activity.xml | 2 ++ .../AccessibilityShortcutInfoTest.java | 16 ++++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) diff --git a/core/java/android/accessibilityservice/AccessibilityShortcutInfo.java b/core/java/android/accessibilityservice/AccessibilityShortcutInfo.java index d79740b49b3d..9912d2b1cc8b 100644 --- a/core/java/android/accessibilityservice/AccessibilityShortcutInfo.java +++ b/core/java/android/accessibilityservice/AccessibilityShortcutInfo.java @@ -75,6 +75,16 @@ public final class AccessibilityShortcutInfo { */ private final int mDescriptionResId; + /** + * Resource id of the animated image of the accessibility shortcut target. + */ + private final int mAnimatedImageRes; + + /** + * Resource id of the html description of the accessibility shortcut target. + */ + private final int mHtmlDescriptionRes; + /** * Creates a new instance. * @@ -119,6 +129,14 @@ public final class AccessibilityShortcutInfo { // Gets summary mSummaryResId = asAttributes.getResourceId( com.android.internal.R.styleable.AccessibilityShortcutTarget_summary, 0); + // Gets animated image + mAnimatedImageRes = asAttributes.getResourceId( + com.android.internal.R.styleable + .AccessibilityShortcutTarget_animatedImageDrawable, 0); + // Gets html description + mHtmlDescriptionRes = asAttributes.getResourceId( + com.android.internal.R.styleable.AccessibilityShortcutTarget_htmlDescription, + 0); asAttributes.recycle(); if (mDescriptionResId == 0 || mSummaryResId == 0) { @@ -171,6 +189,25 @@ public final class AccessibilityShortcutInfo { return loadResourceString(packageManager, mActivityInfo, mDescriptionResId); } + /** + * The animated image resource id of the accessibility shortcut target. + * + * @return The animated image resource id. + */ + public int getAnimatedImageRes() { + return mAnimatedImageRes; + } + + /** + * The localized html description of the accessibility shortcut target. + * + * @return The localized html description. + */ + @Nullable + public String loadHtmlDescription(@NonNull PackageManager packageManager) { + return loadResourceString(packageManager, mActivityInfo, mHtmlDescriptionRes); + } + /** * Gets string resource by the given activity and resource id. */ diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index acffec98b2fc..7091a278640b 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -4962,11 +4962,14 @@ public class Intent implements Parcelable, Cloneable { *
      * <accessibility-shortcut-target
      *     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:htmlDescription="@string/shortcut_target_html_description" />
      * 
*

* Both description and summary are necessary. The system will ignore the accessibility - * shortcut target if they are missing. + * shortcut target if they are missing. The animated image and html description are supported + * to help users understand how to use the shortcut target. *

*/ @SdkConstant(SdkConstantType.INTENT_CATEGORY) diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 20901e04e6c5..7d8b8db9d4a0 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3790,6 +3790,12 @@ + + + + Accessibility shortcut summary + + + Accessibility shortcut html description diff --git a/core/tests/coretests/res/xml/accessibility_shortcut_test_activity.xml b/core/tests/coretests/res/xml/accessibility_shortcut_test_activity.xml index 60e29989ef0d..a597b7190fd7 100644 --- a/core/tests/coretests/res/xml/accessibility_shortcut_test_activity.xml +++ b/core/tests/coretests/res/xml/accessibility_shortcut_test_activity.xml @@ -19,4 +19,6 @@ \ No newline at end of file diff --git a/core/tests/coretests/src/android/accessibilityservice/AccessibilityShortcutInfoTest.java b/core/tests/coretests/src/android/accessibilityservice/AccessibilityShortcutInfoTest.java index ae6d8df26feb..82a7b2c9217e 100644 --- a/core/tests/coretests/src/android/accessibilityservice/AccessibilityShortcutInfoTest.java +++ b/core/tests/coretests/src/android/accessibilityservice/AccessibilityShortcutInfoTest.java @@ -83,6 +83,22 @@ public class AccessibilityShortcutInfoTest { mShortcutInfo.loadSummary(mPackageManager), is(summary)); } + @Test + public void testAnimatedImageRes() { + assertThat("Animated image resource id is not correct", + mShortcutInfo.getAnimatedImageRes(), is(R.drawable.bitmap_drawable)); + } + + @Test + public void testHtmlDescription() { + final String htmlDescription = mTargetContext.getResources() + .getString(R.string.accessibility_shortcut_html_description); + + assertNotNull("Can't find html description string", htmlDescription); + assertThat("Html description is not correct", + mShortcutInfo.loadHtmlDescription(mPackageManager), is(htmlDescription)); + } + @Test public void testEquals() { assertTrue(mShortcutInfo.equals(mShortcutInfo)); -- cgit v1.2.3-59-g8ed1b