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

Commit

Permalink
[android] #3244 - Implementing animateCamera with callback. Updating …
Browse files Browse the repository at this point in the history
…CameraActivity to support 3 use cases to align with the 3 animateCamera methods.
  • Loading branch information
bleege committed Dec 14, 2015
1 parent 08b5c17 commit 19d5237
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,10 @@ public final void animateCamera (CameraUpdate update) {
* @param callback The callback to invoke from the main thread when the animation stops. If the animation completes normally, onFinish() is called; otherwise, onCancel() is called. Do not update or animate the camera from within onCancel().
*/
public final void animateCamera (CameraUpdate update, MapView.CancelableCallback callback) {

animateCamera(update);
if (callback != null) {
callback.onFinish();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.mapbox.mapboxsdk.testapp;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
Expand Down Expand Up @@ -35,6 +39,52 @@ protected void onCreate(Bundle savedInstanceState) {
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.setCompassEnabled(true);
mMapView.onCreate(savedInstanceState);

Button cameraButton = (Button) findViewById(R.id.cameraAnimateButton);
cameraButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Lambeau Field
.zoom(14) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});

Button cameraCallbackButton = (Button) findViewById(R.id.cameraAnimateCallbackButton);
cameraCallbackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(48.21874, 11.62465)) // Sets the center of the map to Allianz Arena
.zoom(16) // Sets the zoom
.bearing(180) // Sets the orientation of the camera to east
.tilt(40) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder

MapView.CancelableCallback callback = new MapView.CancelableCallback() {
@Override
public void onCancel() {
// NOTE: This shouldn't appear
Toast.makeText(getApplicationContext(), "animateCamera() onCancel Callback called.", Toast.LENGTH_SHORT).show();
}

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

mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), callback);

}
});


}

@Override
Expand All @@ -47,15 +97,6 @@ protected void onStart() {
public void onResume() {
super.onResume();
mMapView.onResume();


CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Mountain View
.zoom(14) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,34 @@
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_camera_animate"
android:id="@+id/cameraAnimateButton"
android:layout_margin="@dimen/fab_margin"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@color/white"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_camera_animate_callback"
android:id="@+id/cameraAnimateCallbackButton"
android:layout_alignTop="@+id/cameraAnimateButton"
android:layout_centerHorizontal="true"
android:background="@color/white"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_camera_animate_duration"
android:id="@+id/cameraAnimateDurationButton"
android:layout_alignBottom="@+id/cameraAnimateCallbackButton"
android:layout_alignParentRight="true"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_24dp"
app:backgroundTint="@android:color/white" />
android:layout_marginRight="@dimen/fab_margin"
android:background="@color/white"/>

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<string name="action_visible_bounds_explanation">Center map around 2 markers</string>
<string name="action_remove_polylines">Remove polylines</string>

<string name="button_camera_animate">Animate</string>
<string name="button_camera_animate_callback">Callback</string>
<string name="button_camera_animate_duration">Duration</string>

<string name="label_fps">FPS:</string>

<string name="styleMapboxStreets">Mapbox Streets</string>
Expand Down

0 comments on commit 19d5237

Please sign in to comment.