Skip to content

Commit 8fe8c71

Browse files
tumuyanBambooin
authored andcommitted
fix NullPointerException
# Conflicts: # app/src/main/java/com/osfans/trime/ime/core/Trime.java
1 parent 288573b commit 8fe8c71

File tree

1 file changed

+35
-28
lines changed
  • app/src/main/java/com/osfans/trime/ime/core

1 file changed

+35
-28
lines changed

app/src/main/java/com/osfans/trime/ime/core/Trime.java

+35-28
Original file line numberDiff line numberDiff line change
@@ -481,44 +481,49 @@ private void showCompositionView() {
481481
}
482482

483483
private void loadBackground() {
484-
final Config imeConfig = getImeConfig();
484+
final Config mConfig = getImeConfig();
485485
final int orientation = getResources().getConfiguration().orientation;
486-
final int[] padding =
487-
imeConfig.getKeyboardPadding(
488-
oneHandMode, orientation == Configuration.ORIENTATION_LANDSCAPE);
486+
487+
if (mPopupWindow != null) {
488+
final Drawable d =
489+
mConfig.getDrawable(
490+
"text_back_color",
491+
"layout/border",
492+
"border_color",
493+
"layout/round_corner",
494+
"layout/alpha");
495+
if (d != null) mPopupWindow.setBackgroundDrawable(d);
496+
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP)
497+
mPopupWindow.setElevation(mConfig.getPixel("layout/elevation"));
498+
}
499+
500+
if (mCandidateRoot != null) {
501+
final Drawable d2 =
502+
mConfig.getDrawable(
503+
"candidate_background",
504+
"candidate_border",
505+
"candidate_border_color",
506+
"candidate_border_round",
507+
null);
508+
if (d2 != null) mCandidateRoot.setBackground(d2);
509+
}
510+
511+
if (inputRootBinding == null) return;
512+
513+
int[] padding =
514+
mConfig.getKeyboardPadding(oneHandMode, orientation == Configuration.ORIENTATION_LANDSCAPE);
489515
Timber.i("padding= %s %s %s", padding[0], padding[1], padding[2]);
490516
mainKeyboardView.setPadding(padding[0], 0, padding[1], padding[2]);
491517

492-
final Drawable d =
493-
imeConfig.getDrawable(
494-
"text_back_color",
495-
"layout/border",
496-
"border_color",
497-
"layout/round_corner",
498-
"layout/alpha");
499-
if (d != null) mPopupWindow.setBackgroundDrawable(d);
500-
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP)
501-
mPopupWindow.setElevation(imeConfig.getPixel("layout/elevation"));
502-
503-
final Drawable d2 =
504-
imeConfig.getDrawable(
505-
"candidate_background",
506-
"candidate_border",
507-
"candidate_border_color",
508-
"candidate_border_round",
509-
null);
510-
511-
if (d2 != null) mCandidateRoot.setBackground(d2);
512-
513-
final Drawable d3 = imeConfig.getDrawable_("root_background");
518+
final Drawable d3 = mConfig.getDrawable_("root_background");
514519
if (d3 != null) {
515520
inputRootBinding.inputRoot.setBackground(d3);
516521
} else {
517522
// 避免因为键盘整体透明而造成的异常
518523
inputRootBinding.inputRoot.setBackgroundColor(Color.WHITE);
519524
}
520525

521-
tabView.reset(this);
526+
tabView.reset(self);
522527
}
523528

524529
public void resetKeyboard() {
@@ -543,6 +548,7 @@ public void resetCandidate() {
543548

544549
/** 重置鍵盤、候選條、狀態欄等 !!注意,如果其中調用Rime.setOption,切換方案會卡住 */
545550
private void reset() {
551+
if (inputRootBinding == null) return;
546552
getImeConfig().reset();
547553
loadConfig();
548554
getImeConfig().initCurrentColors();
@@ -1302,7 +1308,8 @@ private String getActiveText(int type) {
13021308

13031309
/** 更新Rime的中西文狀態、編輯區文本 */
13041310
public void updateComposing() {
1305-
final @Nullable InputConnection ic = getCurrentInputConnection();
1311+
final InputConnection ic = getCurrentInputConnection();
1312+
if (ic == null) return;
13061313
if (inlinePreedit != InlineModeType.INLINE_NONE) { // 嵌入模式
13071314
String s = "";
13081315
switch (inlinePreedit) {

0 commit comments

Comments
 (0)