Search in sources :

Example 11 with Key

use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class KeyboardAccessibilityDelegate method onHoverEnter.

/**
     * Process {@link MotionEvent#ACTION_HOVER_ENTER} event.
     *
     * @param event A hover enter event.
     */
protected void onHoverEnter(final MotionEvent event) {
    final Key key = getHoverKeyOf(event);
    if (DEBUG_HOVER) {
        Log.d(TAG, "onHoverEnter: key=" + key);
    }
    if (key != null) {
        onHoverEnterTo(key);
    }
    setLastHoverKey(key);
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 12 with Key

use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class KeyboardAccessibilityDelegate method onHoverExit.

/**
     * Process {@link MotionEvent#ACTION_HOVER_EXIT} event.
     *
     * @param event A hover exit event.
     */
protected void onHoverExit(final MotionEvent event) {
    final Key lastKey = getLastHoverKey();
    if (DEBUG_HOVER) {
        Log.d(TAG, "onHoverExit: key=" + getHoverKeyOf(event) + " last=" + lastKey);
    }
    if (lastKey != null) {
        onHoverExitFrom(lastKey);
    }
    final Key key = getHoverKeyOf(event);
    // off the keyboard area, then force a key press.
    if (key != null) {
        performClickOn(key);
        onHoverExitFrom(key);
    }
    setLastHoverKey(null);
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 13 with Key

use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class KeyboardAccessibilityNodeProvider method createAccessibilityNodeInfo.

/**
     * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
     * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
     * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}.
     * <p>
     * A virtual descendant is an imaginary View that is reported as a part of
     * the view hierarchy for accessibility purposes. This enables custom views
     * that draw complex content to report them selves as a tree of virtual
     * views, thus conveying their logical structure.
     * </p>
     * <p>
     * The implementer is responsible for obtaining an accessibility node info
     * from the pool of reusable instances and setting the desired properties of
     * the node info before returning it.
     * </p>
     *
     * @param virtualViewId A client defined virtual view id.
     * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host
     * View.
     * @see AccessibilityNodeInfoCompat
     */
@Override
public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) {
    if (virtualViewId == UNDEFINED) {
        return null;
    }
    if (virtualViewId == View.NO_ID) {
        // We are requested to create an AccessibilityNodeInfo describing
        // this View, i.e. the root of the virtual sub-tree.
        final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView);
        ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo);
        updateParentLocation();
        // Add the virtual children of the root View.
        final List<Key> sortedKeys = mKeyboard.getSortedKeys();
        final int size = sortedKeys.size();
        for (int index = 0; index < size; index++) {
            final Key key = sortedKeys.get(index);
            if (key.isSpacer()) {
                continue;
            }
            // Use an index of the sorted keys list as a virtual view id.
            rootInfo.addChild(mKeyboardView, index);
        }
        return rootInfo;
    }
    // Find the key that corresponds to the given virtual view id.
    final Key key = getKeyOf(virtualViewId);
    if (key == null) {
        Log.e(TAG, "Invalid virtual view ID: " + virtualViewId);
        return null;
    }
    final String keyDescription = getKeyDescription(key);
    final Rect boundsInParent = key.getHitBox();
    // Calculate the key's in-screen bounds.
    mTempBoundsInScreen.set(boundsInParent);
    mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation));
    final Rect boundsInScreen = mTempBoundsInScreen;
    // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view.
    final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain();
    info.setPackageName(mKeyboardView.getContext().getPackageName());
    info.setClassName(key.getClass().getName());
    info.setContentDescription(keyDescription);
    info.setBoundsInParent(boundsInParent);
    info.setBoundsInScreen(boundsInScreen);
    info.setParent(mKeyboardView);
    info.setSource(mKeyboardView, virtualViewId);
    info.setEnabled(key.isEnabled());
    info.setVisibleToUser(true);
    // See {@link #onHoverEnterTo(Key)} and {@link #onHoverExitFrom(Key)}.
    if (virtualViewId != mHoveringNodeId) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
        if (key.isLongPressEnabled()) {
            info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK);
        }
    }
    if (mAccessibilityFocusedView == virtualViewId) {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    } else {
        info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    }
    return info;
}
Also used : Rect(android.graphics.Rect) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) Key(com.android.inputmethod.keyboard.Key)

Example 14 with Key

use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class MoreKeysKeyboardAccessibilityDelegate method onHoverExit.

@Override
protected void onHoverExit(final MotionEvent event) {
    final Key lastKey = getLastHoverKey();
    if (DEBUG_HOVER) {
        Log.d(TAG, "onHoverExit: key=" + getHoverKeyOf(event) + " last=" + lastKey);
    }
    if (lastKey != null) {
        super.onHoverExitFrom(lastKey);
    }
    setLastHoverKey(null);
    final int actionIndex = event.getActionIndex();
    final int x = (int) event.getX(actionIndex);
    final int y = (int) event.getY(actionIndex);
    final int pointerId = event.getPointerId(actionIndex);
    final long eventTime = event.getEventTime();
    // A hover exit event at one pixel width or height area on the edges of more keys keyboard
    // are treated as closing.
    mMoreKeysKeyboardValidBounds.set(0, 0, mKeyboardView.getWidth(), mKeyboardView.getHeight());
    mMoreKeysKeyboardValidBounds.inset(CLOSING_INSET_IN_PIXEL, CLOSING_INSET_IN_PIXEL);
    if (mMoreKeysKeyboardValidBounds.contains(x, y)) {
        // Invoke {@link MoreKeysKeyboardView#onUpEvent(int,int,int,long)} as if this hover
        // exit event selects a key.
        mKeyboardView.onUpEvent(x, y, pointerId, eventTime);
        // TODO: Should fix this reference. This is a hack to clear the state of
        // {@link PointerTracker}.
        PointerTracker.dismissAllMoreKeysPanels();
        return;
    }
    // Close the more keys keyboard.
    // TODO: Should fix this reference. This is a hack to clear the state of
    // {@link PointerTracker}.
    PointerTracker.dismissAllMoreKeysPanels();
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 15 with Key

use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class DynamicGridKeyboard method saveRecentKeys.

private void saveRecentKeys() {
    final ArrayList<Object> keys = new ArrayList<>();
    for (final Key key : mGridKeys) {
        if (key.getOutputText() != null) {
            keys.add(key.getOutputText());
        } else {
            keys.add(key.getCode());
        }
    }
    final String jsonStr = JsonUtils.listToJsonStr(keys);
    Settings.writeEmojiRecentKeys(mPrefs, jsonStr);
}
Also used : ArrayList(java.util.ArrayList) Key(com.android.inputmethod.keyboard.Key)

Aggregations

Key (com.android.inputmethod.keyboard.Key)24 ArrayList (java.util.ArrayList)4 TypedArray (android.content.res.TypedArray)3 Keyboard (com.android.inputmethod.keyboard.Keyboard)3 Paint (android.graphics.Paint)2 ParseException (com.android.inputmethod.latin.utils.XmlParseUtils.ParseException)2 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1 AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)1 Event (com.android.inputmethod.event.Event)1 PointerTracker (com.android.inputmethod.keyboard.PointerTracker)1 ExpectedKey (com.android.inputmethod.keyboard.layout.expected.ExpectedKey)1 ExpectedAdditionalMoreKey (com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey)1