mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 00:18:18 +00:00
Implement utils except file utils cause uhh i tried my best
This commit is contained in:
1 parent
0f51ca6994
commit
76264581c9
6 files changed
+96
-2
No files matched your search
@@ -65,6 +65,14 @@
|
||||
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
|
||||
</intent-filter>
|
||||
</provider>
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="com.geode.launcher.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -23,6 +23,7 @@ import com.customRobTop.BaseRobTopActivity
|
||||
import com.customRobTop.JniToCpp
|
||||
import com.geode.launcher.utils.Constants
|
||||
import com.geode.launcher.utils.LaunchUtils
|
||||
import com.geode.launcher.utils.GeodeUtils
|
||||
import org.cocos2dx.lib.Cocos2dxEditText
|
||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
||||
import org.cocos2dx.lib.Cocos2dxHelper
|
||||
@@ -74,6 +75,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
||||
}
|
||||
|
||||
Cocos2dxHelper.init(this, this)
|
||||
GeodeUtils.setContext(this)
|
||||
|
||||
System.load("$gdNativeLibraryPath/lib${Constants.FMOD_LIB_NAME}.so")
|
||||
System.load("$gdNativeLibraryPath/lib${Constants.COCOS_LIB_NAME}.so")
|
||||
|
||||
@@ -42,6 +42,13 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gdInstalled) {
|
||||
intent.getBooleanExtra("restarted", false).let {
|
||||
if (it) {
|
||||
onLaunch(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.geode.launcher.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Intent
|
||||
import androidx.core.content.FileProvider
|
||||
import android.provider.DocumentsContract
|
||||
import java.io.File
|
||||
import android.net.Uri
|
||||
import java.lang.ref.WeakReference
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
@Suppress("unused")
|
||||
object GeodeUtils {
|
||||
private lateinit var context: WeakReference<Context>
|
||||
|
||||
fun setContext(context: Context) {
|
||||
this.context = WeakReference(context)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun writeClipboard(text: String) {
|
||||
context.get()?.run {
|
||||
val manager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("Geode", text)
|
||||
manager.setPrimaryClip(clip)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun readClipboard(): String {
|
||||
context.get()?.run {
|
||||
val manager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = manager.primaryClip
|
||||
if (clip != null && clip.itemCount > 0) {
|
||||
return clip.getItemAt(0).text.toString()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun restartGame() {
|
||||
context.get()?.run {
|
||||
packageManager.getLaunchIntentForPackage(packageName)?.also {
|
||||
val mainIntent = Intent.makeRestartActivityTask(it.component)
|
||||
mainIntent.putExtra("restarted", true);
|
||||
startActivity(mainIntent)
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun openFolder(path: String): Boolean {
|
||||
context.get()?.run {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
val dir = FileProvider.getUriForFile(this, "com.geode.launcher.fileprovider", File(path))
|
||||
intent.setDataAndType(dir, "application/*")
|
||||
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<external-path name="external_files" path="."/>
|
||||
<root-path name="external_files" path="/storage/"/>
|
||||
</paths>
|
||||
Reference in new issue
Block a user