-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: makeup a universal TouchEventReceiverWindow
- Loading branch information
1 parent
3346d9c
commit c32c297
Showing
3 changed files
with
59 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/osfans/trime/ime/core/TouchEventReceiverWindow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2015 - 2025 Rime community | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package com.osfans.trime.ime.core | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.Gravity | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import android.widget.PopupWindow | ||
|
||
class TouchEventReceiverWindow( | ||
private val contentView: View, | ||
) { | ||
private val ctx = contentView.context | ||
|
||
private val window = | ||
PopupWindow( | ||
object : View(ctx) { | ||
@SuppressLint("ClickableViewAccessibility") | ||
override fun onTouchEvent(event: MotionEvent): Boolean = contentView.dispatchTouchEvent(event) | ||
}, | ||
) | ||
|
||
private var isWindowShowing = false | ||
|
||
fun showup() { | ||
isWindowShowing = true | ||
val location = intArrayOf(0, 0) | ||
contentView.getLocationInWindow(location) | ||
val (left, top) = location | ||
val width = contentView.width | ||
val height = contentView.height | ||
if (window.isShowing) { | ||
window.update(left, top, width, height) | ||
} else { | ||
window.width = width | ||
window.height = height | ||
window.showAtLocation(contentView, Gravity.NO_GRAVITY, left, top) | ||
} | ||
} | ||
|
||
fun dismiss() { | ||
if (isWindowShowing) { | ||
isWindowShowing = false | ||
window.dismiss() | ||
} | ||
} | ||
} |