Search in sources :

Example 16 with Key

use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ResurrectionRemix.

the class KeyboardView method showPreview.

private void showPreview(int keyIndex) {
    int oldKeyIndex = mCurrentKeyIndex;
    final PopupWindow previewPopup = mPreviewPopup;
    mCurrentKeyIndex = keyIndex;
    // Release the old key and press the new key
    final Key[] keys = mKeys;
    if (oldKeyIndex != mCurrentKeyIndex) {
        if (oldKeyIndex != NOT_A_KEY && keys.length > oldKeyIndex) {
            Key oldKey = keys[oldKeyIndex];
            oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY);
            invalidateKey(oldKeyIndex);
            final int keyCode = oldKey.codes[0];
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, keyCode);
            // TODO: We need to implement AccessibilityNodeProvider for this view.
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, keyCode);
        }
        if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
            Key newKey = keys[mCurrentKeyIndex];
            newKey.onPressed();
            invalidateKey(mCurrentKeyIndex);
            final int keyCode = newKey.codes[0];
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, keyCode);
            // TODO: We need to implement AccessibilityNodeProvider for this view.
            sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, keyCode);
        }
    }
    // If key changed and preview is on ...
    if (oldKeyIndex != mCurrentKeyIndex && mShowPreview) {
        mHandler.removeMessages(MSG_SHOW_PREVIEW);
        if (previewPopup.isShowing()) {
            if (keyIndex == NOT_A_KEY) {
                mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_REMOVE_PREVIEW), DELAY_AFTER_PREVIEW);
            }
        }
        if (keyIndex != NOT_A_KEY) {
            if (previewPopup.isShowing() && mPreviewText.getVisibility() == VISIBLE) {
                // Show right away, if it's already visible and finger is moving around
                showKey(keyIndex);
            } else {
                mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SHOW_PREVIEW, keyIndex, 0), DELAY_BEFORE_PREVIEW);
            }
        }
    }
}
Also used : PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) Key(android.inputmethodservice.Keyboard.Key)

Example 17 with Key

use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ResurrectionRemix.

the class KeyboardView method detectAndSendKey.

private void detectAndSendKey(int index, int x, int y, long eventTime) {
    if (index != NOT_A_KEY && index < mKeys.length) {
        final Key key = mKeys[index];
        if (key.text != null) {
            mKeyboardActionListener.onText(key.text);
            mKeyboardActionListener.onRelease(NOT_A_KEY);
        } else {
            int code = key.codes[0];
            //TextEntryState.keyPressedAt(key, x, y);
            int[] codes = new int[MAX_NEARBY_KEYS];
            Arrays.fill(codes, NOT_A_KEY);
            getKeyIndices(x, y, codes);
            // Multi-tap
            if (mInMultiTap) {
                if (mTapCount != -1) {
                    mKeyboardActionListener.onKey(Keyboard.KEYCODE_DELETE, KEY_DELETE);
                } else {
                    mTapCount = 0;
                }
                code = key.codes[mTapCount];
            }
            mKeyboardActionListener.onKey(code, codes);
            mKeyboardActionListener.onRelease(code);
        }
        mLastSentIndex = index;
        mLastTapTime = eventTime;
    }
}
Also used : Key(android.inputmethodservice.Keyboard.Key) Paint(android.graphics.Paint)

Example 18 with Key

use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by ResurrectionRemix.

the class KeyboardView method computeProximityThreshold.

/**
     * Compute the average distance between adjacent keys (horizontally and vertically)
     * and square it to get the proximity threshold. We use a square here and in computing
     * the touch distance from a key's center to avoid taking a square root.
     * @param keyboard
     */
private void computeProximityThreshold(Keyboard keyboard) {
    if (keyboard == null)
        return;
    final Key[] keys = mKeys;
    if (keys == null)
        return;
    int length = keys.length;
    int dimensionSum = 0;
    for (int i = 0; i < length; i++) {
        Key key = keys[i];
        dimensionSum += Math.min(key.width, key.height) + key.gap;
    }
    if (dimensionSum < 0 || length == 0)
        return;
    mProximityThreshold = (int) (dimensionSum * 1.4f / length);
    // Square it
    mProximityThreshold *= mProximityThreshold;
}
Also used : Key(android.inputmethodservice.Keyboard.Key) Paint(android.graphics.Paint)

Example 19 with Key

use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by crdroidandroid.

the class KeyboardView method showKey.

private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length)
        return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = -mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    // Offset may be zero
    mCoordinates[0] += mMiniKeyboardOffsetX;
    // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY;
    // Set the preview background state
    mPreviewText.getBackground().setState(key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];
    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }
    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY, popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY, mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) PopupWindow(android.widget.PopupWindow) Key(android.inputmethodservice.Keyboard.Key) Paint(android.graphics.Paint)

Example 20 with Key

use of android.inputmethodservice.Keyboard.Key in project android_frameworks_base by crdroidandroid.

the class KeyboardView method openPopupIfRequired.

private boolean openPopupIfRequired(MotionEvent me) {
    // Check if we have a popup layout specified first.
    if (mPopupLayout == 0) {
        return false;
    }
    if (mCurrentKey < 0 || mCurrentKey >= mKeys.length) {
        return false;
    }
    Key popupKey = mKeys[mCurrentKey];
    boolean result = onLongPress(popupKey);
    if (result) {
        mAbortKey = true;
        showPreview(NOT_A_KEY);
    }
    return result;
}
Also used : Key(android.inputmethodservice.Keyboard.Key)

Aggregations

Key (android.inputmethodservice.Keyboard.Key)63 Paint (android.graphics.Paint)42 PopupWindow (android.widget.PopupWindow)14 Canvas (android.graphics.Canvas)7 Rect (android.graphics.Rect)7 Drawable (android.graphics.drawable.Drawable)7 LayoutParams (android.view.ViewGroup.LayoutParams)7