add edittext methods

This commit is contained in:
qimiko committed 2022-05-27 02:16:48 -07:00
1 parent 9c66ee3e98
commit 1115bc2bd4
8 files changed
+254 -37

No files matched your search

-1
View File
@@ -6,7 +6,6 @@ Launches a vanilla copy of Geometry Dash with the Geode loader added.
* Implement remaining Java methods (text editing) * Implement remaining Java methods (text editing)
* Figure out better way of packaging libgeode * Figure out better way of packaging libgeode
* Fix android_asset references in FMOD
* Back button support * Back button support
* (seems to be a focus issue? pressing a key on keyboard allows for the back button to be used) * (seems to be a focus issue? pressing a key on keyboard allows for the back button to be used)
* Fix icon in launcher * Fix icon in launcher
+1 -1
View File
@@ -32,7 +32,7 @@
android:exported="true" android:exported="true"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:theme="@style/Theme.NoActionBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden"> android:windowSoftInputMode="stateAlwaysHidden">
<meta-data <meta-data
android:name="android.app.lib_name" android:name="android.app.lib_name"
@@ -4,6 +4,8 @@ import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.os.Bundle import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -22,12 +24,17 @@ import com.customRobTop.JniToCpp
import com.robtopx.geometryjump.GJConstants import com.robtopx.geometryjump.GJConstants
import com.robtopx.geometryjump.LaunchUtils import com.robtopx.geometryjump.LaunchUtils
import dev.xyze.geodelauncher.ui.theme.GeodeLauncherTheme import dev.xyze.geodelauncher.ui.theme.GeodeLauncherTheme
import org.cocos2dx.lib.Cocos2dxEditText
import org.cocos2dx.lib.Cocos2dxGLSurfaceView import org.cocos2dx.lib.Cocos2dxGLSurfaceView
import org.cocos2dx.lib.Cocos2dxHelper import org.cocos2dx.lib.Cocos2dxHelper
import org.cocos2dx.lib.Cocos2dxRenderer import org.cocos2dx.lib.Cocos2dxRenderer
import org.fmod.FMOD import org.fmod.FMOD
class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperListener { class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setupUIState() setupUIState()
@@ -66,11 +73,26 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
AndroidView( AndroidView(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
factory = { factory = {
Cocos2dxGLSurfaceView(this).apply { val frameLayoutParams = ViewGroup.LayoutParams(-1, -1)
setEGLConfigChooser(5, 6, 5, 0, 16, 8) val frameLayout = FrameLayout(this)
initView() frameLayout.layoutParams = frameLayoutParams
setCocos2dxRenderer(Cocos2dxRenderer()) val editTextLayoutParams = ViewGroup.LayoutParams(-1, -2)
} val editText = Cocos2dxEditText(this)
editText.layoutParams = editTextLayoutParams
frameLayout.addView(editText)
val glSurfaceView = Cocos2dxGLSurfaceView(this)
this.mGLSurfaceView = glSurfaceView
frameLayout.addView(this.mGLSurfaceView)
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8)
glSurfaceView.initView()
glSurfaceView.setCocos2dxRenderer(Cocos2dxRenderer())
editText.inputType = 145
glSurfaceView.setCocos2dxEditText(editText)
frameLayout
} }
) )
SnackbarHost( SnackbarHost(
@@ -0,0 +1,34 @@
package org.cocos2dx.lib
import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import androidx.appcompat.widget.AppCompatEditText
class Cocos2dxEditText : AppCompatEditText {
private var mCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView? = null
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(
context, attrs
) {
}
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
context, attrs, defStyle
) {
}
fun setCocos2dxGLSurfaceView(pCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView?) {
mCocos2dxGLSurfaceView = pCocos2dxGLSurfaceView
}
override fun onKeyDown(pKeyCode: Int, pKeyEvent: KeyEvent): Boolean {
super.onKeyDown(pKeyCode, pKeyEvent)
if (pKeyCode != 4) {
return true
}
mCocos2dxGLSurfaceView!!.requestFocus()
return true
}
}
@@ -6,18 +6,39 @@ import android.opengl.GLSurfaceView
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.os.Message import android.os.Message
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.MotionEvent import android.view.MotionEvent
import android.view.inputmethod.InputMethodManager
import com.customRobTop.BaseRobTopActivity import com.customRobTop.BaseRobTopActivity
private const val HANDLER_OPEN_IME_KEYBOARD = 2
private const val HANDLER_CLOSE_IME_KEYBOARD = 3
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) { class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
companion object { companion object {
lateinit var mCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView lateinit var mCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView
private var sHandler: Handler? = null private lateinit var sHandler: Handler
private lateinit var sCocos2dxTextInputWrapper: Cocos2dxTextInputWrapper
@JvmStatic
fun openIMEKeyboard() {
val msg = Message()
msg.what = HANDLER_OPEN_IME_KEYBOARD
msg.obj = mCocos2dxGLSurfaceView.getContentText()
sHandler.sendMessage(msg)
}
@JvmStatic
fun closeIMEKeyboard() {
val msg = Message()
msg.what = HANDLER_CLOSE_IME_KEYBOARD
sHandler.sendMessage(msg)
}
} }
private lateinit var mCocos2dxRenderer: Cocos2dxRenderer private lateinit var mCocos2dxRenderer: Cocos2dxRenderer
var mCocos2dxEditText: Cocos2dxEditText? = null
fun initView() { fun initView() {
setEGLContextClientVersion(2) setEGLContextClientVersion(2)
@@ -26,26 +47,27 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
preserveEGLContextOnPause = true preserveEGLContextOnPause = true
// } // }
mCocos2dxGLSurfaceView = this mCocos2dxGLSurfaceView = this
// sCocos2dxTextInputWraper = Cocos2dxTextInputWraper(this) sCocos2dxTextInputWrapper = Cocos2dxTextInputWrapper(this)
sHandler = @SuppressLint("HandlerLeak") sHandler = @SuppressLint("HandlerLeak")
object : Handler(Looper.getMainLooper()) { object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
/* when (msg.what) { when (msg.what) {
2 -> { HANDLER_OPEN_IME_KEYBOARD -> {
if (this@Cocos2dxGLSurfaceView.mCocos2dxEditText != null && this@Cocos2dxGLSurfaceView.mCocos2dxEditText.requestFocus()) { if (mCocos2dxEditText?.requestFocus() == true) {
this@Cocos2dxGLSurfaceView.mCocos2dxEditText.removeTextChangedListener( mCocos2dxEditText?.apply {
Cocos2dxGLSurfaceView.sCocos2dxTextInputWraper removeTextChangedListener(
sCocos2dxTextInputWrapper
) )
this@Cocos2dxGLSurfaceView.mCocos2dxEditText.setText("") setText("")
val text = msg.obj as String val text = msg.obj as String
this@Cocos2dxGLSurfaceView.mCocos2dxEditText.append(text) append(text)
Cocos2dxGLSurfaceView.sCocos2dxTextInputWraper.setOriginText(text) sCocos2dxTextInputWrapper.setOriginText(text)
this@Cocos2dxGLSurfaceView.mCocos2dxEditText.addTextChangedListener( addTextChangedListener(
Cocos2dxGLSurfaceView.sCocos2dxTextInputWraper sCocos2dxTextInputWrapper
) )
(Cocos2dxGLSurfaceView.mCocos2dxGLSurfaceView.getContext() }
.getSystemService("input_method") as InputMethodManager).showSoftInput( (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(
this@Cocos2dxGLSurfaceView.mCocos2dxEditText, mCocos2dxEditText,
0 0
) )
Log.d("GLSurfaceView", "showSoftInput") Log.d("GLSurfaceView", "showSoftInput")
@@ -53,31 +75,28 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
} }
return return
} }
3 -> { HANDLER_CLOSE_IME_KEYBOARD -> {
if (this@Cocos2dxGLSurfaceView.mCocos2dxEditText != null) { mCocos2dxEditText?.apply {
this@Cocos2dxGLSurfaceView.mCocos2dxEditText.removeTextChangedListener( removeTextChangedListener(
Cocos2dxGLSurfaceView.sCocos2dxTextInputWraper sCocos2dxTextInputWrapper
) )
(Cocos2dxGLSurfaceView.mCocos2dxGLSurfaceView.getContext() (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(
.getSystemService("input_method") as InputMethodManager).hideSoftInputFromWindow( windowToken,
this@Cocos2dxGLSurfaceView.mCocos2dxEditText.getWindowToken(),
0 0
) )
this@Cocos2dxGLSurfaceView.requestFocus()
Log.d("GLSurfaceView", "HideSoftInput")
this@Cocos2dxGLSurfaceView.mCocos2dxRenderer.handleTextClosed()
return
} }
requestFocus()
Log.d("GLSurfaceView", "HideSoftInput")
mCocos2dxRenderer.handleTextClosed()
return return
} }
else -> return else -> return
} }
*/
} }
} }
} }
override fun onTouchEvent(pMotionEvent: MotionEvent): Boolean { override fun onTouchEvent(pMotionEvent: MotionEvent): Boolean {
val pointerNumber = pMotionEvent.pointerCount val pointerNumber = pMotionEvent.pointerCount
val ids = IntArray(pointerNumber) val ids = IntArray(pointerNumber)
@@ -189,4 +208,30 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
this.mCocos2dxRenderer = renderer this.mCocos2dxRenderer = renderer
setRenderer(this.mCocos2dxRenderer) setRenderer(this.mCocos2dxRenderer)
} }
private fun getContentText(): String {
return mCocos2dxRenderer.getContentText()
}
fun getCocos2dxEditText(): Cocos2dxEditText? {
return mCocos2dxEditText
}
fun setCocos2dxEditText(pCocos2dxEditText: Cocos2dxEditText) {
mCocos2dxEditText = pCocos2dxEditText
if (sCocos2dxTextInputWrapper != null) {
mCocos2dxEditText?.setOnEditorActionListener(sCocos2dxTextInputWrapper)
mCocos2dxEditText?.setCocos2dxGLSurfaceView(this)
requestFocus()
}
}
fun insertText(pText: String) {
queueEvent { mCocos2dxRenderer.handleInsertText(pText) }
}
fun deleteBackward() {
queueEvent { mCocos2dxRenderer.handleDeleteBackward() }
}
} }
@@ -13,11 +13,29 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
} }
@JvmStatic @JvmStatic
private external fun nativeRender() private external fun nativeDeleteBackward()
@JvmStatic
private external fun nativeGetContentText(): String
@JvmStatic
private external fun nativeInsertText(pText: String)
@JvmStatic @JvmStatic
private external fun nativeKeyDown(pKeyCode: Int): Boolean private external fun nativeKeyDown(pKeyCode: Int): Boolean
@JvmStatic
private external fun nativeOnPause()
@JvmStatic
private external fun nativeOnResume()
@JvmStatic
private external fun nativeRender()
@JvmStatic
private external fun nativeTextClosed()
@JvmStatic @JvmStatic
private external fun nativeTouchesBegin(pID: Int, pX: Float, pY: Float) private external fun nativeTouchesBegin(pID: Int, pX: Float, pY: Float)
@@ -75,4 +93,28 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
fun handleKeyDown(pKeyCode: Int) { fun handleKeyDown(pKeyCode: Int) {
nativeKeyDown(pKeyCode) nativeKeyDown(pKeyCode)
} }
fun handleOnPause() {
nativeOnPause()
}
fun handleOnResume() {
nativeOnResume()
}
fun handleInsertText(pText: String) {
nativeInsertText(pText)
}
fun handleDeleteBackward() {
nativeDeleteBackward()
}
fun handleTextClosed() {
nativeTextClosed()
}
fun getContentText(): String {
return nativeGetContentText()
}
} }
@@ -0,0 +1,70 @@
package org.cocos2dx.lib
import android.content.Context
import android.text.TextWatcher
import android.widget.TextView.OnEditorActionListener
import android.text.Editable
import android.view.KeyEvent
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
class Cocos2dxTextInputWrapper(private val mCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView) : TextWatcher, OnEditorActionListener {
private var mOriginText: String? = null
private var mText: String? = null
private val isFullScreenEdit: Boolean
get() = (mCocos2dxGLSurfaceView.mCocos2dxEditText?.context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).isFullscreenMode
fun setOriginText(pOriginText: String?) {
mOriginText = pOriginText
}
override fun afterTextChanged(s: Editable) {
if (!isFullScreenEdit) {
var nModified = s.length - mText!!.length
if (nModified > 0) {
mCocos2dxGLSurfaceView.insertText(
s.subSequence(mText!!.length, s.length).toString()
)
} else {
while (nModified < 0) {
mCocos2dxGLSurfaceView.deleteBackward()
nModified++
}
}
mText = s.toString()
}
}
override fun beforeTextChanged(
pCharSequence: CharSequence,
start: Int,
count: Int,
after: Int
) {
mText = pCharSequence.toString()
}
override fun onTextChanged(pCharSequence: CharSequence, start: Int, before: Int, count: Int) {}
override fun onEditorAction(pTextView: TextView, pActionID: Int, pKeyEvent: KeyEvent?): Boolean {
if (mCocos2dxGLSurfaceView.getCocos2dxEditText() == pTextView && isFullScreenEdit) {
for (i in mOriginText!!.length downTo 1) {
mCocos2dxGLSurfaceView.deleteBackward()
}
var text = pTextView.text.toString()
if (text.compareTo("") == 0) {
text = "\n"
}
if (10 != text[text.length - 1].code) {
text += 10.toChar()
}
mCocos2dxGLSurfaceView.insertText(text)
}
if (pActionID != 6) {
return false
}
mCocos2dxGLSurfaceView.requestFocus()
Cocos2dxGLSurfaceView.closeIMEKeyboard()
return false
}
}
+6 -1
View File
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="Theme.NoActionBar.Fullscreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="Theme.GeodeLauncher" parent="android:Theme.Material.Light.NoActionBar" /> <style name="Theme.GeodeLauncher" parent="android:Theme.Material.Light.NoActionBar" />
</resources> </resources>