【发布时间】:2014-02-13 08:48:33
【问题描述】:
我目前正在自己实现Input Method Editor (IME) 或者在Android 中可以称为Softkeyboard,我已经阅读了creating an input method 并且我已经下载了the SoftKeyboard sample code provided as part of the SDK。我有来自sample Softkeyboard的以下代码:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
/**
* Swapping here with my desired unicode character
* */
if (primaryCode >= 97 && primaryCode <= 122 ) {
mComposing.append(Swap.swapLetters(primaryCode));
}else{
mComposing.append((char) primaryCode);
}
getCurrentInputConnection().setComposingText(mComposing, 1);
updateShiftKeyState(getCurrentInputEditorInfo());
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}
}
上面给出的代码可以正常工作,但是当我点击键时:
<Key android:codes="-1"
android:keyWidth="15%p" android:isModifier="true"
android:isSticky="true" android:keyEdgeFlags="left"/>
类似于Shift键,这会将键转换为大写我不知道如何显示我的下一个键这个键被点击/按下,以下是Logcat的异常:
我发现这可能发生在我们处理Shift 键的地方:
private void handleShift() {
if (mInputView == null) {
return;
}
Keyboard currentKeyboard = mInputView.getKeyboard();
if (mQwertyKeyboard == currentKeyboard) {
// Alphabet keyboard
checkToggleCapsLock();
mInputView.setKeyboard(mSindhi);
} else if (currentKeyboard == mSymbolsKeyboard) {
mSymbolsKeyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(true);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mSymbolsShiftedKeyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(false);
}
}
现在我不知道如何摆脱上述异常并让我的代码正常工作。请解决这个!
【问题讨论】:
标签: android android-softkeyboard android-input-method