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
+227 -333

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,256 +18,250 @@ 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
lateinit var me: WeakReference<Activity>
private var shouldResumeSound = true
fun setCurrentActivity(currentActivity: Activity) {
me = WeakReference(currentActivity)
fun setCurrentActivity(currentActivity: Activity) {
me = WeakReference(currentActivity)
}
@SuppressLint("HardwareIds")
@JvmStatic
fun getUserID(): String {
// this is how RobTop does it in 2.2, based on the meltdown leaks
val androidId = Settings.Secure.getString(me.get()?.contentResolver, Settings.Secure.ANDROID_ID)
return if ("9774d56d682e549c" != androidId) {
UUID.nameUUIDFromBytes(androidId.toByteArray()).toString()
} else return UUID.randomUUID().toString()
}
@JvmStatic
fun isNetworkAvailable(): Boolean {
val connectivityManager = me.get()?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = connectivityManager.activeNetwork
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
return true
}
@JvmStatic
fun onNativePause() {}
@JvmStatic
fun onNativeResume() {}
@SuppressLint("HardwareIds")
@JvmStatic
fun getUserID(): String {
// this is how RobTop does it in 2.2, based on the meltdown leaks
val androidId = Settings.Secure.getString(me.get()?.contentResolver, Settings.Secure.ANDROID_ID)
return if ("9774d56d682e549c" != androidId) {
UUID.nameUUIDFromBytes(androidId.toByteArray()).toString()
} else return UUID.randomUUID().toString()
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
return true
}
@JvmStatic
fun isNetworkAvailable(): Boolean {
val connectivityManager = me.get()?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return false
}
val activeNetwork = connectivityManager.activeNetwork
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
return true
}
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
return true
}
return false
}
@JvmStatic
fun openURL(url: String) {
Log.d("MAIN", "Open URL")
me.get()?.runOnUiThread {
try {
me.get()?.startActivity(
Intent(
"android.intent.action.VIEW",
Uri.parse(url)
)
@JvmStatic
fun openURL(url: String) {
Log.d("MAIN", "Open URL")
me.get()?.runOnUiThread {
try {
me.get()?.startActivity(
Intent(
"android.intent.action.VIEW",
Uri.parse(url)
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
me.get(),
"No activity found to open this URL.",
Toast.LENGTH_SHORT,
).show()
}
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
me.get(),
"No activity found to open this URL.",
Toast.LENGTH_SHORT,
).show()
}
}
}
@JvmStatic
fun sendMail(subject: String, body: String, to: String) {
me.get()?.runOnUiThread {
val i = Intent("android.intent.action.SEND")
i.type = "message/rfc822"
i.putExtra("android.intent.extra.EMAIL", arrayOf(to))
i.putExtra("android.intent.extra.SUBJECT", subject)
i.putExtra("android.intent.extra.TEXT", body)
try {
me.get()?.startActivity(Intent.createChooser(i, "Send mail..."))
} catch (e: ActivityNotFoundException) {
Toast.makeText(
me.get(),
"There are no email clients installed.",
Toast.LENGTH_SHORT,
).show()
}
@JvmStatic
fun sendMail(subject: String, body: String, to: String) {
me.get()?.runOnUiThread {
val i = Intent("android.intent.action.SEND")
i.type = "message/rfc822"
i.putExtra("android.intent.extra.EMAIL", arrayOf(to))
i.putExtra("android.intent.extra.SUBJECT", subject)
i.putExtra("android.intent.extra.TEXT", body)
try {
me.get()?.startActivity(Intent.createChooser(i, "Send mail..."))
} catch (e: ActivityNotFoundException) {
Toast.makeText(
me.get(),
"There are no email clients installed.",
Toast.LENGTH_SHORT,
).show()
}
}
}
@JvmStatic
fun shouldResumeSound(): Boolean {
return shouldResumeSound_
}
@JvmStatic
fun shouldResumeSound(): Boolean {
return shouldResumeSound
}
@JvmStatic
fun setKeyboardState(value: Boolean) {
keyboardActive_ = value
}
@JvmStatic
fun setKeyboardState(value: Boolean) {
keyboardActive = value
}
@JvmStatic
fun setBlockBackButton(value: Boolean) {
blockBackButton_ = value
}
@JvmStatic
fun onToggleKeyboard() {
me.get()?.runOnUiThread {
if (keyboardActive_) {
openIMEKeyboard()
} else {
closeIMEKeyboard()
}
@JvmStatic
fun onToggleKeyboard() {
me.get()?.runOnUiThread {
if (keyboardActive) {
openIMEKeyboard()
} else {
closeIMEKeyboard()
}
}
@JvmStatic
fun loadingFinished() {
isLoaded_ = true
}
@JvmStatic
fun gameServicesIsSignedIn(): Boolean {
return false
}
// everyplay doesn't even exist anymore lol
@JvmStatic
fun isEveryplaySupported(): Boolean {
return false
}
@JvmStatic
fun isRecordingSupported(): Boolean {
return false
}
@JvmStatic
fun stopRecording() {}
@JvmStatic
fun unlockAchievement(id: String) {}
@JvmStatic
fun enableBanner() {}
@JvmStatic
fun disableBanner() {}
@JvmStatic
fun showInterstitial() {}
@JvmStatic
fun cacheInterstitial() {}
@JvmStatic
fun hasCachedInterstitial(): Boolean {
return false
}
@JvmStatic
fun showRewardedVideo() {}
@JvmStatic
fun cacheRewardedVideo() {}
@JvmStatic
fun hasCachedRewardedVideo(): Boolean {
return false
}
@JvmStatic
fun queueRefreshBanner() {}
@JvmStatic
fun enableBannerNoRefresh() {}
@JvmStatic
fun openAppPage() {
// todo: should this open to the rate dialog?
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
me = WeakReference(this)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
hideSystemUi()
@JvmStatic
fun loadingFinished() {
isLoaded = true
}
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) {
}
// Everyplay doesn't even exist anymore lol
@JvmStatic
fun setupEveryplay() {}
@JvmStatic
fun isEveryplaySupported(): Boolean {
return false
}
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 isRecordingSupported(): Boolean {
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() {}
@JvmStatic
fun disableBanner() {}
@JvmStatic
fun showInterstitial() {}
@JvmStatic
fun cacheInterstitial() {}
@JvmStatic
fun hasCachedInterstitial(): Boolean {
return false
}
@JvmStatic
fun showRewardedVideo() {}
@JvmStatic
fun cacheRewardedVideo() {}
@JvmStatic
fun hasCachedRewardedVideo(): Boolean {
return false
}
@JvmStatic
fun queueRefreshBanner() {}
@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 tryShowRateDialog(appName: String) {}
@JvmStatic
fun openAppPage() {}
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.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) }