List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.mirasense.scanditsdk.plugin.Marshal.java
License:Apache License
public static PluginResult createOkResult(JSONArray args) { PluginResult result = new PluginResult(PluginResult.Status.OK, args); result.setKeepCallback(true);//ww w .java 2 s . c om return result; }
From source file:com.mirasense.scanditsdk.plugin.Marshal.java
License:Apache License
public static PluginResult createFailResult(String message) { PluginResult result = new PluginResult(PluginResult.Status.ERROR, message); result.setKeepCallback(true);/*from www .j av a 2 s .co m*/ return result; }
From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java
License:Apache License
@Override public void onResultByRelay(Bundle bundle) { String barcode = bundle.getString("barcode"); String symbology = bundle.getString("symbology"); JSONArray args = new JSONArray(); args.put(barcode);//from w w w .ja v a2 s . com args.put(symbology); PluginResult result = new PluginResult(Status.OK, args); result.setKeepCallback(true); mCallbackContext.sendPluginResult(result); }
From source file:com.mobiquitynetworks.cordova.mnnotifications.NotificationsManager.java
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { if (action.equals(EVENT_START_MONITORING)) { Log.v(TAG, "EVENT_START_MONITORING"); this.startMonitoring(data, callbackContext); return true; } else if (action.equals(EVENT_REGISTER_CALLBACK)) { Log.v(TAG, "EVENT_REGISTER_CALLBACK"); String event = data.getString(0); Log.v(TAG, event);//from www . j a va 2s . com IntentProxy.setBtListener(this); IntentProxy.setgeoListener(this); PluginResult result = new PluginResult(PluginResult.Status.OK, "Set callback for " + event); result.setKeepCallback(true); this.contexts.put(event, callbackContext); callbackContext.sendPluginResult(result); return true; } return false; }
From source file:com.mobiquitynetworks.cordova.mnnotifications.NotificationsManager.java
private void startMonitoring(JSONArray data, CallbackContext callbackContext) { Log.v(TAG, "CONFIG START"); final Context c = this.cordova.getActivity().getApplicationContext(); Properties p = readSDKProperties(c); //gets configuration String sConfig;/* w w w. jav a2 s . co m*/ sConfig = "\nMobiquity Networks ProximityService configuration:\n" + "_________________________________________________________________\n" + "app key:\t\t" + p.getProperty("mobiquity.apm.appkey") + "\n" + "license:\t\t" + p.getProperty("mobiquity.apm.secret") + "\n" + "monitoring on period:\t" + p.getProperty("mobiquity.apm.monitoring.on_period") + "\n" + "monitoring off period:\t" + p.getProperty("mobiquity.apm.monitoring.off_period") + "\n" + "use idfa:\t\t" + p.getProperty("mobiquity.apm.stats.use_idfa_when_possible") + "\n" + "Endpoint:\t\t" + p.getProperty("mobiquity.apm.network.endpoint") + "\n" + "debug:\t\t" + p.getProperty("mobiquity.apm.debug") + "\n" + "_________________________________________________________________"; Log.v(TAG, sConfig); Log.v(TAG, "CONFIG STOP"); //data: [ // {"tags": ["development","software"], // "gender":"M","birthday":"1986-11-20","username":"matt@aimatt.com","language":"English","kids":2,"maritalStatus":"married" // }, // {"battery":0.2}] Log.v(TAG, "data: " + data.toString()); if (data.length() > 0) { try { JSONObject user = (JSONObject) data.get(0); Log.v(TAG, "user: " + user.toString()); TrackingUser.Builder userBuilder = new TrackingUser.Builder(); userBuilder.role(TrackingUser.Role.PRODUSER); TrackingAudience.Builder audienceBuilder = new TrackingAudience.Builder(); // Username if (user.getString("username") != null) { userBuilder.username(user.getString("username")); } // Gender String gender = user.getString("gender"); if (gender.equals("M")) { audienceBuilder.gender(TrackingAudience.Gender.MALE); } else if (gender.equals("F")) { audienceBuilder.gender(TrackingAudience.Gender.FEMALE); } // Marital Status String maritalStatus = user.getString("maritalStatus"); if (maritalStatus.equals("married")) { audienceBuilder.maritalStatus(TrackingAudience.MaritalStatus.MARRIED); } else if (maritalStatus.equals("single")) { audienceBuilder.maritalStatus(TrackingAudience.MaritalStatus.SINGLE); } // Kids audienceBuilder.kids(user.getInt("kids")); // Tags JSONArray tagsJson = user.getJSONArray("tags"); if (tagsJson != null) { ArrayList<String> tags = new ArrayList<String>(); int len = tagsJson.length(); for (int i = 0; i < len; i++) { tags.add(tagsJson.get(i).toString()); } audienceBuilder.tags(new HashSet<String>(tags)); } // Education String education = user.getString("education"); if (education.equals("CLL")) { audienceBuilder.education(TrackingAudience.Education.COLLEGE); } else if (education.equals("GS")) { audienceBuilder.education(TrackingAudience.Education.GRAD_SCHOOL); } else if (education.equals("NCLL")) { audienceBuilder.education(TrackingAudience.Education.NON_COLLEGE); } // Ethnicity String ethnicity = user.getString("ethnicity"); if (ethnicity.equals("AA")) { audienceBuilder.ethnicity(TrackingAudience.Ethnicity.AFRICAN_AMERICAN); } else if (ethnicity.equals("AS")) { audienceBuilder.ethnicity(TrackingAudience.Ethnicity.ASIAN); } else if (ethnicity.equals("CC")) { audienceBuilder.ethnicity(TrackingAudience.Ethnicity.CAUSASIAN); } else if (ethnicity.equals("HP")) { audienceBuilder.ethnicity(TrackingAudience.Ethnicity.HISPANIC); } // TODO: Language userBuilder.audience(audienceBuilder.build()); final TrackingUser trackingUser = userBuilder.build(); cordova.getThreadPool().execute(new Runnable() { public void run() { ProximityManager.getInstance().setTrackingUserInformation(trackingUser); ProximityManager.getInstance().startService(c); } }); // TODO: Custom Vars // HashMap<String, String> trackingCustomVars = new HashMap<String, String>(); // trackingCustomVars.put("custom1", "foo"); // trackingCustomVars.put("custom2", "bar"); // ProximityManager.setTrackingCustomVars(trackingCustomVars); String message = "startMonitoring success"; PluginResult result = new PluginResult(PluginResult.Status.OK, message.toString()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (JSONException e) { Log.e(TAG, "Exception parsing JSON", e); } } }
From source file:com.mobiquitynetworks.cordova.mnnotifications.NotificationsManager.java
public void onBluetooth(MNBluetoothState state) { Log.v(TAG, "onBluetooth " + state); CallbackContext context = this.contexts.get(EVENT_BLUETOOTH_STATE); if (context != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, state.toString()); context.sendPluginResult(result); }/*from www . j a va 2 s. co m*/ }
From source file:com.mobiquitynetworks.cordova.mnnotifications.NotificationsManager.java
public void onGeo(GeoData geoData) { Log.v(TAG, "onGeo " + geoData.toString()); CallbackContext context = this.contexts.get(EVENT_GEO_INFO); if (context != null) { JSONObject o = new JSONObject(); Venue venue = geoData.getVenue(); try {//from w ww . j a v a2 s. c om JSONObject v = new JSONObject(); v.put("name", venue.getName()); v.put("lat", venue.getLatitude()); v.put("lng", venue.getLongitude()); o.put("venue", v); JSONArray pois = new JSONArray(); if (geoData.getPois() != null) { for (POI poi : geoData.getPois()) { JSONObject p = new JSONObject(); p.put("name", poi.getName()); p.put("type", poi.getType()); pois.put(p); } } o.put("pois", pois); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } PluginResult result = new PluginResult(PluginResult.Status.OK, o.toString()); context.sendPluginResult(result); } }
From source file:com.moodstocks.phonegap.plugin.MoodstocksPlugin.java
License:Open Source License
@Override public void onSyncStart() { Log.d(TAG, "[SYNC] Starting..."); JSONObject obj = new JSONObject(); try {/*from w w w . ja v a2s . co m*/ obj.put(MESSAGE, "Sync starts."); obj.put(STATUS, 1); obj.put(PROGRESS, 0); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(true); this.syncCallback.sendPluginResult(r); }
From source file:com.moodstocks.phonegap.plugin.MoodstocksPlugin.java
License:Open Source License
@Override public void onSyncComplete() { Log.d(TAG, "[SYNC] Complete!"); JSONObject obj = new JSONObject(); try {//w w w. j a va2 s.c o m obj.put(MESSAGE, "Sync completed."); obj.put(STATUS, 3); obj.put(PROGRESS, 100); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(false); this.syncCallback.sendPluginResult(r); }
From source file:com.moodstocks.phonegap.plugin.MoodstocksPlugin.java
License:Open Source License
@Override public void onSyncFailed(MoodstocksError e) { e.log();// w ww . j a va2 s . c o m JSONObject obj = new JSONObject(); try { obj.put(MESSAGE, "Sync failed with error code " + e.getErrorCode()); obj.put(STATUS, 0); obj.put(PROGRESS, 0); } catch (JSONException e1) { e1.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.ERROR, obj); r.setKeepCallback(false); this.syncCallback.sendPluginResult(r); }