FileDocCategorySizeDatePackage
GearsNativeDialog.javaAPI DocAndroid 1.5 API8616Wed May 06 22:42:42 BST 2009com.android.browser

GearsNativeDialog

public class GearsNativeDialog extends android.app.Activity
Native dialog Activity used by gears TODO: rename in GearsNativeDialogActivity
hide

Fields Summary
private static final String
TAG
private String
mDialogArguments
private String
mGearsVersion
private boolean
mDebug
private int
mDialogType
private final int
SETTINGS_DIALOG
private final int
PERMISSION_DIALOG
private final int
LOCATION_DIALOG
private final String
VERSION_STRING
private final String
SETTINGS_DIALOG_STRING
private final String
PERMISSION_DIALOG_STRING
private final String
LOCATION_DIALOG_STRING
private boolean
mDialogDismissed
com.android.browser.GearsBaseDialog
dialog
final android.os.Handler
mHandler
Constructors Summary
Methods Summary
private voidcloseDialog(int closingType)
Close the dialog and set the return string value.

    String ret = dialog.closeDialog(closingType);

    if (mDebug) {
      Log.v(TAG, "closeDialog ret value: " + ret);
    }

    NativeDialog.closeDialog(ret);
    notifyEndOfDialog();
    finish();

    // If the dialog sets a notification, we display it.
    int notification = dialog.notification();
    if (notification != 0) {
      Toast toast = Toast.makeText(this, notification, Toast.LENGTH_LONG);
      toast.setGravity(Gravity.BOTTOM, 0, 0);
      toast.show();
    }
  
public booleandispatchKeyEvent(android.view.KeyEvent event)
Intercepts the back key to immediately notify NativeDialog that we are done.

    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK)
      && (event.getAction() == KeyEvent.ACTION_DOWN)) {
      if (!dialog.handleBackButton()) {
        // if the dialog doesn't do anything with the back button
        closeDialog(GearsBaseDialog.CANCEL);
      }
      return true; // event consumed
    }
    return super.dispatchKeyEvent(event);
  
private voidgetArguments()
Get the arguments for the dialog The dialog needs a json string as an argument, as well as a dialogType. In debug mode the arguments are mocked.

    if (mDebug) {
      mDialogType = LOCATION_DIALOG +1;
      mockArguments();

      return;
    }

    Intent intent = getIntent();
    mDialogArguments = intent.getStringExtra("dialogArguments");
    String dialogTypeString = intent.getStringExtra("dialogType");
    if (dialogTypeString == null) {
      return;
    }

    if (Config.LOGV) {
      Log.v(TAG, "dialogtype: " + dialogTypeString);
    }

    if (dialogTypeString.equalsIgnoreCase(SETTINGS_DIALOG_STRING)) {
      mDialogType = SETTINGS_DIALOG;
      mGearsVersion = intent.getStringExtra(VERSION_STRING);
    } else if (dialogTypeString.equalsIgnoreCase(PERMISSION_DIALOG_STRING)) {
      mDialogType = PERMISSION_DIALOG;
    } else if (dialogTypeString.equalsIgnoreCase(LOCATION_DIALOG_STRING)) {
      mDialogType = LOCATION_DIALOG;
    }
  
private voidmockArguments()
Utility method for debugging the dialog. Set mock arguments.


    String argumentsPermissions = "{ locale: \"en-US\", "
        + "origin: \"http://www.google.com\", dialogType: \"localData\","
        + "customIcon: \"http://google-gears.googlecode.com/"
        + "svn/trunk/gears/test/manual/shortcuts/32.png\","
        + "customName: \"My Application\","
        + "customMessage: \"Press the button to enable my "
        + "application to run offline!\" };";

    String argumentsPermissions2 = "{ locale: \"en-US\", "
        + "origin: \"http://www.google.com\", dialogType: \"localData\" };";

    String argumentsLocation = "{ locale: \"en-US\", "
        + "origin: \"http://www.google.com\", dialogType: \"locationData\","
        + "customIcon: \"http://google-gears.googlecode.com/"
        + "svn/trunk/gears/test/manual/shortcuts/32.png\","
        + "customName: \"My Application\","
        + "customMessage: \"Press the button to enable my "
        + "application to run offline!\" };";

    String argumentsSettings = "{ locale: \"en-US\", permissions: [ { "
        + "name: \"http://www.google.com\", "
        + "localStorage: { permissionState: 0 }, "
        + "locationData: { permissionState: 1 } }, "
        + "{ name: \"http://www.aaronboodman.com\", "
        + "localStorage: { permissionState: 1 }, "
        + "locationData: { permissionState: 2 } }, "
        + "{ name: \"http://www.evil.org\", "
        + "localStorage: { permissionState: 2 }, "
        + "locationData: { permissionState: 2 } } ] }";

    switch (mDialogType) {
      case PERMISSION_DIALOG:
        mDialogArguments = argumentsPermissions;
        break;
      case LOCATION_DIALOG:
        mDialogArguments = argumentsLocation;
        break;
      case SETTINGS_DIALOG:
        mDialogArguments = argumentsSettings;
        break;
    }
  
private voidnotifyEndOfDialog()
Signal to NativeDialog that we are done.

    NativeDialog.signalFinishedDialog();
    mDialogDismissed = true;
  
public voidonCreate(android.os.Bundle icicle)


  
      
    getArguments();
    if (mDialogType == SETTINGS_DIALOG) {
      setTheme(android.R.style.Theme);
    }
    super.onCreate(icicle);
    if (mDialogType != SETTINGS_DIALOG) {
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.gears_dialog);
    }

    switch (mDialogType) {
      case SETTINGS_DIALOG:
        dialog = new GearsSettingsDialog(this, mHandler, mDialogArguments);
        dialog.setGearsVersion(mGearsVersion);
        break;
      case PERMISSION_DIALOG:
        dialog = new GearsPermissionsDialog(this, mHandler, mDialogArguments);
        break;
      case LOCATION_DIALOG:
        dialog = new GearsPermissionsDialog(this, mHandler, mDialogArguments);
        break;
      default:
        dialog = new GearsBaseDialog(this, mHandler, mDialogArguments);
    }
    dialog.setDebug(mDebug);
    dialog.setup();
  
protected android.app.DialogonCreateDialog(int id)
If the dialog call showDialog() on ourself, we let it handle the creation of this secondary dialog. It is used in GearsSettingsDialog, to create the confirmation dialog when the user click on "Remove this site from Gears"

    return dialog.onCreateDialog(id);
  
public voidonDestroy()

    super.onDestroy();
    // In case we reach this point without
    // notifying NativeDialog, we do it now.
    if (!mDialogDismissed) {
      notifyEndOfDialog();
    }
  
public voidonPause()

    super.onPause();
    if (!mDialogDismissed) {
      closeDialog(GearsBaseDialog.CANCEL);
    }