예제 #1
0
  /**
   * Beeps the device for a given number of times. By default, it will beep once. If the user
   * explicitly sets the beep count to zero, it will play the applications notification profile. The
   * application profile playback sequence is controlled by the user.
   *
   * @param args JSONArray formatted as [ count ] count: specifies the number of times to beep the
   *     device (default: 1).
   * @return A CommandResult object with the success or failure state for beeping the device.
   */
  public static PluginResult execute(JSONArray args) {
    PluginResult result = null;

    if (Alert.isAudioSupported()) {

      try {
        int repeatCount = 1;
        if (args.length() > 0 && !args.isNull(0)) {
          repeatCount = args.getInt(0);
        }

        // play tone n times
        if (repeatCount > 0) {
          playTone(repeatCount);
        }
        // FIXME: unsupported on other platforms
        // send notification event to application profile
        else {
          NotificationsManager.triggerImmediateEvent(PhoneGapExtension.getAppID(), 0, null, null);
        }
      } catch (JSONException e) {
        Logger.log(BeepAction.class.getName() + ": " + e);
        result = new PluginResult(PluginResult.Status.JSONEXCEPTION, e.getMessage());
      } catch (Exception e) {
        Logger.log(BeepAction.class.getName() + ": " + e);
        result = new PluginResult(PluginResult.Status.IOEXCEPTION, e.getMessage());
      }

      result = new PluginResult(PluginResult.Status.OK);
    } else {
      result = new PluginResult(PluginResult.Status.ILLEGALACCESSEXCEPTION, "Audio not supported");
    }

    return result;
  }
예제 #2
0
 /**
  * Add plugin to be loaded and cached. If plugin is already created, then just return it.
  *
  * @param className The class to load
  * @return The plugin
  */
 public Plugin addPlugin(String className, Class clazz)
     throws ClassNotFoundException, IllegalAccessException, InstantiationException {
   if (this.plugins.containsKey(className)) {
     return this.getPlugin(className);
   }
   Logger.log("PluginManager.addPlugin(" + className + ")");
   Plugin plugin = (Plugin) clazz.newInstance();
   this.plugins.put(className, plugin);
   plugin.setContext(this.ext);
   return plugin;
 }