致命异常:java.lang.NullPointerException 尝试在空对象引用上调用接口方法'void android.inputmethodservice.KeyboardView $ OnKeyboardActionListener.onPress(int)'
覆盖'android.inputmethodservice.KeyboardView.OnKeyboardActionListener中不推荐使用的方法
什么是该课程的替代品?
这是我的代码
public class SoftKeyboard extends InputMethodService implements ActivityCompat.OnRequestPermissionsResultCallback, OnKeyboardActionListener, RecognitionListener{
public void onRelease(int i) {
}
public void swipeRight() {
}
public void swipeUp() {
}
public void swipeLeft() {
handleBackspace();
}
public void swipeDown() {
handleClose();
}
public void onText(CharSequence charSequence) {
InputConnection currentInputConnection = getCurrentInputConnection();
if (currentInputConnection != null) {
currentInputConnection.beginBatchEdit();
if (this.mComposing.length() > 0) {
commitTyped(currentInputConnection);
}
currentInputConnection.commitText(charSequence, 0);
currentInputConnection.endBatchEdit();
updateShiftKeyState(getCurrentInputEditorInfo());
}
}
public void onPress(int i) {
try {
if (mInputView!=null){
for (Key key : this.mInputView.getKeyboard().getKeys()) {
if (key.codes[0] == i) {
if (key.modifier) {
this.mInputView.setPreviewEnabled(false);
} else if (KeyboardState.phoneKeyboard == this.mInputView.getKeyboard()) {
this.mInputView.setPreviewEnabled(false);
} else {
this.mInputView.setPreviewEnabled(this.sessionManager.getPopup().booleanValue());
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
public void onKey(int i, int[] iArr) {
sound_vibrate();
if (isWordSeparator(i)) {
if (this.mComposing.length() > 0) {
commitTyped(getCurrentInputConnection());
}
sendKey(i);
updateShiftKeyState(getCurrentInputEditorInfo());
} else if (i == -5) {
handleBackspace();
} else if (i == -1) {
handleShift();
} else if (i == -3) {
handleClose();
return;
} else if (i != -100) {
if (i == -2 && this.mInputView != null) {
Keyboard keyboard = this.mInputView.getKeyboard();
if ((keyboard == this.mSymbolsKeyboard || keyboard == this.mSymbolsShiftedKeyboard) && keyboard != this.mHindiSymbolsKeyboard) {
if (Preference.getLangSelect().equals("English")) {
setLatinKeyboard(this.mQwertyKeyboard);
this.tv_text.setVisibility(View.VISIBLE);
this.btnTransliteration.setVisibility(View.VISIBLE);
if (this.sessionManager.getTransliteration().booleanValue()) {
this.isEnabled = true;
} else {
this.isEnabled = false;
}
} else {
setLatinKeyboard(this.mOtherKeyboard);
this.tv_text.setVisibility(View.GONE);
this.btnTransliteration.setVisibility(View.GONE);
ll_transliteration.setVisibility(View.GONE);
}
} else if ((keyboard == this.mHindiSymbolsKeyboard || keyboard == this.mHindiSymbolsShiftedKeyboard) && keyboard != this.mSymbolsKeyboard) {
setLatinKeyboard(this.mOtherKeyboard);
this.tv_text.setVisibility(View.GONE);//Gone
this.btnTransliteration.setVisibility(View.GONE);//Gone
this.isEnabled = false;
} else if (keyboard == this.mOtherKeyboard || keyboard == this.mOtherShiftedKeyboard) {
setLatinKeyboard(this.mHindiSymbolsKeyboard);
this.mHindiSymbolsKeyboard.setShifted(false);
this.tv_text.setVisibility(View.GONE);//Gone
this.btnTransliteration.setVisibility(View.GONE);//Gone
this.isEnabled = false;
} else {
this.tv_text.setVisibility(View.VISIBLE);//Gone
this.btnTransliteration.setVisibility(View.VISIBLE);//Gone
this.isEnabled = false;
setLatinKeyboard(this.mSymbolsKeyboard);
this.mSymbolsKeyboard.setShifted(false);
}
updateShiftIcon();
} else if (i != -10000) {
if (i == -10001) {
this.mComposing.append("");
getCurrentInputConnection().setComposingText(this.mComposing, 1);
} else if (i == -10002) {
this.mComposing.append("ẋ");
getCurrentInputConnection().setComposingText(this.mComposing, 1);
} else if (i == -10003) {
this.mComposing.append("Ẋ");
getCurrentInputConnection().setComposingText(this.mComposing, 1);
} else if (i == 1567) {
this.mComposing.append("؟");
getCurrentInputConnection().setComposingText(this.mComposing, 1);
} else {
handleCharacter(i, iArr);
}
} else if (i == -10000) {
btnEmoji.performClick();
}
}
if (!this.sessionManager.getTransliteration().booleanValue() || !this.isEnabled) {
this.word = "";
this.numberOfChracters = 1;
} else if (i == 32) {
ll_suggessions.removeAllViews();
sv_suggessions.setVisibility(View.GONE);
ll_transliteration.setVisibility(View.VISIBLE);
btnSwitchLanguage.setVisibility(View.VISIBLE);
btnSettings.setVisibility(View.VISIBLE);
hScrollView.fullScroll(HorizontalScrollView.FOCUS_LEFT);
if (Helper.isNetworkAvailable(getApplicationContext())) {
try {
if (stringArrayList.size() > 0) {
loadFirstWord(FirstWord);
} else {
loadRequest(this.word);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (this.word.toLowerCase().equals("") || this.word.toLowerCase().equals(null)) {
getCurrentInputConnection().deleteSurroundingText(this.numberOfChracters, 0);
getCurrentInputConnection().setComposingText(" ", 1);
getCurrentInputConnection().finishComposingText();
this.word = "";
this.numberOfChracters = 1;
} else {
String sinlgeEntry = this.dataBaseAdapter.getSinlgeEntry(this.word.toLowerCase());
getCurrentInputConnection().deleteSurroundingText(this.numberOfChracters, 0);
InputConnection currentInputConnection = getCurrentInputConnection();
StringBuilder sb = new StringBuilder();
sb.append(sinlgeEntry);
sb.append(" ");
Log.d("CheckGetStrin", sb.toString());
currentInputConnection.setComposingText(sb.toString(), 1);
getCurrentInputConnection().finishComposingText();
this.word = "";
this.numberOfChracters = 1;
}
}
}
}