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