diff options
author | Tobrun <tobrun@mapbox.com> | 2016-03-05 13:38:39 -0500 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2016-03-06 14:23:47 -0500 |
commit | d39ba766e5e2d9a74921e37ed736b3b60179892e (patch) | |
tree | 1efefb66ba4034eb3a971b8ca4fe35a29071593f /platform | |
parent | 4a3beeddba279f29ce32b172868aa907c9333e6b (diff) | |
download | qtlocation-mapboxgl-d39ba766e5e2d9a74921e37ed736b3b60179892e.tar.gz |
[android] #4206 - property animation example
Diffstat (limited to 'platform')
7 files changed, 193 insertions, 7 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 37bf928a5a..bbd27c0c3e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -108,6 +108,10 @@ <service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" /> + <activity + android:name=".AnimatedMarkerActivity" + android:label="@string/title_activity_animated_marker" /> + </application> </manifest> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/AnimatedMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/AnimatedMarkerActivity.java new file mode 100644 index 0000000000..f0383db75f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/AnimatedMarkerActivity.java @@ -0,0 +1,141 @@ +package com.mapbox.mapboxsdk.testapp; + +import android.animation.TypeEvaluator; +import android.animation.ValueAnimator; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.view.animation.AccelerateDecelerateInterpolator; + +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.constants.Style; +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.utils.ApiAccess; + +public class AnimatedMarkerActivity extends AppCompatActivity { + + private MapboxMap mMapboxMap; + private MapView mMapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_animated_marker); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + + mMapView = (MapView) findViewById(R.id.mapView); + mMapView.setAccessToken(ApiAccess.getToken(this)); + mMapView.setStyleUrl(Style.LIGHT); + mMapView.onCreate(savedInstanceState); + mMapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(@NonNull final MapboxMap mapboxMap) { + mMapboxMap = mapboxMap; + + LatLng brussels = new LatLng(50.900446, 4.485251); + LatLng washington = new LatLng(38.897108, -77.036716); + + final Marker marker = mapboxMap.addMarker(new MarkerOptions().position(brussels)); + ValueAnimator markerAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), new LatLng[]{brussels, washington}); + markerAnimator.setDuration(5000); + markerAnimator.setRepeatCount(ValueAnimator.INFINITE); + markerAnimator.setRepeatMode(ValueAnimator.REVERSE); + markerAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); + markerAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + if (marker != null) { + marker.setPosition((LatLng) animation.getAnimatedValue()); + } + } + }); + markerAnimator.start(); + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_zoom, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + + case android.R.id.home: + onBackPressed(); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + protected void onStart() { + super.onStart(); + mMapView.onStart(); + } + + @Override + public void onResume() { + super.onResume(); + mMapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mMapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mMapView.onStop(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mMapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mMapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mMapView.onLowMemory(); + } + + private class LatLngEvaluator implements TypeEvaluator<LatLng> { + @Override + public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { + return new LatLng(startValue.getLatitude() + (endValue.getLatitude() - startValue.getLatitude()) * fraction, + startValue.getLongitude() + (endValue.getLongitude() - startValue.getLongitude()) * fraction); + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index 9545b929a4..ca79df89d2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -24,26 +24,26 @@ import android.view.MenuItem; import android.view.View; import android.widget.TextView; +import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.IconFactory; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.annotations.Icon; +import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.layers.CustomLayer; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.TrackingSettings; import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer; import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil; import com.mapbox.mapboxsdk.utils.ApiAccess; -import com.mapbox.mapboxsdk.maps.MapView; import java.text.DecimalFormat; import java.util.ArrayList; @@ -467,15 +467,19 @@ public class MainActivity extends AppCompatActivity { case R.id.action_dynamic_marker: startActivity(new Intent(getApplicationContext(), DynamicMarkerChangeActivity.class)); return true; - + case R.id.action_map_padding: - startActivity(new Intent(getApplicationContext(),MapPaddingActivity.class)); + startActivity(new Intent(getApplicationContext(), MapPaddingActivity.class)); return true; case R.id.action_offline: startActivity(new Intent(getApplicationContext(), OfflineActivity.class)); return true; + case R.id.action_animated_marker: + startActivity(new Intent(getApplicationContext(), AnimatedMarkerActivity.class)); + return true; + default: return changeMapStyle(menuItem.getItemId()); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_compare_arrows_black_24dp.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_compare_arrows_black_24dp.xml new file mode 100644 index 0000000000..23417034d6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_compare_arrows_black_24dp.xml @@ -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="M9.01,14L2,14v2h7.01v3L13,15l-3.99,-4v3zM14.99,13v-3L22,10L22,8h-7.01L14.99,5L11,9l3.99,4z"/> +</vector> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animated_marker.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animated_marker.xml new file mode 100644 index 0000000000..6a09109ea8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animated_marker.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <android.support.v7.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:background="@color/primary" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> + + <com.mapbox.mapboxsdk.maps.MapView + android:id="@+id/mapView" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/toolbar" /> + +</RelativeLayout>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml index 92ec45b8c8..d04996dc95 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml @@ -209,7 +209,13 @@ android:checkable="false" android:icon="@drawable/ic_map_padding" android:title="@string/action_map_padding" /> - + + <item + android:id="@+id/action_animated_marker" + android:checkable="false" + android:icon="@drawable/ic_compare_arrows_black_24dp" + android:title="@string/action_animated_marker" /> + </menu> </item> </menu> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 85e928aadc..bd3d6390ee 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -58,6 +58,7 @@ <string name="action_dynamic_marker">Dynamic Marker</string> <string name="action_map_padding">Map Padding</string> <string name="action_offline">Offline Map</string> + <string name="action_animated_marker">Animated Marker</string> <string name="button_camera_move">Move</string> <string name="button_camera_ease">Ease</string> @@ -102,5 +103,6 @@ <string name="scrollby_y_value">Y: %1$d</string> <string name="button_download_region">Download region</string> <string name="button_list_regions">List regions</string> + <string name="title_activity_animated_marker">AnimatedMarkerActivity</string> </resources> |