Exemplo n.º 1
0
 public Main(JSONObject json) {
   this.temp = (float) json.optDouble(Main.JSON_TEMP);
   this.tempMin = (float) json.optDouble(Main.JSON_TEMP_MIN);
   this.tempMax = (float) json.optDouble(Main.JSON_TEMP_MAX);
   this.pressure = (float) json.optDouble(Main.JSON_PRESSURE);
   this.humidity = (float) json.optDouble(Main.JSON_HUMIDITY);
 }
Exemplo n.º 2
0
 public Wind(JSONObject json) {
   this.speed = (float) json.optDouble(Wind.JSON_SPEED);
   this.deg = json.optInt(Wind.JSON_DEG, Integer.MIN_VALUE);
   this.gust = (float) json.optDouble(Wind.JSON_GUST);
   this.varBeg = json.optInt(Wind.JSON_VAR_BEG, Integer.MIN_VALUE);
   this.varEnd = json.optInt(Wind.JSON_VAR_END, Integer.MIN_VALUE);
 }
Exemplo n.º 3
0
  static final Quilt createFromJSONObject(JSONObject jsonObject) throws JSONException {

    int rowCount = jsonObject.optInt("rowCount", 0);
    int columnCount = jsonObject.optInt("columnCount", 0);
    float width = (float) jsonObject.optDouble("width", 0);
    float height = (float) jsonObject.optDouble("height", 0);

    Quilt quilt = new Quilt(rowCount, columnCount, width, height);

    if (jsonObject.has("quiltBlocks")) {
      JSONArray jsonQuiltBlocks = jsonObject.getJSONArray("quiltBlocks");

      int index = -1;
      for (int row = 0; row < quilt.m_rowCount; ++row) {
        for (int column = 0; column < quilt.m_columnCount; ++column) {
          index += 1;
          if (index < jsonQuiltBlocks.length()) {
            JSONObject jsonQuiltBlock = jsonQuiltBlocks.optJSONObject(index);
            if (jsonQuiltBlock != null) {
              QuiltBlock quiltBlock = QuiltBlock.createFromJSONObject(jsonQuiltBlock);
              quilt.setQuiltBlock(row, column, quiltBlock);
            }
          }
        }
      }
    }

    quilt.m_new = false;
    return quilt;
  }
 private static LocationBean translateToLocationBean(JSONObject obj) {
   if (obj == null) {
     return null;
   }
   double latid = obj.optDouble(PurplemoonAPIConstantsV1.JSON_LOCATION_LAT);
   double longit = obj.optDouble(PurplemoonAPIConstantsV1.JSON_LOCATION_LONG);
   String country = obj.optString(PurplemoonAPIConstantsV1.JSON_LOCATION_COUNTRYID, null);
   String locationDesc = obj.optString(PurplemoonAPIConstantsV1.JSON_LOCATION_NAME, null);
   return new LocationBean(longit, latid, country, locationDesc);
 }
 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
   if (holder.getItemViewType() == TYPE_ITEM) {
     JSONObject object = mArray.optJSONObject(position);
     holder.tv_title.setText(object.optString("order_num"));
     holder.tv_buyer.setText("Âò¼Ò£º" + object.optString("user_name"));
     holder.trip.setText("ÔË·Ñ£º£¤" + object.optDouble("send_price"));
     holder.pay_money.setText("ʵ¸¶£º£¤" + object.optDouble("order_price"));
     holder.tv_style.setText("x" + object.optInt("commdify_count"));
   }
 }
Exemplo n.º 6
0
  /**
   * 转换JsonObject对象为JiaoFeiXXEntity实体
   *
   * @param object
   * @return
   */
  public static JiaoFeiXXEntity fromJSON(JSONObject object) {
    JiaoFeiXXEntity jiaofei = new JiaoFeiXXEntity();
    jiaofei.setChaoBiaoRQ(object.optLong("d_ChaoBiaoRQ"));
    jiaofei.setcId(object.optString("s_CID"));
    jiaofei.setFeEID(object.optInt("i_FEEID"));
    jiaofei.setjE(object.optDouble("n_JE"));
    jiaofei.setKaiZhangRQ(object.optLong("d_KAIZHANGRQ"));
    jiaofei.setShiShouWYJ(object.optDouble("n_SHISHOUWYJ"));
    jiaofei.setShiShouZJE(object.optDouble("n_SHISHOUZJE"));
    jiaofei.setShouFeiRQ(object.optLong("d_SHOUFEIRQ"));
    jiaofei.setShouFeiTJ(object.optString("s_SHOUFEITJ"));
    jiaofei.setZhangWuNY(object.optInt("i_ZhangWuNY"));

    return jiaofei;
  }
