Skip to content

Commit 4e9083c

Browse files
committed
fix flickering
1 parent 87528e8 commit 4e9083c

9 files changed

Lines changed: 307 additions & 7 deletions

File tree

app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/IMEService.kt

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
23572357
dispatchInkMotionEvent(
23582358
event = event,
23592359
sourceRoot = mainView.root,
2360-
targetContainer = mainView.keyboardBackgroundContainer,
2360+
targetContainer = mainView.keyboardTouchEffectContainer,
23612361
inkView = mainView.suminagashiInkView
23622362
)
23632363
}
@@ -2368,7 +2368,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
23682368
dispatchLiquidRippleMotionEvent(
23692369
event = event,
23702370
sourceRoot = mainView.root,
2371-
targetContainer = mainView.keyboardBackgroundContainer,
2371+
targetContainer = mainView.keyboardTouchEffectContainer,
23722372
rippleView = mainView.liquidRippleEffectView
23732373
)
23742374
}
@@ -2379,7 +2379,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
23792379
dispatchSprayPaintMotionEvent(
23802380
event = event,
23812381
sourceRoot = mainView.root,
2382-
targetContainer = mainView.keyboardBackgroundContainer,
2382+
targetContainer = mainView.keyboardTouchEffectContainer,
23832383
sprayView = mainView.sprayPaintEffectView
23842384
)
23852385
}
@@ -2455,7 +2455,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
24552455
dispatchInkMotionEvent(
24562456
event = event,
24572457
sourceRoot = floatingView.root,
2458-
targetContainer = floatingView.floatingKeyboardBackgroundContainer,
2458+
targetContainer = floatingView.floatingKeyboardTouchEffectContainer,
24592459
inkView = floatingView.floatingSuminagashiInkView
24602460
)
24612461
}
@@ -2466,7 +2466,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
24662466
dispatchLiquidRippleMotionEvent(
24672467
event = event,
24682468
sourceRoot = floatingView.root,
2469-
targetContainer = floatingView.floatingKeyboardBackgroundContainer,
2469+
targetContainer = floatingView.floatingKeyboardTouchEffectContainer,
24702470
rippleView = floatingView.floatingLiquidRippleEffectView
24712471
)
24722472
}
@@ -2477,7 +2477,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
24772477
dispatchSprayPaintMotionEvent(
24782478
event = event,
24792479
sourceRoot = floatingView.root,
2480-
targetContainer = floatingView.floatingKeyboardBackgroundContainer,
2480+
targetContainer = floatingView.floatingKeyboardTouchEffectContainer,
24812481
sprayView = floatingView.floatingSprayPaintEffectView
24822482
)
24832483
}
@@ -2772,8 +2772,10 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
27722772
)
27732773
applyHeight(floatingView.floatingKeyboardContent.height.takeIf { it > 0 } ?: fallbackHeight
27742774
?: 0)
2775+
updateFloatingKeyboardTouchEffectBounds(floatingView)
27752776
floatingView.root.post {
27762777
applyHeight(floatingView.floatingKeyboardContent.height)
2778+
updateFloatingKeyboardTouchEffectBounds(floatingView)
27772779
updateLuminousBlobEffectBounds(
27782780
blobView = floatingView.floatingLuminousBlobEffectView,
27792781
heightPx = resolveFloatingLuminousBlobKeyboardAreaHeight(
@@ -2784,6 +2786,62 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
27842786
}
27852787
}
27862788

2789+
private fun updateFloatingKeyboardTouchEffectBounds(
2790+
floatingView: FloatingKeyboardLayoutBinding
2791+
) {
2792+
val target = when {
2793+
floatingView.floatingSymbolKeyboard.isVisible -> floatingView.floatingSymbolKeyboard
2794+
floatingView.candidatesRowView.isVisible -> floatingView.candidatesRowView
2795+
else -> floatingView.floatingKeyboardContainer
2796+
}
2797+
2798+
fun applyBounds() {
2799+
if (target.width <= 0 || target.height <= 0) return
2800+
2801+
val rootLocation = IntArray(2)
2802+
val targetLocation = IntArray(2)
2803+
floatingView.root.getLocationInWindow(rootLocation)
2804+
target.getLocationInWindow(targetLocation)
2805+
2806+
val params =
2807+
floatingView.floatingKeyboardTouchEffectContainer.layoutParams as? FrameLayout.LayoutParams
2808+
?: return
2809+
var changed = false
2810+
val left = targetLocation[0] - rootLocation[0]
2811+
val top = targetLocation[1] - rootLocation[1]
2812+
2813+
if (params.width != target.width) {
2814+
params.width = target.width
2815+
changed = true
2816+
}
2817+
if (params.height != target.height) {
2818+
params.height = target.height
2819+
changed = true
2820+
}
2821+
if (params.leftMargin != left) {
2822+
params.leftMargin = left
2823+
changed = true
2824+
}
2825+
if (params.topMargin != top) {
2826+
params.topMargin = top
2827+
changed = true
2828+
}
2829+
2830+
val expectedGravity = Gravity.TOP or Gravity.START
2831+
if (params.gravity != expectedGravity) {
2832+
params.gravity = expectedGravity
2833+
changed = true
2834+
}
2835+
2836+
if (changed) {
2837+
floatingView.floatingKeyboardTouchEffectContainer.layoutParams = params
2838+
}
2839+
}
2840+
2841+
applyBounds()
2842+
floatingView.root.post { applyBounds() }
2843+
}
2844+
27872845
private fun updateLuminousBlobEffectBounds(
27882846
blobView: LuminousBlobEffectView,
27892847
heightPx: Int
@@ -4275,6 +4333,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
42754333
}
42764334
updateFloatingKeyboardBackgroundBounds(floatingKeyboardLayoutBinding, heightPx)
42774335
updateFloatingFullCandidatesHeight(floatingKeyboardLayoutBinding, heightPx)
4336+
updateFloatingKeyboardTouchEffectBounds(floatingKeyboardLayoutBinding)
42784337
}
42794338

