Android Open Source - VolleyDemo City Weather Info






From Project

Back to project page VolleyDemo.

License

The source code is released under:

MIT License

If you think the Android project VolleyDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package br.gdgsp.volleydemo.domain;
//  w  ww  .  ja  v a 2 s.c o m
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author : ubiratanfsoares
 **/

public class CityWeatherInfo {

    private static final String BASE_IMAGE_URL = "http://openweathermap.org/img/w/";

    public static String getBaseImageUrl() {
        return BASE_IMAGE_URL;
    }

    private String mName;
    private int mTemperature;
    private int mHumidity;
    private String mWeatherCondition;
    private String mWeatherIconURL;

    public CityWeatherInfo(JSONObject infoJson) throws JSONException {
        mName = infoJson.getString("name");
        parseTemperature(infoJson);
        parseConditions(infoJson);
    }

    public String getName() {
        return mName;
    }

    public int getTemperature() {
        return mTemperature;
    }

    public int getHumidity() {
        return mHumidity;
    }

    public String getWeatherCondition() {
        return mWeatherCondition;
    }

    public String getWeatherIconURL() {
        return mWeatherIconURL;
    }

    @Override
    public String toString() {
        return mName + " | " + mTemperature;
    }
    private void parseConditions(JSONObject infoJson) throws JSONException {
        final JSONArray conditionsArray = infoJson.getJSONArray("weather");
        final JSONObject conditionInfo = conditionsArray.getJSONObject(0);
        mWeatherCondition = conditionInfo.getString("main");
        mWeatherIconURL = BASE_IMAGE_URL + conditionInfo.getString("icon");
    }

    private void parseTemperature(JSONObject infoJson) throws JSONException {
        final JSONObject mainJson = infoJson.getJSONObject("main");
        mTemperature = mainJson.getInt("temp");
        mHumidity = mainJson.getInt("humidity");
    }
}




Java Source Code List

br.gdgsp.volleydemo.domain.BitmapLruCache.java
br.gdgsp.volleydemo.domain.CityWeatherInfo.java
br.gdgsp.volleydemo.domain.City.java
br.gdgsp.volleydemo.domain.WeatherRequest.java
br.gdgsp.volleydemo.ui.MainActivity.java
br.gdgsp.volleydemo.ui.WeatherInfoAdapter.java