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);
}
}
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;
}
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;
}
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;
}
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();
}
Aggregations