List of usage examples for org.json JSONObject JSONObject
public JSONObject()
From source file:org.loklak.server.UserRoles.java
public UserRoles(JSONObject obj) throws Exception { if (obj != null) { json = obj;//from w ww .ja v a 2 s .c o m } else json = new JSONObject(); }
From source file:org.loklak.server.UserRoles.java
private void createDefaultUserRole(BaseUserRole bur) { JSONObject obj = new JSONObject(); UserRole userRole = new UserRole(bur.name().toLowerCase(), bur, null, obj); setDefaultUserRole(bur, userRole);/*ww w. ja va 2 s . c om*/ roles.put(userRole.getName(), userRole); /* this order of putting this at the end makes sure all content from the role gets written to the file. grrr */ json.put(userRole.getName(), obj); }
From source file:org.loklak.server.UserRoles.java
public void setDefaultUserRole(BaseUserRole bur, UserRole ur) { if (!json.has("defaults")) json.put("defaults", new JSONObject()); defaultRoles.put(bur.name(), ur);// w w w . j a va 2 s . c o m json.getJSONObject("defaults").put(bur.name(), ur.getName()); }
From source file:com.commontime.plugin.LocationManager.java
private void createMonitorCallbacks(final CallbackContext callbackContext) { //Monitor callbacks iBeaconManager.setMonitorNotifier(new MonitorNotifier() { @Override/*from w w w . j a va 2s.com*/ public void didEnterRegion(Region region) { debugLog("didEnterRegion INSIDE for " + region.getUniqueId()); dispatchMonitorState("didEnterRegion", MonitorNotifier.INSIDE, region, callbackContext); } @Override public void didExitRegion(Region region) { debugLog("didExitRegion OUTSIDE for " + region.getUniqueId()); dispatchMonitorState("didExitRegion", MonitorNotifier.OUTSIDE, region, callbackContext); } @Override public void didDetermineStateForRegion(int state, Region region) { debugLog("didDetermineStateForRegion '" + nameOfRegionState(state) + "' for region: " + region.getUniqueId()); dispatchMonitorState("didDetermineStateForRegion", state, region, callbackContext); } // Send state to JS callback until told to stop private void dispatchMonitorState(final String eventType, final int state, final Region region, final CallbackContext callbackContext) { threadPoolExecutor.execute(new Runnable() { public void run() { try { JSONObject data = new JSONObject(); data.put("eventType", eventType); data.put("region", mapOfRegion(region)); if (eventType.equals("didDetermineStateForRegion")) { String stateName = nameOfRegionState(state); data.put("state", stateName); } //send and keep reference to callback PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (Exception e) { Log.e(TAG, "'monitoringDidFailForRegion' exception " + e.getCause()); beaconServiceNotifier.monitoringDidFailForRegion(region, e); } } }); } }); }
From source file:com.commontime.plugin.LocationManager.java
private void createRangingCallbacks(final CallbackContext callbackContext) { iBeaconManager.setRangeNotifier(new RangeNotifier() { @Override// w w w.j ava 2s . c o m public void didRangeBeaconsInRegion(final Collection<Beacon> iBeacons, final Region region) { threadPoolExecutor.execute(new Runnable() { public void run() { try { JSONObject data = new JSONObject(); JSONArray beaconData = new JSONArray(); for (Beacon beacon : iBeacons) { beaconData.put(mapOfBeacon(beacon)); } data.put("eventType", "didRangeBeaconsInRegion"); data.put("region", mapOfRegion(region)); data.put("beacons", beaconData); debugLog("didRangeBeacons: " + data.toString()); //send and keep reference to callback PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (Exception e) { Log.e(TAG, "'rangingBeaconsDidFailForRegion' exception " + e.getCause()); beaconServiceNotifier.rangingBeaconsDidFailForRegion(region, e); } } }); } }); }
From source file:com.commontime.plugin.LocationManager.java
private void createManagerCallbacks(final CallbackContext callbackContext) { beaconServiceNotifier = new IBeaconServiceNotifier() { @Override//from ww w . j av a 2s.c o m public void rangingBeaconsDidFailForRegion(final Region region, final Exception exception) { threadPoolExecutor.execute(new Runnable() { public void run() { sendFailEvent("rangingBeaconsDidFailForRegion", region, exception, callbackContext); } }); } @Override public void monitoringDidFailForRegion(final Region region, final Exception exception) { threadPoolExecutor.execute(new Runnable() { public void run() { sendFailEvent("monitoringDidFailForRegionWithError", region, exception, callbackContext); } }); } @Override public void didStartMonitoringForRegion(final Region region) { threadPoolExecutor.execute(new Runnable() { public void run() { try { JSONObject data = new JSONObject(); data.put("eventType", "didStartMonitoringForRegion"); data.put("region", mapOfRegion(region)); debugLog("didStartMonitoringForRegion: " + data.toString()); //send and keep reference to callback PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (Exception e) { Log.e(TAG, "'startMonitoringForRegion' exception " + e.getCause()); monitoringDidFailForRegion(region, e); } } }); } @Override public void didChangeAuthorizationStatus(final String status) { threadPoolExecutor.execute(new Runnable() { public void run() { try { JSONObject data = new JSONObject(); data.put("eventType", "didChangeAuthorizationStatus"); data.put("authorizationStatus", status); debugLog("didChangeAuthorizationStatus: " + data.toString()); //send and keep reference to callback PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (Exception e) { callbackContext.error("didChangeAuthorizationStatus error: " + e.getMessage()); } } }); } private void sendFailEvent(String eventType, Region region, Exception exception, final CallbackContext callbackContext) { try { JSONObject data = new JSONObject(); data.put("eventType", eventType);//not perfect mapping, but it's very unlikely to happen here data.put("region", mapOfRegion(region)); data.put("error", exception.getMessage()); PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (Exception e) { //still failing, so kill all further event dispatch Log.e(TAG, eventType + " error " + e.getMessage()); callbackContext.error(eventType + " error " + e.getMessage()); } } }; }
From source file:com.commontime.plugin.LocationManager.java
private void getAuthorizationStatus(CallbackContext callbackContext) { _handleCallSafely(callbackContext, new ILocationManagerCommand() { @Override/* ww w. ja va 2s. co m*/ public PluginResult run() { try { //Check app has the necessary permissions if (!hasBlueToothPermission()) { return new PluginResult(PluginResult.Status.ERROR, "Application does not BLUETOOTH or BLUETOOTH_ADMIN permissions"); } //Check the Bluetooth service is running String authStatus = iBeaconManager.checkAvailability() ? "AuthorizationStatusAuthorized" : "AuthorizationStatusDenied"; JSONObject result = new JSONObject(); result.put("authorizationStatus", authStatus); return new PluginResult(PluginResult.Status.OK, result); } catch (BleNotAvailableException e) { //if device does not support iBeacons and error is thrown debugLog("'getAuthorizationStatus' Device not supported: " + e.getMessage()); return new PluginResult(PluginResult.Status.ERROR, e.getMessage()); } catch (Exception e) { debugWarn("'getAuthorizationStatus' exception " + e.getMessage()); return new PluginResult(PluginResult.Status.ERROR, e.getMessage()); } } }); }
From source file:com.commontime.plugin.LocationManager.java
private JSONObject mapOfBeaconRegion(Region region) throws JSONException { JSONObject dict = new JSONObject(); // identifier if (region.getUniqueId() != null) { dict.put("identifier", region.getUniqueId()); }//from w w w .j a v a 2s.c o m dict.put("uuid", region.getId1()); if (region.getId2() != null) { dict.put("major", region.getId2()); } if (region.getId3() != null) { dict.put("minor", region.getId3()); } dict.put("typeName", "BeaconRegion"); return dict; }
From source file:com.commontime.plugin.LocationManager.java
private JSONObject mapOfBeacon(Beacon region) throws JSONException { JSONObject dict = new JSONObject(); //beacon id/*from w w w .j a va 2s . c om*/ dict.put("uuid", region.getId1()); dict.put("major", region.getId2()); dict.put("minor", region.getId3()); // proximity dict.put("proximity", nameOfProximity(region.getDistance())); // signal strength and transmission power dict.put("rssi", region.getRssi()); dict.put("tx", region.getTxPower()); // accuracy = rough distance estimate limited to two decimal places (in metres) // NO NOT ASSUME THIS IS ACCURATE - it is effected by radio interference and obstacles dict.put("accuracy", Math.round(region.getDistance() * 100.0) / 100.0); return dict; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.StatusObj.java
public static JSONObject json(String status) { JSONObject obj = new JSONObject(); try {/* w w w . j av a 2 s .c o m*/ obj.put(TEXT, status); } catch (JSONException e) { } return obj; }