98 lines
3.1 KiB
Java
98 lines
3.1 KiB
Java
package com.khronos.vulkan_samples;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Debug;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
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;
|
|
import com.google.mediapipe.examples.facelandmarker.FaceLandmarkerHelper;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
|
|
public class MainActivity extends GameActivity {
|
|
|
|
|
|
private ExecutorService backgroundExecutor;
|
|
private FaceLandmarkerHelper faceLandmarkerHelper;
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
String native_lib_name = getResources().getString(R.string.native_lib_name);
|
|
try {
|
|
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: ");
|
|
|
|
// 添加按钮到布局
|
|
addButtonToLayout();
|
|
|
|
backgroundExecutor = Executors.newSingleThreadExecutor();
|
|
backgroundExecutor.execute(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
if (faceLandmarkerHelper.isClose()) {
|
|
faceLandmarkerHelper.setupFaceLandmarker();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
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);
|
|
} |