/**
   * Executes the request and returns PluginResult.
   *
   * @param action The action to execute.
   * @param args JSONArry of arguments for the plugin.
   * @param callbackId The callback id used when calling back into JavaScript.
   * @return A PluginResult object with a status and message.
   */
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    try {
      if (action.equals("createVideoThumbnail")) {
        String pvUrl = args.getString(0);
        if (pvUrl != null && pvUrl.length() > 0) {
          // do smth with pvUrl

          // MINI_KIND: 512 x 384 thumbnail
          Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(pvUrl, Thumbnails.MINI_KIND);

          try {
            FileOutputStream out = new FileOutputStream(pvUrl + ".jpg");
            bmThumbnail.compress(Bitmap.CompressFormat.JPEG, 55, out);
            //	                	       File file = new File(pvUrl + ".jpg");
            //	                	       boolean val = file.exists();

          } catch (Exception e) {
            e.printStackTrace();
          }

          callbackContext.success(pvUrl + ".jpg");
          return true;
        }
      } else {
        if (action.equals("createImageThumbnail")) {
          String pvUrl = args.getString(0);
          if (pvUrl != null && pvUrl.length() > 0) {
            // do smth with pvUrl

            Bitmap bitmap = BitmapFactory.decodeFile(pvUrl);

            Bitmap bmThumbnail = ThumbnailUtils.extractThumbnail(bitmap, 512, 384);

            try {
              FileOutputStream out = new FileOutputStream(pvUrl + ".jpg");
              bmThumbnail.compress(Bitmap.CompressFormat.JPEG, 55, out);
            } catch (Exception e) {
              e.printStackTrace();
            }

            callbackContext.success(pvUrl + ".jpg");
            return true;
          }
        }
      }

    } catch (JSONException e) {

    }
    return false;
  }
  public void getDeviceDetail(JSONArray array, CallbackContext callbackContext)
      throws JSONException {
    JSONObject deviceDetail = new JSONObject();

    NetmeraDeviceDetail netmeraDeviceDetail;
    try {
      netmeraDeviceDetail = NetmeraPushService.getDeviceDetail(Netmera.getContext());
    } catch (NetmeraException e) {
      callbackContext.error(jsonError(e));
      return;
    }
    List<String> deviceGroups = netmeraDeviceDetail.getDeviceGroups();

    if (deviceGroups.size() > 0) {
      JSONArray tagArray = new JSONArray();
      for (int i = 0; i < deviceGroups.size(); i++) {
        tagArray.put(deviceGroups.get(i));
      }
      deviceDetail.put("tags", tagArray);
    }

    NetmeraGeoLocation deviceLocation = netmeraDeviceDetail.getDeviceLocation();
    if (deviceLocation != null) {
      JSONObject location = new JSONObject();
      location.put("latitude", deviceLocation.getLatitude());
      location.put("longitude", deviceLocation.getLongitude());
      deviceDetail.put("location", location);
    }

    callbackContext.success(deviceDetail);
  }
  private void doOnUnregistered(String registrationId) {
    CallbackContext callback = callbackIds.get("unregisterDevice");
    if (callback == null) return;

    callback.success(registrationId);
    callbackIds.remove("unregisterDevice");
  }
 private void echo(String message, CallbackContext callbackContext) {
   if (message != null && message.length() > 0) {
     callbackContext.success(message);
   } else {
     callbackContext.error("Expected one non-empty string argument.");
   }
 }
