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

Commit dcade181 authored by Alan Viverette's avatar Alan Viverette
Browse files

Added support for speaking keys through accessibility service.

Issue: 3366636

Change-Id: I70a2ebb4420782ba4d7d874ffc2259bb1b80446f
parent ededda05
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -28,4 +28,24 @@
    <integer name="key_delete">-5</integer>
    <integer name="key_settings">-100</integer>
    <integer name="key_voice">-102</integer>

    <!-- Array used for mapping key codes to description strings. -->
    <array name="key_descriptions">
        <item>@integer/key_tab</item>
        <item>@string/description_tab_key</item>
        <item>@integer/key_return</item>
        <item>@string/description_return_key</item>
        <item>@integer/key_space</item>
        <item>@string/description_space_key</item>
        <item>@integer/key_shift</item>
        <item>@string/description_shift_key</item>
        <item>@integer/key_switch_alpha_symbol</item>
        <item>@string/description_switch_alpha_symbol_key</item>
        <item>@integer/key_delete</item>
        <item>@string/description_delete_key</item>
        <item>@integer/key_settings</item>
        <item>@string/description_settings_key</item>
        <item>@integer/key_voice</item>
        <item>@string/description_voice_key</item>
    </array>
</resources>
+25 −0
Original line number Diff line number Diff line
@@ -102,6 +102,31 @@
    <!-- Label for "Wait" key of phone number keyboard.  Must be short to fit on key! [CHAR LIMIT=5]-->
    <string name="label_wait_key">Wait</string>

    <!-- Spoken text description for delete key. -->
    <string name="description_delete_key">Delete</string>
    <!-- Spoken text description for return key. -->
    <string name="description_return_key">Return</string>
    <!-- Spoken text description for settings key. -->
    <string name="description_settings_key">Settings</string>
    <!-- Spoken text description for shift key. -->
    <string name="description_shift_key">Shift</string>
    <!-- Spoken text description for space key. -->
    <string name="description_space_key">Space</string>
    <!-- Spoken text description for symbols key. -->
    <string name="description_switch_alpha_symbol_key">Symbols</string>
    <!-- Spoken text description for tab key. -->
    <string name="description_tab_key">Tab</string>
    <!-- Spoken text description for voice input key. -->
    <string name="description_voice_key">Voice Input</string>
    <!-- Spoken text description for symbols mode on. -->
    <string name="description_symbols_on">Symbols on</string>
    <!-- Spoken text description for symbols mode off. -->
    <string name="description_symbols_off">Symbols off</string>
    <!-- Spoken text description for shift mode on. -->
    <string name="description_shift_on">Shift on</string>
    <!-- Spoken text description for shift mode off. -->
    <string name="description_shift_off">Shift off</string>

    <!-- Voice related labels -->

    <!-- Title of the warning dialog that shows when a user initiates voice input for
