Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - use the correct cancelable callback after posting the can…
Browse files Browse the repository at this point in the history
…celation
  • Loading branch information
tobrun committed Jan 9, 2018
1 parent c7b2c5c commit 5d791f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.graphics.RectF;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -713,20 +712,6 @@ public final void moveCamera(CameraUpdate update) {
*/
public final void moveCamera(final CameraUpdate update, final MapboxMap.CancelableCallback callback) {
transform.moveCamera(MapboxMap.this, update, callback);
// MapChange.REGION_DID_CHANGE_ANIMATED is not called for `jumpTo`
// invalidate camera position to provide OnCameraChange event.
invalidateCameraPosition();

if (callback != null) {
new Handler().post(new Runnable() {
@Override
public void run() {
if (callback != null) {
callback.onFinish();
}
}
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;

import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;

import timber.log.Timber;

import static com.mapbox.mapboxsdk.maps.MapView.REGION_DID_CHANGE_ANIMATED;
Expand All @@ -32,6 +30,7 @@ final class Transform implements MapView.OnMapChangedListener {
private final MarkerViewManager markerViewManager;
private final TrackingSettings trackingSettings;
private final MyLocationView myLocationView;
private final Handler handler = new Handler();

private CameraPosition cameraPosition;
private MapboxMap.CancelableCallback cameraCancelableCallback;
Expand Down Expand Up @@ -83,7 +82,7 @@ public void onMapChanged(@MapView.MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED) {
updateCameraPosition(invalidateCameraPosition());
if (cameraCancelableCallback != null) {
new Handler().post(new Runnable() {
handler.post(new Runnable() {
@Override
public void run() {
if (cameraCancelableCallback != null) {
Expand All @@ -99,14 +98,21 @@ public void run() {
}

@UiThread
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) {
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, final MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
cameraChangeDispatcher.onCameraIdle();
handler.post(new Runnable() {
@Override
public void run() {
invalidateCameraPosition();
callback.onFinish();
}
});
}
}

Expand Down Expand Up @@ -182,16 +188,15 @@ void cancelTransitions() {

// notify animateCamera and easeCamera about cancelling
if (cameraCancelableCallback != null) {
final MapboxMap.CancelableCallback callback = cameraCancelableCallback;
cameraChangeDispatcher.onCameraIdle();
new Handler().post(new Runnable() {
handler.post(new Runnable() {
@Override
public void run() {
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onCancel();
cameraCancelableCallback = null;
}
callback.onCancel();
}
});
cameraCancelableCallback = null;
}

// cancel ongoing transitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;

import timber.log.Timber;

/**
Expand Down

0 comments on commit 5d791f8

Please sign in to comment.