From f20dfb5ec4d05416bf53367db1c143e2799d3639 Mon Sep 17 00:00:00 2001 From: keyboardr Date: Tue, 27 Jun 2017 17:13:36 -0700 Subject: Add accessibility info for bubble. Bug: 62886248 Test: Manual with talkback enabled PiperOrigin-RevId: 160349111 Change-Id: I9eaaac90b93b7e6f3a002288d0d68fbbe3fae56c --- java/com/android/dialershared/bubble/Bubble.java | 38 ++++++++++++++++++++++ .../android/dialershared/bubble/BubbleInfo.java | 10 ++++++ .../dialershared/bubble/res/values/strings.xml | 20 ++++++++++++ .../android/incallui/ReturnToCallController.java | 4 +++ java/com/android/incallui/res/values/strings.xml | 2 ++ 5 files changed, 74 insertions(+) create mode 100644 java/com/android/dialershared/bubble/res/values/strings.xml (limited to 'java/com/android') diff --git a/java/com/android/dialershared/bubble/Bubble.java b/java/com/android/dialershared/bubble/Bubble.java index f2ba117d8..81e1dcbfb 100644 --- a/java/com/android/dialershared/bubble/Bubble.java +++ b/java/com/android/dialershared/bubble/Bubble.java @@ -31,6 +31,7 @@ import android.graphics.drawable.RippleDrawable; import android.net.Uri; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; +import android.os.Bundle; import android.os.Handler; import android.provider.Settings; import android.support.annotation.ColorInt; @@ -49,12 +50,15 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.View.AccessibilityDelegate; import android.view.ViewGroup; import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewPropertyAnimator; import android.view.ViewTreeObserver.OnPreDrawListener; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; +import android.view.accessibility.AccessibilityNodeInfo; +import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; import android.view.animation.AnticipateInterpolator; import android.view.animation.OvershootInterpolator; import android.widget.FrameLayout; @@ -107,6 +111,38 @@ public class Bubble { private Integer overrideGravity; private ViewPropertyAnimator exitAnimator; + private final AccessibilityDelegate accessibilityDelegate = + new AccessibilityDelegate() { + @Override + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + if (textShowing) { + info.setContentDescription(viewHolder.getPrimaryText().getText()); + return; + } + if (expanded) { + info.setContentDescription(currentInfo.getPrimaryContentDescription()); + info.addAction(AccessibilityAction.ACTION_CLICK); + } else { + info.setContentDescription(currentInfo.getBubbleContentDescription()); + info.addAction( + new AccessibilityAction( + AccessibilityNodeInfo.ACTION_CLICK, + host.getContext().getString(R.string.content_description_action_bubble_click))); + } + info.addAction(AccessibilityAction.ACTION_MOVE_WINDOW); + } + + @Override + public boolean performAccessibilityAction(View host, int action, Bundle args) { + if (action == AccessibilityNodeInfo.ACTION_CLICK) { + primaryButtonClick(); + return true; + } + return super.performAccessibilityAction(host, action, args); + } + }; + @Retention(RetentionPolicy.SOURCE) @IntDef({CollapseEnd.NOTHING, CollapseEnd.HIDE}) private @interface CollapseEnd { @@ -713,6 +749,8 @@ public class Bubble { secondButton = contentView.findViewById(R.id.bubble_icon_second); thirdButton = contentView.findViewById(R.id.bubble_icon_third); + primaryButton.setAccessibilityDelegate(accessibilityDelegate); + root.setOnBackPressedListener( () -> { if (visibility == Visibility.SHOWING && expanded) { diff --git a/java/com/android/dialershared/bubble/BubbleInfo.java b/java/com/android/dialershared/bubble/BubbleInfo.java index eb9abd059..99875fe2a 100644 --- a/java/com/android/dialershared/bubble/BubbleInfo.java +++ b/java/com/android/dialershared/bubble/BubbleInfo.java @@ -28,12 +28,18 @@ import java.util.List; /** Info for displaying a {@link Bubble} */ @AutoValue public abstract class BubbleInfo { + @NonNull + public abstract CharSequence getBubbleContentDescription(); + @ColorInt public abstract int getPrimaryColor(); @NonNull public abstract Icon getPrimaryIcon(); + @NonNull + public abstract CharSequence getPrimaryContentDescription(); + @NonNull public abstract PendingIntent getPrimaryIntent(); @@ -60,12 +66,16 @@ public abstract class BubbleInfo { @AutoValue.Builder public abstract static class Builder { + public abstract Builder setBubbleContentDescription(@NonNull CharSequence description); + public abstract Builder setPrimaryColor(@ColorInt int primaryColor); public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon); public abstract Builder setPrimaryIntent(@NonNull PendingIntent primaryIntent); + public abstract Builder setPrimaryContentDescription(@NonNull CharSequence description); + public abstract Builder setStartingYPosition(@Px int startingYPosition); public abstract Builder setActions(List actions); diff --git a/java/com/android/dialershared/bubble/res/values/strings.xml b/java/com/android/dialershared/bubble/res/values/strings.xml new file mode 100644 index 000000000..c68619899 --- /dev/null +++ b/java/com/android/dialershared/bubble/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + + Expand drawer + diff --git a/java/com/android/incallui/ReturnToCallController.java b/java/com/android/incallui/ReturnToCallController.java index 33154c5cf..c105e68e7 100644 --- a/java/com/android/incallui/ReturnToCallController.java +++ b/java/com/android/incallui/ReturnToCallController.java @@ -169,6 +169,10 @@ public class ReturnToCallController implements InCallUiListener, Listener, Audio .setStartingYPosition( context.getResources().getDimensionPixelOffset(R.dimen.return_to_call_initial_offset_y)) .setPrimaryIntent(PendingIntent.getActivity(context, 0, activityIntent, 0)) + .setBubbleContentDescription( + context.getText(R.string.content_description_return_to_call_bubble)) + .setPrimaryContentDescription( + context.getText(R.string.content_description_return_to_call_primary)) .setActions(generateActions()) .build(); } diff --git a/java/com/android/incallui/res/values/strings.xml b/java/com/android/incallui/res/values/strings.xml index 4113313df..c69487453 100644 --- a/java/com/android/incallui/res/values/strings.xml +++ b/java/com/android/incallui/res/values/strings.xml @@ -357,5 +357,7 @@ data charges may apply. Do not show this again + Ongoing call + Return to call -- cgit v1.2.3