Skip to content

Commit

Permalink
fix: prevent NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
goofyz committed Dec 30, 2023
1 parent 0c971be commit ab36ded
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,14 @@ private void reset() {

/** Must be called on the UI thread */
public void initKeyboard() {
reset();
// setNavBarColor();
textInputManager.setShouldUpdateRimeOption(true); // 不能在Rime.onMessage中調用set_option,會卡死
bindKeyboardToInputView();
// loadBackground(); // reset()调用过resetCandidate(),resetCandidate()一键调用过loadBackground();
updateComposing(); // 切換主題時刷新候選
if (textInputManager != null) {
reset();
// setNavBarColor();
textInputManager.setShouldUpdateRimeOption(true); // 不能在Rime.onMessage中調用set_option,會卡死
bindKeyboardToInputView();
// loadBackground(); // reset()调用过resetCandidate(),resetCandidate()一键调用过loadBackground();
updateComposing(); // 切換主題時刷新候選
}
}

public void initKeyboardDarkMode(boolean darkMode) {
Expand Down Expand Up @@ -723,10 +725,6 @@ public void onUpdateSelection(
}
// Update the caps-lock status for the current cursor position.
dispatchCapsStateToInputView();

Timber.d(
"OnUpdateSelection: old: %d, %d, new: %d, %d, candidate: %d, %d",
oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);
}

@Override
Expand Down Expand Up @@ -987,6 +985,9 @@ public boolean onRimeKey(int[] event) {
}

private boolean composeEvent(@NonNull KeyEvent event) {
if (textInputManager == null) {
return false;
}
final int keyCode = event.getKeyCode();
if (keyCode == KeyEvent.KEYCODE_MENU) return false; // 不處理 Menu 鍵
if (!Keycode.Companion.isStdKey(keyCode)) return false; // 只處理安卓標準按鍵
Expand Down

0 comments on commit ab36ded

Please sign in to comment.