From 759e67b70d4bad8794c7b627f46cd660299c0271 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 1 Dec 2015 16:01:32 -0500 Subject: [PATCH] [android] #2805 - add sample tilt activity to test app --- .../src/main/AndroidManifest.xml | 3 + .../mapboxsdk/testapp/MainActivity.java | 4 + .../mapboxsdk/testapp/TiltActivity.java | 85 +++++++++++++++++++ .../src/main/res/layout/activity_tilt.xml | 13 +++ .../src/main/res/menu/menu_drawer.xml | 6 ++ .../src/main/res/values/strings.xml | 2 + 6 files changed, 113 insertions(+) create mode 100644 android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java create mode 100644 android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index e600ef3b5..de5f3a2aa 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -38,6 +38,9 @@ android:name=".BulkMarkerActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/action_add_bulk_markers" /> + diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index 570c85342..17af8fe2d 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -341,6 +341,10 @@ public class MainActivity extends AppCompatActivity { startActivity(new Intent(getApplicationContext(), InfoWindowAdapterActivity.class)); return true; + case R.id.action_tilt: + startActivity(new Intent(getApplicationContext(), TiltActivity.class)); + return true; + case R.id.action_map_fragment: startActivity(new Intent(getApplicationContext(), MapFragmentActivity.class)); return true; diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java new file mode 100644 index 000000000..5ff29fe22 --- /dev/null +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java @@ -0,0 +1,85 @@ +package com.mapbox.mapboxsdk.testapp; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.constants.Style; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.utils.ApiAccess; +import com.mapbox.mapboxsdk.views.MapView; + +public class TiltActivity extends AppCompatActivity { + + private MapView mMapView = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_tilt); + + // Target + LatLng nyc = new LatLng(40.73581, -73.99155); + + // Set up the map + mMapView = (MapView) findViewById(R.id.tiltMapView); + mMapView.setAccessToken(ApiAccess.getToken(this)); + mMapView.setStyleUrl(Style.MAPBOX_STREETS); + mMapView.setCenterCoordinate(nyc); + mMapView.setZoomLevel(11); + mMapView.onCreate(savedInstanceState); + + /* + * Our tilt API follows Google's Android API: + * https://developers.google.com/maps/documentation/android-api/views#updating_the_camera_view + */ + + // Construct a CameraPosition focusing on target and animate the camera to that position. + CameraPosition cameraPosition = new CameraPosition.Builder() + .target(nyc) // Sets the center of the map to target + .zoom(17) // 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 + + // Triggers tilt + //mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); + } + + @Override + protected void onStart() { + super.onStart(); + mMapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + mMapView.onStop(); + } + + @Override + public void onPause() { + super.onPause(); + mMapView.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + mMapView.onResume(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mMapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mMapView.onSaveInstanceState(outState); + } + +} diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml new file mode 100644 index 000000000..2e27fbf07 --- /dev/null +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml index 69c3f7e59..f8bf152a5 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml @@ -66,6 +66,12 @@ android:title="@string/navdrawer_menu_title_individual_tests"> + + Mapbox GL + Map Tilt InfoWindow Adapter Map Fragment Activity Press For Marker Activity @@ -24,6 +25,7 @@ Cycle map debug options Toggle point annotations InfoWindow Adapter + Tilt MapFragment Press For Marker Manual Zoom