use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class LayoutTestsBase method doKeyboardTests.
// Comparing expected keyboard and actual keyboard.
private void doKeyboardTests(final int elementId) {
final ExpectedKey[][] expectedKeyboard = mLayout.getLayout(isPhone(), elementId);
// Skip test if no keyboard is defined.
if (expectedKeyboard == null) {
return;
}
final String tag = mLogTag + "/" + KeyboardId.elementIdToName(elementId);
// Create actual keyboard object.
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(elementId);
// Create actual keyboard to be compared with the expected keyboard.
final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard(keyboard.getSortedKeys());
// Dump human readable definition of expected/actual keyboards.
Log.d(tag, "expected=\n" + ExpectedKeyboardBuilder.toString(expectedKeyboard));
Log.d(tag, "actual =\n" + ActualKeyboardBuilder.toString(actualKeyboard));
// Test both keyboards have the same number of rows.
assertEquals(tag + " labels" + "\nexpected=" + ExpectedKeyboardBuilder.toString(expectedKeyboard) + "\nactual =" + ActualKeyboardBuilder.toString(actualKeyboard), expectedKeyboard.length, actualKeyboard.length);
for (int r = 0; r < actualKeyboard.length; r++) {
final int row = r + 1;
// Test both keyboards' rows have the same number of columns.
assertEquals(tag + " labels row=" + row + "\nexpected=" + Arrays.toString(expectedKeyboard[r]) + "\nactual =" + ActualKeyboardBuilder.toString(actualKeyboard[r]), expectedKeyboard[r].length, actualKeyboard[r].length);
for (int c = 0; c < actualKeyboard[r].length; c++) {
final int column = c + 1;
final Key actualKey = actualKeyboard[r][c];
final ExpectedKey expectedKey = expectedKeyboard[r][c];
// Test both keyboards' keys have the same visual outlook and key output.
assertTrue(tag + " labels row,column=" + row + "," + column + "\nexpected=" + expectedKey + "\nactual =" + ActualKeyboardBuilder.toString(actualKey), expectedKey.equalsTo(actualKey));
}
}
}
use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class InputTestsBase method typeInternal.
// type(int) and type(String): helper methods to send a code point resp. a string to LatinIME.
protected void typeInternal(final int codePoint, final boolean isKeyRepeat) {
// onPressKey and onReleaseKey are explicitly deactivated here, but they do happen in the
// code (although multitouch/slide input and other factors make the sequencing complicated).
// They are supposed to be entirely deconnected from the input logic from LatinIME point of
// view and only delegates to the parts of the code that care. So we don't include them here
// to keep these tests as pinpoint as possible and avoid bringing it too many dependencies,
// but keep them in mind if something breaks. Commenting them out as is should work.
//mLatinIME.onPressKey(codePoint, 0 /* repeatCount */, true /* isSinglePointer */);
final Key key = mKeyboard.getKey(codePoint);
final Event event;
if (key == null) {
event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, isKeyRepeat);
} else {
final int x = key.getX() + key.getWidth() / 2;
final int y = key.getY() + key.getHeight() / 2;
event = LatinIME.createSoftwareKeypressEvent(codePoint, x, y, isKeyRepeat);
}
mLatinIME.onEvent(event);
// Also see the comment at the top of this function about onReleaseKey
//mLatinIME.onReleaseKey(codePoint, false /* withSliding */);
}
use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class ActionTestsBase method assertActionKey.
private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet, final int elementId, final ExpectedActionKey expectedKey) {
final Keyboard keyboard = layoutSet.getKeyboard(elementId);
final Key actualKey = keyboard.getKey(Constants.CODE_ENTER);
assertNotNull(tag + " enter key on " + keyboard.mId, actualKey);
assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel());
assertEquals(tag + " icon " + expectedKey, expectedKey.getIconId(), actualKey.getIconId());
}
use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class EmojiCategory method getKeyboard.
public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) {
synchronized (mCategoryKeyboardMap) {
final Long categoryKeyboardMapKey = getCategoryKeyboardMapKey(categoryId, id);
if (mCategoryKeyboardMap.containsKey(categoryKeyboardMapKey)) {
return mCategoryKeyboardMap.get(categoryKeyboardMapKey);
}
if (categoryId == EmojiCategory.ID_RECENTS) {
final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs, mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), mMaxPageKeyCount, categoryId);
mCategoryKeyboardMap.put(categoryKeyboardMapKey, kbd);
return kbd;
}
final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElementId[categoryId]);
final Key[][] sortedKeys = sortKeysIntoPages(keyboard.getSortedKeys(), mMaxPageKeyCount);
for (int pageId = 0; pageId < sortedKeys.length; ++pageId) {
final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs, mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), mMaxPageKeyCount, categoryId);
for (final Key emojiKey : sortedKeys[pageId]) {
if (emojiKey == null) {
break;
}
tempKeyboard.addKeyLast(emojiKey);
}
mCategoryKeyboardMap.put(getCategoryKeyboardMapKey(categoryId, pageId), tempKeyboard);
}
return mCategoryKeyboardMap.get(categoryKeyboardMapKey);
}
}
use of com.android.inputmethod.keyboard.Key in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class EmojiPageKeyboardView method onSingleTapUp.
@Override
public boolean onSingleTapUp(final MotionEvent e) {
final Key key = getKey(e);
final Runnable pendingKeyDown = mPendingKeyDown;
final Key currentKey = mCurrentKey;
releaseCurrentKey(false);
if (key == null) {
return false;
}
if (key == currentKey && pendingKeyDown != null) {
pendingKeyDown.run();
// Trigger key-release event a little later so that a user can see visual feedback.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
callListenerOnReleaseKey(key, true);
}
}, KEY_RELEASE_DELAY_TIME);
} else {
callListenerOnReleaseKey(key, true);
}
return true;
}
Aggregations