diff options
author | Luis Vidal <lvidal@cyngn.com> | 2016-04-12 18:24:27 -0700 |
---|---|---|
committer | Luis Vidal <lvidal@cyngn.com> | 2016-04-13 11:57:38 -0700 |
commit | ad0d8c53a0987e5877df5dfe30b7b7025cefffd0 (patch) | |
tree | 326823e70b78e21dc3b1404a29ab806b2b06c3ec /sdk/src/java/cyanogenmod/weather/CMWeatherManager.java | |
parent | 1dab5a0ca90d877c2f1728e75176e100547192ea (diff) | |
download | vendor_cmsdk-ad0d8c53a0987e5877df5dfe30b7b7025cefffd0.zip vendor_cmsdk-ad0d8c53a0987e5877df5dfe30b7b7025cefffd0.tar.gz vendor_cmsdk-ad0d8c53a0987e5877df5dfe30b7b7025cefffd0.tar.bz2 |
Weather API: Return ID rather than RequestInfo [1/2]
Instead of exposing the RequestInfo object created by the WeatherMgr
return an ID to identify the request. This ID can be later used to
cancel the request if needed. The WeatherProviderService base class
keeps track of the ongoing requests and can map this ID to the
corresponding request
This patch also include the following minor changes:
- Use List instead of ArrayList in API
- Update javadoc to public methods to reflect API changes
- Use UUID random generator in immutable classes to generate the
hashcode rather than relying solely in the hashcode of the builder
object.
Change-Id: Ib88dd0ecddd6fdb016b77ac29709fbae092dea29
TICKET: CYNGNOS-2425
TICKET: CYNGNOS-2423
Diffstat (limited to 'sdk/src/java/cyanogenmod/weather/CMWeatherManager.java')
-rw-r--r-- | sdk/src/java/cyanogenmod/weather/CMWeatherManager.java | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java index 3ab510e..2613ea5 100644 --- a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java +++ b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java @@ -131,14 +131,14 @@ public class CMWeatherManager { * @param listener {@link WeatherUpdateRequestListener} To be notified once the active weather * service provider has finished * processing your request - * @return A {@link RequestInfo} identifying the request submitted to the weather service. - * Note that this method might return null if an error occurred while trying to submit + * @return An integer that identifies the request submitted to the weather service + * Note that this method might return -1 if an error occurred while trying to submit * the request. */ - public RequestInfo requestWeatherUpdate(@NonNull Location location, + public int requestWeatherUpdate(@NonNull Location location, @NonNull WeatherUpdateRequestListener listener) { if (sWeatherManagerService == null) { - return null; + return -1; } try { @@ -148,9 +148,9 @@ public class CMWeatherManager { .build(); if (listener != null) mWeatherUpdateRequestListeners.put(info, listener); sWeatherManagerService.updateWeather(info); - return info; + return info.hashCode(); } catch (RemoteException e) { - return null; + return -1; } } @@ -164,14 +164,14 @@ public class CMWeatherManager { * @param listener {@link WeatherUpdateRequestListener} To be notified once the active weather * service provider has finished * processing your request - * @return A {@link RequestInfo} identifying the request submitted to the weather service. - * Note that this method might return null if an error occurred while trying to submit + * @return An integer that identifies the request submitted to the weather service. + * Note that this method might return -1 if an error occurred while trying to submit * the request. */ - public RequestInfo requestWeatherUpdate(@NonNull WeatherLocation weatherLocation, + public int requestWeatherUpdate(@NonNull WeatherLocation weatherLocation, @NonNull WeatherUpdateRequestListener listener) { if (sWeatherManagerService == null) { - return null; + return -1; } try { @@ -181,9 +181,9 @@ public class CMWeatherManager { .build(); if (listener != null) mWeatherUpdateRequestListeners.put(info, listener); sWeatherManagerService.updateWeather(info); - return info; + return info.hashCode(); } catch (RemoteException e) { - return null; + return -1; } } @@ -195,13 +195,13 @@ public class CMWeatherManager { * completed. Upon success, a list of * {@link cyanogenmod.weather.WeatherLocation} * will be provided - * @return A {@link RequestInfo} identifying the request submitted to the weather service. - * Note that this method might return null if an error occurred while trying to submit + * @return An integer that identifies the request submitted to the weather service. + * Note that this method might return -1 if an error occurred while trying to submit * the request. */ - public RequestInfo lookupCity(@NonNull String city, @NonNull LookupCityRequestListener listener) { + public int lookupCity(@NonNull String city, @NonNull LookupCityRequestListener listener) { if (sWeatherManagerService == null) { - return null; + return -1; } try { RequestInfo info = new RequestInfo @@ -210,26 +210,23 @@ public class CMWeatherManager { .build(); if (listener != null) mLookupNameRequestListeners.put(info, listener); sWeatherManagerService.lookupCity(info); - return info; + return info.hashCode(); } catch (RemoteException e) { - return null; + return -1; } } /** * Cancels a request that was previously submitted to the weather service. - * @param info The {@link RequestInfo} that you received when the request was submitted + * @param requestId The ID that you received when the request was submitted */ - public void cancelRequest(RequestInfo info) { + public void cancelRequest(int requestId) { if (sWeatherManagerService == null) { return; } - if (info == null) { - return; - } try { - sWeatherManagerService.cancelRequest(info); + sWeatherManagerService.cancelRequest(requestId); }catch (RemoteException e){ } } @@ -345,11 +342,7 @@ public class CMWeatherManager { mHandler.post(new Runnable() { @Override public void run() { - ArrayList<WeatherLocation> list = null; - if (weatherLocations != null) { - list = new ArrayList<>(weatherLocations); - } - listener.onLookupCityRequestCompleted(list); + listener.onLookupCityRequestCompleted(weatherLocations); } }); } @@ -386,7 +379,7 @@ public class CMWeatherManager { * * @param locations */ - void onLookupCityRequestCompleted(ArrayList<WeatherLocation> locations); + void onLookupCityRequestCompleted(List<WeatherLocation> locations); } /** |