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.Activity
import android.app.KeyguardManager import android.app.KeyguardManager
import android.content.* import android.content.*
import android.content.pm.ActivityInfo
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.NetworkCapabilities import android.net.NetworkCapabilities
import android.net.Uri import android.net.Uri
import android.os.Bundle
import android.provider.Settings import android.provider.Settings
import android.util.Log import android.util.Log
import android.widget.Toast 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 com.customRobTop.JniToCpp.resumeSound
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.closeIMEKeyboard import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.closeIMEKeyboard
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.openIMEKeyboard import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.openIMEKeyboard
@@ -23,28 +18,20 @@ import java.util.*
@Suppress("unused", "UNUSED_PARAMETER") @Suppress("unused", "UNUSED_PARAMETER")
open class BaseRobTopActivity : DefaultRobTopActivity() { object BaseRobTopActivity {
companion object { private var isLoaded = false
private var isLoaded_ = false var blockBackButton = false
var blockBackButton_ = false private var keyboardActive = false
private var keyboardActive_ = false
private var isPaused_ = false var isPaused = false
lateinit var me: WeakReference<Activity> lateinit var me: WeakReference<Activity>
private var receiver_: BroadcastReceiver? = null private var shouldResumeSound = true
private var shouldResumeSound_ = true
fun setCurrentActivity(currentActivity: Activity) { fun setCurrentActivity(currentActivity: Activity) {
me = WeakReference(currentActivity) me = WeakReference(currentActivity)
} }
@JvmStatic
fun onNativePause() {}
@JvmStatic
fun onNativeResume() {}
@SuppressLint("HardwareIds") @SuppressLint("HardwareIds")
@JvmStatic @JvmStatic
fun getUserID(): String { fun getUserID(): String {
@@ -116,23 +103,18 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
@JvmStatic @JvmStatic
fun shouldResumeSound(): Boolean { fun shouldResumeSound(): Boolean {
return shouldResumeSound_ return shouldResumeSound
} }
@JvmStatic @JvmStatic
fun setKeyboardState(value: Boolean) { fun setKeyboardState(value: Boolean) {
keyboardActive_ = value keyboardActive = value
}
@JvmStatic
fun setBlockBackButton(value: Boolean) {
blockBackButton_ = value
} }
@JvmStatic @JvmStatic
fun onToggleKeyboard() { fun onToggleKeyboard() {
me.get()?.runOnUiThread { me.get()?.runOnUiThread {
if (keyboardActive_) { if (keyboardActive) {
openIMEKeyboard() openIMEKeyboard()
} else { } else {
closeIMEKeyboard() closeIMEKeyboard()
@@ -142,15 +124,13 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
@JvmStatic @JvmStatic
fun loadingFinished() { fun loadingFinished() {
isLoaded_ = true isLoaded = true
} }
// Everyplay doesn't even exist anymore lol
@JvmStatic @JvmStatic
fun gameServicesIsSignedIn(): Boolean { fun setupEveryplay() {}
return false
}
// everyplay doesn't even exist anymore lol
@JvmStatic @JvmStatic
fun isEveryplaySupported(): Boolean { fun isEveryplaySupported(): Boolean {
return false return false
@@ -161,12 +141,63 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
return false return false
} }
@JvmStatic
fun isRecordingPaused() : Boolean {
return false
}
@JvmStatic
fun isRecording() : Boolean {
return false
}
@JvmStatic
fun startRecording() {}
@JvmStatic @JvmStatic
fun stopRecording() {} 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 @JvmStatic
fun unlockAchievement(id: String) {} fun unlockAchievement(id: String) {}
@JvmStatic
fun showAchievements() {}
// advertisements stuff, useless for full version
@JvmStatic @JvmStatic
fun enableBanner() {} fun enableBanner() {}
@@ -201,44 +232,13 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
@JvmStatic @JvmStatic
fun enableBannerNoRefresh() {} fun enableBannerNoRefresh() {}
// for in game rate buttons, may implement in the future depending on how lazy I am
// (requires Play Store library)
@JvmStatic @JvmStatic
fun openAppPage() { fun tryShowRateDialog(appName: String) {}
// todo: should this open to the rate dialog?
}
}
override fun onCreate(savedInstanceState: Bundle?) { @JvmStatic
super.onCreate(savedInstanceState) fun openAppPage() {}
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())
}
class ReceiverScreen : BroadcastReceiver() { class ReceiverScreen : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
@@ -246,33 +246,22 @@ open class BaseRobTopActivity : DefaultRobTopActivity() {
Intent.ACTION_SCREEN_ON -> { Intent.ACTION_SCREEN_ON -> {
Log.d("TAG", "ACTION_SCREEN_ON") Log.d("TAG", "ACTION_SCREEN_ON")
if (!(me.get()?.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isKeyguardLocked) { if (!(me.get()?.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isKeyguardLocked) {
shouldResumeSound_ = true shouldResumeSound = true
} }
if (!isPaused_ && shouldResumeSound_) { if (!isPaused && shouldResumeSound) {
resumeSound() resumeSound()
} }
} }
Intent.ACTION_SCREEN_OFF -> { Intent.ACTION_SCREEN_OFF -> {
shouldResumeSound_ = false shouldResumeSound = false
} }
Intent.ACTION_USER_PRESENT -> { Intent.ACTION_USER_PRESENT -> {
shouldResumeSound_ = true shouldResumeSound = true
if (!isPaused_) { if (!isPaused) {
resumeSound() 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 package dev.xyze.geodelauncher
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Intent import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@@ -39,6 +41,7 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
private var mIsRunning = false private var mIsRunning = false
private var mIsOnPause = false private var mIsOnPause = false
private var mHasWindowFocus = false private var mHasWindowFocus = false
private var mReceiver: BroadcastReceiver? = null
@SuppressLint("UnsafeDynamicallyLoadedCode") @SuppressLint("UnsafeDynamicallyLoadedCode")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -139,7 +142,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() registerReceiver()
} }
private fun setupUIState() { private fun setupUIState() {
@@ -177,6 +180,7 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
mIsOnPause = false mIsOnPause = false
BaseRobTopActivity.isPaused = false
if (mHasWindowFocus && !this.mIsRunning) { if (mHasWindowFocus && !this.mIsRunning) {
resumeGame() resumeGame()
} }
@@ -185,11 +189,27 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
mIsOnPause = true mIsOnPause = true
BaseRobTopActivity.isPaused = true
if (mIsRunning) { if (mIsRunning) {
pauseGame() 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) { override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
super.onWindowFocusChanged(hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus)
mHasWindowFocus = hasWindowFocus mHasWindowFocus = hasWindowFocus
@@ -1,116 +1,11 @@
package org.cocos2dx.lib 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 import com.customRobTop.BaseRobTopActivity
@Suppress("unused")
open class Cocos2dxActivity : BaseRobTopActivity(), Cocos2dxHelper.Cocos2dxHelperListener { object Cocos2dxActivity {
private val sTag = Cocos2dxActivity::class.java.simpleName @JvmStatic
private lateinit var mGLSurfaceView: Cocos2dxGLSurfaceView fun openURL(url: String) {
private var hasWindowFocus = false BaseRobTopActivity.openURL(url)
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
} }
} }
@@ -212,7 +212,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
override fun onKeyDown(pKeyCode: Int, pKeyEvent: KeyEvent): Boolean { override fun onKeyDown(pKeyCode: Int, pKeyEvent: KeyEvent): Boolean {
return when (pKeyCode) { return when (pKeyCode) {
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU -> { KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU -> {
if (pKeyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton_) { if (pKeyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton) {
return true return true
} }
queueEvent { mCocos2dxRenderer.handleKeyDown(pKeyCode) } queueEvent { mCocos2dxRenderer.handleKeyDown(pKeyCode) }