Exemplo n.º 7
0
 private IGPSObject parseGST(final JSONObject json) {
   IGPSObject gps;
   final GSTObject gst = new GSTObject();
   gst.setTag(json.optString("tag", null));
   gst.setDevice(json.optString("device", null));
   gst.setTimestamp(this.parseTimestamp(json, "time"));
   gst.setRms(json.optDouble("rms", Double.NaN));
   gst.setMajor(json.optDouble("major", Double.NaN));
   gst.setMinor(json.optDouble("minor", Double.NaN));
   gst.setOrient(json.optDouble("orient", Double.NaN));
   gst.setLat(json.optDouble("lat", Double.NaN));
   gst.setLon(json.optDouble("lon", Double.NaN));
   gst.setAlt(json.optDouble("alt", Double.NaN));
   gps = gst;
   return gps;
 }
Exemplo n.º 8
0
  @Override
  public void parseJson(String jsonStr) {
    JSONObject jsonObject = getJsonObject(jsonStr);
    this.setAge(jsonObject.optString("age"));
    this.setImgUrl(jsonObject.optString("avatar"));
    this.setNickname(jsonObject.optString("nickname"));
    this.setHeight(jsonObject.optString("height"));
    this.setOnline(jsonObject.optInt("online"));
    this.setImgUrl(jsonObject.optString("avatar"));
    this.setUid(jsonObject.optLong("uid"));
    this.setProvince(jsonObject.optString("province"));
    this.setCity(jsonObject.optString("city"));
    this.setGrade(jsonObject.optInt("grade"));
    this.gender = jsonObject.optInt("gender");

    this.hasLocalTag = jsonObject.optBoolean("hasLocalTag");
    if (hasLocalTag) {
      this.localTag = new LocateTag();
      localTag.parseJson(jsonObject.optString("localTag"));
    }
    this.score = jsonObject.optInt("score");
    this.lat = jsonObject.optDouble("lat");
    this.lng = jsonObject.optDouble("lng");
    this.distance = LocationMgr.getDistance(lng, lat);
    this.certify_level = jsonObject.optInt("certify_level");
    this.setFollowed(jsonObject.optBoolean("following"));
    this.setTm(jsonObject.optString("tm"));
    JSONObject JsonStatus = jsonObject.optJSONObject("status");
    if (JsonStatus != null) {
      this.setShow(JsonStatus.optString("show"));
    }
  }
  public UserSmart(JSONObject objUser) {
    super();
    this.checkInId = objUser.optInt("checkin_id");
    this.userId = objUser.optInt("id");
    this.nickName = objUser.optString("nickname");
    this.statusText = objUser.optString("status_text");
    this.photo = objUser.optString("photo");
    this.majorJobCategory = objUser.optString("major_job_category");
    this.minorJobCategory = objUser.optString("minor_job_category");
    this.headLine = objUser.optString("headline");

    if (!objUser.optString("filename").equals("")) this.fileName = objUser.optString("filename");
    else if (!objUser.optString("imageUrl").equals(""))
      this.fileName = objUser.optString("imageUrl");
    else if (Constants.debugLog)
      Log.d(
          "UserSmart",
          "Warning, could not parse user image URL with keys 'filename' or 'imageUrl'...");

    this.lat = objUser.optDouble("lat");
    this.lng = objUser.optDouble("lng");
    this.checkedIn = objUser.optInt("checked_in");
    this.foursquareId = objUser.optString("foursquare");
    this.venueName = objUser.optString("venue_name");
    this.venueId = objUser.optInt("venue_id");
    this.checkInCount = objUser.optInt("checkin_count");
    this.skills = objUser.optString("skills");
    this.sponsorNickname = objUser.optString("sponsorNickname");
    if (this.sponsorNickname.equalsIgnoreCase("") == false) {
      Log.d("UserSmart", "Sponsor: %s" + this.sponsorNickname);
      int test = 5;
      int test2 = test;
    }
    this.met = objUser.optBoolean("met");
  }
 @Override
 public boolean importValue(JSONObject json, String key, SharedPreferences.Editor editor) {
   final Preference preference = supportedMap.get(key);
   if (preference == null || !preference.exportable()) return false;
   switch (preference.type()) {
     case BOOLEAN:
       editor.putBoolean(key, json.optBoolean(key, preference.defaultBoolean()));
       break;
     case INT:
       editor.putInt(key, json.optInt(key, preference.defaultInt()));
       break;
     case LONG:
       editor.putLong(key, json.optLong(key, preference.defaultLong()));
       break;
     case FLOAT:
       editor.putFloat(key, (float) json.optDouble(key, preference.defaultFloat()));
       break;
     case STRING:
       editor.putString(key, json.optString(key, preference.defaultString()));
       break;
     default:
       break;
   }
   return true;
 }
