@@ -61,6 +61,7 @@ import org.fcitx.fcitx5.android.daemon.FcitxDaemon
61
61
import org.fcitx.fcitx5.android.data.InputFeedbacks
62
62
import org.fcitx.fcitx5.android.data.prefs.AppPrefs
63
63
import org.fcitx.fcitx5.android.data.prefs.ManagedPreference
64
+ import org.fcitx.fcitx5.android.data.prefs.ManagedPreferenceProvider
64
65
import org.fcitx.fcitx5.android.data.theme.Theme
65
66
import org.fcitx.fcitx5.android.data.theme.ThemeManager
66
67
import org.fcitx.fcitx5.android.data.theme.ThemePrefs.NavbarBackground
@@ -165,34 +166,44 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
165
166
}
166
167
}
167
168
168
- @Keep
169
- private val recreateInputViewListener = ManagedPreference .OnChangeListener <Any > { _, _ ->
170
- recreateInputView(ThemeManager .activeTheme)
171
- }
172
-
173
- @Keep
174
- private val onThemeChangeListener = ThemeManager .OnThemeChangeListener {
175
- recreateInputView(it)
169
+ private fun replaceInputView (theme : Theme ): InputView {
170
+ val newInputView = InputView (this , fcitx, theme)
171
+ setInputView(newInputView)
172
+ inputDeviceMgr.setInputView(newInputView)
173
+ inputView = newInputView
174
+ return newInputView
176
175
}
177
176
178
- private fun setupInputViews (theme : Theme ): InputView {
179
- evaluateNavbarUpdates()
180
- val newInputView = InputView (this , fcitx, theme)
177
+ private fun replaceCandidateView (theme : Theme ): CandidatesView {
181
178
val newCandidatesView = CandidatesView (this , fcitx, theme)
182
179
// replace CandidatesView manually
183
180
contentView.removeView(candidatesView)
184
181
// put CandidatesView directly under content view
185
182
contentView.addView(newCandidatesView)
186
- inputView = newInputView
183
+ inputDeviceMgr.setCandidatesView(newCandidatesView)
187
184
candidatesView = newCandidatesView
188
- inputDeviceMgr.setViews(newInputView, newCandidatesView)
189
- return newInputView
185
+ return newCandidatesView
190
186
}
191
187
192
- private fun recreateInputView (theme : Theme ) {
193
- // InputView should be first created in `onCreateInputView`
194
- // `setInputView` should only be used to 'replace' current InputView
195
- setInputView(setupInputViews(theme))
188
+ private fun replaceInputViews (theme : Theme ) {
189
+ evaluateNavbarUpdates()
190
+ replaceInputView(theme)
191
+ replaceCandidateView(theme)
192
+ }
193
+
194
+ @Keep
195
+ private val recreateInputViewListener = ManagedPreference .OnChangeListener <Any > { _, _ ->
196
+ replaceInputView(ThemeManager .activeTheme)
197
+ }
198
+
199
+ @Keep
200
+ private val recreateCandidatesViewListener = ManagedPreferenceProvider .OnChangeListener {
201
+ replaceCandidateView(ThemeManager .activeTheme)
202
+ }
203
+
204
+ @Keep
205
+ private val onThemeChangeListener = ThemeManager .OnThemeChangeListener {
206
+ replaceInputViews(it)
196
207
}
197
208
198
209
/* *
@@ -223,6 +234,7 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
223
234
pkgNameCache = PackageNameCache (this )
224
235
AppPrefs .getInstance().apply {
225
236
keyboard.expandKeypressArea.registerOnChangeListener(recreateInputViewListener)
237
+ candidates.registerOnChangeListener(recreateCandidatesViewListener)
226
238
advanced.disableAnimation.registerOnChangeListener(recreateInputViewListener)
227
239
}
228
240
ThemeManager .addOnChangedListener(onThemeChangeListener)
@@ -502,12 +514,10 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
502
514
}
503
515
}
504
516
505
- override fun onCreateInputView (): View {
506
- // onCreateInputView will be called once, when the input area is first displayed,
507
- // during each onConfigurationChanged period.
508
- // That is, onCreateInputView would be called again, after system dark mode changes,
509
- // or screen orientation changes.
510
- return setupInputViews(ThemeManager .activeTheme)
517
+ override fun onCreateInputView (): View ? {
518
+ replaceInputViews(ThemeManager .activeTheme)
519
+ // We will call `setInputView` by ourselves. This is fine.
520
+ return null
511
521
}
512
522
513
523
override fun setInputView (view : View ) {
@@ -535,20 +545,20 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
535
545
private var inputViewLocation = intArrayOf(0 , 0 )
536
546
537
547
override fun onComputeInsets (outInsets : Insets ) {
538
- if (candidatesView?.handleEvents == true ) {
548
+ if (inputDeviceMgr.isVirtualKeyboard) {
549
+ inputView?.keyboardView?.getLocationInWindow(inputViewLocation)
550
+ outInsets.apply {
551
+ contentTopInsets = inputViewLocation[1 ]
552
+ visibleTopInsets = inputViewLocation[1 ]
553
+ touchableInsets = Insets .TOUCHABLE_INSETS_VISIBLE
554
+ }
555
+ } else {
539
556
val h = decorView.height
540
557
outInsets.apply {
541
558
contentTopInsets = h
542
559
visibleTopInsets = h
543
560
touchableInsets = Insets .TOUCHABLE_INSETS_VISIBLE
544
561
}
545
- return
546
- }
547
- inputView?.keyboardView?.getLocationInWindow(inputViewLocation)
548
- outInsets.apply {
549
- contentTopInsets = inputViewLocation[1 ]
550
- visibleTopInsets = inputViewLocation[1 ]
551
- touchableInsets = Insets .TOUCHABLE_INSETS_VISIBLE
552
562
}
553
563
}
554
564
@@ -962,7 +972,7 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
962
972
963
973
@RequiresApi(Build .VERSION_CODES .R )
964
974
override fun onInlineSuggestionsResponse (response : InlineSuggestionsResponse ): Boolean {
965
- if (! inlineSuggestions || candidatesView?.handleEvents == true ) return false
975
+ if (! inlineSuggestions || ! inputDeviceMgr.isVirtualKeyboard ) return false
966
976
return inputView?.handleInlineSuggestions(response) == true
967
977
}
968
978
@@ -1001,6 +1011,7 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
1001
1011
override fun onDestroy () {
1002
1012
AppPrefs .getInstance().apply {
1003
1013
keyboard.expandKeypressArea.unregisterOnChangeListener(recreateInputViewListener)
1014
+ candidates.unregisterOnChangeListener(recreateCandidatesViewListener)
1004
1015
advanced.disableAnimation.unregisterOnChangeListener(recreateInputViewListener)
1005
1016
}
1006
1017
ThemeManager .removeOnChangedListener(onThemeChangeListener)
0 commit comments