|
| 1 | +/* |
| 2 | + * Copyright (C) 2018 by Sascha Willems - www.saschawillems.de |
| 3 | + * |
| 4 | + * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) |
| 5 | + */ |
| 6 | +package de.saschawillems.vulkanSample; |
| 7 | + |
| 8 | +import android.app.AlertDialog; |
| 9 | +import android.app.NativeActivity; |
| 10 | +import android.content.DialogInterface; |
| 11 | +import android.content.pm.ApplicationInfo; |
| 12 | +import android.os.Bundle; |
| 13 | + |
| 14 | +import java.util.concurrent.Semaphore; |
| 15 | + |
| 16 | +public class VulkanActivity extends NativeActivity { |
| 17 | + |
| 18 | + static { |
| 19 | + // Load native library |
| 20 | + System.loadLibrary("native-lib"); |
| 21 | + } |
| 22 | + @Override |
| 23 | + protected void onCreate(Bundle savedInstanceState) { |
| 24 | + super.onCreate(savedInstanceState); |
| 25 | + } |
| 26 | + |
| 27 | + // Use a semaphore to create a modal dialog |
| 28 | + |
| 29 | + private final Semaphore semaphore = new Semaphore(0, true); |
| 30 | + |
| 31 | + public void showAlert(final String message) |
| 32 | + { |
| 33 | + final VulkanActivity activity = this; |
| 34 | + |
| 35 | + ApplicationInfo applicationInfo = activity.getApplicationInfo(); |
| 36 | + final String applicationName = applicationInfo.nonLocalizedLabel.toString(); |
| 37 | + |
| 38 | + this.runOnUiThread(new Runnable() { |
| 39 | + public void run() { |
| 40 | + AlertDialog.Builder builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert); |
| 41 | + builder.setTitle(applicationName); |
| 42 | + builder.setMessage(message); |
| 43 | + builder.setPositiveButton("Close", new DialogInterface.OnClickListener() { |
| 44 | + public void onClick(DialogInterface dialog, int id) { |
| 45 | + semaphore.release(); |
| 46 | + } |
| 47 | + }); |
| 48 | + builder.setCancelable(false); |
| 49 | + AlertDialog dialog = builder.create(); |
| 50 | + dialog.show(); |
| 51 | + } |
| 52 | + }); |
| 53 | + try { |
| 54 | + semaphore.acquire(); |
| 55 | + } |
| 56 | + catch (InterruptedException e) { } |
| 57 | + } |
| 58 | +} |
0 commit comments