Exemplo n.º 11
0
 private UserData processLookup(JSONObject json) {
   final UserData data = new UserData();
   try {
     final JSONArray local = json.optJSONArray("local");
     if (local == null) {
       SuperBans.log("Unable to properly communicate with MCBans. Check your API Key");
       return data;
     }
     for (int i = 0; i < local.length(); i++) {
       final String[] ban = processBanLookup(local.getString(i));
       data.getBanList()
           .addBanData(new MCBansBanData(ban[1], MCBansBanData.BanType.LOCAL, ban[0]));
     }
     final JSONArray global = json.optJSONArray("global");
     for (int i = 0; i < global.length(); i++) {
       final String[] ban = processBanLookup(global.getString(i));
       data.getBanList()
           .addBanData(new MCBansBanData(ban[1], MCBansBanData.BanType.GLOBAL, ban[0]));
     }
   } catch (final JSONException e) {
     e.printStackTrace();
   }
   data.setExtra("mcbans_rep", String.valueOf(json.optDouble("reputation", 10.0)));
   return data;
 }
 public ModelAwardHistory(JSONObject object) throws JSONException {
   if (object != null) {
     jsonObject = object;
     if (object.has("id")) {
       if (!object.optString("id").equalsIgnoreCase("null")) {
         id = object.optString("id");
       }
     }
     if (object.has("winDate")) {
       if (!object.optString("winDate").equalsIgnoreCase("null")) {
         winDate = object.optString("winDate");
       }
     }
     if (object.has("orderNumber")) {
       if (!object.optString("orderNumber").equalsIgnoreCase("null")) {
         orderNumber = object.optString("orderNumber");
       }
     }
     if (object.has("prizeId")) {
       if (!object.optString("prizeId").equalsIgnoreCase("null")) {
         prizeId = object.optString("prizeId");
       }
     }
     if (object.has("winMoney")) {
       if (!object.optString("winMoney").equalsIgnoreCase("null")) {
         winMoney = object.optDouble("winMoney");
       }
     }
     isGrant = object.optInt("isGrant");
     award = new ModelAward(object.optJSONObject("prize"));
   }
 }
Exemplo n.º 13
0
  @Override
  public PluginResult execute(String action, JSONArray args, String callbackId) {
    this.callbackId = callbackId;
    this.limit = 1;
    this.duration = 0.0f;
    this.results = new JSONArray();

    JSONObject options = args.optJSONObject(0);
    if (options != null) {
      limit = options.optLong("limit", 1);
      duration = options.optDouble("duration", 0.0f);
    }

    if (action.equals("getFormatData")) {
      try {
        JSONObject obj = getFormatData(args.getString(0), args.getString(1));
        return new PluginResult(PluginResult.Status.OK, obj);
      } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.ERROR);
      }
    } else if (action.equals("captureAudio")) {
      this.captureAudio();
    } else if (action.equals("captureImage")) {
      this.captureImage();
    } else if (action.equals("captureVideo")) {
      this.captureVideo(duration);
    }

    PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
    r.setKeepCallback(true);
    return r;
  }
