This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - add API to perform platform side animations
- Loading branch information
Showing
8 changed files
with
282 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
...pp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimatorActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package com.mapbox.mapboxsdk.testapp.activity.camera; | ||
|
||
import android.animation.Animator; | ||
import android.animation.AnimatorSet; | ||
import android.animation.TypeEvaluator; | ||
import android.animation.ValueAnimator; | ||
import android.os.Bundle; | ||
import android.support.v4.view.animation.FastOutLinearInInterpolator; | ||
import android.support.v4.view.animation.FastOutSlowInInterpolator; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.view.animation.AnticipateOvershootInterpolator; | ||
|
||
import com.mapbox.mapboxsdk.camera.CameraPosition; | ||
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; | ||
|
||
/** | ||
* Test activity showcasing using Android SDK animators to animate camera position changes. | ||
*/ | ||
public class CameraAnimatorActivity extends AppCompatActivity implements OnMapReadyCallback { | ||
|
||
private static final double ANIMATION_DELAY_FACTOR = 1.5; | ||
|
||
private MapView mapView; | ||
private MapboxMap mapboxMap; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_camera_animator); | ||
|
||
mapView = (MapView) findViewById(R.id.mapView); | ||
if (mapView != null) { | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(this); | ||
} | ||
} | ||
|
||
@Override | ||
public void onMapReady(final MapboxMap map) { | ||
mapboxMap = map; | ||
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
view.setVisibility(View.GONE); | ||
createAnimator(mapboxMap.getCameraPosition()).start(); | ||
} | ||
}); | ||
} | ||
|
||
private Animator createAnimator(CameraPosition currentPosition) { | ||
AnimatorSet animatorSet = new AnimatorSet(); | ||
animatorSet.play(createLatLngAnimator(currentPosition.target)); | ||
animatorSet.play(createZoomAnimator(currentPosition.zoom)); | ||
animatorSet.play(createBearingAnimator(currentPosition.bearing)); | ||
animatorSet.play(createTiltAnimator(currentPosition.tilt)); | ||
return animatorSet; | ||
} | ||
|
||
private Animator createLatLngAnimator(LatLng currentPosition) { | ||
LatLng target = new LatLng(37.789992, -122.402214); | ||
ValueAnimator latLngAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), currentPosition, target); | ||
latLngAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR)); | ||
latLngAnimator.setInterpolator(new FastOutSlowInInterpolator()); | ||
latLngAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setLatLng((LatLng) animation.getAnimatedValue()); | ||
} | ||
}); | ||
return latLngAnimator; | ||
} | ||
|
||
private Animator createZoomAnimator(double currentZoom) { | ||
ValueAnimator zoomAnimator = ValueAnimator.ofFloat((float) currentZoom, 14.5f); | ||
zoomAnimator.setDuration((long) (2200 * ANIMATION_DELAY_FACTOR)); | ||
zoomAnimator.setStartDelay((long) (600 * ANIMATION_DELAY_FACTOR)); | ||
zoomAnimator.setInterpolator(new AnticipateOvershootInterpolator()); | ||
zoomAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setZoom((Float) animation.getAnimatedValue()); | ||
} | ||
}); | ||
return zoomAnimator; | ||
} | ||
|
||
private Animator createBearingAnimator(double currentBearing) { | ||
ValueAnimator bearingAnimator = ValueAnimator.ofFloat((float) currentBearing, 135); | ||
bearingAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR)); | ||
bearingAnimator.setStartDelay((long) (1000 * ANIMATION_DELAY_FACTOR)); | ||
bearingAnimator.setInterpolator(new FastOutLinearInInterpolator()); | ||
bearingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setBearing((Float) animation.getAnimatedValue()); | ||
} | ||
}); | ||
return bearingAnimator; | ||
} | ||
|
||
private Animator createTiltAnimator(double currentTilt) { | ||
ValueAnimator tiltAnimator = ValueAnimator.ofFloat((float) currentTilt, 60); | ||
tiltAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR)); | ||
tiltAnimator.setStartDelay((long) (1500 * ANIMATION_DELAY_FACTOR)); | ||
tiltAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setTilt((Float) animation.getAnimatedValue()); | ||
} | ||
}); | ||
return tiltAnimator; | ||
} | ||
|
||
private static class LatLngEvaluator implements TypeEvaluator<LatLng> { | ||
|
||
private final LatLng latLng = new LatLng(); | ||
|
||
@Override | ||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { | ||
latLng.setLatitude(startValue.getLatitude() | ||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); | ||
latLng.setLongitude(startValue.getLongitude() | ||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); | ||
return latLng; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...form/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_play_arrow_black_24dp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M8,5v14l11,-7z"/> | ||
</vector> |
27 changes: 27 additions & 0 deletions
27
platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_animator.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/coordinator_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:mapbox_cameraTargetLat="37.774913" | ||
app:mapbox_cameraTargetLng="-122.419368" | ||
app:mapbox_cameraZoom="11" | ||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/fab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="end|bottom" | ||
android:layout_margin="@dimen/fab_margin" | ||
android:src="@drawable/ic_play_arrow_black_24dp" | ||
app:backgroundTint="@android:color/white"/> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters