1
我目前正在自己的實現Input Method Editor (IME)
或可以在Android中調用Softkeyboard
我已閱讀creating an input method我已經下載the SoftKeyboard sample code provided as part of the SDK
。我有以下代碼sample Softkeyboard:如何通過按Shift鍵更改android的鍵盤佈局
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);
}
}
現在我沒有任何想法如何擺脫上述異常,並得到我的代碼工作。請解決這個問題!