+21 −1
Original line number Diff line number Diff line
@@ -336,7 +336,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
            // state when shift key is pressed to go to normal mode.
            // On the other hand, on distinct multi touch panel device, turning off the shift locked
            // state with shift key pressing is handled by onReleaseShift().
            if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) {
            if ((!hasDistinctMultitouch() || isAccessibilityEnabled())
                    && !shifted && latinKeyboard.isShiftLocked()) {
                latinKeyboard.setShiftLocked(false);
            }
            if (latinKeyboard.setShifted(shifted)) {
@@ -434,6 +435,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    public void onPressShift() {
        if (!isKeyboardAvailable())
            return;
        // If accessibility is enabled, disable momentary shift lock.
        if (isAccessibilityEnabled())
            return;
        ShiftKeyState shiftKeyState = mShiftKeyState;
        if (DEBUG_STATE)
            Log.d(TAG, "onPressShift:"
@@ -469,6 +473,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    public void onReleaseShift() {
        if (!isKeyboardAvailable())
            return;
        // If accessibility is enabled, disable momentary shift lock.
        if (isAccessibilityEnabled())
            return;
        ShiftKeyState shiftKeyState = mShiftKeyState;
        if (DEBUG_STATE)
            Log.d(TAG, "onReleaseShift:"
@@ -494,6 +501,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    }

    public void onPressSymbol() {
        // If accessibility is enabled, disable momentary symbol lock.
        if (isAccessibilityEnabled())
            return;
        if (DEBUG_STATE)
            Log.d(TAG, "onPressSymbol:"
                    + " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
@@ -504,6 +514,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    }

    public void onReleaseSymbol() {
        // If accessibility is enabled, disable momentary symbol lock.
        if (isAccessibilityEnabled())
            return;
        if (DEBUG_STATE)
            Log.d(TAG, "onReleaseSymbol:"
                    + " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
@@ -516,6 +529,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
    }

    public void onOtherKeyPressed() {
        // If accessibility is enabled, disable momentary mode locking.
        if (isAccessibilityEnabled())
            return;
        if (DEBUG_STATE)
            Log.d(TAG, "onOtherKeyPressed:"
                    + " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
@@ -574,6 +590,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
        }
    }

    public boolean isAccessibilityEnabled() {
        return mInputView != null && mInputView.isAccessibilityEnabled();
    }

    public boolean hasDistinctMultitouch() {
        return mInputView != null && mInputView.hasDistinctMultitouch();
    }
+34 −5
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
@@ -146,6 +147,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
    private final boolean mHasDistinctMultitouch;
    private int mOldPointerCount = 1;

    // Accessibility
    private boolean mIsAccessibilityEnabled;

    protected KeyDetector mKeyDetector = new ProximityKeyDetector();

    // Swipe gesture detector
@@ -523,7 +527,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
    }

    /**
     * Return whether the device has distinct multi-touch panel.
     * Returns whether the device has distinct multi-touch panel.
     * @return true if the device has distinct multi-touch panel.
     */
    @Override
@@ -531,6 +535,28 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
        return mHasDistinctMultitouch;
    }

    /**
     * Enables or disables accessibility.
     * @param accessibilityEnabled whether or not to enable accessibility
     */
    public void setAccessibilityEnabled(boolean accessibilityEnabled) {
        mIsAccessibilityEnabled = accessibilityEnabled;

        // Propagate this change to all existing pointer trackers.
        for (PointerTracker tracker : mPointerTrackers) {
            tracker.setAccessibilityEnabled(accessibilityEnabled);
        }
    }

    /**
     * Returns whether the device has accessibility enabled.
     * @return true if the device has accessibility enabled.
     */
    @Override
    public boolean isAccessibilityEnabled() {
        return mIsAccessibilityEnabled;
    }

    /**
     * Enables or disables the key feedback popup. This is a popup that shows a magnified
     * version of the depressed key. By default the preview is enabled.
@@ -1210,15 +1236,18 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
        // TODO: cleanup this code into a multi-touch to single-touch event converter class?
        // If the device does not have distinct multi-touch support panel, ignore all multi-touch
        // events except a transition from/to single-touch.
        if (!mHasDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) {
        if ((!mHasDistinctMultitouch || mIsAccessibilityEnabled)
                && pointerCount > 1 && oldPointerCount > 1) {
            return true;
        }

        // Track the last few movements to look for spurious swipes.
        mSwipeTracker.addMovement(me);

        // Gesture detector must be enabled only when mini-keyboard is not on the screen.
        if (mMiniKeyboardView == null
        // Gesture detector must be enabled only when mini-keyboard is not on the screen and
        // accessibility is not enabled.
        // TODO: Reconcile gesture detection and accessibility features.
        if (mMiniKeyboardView == null && !mIsAccessibilityEnabled
                && mGestureDetector != null && mGestureDetector.onTouchEvent(me)) {
            dismissKeyPreview();
            mHandler.cancelKeyTimers();
@@ -1263,7 +1292,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
        // TODO: cleanup this code into a multi-touch to single-touch event converter class?
        // Translate mutli-touch event to single-touch events on the device that has no distinct
        // multi-touch panel.
        if (!mHasDistinctMultitouch) {
        if (!mHasDistinctMultitouch || mIsAccessibilityEnabled) {
            // Use only main (id=0) pointer tracker.
            PointerTracker tracker = getPointerTracker(0);
            if (pointerCount == 1 && oldPointerCount == 2) {
+4 −0
Original line number Diff line number Diff line
@@ -145,6 +145,10 @@ public class LatinKeyboardView extends KeyboardView {
        // If device has distinct multi touch panel, there is no need to check sudden jump.
        if (hasDistinctMultitouch())
            return false;
        // If accessibiliy is enabled, stop looking for sudden jumps because it interferes
        // with touch exploration of the keyboard.
        if (isAccessibilityEnabled())
            return false;
        final int action = me.getAction();
        final int x = (int) me.getX();
        final int y = (int) me.getY();
Loading