remove the activity from activity classes

This commit is contained in:
qimiko committed 2022-05-27 22:45:09 -07:00
1 parent ea1e74e587
commit 28c0007d14
5 files changed
+100 -206

No files matched your search

@@ -4,17 +4,12 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.app.KeyguardManager
import android.content.*
import android.content.pm.ActivityInfo
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import com.customRobTop.JniToCpp.resumeSound
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.closeIMEKeyboard
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.openIMEKeyboard
@@ -23,28 +18,20 @@ import java.util.*
@Suppress("unused", "UNUSED_PARAMETER")
open class BaseRobTopActivity : DefaultRobTopActivity() {
companion object {
private var isLoaded_ = false
var blockBackButton_ = false
private var keyboardActive_ = false
object BaseRobTopActivity {
private var isLoaded = false
var blockBackButton = false
private var keyboardActive = false
private var isPaused_ = false
var isPaused = false
lateinit var me: WeakReference<Activity>
private var receiver_: BroadcastReceiver? = null
private var shouldResumeSound_ = true
private var shouldResumeSound = true
fun setCurrentActivity(currentActivity: Activity) {
me = WeakReference(currentActivity)
}
@JvmStatic
fun onNativePause() {}
@JvmStatic
fun onNativeResume() {}
@SuppressLint("HardwareIds")
@JvmStatic
fun getUserID(): String {
@@ -116,23 +103,18 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
@JvmStatic
fun shouldResumeSound(): Boolean {
return shouldResumeSound_
return shouldResumeSound
}
@JvmStatic
fun setKeyboardState(value: Boolean) {
keyboardActive_ = value
}
@JvmStatic
fun setBlockBackButton(value: Boolean) {
blockBackButton_ = value
keyboardActive = value
}
@JvmStatic
fun onToggleKeyboard() {
me.get()?.runOnUiThread {
if (keyboardActive_) {
if (keyboardActive) {
openIMEKeyboard()
} else {
closeIMEKeyboard()
@@ -142,15 +124,13 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
@JvmStatic
fun loadingFinished() {
isLoaded_ = true
isLoaded = true
}
// Everyplay doesn't even exist anymore lol
@JvmStatic
fun gameServicesIsSignedIn(): Boolean {
return false
}
fun setupEveryplay() {}
// everyplay doesn't even exist anymore lol
@JvmStatic
fun isEveryplaySupported(): Boolean {
return false
@@ -161,12 +141,63 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
return false
}
@JvmStatic
fun isRecordingPaused() : Boolean {
return false
}
@JvmStatic
fun isRecording() : Boolean {
return false
}
@JvmStatic
fun startRecording() {}
@JvmStatic
fun stopRecording() {}
@JvmStatic
fun resumeRecording() {}
@JvmStatic
fun pauseRecording() {}
@JvmStatic
fun playLastRecording() {}
@JvmStatic
fun showEveryplay() {}
@JvmStatic
fun setEveryplayMetadata(levelID: String, levelName: String) {}
@JvmStatic
fun onNativePause() {}
@JvmStatic
fun onNativeResume() {}
// Google Play Games methods
// for some reason the button is hidden in game
@JvmStatic
fun gameServicesIsSignedIn(): Boolean {
return false
}
@JvmStatic
fun gameServicesSignIn() { }
@JvmStatic
fun gameServicesSignOut() { }
@JvmStatic
fun unlockAchievement(id: String) {}
@JvmStatic
fun showAchievements() {}
// advertisements stuff, useless for full version
@JvmStatic
fun enableBanner() {}
@@ -201,44 +232,13 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
@JvmStatic
fun enableBannerNoRefresh() {}
// for in game rate buttons, may implement in the future depending on how lazy I am
// (requires Play Store library)
@JvmStatic
fun openAppPage() {
// todo: should this open to the rate dialog?
}
}
fun tryShowRateDialog(appName: String) {}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
me = WeakReference(this)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
hideSystemUi()
}
open fun registerReceiver() {
if (receiver_ != null) {
me.get()?.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() {
val windowInsetsController =
ViewCompat.getWindowInsetsController(window.decorView) ?: return
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
}
@JvmStatic
fun openAppPage() {}
class ReceiverScreen : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
@@ -246,33 +246,22 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
Intent.ACTION_SCREEN_ON -> {
Log.d("TAG", "ACTION_SCREEN_ON")
if (!(me.get()?.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isKeyguardLocked) {
shouldResumeSound_ = true
shouldResumeSound = true
}
if (!isPaused_ && shouldResumeSound_) {
if (!isPaused && shouldResumeSound) {
resumeSound()
}
}
Intent.ACTION_SCREEN_OFF -> {
shouldResumeSound_ = false
shouldResumeSound = false
}
Intent.ACTION_USER_PRESENT -> {
shouldResumeSound_ = true
if (!isPaused_) {
shouldResumeSound = true
if (!isPaused) {
resumeSound()
}
}
}
}
}
override fun onResume() {
super.onResume()
isPaused_ = false
}
/* access modifiers changed from: protected */
override fun onPause() {
super.onPause()
isPaused_ = true
}
}
@@ -1,10 +0,0 @@
package com.customRobTop
import android.app.Activity
import android.os.Bundle
open class DefaultRobTopActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
@@ -1,7 +1,9 @@
package dev.xyze.geodelauncher
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
@@ -39,6 +41,7 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
private var mIsRunning = false
private var mIsOnPause = false
private var mHasWindowFocus = false
private var mReceiver: BroadcastReceiver? = null
@SuppressLint("UnsafeDynamicallyLoadedCode")
override fun onCreate(savedInstanceState: Bundle?) {
@@ -139,7 +142,7 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
Cocos2dxHelper.nativeSetApkPath(gdPackageInfo.applicationInfo.sourceDir)
BaseRobTopActivity.setCurrentActivity(this)
(BaseRobTopActivity.me as? BaseRobTopActivity)?.registerReceiver()
registerReceiver()
}
private fun setupUIState() {
@@ -177,6 +180,7 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
override fun onResume() {
super.onResume()
mIsOnPause = false
BaseRobTopActivity.isPaused = false
if (mHasWindowFocus && !this.mIsRunning) {
resumeGame()
}
@@ -185,11 +189,27 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
override fun onPause() {
super.onPause()
mIsOnPause = true
BaseRobTopActivity.isPaused = true
if (mIsRunning) {
pauseGame()
}
}
private fun registerReceiver() {
if (mReceiver != null) {
unregisterReceiver(mReceiver)
mReceiver = null
}
try {
val filter = IntentFilter(Intent.ACTION_SCREEN_ON)
filter.addAction(Intent.ACTION_SCREEN_OFF)
filter.addAction(Intent.ACTION_USER_PRESENT)
mReceiver = BaseRobTopActivity.ReceiverScreen()
registerReceiver(mReceiver, filter)
} catch (e: Exception) {
}
}
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
super.onWindowFocusChanged(hasWindowFocus)
mHasWindowFocus = hasWindowFocus
@@ -1,116 +1,11 @@
package org.cocos2dx.lib
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.ViewGroup
import android.widget.FrameLayout
import com.customRobTop.BaseRobTopActivity
open class Cocos2dxActivity : BaseRobTopActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
private val sTag = Cocos2dxActivity::class.java.simpleName
private lateinit var mGLSurfaceView: Cocos2dxGLSurfaceView
private var hasWindowFocus = false
private var mIsOnPause = false
private var mIsRunning = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
init()
Cocos2dxHelper.init(this, this)
}
private fun resumeGame() {
this.mIsRunning = true
mGLSurfaceView.onResume()
}
private fun pauseGame() {
this.mIsRunning = false
mGLSurfaceView.onPause()
}
override fun onResume() {
super.onResume()
this.mIsOnPause = false
if (this.hasWindowFocus && !this.mIsRunning) {
resumeGame()
}
}
override fun onPause() {
super.onPause()
this.mIsOnPause = true
if (this.mIsRunning) {
pauseGame()
}
}
override fun showDialog(pTitle: String, pMessage: String) {
/*
val msg = Message()
msg.what = 1
msg.obj = DialogMessage(pTitle, pMessage)
this.mHandler.sendMessage(msg)
*/
}
override fun showEditTextDialog(
pTitle: String,
pMessage: String,
pInputMode: Int,
pInputFlag: Int,
pReturnType: Int,
pMaxLength: Int
) {
/*
val msg = Message()
msg.what = 2
msg.obj = EditBoxMessage(pTitle, pContent, pInputMode, pInputFlag, pReturnType, pMaxLength)
this.mHandler.sendMessage(msg)
*/
}
override fun runOnGLThread(pRunnable: Runnable) {
mGLSurfaceView.queueEvent(pRunnable)
}
private fun init() {
val frameLayoutParams = ViewGroup.LayoutParams(-1, -1)
val frameLayout = FrameLayout(this)
frameLayout.layoutParams = frameLayoutParams
// val edittextLayoutParams = ViewGroup.LayoutParams(-1, -2)
// val edittext = Cocos2dxEditText(this)
// edittext.setLayoutParams(edittextLayoutParams)
// frameLayout.addView(edittext)
this.mGLSurfaceView = onCreateView()
frameLayout.addView(this.mGLSurfaceView)
if (isAndroidEmulator()) {
this.mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0)
}
this.mGLSurfaceView.setCocos2dxRenderer(Cocos2dxRenderer())
// edittext.setInputType(145)
// this.mGLSurfaceView.setCocos2dxEditText(edittext)
setContentView(frameLayout)
}
open fun onCreateView(): Cocos2dxGLSurfaceView {
val glSurfaceView = Cocos2dxGLSurfaceView(this)
glSurfaceView.initView()
return glSurfaceView
}
private fun isAndroidEmulator(): Boolean {
Log.d(sTag, "model=" + Build.MODEL)
val product = Build.PRODUCT
Log.d(sTag, "product=$product")
var isEmulator = false
if (product != null) {
isEmulator = product == "sdk" || product.contains("_sdk") || product.contains("sdk_")
}
Log.d(sTag, "isEmulator=$isEmulator")
return isEmulator
@Suppress("unused")
object Cocos2dxActivity {
@JvmStatic
fun openURL(url: String) {
BaseRobTopActivity.openURL(url)
}
}
@@ -212,7 +212,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
override fun onKeyDown(pKeyCode: Int, pKeyEvent: KeyEvent): Boolean {
return when (pKeyCode) {
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU -> {
if (pKeyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton_) {
if (pKeyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton) {
return true
}
queueEvent { mCocos2dxRenderer.handleKeyDown(pKeyCode) }