|
88 | 88 | import java.util.Locale; |
89 | 89 | import java.util.Objects; |
90 | 90 | import java.util.concurrent.CopyOnWriteArrayList; |
| 91 | +import splitties.bitflags.BitFlagsKt; |
91 | 92 | import splitties.systemservices.SystemServicesKt; |
92 | 93 | import timber.log.Timber; |
93 | 94 |
|
@@ -121,6 +122,8 @@ public Config getImeConfig() { |
121 | 122 | public InputFeedbackManager inputFeedbackManager = null; // 效果管理器 |
122 | 123 | private IntentReceiver mIntentReceiver = null; |
123 | 124 |
|
| 125 | + public EditorInfo editorInfo = null; |
| 126 | + |
124 | 127 | private boolean isWindowShown = false; // 键盘窗口是否已显示 |
125 | 128 |
|
126 | 129 | private boolean isAutoCaps; // 句首自動大寫 |
@@ -606,6 +609,35 @@ public void onDestroy() { |
606 | 609 | self = null; |
607 | 610 | } |
608 | 611 |
|
| 612 | + private void handleReturnKey() { |
| 613 | + if (editorInfo == null) sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); |
| 614 | + if ((editorInfo.inputType & InputType.TYPE_MASK_CLASS) == InputType.TYPE_NULL) { |
| 615 | + sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); |
| 616 | + } |
| 617 | + if (BitFlagsKt.hasFlag(editorInfo.imeOptions, EditorInfo.IME_FLAG_NO_ENTER_ACTION)) { |
| 618 | + final InputConnection ic = getCurrentInputConnection(); |
| 619 | + if (ic != null) ic.commitText("\n", 1); |
| 620 | + return; |
| 621 | + } |
| 622 | + if (!TextUtils.isEmpty(editorInfo.actionLabel) |
| 623 | + && editorInfo.actionId != EditorInfo.IME_ACTION_UNSPECIFIED) { |
| 624 | + final InputConnection ic = getCurrentInputConnection(); |
| 625 | + if (ic != null) ic.performEditorAction(editorInfo.actionId); |
| 626 | + return; |
| 627 | + } |
| 628 | + final int action = editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION; |
| 629 | + final InputConnection ic = getCurrentInputConnection(); |
| 630 | + switch (action) { |
| 631 | + case EditorInfo.IME_ACTION_UNSPECIFIED: |
| 632 | + case EditorInfo.IME_ACTION_NONE: |
| 633 | + if (ic != null) ic.commitText("\n", 1); |
| 634 | + break; |
| 635 | + default: |
| 636 | + if (ic != null) ic.performEditorAction(action); |
| 637 | + break; |
| 638 | + } |
| 639 | + } |
| 640 | + |
609 | 641 | @Override |
610 | 642 | public void onConfigurationChanged(@NonNull Configuration newConfig) { |
611 | 643 | final Configuration config = getResources().getConfiguration(); |
@@ -732,9 +764,16 @@ public void setShowComment(boolean show_comment) { |
732 | 764 | mComposition.setShowComment(show_comment); |
733 | 765 | } |
734 | 766 |
|
| 767 | + @Override |
| 768 | + public void onStartInput(EditorInfo attribute, boolean restarting) { |
| 769 | + editorInfo = attribute; |
| 770 | + Timber.d("onStartInput: restarting=%s", restarting); |
| 771 | + } |
| 772 | + |
735 | 773 | @Override |
736 | 774 | public void onStartInputView(EditorInfo attribute, boolean restarting) { |
737 | | - super.onStartInputView(attribute, restarting); |
| 775 | + Timber.d("onStartInputView: restarting=%s", restarting); |
| 776 | + editorInfo = attribute; |
738 | 777 | if (getPrefs().getThemeAndColor().getAutoDark()) { |
739 | 778 | int nightModeFlags = |
740 | 779 | getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; |
@@ -842,6 +881,12 @@ public void onFinishInputView(boolean finishingInput) { |
842 | 881 | } |
843 | 882 | } |
844 | 883 |
|
| 884 | + @Override |
| 885 | + public void onFinishInput() { |
| 886 | + editorInfo = null; |
| 887 | + super.onFinishInput(); |
| 888 | + } |
| 889 | + |
845 | 890 | public void bindKeyboardToInputView() { |
846 | 891 | if (mainKeyboardView != null) { |
847 | 892 | // Bind the selected keyboard to the input view. |
@@ -1224,11 +1269,7 @@ public void launchSettings() { |
1224 | 1269 | private boolean performEnter(int keyCode) { // 回車 |
1225 | 1270 | if (keyCode == KeyEvent.KEYCODE_ENTER) { |
1226 | 1271 | DraftHelper.INSTANCE.onInputEventChanged(); |
1227 | | - if (textInputManager.getPerformEnterAsLineBreak()) { |
1228 | | - commitText("\n"); |
1229 | | - } else { |
1230 | | - sendKeyChar('\n'); |
1231 | | - } |
| 1272 | + handleReturnKey(); |
1232 | 1273 | return true; |
1233 | 1274 | } |
1234 | 1275 | return false; |
|
0 commit comments