save code
This commit is contained in:
@@ -12,14 +12,14 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'com.khronos.vulkan_samples'
|
applicationId 'com.khronos.vulkan_samples'
|
||||||
namespace "com.khronos.vulkan_samples"
|
namespace "com.khronos.vulkan_samples"
|
||||||
minSdk 30
|
minSdk 28
|
||||||
targetSdk 35
|
targetSdk 35
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
abiFilters.addAll( 'arm64-v8a' )
|
abiFilters.addAll( 'arm64-v8a', 'x86_64')
|
||||||
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DVKB_VALIDATION_LAYERS=OFF'
|
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DVKB_VALIDATION_LAYERS=OFF'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,10 @@
|
|||||||
android:value="@string/native_lib_name" />
|
android:value="@string/native_lib_name" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".SecondActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:authorities="${applicationId}.provider"
|
android:authorities="${applicationId}.provider"
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.khronos.vulkan_samples;
|
package com.khronos.vulkan_samples;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Debug;
|
import android.os.Debug;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.EdgeToEdge;
|
import androidx.activity.EdgeToEdge;
|
||||||
@@ -17,8 +21,8 @@ public class MainActivity extends GameActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
String native_lib_name = getResources().getString(R.string.native_lib_name);
|
||||||
try {
|
try {
|
||||||
String native_lib_name = getResources().getString(R.string.native_lib_name);
|
|
||||||
System.loadLibrary(native_lib_name);
|
System.loadLibrary(native_lib_name);
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
Toast.makeText(getApplicationContext(), "Native code library failed to load.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "Native code library failed to load.", Toast.LENGTH_SHORT).show();
|
||||||
@@ -29,6 +33,47 @@ public class MainActivity extends GameActivity {
|
|||||||
sendArgumentsToPlatform(argArray);
|
sendArgumentsToPlatform(argArray);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.i("MainActivity", "onCreate: ");
|
Log.i("MainActivity", "onCreate: ");
|
||||||
|
|
||||||
|
// 添加按钮到布局
|
||||||
|
addButtonToLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addButtonToLayout() {
|
||||||
|
// 创建按钮
|
||||||
|
Button button = new Button(this);
|
||||||
|
button.setText("Vulkan 按钮");
|
||||||
|
|
||||||
|
// 设置按钮位置(使用绝对坐标)
|
||||||
|
button.setX(50); // 距离左边50像素
|
||||||
|
button.setY(50); // 距离顶部50像素
|
||||||
|
|
||||||
|
// 设置按钮点击事件
|
||||||
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
onButtonClicked();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 将按钮添加到 GameActivity 的布局中(不会覆盖 Vulkan 表面)
|
||||||
|
addContentView(button, new ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void onButtonClicked() {
|
||||||
|
Toast.makeText(this, "Vulkan 按钮被点击了!", Toast.LENGTH_SHORT).show();
|
||||||
|
nativeButtonClicked();
|
||||||
|
// 启动SecondActivity
|
||||||
|
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
|
||||||
|
// 可以传递数据
|
||||||
|
intent.putExtra("message", "Hello from MainActivity!");
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private native void nativeButtonClicked();
|
||||||
|
|
||||||
private native void sendArgumentsToPlatform(String[] args);
|
private native void sendArgumentsToPlatform(String[] args);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.khronos.vulkan_samples;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
public class SecondActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_second);
|
||||||
|
|
||||||
|
TextView textView = findViewById(R.id.textViewSecond);
|
||||||
|
Button buttonBack = findViewById(R.id.buttonBack);
|
||||||
|
|
||||||
|
// 接收从MainActivity传递的数据
|
||||||
|
Intent intent = getIntent();
|
||||||
|
if (intent != null && intent.hasExtra("message")) {
|
||||||
|
String message = intent.getStringExtra("message");
|
||||||
|
textView.setText(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonBack.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// 返回数据到MainActivity
|
||||||
|
Intent returnIntent = new Intent();
|
||||||
|
returnIntent.putExtra("returnData", "Hello back from SecondActivity!");
|
||||||
|
setResult(RESULT_OK, returnIntent);
|
||||||
|
|
||||||
|
// 结束当前Activity
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewSecond"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Second Activity"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:layout_marginBottom="32dp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonBack"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to Main Activity"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "android/context.hpp"
|
#include "android/context.hpp"
|
||||||
|
#include "core/util/logging.hpp"
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -101,4 +101,10 @@ Java_com_khronos_vulkan_1samples_MainActivity_sendArgumentsToPlatform(JNIEnv *en
|
|||||||
}
|
}
|
||||||
|
|
||||||
vkb::AndroidPlatformContext::android_arguments = args;
|
vkb::AndroidPlatformContext::android_arguments = args;
|
||||||
|
}
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_khronos_vulkan_1samples_MainActivity_nativeButtonClicked(JNIEnv *env, jobject thiz) {
|
||||||
|
// TODO: implement nativeButtonClicked()
|
||||||
|
LOGI("call MainActivity_nativeButtonClicked.");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user