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

Commit c7375afe authored by alanv's avatar alanv
Browse files

Fix keypad accessibility.

Add lift-to-type to the PIN keypad. Speak entered PIN digits. Add content
descriptions to PIN keypad buttons.

Bug: 7436382
Change-Id: I7cb3977cc769598c5f783221e1257b13e5e108c7
parent 3e31a0dc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:background="?android:attr/selectableItemBackground"
            android:contentDescription="@string/keyboardview_keycode_delete"
            />
    </LinearLayout>
    <View
@@ -196,6 +197,7 @@
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@drawable/sym_keyboard_return_holo"
            android:contentDescription="@string/keyboardview_keycode_enter"
            />
    </LinearLayout>

+3 −0
Original line number Diff line number Diff line
@@ -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) {
+1 −0
Original line number Diff line number Diff line
@@ -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,
+44 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
}