Example #1
0
 /**
  * This method is called by SDL using JNI.
  *
  * @return result of getSystemService(name) but executed on UI thread.
  */
 public Object getSystemServiceFromUiThread(final String name) {
   final Object lock = new Object();
   final Object[] results = new Object[2]; // array for writable variables
   synchronized (lock) {
     runOnUiThread(
         new Runnable() {
           @Override
           public void run() {
             synchronized (lock) {
               results[0] = getSystemService(name);
               results[1] = Boolean.TRUE;
               lock.notify();
             }
           }
         });
     if (results[1] == null) {
       try {
         lock.wait();
       } catch (InterruptedException ex) {
         ex.printStackTrace();
       }
     }
   }
   return results[0];
 }
 public void stop() {
   running.set(false);
   try {
     thread.join();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Example #3
0
  /**
   * This method is called by SDL using JNI. Shows the messagebox from UI thread and block calling
   * thread. buttonFlags, buttonIds and buttonTexts must have same length.
   *
   * @param buttonFlags array containing flags for every button.
   * @param buttonIds array containing id for every button.
   * @param buttonTexts array containing text for every button.
   * @param colors null for default or array of length 5 containing colors.
   * @return button id or -1.
   */
  public int messageboxShowMessageBox(
      final int flags,
      final String title,
      final String message,
      final int[] buttonFlags,
      final int[] buttonIds,
      final String[] buttonTexts,
      final int[] colors) {

    messageboxSelection[0] = -1;

    // sanity checks

    if ((buttonFlags.length != buttonIds.length) && (buttonIds.length != buttonTexts.length)) {
      return -1; // implementation broken
    }

    // collect arguments for Dialog

    final Bundle args = new Bundle();
    args.putInt("flags", flags);
    args.putString("title", title);
    args.putString("message", message);
    args.putIntArray("buttonFlags", buttonFlags);
    args.putIntArray("buttonIds", buttonIds);
    args.putStringArray("buttonTexts", buttonTexts);
    args.putIntArray("colors", colors);

    // trigger Dialog creation on UI thread

    runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            showDialog(dialogs++, args);
          }
        });

    // block the calling thread

    synchronized (messageboxSelection) {
      try {
        messageboxSelection.wait();
      } catch (InterruptedException ex) {
        ex.printStackTrace();
        return -1;
      }
    }

    // return selected value

    return messageboxSelection[0];
  }