public abstract class WeatherClient
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
static interface |
WeatherClient.CityEventListener
This interface must be implemented by the client that wants to get informed when
the city list is ready.
|
static class |
WeatherClient.ClientBuilder
This class must be used to obtain a valid instance of WeatherClient.
|
static interface |
WeatherClient.ForecastWeatherEventListener
This interface must be implemented by the client that wants to get informed when
the forecast weather data is ready.
|
static interface |
WeatherClient.GenericRequestWeatherEventListener<T>
This interface must be implemented by the client that wants to get informed when
the generic request is available
|
static interface |
WeatherClient.HistoricalWeatherEventListener
This interface must be implemented by the client that wants to get informed when
the historical weather data is ready.
|
static interface |
WeatherClient.HourForecastWeatherEventListener
This interface must be implemented by the client that wants to get informed when
the hour forecast weather data is ready.
|
static interface |
WeatherClient.WeatherClientListener
This is the base interface.
|
static interface |
WeatherClient.WeatherEventListener
This interface must be implemented by the client that wants to get informed when
the weather data is ready.
|
static interface |
WeatherClient.WeatherImageListener
This interface must be implemented by the client that wants to get informed when
the forecast weather image is ready.
|
Modifier and Type | Field and Description |
---|---|
protected WeatherClient.CityEventListener |
cityListener |
protected Context |
ctx |
static int |
LOCATION_TIMEOUT |
protected LocationListener |
locListener |
protected IWeatherProvider |
provider |
Constructor and Description |
---|
WeatherClient() |
Modifier and Type | Method and Description |
---|---|
static Criteria |
createDefaultCriteria() |
void |
createProvider(IProviderType providerType,
WeatherConfig config)
Deprecated.
Version 1.4 use instead
WeatherClient.ClientBuilder |
abstract void |
getCurrentCondition(java.lang.String location,
WeatherClient.WeatherEventListener listener)
|
abstract void |
getCurrentCondition(WeatherRequest request,
WeatherClient.WeatherEventListener listener)
Get the current weather condition.
|
abstract 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
|
abstract void |
getForecastWeather(java.lang.String location,
WeatherClient.ForecastWeatherEventListener listener)
|
abstract void |
getForecastWeather(WeatherRequest request,
WeatherClient.ForecastWeatherEventListener listener)
Get the forecast weather condition.
|
abstract void |
getHistoricalWeather(java.lang.String location,
java.util.Date d1,
java.util.Date d2,
WeatherClient.HistoricalWeatherEventListener listener)
|
abstract void |
getHistoricalWeather(WeatherRequest request,
java.util.Date d1,
java.util.Date d2,
WeatherClient.HistoricalWeatherEventListener listener)
Get the historical weather condition.
|
abstract void |
getHourForecastWeather(java.lang.String location,
WeatherClient.HourForecastWeatherEventListener listener)
|
abstract void |
getHourForecastWeather(WeatherRequest request,
WeatherClient.HourForecastWeatherEventListener listener)
Get the forecast weather condition.
|
abstract 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
|
abstract <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. |
abstract 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 |
protected void |
handleLocation(Criteria criteria,
WeatherClient.CityEventListener listener) |
void |
init(Context ctx)
This method has to be called before any HTTP request
|
abstract void |
searchCity(double lat,
double lon,
WeatherClient.CityEventListener listener)
Search the city using latitude and longitude.
|
abstract void |
searchCity(java.lang.String pattern,
WeatherClient.CityEventListener listener)
Search the city using a name pattern.
|
abstract void |
searchCityByLocation(Criteria criteria,
WeatherClient.CityEventListener listener)
Search the city using geographic coordinates.
|
protected abstract 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
|
protected IWeatherProvider provider
protected Context ctx
protected WeatherClient.CityEventListener cityListener
public static int LOCATION_TIMEOUT
protected LocationListener locListener
public void init(Context ctx)
ctx
- Reference to the Context
public void updateWeatherConfig(WeatherConfig config)
config
- WeatherConfig infoWeatherConfig
public abstract void getCurrentCondition(java.lang.String location, WeatherClient.WeatherEventListener listener) throws ApiKeyRequiredException
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
location
- a String representing the location idlistener
- WeatherClient.WeatherEventListener
ApiKeyRequiredException
public abstract 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
pattern
- a String representing the patternlistener
- WeatherClient.CityEventListener
ApiKeyRequiredException
public abstract 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
lat
- a double representing the latitudelon
- a double representing the longitudelistener
- WeatherClient.CityEventListener
ApiKeyRequiredException
public abstract void getForecastWeather(java.lang.String location, WeatherClient.ForecastWeatherEventListener listener) throws ApiKeyRequiredException
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
location
- a String representing the location idlistener
- WeatherClient.ForecastWeatherEventListener
ApiKeyRequiredException
public abstract void getHourForecastWeather(java.lang.String location, WeatherClient.HourForecastWeatherEventListener listener) throws ApiKeyRequiredException
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
location
- a String representing the location idlistener
- WeatherClient.HourForecastWeatherEventListener
ApiKeyRequiredException
public abstract void getHistoricalWeather(java.lang.String location, 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
location
- a String representing the location idd1
- is the starting dated2
- is the end datelistener
- WeatherClient.HistoricalWeatherEventListener
ApiKeyRequiredException
public abstract void getDefaultProviderImage(java.lang.String icon, WeatherClient.WeatherImageListener listener)
icon
- String The icon containing the weather code to retrieve the imagelistener
- WeatherClient.WeatherImageListener
public abstract void searchCityByLocation(Criteria criteria, WeatherClient.CityEventListener listener) throws LocationProviderNotFoundException
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
criteria
- android.location.Criteria
listener
- WeatherClient.CityEventListener
ApiKeyRequiredException
LocationProviderNotFoundException
public abstract void getWeatherImage(java.lang.String cityId, Params params, WeatherClient.WeatherImageListener listener)
IWeatherProvider
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 usepublic 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 requestprovider
- IWeatherProvider
com.survivingwithandroid.weather.lib.provider.openweathermap.OpenweathermapProvider}
,
com.survivingwithandroid.weather.lib.provider.yahooweather.YahooWeatherProvider}
public static Criteria createDefaultCriteria()
public void createProvider(IProviderType providerType, WeatherConfig config) throws WeatherProviderInstantiationException
WeatherClient.ClientBuilder
IWeatherProvider provider = null;
try {
provider = WeatherProviderFactory.createProvider(new OpenweathermapProviderType(), config);
client.setProvider(provider);
}
catch (Throwable t) {
t.printStackTrace();
// There's a problem
}
protected void handleLocation(Criteria criteria, WeatherClient.CityEventListener listener) throws LocationProviderNotFoundException
protected abstract void searchCityByLocation(Location location, WeatherClient.CityEventListener listener) throws ApiKeyRequiredException
ApiKeyRequiredException
public abstract 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
request
- WeatherRequest
listener
- WeatherClient.WeatherEventListener
ApiKeyRequiredException
public abstract 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
request
- WeatherRequest
listener
- WeatherClient.ForecastWeatherEventListener
ApiKeyRequiredException
public abstract 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
request
- WeatherRequest
listener
- WeatherClient.HourForecastWeatherEventListener
ApiKeyRequiredException
public abstract 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
request
- WeatherRequest
d1
- is the starting dated2
- is the end datelistener
- WeatherClient.HistoricalWeatherEventListener
ApiKeyRequiredException
public abstract <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
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 abstract void getImage(java.lang.String url, WeatherClient.WeatherImageListener listener)
url
- String representing the urllistener
- WeatherClient.WeatherImageListener