Android Open Source - ThinkPageSDK_Android T P Weather






From Project

Back to project page ThinkPageSDK_Android.

License

The source code is released under:

MIT License

If you think the Android project ThinkPageSDK_Android 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 com.thinkpage.sdk;
import java.text.SimpleDateFormat;
import java.util.*;
//from  w  w w .jav  a 2s .  com
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.net.ParseException;

public class TPWeather {
  TPWeather(JSONObject jsonResponse) 
  {
        try
        {
      status = jsonResponse.getString("status");
      JSONArray array = jsonResponse.getJSONArray("weather");
      if (array.length() > 0)
          {
        // currently only handle the first city's weather
        JSONObject weatherObj = array.getJSONObject(0);
                try
                    {
                // get city name and last update
                    city = new TPCity(weatherObj.getString("city_name"), weatherObj.getString("city_id"));
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                    lastUpdate = formatter.parse(weatherObj.getString("last_update"));
                    }
                catch (java.text.ParseException e)
                    {

                    }
                catch (final JSONException ex)
                    {

                    };

                try
                    {
                    // get current weather
                    currentWeather = new TPWeatherNow(weatherObj.getJSONObject("now"));
                    }
                catch (final JSONException ex)
                    {

                    };

                try
                    {
                    // check and get airqualities and weather suggestions for current weather
                    if (currentWeather != null && currentWeather.airQualities != null) {
                        airQualities = currentWeather.airQualities.clone();
                    }

                    JSONObject todayInfo = weatherObj.getJSONObject("today");
                    sunriseTime = todayInfo.getString("sunrise");
                    sunsetTime = todayInfo.getString("sunset");
                    weatherSuggestions = new TPWeatherSuggestions(todayInfo.getJSONObject("suggestion"));
                    }
                catch (final JSONException ex)
                    {


                    };

                try
                    {
                    //may be the suggestion query
                    weatherSuggestions = new TPWeatherSuggestions(weatherObj.getJSONObject("suggestion"));
                    }
                catch (final JSONException ex)
                    {
                    };

                // future weather
                try
                    {
                    //get future weather
                    JSONArray futureWeatherArray = weatherObj.getJSONArray("future");
                    if (futureWeatherArray.length() > 0)
                        {
                        futureWeathers = new TPWeatherFuture[futureWeatherArray.length()];
                        for (int i = 0; i < futureWeatherArray.length(); ++i)
                            {
                            futureWeathers[i] = new TPWeatherFuture(futureWeatherArray.getJSONObject(i));
                            }
                        }
                    }
                catch (final JSONException ex)
                    {

                    };

                    // air quality if not set
                    if (airQualities == null) {
                        JSONObject airQualitiesAll = weatherObj.getJSONObject("air_quality");
                        TPAirQuality cityAirQuality = new TPAirQuality(airQualitiesAll.getJSONObject("city"));
                        JSONArray stationsAirQualityReport = airQualitiesAll.getJSONArray("stations");
                        airQualities = new TPAirQuality[stationsAirQualityReport.length() + 1];
                        airQualities[0] = cityAirQuality;
                        for (int i = 1; i <= stationsAirQualityReport.length(); ++i) {
                            airQualities[i] = new TPAirQuality(stationsAirQualityReport.getJSONObject(i - 1));
                        }
                    }

      }
      }
    catch (final JSONException ex) 
    {
      
        };
    
  }

  boolean isValid()
  {
    return false;
  }

  public String status;

  /*!
   the city this weather report belongs to
    **/
  public TPCity city;

  /*!
   the last update date/time of this weather report
   **/
  public Date lastUpdate;

  /*!
   current weather information
   **/
  public TPWeatherNow currentWeather;

  /*!
   air quality information. TPAirQuality in the NSArray
   **/
  public TPAirQuality[] airQualities;

    public String sunriseTime;

    public String sunsetTime;

  /*!
   weather suggestions
   **/
  public TPWeatherSuggestions weatherSuggestions;

  /*!
   future weather information, TPWeatherFuture in the NSArray
   **/
  public TPWeatherFuture[] futureWeathers;
}




Java Source Code List

com.example.thinkpageandroid.MainActivity.java
com.loopj.android.http.AsyncHttpClient.java
com.loopj.android.http.AsyncHttpRequest.java
com.loopj.android.http.AsyncHttpResponseHandler.java
com.loopj.android.http.Base64DataException.java
com.loopj.android.http.Base64OutputStream.java
com.loopj.android.http.Base64.java
com.loopj.android.http.BaseJsonHttpResponseHandler.java
com.loopj.android.http.BinaryHttpResponseHandler.java
com.loopj.android.http.DataAsyncHttpResponseHandler.java
com.loopj.android.http.FileAsyncHttpResponseHandler.java
com.loopj.android.http.JsonHttpResponseHandler.java
com.loopj.android.http.JsonStreamerEntity.java
com.loopj.android.http.MySSLSocketFactory.java
com.loopj.android.http.PersistentCookieStore.java
com.loopj.android.http.PreemtiveAuthorizationHttpRequestInterceptor.java
com.loopj.android.http.RangeFileAsyncHttpResponseHandler.java
com.loopj.android.http.RequestHandle.java
com.loopj.android.http.RequestParams.java
com.loopj.android.http.ResponseHandlerInterface.java
com.loopj.android.http.RetryHandler.java
com.loopj.android.http.SerializableCookie.java
com.loopj.android.http.SimpleMultipartEntity.java
com.loopj.android.http.SyncHttpClient.java
com.loopj.android.http.TextHttpResponseHandler.java
com.thinkpage.sdk.TPAirQuality.java
com.thinkpage.sdk.TPCity.java
com.thinkpage.sdk.TPWeatherFuture.java
com.thinkpage.sdk.TPWeatherManagerDelegate.java
com.thinkpage.sdk.TPWeatherManager.java
com.thinkpage.sdk.TPWeatherNow.java
com.thinkpage.sdk.TPWeatherSuggestions.java
com.thinkpage.sdk.TPWeather.java