Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27c781d9 authored by Rhed Jao's avatar Rhed Jao
Browse files

Support settings activity for accessibility shortcut target

Bug: 150277218
Test: atest AccessibilityShortcutInfoTest
Change-Id: I9afc6b2c917b0abe7bb4f5969dd665ba31157c7c
parent 01a592bf
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -90,6 +90,12 @@ public final class AccessibilityShortcutInfo {
     */
    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.
     *
@@ -142,6 +148,9 @@ public final class AccessibilityShortcutInfo {
            mHtmlDescriptionRes = asAttributes.getResourceId(
                    com.android.internal.R.styleable.AccessibilityShortcutTarget_htmlDescription,
                    0);
            // Get settings activity name
            mSettingsActivityName = asAttributes.getString(
                    com.android.internal.R.styleable.AccessibilityShortcutTarget_settingsActivity);
            asAttributes.recycle();

            if (mDescriptionResId == 0 || mSummaryResId == 0) {
@@ -237,6 +246,16 @@ public final class AccessibilityShortcutInfo {
        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.
     */
+5 −2
Original line number Diff line number Diff line
@@ -4974,12 +4974,15 @@ public class Intent implements Parcelable, Cloneable {
     *     android:description="@string/shortcut_target_description"
     *     android:summary="@string/shortcut_target_summary"
     *     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>
     * <p>
     * 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
     * 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>
     */
    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
+3 −0
Original line number Diff line number Diff line
@@ -3796,6 +3796,9 @@
        <!-- Html description of the target of accessibility shortcut purpose or behavior, to help
             users understand how the target of accessibility shortcut can help them. -->
        <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>

    <!-- Use <code>print-service</code> as the root tag of the XML resource that
+1 −0
Original line number Diff line number Diff line
@@ -21,4 +21,5 @@
                        android:summary="@string/accessibility_shortcut_summary"
                        android:animatedImageDrawable="@drawable/bitmap_drawable"
                        android:htmlDescription="@string/accessibility_shortcut_html_description"
                        android:settingsActivity="com.example.shortcut.target.SettingsActivity"
/>
 No newline at end of file
+9 −0
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ import java.util.List;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class AccessibilityShortcutInfoTest {
    private static final String SETTINGS_ACTIVITY_NAME =
            "com.example.shortcut.target.SettingsActivity";

    private Context mTargetContext;
    private PackageManager mPackageManager;
    private ComponentName mComponentName;
@@ -105,6 +108,12 @@ public class AccessibilityShortcutInfoTest {
                mShortcutInfo.loadHtmlDescription(mPackageManager), is(htmlDescription));
    }

    @Test
    public void testSettingsActivity() {
        assertThat("Settings Activity is not correct",
                mShortcutInfo.getSettingsActivityName(), is(SETTINGS_ACTIVITY_NAME));
    }

    @Test
    public void testEquals() {
        assertTrue(mShortcutInfo.equals(mShortcutInfo));