-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I13a9e87b0c0ca804f6125515189337e673db1994
- Loading branch information
1 parent
029fc80
commit 73e00e2
Showing
5 changed files
with
104 additions
and
38 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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/org/lineageos/recorder/ext/InputMethodManager.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,44 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 The LineageOS Project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.lineageos.recorder.ext | ||
|
||
import android.view.View | ||
import android.view.inputmethod.InputMethodManager | ||
|
||
private const val SHOW_REQUEST_TIMEOUT = 1000 | ||
|
||
private fun InputMethodManager.scheduleShowSoftInput( | ||
view: View, | ||
flags: Int, | ||
runnable: Runnable, | ||
showRequestTime: Long, | ||
) { | ||
if (!view.hasFocus() | ||
|| (showRequestTime + SHOW_REQUEST_TIMEOUT) <= System.currentTimeMillis() | ||
) { | ||
return | ||
} | ||
|
||
if (showSoftInput(view, flags)) { | ||
return | ||
} else { | ||
view.removeCallbacks(runnable) | ||
view.postDelayed(runnable, 50) | ||
} | ||
} | ||
|
||
/** | ||
* @see InputMethodManager.showSoftInput | ||
*/ | ||
fun InputMethodManager.scheduleShowSoftInput(view: View, flags: Int) { | ||
val runnable = object : Runnable { | ||
override fun run() { | ||
scheduleShowSoftInput(view, flags, this, System.currentTimeMillis()) | ||
} | ||
} | ||
|
||
runnable.run() | ||
} |
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
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