42804339
keyboardContainer?.let { container ->
@@ -13282,6 +13341,7 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
1328213341
floatingKeyboardLayoutBinding.floatingSymbolKeyboard.isVisible = false
1328313342
renderCurrentKeyboardStateOnActiveSurface()
1328413343
}
13344+
updateFloatingKeyboardTouchEffectBounds(floatingKeyboardLayoutBinding)
1328513345
}
1328613346
} else {
1328713347
setKeyboardSizeForHeightSymbol(mainView, isSymbolKeyboardShow.isShown)
@@ -14410,6 +14470,31 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
1441014470
}
1441114471
}
1441214472

14473+
private fun updateNormalKeyboardTouchEffectBounds(
14474+
mainView: MainLayoutBinding,
14475+
keyboardBodyHeightPx: Int
14476+
) {
14477+
if (keyboardBodyHeightPx <= 0) return
14478+
14479+
val container = mainView.keyboardTouchEffectContainer
14480+
val params = container.layoutParams as? FrameLayout.LayoutParams ?: return
14481+
var changed = false
14482+
14483+
if (params.height != keyboardBodyHeightPx) {
14484+
params.height = keyboardBodyHeightPx
14485+
changed = true
14486+
}
14487+
14488+
if (params.gravity != Gravity.BOTTOM) {
14489+
params.gravity = Gravity.BOTTOM
14490+
changed = true
14491+
}
14492+
14493+
if (changed) {
14494+
container.layoutParams = params
14495+
}
14496+
}
14497+
1441314498
private fun applyKeyboardLayoutParameters(
1441414499
mainView: MainLayoutBinding,
1441514500
heightPx: Int,
@@ -14460,6 +14545,10 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
1446014545
mainView = mainView,
1446114546
heightPx = backgroundSurfaceHeight
1446214547
)
14548+
updateNormalKeyboardTouchEffectBounds(
14549+
mainView = mainView,
14550+
keyboardBodyHeightPx = heightPx
14551+
)
1446314552
updateLuminousBlobEffectBounds(
1446414553
blobView = mainView.luminousBlobEffectView,
1446514554
heightPx = heightPx
@@ -14633,6 +14722,10 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
1463314722
mainView = mainView,
1463414723
heightPx = backgroundSurfaceHeight
1463514724
)
14725+
updateNormalKeyboardTouchEffectBounds(
14726+
mainView = mainView,
14727+
keyboardBodyHeightPx = heightPx
14728+
)
1463614729
updateLuminousBlobEffectBounds(
1463714730
blobView = mainView.luminousBlobEffectView,
1463814731
heightPx = heightPx
@@ -14711,6 +14804,11 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
1471114804
floatingKeyboardLayoutBinding.suggestionVisibility.apply {
1471214805
this.setImageDrawable(if (isVisible) cachedArrowDropDownDrawable else cachedArrowDropUpDrawable)
1471314806
}
14807+
updateFloatingKeyboardTouchEffectBounds(floatingKeyboardLayoutBinding)
14808+
floatingKeyboardLayoutBinding.root.postDelayed(
14809+
{ updateFloatingKeyboardTouchEffectBounds(floatingKeyboardLayoutBinding) },
14810+
240L
14811+
)
1471414812
}
1471514813
}
1471614814
animateViewVisibility(mainView.candidatesRowView, !isVisible)
@@ -16917,7 +17015,10 @@ class IMEService : InputMethodService(), LifecycleOwner, InputConnection,
1691717015
if (keyboardSymbolViewState.value.isShown) {
1691817016
_keyboardSymbolViewState.value = SymbolKeyboardState()
1691917017
}
16920-
floatingKeyboardBinding?.floatingSymbolKeyboard?.isVisible = false
17018+
floatingKeyboardBinding?.let { floatingView ->
17019+
floatingView.floatingSymbolKeyboard.isVisible = false
17020+
updateFloatingKeyboardTouchEffectBounds(floatingView)
17021+
}
1692117022
}
1692217023

