diff options
author | keyboardr <keyboardr@google.com> | 2017-06-27 17:13:36 -0700 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2017-06-30 14:36:35 -0700 |
commit | f20dfb5ec4d05416bf53367db1c143e2799d3639 (patch) | |
tree | 1d9aa62936262df15e857112b68e367d23b68a82 /java | |
parent | 163e709f0cf743e21abac89190dcfaab33ad4001 (diff) |
Add accessibility info for bubble.
Bug: 62886248
Test: Manual with talkback enabled
PiperOrigin-RevId: 160349111
Change-Id: I9eaaac90b93b7e6f3a002288d0d68fbbe3fae56c
Diffstat (limited to 'java')
5 files changed, 74 insertions, 0 deletions
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,6 +28,9 @@ 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(); @@ -35,6 +38,9 @@ public abstract class BubbleInfo { public abstract Icon getPrimaryIcon(); @NonNull + public abstract CharSequence getPrimaryContentDescription(); + + @NonNull public abstract PendingIntent getPrimaryIntent(); @Px @@ -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<Action> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2017 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + +<resources> + <string name="content_description_action_bubble_click">Expand drawer</string> +</resources> 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. </string> <string name="video_call_lte_to_wifi_failed_do_not_show">Do not show this again</string> + <string name="content_description_return_to_call_bubble">Ongoing call</string> + <string name="content_description_return_to_call_primary">Return to call</string> </resources> |