Exemplo n.º 14
0
 private IGPSObject parseEPHEM1(final JSONObject json) {
   IGPSObject gps;
   final EPHEM1Object emphem1 = new EPHEM1Object();
   emphem1.setWN(json.optInt("WN"));
   emphem1.setIODC(json.optInt("IODC"));
   emphem1.setL2(json.optInt("L2"));
   emphem1.setUra(json.optDouble("ura", Double.NaN));
   emphem1.setHlth(json.optDouble("hlth", Double.NaN));
   emphem1.setL2P(json.optInt("L2P"));
   emphem1.setTgd(json.optDouble("Tgd", Double.NaN));
   emphem1.setToc(json.optInt("toc"));
   emphem1.setAf2(json.optDouble("af2", Double.NaN));
   emphem1.setAf1(json.optDouble("af1", Double.NaN));
   emphem1.setAf0(json.optDouble("af0", Double.NaN));
   gps = emphem1;
   return gps;
 }
Exemplo n.º 15
0
  @Override
  protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException {
    double boost = jsonQuery.optDouble(BOOST_PARAM, 1.0);

    MatchAllDocsQuery q = new MatchAllDocsQuery();
    q.setBoost((float) boost);

    return q;
  }
Exemplo n.º 16
0
 private IGPSObject parseVERSION(final JSONObject json) {
   IGPSObject gps;
   final VersionObject ver = new VersionObject();
   ver.setRelease(json.optString("release", null));
   ver.setRev(json.optString("rev", null));
   ver.setProtocolMajor(json.optDouble("proto_major", 0));
   ver.setProtocolMinor(json.optDouble("proto_minor", 0));
   gps = ver;
   return gps;
 }
  private List<Case> readMapData() throws JSONException {
    InputStream inputStream = getResources().openRawResource(R.raw.dealing_test_data);

    List<Case> items = new ArrayList<Case>();
    String json = new Scanner(inputStream).useDelimiter(REGEX_INPUT_BOUNDARY_BEGINNING).next();
    JSONArray array = new JSONArray(json);
    for (int i = 0; i < array.length(); i++) {
      JSONObject object = array.getJSONObject(i);
      if (object.optString("UnitPrice").equals("--")) {
        continue;
      }
      String build_name = object.optString("BuildingName");
      String address = object.optString("Address");
      double lat = object.optDouble("Latitude");
      double lng = object.optDouble("Longitude");
      String unit_price = object.optString("UnitPrice");
      items.add(new Case(build_name, address, lat, lng, Float.parseFloat(unit_price)));
    }
    return items;
  }
Exemplo n.º 18
0
  public static Movie parseMovieJSON(JSONObject json_movie) {

    Movie movie = new Movie();
    movie.thumb_url = json_movie.optString("urlPoster");
    movie.title = json_movie.optString("title");
    movie.mpaa_rating = json_movie.optString("rated");
    movie.rating = (float) json_movie.optDouble("rating");
    movie.synopsis = json_movie.optString("plot");
    movie.movie_url = json_movie.optString("urlIMDB");

    return movie;
  }
Exemplo n.º 19
0
 private IGPSObject parseEPHEM3(final JSONObject json) {
   IGPSObject gps;
   final EPHEM3Object emphem3 = new EPHEM3Object();
   emphem3.setIODE(json.optInt("IODE"));
   emphem3.setIDOT(json.optDouble("IDOT", Double.NaN));
   emphem3.setCic(json.optDouble("Cic", Double.NaN));
   emphem3.setOmega0(json.optDouble("Omega0", Double.NaN));
   emphem3.setCis(json.optDouble("Cis", Double.NaN));
   emphem3.setI0(json.optDouble("i0", Double.NaN));
   emphem3.setCrc(json.optDouble("Crc", Double.NaN));
   emphem3.setOmega(json.optDouble("omega", Double.NaN));
   emphem3.setOmegad(json.optDouble("Omegad", Double.NaN));
   gps = emphem3;
   return gps;
 }
  public void testTrackCharge() {
    final List<JSONObject> messages = new ArrayList<JSONObject>();
    final AnalyticsMessages listener =
        new AnalyticsMessages(getContext()) {
          @Override
          public void eventsMessage(EventDescription heard) {
            throw new RuntimeException("Should not be called during this test");
          }

          @Override
          public void peopleMessage(JSONObject heard) {
            messages.add(heard);
          }
        };

    class ListeningAPI extends TestUtils.CleanMixpanelAPI {
      public ListeningAPI(Context c, Future<SharedPreferences> referrerPrefs, String token) {
        super(c, referrerPrefs, token);
      }

      @Override
      protected AnalyticsMessages getAnalyticsMessages() {
        return listener;
      }
    }

    MixpanelAPI api = new ListeningAPI(getContext(), mMockPreferences, "TRACKCHARGE TEST TOKEN");
    api.getPeople().identify("TRACKCHARGE PERSON");

    JSONObject props;
    try {
      props = new JSONObject("{'$time':'Should override', 'Orange':'Banana'}");
    } catch (JSONException e) {
      throw new RuntimeException("Can't construct fixture for trackCharge test");
    }

    api.getPeople().trackCharge(2.13, props);
    assertEquals(messages.size(), 1);

    JSONObject message = messages.get(0);

    try {
      JSONObject append = message.getJSONObject("$append");
      JSONObject newTransaction = append.getJSONObject("$transactions");
      assertEquals(newTransaction.optString("Orange"), "Banana");
      assertEquals(newTransaction.optString("$time"), "Should override");
      assertEquals(newTransaction.optDouble("$amount"), 2.13);
    } catch (JSONException e) {
      fail("Transaction message had unexpected layout:\n" + message.toString());
    }
  }
