コード例 #1
0
  /**
   * Close a custom browser screen.
   *
   * @return a PluginResult
   */
  private synchronized PluginResult closeBrowser() {
    JSONObject obj = null;

    if (browser != null && browser.isDisplayed()) {
      uiApp.invokeAndWait(
          new Runnable() {
            public void run() {
              try {
                uiApp.popScreen(browser);
              } catch (IllegalArgumentException e) {
                Logger.log(
                    ChildBrowser.TAG + ": Caught illegal argument exception: " + e.getMessage());
              }
            }
          });
      browser = null;

      obj = new JSONObject();
      try {
        obj.put("type", CustomBrowser.CLOSE_EVENT);
      } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
      }
    }

    return new PluginResult(PluginResult.Status.OK, obj);
  }
コード例 #2
0
  /**
   * Display the specified URL in a custom browser screen.
   *
   * @param args JSONArry of arguments for the action.
   * @return a PluginResult
   */
  private synchronized PluginResult showWebPage(JSONArray args) {
    PluginResult result;

    if (browser == null) {
      try {
        boolean showLocationBar = true;
        String url = args.getString(0);
        JSONObject options = args.getJSONObject(1);

        // Determine whether to show or hide navigation bar.
        if (options != null) {
          showLocationBar = options.optBoolean("showLocationBar", true);
        }

        browser = new CustomBrowser(callbackId);
        if (browser.init(showLocationBar)) {
          uiApp.invokeLater(
              new Runnable() {
                public void run() {
                  uiApp.pushScreen(browser);
                }
              });

          browser.loadURL(url);

          // Must keep the callback for browser URL load and close
          // events.
          result = new PluginResult(PluginResult.Status.OK, "");
          result.setKeepCallback(true);
        } else {
          result =
              new PluginResult(
                  PluginResult.Status.ERROR, TAG + "Failed to initialize CustomBrowser.");
        }
      } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
      }
    } else {
      result = new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open.");
    }

    return result;
  }