Search in sources :

Example 16 with Key

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

the class DynamicGridKeyboard method loadRecentKeys.

public void loadRecentKeys(final Collection<DynamicGridKeyboard> keyboards) {
    final String str = Settings.readEmojiRecentKeys(mPrefs);
    final List<Object> keys = JsonUtils.jsonStrToList(str);
    for (final Object o : keys) {
        final Key key;
        if (o instanceof Integer) {
            final int code = (Integer) o;
            key = getKeyByCode(keyboards, code);
        } else if (o instanceof String) {
            final String outputText = (String) o;
            key = getKeyByOutputText(keyboards, outputText);
        } else {
            Log.w(TAG, "Invalid object: " + o);
            continue;
        }
        addKeyLast(key);
    }
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 17 with Key

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

the class EmojiCategory method sortKeysIntoPages.

private static Key[][] sortKeysIntoPages(final List<Key> inKeys, final int maxPageCount) {
    final ArrayList<Key> keys = new ArrayList<>(inKeys);
    Collections.sort(keys, EMOJI_KEY_COMPARATOR);
    final int pageCount = (keys.size() - 1) / maxPageCount + 1;
    final Key[][] retval = new Key[pageCount][maxPageCount];
    for (int i = 0; i < keys.size(); ++i) {
        retval[i / maxPageCount][i % maxPageCount] = keys.get(i);
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) Key(com.android.inputmethod.keyboard.Key) Paint(android.graphics.Paint)

Example 18 with Key

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

the class EmojiPageKeyboardView method onDown.

@Override
public boolean onDown(final MotionEvent e) {
    final Key key = getKey(e);
    releaseCurrentKey(false);
    mCurrentKey = key;
    if (key == null) {
        return false;
    }
    // Do not trigger key-down effect right now in case this is actually a fling action.
    mPendingKeyDown = new Runnable() {

        @Override
        public void run() {
            callListenerOnPressKey(key);
        }
    };
    mHandler.postDelayed(mPendingKeyDown, KEY_PRESS_DELAY_TIME);
    return false;
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 19 with Key

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

the class EmojiPageKeyboardView method releaseCurrentKey.

public void releaseCurrentKey(final boolean withKeyRegistering) {
    mHandler.removeCallbacks(mPendingKeyDown);
    mPendingKeyDown = null;
    final Key currentKey = mCurrentKey;
    if (currentKey == null) {
        return;
    }
    callListenerOnReleaseKey(currentKey, withKeyRegistering);
    mCurrentKey = null;
}
Also used : Key(com.android.inputmethod.keyboard.Key)

Example 20 with Key

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

the class ActualKeyboardBuilder method buildKeyboard.

/**
     * Create the keyboard that consists of the array of rows of the actual keyboard's keys.
     * @param sortedKeys keys list of the actual keyboard that is sorted from top-left to
     * bottom-right.
     * @return the actual keyboard grouped with rows.
     */
public static Key[][] buildKeyboard(final List<Key> sortedKeys) {
    // Filter out spacer to prepare to create rows.
    final ArrayList<Key> filteredSortedKeys = filterOutSpacer(sortedKeys);
    // Grouping keys into rows.
    final ArrayList<ArrayList<Key>> rows = new ArrayList<>();
    ArrayList<Key> elements = new ArrayList<>();
    int lastY = filteredSortedKeys.get(0).getY();
    for (final Key key : filteredSortedKeys) {
        if (lastY != key.getY()) {
            // A new row is starting.
            lastY = key.getY();
            rows.add(elements);
            elements = new ArrayList<>();
        }
        elements.add(key);
    }
    // Add the last row.
    rows.add(elements);
    // Calculate each dimension of rows and create a builder.
    final int[] dimensions = new int[rows.size()];
    for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) {
        dimensions[rowIndex] = rows.get(rowIndex).size();
    }
    final ActualKeyboardBuilder builder = new ActualKeyboardBuilder();
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
        final int row = rowIndex + 1;
        final ArrayList<Key> rowKeys = rows.get(rowIndex);
        builder.setRowAt(row, rowKeys.toArray(new Key[rowKeys.size()]));
    }
    return builder.build();
}
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