Exemplo n.º 21
0
 public bo b(fo paramfo, JSONObject paramJSONObject)
     throws JSONException, InterruptedException, ExecutionException {
   Future localFuture = paramfo.a(paramJSONObject, "image", true);
   paramfo = paramfo.a(paramJSONObject, "app_icon", true);
   return new bo(
       paramJSONObject.getString("headline"),
       (Drawable) localFuture.get(),
       paramJSONObject.getString("body"),
       (Drawable) paramfo.get(),
       paramJSONObject.getString("call_to_action"),
       paramJSONObject.optDouble("rating", -1.0D),
       paramJSONObject.optString("store"),
       paramJSONObject.optString("price"));
 }
Exemplo n.º 22
0
 public zzd zzb(zzfy zzfy1, JSONObject jsonobject) {
   Object obj = zzfy1.zza(jsonobject, "images", true, zzBY, zzBZ);
   zzhv zzhv1 = zzfy1.zza(jsonobject, "app_icon", true, zzBY);
   zzfy1 = zzfy1.zze(jsonobject);
   ArrayList arraylist = new ArrayList();
   for (obj = ((List) (obj)).iterator();
       ((Iterator) (obj)).hasNext();
       arraylist.add(((zzhv) ((Iterator) (obj)).next()).get())) {}
   return new zzd(
       jsonobject.getString("headline"),
       arraylist,
       jsonobject.getString("body"),
       (zzc) zzhv1.get(),
       jsonobject.getString("call_to_action"),
       jsonobject.optDouble("rating", -1D),
       jsonobject.optString("store"),
       jsonobject.optString("price"),
       (zza) zzfy1.get());
 }
Exemplo n.º 23
0
 private IGPSObject parseALMANAC(final JSONObject json) {
   IGPSObject gps;
   final ALMANACObject almanac = new ALMANACObject();
   almanac.setID(json.optInt("ID"));
   almanac.setHealth(json.optInt("Health"));
   almanac.setE(json.optDouble("e", Double.NaN));
   almanac.setToa(json.optInt("toa"));
   almanac.setDeltai(json.optDouble("deltai", Double.NaN));
   almanac.setOmegad(json.optDouble("Omegad", Double.NaN));
   almanac.setSqrtA(json.optDouble("sqrtA", Double.NaN));
   almanac.setOmega0(json.optDouble("Omega0", Double.NaN));
   almanac.setOmega(json.optDouble("omega", Double.NaN));
   almanac.setM0(json.optDouble("M0", Double.NaN));
   almanac.setAf0(json.optDouble("af0", Double.NaN));
   almanac.setAf1(json.optDouble("af1", Double.NaN));
   gps = almanac;
   return gps;
 }
Exemplo n.º 24
0
 private IGPSObject parseEPHEM2(final JSONObject json) {
   IGPSObject gps;
   final EPHEM2Object emphem2 = new EPHEM2Object();
   emphem2.setIODE(json.optInt("IODE"));
   emphem2.setCrs(json.optDouble("Crs", Double.NaN));
   emphem2.setDeltan(json.optDouble("deltan", Double.NaN));
   emphem2.setM0(json.optDouble("M0", Double.NaN));
   emphem2.setCuc(json.optDouble("Cuc", Double.NaN));
   emphem2.setE(json.optDouble("e", Double.NaN));
   emphem2.setCus(json.optDouble("Cus", Double.NaN));
   emphem2.setSqrtA(json.optInt("sqrtA"));
   emphem2.setToe(json.optInt("toe"));
   emphem2.setFIT(json.optInt("FIT"));
   emphem2.setAODO(json.optInt("AODO"));
   gps = emphem2;
   return gps;
 }