Esempio n. 5
0
 @Override
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
   if (action.equals("show")) {
     this.showKeyBoard();
     callbackContext.success("done");
     return true;
   } else if (action.equals("hide")) {
     this.hideKeyBoard();
     callbackContext.success();
     return true;
   } else if (action.equals("isShowing")) {
     callbackContext.success(Boolean.toString(this.isKeyBoardShowing()));
     return true;
   } else {
     return false;
   }
 }
 private void checkLink(String message, CallbackContext callbackContext) {
   Log.v(TAG, "checkLink method executing");
   if (mDbxAcctMgr.hasLinkedAccount()) {
     callbackContext.success();
   } else {
     callbackContext.error("User not authenticated yet");
   }
 }
 public void handleRichPush(JSONArray array, CallbackContext callbackContext)
     throws JSONException {
   try {
     NetmeraPushService.handleRichPush(webView);
     callbackContext.success();
   } catch (NetmeraException e) {
     callbackContext.error(jsonError(e));
   }
 }
  public void initialize(JSONArray params, CallbackContext callbackContext) throws JSONException {
    Context context = this.cordova.getActivity().getApplicationContext();

    String apiKey = params.getString(0);
    String senderId = params.getString(1);

    Netmera.init(context, apiKey);
    senderID = senderId;
    callbackContext.success();
  }
  public void getNotification(JSONArray array, CallbackContext callbackContext) {
    String message = NetmeraPhoneGapPlugin.message;
    Map<String, String> extras = NetmeraPhoneGapPlugin.extras;
    JSONObject obj = jsonNotification(message, extras);

    callbackContext.success(obj);

    // reset incoming push data until the next background push comes in
    NetmeraPhoneGapPlugin.message = "";
    NetmeraPhoneGapPlugin.extras = new HashMap<String, String>();
  }
 public void unregister(JSONArray array, CallbackContext callbackContext) throws JSONException {
   NetmeraDeviceDetail deviceDetail;
   try {
     deviceDetail = jsonArraytoNetmeraDeviceDetail(array);
   } catch (NetmeraException e) {
     callbackContext.error(jsonError(e));
     return;
   }
   NetmeraPushService.unregister(deviceDetail);
   callbackContext.success();
 }
Esempio n. 11
0
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    Intent batteryIntent =
        this.cordova
            .getActivity()
            .registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

    callbackContext.success(
        new JSONObject().put("returnVal", (((float) level / (float) scale) * 100.0f)));
    return true;
  }
    @Override
    public void onComplete(Bundle values) {
      String token = values.getString("access_token");
      String expires_in = values.getString("expires_in");

      JSONObject json = new JSONObject();
      try {
        json.put("token", token);
        json.put("expires_in", expires_in);
        callbackContext.success(json);
      } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.error(getErrorObject(e.getMessage()));
      }
    }
Esempio n. 13
0
  private boolean internalSendTags(JSONArray data, CallbackContext callbackContext) {
    JSONObject params;
    try {
      params = data.getJSONObject(0);
    } catch (JSONException e) {
      e.printStackTrace();
      return false;
    }

    @SuppressWarnings("unchecked")
    Iterator<String> nameItr = params.keys();
    Map<String, Object> paramsMap = new HashMap<String, Object>();
    while (nameItr.hasNext()) {
      try {
        String name = nameItr.next();
        paramsMap.put(name, params.get(name));
      } catch (JSONException e) {
        e.printStackTrace();
        return false;
      }
    }

    try {
      Map<String, String> skippedTags =
          PushManager.sendTagsFromBG(cordova.getActivity(), paramsMap);

      JSONObject skippedTagsObj = new JSONObject();
      for (String tagName : skippedTags.keySet()) {
        skippedTags.put(tagName, skippedTags.get(tagName));
      }

      callbackContext.success(skippedTagsObj);
      return true;
    } catch (PushWooshException e) {
      e.printStackTrace();
      return false;
    }
  }
 private void unlink(String message, CallbackContext callbackContext) {
   Log.v(TAG, "unlink method executing");
   mDbxAcctMgr.unlink();
   callbackContext.success();
 }
 private void link(String message, CallbackContext callbackContext) {
   Log.v(TAG, "link method executing");
   mDbxAcctMgr.startLink(cordova.getActivity(), REQUEST_LINK_TO_DBX);
   callbackContext.success();
 }