From da7771683a334db63b4503a291d3c67e7b4ca22e Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Wed, 4 Apr 2018 17:24:11 -0700 Subject: Fixed some issues in dialer's dialpad for talkback users. - Content description for voicemail button is now "1... double tap and hold to call vociemail" - Content description for 0 button is now "0... double tap and hold for plus symbol" Bug: 19621015,62712616 Test: manual + a11y office hours PiperOrigin-RevId: 191673375 Change-Id: I9b5d8d875f1bf218be6fcc33dff4ac9e479e4f43 --- .../dialer/dialpadview/DialpadKeyButton.java | 76 ++++------------------ 1 file changed, 14 insertions(+), 62 deletions(-) (limited to 'java/com/android/dialer/dialpadview/DialpadKeyButton.java') diff --git a/java/com/android/dialer/dialpadview/DialpadKeyButton.java b/java/com/android/dialer/dialpadview/DialpadKeyButton.java index 84aca14f2..47553b6f9 100644 --- a/java/com/android/dialer/dialpadview/DialpadKeyButton.java +++ b/java/com/android/dialer/dialpadview/DialpadKeyButton.java @@ -19,13 +19,14 @@ package com.android.dialer.dialpadview; import android.content.Context; import android.graphics.RectF; import android.os.Bundle; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import android.view.ViewConfiguration; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; +import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; import android.widget.FrameLayout; /** @@ -45,33 +46,21 @@ import android.widget.FrameLayout; */ public class DialpadKeyButton extends FrameLayout { - /** Timeout before switching to long-click accessibility mode. */ - private static final int LONG_HOVER_TIMEOUT = ViewConfiguration.getLongPressTimeout() * 2; - /** Accessibility manager instance used to check touch exploration state. */ private AccessibilityManager accessibilityManager; /** Bounds used to filter HOVER_EXIT events. */ private RectF hoverBounds = new RectF(); - /** Whether this view is currently in the long-hover state. */ - private boolean longHovered; - /** Alternate content description for long-hover state. */ private CharSequence longHoverContentDesc; - /** Backup of standard content description. Used for accessibility. */ - private CharSequence backupContentDesc; - /** Backup of clickable property. Used for accessibility. */ private boolean wasClickable; /** Backup of long-clickable property. Used for accessibility. */ private boolean wasLongClickable; - /** Runnable used to trigger long-click mode for accessibility. */ - private Runnable longHoverRunnable; - private OnPressedListener onPressedListener; public DialpadKeyButton(Context context, AttributeSet attrs) { @@ -95,19 +84,6 @@ public class DialpadKeyButton extends FrameLayout { public void setLongHoverContentDescription(CharSequence contentDescription) { longHoverContentDesc = contentDescription; - - if (longHovered) { - super.setContentDescription(longHoverContentDesc); - } - } - - @Override - public void setContentDescription(CharSequence contentDescription) { - if (longHovered) { - backupContentDesc = contentDescription; - } else { - super.setContentDescription(contentDescription); - } } @Override @@ -138,6 +114,18 @@ public class DialpadKeyButton extends FrameLayout { return super.performAccessibilityAction(action, arguments); } + @Override + public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(info); + // If the button has a long hover description, ask talkback to announce the action follow by + // the description (for example "double tap and hold to call voicemail"). + if (!TextUtils.isEmpty(longHoverContentDesc)) { + AccessibilityAction longClickAction = + new AccessibilityAction(AccessibilityNodeInfo.ACTION_LONG_CLICK, longHoverContentDesc); + info.addAction(longClickAction); + } + } + @Override public boolean onHoverEvent(MotionEvent event) { // When touch exploration is turned on, lifting a finger while inside @@ -148,20 +136,6 @@ public class DialpadKeyButton extends FrameLayout { // Lift-to-type temporarily disables double-tap activation. wasClickable = isClickable(); wasLongClickable = isLongClickable(); - if (wasLongClickable && longHoverContentDesc != null) { - if (longHoverRunnable == null) { - longHoverRunnable = - new Runnable() { - @Override - public void run() { - setLongHovered(true); - announceForAccessibility(longHoverContentDesc); - } - }; - } - postDelayed(longHoverRunnable, LONG_HOVER_TIMEOUT); - } - setClickable(false); setLongClickable(false); break; @@ -170,7 +144,6 @@ public class DialpadKeyButton extends FrameLayout { simulateClickForAccessibility(); } - cancelLongHover(); setClickable(wasClickable); setLongClickable(wasLongClickable); break; @@ -201,27 +174,6 @@ public class DialpadKeyButton extends FrameLayout { setPressed(false); } - private void setLongHovered(boolean enabled) { - if (longHovered != enabled) { - longHovered = enabled; - - // Switch between normal and alternate description, if available. - if (enabled) { - backupContentDesc = getContentDescription(); - super.setContentDescription(longHoverContentDesc); - } else { - super.setContentDescription(backupContentDesc); - } - } - } - - private void cancelLongHover() { - if (longHoverRunnable != null) { - removeCallbacks(longHoverRunnable); - } - setLongHovered(false); - } - public interface OnPressedListener { void onPressed(View view, boolean pressed); -- cgit v1.2.3