public class WeatherClientDefault extends WeatherClient
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 = WeatherClient.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
ctx, LOCATION_TIMEOUT, locListener, provider
Constructor and Description |
---|
WeatherClientDefault() |
Modifier and Type | Method and Description |
---|---|
void |
getCurrentCondition(java.lang.String location,
WeatherClient.WeatherEventListener listener)
|
void |
getCurrentCondition(WeatherRequest wRequest,
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)
|
void |
getForecastWeather(WeatherRequest wRequest,
WeatherClient.ForecastWeatherEventListener listener)
Get the forecast weather condition.
|
void |
getHistoricalWeather(java.lang.String location,
java.util.Date startDate,
java.util.Date endDate,
WeatherClient.HistoricalWeatherEventListener listener)
|
void |
getHistoricalWeather(WeatherRequest wRequest,
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 wRequest,
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 WeatherClientDefault |
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, handleLocation
public static WeatherClientDefault getInstance()
WeatherClient.ClientBuilder
public void init(Context ctx)
WeatherClient
init
in class WeatherClient
ctx
- Reference to the Context
public void updateWeatherConfig(WeatherConfig config)
updateWeatherConfig
in class WeatherClient
config
- WeatherConfig infoWeatherConfig
public 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 WeatherClient
location
- a String representing the location idlistener
- WeatherClient.WeatherEventListener
ApiKeyRequiredException
public 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 WeatherClient
pattern
- a String representing the patternlistener
- WeatherClient.CityEventListener
ApiKeyRequiredException
public 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 WeatherClient
lat
- a double representing the latitudelon
- a double representing the longitudelistener
- WeatherClient.CityEventListener
ApiKeyRequiredException
public 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 WeatherClient
location
- a String representing the location idlistener
- WeatherClient.ForecastWeatherEventListener
ApiKeyRequiredException
public 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 WeatherClient
location
- a String representing the location idlistener
- WeatherClient.HourForecastWeatherEventListener
ApiKeyRequiredException
public void getHistoricalWeather(java.lang.String location, java.util.Date startDate, java.util.Date endDate, WeatherClient.HistoricalWeatherEventListener listener) throws ApiKeyRequiredException
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 WeatherClient
location
- a String representing the location idlistener
- WeatherClient.HistoricalWeatherEventListener
startDate
- is the starting dateendDate
- is the end dateApiKeyRequiredException
public void getDefaultProviderImage(java.lang.String icon, WeatherClient.WeatherImageListener listener)
getDefaultProviderImage
in class WeatherClient
icon
- String The icon containing the weather code to retrieve the imagelistener
- WeatherClient.WeatherImageListener
public void searchCityByLocation(Criteria criteria, WeatherClient.CityEventListener listener) throws LocationProviderNotFoundException
searchCityByLocation
in class WeatherClient
LocationProviderNotFoundException
public 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 WeatherClient
provider
- IWeatherProvider
com.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)
IWeatherProvider
getWeatherImage
in class WeatherClient
cityId
- 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 WeatherClient
ApiKeyRequiredException
public void getCurrentCondition(WeatherRequest wRequest, 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 WeatherClient
wRequest
- WeatherRequest
listener
- WeatherClient.WeatherEventListener
ApiKeyRequiredException
public void getForecastWeather(WeatherRequest wRequest, 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 WeatherClient
wRequest
- WeatherRequest
listener
- WeatherClient.ForecastWeatherEventListener
ApiKeyRequiredException
public void getHourForecastWeather(WeatherRequest wRequest, 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 WeatherClient
wRequest
- WeatherRequest
listener
- WeatherClient.HourForecastWeatherEventListener
ApiKeyRequiredException
public void getHistoricalWeather(WeatherRequest wRequest, 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 WeatherClient
wRequest
- WeatherRequest
d1
- is the starting dated2
- listener
- WeatherClient.HistoricalWeatherEventListener
@param2 d2 is the end dateApiKeyRequiredException
public <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 WeatherClient
request
- WeatherRequest
extRequest
- is the extended request as required by the weather providerparser
- is the parser used to parsed the response GenericResponseParser
listener
- WeatherClient.GenericRequestWeatherEventListener
ApiKeyRequiredException
public void getImage(java.lang.String url, WeatherClient.WeatherImageListener listener)
getImage
in class WeatherClient
url
- String representing the urllistener
- WeatherClient.WeatherImageListener