save code

This commit is contained in:
xsl
2025-09-07 23:13:39 +08:00
parent 62db716392
commit d3970ceb0f
6 changed files with 141 additions and 5 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
plugins { plugins {
id 'com.android.application' version '8.7.2' apply false id 'com.android.application' version '8.12.2' apply false
id 'com.android.library' version '8.7.2' apply false id 'com.android.library' version '8.12.2' apply false
} }
tasks.register('clean', Delete) { tasks.register('clean', Delete) {
+1 -1
View File
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
+1 -1
View File
@@ -29,7 +29,7 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning,HardcodedDebugMode"> tools:ignore="GoogleAppIndexingWarning,HardcodedDebugMode">
<activity android:name="com.khronos.vulkan_samples.SampleLauncherActivity" <activity android:name="com.khronos.vulkan_samples.MainActivity"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@@ -0,0 +1,34 @@
package com.khronos.vulkan_samples;
import android.os.Bundle;
import android.os.Debug;
import android.util.Log;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.google.androidgamesdk.GameActivity;
public class MainActivity extends GameActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
String native_lib_name = getResources().getString(R.string.native_lib_name);
System.loadLibrary(native_lib_name);
} catch (UnsatisfiedLinkError e) {
Toast.makeText(getApplicationContext(), "Native code library failed to load.", Toast.LENGTH_SHORT).show();
}
String[] argArray = new String[2];
argArray[0] = "sample";
argArray[1] = "hello_triangle";
sendArgumentsToPlatform(argArray);
super.onCreate(savedInstanceState);
Log.i("MainActivity", "onCreate: ");
}
private native void sendArgumentsToPlatform(String[] args);
}
@@ -0,0 +1,83 @@
package com.khronos.vulkan_samples;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.view.View;
import com.google.androidgamesdk.GameActivity;
import com.khronos.vulkan_samples.common.Notifications;
import java.util.concurrent.Semaphore;
public class NativeMyActivity extends GameActivity {
private Context context;
private final Semaphore semaphore = new Semaphore(0, true);
@Override
protected void onCreate(Bundle instance) {
super.onCreate(instance);
Notifications.initNotificationChannel(this);
context = this;
String[] argArray = new String[2];
argArray[0] = "sample";
argArray[1] = "hello_triangle";
sendArgumentsToPlatform(argArray);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}
/***
* Handle the application when an error is thrown and display a message
*/
public void fatalError(String message) {
final NativeMyActivity activity = this;
ApplicationInfo applicationInfo = activity.getApplicationInfo();
this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Vulkan Samples");
builder.setMessage(message);
builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
semaphore.release();
}
});
builder.setCancelable(false);
AlertDialog dialog = builder.create();
dialog.show();
}
});
try {
semaphore.acquire();
}
catch (InterruptedException e) { }
activity.finish();
}
private native void sendArgumentsToPlatform(String[] args);
}
+20 -1
View File
@@ -82,4 +82,23 @@ AndroidPlatformContext::AndroidPlatformContext(android_app *app) :
_temp_directory = details::get_external_cache_directory(app); _temp_directory = details::get_external_cache_directory(app);
_arguments = android_arguments; _arguments = android_arguments;
} }
} // namespace vkb } // namespace vkb
extern "C"
JNIEXPORT void JNICALL
Java_com_khronos_vulkan_1samples_MainActivity_sendArgumentsToPlatform(JNIEnv *env, jobject thiz, jobjectArray arg_strings) {
// TODO: implement sendArgumentsToPlatform()
std::vector<std::string> args;
for (int i = 0; i < env->GetArrayLength(arg_strings); i++)
{
jstring arg_string = (jstring) (env->GetObjectArrayElement(arg_strings, i));
const char *arg = env->GetStringUTFChars(arg_string, 0);
args.push_back(std::string(arg));
env->ReleaseStringUTFChars(arg_string, arg);
}
vkb::AndroidPlatformContext::android_arguments = args;
}