diff options
author | Luis Vidal <lvidal@cyngn.com> | 2016-04-06 15:39:49 -0700 |
---|---|---|
committer | Luis Vidal <lvidal@cyngn.com> | 2016-04-07 22:42:43 -0700 |
commit | 343245f4e6331b1059240150e62e0c9a9d8d3a54 (patch) | |
tree | 2a8901d3268646f2576033895e95be7a7aed4410 /sdk/src/java/cyanogenmod/weather | |
parent | 2eddb5f7c706d37004e06ecd5c39d0f3ab724f55 (diff) | |
download | vendor_cmsdk-343245f4e6331b1059240150e62e0c9a9d8d3a54.zip vendor_cmsdk-343245f4e6331b1059240150e62e0c9a9d8d3a54.tar.gz vendor_cmsdk-343245f4e6331b1059240150e62e0c9a9d8d3a54.tar.bz2 |
Add API to cancel an active weather request
Add new API cancelRequest to CMWeatherManager. This will allow
clients to cancel a request that was previuosly submitted to
the weather service.
As part of this change, requestWeatherUpdate(weatherLocation),
requestWeatherUpdate(Location) and lookupCity(cityName) will
now return the RequestInfo object created if the request
was successfully submitted to the weather manager service
TICKET: CYNGNOS-2383
TICKET: CYNGNOS-2385
Change-Id: Ic122f91e0ea8a24d81dbed48741ef1e33567b56c
Diffstat (limited to 'sdk/src/java/cyanogenmod/weather')
-rw-r--r-- | sdk/src/java/cyanogenmod/weather/CMWeatherManager.java | 45 | ||||
-rw-r--r-- | sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl | 1 | ||||
-rw-r--r-- | sdk/src/java/cyanogenmod/weather/RequestInfo.java | 4 |
3 files changed, 42 insertions, 8 deletions
diff --git a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java index 32eab52..3ab510e 100644 --- a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java +++ b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java @@ -131,11 +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 + * the request. */ - public void requestWeatherUpdate(@NonNull Location location, + public RequestInfo requestWeatherUpdate(@NonNull Location location, @NonNull WeatherUpdateRequestListener listener) { if (sWeatherManagerService == null) { - return; + return null; } try { @@ -145,7 +148,9 @@ public class CMWeatherManager { .build(); if (listener != null) mWeatherUpdateRequestListeners.put(info, listener); sWeatherManagerService.updateWeather(info); + return info; } catch (RemoteException e) { + return null; } } @@ -159,11 +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 + * the request. */ - public void requestWeatherUpdate(@NonNull WeatherLocation weatherLocation, + public RequestInfo requestWeatherUpdate(@NonNull WeatherLocation weatherLocation, @NonNull WeatherUpdateRequestListener listener) { if (sWeatherManagerService == null) { - return; + return null; } try { @@ -173,7 +181,9 @@ public class CMWeatherManager { .build(); if (listener != null) mWeatherUpdateRequestListeners.put(info, listener); sWeatherManagerService.updateWeather(info); + return info; } catch (RemoteException e) { + return null; } } @@ -185,10 +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 + * the request. */ - public void lookupCity(@NonNull String city, @NonNull LookupCityRequestListener listener) { + public RequestInfo lookupCity(@NonNull String city, @NonNull LookupCityRequestListener listener) { if (sWeatherManagerService == null) { - return; + return null; } try { RequestInfo info = new RequestInfo @@ -197,7 +210,27 @@ public class CMWeatherManager { .build(); if (listener != null) mLookupNameRequestListeners.put(info, listener); sWeatherManagerService.lookupCity(info); + return info; } catch (RemoteException e) { + return null; + } + } + + /** + * Cancels a request that was previously submitted to the weather service. + * @param info The {@link RequestInfo} that you received when the request was submitted + */ + public void cancelRequest(RequestInfo info) { + if (sWeatherManagerService == null) { + return; + } + if (info == null) { + return; + } + + try { + sWeatherManagerService.cancelRequest(info); + }catch (RemoteException e){ } } diff --git a/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl b/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl index 21e1d26..8caac49 100644 --- a/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl +++ b/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl @@ -28,4 +28,5 @@ interface ICMWeatherManager { oneway void unregisterWeatherServiceProviderChangeListener( in IWeatherServiceProviderChangeListener listener); String getActiveWeatherServiceProviderLabel(); + oneway void cancelRequest(in RequestInfo info); }
\ No newline at end of file diff --git a/sdk/src/java/cyanogenmod/weather/RequestInfo.java b/sdk/src/java/cyanogenmod/weather/RequestInfo.java index 353b5fd..4086c62 100644 --- a/sdk/src/java/cyanogenmod/weather/RequestInfo.java +++ b/sdk/src/java/cyanogenmod/weather/RequestInfo.java @@ -85,7 +85,7 @@ public final class RequestInfo implements Parcelable { * set, will null out the city name and weather location. */ public Builder setLocation(Location location) { - this.mLocation = location; + this.mLocation = new Location(location); this.mCityName = null; this.mWeatherLocation = null; this.mRequestType = TYPE_GEO_LOCATION_REQ; @@ -208,7 +208,7 @@ public final class RequestInfo implements Parcelable { * otherwise */ public Location getLocation() { - return mLocation; + return new Location(mLocation); } /** |