Exemplo n.º 25
0
 private IGPSObject parseSKY(final JSONObject json) throws ParseException {
   IGPSObject gps;
   final SKYObject sky = new SKYObject();
   sky.setTag(json.optString("tag", null));
   sky.setDevice(json.optString("device", null));
   sky.setTimestamp(this.parseTimestamp(json, "time"));
   sky.setLongitudeDOP(json.optDouble("xdop", Double.NaN));
   sky.setLatitudeDOP(json.optDouble("ydop", Double.NaN));
   sky.setAltitudeDOP(json.optDouble("vdop", Double.NaN));
   sky.setTimestampDOP(json.optDouble("tdop", Double.NaN));
   sky.setHorizontalDOP(json.optDouble("hdop", Double.NaN));
   sky.setSphericalDOP(json.optDouble("pdop", Double.NaN));
   sky.setHypersphericalDOP(json.optDouble("gdop", Double.NaN));
   sky.setSatellites(this.parseObjectArray(json.optJSONArray("satellites"), SATObject.class));
   gps = sky;
   return gps;
 }
Exemplo n.º 26
0
  /**
   * @param json
   * @return
   */
  public static CheckRechargeCardResponseModel ParseCheckRechargeCardResponse(String json) {
    CheckRechargeCardResponseModel checkRechargeCardResponse = new CheckRechargeCardResponseModel();
    if (json == null) {
      return null;
    }

    try {
      JSONObject jsonObj = new JSONObject(json);
      JSONObject checkRechargeCardUpObj = jsonObj.getJSONObject("CheckRechargeCardResponse");

      checkRechargeCardResponse.responsePublicModel.setResultCode(
          checkRechargeCardUpObj.getInt("resultCode"));
      checkRechargeCardResponse.responsePublicModel.setResultDescription(
          checkRechargeCardUpObj.optString("resultDescription"));
      if (checkRechargeCardResponse.responsePublicModel.getResultCode() != 0) {
        JSONObject eventManagementObj = checkRechargeCardUpObj.getJSONObject("eventManagement");
        checkRechargeCardResponse.responsePublicModel.eventManagement.setErrorCode(
            eventManagementObj.optString("errorCode"));
        checkRechargeCardResponse.responsePublicModel.eventManagement.setErrorDescription(
            eventManagementObj.optString("errorDescription"));
        return checkRechargeCardResponse;
      }
      checkRechargeCardResponse.responsePublicModel.setTransactionId(
          checkRechargeCardUpObj.optString("transactionId"));

      if (App.isNewPaymentsUpdate) {
        checkRechargeCardResponse.setTransferId(checkRechargeCardUpObj.optString("transferId"));
      }
      checkRechargeCardResponse.setCharges(checkRechargeCardUpObj.optDouble("charges"));
      checkRechargeCardResponse.setExecutionDate(checkRechargeCardUpObj.optString("executionDate"));
      checkRechargeCardResponse.setSrcbankName(checkRechargeCardUpObj.optString("srcbankName"));
      checkRechargeCardResponse.setSrcBranchName(checkRechargeCardUpObj.optString("srcBranchName"));

    } catch (Exception e) {
      LogManager.e("ParseCheckRechargeCardResponse is error" + e.getLocalizedMessage());
    }
    return checkRechargeCardResponse;
  }
  public Weather parseWeather(String jsonData) throws JsonParseException {
    Weather weather;
    if ("".equals(jsonData)) return null;
    try {
      JSONObject jsonObject = new JSONObject(jsonData);
      JSONObject sys = jsonObject.getJSONObject("sys");
      JSONObject main = jsonObject.getJSONObject("main");
      JSONObject windj = jsonObject.getJSONObject("wind");
      JSONObject weatherObj = jsonObject.getJSONArray("weather").getJSONObject(0);
      String name = jsonObject.getString("name");

      int cityId = jsonObject.getInt("id");
      String cityCountry = sys.getString("country");
      City city = new City(cityId, name, cityCountry);

      double windSpeed = windj.getDouble("speed");
      double windDegree = windj.optDouble("deg", -1d);
      Wind wind = new Wind(windDegree, windSpeed);

      double temperature = main.getDouble("temp");
      double pressure = main.getDouble("pressure");
      double humidity = main.getDouble("humidity");
      WeatherCondition condition = new WeatherCondition(temperature, pressure, humidity);

      long sunrise = sys.getLong("sunrise");
      long sunset = sys.getLong("sunset");
      AdditionalInfo info = new AdditionalInfo(sunrise, sunset);

      int weatherId = weatherObj.getInt("id");
      String description = weatherObj.getString("description");
      weather = new Weather(weatherId, description, new Date().getTime() / 1000);
      weather.setCity(city).setCondition(condition).setInfo(info).setWind(wind);
    } catch (JSONException e) {
      Log.e(LOG_TAG, "Parsing error!", e);
      throw new JsonParseException("Exception during parsing!", e);
    }
    return weather;
  }
