mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-20 08:50:25 +00:00
replace InputConnectionCompatUtils by API check
This commit is contained in:
parent
c7751423a1
commit
c007366966
2 changed files with 5 additions and 50 deletions
|
@ -1,47 +0,0 @@
|
||||||
package org.dslul.openboard.inputmethod.compat
|
|
||||||
|
|
||||||
import android.view.inputmethod.InputConnection
|
|
||||||
import org.dslul.openboard.inputmethod.compat.CompatUtils.ClassWrapper
|
|
||||||
import org.dslul.openboard.inputmethod.compat.CompatUtils.ToBooleanMethodWrapper
|
|
||||||
|
|
||||||
object InputConnectionCompatUtils {
|
|
||||||
private var sInputConnectionType: ClassWrapper? = null
|
|
||||||
private var sRequestCursorUpdatesMethod: ToBooleanMethodWrapper? = null
|
|
||||||
private val isRequestCursorUpdatesAvailable: Boolean
|
|
||||||
get() = sRequestCursorUpdatesMethod != null
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local copies of some constants in InputConnection until the SDK becomes publicly available.
|
|
||||||
*/
|
|
||||||
private const val CURSOR_UPDATE_IMMEDIATE = 1 shl 0
|
|
||||||
private const val CURSOR_UPDATE_MONITOR = 1 shl 1
|
|
||||||
private fun requestCursorUpdatesImpl(inputConnection: InputConnection,
|
|
||||||
cursorUpdateMode: Int): Boolean {
|
|
||||||
return if (!isRequestCursorUpdatesAvailable) {
|
|
||||||
false
|
|
||||||
} else sRequestCursorUpdatesMethod!!.invoke(inputConnection, cursorUpdateMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests the editor to call back [InputMethodManager.updateCursorAnchorInfo].
|
|
||||||
* @param inputConnection the input connection to which the request is to be sent.
|
|
||||||
* @param enableMonitor `true` to request the editor to call back the method whenever the
|
|
||||||
* cursor/anchor position is changed.
|
|
||||||
* @param requestImmediateCallback `true` to request the editor to call back the method
|
|
||||||
* as soon as possible to notify the current cursor/anchor position to the input method.
|
|
||||||
* @return `false` if the request is not handled. Otherwise returns `true`.
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun requestCursorUpdates(inputConnection: InputConnection,
|
|
||||||
enableMonitor: Boolean, requestImmediateCallback: Boolean): Boolean {
|
|
||||||
val cursorUpdateMode = ((if (enableMonitor) CURSOR_UPDATE_MONITOR else 0)
|
|
||||||
or if (requestImmediateCallback) CURSOR_UPDATE_IMMEDIATE else 0)
|
|
||||||
return requestCursorUpdatesImpl(inputConnection, cursorUpdateMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
sInputConnectionType = ClassWrapper(InputConnection::class.java)
|
|
||||||
sRequestCursorUpdatesMethod = sInputConnectionType!!.getPrimitiveMethod(
|
|
||||||
"requestCursorUpdates", false, Int::class.javaPrimitiveType)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,7 +34,6 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.compat.InputConnectionCompatUtils;
|
|
||||||
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
||||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.common.UnicodeSurrogate;
|
import org.dslul.openboard.inputmethod.latin.common.UnicodeSurrogate;
|
||||||
|
@ -1061,7 +1060,10 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
||||||
if (!isConnected()) {
|
if (!isConnected()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return InputConnectionCompatUtils.requestCursorUpdates(
|
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP)
|
||||||
mIC, enableMonitor, requestImmediateCallback);
|
return false;
|
||||||
|
final int cursorUpdateMode = (enableMonitor ? InputConnection.CURSOR_UPDATE_MONITOR : 0)
|
||||||
|
| (requestImmediateCallback ? InputConnection.CURSOR_UPDATE_IMMEDIATE : 0);
|
||||||
|
return mIC.requestCursorUpdates(cursorUpdateMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue