mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 08:19:33 +00:00
implement pause methods
This commit is contained in:
2 files changed
+124
-5
No files matched your search
@@ -2,9 +2,8 @@ package com.customRobTop
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ActivityNotFoundException
|
import android.app.KeyguardManager
|
||||||
import android.content.Context
|
import android.content.*
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
@@ -16,6 +15,9 @@ import android.widget.Toast
|
|||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.WindowInsetsControllerCompat
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
|
import com.customRobTop.JniToCpp.resumeSound
|
||||||
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.closeIMEKeyboard
|
||||||
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.openIMEKeyboard
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
@@ -23,14 +25,25 @@ import java.util.*
|
|||||||
open class BaseRobTopActivity : DefaultRobTopActivity() {
|
open class BaseRobTopActivity : DefaultRobTopActivity() {
|
||||||
companion object {
|
companion object {
|
||||||
private var isLoaded_ = false
|
private var isLoaded_ = false
|
||||||
lateinit var me: Activity
|
|
||||||
var blockBackButton_ = false
|
var blockBackButton_ = false
|
||||||
private var keyboardActive_ = false
|
private var keyboardActive_ = false
|
||||||
|
|
||||||
|
private var isPaused_ = false
|
||||||
|
|
||||||
|
lateinit var me: Activity
|
||||||
|
private var receiver_: BroadcastReceiver? = null
|
||||||
|
private var shouldResumeSound_ = true
|
||||||
|
|
||||||
fun setCurrentActivity(currentActivity: Activity) {
|
fun setCurrentActivity(currentActivity: Activity) {
|
||||||
me = currentActivity
|
me = currentActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun onNativePause() {}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun onNativeResume() {}
|
||||||
|
|
||||||
@SuppressLint("HardwareIds")
|
@SuppressLint("HardwareIds")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getUserID(): String {
|
fun getUserID(): String {
|
||||||
@@ -92,6 +105,10 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun shouldResumeSound(): Boolean {
|
||||||
|
return shouldResumeSound_
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setKeyboardState(value: Boolean) {
|
fun setKeyboardState(value: Boolean) {
|
||||||
@@ -103,6 +120,17 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
|
|||||||
blockBackButton_ = value
|
blockBackButton_ = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun onToggleKeyboard() {
|
||||||
|
me.runOnUiThread {
|
||||||
|
if (keyboardActive_) {
|
||||||
|
openIMEKeyboard()
|
||||||
|
} else {
|
||||||
|
closeIMEKeyboard()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun loadingFinished() {
|
fun loadingFinished() {
|
||||||
isLoaded_ = true
|
isLoaded_ = true
|
||||||
@@ -140,6 +168,21 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
|
|||||||
hideSystemUi()
|
hideSystemUi()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun registerReceiver() {
|
||||||
|
if (receiver_ != null) {
|
||||||
|
me.unregisterReceiver(receiver_)
|
||||||
|
receiver_ = null
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val filter = IntentFilter(Intent.ACTION_SCREEN_ON)
|
||||||
|
filter.addAction(Intent.ACTION_SCREEN_OFF)
|
||||||
|
filter.addAction(Intent.ACTION_USER_PRESENT)
|
||||||
|
receiver_ = ReceiverScreen()
|
||||||
|
registerReceiver(receiver_, filter)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun hideSystemUi() {
|
private fun hideSystemUi() {
|
||||||
val windowInsetsController =
|
val windowInsetsController =
|
||||||
ViewCompat.getWindowInsetsController(window.decorView) ?: return
|
ViewCompat.getWindowInsetsController(window.decorView) ?: return
|
||||||
@@ -148,4 +191,40 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
|
|||||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ReceiverScreen : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
when (intent.action) {
|
||||||
|
Intent.ACTION_SCREEN_ON -> {
|
||||||
|
Log.d("TAG", "ACTION_SCREEN_ON")
|
||||||
|
if (!(me.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isKeyguardLocked) {
|
||||||
|
shouldResumeSound_ = true
|
||||||
|
}
|
||||||
|
if (!isPaused_ && shouldResumeSound_) {
|
||||||
|
resumeSound()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Intent.ACTION_SCREEN_OFF -> {
|
||||||
|
shouldResumeSound_ = false
|
||||||
|
}
|
||||||
|
Intent.ACTION_USER_PRESENT -> {
|
||||||
|
shouldResumeSound_ = true
|
||||||
|
if (!isPaused_) {
|
||||||
|
resumeSound()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
isPaused_ = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/* access modifiers changed from: protected */
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
isPaused_ = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,10 @@ import org.fmod.FMOD
|
|||||||
|
|
||||||
class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
|
class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
|
||||||
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
||||||
private var sTag = GeometryDashActivity::class.simpleName
|
private val sTag = GeometryDashActivity::class.simpleName
|
||||||
|
private var mIsRunning = false
|
||||||
|
private var mIsOnPause = false
|
||||||
|
private var mHasWindowFocus = false
|
||||||
|
|
||||||
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -127,6 +130,7 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
Cocos2dxHelper.nativeSetApkPath(gdPackageInfo.applicationInfo.sourceDir)
|
Cocos2dxHelper.nativeSetApkPath(gdPackageInfo.applicationInfo.sourceDir)
|
||||||
|
|
||||||
BaseRobTopActivity.setCurrentActivity(this)
|
BaseRobTopActivity.setCurrentActivity(this)
|
||||||
|
(BaseRobTopActivity.me as? BaseRobTopActivity)?.registerReceiver()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupUIState() {
|
private fun setupUIState() {
|
||||||
@@ -149,6 +153,42 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
FMOD.close()
|
FMOD.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resumeGame() {
|
||||||
|
mIsRunning = true
|
||||||
|
// Cocos2dxHelper.onResume()
|
||||||
|
mGLSurfaceView?.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun pauseGame() {
|
||||||
|
mIsRunning = false
|
||||||
|
// Cocos2dxHelper.onPause()
|
||||||
|
mGLSurfaceView?.onPause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
mIsOnPause = false
|
||||||
|
if (mHasWindowFocus && !this.mIsRunning) {
|
||||||
|
resumeGame()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
mIsOnPause = true
|
||||||
|
if (mIsRunning) {
|
||||||
|
pauseGame()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
|
||||||
|
super.onWindowFocusChanged(hasWindowFocus)
|
||||||
|
mHasWindowFocus = hasWindowFocus
|
||||||
|
if (hasWindowFocus && !mIsOnPause) {
|
||||||
|
resumeGame()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun runOnGLThread(pRunnable: Runnable) {
|
override fun runOnGLThread(pRunnable: Runnable) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user