public class StandardHttpClient extends WeatherClient
WeatherClient,
this is a synchronous client and you should consider it when using this class in your main thread.
This class uses a IWeatherProvider to parse the response. Internally this class is based on standard HttpURLConnection
Usually you need only one instance of this class in your app so that the class implements the Singleton pattern To get the reference to this class you have to use getInstance method:
WeatherClient client = StandardHttpClient.getInstance();
soon after you the the reference and before you make any requests you have to pass the Context
to this class.
WeatherClient.CityEventListener, WeatherClient.ClientBuilder, WeatherClient.ForecastWeatherEventListener, WeatherClient.GenericRequestWeatherEventListener<T>, WeatherClient.HistoricalWeatherEventListener, WeatherClient.HourForecastWeatherEventListener, WeatherClient.WeatherClientListener, WeatherClient.WeatherEventListener, WeatherClient.WeatherImageListener| Modifier and Type | Field and Description |
|---|---|
static int |
LOCATION_TIMEOUT |
ctx, provider| Constructor and Description |
|---|
StandardHttpClient() |
| Modifier and Type | Method and Description |
|---|---|
void |
getCurrentCondition(java.lang.String location,
WeatherClient.WeatherEventListener listener)
|
CurrentWeather |
getCurrentCondition(WeatherRequest request)
Get the current weather condition.
|
void |
getCurrentCondition(WeatherRequest request,
WeatherClient.WeatherEventListener listener)
Get the current weather condition.
|
void |
getDefaultProviderImage(java.lang.String icon,
WeatherClient.WeatherImageListener listener)
This is the default image Provider that can be used to get the image provided by the Weather provider
|
void |
getForecastWeather(java.lang.String location,
WeatherClient.ForecastWeatherEventListener listener)
|
WeatherForecast |
getForecastWeather(WeatherRequest request)
Get the forecast weather condition.
|
void |
getForecastWeather(WeatherRequest request,
WeatherClient.ForecastWeatherEventListener listener)
Get the forecast weather condition.
|
void |
getHistoricalWeather(java.lang.String location,
java.util.Date d1,
java.util.Date d2,
WeatherClient.HistoricalWeatherEventListener listener)
|
void |
getHistoricalWeather(WeatherRequest request,
java.util.Date d1,
java.util.Date d2,
WeatherClient.HistoricalWeatherEventListener listener)
Get the historical weather condition.
|
void |
getHourForecastWeather(java.lang.String location,
WeatherClient.HourForecastWeatherEventListener listener)
|
void |
getHourForecastWeather(WeatherRequest request,
WeatherClient.HourForecastWeatherEventListener listener)
Get the forecast weather condition.
|
void |
getImage(java.lang.String url,
WeatherClient.WeatherImageListener listener)
Get an image at the specified URL and inform the listener when the image is ready
|
static StandardHttpClient |
getInstance()
Deprecated.
Release 1.4 repleaced by
WeatherClient.ClientBuilder |
<T extends WeatherProviderFeature,S> |
getProviderWeatherFeature(WeatherRequest request,
T extRequest,
GenericResponseParser<S> parser,
WeatherClient.GenericRequestWeatherEventListener<S> listener)
Get a specific weather provider feature not implemented in all weather provider
When the data is ready this method calls the onWeatherRetrieved passing the
HistoricalWeather weather information. |
void |
getWeatherImage(java.lang.String cityId,
Params params,
WeatherClient.WeatherImageListener listener)
This method retrieves the image using the url generated by the weahter provider
IWeatherProvider |
void |
init(Context ctx)
This method has to be called before any HTTP request
|
void |
searchCity(double lat,
double lon,
WeatherClient.CityEventListener listener)
Search the city using latitude and longitude.
|
void |
searchCity(java.lang.String pattern,
WeatherClient.CityEventListener listener)
Search the city using a name pattern.
|
void |
searchCityByLocation(Criteria criteria,
WeatherClient.CityEventListener listener) |
protected void |
searchCityByLocation(Location location,
WeatherClient.CityEventListener listener) |
void |
setProvider(IWeatherProvider provider)
This method is used to set the Weather provider.
|
void |
updateWeatherConfig(WeatherConfig config)
This method update the current provider configuration
|
createDefaultCriteria, createProvider, handleLocationpublic static StandardHttpClient getInstance()
WeatherClient.ClientBuilderpublic void init(Context ctx)
init in class WeatherClientctx - Reference to the Contextpublic void updateWeatherConfig(WeatherConfig config)
updateWeatherConfig in class WeatherClientconfig - WeatherConfig infoWeatherConfigpublic void getCurrentCondition(java.lang.String location,
WeatherClient.WeatherEventListener listener)
throws ApiKeyRequiredException
WeatherClient.getCurrentCondition(com.survivingwithandroid.weather.lib.request.WeatherRequest, com.survivingwithandroid.weather.lib.WeatherClient.WeatherEventListener)WeatherClient.WeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the current weather information. If there are some errors during the request parsing, it calls onWeatherError passing the exception or onConnectionError if the errors happened during the HTTP connection
getCurrentCondition in class WeatherClientlocation - a String representing the location idlistener - WeatherClient.WeatherEventListenerApiKeyRequiredExceptionpublic void searchCity(java.lang.String pattern,
WeatherClient.CityEventListener listener)
throws ApiKeyRequiredException
WeatherClient.CityEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onCityListRetrieved passing a List of cities.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
searchCity in class WeatherClientpattern - a String representing the patternlistener - WeatherClient.CityEventListenerApiKeyRequiredExceptionpublic void getForecastWeather(java.lang.String location,
WeatherClient.ForecastWeatherEventListener listener)
throws ApiKeyRequiredException
WeatherClient.getForecastWeather(com.survivingwithandroid.weather.lib.request.WeatherRequest, com.survivingwithandroid.weather.lib.WeatherClient.ForecastWeatherEventListener)WeatherClient.ForecastWeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the WeatherForecast weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getForecastWeather in class WeatherClientlocation - a String representing the location idlistener - WeatherClient.ForecastWeatherEventListenerApiKeyRequiredExceptionpublic void getHourForecastWeather(java.lang.String location,
WeatherClient.HourForecastWeatherEventListener listener)
throws ApiKeyRequiredException
WeatherClient.getHourForecastWeather(com.survivingwithandroid.weather.lib.request.WeatherRequest, com.survivingwithandroid.weather.lib.WeatherClient.HourForecastWeatherEventListener)WeatherClient.HourForecastWeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the WeatherHourForecast weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getHourForecastWeather in class WeatherClientlocation - a String representing the location idlistener - WeatherClient.HourForecastWeatherEventListenerApiKeyRequiredExceptionpublic void getDefaultProviderImage(java.lang.String icon,
WeatherClient.WeatherImageListener listener)
WeatherClientgetDefaultProviderImage in class WeatherClienticon - String The icon containing the weather code to retrieve the imagelistener - WeatherClient.WeatherImageListenerpublic void getHistoricalWeather(java.lang.String location,
java.util.Date d1,
java.util.Date d2,
WeatherClient.HistoricalWeatherEventListener listener)
WeatherClient.getHistoricalWeather(com.survivingwithandroid.weather.lib.request.WeatherRequest, java.util.Date, java.util.Date, com.survivingwithandroid.weather.lib.WeatherClient.HistoricalWeatherEventListener)WeatherClient.HistoricalWeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the HistoricalWeather weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getHistoricalWeather in class WeatherClientlocation - a String representing the location idd1 - is the starting dated2 - listener - WeatherClient.HistoricalWeatherEventListener @param2 d2 is the end dateApiKeyRequiredExceptionpublic void searchCityByLocation(Criteria criteria,
WeatherClient.CityEventListener listener)
throws LocationProviderNotFoundException
searchCityByLocation in class WeatherClientLocationProviderNotFoundExceptionpublic void setProvider(IWeatherProvider provider)
IWeatherProvider
interface. This method has to be called before making any HTTP request otherwise the client doesn't know how
to parse the requestsetProvider in class WeatherClientprovider - IWeatherProvidercom.survivingwithandroid.weather.lib.provider.openweathermap.OpenweathermapProvider},
com.survivingwithandroid.weather.lib.provider.yahooweather.YahooWeatherProvider}public void getWeatherImage(java.lang.String cityId,
Params params,
WeatherClient.WeatherImageListener listener)
IWeatherProvidergetWeatherImage in class WeatherClientcityId - String representing the city idparams - Params: list of parameters used to create the imagelistener - WeatherClient.WeatherImageListener listener that gets notified when the image is ready to useprotected void searchCityByLocation(Location location,
WeatherClient.CityEventListener listener)
throws ApiKeyRequiredException
searchCityByLocation in class WeatherClientApiKeyRequiredExceptionpublic void searchCity(double lat,
double lon,
WeatherClient.CityEventListener listener)
throws ApiKeyRequiredException
WeatherClient.CityEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onCityListRetrieved passing a List of cities.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
searchCity in class WeatherClientlat - a double representing the latitudelon - a double representing the longitudelistener - WeatherClient.CityEventListenerApiKeyRequiredExceptionpublic void getCurrentCondition(WeatherRequest request, WeatherClient.WeatherEventListener listener) throws ApiKeyRequiredException
WeatherClient.WeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the current weather information. If there are some errors during the request parsing, it calls onWeatherError passing the exception or onConnectionError if the errors happened during the HTTP connection
getCurrentCondition in class WeatherClientrequest - WeatherRequestlistener - WeatherClient.WeatherEventListenerApiKeyRequiredExceptionpublic CurrentWeather getCurrentCondition(WeatherRequest request) throws ApiKeyRequiredException, WeatherLibException
request - WeatherRequestApiKeyRequiredExceptionWeatherLibExceptionpublic void getForecastWeather(WeatherRequest request, WeatherClient.ForecastWeatherEventListener listener) throws ApiKeyRequiredException
WeatherClient.ForecastWeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the WeatherForecast weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getForecastWeather in class WeatherClientrequest - WeatherRequestlistener - WeatherClient.ForecastWeatherEventListenerApiKeyRequiredExceptionpublic WeatherForecast getForecastWeather(WeatherRequest request) throws ApiKeyRequiredException, WeatherLibException
request - WeatherRequestApiKeyRequiredExceptionWeatherLibExceptionpublic void getHourForecastWeather(WeatherRequest request, WeatherClient.HourForecastWeatherEventListener listener) throws ApiKeyRequiredException
WeatherClient.HourForecastWeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the WeatherHourForecast weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getHourForecastWeather in class WeatherClientrequest - WeatherRequestlistener - WeatherClient.HourForecastWeatherEventListenerApiKeyRequiredExceptionpublic void getHistoricalWeather(WeatherRequest request, java.util.Date d1, java.util.Date d2, WeatherClient.HistoricalWeatherEventListener listener)
WeatherClient.HistoricalWeatherEventListener to
get notified when the weather data is ready.
When the data is ready this method calls the onWeatherRetrieved passing the HistoricalWeather weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getHistoricalWeather in class WeatherClientrequest - WeatherRequestd1 - is the starting dated2 - listener - WeatherClient.HistoricalWeatherEventListener @param2 d2 is the end dateApiKeyRequiredExceptionpublic <T extends WeatherProviderFeature,S> void getProviderWeatherFeature(WeatherRequest request, T extRequest, GenericResponseParser<S> parser, WeatherClient.GenericRequestWeatherEventListener<S> listener)
When the data is ready this method calls the onWeatherRetrieved passing the HistoricalWeather weather information.
If there are some errors during the request parsing, it calls onWeatherError passing the exception or
onConnectionError if the errors happened during the HTTP connection
getProviderWeatherFeature in class WeatherClientrequest - WeatherRequestextRequest - is the extended request as required by the weather providerparser - is the parser used to parsed the response GenericResponseParserlistener - WeatherClient.GenericRequestWeatherEventListenerApiKeyRequiredExceptionpublic void getImage(java.lang.String url,
WeatherClient.WeatherImageListener listener)
getImage in class WeatherClienturl - String representing the urllistener - WeatherClient.WeatherImageListener