summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuardiola31337 <pablo.guardiola@mapbox.com>2017-03-03 14:54:38 -0500
committerGuardiola31337 <pablo.guardiola@mapbox.com>2017-03-03 14:54:38 -0500
commit12eb147234814a8d5b0b7c634a1302407ef85561 (patch)
treec0aa3f808ff6eaa48aba9332337146a081a2377e
parent7c1fe5b495000f991cbc8c4fa0ef71e648f5ae64 (diff)
downloadqtlocation-mapboxgl-upstream/7878_dont_disable_tracking_on_gestures.tar.gz
[android] add camera location activityupstream/7878_dont_disable_tracking_on_gestures
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/CameraLocationActivity.java216
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_location.xml55
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml2
4 files changed, 284 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index 9aeb0282b9..eaed048c2c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -217,6 +217,17 @@
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
+ android:name=".activity.userlocation.CameraLocationActivity"
+ android:description="@string/description_user_location_tracking_camera"
+ android:label="@string/activity_user_tracking_mode_camera">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_userlocation"/>
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity"/>
+ </activity>
+ <activity
android:name=".activity.userlocation.MyLocationDrawableActivity"
android:description="@string/description_user_location_customization"
android:label="@string/activity_user_tracking_customization">
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/CameraLocationActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/CameraLocationActivity.java
new file mode 100644
index 0000000000..e89c1ff4b3
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/CameraLocationActivity.java
@@ -0,0 +1,216 @@
+package com.mapbox.mapboxsdk.testapp.activity.userlocation;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.SwitchCompat;
+import android.view.View;
+import android.widget.CompoundButton;
+import android.widget.Toast;
+
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.constants.MyLocationTracking;
+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.maps.TrackingSettings;
+import com.mapbox.mapboxsdk.testapp.R;
+
+import timber.log.Timber;
+
+/**
+ * Test activity showcasing the Camera API and listen to camera updates by animating the camera above London.
+ * <p>
+ * Shows how to use animate, ease and move camera update factory methods.
+ * </p>
+ */
+public class CameraLocationActivity extends AppCompatActivity implements OnMapReadyCallback {
+
+ private static final LatLng LAT_LNG_MED_STAR_HOSPITAL = new LatLng(-77.014517, 38.929326);
+ private static final LatLng LAT_LNG_NATIONAL_GEO_MUSEUM = new LatLng(-77.037959, 38.905410);
+
+ private MapboxMap mapboxMap;
+ private MapView mapView;
+ private boolean cameraState;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_camera_location);
+
+ SwitchCompat mySwitch = (SwitchCompat) findViewById(R.id.locationButton);
+
+ mySwitch.setChecked(false);
+ mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ TrackingSettings trackingSettings = mapboxMap.getTrackingSettings();
+ if (isChecked) {
+ trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ } else {
+ trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
+ }
+ mapboxMap.setMyLocationEnabled(true);
+ }
+ });
+
+ mapView = (MapView) findViewById(R.id.mapView);
+ if (mapView != null) {
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(this);
+ }
+ }
+
+ @Override
+ public void onMapReady(MapboxMap map) {
+ mapboxMap = map;
+ mapboxMap.getUiSettings().setAttributionEnabled(false);
+ mapboxMap.getUiSettings().setLogoEnabled(false);
+ mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
+ @Override
+ public void onCameraChange(CameraPosition position) {
+ Timber.w(position.toString());
+ }
+ });
+
+ // handle move button clicks
+ View moveButton = findViewById(R.id.cameraMoveButton);
+ if (moveButton != null) {
+ moveButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .target(getNextLatLng())
+ .zoom(14)
+ .tilt(30)
+ .tilt(0)
+ .build();
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
+ }
+ });
+ }
+
+ // handle ease button clicks
+ View easeButton = findViewById(R.id.cameraEaseButton);
+ if (easeButton != null) {
+ easeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .target(getNextLatLng())
+ .zoom(15)
+ .bearing(180)
+ .tilt(30)
+ .build();
+
+ MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
+ @Override
+ public void onCancel() {
+ Timber.i("Duration onCancel Callback called.");
+ Toast.makeText(
+ CameraLocationActivity.this,
+ "Ease onCancel Callback called.",
+ Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void onFinish() {
+ Timber.i("Duration onFinish Callback called.");
+ Toast.makeText(
+ CameraLocationActivity.this,
+ "Ease onFinish Callback called.",
+ Toast.LENGTH_LONG).show();
+ }
+ };
+
+ mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback);
+ }
+ });
+ }
+
+ // handle animate button clicks
+ View animateButton = findViewById(R.id.cameraAnimateButton);
+ if (animateButton != null) {
+ animateButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .target(getNextLatLng())
+ .bearing(270)
+ .tilt(20)
+ .build();
+
+ MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
+ @Override
+ public void onCancel() {
+ Timber.i("Duration onCancel Callback called.");
+ Toast.makeText(
+ CameraLocationActivity.this,
+ "Duration onCancel Callback called.",
+ Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void onFinish() {
+ Timber.i("Duration onFinish Callback called.");
+ Toast.makeText(
+ CameraLocationActivity.this,
+ "Duration onFinish Callback called.",
+ Toast.LENGTH_LONG).show();
+ }
+ };
+
+ mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback);
+ }
+ });
+ }
+ }
+
+ private LatLng getNextLatLng() {
+ cameraState = !cameraState;
+ return cameraState ? LAT_LNG_NATIONAL_GEO_MUSEUM : LAT_LNG_MED_STAR_HOSPITAL;
+ }
+
+ @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();
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_location.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_location.xml
new file mode 100644
index 0000000000..9f28b7e5c4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera_location.xml
@@ -0,0 +1,55 @@
+<?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">
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:id="@+id/mapView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:mapbox_myLocationTintColor="@color/primary"
+ app:mapbox_myLocationAccuracyTintColor="@color/primary"
+ app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
+ app:mapbox_cameraTargetLat="38.913258"
+ app:mapbox_cameraTargetLng="-77.032620"
+ app:mapbox_cameraZoom="15"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:orientation="horizontal"
+ android:weightSum="4">
+
+ <Button
+ android:id="@+id/cameraMoveButton"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/button_camera_move"/>
+
+ <Button
+ android:id="@+id/cameraEaseButton"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/button_camera_ease"/>
+
+ <Button
+ android:id="@+id/cameraAnimateButton"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/button_camera_animate"/>
+
+ <android.support.v7.widget.SwitchCompat
+ android:id="@+id/locationButton"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"/>
+
+ </LinearLayout>
+</RelativeLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
index 61d251f861..b480103db6 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
@@ -25,6 +25,7 @@
<string name="activity_double_map">Double Map Activity</string>
<string name="activity_snapshot">Snapshot Activity</string>
<string name="activity_user_tracking_mode">User tracking mode</string>
+ <string name="activity_user_tracking_mode_camera">User tracking mode (Camera)</string>
<string name="activity_user_tracking_customization">User location drawable</string>
<string name="activity_user_dot_color">User location tint color</string>
<string name="activity_user_location_toggle">User location toggle</string>
@@ -56,6 +57,7 @@
<!--Description-->
<string name="description_user_location_tracking">Tracks the location of the user</string>
+ <string name="description_user_location_tracking_camera">Tracks the location of the user (Camera)</string>
<string name="description_user_location_customization">Customize the location of the user</string>
<string name="description_user_location_dot_color">Customize the user location color</string>
<string name="description_user_location_toggle">Toggle location of the user on and off</string>