Search in sources :

Example 6 with Key

use of android.inputmethodservice.Keyboard.Key in project XobotOS by xamarin.

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 7 with Key

use of android.inputmethodservice.Keyboard.Key in project XobotOS by xamarin.

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 8 with Key

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

the class KeyboardView method onBufferDraw.

private void onBufferDraw() {
    if (mBuffer == null || mKeyboardChanged) {
        if (mBuffer == null || mKeyboardChanged && (mBuffer.getWidth() != getWidth() || mBuffer.getHeight() != getHeight())) {
            // Make sure our bitmap is at least 1x1
            final int width = Math.max(1, getWidth());
            final int height = Math.max(1, getHeight());
            mBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCanvas = new Canvas(mBuffer);
        }
        invalidateAllKeys();
        mKeyboardChanged = false;
    }
    final Canvas canvas = mCanvas;
    canvas.clipRect(mDirtyRect, Op.REPLACE);
    if (mKeyboard == null)
        return;
    final Paint paint = mPaint;
    final Drawable keyBackground = mKeyBackground;
    final Rect clipRegion = mClipRegion;
    final Rect padding = mPadding;
    final int kbdPaddingLeft = mPaddingLeft;
    final int kbdPaddingTop = mPaddingTop;
    final Key[] keys = mKeys;
    final Key invalidKey = mInvalidatedKey;
    paint.setColor(mKeyTextColor);
    boolean drawSingleKey = false;
    if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
        // Is clipRegion completely contained within the invalidated key?
        if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
            drawSingleKey = true;
        }
    }
    canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
    final int keyCount = keys.length;
    for (int i = 0; i < keyCount; i++) {
        final Key key = keys[i];
        if (drawSingleKey && invalidKey != key) {
            continue;
        }
        int[] drawableState = key.getCurrentDrawableState();
        keyBackground.setState(drawableState);
        // Switch the character to uppercase if shift is pressed
        String label = key.label == null ? null : adjustCase(key.label).toString();
        final Rect bounds = keyBackground.getBounds();
        if (key.width != bounds.right || key.height != bounds.bottom) {
            keyBackground.setBounds(0, 0, key.width, key.height);
        }
        canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
        keyBackground.draw(canvas);
        if (label != null) {
            // For characters, use large font. For labels like "Done", use small font.
            if (label.length() > 1 && key.codes.length < 2) {
                paint.setTextSize(mLabelTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
            } else {
                paint.setTextSize(mKeyTextSize);
                paint.setTypeface(Typeface.DEFAULT);
            }
            // Draw a drop shadow for the text
            paint.setShadowLayer(mShadowRadius, 0, 0, mShadowColor);
            // Draw the text
            canvas.drawText(label, (key.width - padding.left - padding.right) / 2 + padding.left, (key.height - padding.top - padding.bottom) / 2 + (paint.getTextSize() - paint.descent()) / 2 + padding.top, paint);
            // Turn off drop shadow
            paint.setShadowLayer(0, 0, 0, 0);
        } else if (key.icon != null) {
            final int drawableX = (key.width - padding.left - padding.right - key.icon.getIntrinsicWidth()) / 2 + padding.left;
            final int drawableY = (key.height - padding.top - padding.bottom - key.icon.getIntrinsicHeight()) / 2 + padding.top;
            canvas.translate(drawableX, drawableY);
            key.icon.setBounds(0, 0, key.icon.getIntrinsicWidth(), key.icon.getIntrinsicHeight());
            key.icon.draw(canvas);
            canvas.translate(-drawableX, -drawableY);
        }
        canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
    }
    mInvalidatedKey = null;
    // Overlay a dark rectangle to dim the keyboard
    if (mMiniKeyboardOnScreen) {
        paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
    }
    if (DEBUG && mShowTouchPoints) {
        paint.setAlpha(128);
        paint.setColor(0xFFFF0000);
        canvas.drawCircle(mStartX, mStartY, 3, paint);
        canvas.drawLine(mStartX, mStartY, mLastX, mLastY, paint);
        paint.setColor(0xFF0000FF);
        canvas.drawCircle(mLastX, mLastY, 3, paint);
        paint.setColor(0xFF00FF00);
        canvas.drawCircle((mStartX + mLastX) / 2, (mStartY + mLastY) / 2, 2, paint);
    }
    mDrawPending = false;
    mDirtyRect.setEmpty();
}
Also used : Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint) Key(android.inputmethodservice.Keyboard.Key)

Example 9 with Key

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

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 10 with Key

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

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)

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