LumberyardNativeUI.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. package com.amazon.lumberyard.NativeUI;
  9. import android.app.Activity;
  10. import android.app.AlertDialog;
  11. import android.content.DialogInterface;
  12. import android.util.Log;
  13. import android.widget.TextView;
  14. import java.util.ArrayList;
  15. import java.util.concurrent.atomic.AtomicReference;
  16. public class LumberyardNativeUI
  17. {
  18. public static void DisplayDialog(final Activity activity, final String title, final String message, final String[] options)
  19. {
  20. Log.d("LMBR", "DisplayDialog called");
  21. userSelection = new AtomicReference<String>("");
  22. userSelection.set("");
  23. Runnable uiDialog = new Runnable()
  24. {
  25. public void run()
  26. {
  27. AlertDialog.Builder builder = new AlertDialog.Builder(activity);
  28. TextView textView = new TextView(activity);
  29. textView.setText(title + "\n" + message);
  30. builder.setCustomTitle(textView);
  31. builder.setItems(options, new DialogInterface.OnClickListener() {
  32. public void onClick(DialogInterface dialog, int index) {
  33. userSelection.set(options[index]);
  34. Log.d("LMBR", "Selected option: " + userSelection.get());
  35. }
  36. });
  37. AlertDialog dialog = builder.create();
  38. dialog.show();
  39. }
  40. };
  41. activity.runOnUiThread(uiDialog);
  42. }
  43. public static String GetUserSelection()
  44. {
  45. return userSelection.get();
  46. }
  47. public static AtomicReference<String> userSelection;
  48. }