1692317024
private fun currentKeyboardLayoutEditOrientation(): KeyboardLayoutEditOrientation {

app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/image_effect/FluidInkRenderer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ internal class FluidInkRenderer(
102102

103103
override fun resizeSurface(width: Int, height: Int) {
104104
postOnRenderer {
105+
if (width <= 0 || height <= 0) return@postOnRenderer
106+
if (width == surfaceWidth && height == surfaceHeight) return@postOnRenderer
105107
if (released || egl == null || !settings.enabled) return@postOnRenderer
106108
runRendererCatching("resize fluid surface") {
107109
surfaceWidth = width

app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/image_effect/LiquidRippleRenderer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ internal class LiquidRippleRenderer(
101101

102102
override fun resizeSurface(width: Int, height: Int) {
103103
postOnRenderer {
104+
if (width <= 0 || height <= 0) return@postOnRenderer
105+
if (width == surfaceWidth && height == surfaceHeight) return@postOnRenderer
104106
if (released || egl == null || !settings.enabled) return@postOnRenderer
105107
runRendererCatching("resize liquid ripple surface") {
106108
surfaceWidth = width

app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/image_effect/SprayPaintRenderer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ internal class SprayPaintRenderer(
103103

104104
override fun resizeSurface(width: Int, height: Int) {
105105
postOnRenderer {
106+
if (width <= 0 || height <= 0) return@postOnRenderer
107+
if (width == surfaceWidth && height == surfaceHeight) return@postOnRenderer
106108
if (released || egl == null || !settings.enabled) return@postOnRenderer
107109
runRendererCatching("resize spray paint surface") {
108110
surfaceWidth = width

app/src/main/res/layout-land/main_layout.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
android:contentDescription="@null"
3232
android:scaleType="fitCenter"
3333
android:visibility="gone" />
34+
</FrameLayout>
35+
36+
<FrameLayout
37+
android:id="@+id/keyboard_touch_effect_container"
38+
android:layout_width="match_parent"
39+
android:layout_height="@dimen/keyboard_height"
40+
android:layout_gravity="bottom"
41+
android:clickable="false"
42+
android:focusable="false"
43+
android:importantForAccessibility="no">
3444

3545
<com.kazumaproject.markdownhelperkeyboard.ime_service.image_effect.SuminagashiInkView
3646
android:id="@+id/suminagashi_ink_view"

app/src/main/res/layout-sw600dp/main_layout.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
android:contentDescription="@null"
3232
android:scaleType="fitCenter"
3333
android:visibility="gone" />
34+
</FrameLayout>
35+
36+
<FrameLayout
37+
android:id="@+id/keyboard_touch_effect_container"
38+
android:layout_width="match_parent"
39+
android:layout_height="@dimen/keyboard_height"
40+
android:layout_gravity="bottom"
41+
android:clickable="false"
42+
android:focusable="false"
43+
android:importantForAccessibility="no">
3444

3545
<com.kazumaproject.markdownhelperkeyboard.ime_service.image_effect.SuminagashiInkView
3646
android:id="@+id/suminagashi_ink_view"

app/src/main/res/layout/floating_keyboard_layout.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
android:focusable="false"
3636
android:scaleType="fitCenter"
3737
android:visibility="gone" />
38+
</FrameLayout>
39+
40+
<FrameLayout
41+
android:id="@+id/floating_keyboard_touch_effect_container"
42+
android:layout_width="match_parent"
43+
android:layout_height="match_parent"
44+
android:clickable="false"
45+
android:focusable="false"
46+
android:importantForAccessibility="no">
3847

3948
<com.kazumaproject.markdownhelperkeyboard.ime_service.image_effect.SuminagashiInkView
4049
android:id="@+id/floating_suminagashi_ink_view"

app/src/main/res/layout/main_layout.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
android:contentDescription="@null"
3232
android:scaleType="fitCenter"
3333
android:visibility="gone" />
34+
</FrameLayout>
35+
36+
<FrameLayout
37+
android:id="@+id/keyboard_touch_effect_container"
38+
android:layout_width="match_parent"
39+
android:layout_height="@dimen/keyboard_height"
40+
android:layout_gravity="bottom"
41+
android:clickable="false"
42+
android:focusable="false"
43+
android:importantForAccessibility="no">
3444

3545
<com.kazumaproject.markdownhelperkeyboard.ime_service.image_effect.SuminagashiInkView
3646
android:id="@+id/suminagashi_ink_view"

0 commit comments

Comments
 (0)