Skip to content

Commit

Permalink
refactor(app): introduce 'openExternal' on app activity
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Jul 18, 2024
1 parent 49ce80f commit 6b37ad6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
19 changes: 11 additions & 8 deletions src/app/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1125,19 +1125,21 @@ extern "C" {
void ANDROID_EXTERNAL(app, App, onCreateAppActivity)(
JNIEnv *env,
jobject self,
jobject appActivity
jobject activity
) {
auto app = App::sharedApplication();

if (!app) {
ANDROID_THROW(env, "Missing 'App' in environment");
}

if (app->appActivity) {
app->jni->DeleteGlobalRef(app->appActivity);
if (app->activity) {
app->jni->DeleteGlobalRef(app->activity);
}

app->appActivity = env->NewGlobalRef(appActivity);
app->activity = env->NewGlobalRef(activity);
app->core->platform.jvm = Android::JVMEnvironment(app->jni);
app->core->platform.activity = app->activity;
app->run();

if (app->windowManager.getWindowStatus(0) == WindowManager::WINDOW_NONE) {
Expand Down Expand Up @@ -1218,17 +1220,18 @@ extern "C" {
void ANDROID_EXTERNAL(app, App, onDestroyAppActivity)(
JNIEnv *env,
jobject self,
jobject appActivity
jobject activity
) {
auto app = App::sharedApplication();

if (!app) {
ANDROID_THROW(env, "Missing 'App' in environment");
}

if (app->appActivity) {
env->DeleteGlobalRef(app->appActivity);
app->appActivity = nullptr;
if (app->activity) {
env->DeleteGlobalRef(app->activity);
app->activity = nullptr;
app->core->platform.activity = nullptr;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/app.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ namespace SSC {
Android::BuildInformation androidBuildInformation;
Android::Looper androidLooper;
Android::JVMEnvironment jvm;
Android::Activity activity = nullptr;
Android::Application self = nullptr;
JNIEnv* jni = nullptr;
jobject self = nullptr;
jobject appActivity = nullptr;
bool isAndroidEmulator = false;
#endif

Expand Down
8 changes: 8 additions & 0 deletions src/app/app.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.app.NotificationManager
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.AssetManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.webkit.MimeTypeMap
Expand Down Expand Up @@ -63,6 +64,13 @@ open class AppActivity : WindowManagerActivity() {
)
}

fun openExternal (value: String) {
val uri = Uri.parse(value)
val action = Intent.ACTION_VIEW
val intent = Intent(action, uri)
this.startActivity(intent)
}

override fun onCreate (savedInstanceState: Bundle?) {
this.supportActionBar?.hide()
this.getWindow()?.statusBarColor = android.graphics.Color.TRANSPARENT
Expand Down
16 changes: 8 additions & 8 deletions src/window/android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace SSC {
// `activity.createWindow(index, shouldExitApplicationOnClose): Unit`
CallVoidClassMethodFromAndroidEnvironment(
attachment.env,
app->appActivity,
app->activity,
"createWindow",
"(IZZ)V",
options.index,
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace SSC {
CallClassMethodFromAndroidEnvironment(
attachment.env,
Boolean,
app->appActivity,
app->activity,
"evaluateJavaScript",
"(ILjava/lang/String;)Z",
this->index,
Expand All @@ -102,7 +102,7 @@ namespace SSC {
CallClassMethodFromAndroidEnvironment(
attachment.env,
Boolean,
app->appActivity,
app->activity,
"showWindow",
"(I)Z",
this->index
Expand All @@ -117,7 +117,7 @@ namespace SSC {
CallClassMethodFromAndroidEnvironment(
attachment.env,
Boolean,
app->appActivity,
app->activity,
"hideWindow",
"(I)Z",
this->index
Expand All @@ -140,7 +140,7 @@ namespace SSC {
CallClassMethodFromAndroidEnvironment(
attachment.env,
Boolean,
app->appActivity,
app->activity,
"closeWindow",
"(I)Z",
this->index
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace SSC {
const auto result = CallClassMethodFromAndroidEnvironment(
attachment.env,
Boolean,
app->appActivity,
app->activity,
"navigateWindow",
"(ILjava/lang/String;)Z",
this->index,
Expand All @@ -188,7 +188,7 @@ namespace SSC {
// `activity.getWindowTitle(index): String`
const auto titleString = (jstring) CallObjectClassMethodFromAndroidEnvironment(
attachment.env,
app->appActivity,
app->activity,
"getWindowTitle",
"(I)Ljava/lang/String;",
this->index
Expand All @@ -206,7 +206,7 @@ namespace SSC {
CallClassMethodFromAndroidEnvironment(
attachment.env,
Boolean,
app->appActivity,
app->activity,
"setWindowTitle",
"(ILjava/lang/String;)Z",
this->index,
Expand Down

0 comments on commit 6b37ad6

Please sign in to comment.