Android alert display functionality using JNI
This commit is contained in:
parent
1227f1e7f4
commit
5056563f5d
5 changed files with 64 additions and 3 deletions
|
|
@ -1,9 +1,10 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply from: '../gradle/outputfilename.gradle'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
defaultConfig {
|
||||
applicationId "de.saschawillems.vulkanTriangle"
|
||||
applicationId "de.saschawillems.VulkanTriangle"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
|
|
|
|||
|
|
@ -5,10 +5,18 @@
|
|||
*/
|
||||
package de.saschawillems.vulkanSample;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.NativeActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class VulkanActivity extends NativeActivity {
|
||||
|
||||
VulkanActivity _activity;
|
||||
|
||||
static {
|
||||
// Load native library
|
||||
System.loadLibrary("native-lib");
|
||||
|
|
@ -16,5 +24,36 @@ public class VulkanActivity extends NativeActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
_activity = this;
|
||||
}
|
||||
|
||||
// Use a semaphore to create a modal dialog
|
||||
|
||||
private final Semaphore semaphore = new Semaphore(0, true);
|
||||
|
||||
public void showAlert(final String message)
|
||||
{
|
||||
ApplicationInfo applicationInfo = _activity.getApplicationInfo();
|
||||
final String applicationName = applicationInfo.nonLocalizedLabel.toString();
|
||||
|
||||
this.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(_activity, AlertDialog.THEME_HOLO_DARK);
|
||||
builder.setTitle(applicationName);
|
||||
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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue