OSDN Git Service

Fix keypad accessibility.
authoralanv <alanv@google.com>
Wed, 31 Oct 2012 00:07:37 +0000 (17:07 -0700)
committeralanv <alanv@google.com>
Wed, 31 Oct 2012 00:07:37 +0000 (17:07 -0700)
Add lift-to-type to the PIN keypad. Speak entered PIN digits. Add content
descriptions to PIN keypad buttons.

Bug: 7436382
Change-Id: I7cb3977cc769598c5f783221e1257b13e5e108c7

core/res/res/layout/keyguard_pin_view.xml
policy/src/com/android/internal/policy/impl/keyguard/KeyguardAbsKeyInputView.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardPINView.java
policy/src/com/android/internal/policy/impl/keyguard/NumPadKey.java

index d62570b..c2c9c37 100644 (file)
@@ -59,6 +59,7 @@
             android:paddingLeft="24dp"
             android:paddingRight="24dp"
             android:background="?android:attr/selectableItemBackground"
+            android:contentDescription="@string/keyboardview_keycode_delete"
             />
     </LinearLayout>
     <View
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:src="@drawable/sym_keyboard_return_holo"
+            android:contentDescription="@string/keyboardview_keycode_enter"
             />
     </LinearLayout>
 
index 9c21830..973e640 100644 (file)
@@ -97,6 +97,9 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
         mPasswordEntry.setOnEditorActionListener(this);
         mPasswordEntry.addTextChangedListener(this);
 
+        // Set selected property on so the view can send accessibility events.
+        mPasswordEntry.setSelected(true);
+
         // Poke the wakelock any time the text is selected or modified
         mPasswordEntry.setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
index bea9aec..c2d5916 100644 (file)
@@ -59,6 +59,7 @@ public class KeyguardPINView extends KeyguardAbsKeyInputView
                     verifyPasswordAndUnlock();
                 }
             });
+            ok.setOnHoverListener(new NumPadKey.LiftToActivateListener(getContext()));
         }
 
         // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
index 060cc03..ca36007 100644 (file)
@@ -22,7 +22,9 @@ import android.text.SpannableStringBuilder;
 import android.text.style.TextAppearanceSpan;
 import android.util.AttributeSet;
 import android.view.HapticFeedbackConstants;
+import android.view.MotionEvent;
 import android.view.View;
+import android.view.accessibility.AccessibilityManager;
 import android.widget.Button;
 import android.widget.TextView;
 
@@ -72,6 +74,7 @@ public class NumPadKey extends Button {
         setTextViewResId(a.getResourceId(R.styleable.NumPadKey_textView, 0));
 
         setOnClickListener(mListener);
+        setOnHoverListener(new LiftToActivateListener(context));
 
         mEnableHaptics = new LockPatternUtils(context).isTactileFeedbackEnabled();
 
@@ -113,4 +116,45 @@ public class NumPadKey extends Button {
                     | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
         }
     }
+
+    /**
+     * Hover listener that implements lift-to-activate interaction for
+     * accessibility. May be added to multiple views.
+     */
+    static class LiftToActivateListener implements View.OnHoverListener {
+        /** Manager used to query accessibility enabled state. */
+        private final AccessibilityManager mAccessibilityManager;
+
+        public LiftToActivateListener(Context context) {
+            mAccessibilityManager = (AccessibilityManager) context.getSystemService(
+                    Context.ACCESSIBILITY_SERVICE);
+        }
+
+        @Override
+        public boolean onHover(View v, MotionEvent event) {
+            // When touch exploration is turned on, lifting a finger while
+            // inside the view bounds should perform a click action.
+            if (mAccessibilityManager.isEnabled()
+                    && mAccessibilityManager.isTouchExplorationEnabled()) {
+                switch (event.getActionMasked()) {
+                    case MotionEvent.ACTION_HOVER_ENTER:
+                        // Lift-to-type temporarily disables double-tap
+                        // activation.
+                        v.setClickable(false);
+                        break;
+                    case MotionEvent.ACTION_HOVER_EXIT:
+                        final int x = (int) event.getX();
+                        final int y = (int) event.getY();
+                        if ((x > v.getPaddingLeft()) && (y > v.getPaddingTop())
+                                && (x < v.getWidth() - v.getPaddingRight())
+                                && (y < v.getHeight() - v.getPaddingBottom())) {
+                            v.performClick();
+                        }
+                        v.setClickable(true);
+                        break;
+                }
+            }
+            return false;
+        }
+    }
 }