diff options
author | Antonio Zugaldia <antonio@mapbox.com> | 2016-07-14 16:20:02 -0400 |
---|---|---|
committer | Antonio Zugaldia <antonio@mapbox.com> | 2016-07-14 16:44:58 -0400 |
commit | 11095881f7ed8e78d4b2b27ef37baabcfca0b80f (patch) | |
tree | e72b46187a6e34f997040d10d2dede9e0230d134 | |
parent | 277b1f4c2540466c72c6147892d9b4247393fbd1 (diff) | |
download | qtlocation-mapboxgl-11095881f7ed8e78d4b2b27ef37baabcfca0b80f.tar.gz |
[android] Adds an API to enable/disable delivering messages when the region goes inactive.
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java index 7f066e74d1..3756c93df2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java @@ -140,6 +140,34 @@ public class OfflineRegion { public static final int STATE_INACTIVE = 0; public static final int STATE_ACTIVE = 1; + // Keep track of the region state + private int state = STATE_INACTIVE; + + private boolean deliverInactiveMessages = false; + + /** + * Gets whether or not the `OfflineRegionObserver` will continue to deliver messages even if + * the region state has been set as STATE_INACTIVE. + */ + public boolean isDeliveringInactiveMessages() { + return deliverInactiveMessages; + } + + /** + * When set true, the `OfflineRegionObserver` will continue to deliver messages even if + * the region state has been set as STATE_INACTIVE (operations happen asynchronously). If set + * false, the client won't be notified of further messages. + */ + public void setDeliverInactiveMessages(boolean deliverInactiveMessages) { + this.deliverInactiveMessages = deliverInactiveMessages; + } + + private boolean deliverMessages() { + if (state == STATE_ACTIVE) return true; + if (isDeliveringInactiveMessages()) return true; + return false; + } + /* * Constructor */ @@ -180,32 +208,38 @@ public class OfflineRegion { setOfflineRegionObserver(new OfflineRegionObserver() { @Override public void onStatusChanged(final OfflineRegionStatus status) { - getHandler().post(new Runnable() { - @Override - public void run() { - observer.onStatusChanged(status); - } - }); + if (deliverMessages()) { + getHandler().post(new Runnable() { + @Override + public void run() { + observer.onStatusChanged(status); + } + }); + } } @Override public void onError(final OfflineRegionError error) { - getHandler().post(new Runnable() { - @Override - public void run() { - observer.onError(error); - } - }); + if (deliverMessages()) { + getHandler().post(new Runnable() { + @Override + public void run() { + observer.onError(error); + } + }); + } } @Override public void mapboxTileCountLimitExceeded(final long limit) { - getHandler().post(new Runnable() { - @Override - public void run() { - observer.mapboxTileCountLimitExceeded(limit); - } - }); + if (deliverMessages()) { + getHandler().post(new Runnable() { + @Override + public void run() { + observer.mapboxTileCountLimitExceeded(limit); + } + }); + } } }); } @@ -214,6 +248,7 @@ public class OfflineRegion { * Pause or resume downloading of regional resources. */ public void setDownloadState(@DownloadState int state) { + this.state = state; setOfflineRegionDownloadState(state); } |