Skip to content

Commit 9a5d296

Browse files
nopdanWhiredPlanck
authored andcommitted
fix: 输入状态下切换深色模式时,悬浮窗无法关闭
1 parent 81258b3 commit 9a5d296

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

app/src/main/java/com/osfans/trime/ime/composition/CompositionPopupWindow.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ class CompositionPopupWindow(
8585
theme.generalStyle.layout.alpha,
8686
),
8787
)
88-
elevation = ctx.dp(theme.generalStyle.layout.elevation.toFloat())
88+
elevation =
89+
ctx.dp(
90+
theme.generalStyle.layout.elevation
91+
.toFloat(),
92+
)
8993
}
9094

9195
var isCursorUpdated = false // 光標是否移動
@@ -170,11 +174,12 @@ class CompositionPopupWindow(
170174
}
171175
}
172176

173-
fun isWinFixed(): Boolean {
174-
return Build.VERSION.SDK_INT <= VERSION_CODES.LOLLIPOP ||
175-
popupWindowPos !== PopupPosition.LEFT && popupWindowPos !== PopupPosition.RIGHT &&
176-
popupWindowPos !== PopupPosition.LEFT_UP && popupWindowPos !== PopupPosition.RIGHT_UP
177-
}
177+
fun isWinFixed(): Boolean =
178+
Build.VERSION.SDK_INT <= VERSION_CODES.LOLLIPOP ||
179+
popupWindowPos !== PopupPosition.LEFT &&
180+
popupWindowPos !== PopupPosition.RIGHT &&
181+
popupWindowPos !== PopupPosition.LEFT_UP &&
182+
popupWindowPos !== PopupPosition.RIGHT_UP
178183

179184
private fun updatePopupWindow(
180185
offsetX: Int,
@@ -195,7 +200,7 @@ class CompositionPopupWindow(
195200
}
196201
}
197202

198-
private fun hideCompositionView() {
203+
fun hideCompositionView() {
199204
mPopupWindow.dismiss()
200205
mPopupHandler.removeCallbacks(mPopupTimer)
201206
}

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
372372
override fun onConfigurationChanged(newConfig: Configuration) {
373373
super.onConfigurationChanged(newConfig)
374374
postRimeJob { clearComposition() }
375+
inputView?.composition?.hideCompositionView()
375376
ColorManager.onSystemNightModeChange(newConfig.isNightMode())
376377
}
377378

@@ -429,6 +430,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
429430
}
430431

431432
override fun onCreateInputView(): View {
433+
Timber.d("onCreateInputView")
432434
postRimeJob(Dispatchers.Main) {
433435
recreateInputView()
434436
}
@@ -438,7 +440,8 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
438440

439441
override fun setInputView(view: View) {
440442
val inputArea =
441-
window.window!!.decorView
443+
window.window!!
444+
.decorView
442445
.findViewById<FrameLayout>(android.R.id.inputArea)
443446
inputArea.updateLayoutParams<ViewGroup.LayoutParams> {
444447
height = ViewGroup.LayoutParams.MATCH_PARENT
@@ -541,7 +544,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
541544
} else if (attribute.packageName == BuildConfig.APPLICATION_ID ||
542545
prefs
543546
.clipboard
544-
.draftExcludeApp.trim().split('\n')
547+
.draftExcludeApp
548+
.trim()
549+
.split('\n')
545550
.contains(attribute.packageName)
546551
) {
547552
normalTextEditor = false
@@ -1170,13 +1175,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
11701175
}
11711176
}
11721177

1173-
fun addEventListener(listener: EventListener): Boolean {
1174-
return eventListeners.add(listener)
1175-
}
1178+
fun addEventListener(listener: EventListener): Boolean = eventListeners.add(listener)
11761179

1177-
fun removeEventListener(listener: EventListener): Boolean {
1178-
return eventListeners.remove(listener)
1179-
}
1180+
fun removeEventListener(listener: EventListener): Boolean = eventListeners.remove(listener)
11801181

11811182
interface EventListener {
11821183
fun onCreate() {}
@@ -1197,13 +1198,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
11971198
var self: TrimeInputMethodService? = null
11981199

11991200
@JvmStatic
1200-
fun getService(): TrimeInputMethodService {
1201-
return self ?: throw IllegalStateException("Trime not initialized")
1202-
}
1201+
fun getService(): TrimeInputMethodService = self ?: throw IllegalStateException("Trime not initialized")
12031202

1204-
fun getServiceOrNull(): TrimeInputMethodService? {
1205-
return self
1206-
}
1203+
fun getServiceOrNull(): TrimeInputMethodService? = self
12071204

12081205
private val syncBackgroundHandler =
12091206
Handler(

0 commit comments

Comments
 (0)