Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.magdalena.lokalizacja;
- import android.util.Log;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- /**
- * Created by Magdalena on 2016-11-30.
- */
- public class BudowanieJSON {
- private static JSONArray lokalizacjaJsonArray = new JSONArray();
- private static JSONArray watmoJsonArray = new JSONArray();
- private static JSONArray dzwiekJsonArray = new JSONArray();
- private static JSONArray swiatloJsonArray = new JSONArray();
- public static JSONObject jsonToSend = new JSONObject();
- public static void lokalizacjaJSONArray(double lat, double lon) {
- Log.i("TAG", "activityJSONArray");
- JSONObject jsonObject = new JSONObject();
- try {
- jsonObject.put("lat", lat);
- jsonObject.put("lon", lon);
- Log.i("TAG", "json: " + jsonObject.toString());
- } catch (JSONException je) {
- je.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- lokalizacjaJsonArray.put(jsonObject);
- Log.i("TAG", "json: " + lokalizacjaJsonArray.toString());
- }
- public static void watmoJSONArray(String miasto, String temperatura, String cisnienie) {
- Log.i("TAG", "activityJSONArray");
- JSONObject jsonObject = new JSONObject();
- try {
- jsonObject.put("miasto", miasto);
- jsonObject.put("temperatura", temperatura);
- jsonObject.put("cisnienie", cisnienie);
- Log.i("TAG", "json: " + jsonObject.toString());
- } catch (JSONException je) {
- je.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- watmoJsonArray.put(jsonObject);
- Log.i("TAG", "json: " + watmoJsonArray.toString());
- }
- /* public static void dzwiekJsonArray(double volume){
- Log.i("TAG", "activityJSONArray");
- JSONObject jsonObject = new JSONObject();
- try{
- jsonObject.put("Db:", volume);
- }catch (JSONException je){
- je.printStackTrace();
- }catch (Exception e){
- e.printStackTrace();
- }
- dzwiekJsonArray.put(jsonObject);
- Log.i("TAG", "json:" + dzwiekJsonArray.toString());
- }*/
- public static void swiatloJSonArray(float lux){
- Log.i("TAG", "LightService");
- JSONObject jsonObject = new JSONObject();
- try {
- jsonObject.put("lux", lux);
- }catch (JSONException je){
- je.printStackTrace();
- }catch (Exception e){
- e.printStackTrace();
- }
- swiatloJsonArray.put(jsonObject);
- Log.i("TAG", "json:" + swiatloJsonArray);
- }
- public static JSONObject bulidJSONToSend() {
- try {
- jsonToSend.put("lokalizacja", lokalizacjaJsonArray);
- jsonToSend.put("pogoda", watmoJsonArray);
- jsonToSend.put("dB", dzwiekJsonArray);
- jsonToSend.put("lux", swiatloJsonArray);
- } catch (JSONException je) {
- je.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return jsonToSend;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement