FileDocCategorySizeDatePackage
NativeDialog.javaAPI DocAndroid 1.5 API4876Wed May 06 22:41:56 BST 2009android.webkit.gears

NativeDialog

public class NativeDialog extends Object
Utility class to call a modal native dialog on Android The dialog itself is an Activity defined in the Browser.
hide

Fields Summary
private static final String
TAG
private final String
DIALOG_PACKAGE
private final String
DIALOG_CLASS
private static Lock
mLock
private static Condition
mDialogFinished
private static String
mResults
private static boolean
mAsynchronousDialog
Constructors Summary
Methods Summary
private static native voidcloseAsynchronousDialog(java.lang.String res)
Native callback method

public static voidcloseDialog(java.lang.String res)
Static method that GearsNativeDialog calls to set the dialog's result

    mResults = res;
  
private android.content.IntentcreateIntent(java.lang.String type, java.lang.String arguments)
Utility function to build the intent calling the dialog activity


               
        
    Intent intent = new Intent();
    intent.setClassName(DIALOG_PACKAGE, DIALOG_CLASS);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("dialogArguments", arguments);
    intent.putExtra("dialogType", type);
    return intent;
  
public voidshowAsyncDialog(android.content.Context context, java.lang.String type, java.lang.String arguments)
Opens a native dialog asynchronously The dialog is an activity (GearsNativeDialog) provided by the Browser.

    mAsynchronousDialog = true;
    Intent intent = createIntent(type, arguments);
    context.startActivity(intent);
  
public java.lang.StringshowDialog(android.content.Context context, java.lang.String file, java.lang.String arguments)
Opens a native dialog synchronously and waits for its completion. The dialog is an activity (GearsNativeDialog) provided by the Browser that we call via startActivity(). Contrary to a normal activity though, we need to block until it returns. To do so, we define a static lock object in this class, which GearsNativeDialog can unlock once done


    try {
      mAsynchronousDialog = false;
      mLock.lock();
      File path = new File(file);
      String fileName = path.getName();
      String type = fileName.substring(0, fileName.indexOf(".html"));
      Intent intent = createIntent(type, arguments);

      mResults = null;
      context.startActivity(intent);
      mDialogFinished.await();
    } catch (InterruptedException e) {
      Log.e(TAG, "exception e: " + e);
    } catch (ActivityNotFoundException e) {
      Log.e(TAG, "exception e: " + e);
    } finally {
      mLock.unlock();
    }

    return mResults;
  
public static voidsignalFinishedDialog()
Static method that GearsNativeDialog calls to unlock us

    if (!mAsynchronousDialog) {
      mLock.lock();
      mDialogFinished.signal();
      mLock.unlock();
    } else {
      // we call the native callback
      closeAsynchronousDialog(mResults);
    }