Skip to content

Instantly share code, notes, and snippets.

@nipundavid
Last active July 22, 2017 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nipundavid/f9d915483d38affd7859efb4e0548e36 to your computer and use it in GitHub Desktop.
Save nipundavid/f9d915483d38affd7859efb4e0548e36 to your computer and use it in GitHub Desktop.
package com.plugin.android.dialogboxmodule;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.view.ContextThemeWrapper;
import com.unity3d.player.UnityPlayer;
/**
* Created by nipundavid on 6/21/2017.
*/
public class ShowNativeDialogBox {
public static void ShowDialogPopup(String title, String message, String yesButtonText, String noButtonText) {
AlertDialog.Builder dialogPopupBuilder = new AlertDialog.Builder(new ContextThemeWrapper(UnityPlayer.currentActivity, GetTheme()));
dialogPopupBuilder.setTitle(title);
dialogPopupBuilder.setMessage(message);
dialogPopupBuilder.setPositiveButton(yesButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UnityPlayer.UnitySendMessage("AndroidCallBacks", "HandleCallBacks", "0");
}
});
dialogPopupBuilder.setNegativeButton(noButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UnityPlayer.UnitySendMessage("AndroidCallBacks", "HandleCallBacks", "1");
}
});
dialogPopupBuilder.setCancelable(false);
dialogPopupBuilder.show();
}
private static int GetTheme(){
int theme = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
theme = android.R.style.Theme_Material_Light_Dialog;
} else {
theme = android.R.style.Theme_Holo_Dialog;
}
return theme;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment