mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 16:32:39 +00:00
Compare commits
1
Commits
1.9.0
...
multiline-input
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d2b5e0091 |
No files matched your search
@@ -31,6 +31,7 @@ import com.geode.launcher.UserDirectoryProvider
|
||||
import com.geode.launcher.activityresult.GeodeOpenFileActivityResult
|
||||
import com.geode.launcher.activityresult.GeodeOpenFilesActivityResult
|
||||
import com.geode.launcher.activityresult.GeodeSaveFileActivityResult
|
||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
||||
import java.io.File
|
||||
import java.lang.ref.WeakReference
|
||||
import kotlin.system.exitProcess
|
||||
@@ -572,6 +573,11 @@ object GeodeUtils {
|
||||
.launchUrl(activity, url.toUri())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun openMultilineIMEKeyboard() {
|
||||
Cocos2dxGLSurfaceView.openMultilineIMEKeyboard()
|
||||
}
|
||||
|
||||
external fun nativeKeyUp(keyCode: Int, modifiers: Int)
|
||||
external fun nativeKeyDown(keyCode: Int, modifiers: Int, isRepeating: Boolean)
|
||||
external fun nativeActionScroll(scrollX: Float, scrollY: Float)
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
@@ -19,6 +20,8 @@ import com.geode.launcher.utils.GeodeUtils
|
||||
|
||||
private const val HANDLER_OPEN_IME_KEYBOARD = 2
|
||||
private const val HANDLER_CLOSE_IME_KEYBOARD = 3
|
||||
private const val HANDLER_ARG_MULTILINE = 1
|
||||
private const val HANDLER_ARG_SINGLELINE = 0
|
||||
private const val MS_TO_NS = 1_000_000
|
||||
|
||||
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
@@ -27,11 +30,22 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
private lateinit var handler: Handler
|
||||
private lateinit var cocos2dxTextInputWrapper: Cocos2dxTextInputWrapper
|
||||
|
||||
fun openMultilineIMEKeyboard() {
|
||||
val msg = Message().apply {
|
||||
what = HANDLER_OPEN_IME_KEYBOARD
|
||||
obj = cocos2dxGLSurfaceView.getContentText()
|
||||
arg1 = HANDLER_ARG_MULTILINE
|
||||
}
|
||||
handler.sendMessage(msg)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun openIMEKeyboard() {
|
||||
val msg = Message()
|
||||
msg.what = HANDLER_OPEN_IME_KEYBOARD
|
||||
msg.obj = cocos2dxGLSurfaceView.getContentText()
|
||||
val msg = Message().apply {
|
||||
what = HANDLER_OPEN_IME_KEYBOARD
|
||||
obj = cocos2dxGLSurfaceView.getContentText()
|
||||
arg1 = HANDLER_ARG_SINGLELINE
|
||||
}
|
||||
handler.sendMessage(msg)
|
||||
}
|
||||
|
||||
@@ -67,6 +81,18 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
requestFocus()
|
||||
}
|
||||
|
||||
fun setKeyboardMultiline() {
|
||||
val editText = cocos2dxEditText ?: return
|
||||
editText.inputType = editText.inputType or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||
editText.maxLines = Int.MAX_VALUE
|
||||
}
|
||||
|
||||
fun setKeyboardSingleLine() {
|
||||
val editText = cocos2dxEditText ?: return
|
||||
editText.inputType = editText.inputType and InputType.TYPE_TEXT_FLAG_MULTI_LINE.inv()
|
||||
editText.maxLines = 1
|
||||
}
|
||||
|
||||
fun initView() {
|
||||
setEGLContextClientVersion(2)
|
||||
isFocusableInTouchMode = true
|
||||
@@ -78,6 +104,12 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
when (msg.what) {
|
||||
HANDLER_OPEN_IME_KEYBOARD -> {
|
||||
if (cocos2dxEditText?.requestFocus() == true) {
|
||||
if (msg.arg1 == HANDLER_ARG_MULTILINE) {
|
||||
setKeyboardMultiline()
|
||||
} else {
|
||||
setKeyboardSingleLine()
|
||||
}
|
||||
|
||||
cocos2dxEditText?.apply {
|
||||
removeTextChangedListener(
|
||||
cocos2dxTextInputWrapper
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.text.TextWatcher
|
||||
import android.widget.TextView.OnEditorActionListener
|
||||
import android.text.Editable
|
||||
import android.view.KeyEvent
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.TextView
|
||||
|
||||
@@ -47,6 +48,10 @@ class Cocos2dxTextInputWrapper(private val cocos2dxGLSurfaceView: Cocos2dxGLSurf
|
||||
|
||||
override fun onTextChanged(pCharSequence: CharSequence, start: Int, before: Int, count: Int) {}
|
||||
override fun onEditorAction(textView: TextView, actionID: Int, keyEvent: KeyEvent?): Boolean {
|
||||
if (actionID != EditorInfo.IME_ACTION_DONE) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (cocos2dxGLSurfaceView.cocos2dxEditText == textView && isFullScreenEdit) {
|
||||
for (i in originText!!.length downTo 1) {
|
||||
cocos2dxGLSurfaceView.deleteBackward()
|
||||
@@ -58,9 +63,7 @@ class Cocos2dxTextInputWrapper(private val cocos2dxGLSurfaceView: Cocos2dxGLSurf
|
||||
|
||||
cocos2dxGLSurfaceView.insertText(text)
|
||||
}
|
||||
if (actionID != 6) {
|
||||
return false
|
||||
}
|
||||
|
||||
cocos2dxGLSurfaceView.requestFocus()
|
||||
Cocos2dxGLSurfaceView.closeIMEKeyboard()
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user