List of usage examples for org.json JSONArray JSONArray
public JSONArray(Object array) throws JSONException
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
public void dropdownState() throws JSONException { RequestParams params = null;// ww w . j a v a2s .c om params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "OCRD"); jsonObject.put("FieldName", "STATE"); params.put("sJsonInput", jsonObject.toString()); RestService.post(METHOD_PROPERTY_STATE, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("State Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonliststate = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonliststate.add(proList); System.out.println("JSON STATE LIST"); System.out.println(jsonliststate); } // Spinner set Array Data in Drop down sAdaparea = new SimpleAdapter(AddCaseStep2of4.this, jsonliststate, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertySTATE.setAdapter(sAdaparea); for (int j = 0; j < jsonliststate.size(); j++) { if (jsonliststate.get(j).get("Id_T").equals(statevalue)) { spinnerpropertySTATE.setSelection(j); break; } } } catch (JSONException e) { // TODO Auto-generated // catc // block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("State Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
public void dropdownPorject() { RequestParams params = null;//from w w w . j a v a2 s. com params = new RequestParams(); RestService.post(METHOD_PROPERTY_LIST_DROPDOWN, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("property Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonlistProject = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonlistProject.add(proList); System.out.println("JSON PROPERTY LIST"); System.out.println(jsonlistProject); } // Spinner set Array Data in Drop down sAdapPROJ = new SimpleAdapter(AddCaseStep2of4.this, jsonlistProject, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertyPROJECT.setAdapter(sAdapPROJ); for (int j = 0; j < jsonlistProject.size(); j++) { if (jsonlistProject.get(j).get("Id_T").equals(projectDetailResponse)) { spinnerpropertyPROJECT.setSelection(j); break; } } } catch (JSONException e) { // TODO Auto-generated // catc // block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Property Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:org.dasein.cloud.benchmark.Suite.java
static public void main(String... args) throws Exception { ArrayList<Map<String, Object>> suites = new ArrayList<Map<String, Object>>(); ArrayList<Map<String, Object>> tests = new ArrayList<Map<String, Object>>(); for (String suiteFile : args) { HashMap<String, Object> suite = new HashMap<String, Object>(); ArrayList<Benchmark> benchmarks = new ArrayList<Benchmark>(); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(suiteFile))); StringBuilder json = new StringBuilder(); String line;//w w w . j ava 2 s . c o m while ((line = reader.readLine()) != null) { json.append(line); json.append("\n"); } JSONObject ob = new JSONObject(json.toString()); suite.put("name", ob.getString("name")); suite.put("description", ob.getString("description")); JSONArray benchmarkClasses = ob.getJSONArray("benchmarks"); for (int i = 0; i < benchmarkClasses.length(); i++) { String cname = benchmarkClasses.getString(i); benchmarks.add((Benchmark) Class.forName(cname).newInstance()); } JSONArray clouds = ob.getJSONArray("clouds"); for (int i = 0; i < clouds.length(); i++) { JSONObject cloud = clouds.getJSONObject(i); if (cloud.has("regions")) { JSONObject regions = cloud.getJSONObject("regions"); String[] regionIds = JSONObject.getNames(regions); if (regionIds != null) { for (String regionId : regionIds) { final JSONObject regionCfg = regions.getJSONObject(regionId); String cname = cloud.getString("providerClass"); CloudProvider provider = (CloudProvider) Class.forName(cname).newInstance(); JSONObject ctxCfg = cloud.getJSONObject("context"); ProviderContext ctx = new ProviderContext(); ctx.setEndpoint(regionCfg.getString("endpoint")); ctx.setAccountNumber(ctxCfg.getString("accountNumber")); ctx.setRegionId(regionId); if (ctxCfg.has("accessPublic")) { ctx.setAccessPublic(ctxCfg.getString("accessPublic").getBytes("utf-8")); } if (ctxCfg.has("accessPrivate")) { ctx.setAccessPrivate(ctxCfg.getString("accessPrivate").getBytes("utf-8")); } ctx.setCloudName(ctxCfg.getString("cloudName")); ctx.setProviderName(ctxCfg.getString("providerName")); if (ctxCfg.has("x509Cert")) { ctx.setX509Cert(ctxCfg.getString("x509Cert").getBytes("utf-8")); } if (ctxCfg.has("x509Key")) { ctx.setX509Key(ctxCfg.getString("x509Key").getBytes("utf-8")); } if (ctxCfg.has("customProperties")) { JSONObject p = ctxCfg.getJSONObject("customProperties"); String[] names = JSONObject.getNames(p); if (names != null) { Properties props = new Properties(); for (String name : names) { String value = p.getString(name); if (value != null) { props.put(name, value); } } ctx.setCustomProperties(props); } } provider.connect(ctx); Suite s = new Suite(benchmarks, provider); tests.add(s.runBenchmarks(regionCfg)); } } } } suite.put("benchmarks", tests); suites.add(suite); } System.out.println((new JSONArray(suites)).toString()); }
From source file:com.iespuig.attendancemanager.StudentFetchr.java
public ArrayList<Student> fetchStudent(Classblock classBlock) { ArrayList<Student> items = new ArrayList<Student>(); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(context); String schoolName = SP.getString(("schoolName"), ""); String urlServer = SP.getString("urlServer", ""); Format formatter = new SimpleDateFormat("ddMMyyyy"); try {/*from w w w . j a v a 2 s . com*/ String url = Uri.parse(urlServer).buildUpon().appendQueryParameter("action", ACTION_GET_STUDENTS) .appendQueryParameter("school", schoolName) .appendQueryParameter("login", User.getInstance().getLogin()) .appendQueryParameter("password", User.getInstance().getPassword()) .appendQueryParameter("idGroup", String.valueOf(classBlock.getIdGroup())) .appendQueryParameter("idClassBlock", String.valueOf(classBlock.getId())) .appendQueryParameter("date", formatter.format(classBlock.getDate())).build().toString(); Log.i(TAG, "url: " + url); String data = AtmNet.getUrl(url); Log.i(TAG, "url: " + data); JSONObject jsonObject = new JSONObject(data); JSONArray jsonArray = new JSONArray(jsonObject.getString("data")); for (int i = 0; i < jsonArray.length(); i++) { JSONObject row = jsonArray.getJSONObject(i); Student item = new Student(); item.setId(row.getInt("id")); item.setFullname(row.getString("fullname")); item.setName(row.getString("name")); item.setSurname1(row.getString("surname1")); item.setSurname2(row.getString("surname2")); item.setMissType(0); item.setNotMaterial(false); item.setNetworkTransit(false); if (row.has("misses")) { JSONArray misses = row.getJSONArray("misses"); for (int j = 0; j < misses.length(); j++) { int miss = misses.getInt(j); if (miss > NOT_MISS && miss <= EXPULSION) { item.setMissType(miss); } if (miss == NOT_MATERIAL) item.setNotMaterial(true); } } items.add(item); } } catch (IOException ioe) { Log.e(TAG, "Failed to fetch items", ioe); } catch (JSONException je) { Log.e(TAG, "Failed to parse JSON", je); } return items; }
From source file:org.restcomm.app.utillib.Reporters.WebReporter.WebReporter.java
public static String geocode(Context context, double latitude, double longitude) { String addressString = String.format("%.4f, %.4f", latitude, longitude); try {/*from w ww . j a v a 2 s . c o m*/ String apiKey = Global.getApiKey(context); String server = Global.getApiUrl(context); String url = server + "/api/osm/location?apiKey=" + apiKey + "&location=" + latitude + "&location=" + longitude; String response = WebReporter.getHttpURLResponse(url, false); JSONObject json = null; JSONArray jsonArray = null; if (response == null) return addressString; try { jsonArray = new JSONArray(response); } catch (JSONException e) { return addressString; } try { for (int i = 0; i < jsonArray.length(); i++) { json = jsonArray.getJSONObject(i); if (json.has("error")) { String error = json.getString("error"); return null; } else { addressString = ""; json = json.getJSONObject("address"); String number = ""; if (json.has("house_number")) { number = json.getString("house_number"); addressString += number + " "; } String road = json.getString("road"); addressString += road;// + suburb; return addressString; } } } catch (JSONException e) { e.printStackTrace(); } } catch (Exception e) { } return addressString; }
From source file:com.google.samples.apps.friendlyping.gcm.MyGcmListenerService.java
private ArrayList<Pinger> getPingers(Bundle data) throws JSONException { final JSONArray clients = new JSONArray(data.getString("clients")); ArrayList<Pinger> pingers = new ArrayList<>(clients.length()); for (int i = 0; i < clients.length(); i++) { JSONObject jsonPinger = clients.getJSONObject(i); pingers.add(Pinger.fromJson(jsonPinger)); }/*www.ja va 2 s . c o m*/ return pingers; }
From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { mActivity.setOnLifeCycleChangeListener(this); isChanged = isCloud = false;//from w w w .j av a 2s. c o m // Override the default content view. root = (ViewGroup) super.onCreateView(inflater, container, bundle); final ImageView moreAlarm = (ImageView) root.findViewById(R.id.more_alarm); FragmentChangeActivity.moreAlarm = moreAlarm; moreAlarm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (menu.isMenuShowing()) { menu.showContent(); } else { menu.showMenu(true); } } }); // Make the entire view selected when focused. moreAlarm.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { v.setSelected(hasFocus); } }); addPreferencesFromResource(R.xml.alarm_prefs); myUUID = SplashActivity.myUUID; // Get each preference so we can retrieve the value later. mLabel = findPreference("label"); mLabel.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showEditTextPreference(mLabel.getKey(), mLabel.getTitle(), mLabelText); return true; } }); Preference.OnPreferenceChangeListener preferceChangedListener = new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference p, Object newValue) { isChanged = true; return true; } }; mEnabledPref = (CheckBoxPreference) findPreference("enabled"); mEnabledPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!isCloud) { isChanged = true; if ((Boolean) newValue) showCategory(); else hideCategory(); return true; } if ((Boolean) newValue) { try { tempjson = new JSONArray("[]"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } selectedDevice = ""; for (int i = 0; i < json.length(); i++) { if (UIDitems[i].toString().equals(myUUID)) checkedItems[i] = true; if (checkedItems[i]) { Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } if (!selectedDevice.equals("")) selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2); } else { try { tempjson = new JSONArray("[]"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } selectedDevice = ""; for (int i = 0; i < json.length(); i++) { if (UIDitems[i].toString().equals(myUUID)) checkedItems[i] = false; if (checkedItems[i]) { Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } if (!selectedDevice.equals("")) selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2); } mForest.setSummary(selectedDevice); isChanged = true; return true; } }); mTimePref = findPreference("time"); mVibratePref = (CheckBoxPreference) findPreference("vibrate"); mVibratePref.setOnPreferenceChangeListener(preferceChangedListener); mRepeatPref = findPreference("setRepeat"); mRepeatPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String[] values = new String[] { DateUtils.getDayOfWeekString(Calendar.MONDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.TUESDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.WEDNESDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.THURSDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.FRIDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.SATURDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.SUNDAY, DateUtils.LENGTH_LONG) }; Intent intent = new Intent(mActivity, RepeatListPreference.class); intent.putExtra("key", mRepeatPref.getKey()); intent.putExtra("title", mRepeatPref.getTitle()); intent.putExtra("lists", values); intent.putExtra("multi", true); startActivity(intent); return true; } }); mForestName = findPreference("forest_name"); mForest = findPreference("forest"); mColorPref = (AmbilWarnaPreference) findPreference("color"); prefs = mActivity.getSharedPreferences("forest", mActivity.MODE_PRIVATE); Intent i = mActivity.setAlarmGetIntent; mId = i.getIntExtra(Alarms.ALARM_ID, -1); alarm = null; if (mId == -1) { // No alarm id means create a new alarm. alarm = new Alarm(); isChanged = true; } else { // * load alarm details from database alarm = Alarms.getAlarm(mActivity.getContentResolver(), mId); // Bad alarm, bail to avoid a NPE. if (alarm == null) { finish(); return root; } isCloud = wasCloud = alarm.cloudEnabled; } mOriginalAlarm = alarm; if (wasCloud) { try { Log.e("url", " : " + alarm.cloudName); json = new JSONArray(prefs.getString(alarm.cloudName + "_registeredDevice", "")); String cloud_uid = alarm.cloudUID; if (cloud_uid.equals("")) cloud_uid = "[]"; Log.e("url", cloud_uid); tempjson = new JSONArray(cloud_uid); items = new String[json.length()]; UIDitems = new CharSequence[json.length()]; checkedItems = new boolean[json.length()]; for (int j = 0; j < json.length(); j++) { JSONObject jsonObj = json.getJSONObject(j); items[j] = jsonObj.getString("name"); UIDitems[j] = jsonObj.getString("uid"); checkedItems[j] = alarm.cloudUID.contains(jsonObj.getString("uid")); } } catch (Exception e) { Log.e("url", e.toString()); } selectedDevice = alarm.cloudDevices; mForestName.setEnabled(false); } else { if (prefs.getString("name", "").length() > 0) { names = prefs.getString("name", "").substring(1).split("\\|"); nameCheckedIndex = -1; } else mForestName.setEnabled(false); mForest.setEnabled(false); } memi_count = alarm.memiCount; snooze_strength = alarm.snoozeStrength; snooze_count = alarm.snoozeCount; updatePrefs(mOriginalAlarm); mTimePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { showTimePicker(); return false; } }); mForestName.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showListPreference(mForestName.getKey(), mForestName.getTitle(), names, String.valueOf(nameCheckedIndex), false); return true; } }); mForest.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { showListPreference(mForest.getKey(), mForest.getTitle(), items, booleanArrayToString(checkedItems), true); return true; } }); mColorPref.setOnPreferenceChangeListener(preferceChangedListener); // We have to do this to get the save/cancel buttons to highlight on // their own. ((ListView) root.findViewById(android.R.id.list)).setItemsCanFocus(true); // Attach actions to each button. View.OnClickListener back_click = new View.OnClickListener() { public void onClick(View v) { DontSaveDialog(false, null, false); } }; ImageView b = (ImageView) root.findViewById(R.id.back); b.setOnClickListener(back_click); b = (ImageView) root.findViewById(R.id.logo); b.setOnClickListener(back_click); b = (ImageView) root.findViewById(R.id.alarm_save); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { saveAlarm(); } }); b = (ImageView) root.findViewById(R.id.alarm_delete); if (mId == -1) { b.setEnabled(false); } else { b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { deleteAlarm(); } }); } // The last thing we do is pop the time picker if this is a new alarm. if (mId == -1) { // Assume the user hit cancel mTimePickerCancelled = true; showTimePicker(); } if (!isCloud && !alarm.enabled) hideCategory(); FragmentChangeActivity.OnNotifyArrived.sendEmptyMessage(0); return root; }
From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java
public static void onActivityResult(String key, String which_str) { if (mForestName.getKey().equals(key)) { int which = Integer.parseInt(which_str); mForestName.setSummary(names[which]); String json_string = prefs.getString(names[which] + "_registeredDevice", ""); if (json_string.equals("")) json_string = "[]"; try {// ww w. ja va2 s.c o m json = new JSONArray(json_string); tempjson = new JSONArray("[]"); items = new String[json.length()]; UIDitems = new CharSequence[json.length()]; checkedItems = new boolean[json.length()]; for (int j = 0; j < json.length(); j++) { JSONObject jsonObj = json.getJSONObject(j); items[j] = jsonObj.getString("name"); UIDitems[j] = jsonObj.getString("uid"); checkedItems[j] = alarm.cloudUID.contains(jsonObj.getString("uid")); } } catch (JSONException e) { e.printStackTrace(); } nameCheckedIndex = which; selectedDevice = ""; if (mEnabledPref.isChecked()) { for (int i = 0; i < json.length(); i++) { if (UIDitems[i].toString().equals(myUUID)) checkedItems[i] = true; if (checkedItems[i]) { Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } } else { for (int i = 0; i < json.length(); i++) { if (UIDitems[i].toString().equals(myUUID)) checkedItems[i] = false; if (checkedItems[i]) { Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } } if (!selectedDevice.equals("")) selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2); mForest.setSummary(selectedDevice); mForest.setEnabled(true); isChanged = isCloud = true; } else if (mForest.getKey().equals(key)) { String[] str_array = which_str.split("\\|"); boolean[] values = new boolean[str_array.length]; for (int i = 0; i < str_array.length; i++) { values[i] = str_array[i].equals("1"); } checkedItems = values; boolean hasMyDevice = false; try { tempjson = new JSONArray("[]"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } selectedDevice = ""; for (int i = 0; i < json.length(); i++) { if (values[i]) { if (UIDitems[i].toString().equals(myUUID)) hasMyDevice = true; Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } if (!selectedDevice.equals("")) selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2); mForest.setSummary(selectedDevice); mEnabledPref.setChecked(hasMyDevice); isChanged = true; } else if (mLabel.getKey().equals(key)) { mLabelText = which_str; mLabel.setSummary(which_str); isChanged = true; } }
From source file:org.wso2.carbon.connector.clevertim.UpdateCase.java
/** * Create JSON request for UpdateCase./*from w w w . ja va 2 s .co m*/ * * @return JSON payload. * @throws JSONException thrown when parsing JSON String. */ private String getJsonPayload() throws JSONException { JSONObject jsonPayload = new JSONObject(); String id = (String) messageContext.getProperty(Constants.ID); if (id != null && !id.isEmpty()) { jsonPayload.put(Constants.JSONKeys.ID, id); } String name = (String) messageContext.getProperty(Constants.NAME); if (name != null && !name.isEmpty()) { jsonPayload.put(Constants.JSONKeys.NAME, name.trim()); } String description = (String) messageContext.getProperty(Constants.DESCRIPTION); if (description != null && !description.isEmpty()) { jsonPayload.put(Constants.JSONKeys.DESCRIPTION, description.trim()); } String leadUser = (String) messageContext.getProperty(Constants.LEAD_USER); if (leadUser != null && !leadUser.isEmpty()) { jsonPayload.put(Constants.JSONKeys.LEAD_USER, leadUser.trim()); } String customer = (String) messageContext.getProperty(Constants.CUSTOMER); if (customer != null && !customer.isEmpty()) { jsonPayload.put(Constants.JSONKeys.CUSTOMER, customer.trim()); } String customFields = (String) messageContext.getProperty(Constants.CUSTOM_FIELDS); if (customFields != null && !customFields.isEmpty()) { jsonPayload.put(Constants.JSONKeys.CUSTOM_FIELD, new JSONObject(customFields)); } String tags = (String) messageContext.getProperty(Constants.TAGS); if (tags != null && !tags.isEmpty()) { jsonPayload.put(Constants.JSONKeys.TAGS, new JSONArray(tags)); } return jsonPayload.toString(); }
From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver.java
@Override public void onReceive(Context context, Intent intent) { Prefs prefs = GBApplication.getPrefs(); if ("never".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { return;/* w w w . j a v a 2 s. c o m*/ } if ("when_screen_off".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (powermanager.isScreenOn()) { return; } } String messageType = intent.getStringExtra("messageType"); if (!messageType.equals("PEBBLE_ALERT")) { LOG.info("non PEBBLE_ALERT message type not supported"); return; } if (!intent.hasExtra("notificationData")) { LOG.info("missing notificationData extra"); return; } NotificationSpec notificationSpec = new NotificationSpec(); notificationSpec.id = -1; String notificationData = intent.getStringExtra("notificationData"); try { JSONArray notificationJSON = new JSONArray(notificationData); notificationSpec.title = notificationJSON.getJSONObject(0).getString("title"); notificationSpec.body = notificationJSON.getJSONObject(0).getString("body"); } catch (JSONException e) { e.printStackTrace(); return; } if (notificationSpec.title != null) { notificationSpec.type = NotificationType.UNKNOWN; String sender = intent.getStringExtra("sender"); if ("Conversations".equals(sender)) { notificationSpec.type = NotificationType.CONVERSATIONS; } else if ("OsmAnd".equals(sender)) { notificationSpec.type = NotificationType.GENERIC_NAVIGATION; } GBApplication.deviceService().onNotification(notificationSpec); } }