List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:de.dmxcontrol.model.BaseModel.java
protected void SendData(String propertyType, Object valueType, Object value) throws JSONException { JSONArray array = new JSONArray(); for (int i = 0; i < ReceivedData.get().Devices.size(); i++) { if (getEntitySelection().contains(EntityManager.Type.DEVICE, ReceivedData.get().Devices.get(i).getId())) { array.put(ReceivedData.get().Devices.get(i).guid); }/*from w w w. jav a2s . c o m*/ } for (int i = 0; i < ReceivedData.get().Groups.size(); i++) { if (getEntitySelection().contains(EntityManager.Type.GROUP, ReceivedData.get().Groups.get(i).getId())) { array.put(ReceivedData.get().Groups.get(i).guid); } } JSONObject o = new JSONObject(); o.put("Type", "PropertyValue"); o.put("GUIDs", array); o.put("PropertyType", propertyType); o.put("ValueType", valueType); o.put("Value", value); ServiceFrontend.get().sendMessage(o.toString().getBytes()); }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainPoll.java
/** * Parse an announcement./* w ww.j a v a 2 s . co m*/ * @param jid service that sent the announcement. * @param xml raw XML of announcement to store in SQLite. * @param root parsed XML root DOM element. * @throws JSONException if a parsing error occurs. */ CapptainPoll(String jid, String xml, Element root) throws JSONException { super(jid, xml, root); mAnswers = new Bundle(); mQuestions = new JSONArray(); NodeList questions = root.getElementsByTagNameNS(REACH_NAMESPACE, "question"); for (int i = 0; i < questions.getLength(); i++) { Element questionE = (Element) questions.item(i); NodeList choicesN = questionE.getElementsByTagNameNS(REACH_NAMESPACE, "choice"); JSONArray choicesJ = new JSONArray(); for (int j = 0; j < choicesN.getLength(); j++) { Element choiceE = (Element) choicesN.item(j); JSONObject choiceJ = new JSONObject(); choiceJ.put("id", choiceE.getAttribute("id")); choiceJ.put("title", XmlUtil.getText(choiceE)); choiceJ.put("default", Boolean.parseBoolean(choiceE.getAttribute("default"))); choicesJ.put(choiceJ); } JSONObject questionJ = new JSONObject(); questionJ.put("id", questionE.getAttribute("id")); questionJ.put("title", XmlUtil.getTagText(questionE, "title", null)); questionJ.put("choices", choicesJ); mQuestions.put(questionJ); } }
From source file:org.seadpdt.impl.SearchServiceImpl.java
private Response getAllPublishedROs(Document filter, Date start, Date end, String creatorRegex) { FindIterable<Document> iter = publicationsCollection.find(filter); setROProjection(iter);// ww w. ja v a 2 s.co m MongoCursor<Document> cursor = iter.iterator(); JSONArray array = new JSONArray(); while (cursor.hasNext()) { Document document = cursor.next(); reArrangeDocument(document); if (withinDateRange(document.getString("Publication Date"), start, end) && creatorMatch(document.get("Creator"), creatorRegex)) { array.put(JSON.parse(document.toJson())); } } return Response.ok(array.toString()).cacheControl(control).build(); }
From source file:org.bcsphere.bluetooth.BluetoothSam42.java
@Override public void getConnectedDevices(JSONArray json, CallbackContext callbackContext) { Log.i(TAG, "getConnectedDevices"); if (!isInitialized(callbackContext)) { return;//from ww w . j a v a 2 s. c o m } @SuppressWarnings("unchecked") List<BluetoothDevice> bluetoothDevices = bluetoothGatt.getConnectedDevices(); JSONArray jsonDevices = new JSONArray(); for (BluetoothDevice device : bluetoothDevices) { JSONObject jsonDevice = new JSONObject(); Tools.addProperty(jsonDevice, Tools.DEVICE_ADDRESS, device.getAddress()); Tools.addProperty(jsonDevice, Tools.DEVICE_NAME, device.getName()); jsonDevices.put(jsonDevice); } callbackContext.success(jsonDevices); }
From source file:org.bcsphere.bluetooth.BluetoothSam42.java
@Override public void getCharacteristics(JSONArray json, CallbackContext callbackContext) { Log.i(TAG, "getCharacteristics"); if (!isInitialized(callbackContext)) { return;/*from w w w .java 2s .c o m*/ } String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS); String serviceIndex = Tools.getData(json, Tools.SERVICE_INDEX); String[] args = new String[] { deviceAddress, serviceIndex }; if (!isNullOrEmpty(args, callbackContext)) { return; } BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress); if (!isConnected(device)) { Tools.sendErrorMsg(callbackContext); return; } if (serviceIndex == null) { Tools.sendErrorMsg(callbackContext); return; } JSONObject jsonObject = new JSONObject(); Tools.addProperty(jsonObject, Tools.DEVICE_ADDRESS, deviceAddress); JSONArray characteristics = new JSONArray(); int size = getService(deviceAddress, serviceIndex).getCharacteristics().size(); for (int i = 0; i < size; i++) { BluetoothGattCharacteristic bluetoothGattCharacteristic = getCharacteristic(deviceAddress, serviceIndex, String.valueOf(i)); UUID charateristicUUID = bluetoothGattCharacteristic.getUuid(); JSONObject characteristic = new JSONObject(); Tools.addProperty(characteristic, Tools.CHARACTERISTIC_INDEX, i); Tools.addProperty(characteristic, Tools.CHARACTERISTIC_UUID, charateristicUUID); Tools.addProperty(characteristic, Tools.CHARACTERISTIC_NAME, Tools.lookup(charateristicUUID)); Tools.addProperty(characteristic, Tools.CHARACTERISTIC_PROPERTY, Tools.decodeProperty(bluetoothGattCharacteristic.getProperties())); characteristics.put(characteristic); } Tools.addProperty(jsonObject, Tools.CHARACTERISTICS, characteristics); callbackContext.success(jsonObject); }
From source file:org.bcsphere.bluetooth.BluetoothSam42.java
@Override public void getDescriptors(JSONArray json, CallbackContext callbackContext) { Log.i(TAG, "getDescriptors"); if (!isInitialized(callbackContext)) { return;/* w w w. j av a2s . c o m*/ } String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS); String serviceIndex = Tools.getData(json, Tools.SERVICE_INDEX); String characteristicIndex = Tools.getData(json, Tools.CHARACTERISTIC_INDEX); String[] args = new String[] { deviceAddress, serviceIndex, characteristicIndex }; if (!isNullOrEmpty(args, callbackContext)) { return; } BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress); if (!isConnected(device)) { Tools.sendErrorMsg(callbackContext); return; } JSONObject jsonObject = new JSONObject(); Tools.addProperty(jsonObject, Tools.DEVICE_ADDRESS, deviceAddress); JSONArray descriptors = new JSONArray(); @SuppressWarnings("unchecked") List<BluetoothGattDescriptor> listBluetoothGattDescriptors = getCharacteristic(deviceAddress, serviceIndex, characteristicIndex).getDescriptors(); int length = listBluetoothGattDescriptors.size(); for (int i = 0; i < length; i++) { UUID uuid = listBluetoothGattDescriptors.get(i).getUuid(); JSONObject descriptor = new JSONObject(); Tools.addProperty(descriptor, Tools.DESCRIPTOR_INDEX, i); Tools.addProperty(descriptor, Tools.DESCRIPTOR_UUID, uuid); Tools.addProperty(descriptor, Tools.DESCRIPTOR_NAME, Tools.lookup(uuid)); descriptors.put(descriptor); } Tools.addProperty(jsonObject, Tools.DESCRIPTORS, descriptors); callbackContext.success(jsonObject); }
From source file:co.edu.uniajc.vtf.ar.ARViewActivity.java
private JSONArray createJsonArray(ArrayList<PointOfInterestEntity> loPoints) { final JSONArray loPois = new JSONArray(); for (PointOfInterestEntity point : loPoints) { final HashMap<String, String> loPoiInformation = new HashMap<String, String>(); loPoiInformation.put("id", String.valueOf(point.getId())); loPoiInformation.put("longitude", String.valueOf(point.getLongitude())); loPoiInformation.put("latitude", String.valueOf(point.getLatitude())); loPoiInformation.put("altitude", String.valueOf(point.getAltitude())); loPoiInformation.put("distance", "0"); loPoiInformation.put("type", String.valueOf(point.getSiteType())); loPoiInformation.put("title", point.getTitle()); loPoiInformation.put("description", point.getDescription()); loPois.put(new JSONObject(loPoiInformation)); }/*from w ww. j ava2s .c o m*/ return loPois; }
From source file:produvia.com.scanner.DevicesActivity.java
public void promptLogin(final JSONObject loginService, final JSONObject responseData) { runOnUiThread(new Runnable() { public void run() { try { String type = loginService.getString("type"); //there was a login error. login again if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) { //prompt for username and password and retry: promptUsernamePassword(loginService, responseData, false, null); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) { promptUsernamePassword(loginService, responseData, true, loginService.getString("description")); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) { //prompt for username and password and retry: int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout") : 15;/*www. j av a 2s. c om*/ final AlertDialog alertDialog = new AlertDialog.Builder(DevicesActivity.this).create(); alertDialog.setTitle(loginService.getString("description")); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + countdown + " seconds..."); alertDialog.show(); // new CountDownTimer(countdown * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { try { alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + millisUntilFinished / 1000 + " seconds..."); } catch (JSONException e) { } } @Override public void onFinish() { alertDialog.dismiss(); new Thread(new Runnable() { public void run() { try { JSONArray services = new JSONArray(); services.put(loginService); responseData.put("services", services); WeaverSdkApi.servicesSet(DevicesActivity.this, responseData); } catch (JSONException e) { } } }).start(); } }.start(); } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:produvia.com.scanner.DevicesActivity.java
public void promptUsernamePassword(final JSONObject loginService, final JSONObject responseData, final boolean isKey, String description) throws JSONException { LayoutInflater li = LayoutInflater.from(DevicesActivity.this); View promptsView = li.inflate(R.layout.prompt_userpass, null); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DevicesActivity.this); alertDialogBuilder.setView(promptsView); final EditText userInput = (EditText) promptsView.findViewById(R.id.pu_username); final EditText passInput = (EditText) promptsView.findViewById(R.id.pu_password); //if it's a key type input hide the password field: if (isKey) {//from w ww . j a v a2s . c om passInput.setVisibility(View.GONE); userInput.setText(loginService.getJSONObject("properties").getString("key")); userInput.setHint("Enter key"); } else { userInput.setText(loginService.getJSONObject("properties").getString("username")); passInput.setText(loginService.getJSONObject("properties").getString("password")); } final TextView prompt_user_pass = (TextView) promptsView.findViewById(R.id.user_pass_title); String name = responseData.getJSONObject("devices_info").getJSONObject(loginService.getString("device_id")) .getString("name"); String message; if (description == null) { message = "Enter " + name + "'s username and password."; } else { message = description; } message += "\n(if it's disconnected just press cancel)"; prompt_user_pass.setText(message); // set dialog message alertDialogBuilder.setCancelable(false).setNegativeButton("Go", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String username = (userInput.getText()).toString(); String password = (passInput.getText()).toString(); try { if (isKey) { loginService.getJSONObject("properties").put("key", username); } else { loginService.getJSONObject("properties").put("username", username); loginService.getJSONObject("properties").put("password", password); } //stick the service into the response data structure and set the service: JSONArray services = new JSONArray(); services.put(loginService); responseData.put("services", services); WeaverSdkApi.servicesSet(DevicesActivity.this, responseData); } catch (JSONException e) { } } }).setPositiveButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:com.phonegap.DroidGap.java
/** * Load the url into the webview./* ww w .j av a2 s . c o m*/ * * @param url */ public void loadUrl(final String url) { System.out.println("loadUrl(" + url + ")"); this.url = url; int i = url.lastIndexOf('/'); if (i > 0) { this.baseUrl = url.substring(0, i); } else { this.baseUrl = this.url; } System.out.println("url=" + url + " baseUrl=" + baseUrl); mydialog = ProgressDialog.show(this, "su...", "Loading", true); // Load URL on UI thread final DroidGap me = this; this.runOnUiThread(new Runnable() { public void run() { // Handle activity parameters me.handleActivityParameters(); // Initialize callback server me.callbackServer.init(url); // If loadingDialog, then show the App loading dialog String loading = me.getStringProperty("loadingDialog", null); if (loading != null) { String title = ""; String message = "Loading Application..."; if (loading.length() > 0) { int comma = loading.indexOf(','); if (comma > 0) { title = loading.substring(0, comma); message = loading.substring(comma + 1); } else { title = ""; message = loading; } } JSONArray parm = new JSONArray(); parm.put(title); parm.put(message); me.pluginManager.exec("Notification", "activityStart", null, parm.toString(), false); } // Create a timeout timer for loadUrl final int currentLoadUrlTimeout = me.loadUrlTimeout; Runnable runnable = new Runnable() { public void run() { try { synchronized (this) { wait(me.loadUrlTimeoutValue); } } catch (InterruptedException e) { e.printStackTrace(); } // If timeout, then stop loading and handle error if (me.loadUrlTimeout == currentLoadUrlTimeout) { me.appView.stopLoading(); me.webViewClient.onReceivedError(me.appView, -6, "The connection to the server was unsuccessful.", url); } } }; Thread thread = new Thread(runnable); thread.start(); me.appView.loadUrl(url); } }); }