List of usage examples for org.apache.cordova.api CallbackContext error
public void error(int message)
From source file:com.giedrius.plugin.LFOpenPlugin.java
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (ACTION_GET_WORKOUT_OBJ.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { //Intent intent = new Intent(Intent.ACTION_EDIT).setType("vnd.android.cursor.item/event"); //this.cordova.getActivity().startActivity(intent); //showCalendar(action, args, callbackContext); //Intent intent = new Intent(cordova.getActivity(), WorkoutActivity.class); //cordova.getActivity().startActivity(intent); //callbackContext.success(); LFOpenEquipmentObserver lfopen = new LFOpenEquipmentObserver(); JSONObject workoutJsonObj = new JSONObject(); WorkoutStream workoutObj = lfopen.getWorkoutObj(); // put workout details into JSON object try { workoutJsonObj.put("accumulatedCalories", getRoundedValue(workoutObj.getAccumulatedCalories())); workoutJsonObj.put("accumulatedDistance", getRoundedValue(workoutObj.getAccumulatedDistance())); workoutJsonObj.put("accumulatedDistanceClimbed", getRoundedValue(workoutObj.getAccumulatedDistanceClimbed())); workoutJsonObj.put("currentHeartRate", getRoundedValue(workoutObj.getCurrentHeartRate())); workoutJsonObj.put("currentIncline", getRoundedValue(workoutObj.getCurrentIncline())); workoutJsonObj.put("currentLevel", getRoundedValue(workoutObj.getCurrentLevel())); workoutJsonObj.put("currentResistance", getRoundedValue(workoutObj.getCurrentResistance())); workoutJsonObj.put("currentSpeed", getRoundedValue(workoutObj.getCurrentSpeed())); workoutJsonObj.put("currentSpeedRPM", getRoundedValue(workoutObj.getCurrentSpeedRPM())); workoutJsonObj.put("targetCalories", getRoundedValue(workoutObj.getTargetCalories())); workoutJsonObj.put("targetDistance", getRoundedValue(workoutObj.getTargetDistance())); workoutJsonObj.put("targetDistanceClibmed", getRoundedValue(workoutObj.getTargetDistanceClibmed())); workoutJsonObj.put("targetHeartRate", getRoundedValue(workoutObj.getTargetHeartRate())); workoutJsonObj.put("targetIncline", getRoundedValue(workoutObj.getTargetIncline())); workoutJsonObj.put("targetSpeed", getRoundedValue(workoutObj.getTargetSpeed())); workoutJsonObj.put("targetWorkoutSeconds", getRoundedValue(workoutObj.getTargetWorkoutSeconds())); workoutJsonObj.put("workoutElapseSeconds", getRoundedValue(workoutObj.getWorkoutElapseSeconds())); workoutJsonObj.put("workoutState", workoutObj.getWorkoutState()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }/*ww w. j a va 2 s.co m*/ callbackContext.sendPluginResult(new PluginResult(Status.OK, workoutJsonObj)); //callbackContext.success(); } }); return true; } callbackContext.error("Invalid action"); return false; }
From source file:com.giedrius.plugin.LFOpenPlugin.java
public boolean showCalendar(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {/* w ww .j av a 2s . c om*/ if (ACTION_GET_WORKOUT_OBJ.equals(action)) { JSONObject arg_object = args.getJSONObject(0); Intent calIntent = new Intent(Intent.ACTION_EDIT).setType("vnd.android.cursor.item/event") .putExtra("beginTime", arg_object.getLong("startTimeMillis")) .putExtra("endTime", arg_object.getLong("endTimeMillis")) .putExtra("title", arg_object.getString("title")) .putExtra("description", arg_object.getString("description")) .putExtra("eventLocation", arg_object.getString("eventLocation")); this.cordova.getActivity().startActivity(calIntent); callbackContext.success(); return true; } callbackContext.error("Invalid action"); return false; } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); return false; } }
From source file:com.google.cordova.ChromeAlarms.java
License:Open Source License
private void create(final CordovaArgs args, final CallbackContext callbackContext) { try {//from w w w . ja va2s . co m String name = args.getString(0); Alarm alarm = new Alarm(name, (long) args.getDouble(1), (long) (args.optDouble(2) * 60000)); PendingIntent alarmPendingIntent = makePendingIntentForAlarm(name, PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.cancel(alarmPendingIntent); if (alarm.periodInMillis == 0) { alarmManager.set(AlarmManager.RTC_WAKEUP, alarm.scheduledTime, alarmPendingIntent); } else { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarm.scheduledTime, alarm.periodInMillis, alarmPendingIntent); } callbackContext.success(); } catch (Exception e) { Log.e(LOG_TAG, "Could not create alarm", e); callbackContext.error("Could not create alarm"); } }
From source file:com.google.cordova.ChromeAlarms.java
License:Open Source License
private void clear(final CordovaArgs args, final CallbackContext callbackContext) { try {// ww w.j av a 2 s. c o m JSONArray alarmNames = args.getJSONArray(0); for (int i = 0; i < alarmNames.length(); i++) { cancelAlarm(alarmNames.getString(i)); } callbackContext.success(); } catch (Exception e) { Log.e(LOG_TAG, "Could not clear alarm", e); callbackContext.error("Could not create alarm"); } }
From source file:com.google.cordova.ChromeI18n.java
License:Open Source License
private void getAcceptLanguages(final CordovaArgs args, final CallbackContext callbackContext) { try {/* w ww .j av a 2s. c o m*/ JSONArray ret = new JSONArray(); Locale locale = Locale.getDefault(); String localString = locale.toString().replace('_', '-'); ret.put(localString); callbackContext.success(ret); } catch (Exception e) { callbackContext.error("Could not retrieve supported locales"); Log.e(LOG_TAG, "Could not retrieve supported locales", e); } }
From source file:com.google.cordova.ChromeIdentity.java
License:Open Source License
private void getAuthTokenCallback(String token, CallbackContext callbackContext) { if (token.trim().equals("")) { callbackContext.error("Could not get auth token"); } else {/*from w w w . ja va2s .co m*/ callbackContext.success(token); } }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void connect(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); String address = args.getString(1); int port = args.getInt(2); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;/*from w w w.ja v a 2s . c o m*/ } boolean success = sd.connect(address, port); if (success) callbackContext.success(); else callbackContext.error("Failed to connect"); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void bind(CordovaArgs args, final CallbackContext context) throws JSONException { int socketId = args.getInt(0); String address = args.getString(1); int port = args.getInt(2); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;/*from ww w. j av a 2 s . c o m*/ } boolean success = sd.bind(address, port); if (success) context.success(); else context.error("Failed to bind."); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void listen(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;/*from w w w . j a v a2 s .c o m*/ } String address = args.getString(1); int port = args.getInt(2); int backlog = args.getInt(3); boolean success = sd.listen(address, port, backlog); if (success) callbackContext.success(); else callbackContext.error("Failed to listen()"); }
From source file:com.google.cordova.ChromeStorage.java
License:Open Source License
private void get(final CordovaArgs args, final CallbackContext callbackContext) { executorService.execute(new Runnable() { @Override//from w w w . jav a2 s . c o m public void run() { JSONObject storage = getStoredValuesForKeys(args, /*useDefaultValues*/ true); if (storage == null) { callbackContext.error("Could not retrieve storage"); } else { callbackContext.success(storage); } } }); }