Exemplo n.º 28
0
  public boolean onPreferenceClick(Preference preference) {
    int Color, ColorShadow, Width;
    double ShadowRadius;
    try {
      final JSONObject json = new JSONObject(getValue());
      Color = json.optInt(Track.COLOR, 0xffA565FE);
      Width = json.optInt(Track.WIDTH, 4);
      ShadowRadius = json.optDouble(Track.SHADOWRADIUS, 0);
      ColorShadow = json.optInt(Track.COLORSHADOW, 0xffA565FE);
    } catch (Exception e) {
      Ut.e(e.toString(), e);
      Color = 0xffA565FE;
      Width = 4;
      ShadowRadius = 0;
      ColorShadow = 0xffA565FE;
    }

    mDialog = new TrackStylePickerDialog(getContext(), Color, Width, ColorShadow, ShadowRadius);
    mDialog.setOnTrackStyleChangedListener(this);
    mDialog.show();

    return false;
  }
Exemplo n.º 29
0
  @Override
  protected void onBindView(View view) {
    super.onBindView(view);
    mView = view;

    int Color, ColorShadow, Width;
    double ShadowRadius;
    try {
      final JSONObject json = new JSONObject(getValue());
      Color = json.optInt(Track.COLOR, 0xffA565FE);
      Width = json.optInt(Track.WIDTH, 4);
      ShadowRadius = json.optDouble(Track.SHADOWRADIUS, 0);
      ColorShadow = json.optInt(Track.COLORSHADOW, 0xffA565FE);
    } catch (Exception e) {
      Ut.e(e.toString(), e);
      Color = 0xffA565FE;
      Width = 4;
      ShadowRadius = 0;
      ColorShadow = 0xffA565FE;
    }

    setPreviewColor(Color, Width, ColorShadow, ShadowRadius);
  }
Exemplo n.º 30
0
  private void deserializeFromObj(JSONObject obj) throws JSONException {
    this.TravelMode = obj.optString("travelMode");
    this.TravelDistance = obj.optDouble("travelDistance");
    this.TravelDuration = obj.optLong("travelDuration");

    JSONObject maneuverPoint = obj.getJSONObject("maneuverPoint");

    if (maneuverPoint != null) {
      JSONArray jsonArray = maneuverPoint.optJSONArray("coordinates");

      if (jsonArray != null && jsonArray.length() >= 2) {
        this.ManeuverPoint = new Coordinate(jsonArray.getDouble(0), jsonArray.getDouble(1));
      }
    }

    JSONObject instruction = obj.getJSONObject("instruction");
    this.Instruction = new Instruction(instruction);

    this.CompassDirection = obj.optString("compassDirection");

    JSONArray hints = obj.optJSONArray("hint");
    if (hints != null) {
      this.Hint = new Hint[hints.length()];
      for (int i = 0; i < hints.length(); i++) {
        this.Hint[i] = new Hint(hints.getJSONObject(i));
      }
    }

    JSONArray warnings = obj.optJSONArray("warning");
    if (warnings != null) {
      this.Warning = new Warning[warnings.length()];
      for (int i = 0; i < warnings.length(); i++) {
        this.Warning[i] = new Warning(warnings.getJSONObject(i));
      }
    }
  }