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

Commit

Permalink
[android] #3244 - Adding support for Callbacks using MapChange events.
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Dec 17, 2015
1 parent 054433a commit 33af8ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,32 @@ public final void animateCamera (CameraUpdate update, MapView.CancelableCallback
* @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
* @param callback An optional callback to be notified from the main thread when the animation stops. If the animation stops due to its natural completion, the callback will be notified with onFinish(). If the animation stops due to interruption by a later camera movement or a user gesture, onCancel() will be called. The callback should not attempt to move or animate the camera in its cancellation method. If a callback isn't required, leave it as null.
*/
public final void animateCamera (CameraUpdate update, int durationMs, MapView.CancelableCallback callback) {
public final void animateCamera (CameraUpdate update, int durationMs, final MapView.CancelableCallback callback) {

mNativeMapView.cancelTransitions();

// Register callbacks early enough
if (callback != null) {
final MapView view = this;
addOnMapChangedListener(new OnMapChangedListener() {
@Override
public void onMapChanged(@MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED || change == REGION_DID_CHANGE) {
// Invoke callback on UI Thread
view.post(new Runnable() {
@Override
public void run() {
callback.onFinish();
}
});

// Clean up after self
removeOnMapChangedListener(this);
}
}
});
}

// Convert Degrees To Radians
double angle = -1;
if (update.getBearing() >= 0) {
Expand All @@ -1543,13 +1566,6 @@ public final void animateCamera (CameraUpdate update, int durationMs, MapView.Ca
Log.i(TAG, "flyTo() called with angle = " + angle + "; target = " + update.getTarget() + "; durationNano = " + durationNano + "; Pitch = " + pitch + "; Zoom = " + update.getZoom());
flyTo(angle, update.getTarget(), durationNano, pitch, update.getZoom());
}

/*
// Not implemented yet
if (callback != null) {
callback.onFinish();
}
*/
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
Expand All @@ -18,6 +19,8 @@

public class CameraActivity extends AppCompatActivity {

private static final String TAG = "CameraActivity";

private MapView mMapView;

@Override
Expand Down Expand Up @@ -70,12 +73,12 @@ public void onClick(View view) {
@Override
public void onCancel() {
// NOTE: This shouldn't appear
Toast.makeText(getApplicationContext(), "onCancel Callback called.", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onCancel Callback called.");
}

@Override
public void onFinish() {
Toast.makeText(getApplicationContext(), "onFinish Callback called.", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onFinish Callback called.");
}
};

Expand All @@ -99,12 +102,12 @@ public void onClick(View view) {
MapView.CancelableCallback callback = new MapView.CancelableCallback() {
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), "Duration onCancel Callback called.", Toast.LENGTH_SHORT).show();
Log.i(TAG, "Duration onCancel Callback called.");
}

@Override
public void onFinish() {
Toast.makeText(getApplicationContext(), "Duration onFinish Callback called.", Toast.LENGTH_SHORT).show();
Log.i(TAG, "Duration onFinish Callback called.");
}
};

Expand Down

0 comments on commit 33af8ac

Please sign in to comment.