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.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,256 +18,250 @@ 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)
}
@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 if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
fun onNativePause() {} return true
@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()
} }
@JvmStatic return false
fun isNetworkAvailable(): Boolean { }
val connectivityManager = me.get()?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = connectivityManager.activeNetwork @JvmStatic
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false fun openURL(url: String) {
Log.d("MAIN", "Open URL")
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { me.get()?.runOnUiThread {
return true try {
} me.get()?.startActivity(
Intent(
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { "android.intent.action.VIEW",
return true Uri.parse(url)
}
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)
)
) )
} catch (e: ActivityNotFoundException) { )
Toast.makeText( } catch (e: ActivityNotFoundException) {
me.get(), Toast.makeText(
"No activity found to open this URL.", me.get(),
Toast.LENGTH_SHORT, "No activity found to open this URL.",
).show() Toast.LENGTH_SHORT,
} ).show()
} }
} }
}
@JvmStatic @JvmStatic
fun sendMail(subject: String, body: String, to: String) { fun sendMail(subject: String, body: String, to: String) {
me.get()?.runOnUiThread { me.get()?.runOnUiThread {
val i = Intent("android.intent.action.SEND") val i = Intent("android.intent.action.SEND")
i.type = "message/rfc822" i.type = "message/rfc822"
i.putExtra("android.intent.extra.EMAIL", arrayOf(to)) i.putExtra("android.intent.extra.EMAIL", arrayOf(to))
i.putExtra("android.intent.extra.SUBJECT", subject) i.putExtra("android.intent.extra.SUBJECT", subject)
i.putExtra("android.intent.extra.TEXT", body) i.putExtra("android.intent.extra.TEXT", body)
try { try {
me.get()?.startActivity(Intent.createChooser(i, "Send mail...")) me.get()?.startActivity(Intent.createChooser(i, "Send mail..."))
} catch (e: ActivityNotFoundException) { } catch (e: ActivityNotFoundException) {
Toast.makeText( Toast.makeText(
me.get(), me.get(),
"There are no email clients installed.", "There are no email clients installed.",
Toast.LENGTH_SHORT, Toast.LENGTH_SHORT,
).show() ).show()
}
} }
} }
}
@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 @JvmStatic
fun setBlockBackButton(value: Boolean) { fun onToggleKeyboard() {
blockBackButton_ = value me.get()?.runOnUiThread {
} if (keyboardActive) {
openIMEKeyboard()
@JvmStatic } else {
fun onToggleKeyboard() { closeIMEKeyboard()
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?) { @JvmStatic
super.onCreate(savedInstanceState) fun loadingFinished() {
me = WeakReference(this) isLoaded = true
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
hideSystemUi()
} }
open fun registerReceiver() { // Everyplay doesn't even exist anymore lol
if (receiver_ != null) { @JvmStatic
me.get()?.unregisterReceiver(receiver_) fun setupEveryplay() {}
receiver_ = null
} @JvmStatic
try { fun isEveryplaySupported(): Boolean {
val filter = IntentFilter(Intent.ACTION_SCREEN_ON) return false
filter.addAction(Intent.ACTION_SCREEN_OFF)
filter.addAction(Intent.ACTION_USER_PRESENT)
receiver_ = ReceiverScreen()
registerReceiver(receiver_, filter)
} catch (e: Exception) {
}
} }
private fun hideSystemUi() { @JvmStatic
val windowInsetsController = fun isRecordingSupported(): Boolean {
ViewCompat.getWindowInsetsController(window.decorView) ?: return return false
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
} }
@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() { class ReceiverScreen : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
when (intent.action) { when (intent.action) {
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) }