Search in sources :

Example 21 with Key

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

the class KeyboardBuilder method parseGridRows.

private void parseGridRows(final XmlPullParser parser, final boolean skip) throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_GRID_ROWS, parser);
        if (DEBUG) {
            startEndTag("<%s /> skipped", TAG_GRID_ROWS);
        }
        return;
    }
    final KeyboardRow gridRows = new KeyboardRow(mResources, mParams, parser, mCurrentY);
    final TypedArray gridRowAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard_GridRows);
    final int codesArrayId = gridRowAttr.getResourceId(R.styleable.Keyboard_GridRows_codesArray, 0);
    final int textsArrayId = gridRowAttr.getResourceId(R.styleable.Keyboard_GridRows_textsArray, 0);
    gridRowAttr.recycle();
    if (codesArrayId == 0 && textsArrayId == 0) {
        throw new XmlParseUtils.ParseException("Missing codesArray or textsArray attributes", parser);
    }
    if (codesArrayId != 0 && textsArrayId != 0) {
        throw new XmlParseUtils.ParseException("Both codesArray and textsArray attributes specifed", parser);
    }
    final String[] array = mResources.getStringArray(codesArrayId != 0 ? codesArrayId : textsArrayId);
    final int counts = array.length;
    final float keyWidth = gridRows.getKeyWidth(null, 0.0f);
    final int numColumns = (int) (mParams.mOccupiedWidth / keyWidth);
    for (int index = 0; index < counts; index += numColumns) {
        final KeyboardRow row = new KeyboardRow(mResources, mParams, parser, mCurrentY);
        startRow(row);
        for (int c = 0; c < numColumns; c++) {
            final int i = index + c;
            if (i >= counts) {
                break;
            }
            final String label;
            final int code;
            final String outputText;
            final int supportedMinSdkVersion;
            if (codesArrayId != 0) {
                final String codeArraySpec = array[i];
                label = CodesArrayParser.parseLabel(codeArraySpec);
                code = CodesArrayParser.parseCode(codeArraySpec);
                outputText = CodesArrayParser.parseOutputText(codeArraySpec);
                supportedMinSdkVersion = CodesArrayParser.getMinSupportSdkVersion(codeArraySpec);
            } else {
                final String textArraySpec = array[i];
                // TODO: Utilize KeySpecParser or write more generic TextsArrayParser.
                label = textArraySpec;
                code = Constants.CODE_OUTPUT_TEXT;
                outputText = textArraySpec + (char) Constants.CODE_SPACE;
                supportedMinSdkVersion = 0;
            }
            if (Build.VERSION.SDK_INT < supportedMinSdkVersion) {
                continue;
            }
            final int labelFlags = row.getDefaultKeyLabelFlags();
            // TODO: Should be able to assign default keyActionFlags as well.
            final int backgroundType = row.getDefaultBackgroundType();
            final int x = (int) row.getKeyX(null);
            final int y = row.getKeyY();
            final int width = (int) keyWidth;
            final int height = row.getRowHeight();
            final Key key = new Key(label, KeyboardIconsSet.ICON_UNDEFINED, code, outputText, null, /* hintLabel */
            labelFlags, backgroundType, x, y, width, height, mParams.mHorizontalGap, mParams.mVerticalGap);
            endKey(key);
            row.advanceXPos(keyWidth);
        }
        endRow(row);
    }
    XmlParseUtils.checkEndTag(TAG_GRID_ROWS, parser);
}
Also used : TypedArray(android.content.res.TypedArray) ParseException(com.android.inputmethod.latin.utils.XmlParseUtils.ParseException) Key(com.android.inputmethod.keyboard.Key)

Example 22 with Key

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

the class KeyboardParams method onAddKey.

public void onAddKey(@Nonnull final Key newKey) {
    final Key key = mUniqueKeysCache.getUniqueKey(newKey);
    final boolean isSpacer = key.isSpacer();
    if (isSpacer && key.getWidth() == 0) {
        // Ignore zero width {@link Spacer}.
        return;
    }
    mSortedKeys.add(key);
    if (isSpacer) {
        return;
    }
    updateHistogram(key);
    if (key.getCode() == Constants.CODE_SHIFT) {
        mShiftKeys.add(key);
    }
    if (key.altCodeWhileTyping()) {
        mAltCodeKeysWhileTyping.add(key);
    }
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 23 with Key

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

the class TimerHandler method startLongPressTimerOf.

@Override
public void startLongPressTimerOf(@Nonnull final PointerTracker tracker, final int delay) {
    final Key key = tracker.getKey();
    if (key == null) {
        return;
    }
    // Use a separate message id for long pressing shift key, because long press shift key
    // timers should be canceled when other key is pressed.
    final int messageId = (key.getCode() == Constants.CODE_SHIFT) ? MSG_LONGPRESS_SHIFT_KEY : MSG_LONGPRESS_KEY;
    sendMessageDelayed(obtainMessage(messageId, tracker), delay);
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 24 with Key

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

the class TimerHandler method startKeyRepeatTimerOf.

@Override
public void startKeyRepeatTimerOf(@Nonnull final PointerTracker tracker, final int repeatCount, final int delay) {
    final Key key = tracker.getKey();
    if (key == null || delay == 0) {
        return;
    }
    sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.getCode(), repeatCount, tracker), delay);
}
Also used : 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