diff options
author | Tobrun <tobrun@mapbox.com> | 2016-03-29 16:03:16 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-03-30 16:49:20 +0200 |
commit | 58da079f8cd18f66be8792e30cf2679cce04db6b (patch) | |
tree | d0e5cc8ac0cd58a961294271a266e3d878a45320 /platform | |
parent | 47ac55538ad691acc897e425ca0a892d6a3d4b99 (diff) | |
download | qtlocation-mapboxgl-58da079f8cd18f66be8792e30cf2679cce04db6b.tar.gz |
[android] #4365 - Camera Animation Type Example
Diffstat (limited to 'platform')
7 files changed, 83 insertions, 59 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java index acec8f17fb..b3da298c06 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java @@ -56,7 +56,6 @@ public final class CameraUpdateFactory { return newLatLngBounds(bounds, padding, padding, padding, padding); } - /** * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude * bounds are centered on screen at the greatest possible zoom level. diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CameraActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CameraActivityTest.java index f8a895237c..07158f708d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CameraActivityTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CameraActivityTest.java @@ -5,7 +5,7 @@ import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; -import com.mapbox.mapboxsdk.testapp.activity.CameraActivity; +import com.mapbox.mapboxsdk.testapp.activity.CameraAnimationTypeActivity; import com.mapbox.mapboxsdk.testapp.R; import org.junit.Before; @@ -14,14 +14,14 @@ import org.junit.Test; import org.junit.runner.RunWith; /** - * Tests on CameraActivity + * Tests on CameraAnimationTypeActivity */ @RunWith(AndroidJUnit4.class) @LargeTest public class CameraActivityTest extends BaseTest { @Rule - public ActivityTestRule<CameraActivity> mActivityRule = new ActivityTestRule<>(CameraActivity.class); + public ActivityTestRule<CameraAnimationTypeActivity> mActivityRule = new ActivityTestRule<>(CameraAnimationTypeActivity.class); private Activity mActivity = null; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CoordinateChangeActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CoordinateChangeActivityTest.java index 8aa2d48b7e..9d5218ea83 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CoordinateChangeActivityTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/espresso/CoordinateChangeActivityTest.java @@ -14,7 +14,7 @@ import org.junit.Test; import org.junit.runner.RunWith; /** - * Tests on CameraActivity + * Tests on CameraAnimationTypeActivity */ @RunWith(AndroidJUnit4.class) @LargeTest diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 4a639b7f38..e2a5aa9926 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -57,9 +57,9 @@ android:value="@string/category_marker" /> </activity> <activity - android:name=".activity.CameraActivity" - android:description="@string/description_camera" - android:label="@string/activity_camera"> + android:name=".activity.CameraAnimationTypeActivity" + android:description="@string/description_camera_animation_types" + android:label="@string/activity_camera_animation_types"> <meta-data android:name="@string/category" android:value="@string/category_camera" /> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/CameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/CameraAnimationTypeActivity.java index 720c73bf9c..7185335939 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/CameraActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/CameraAnimationTypeActivity.java @@ -20,16 +20,20 @@ import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.utils.ApiAccess; import com.mapbox.mapboxsdk.maps.MapView; -public class CameraActivity extends AppCompatActivity { +public class CameraAnimationTypeActivity extends AppCompatActivity { private static final String TAG = "CameraActivity"; - private MapView mMapView; + private MapView mapView; + + private boolean cameraState; + private static final LatLng LAT_LNG_LONDON_EYE = new LatLng(51.50325, -0.11968); + private static final LatLng LAT_LNG_TOWER_BRIDGE = new LatLng(51.50550, -0.07520); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_camera); + setContentView(R.layout.activity_camera_animation_types); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); @@ -40,13 +44,14 @@ public class CameraActivity extends AppCompatActivity { actionBar.setDisplayShowHomeEnabled(true); } - mMapView = (MapView) findViewById(R.id.cameraMapView); - mMapView.setAccessToken(ApiAccess.getToken(this)); - mMapView.onCreate(savedInstanceState); - mMapView.getMapAsync(new OnMapReadyCallback() { + mapView = (MapView) findViewById(R.id.mapView); + mapView.setAccessToken(ApiAccess.getToken(this)); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull final MapboxMap mapboxMap) { - // set a style + mapboxMap.getUiSettings().setAttributionEnabled(false); + mapboxMap.getUiSettings().setLogoEnabled(false); mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition position) { @@ -59,9 +64,10 @@ public class CameraActivity extends AppCompatActivity { @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 - .tilt(30) // Sets the tilt of the camera to 30 degrees + .target(getNextLatLng()) + .zoom(14) + .tilt(30) + .tilt(0) .build(); mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); @@ -73,26 +79,27 @@ public class CameraActivity extends AppCompatActivity { @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 south - .build(); // Creates a CameraPosition from the builder + .target(getNextLatLng()) + .zoom(15) + .bearing(180) + .tilt(30) + .build(); MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() { @Override public void onCancel() { Log.i(TAG, "Duration onCancel Callback called."); - Toast.makeText(CameraActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show(); + Toast.makeText(CameraAnimationTypeActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show(); } @Override public void onFinish() { Log.i(TAG, "Duration onFinish Callback called."); - Toast.makeText(CameraActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show(); + Toast.makeText(CameraAnimationTypeActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show(); } }; - mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback); + mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback); } }); @@ -101,72 +108,77 @@ public class CameraActivity extends AppCompatActivity { @Override public void onClick(View view) { CameraPosition cameraPosition = new CameraPosition.Builder() - .target(new LatLng(-22.91214, -43.23012)) // Sets the center of the map to Maracanã - .bearing(270) // Sets the orientation of the camera to west - .tilt(20) // Sets the tilt of the camera to 30 degrees - .build(); // Creates a CameraPosition from the builder + .target(getNextLatLng()) + .bearing(270) + .tilt(20) + .build(); MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() { @Override public void onCancel() { Log.i(TAG, "Duration onCancel Callback called."); - Toast.makeText(CameraActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show(); + Toast.makeText(CameraAnimationTypeActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show(); } @Override public void onFinish() { Log.i(TAG, "Duration onFinish Callback called."); - Toast.makeText(CameraActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show(); + Toast.makeText(CameraAnimationTypeActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show(); } }; - mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback); + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback); } }); } }); } + private LatLng getNextLatLng() { + cameraState = !cameraState; + return cameraState ? LAT_LNG_TOWER_BRIDGE : LAT_LNG_LONDON_EYE; + } + @Override protected void onStart() { super.onStart(); - mMapView.onStart(); + mapView.onStart(); } @Override public void onResume() { super.onResume(); - mMapView.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - mMapView.onPause(); + mapView.onPause(); } @Override protected void onStop() { super.onStop(); - mMapView.onStop(); + mapView.onStop(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mMapView.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } @Override protected void onDestroy() { super.onDestroy(); - mMapView.onDestroy(); + mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); - mMapView.onLowMemory(); + mapView.onLowMemory(); } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_animation_types.xml index 0b318d781b..db5169f860 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_animation_types.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> @@ -12,39 +13,41 @@ android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> <com.mapbox.mapboxsdk.maps.MapView - android:id="@+id/cameraMapView" + android:id="@id/mapView" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_below="@+id/toolbar"/> + android:layout_below="@+id/toolbar" + app:center_latitude="51.50325" + app:center_longitude="-0.11968" + app:zoom="15" /> <Button + android:id="@+id/cameraMoveButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/button_camera_move" - android:id="@+id/cameraMoveButton" - android:layout_margin="@dimen/fab_margin" + android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" - android:layout_alignParentBottom="true" - android:background="@color/white"/> + android:layout_margin="@dimen/fab_margin" + android:text="@string/button_camera_move" /> <Button + android:id="@+id/cameraEaseButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/button_camera_ease" - android:id="@+id/cameraEaseButton" android:layout_alignTop="@+id/cameraMoveButton" android:layout_centerHorizontal="true" - android:background="@color/white"/> + android:text="@string/button_camera_ease" /> <Button + android:id="@+id/cameraAnimateButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/button_camera_animate" - android:id="@+id/cameraAnimateButton" android:layout_alignBottom="@+id/cameraEaseButton" android:layout_alignParentRight="true" + android:layout_alignParentEnd="true" android:layout_marginRight="@dimen/fab_margin" - android:background="@color/white"/> + android:layout_marginEnd="@dimen/fab_margin" + android:text="@string/button_camera_animate" /> </RelativeLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 28475f2175..1f6e3a175f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -5,25 +5,35 @@ <!-- Test Activities --> <string name="activity_mapboxmap">MapboxMap Activity</string> - <string name="activity_tilt">Map Tilt Activity</string> + + <!-- Fragment --> <string name="activity_map_fragment_suport">Support Map Fragment Activity</string> <string name="activity_map_fragment">Map Fragment Activity</string> + + <!-- Markers --> <string name="activity_press_for_marker">Press For Marker Activity</string> <string name="activity_marker_in_bulk">Add Bulk Markers Activity</string> - <string name="activity_manual_zoom">Manual Zoom Activity</string> + <string name="activity_add_bulk_markers">Add Markers In Bulk Activity</string> + + <!-- InfoWindow--> <string name="activity_info_window">Basic InfoWindow example</string> <string name="activity_infowindow_adapter">Custom InfoWindow Adapter</string> + + <!-- Camera --> + <string name="activity_manual_zoom">Manual Zoom Activity</string> <string name="activity_visible_coordinate_bounds">Visible Coordinate Bounds Activity</string> + <string name="activity_tilt">Map Tilt Activity</string> + <string name="activity_scroll_by">Scroll By Method</string> + + <!-- Other --> <string name="activity_user_tracking_mode">User tracking mode Activity</string> - <string name="activity_add_bulk_markers">Add Markers In Bulk Activity</string> - <string name="activity_camera">Camera Activity</string> + <string name="activity_camera_animation_types">Camera Animation Types</string> <string name="activity_polyline">Polyline Activity</string> <string name="activity_animate_coordinate_change">Animate Coordinate Change Activity</string> <string name="activity_custom_layer">Custom Layer Activity</string> <string name="activity_directions">Directions Activity</string> <string name="activity_geocoder">Geocoder Activity</string> <string name="activity_double_map">Double Map Activity</string> - <string name="activity_scroll_by">Scroll By Activity</string> <string name="activity_dynamic_marker">Dynamic Marker Activity</string> <string name="activity_map_padding">Map Padding Activity</string> <string name="activity_offline">Offline Map Activity</string> @@ -44,7 +54,7 @@ <string name="description_animate_coordinate_change">Animate Coordinate Change</string> <string name="description_info_window_concurrent">InfoWindow example with multiple open</string> <string name="description_add_bulk_markers">Example which adds Markers in bulk</string> - <string name="description_camera">Showcase Camera API</string> + <string name="description_camera_animation_types">Showcase the different animation types</string> <string name="description_visible_bounds">Limit Visible Bounds example</string> <string name="description_double_mapview">Having 2 MapViews in one location</string> <string name="description_dynamic_marker">Dynamic Marker example</string> |