summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-09-04 12:51:38 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-09-12 13:59:11 +0200
commitbfe0b67572e877dbc55f27dfcfee7c75b953fc8a (patch)
tree4ffc55176be32d7c2f7953e33dc222c0afa2a2fa /platform
parent465316b4cef4b0d4630d855a789f5b6acef2084e (diff)
downloadqtlocation-mapboxgl-bfe0b67572e877dbc55f27dfcfee7c75b953fc8a.tar.gz
[android] LocationLayer example activities
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java28
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/build.gradle4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml44
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerFragmentActivity.kt171
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerMapChangeActivity.java131
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java393
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java190
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java59
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_arrow.xml11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_icon.xml10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_puck_icon.xml23
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_location_disabled.xml9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_fragment.xml24
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_map_change.xml30
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_mode.xml78
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_manual_update.xml43
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_location_mode.xml20
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml12
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml4
-rw-r--r--platform/android/gradle/dependencies.gradle94
22 files changed, 1325 insertions, 58 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
index 45a13ed58b..021729b6ba 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
@@ -143,7 +143,7 @@ public final class LocationLayerPlugin {
/**
* This method will show the location icon and enable the camera tracking the location.
* <p>
- * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
+ * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine}.
*
* @param context the context
*/
@@ -155,10 +155,10 @@ public final class LocationLayerPlugin {
/**
* This method will show the location icon and enable the camera tracking the location.
- * <p>
- * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
*
- * @param context the context
+ * @param context the context
+ * @param useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if
+ * there should be no location engine initialized
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
public void activateLocationLayerPlugin(@NonNull Context context, boolean useDefaultLocationEngine) {
@@ -172,7 +172,7 @@ public final class LocationLayerPlugin {
/**
* This method will show the location icon and enable the camera tracking the location.
* <p>
- * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
+ * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine}.
*
* @param context the context
* @param styleRes the LocationLayerPlugin style res
@@ -185,7 +185,7 @@ public final class LocationLayerPlugin {
/**
* This method will show the location icon and enable the camera tracking the location.
* <p>
- * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
+ * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine}.
* </p>
*
* @param context the context
@@ -200,9 +200,6 @@ public final class LocationLayerPlugin {
/**
* This method will show the location icon and enable the camera tracking the location.
- * <p>
- * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
- * </p>
*
* @param context the context
* @param locationEngine the engine, or null if you'd like to only force location updates
@@ -215,9 +212,16 @@ public final class LocationLayerPlugin {
/**
* This method will show the location icon and enable the camera tracking the location.
- * <p>
- * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
- * </p>
+ *
+ * @param context the context
+ * @param locationEngine the engine
+ */
+ public void activateLocationLayerPlugin(@NonNull Context context, @NonNull LocationEngine locationEngine) {
+ activateLocationLayerPlugin(context, locationEngine, R.style.mapbox_LocationLayer);
+ }
+
+ /**
+ * This method will show the location icon and enable the camera tracking the location.
*
* @param locationEngine the engine, or null if you'd like to only force location updates
* @param options the options
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
index cf0a8ed66e..dee713ffcb 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
+++ b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
@@ -11,6 +11,9 @@ android {
versionCode 13
versionName "6.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ vectorDrawables {
+ useSupportLibrary true
+ }
}
compileOptions {
@@ -63,6 +66,7 @@ dependencies {
implementation dependenciesList.supportAppcompatV7
implementation dependenciesList.supportRecyclerView
implementation dependenciesList.supportDesign
+ implementation dependenciesList.supportConstraintLayout
// implementation dependenciesList.lost
implementation dependenciesList.gmsLocation
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index d9e2001479..8597a9ac14 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -815,6 +815,50 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity" />
</activity>
+ <activity
+ android:name=".activity.location.LocationLayerMapChangeActivity"
+ android:description="@string/description_location_map_change"
+ android:label="@string/activity_location_map_change">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_location" />
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity" />
+ </activity>
+ <activity
+ android:name=".activity.location.LocationLayerModesActivity"
+ android:description="@string/description_location_modes"
+ android:label="@string/activity_location_modes">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_location" />
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity" />
+ </activity>
+ <activity
+ android:name=".activity.location.LocationLayerFragmentActivity"
+ android:description="@string/description_location_fragment"
+ android:label="@string/activity_location_fragment">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_location" />
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity" />
+ </activity>
+ <activity
+ android:name=".activity.location.ManualLocationUpdatesActivity"
+ android:description="@string/description_location_manual"
+ android:label="@string/activity_location_manual">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_location" />
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity" />
+ </activity>
<!-- For Instrumentation tests -->
<activity
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerFragmentActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerFragmentActivity.kt
new file mode 100644
index 0000000000..fa2c84ab92
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerFragmentActivity.kt
@@ -0,0 +1,171 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.app.Fragment
+import android.location.Location
+import android.os.Bundle
+import android.support.v7.app.AppCompatActivity
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import android.widget.Toast
+import com.mapbox.android.core.location.LocationEngineListener
+import com.mapbox.android.core.permissions.PermissionsListener
+import com.mapbox.android.core.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin
+import com.mapbox.mapboxsdk.testapp.R
+import kotlinx.android.synthetic.main.activity_location_layer_fragment.*
+
+class LocationLayerFragmentActivity : AppCompatActivity() {
+ private lateinit var permissionsManager: PermissionsManager
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_layer_fragment)
+
+ fab.setOnClickListener {
+ val fragment = fragmentManager.findFragmentByTag(EmptyFragment.TAG)
+ if (fragment == null) {
+ fragmentManager
+ .beginTransaction()
+ .replace(R.id.container, EmptyFragment.newInstance(), EmptyFragment.TAG)
+ .addToBackStack("transaction2")
+ .commit()
+ } else {
+ this.onBackPressed()
+ }
+ }
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ if (savedInstanceState == null) {
+ fragmentManager
+ .beginTransaction()
+ .replace(R.id.container, LocationLayerFragment.newInstance(), LocationLayerFragment.TAG)
+ .commit()
+ }
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: MutableList<String>?) {
+ Toast.makeText(this@LocationLayerFragmentActivity, "You need to accept location permissions.",
+ Toast.LENGTH_SHORT).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ if (savedInstanceState == null) {
+ fragmentManager
+ .beginTransaction()
+ .replace(R.id.container, LocationLayerFragment.newInstance(), LocationLayerFragment.TAG)
+ .commit()
+ }
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager.requestLocationPermissions(this)
+ }
+ }
+
+ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ class LocationLayerFragment : Fragment(), LocationEngineListener {
+ companion object {
+ const val TAG = "LLFragment"
+ fun newInstance(): LocationLayerFragment {
+ return LocationLayerFragment()
+ }
+ }
+
+ private lateinit var mapView: MapView
+ private lateinit var mapboxMap: MapboxMap
+ private var plugin: LocationLayerPlugin? = null
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ mapView = MapView(inflater.context)
+ return mapView
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
+ mapView.onCreate(savedInstanceState)
+ mapView.getMapAsync {
+ mapboxMap = it
+ plugin = mapboxMap.locationLayerPlugin
+ plugin?.activateLocationLayerPlugin(activity)
+ plugin?.locationEngine?.addLocationEngineListener(this)
+ }
+ }
+
+ override fun onLocationChanged(location: Location?) {
+ if (location != null) {
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 12.0))
+ plugin?.locationEngine?.removeLocationEngineListener(this)
+ }
+ }
+
+ override fun onConnected() {
+ // no impl
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView.onPause()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView.onSaveInstanceState(outState)
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView.onStop()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView.onLowMemory()
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ mapView.onDestroy()
+ plugin?.locationEngine?.removeLocationEngineListener(this)
+ }
+ }
+
+ class EmptyFragment : Fragment() {
+ companion object {
+ const val TAG = "EmptyFragment"
+ fun newInstance(): EmptyFragment {
+ return EmptyFragment()
+ }
+ }
+
+ override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
+ val textView = TextView(inflater?.context)
+ textView.text = "This is an empty Fragment"
+ return textView
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerMapChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerMapChangeActivity.java
new file mode 100644
index 0000000000..e59627d35e
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerMapChangeActivity.java
@@ -0,0 +1,131 @@
+package com.mapbox.mapboxsdk.testapp.activity.location;
+
+import android.annotation.SuppressLint;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.design.widget.FloatingActionButton;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.Toast;
+
+import com.mapbox.android.core.permissions.PermissionsListener;
+import com.mapbox.android.core.permissions.PermissionsManager;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
+import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
+import com.mapbox.mapboxsdk.testapp.R;
+
+import java.util.List;
+
+public class LocationLayerMapChangeActivity extends AppCompatActivity implements OnMapReadyCallback {
+
+ private MapView mapView;
+ private MapboxMap mapboxMap;
+ private PermissionsManager permissionsManager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_location_layer_map_change);
+
+ mapView = findViewById(R.id.mapView);
+ FloatingActionButton stylesFab = findViewById(R.id.fabStyles);
+
+ stylesFab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mapboxMap != null) {
+ mapboxMap.setStyleUrl(Utils.getNextStyle());
+ }
+ }
+ });
+
+ mapView.setStyleUrl(Utils.getNextStyle());
+ mapView.onCreate(savedInstanceState);
+
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this);
+ } else {
+ permissionsManager = new PermissionsManager(new PermissionsListener() {
+ @Override
+ public void onExplanationNeeded(List<String> permissionsToExplain) {
+ Toast.makeText(LocationLayerMapChangeActivity.this, "You need to accept location permissions.",
+ Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onPermissionResult(boolean granted) {
+ if (granted) {
+ mapView.getMapAsync(LocationLayerMapChangeActivity.this);
+ } else {
+ finish();
+ }
+ }
+ });
+ permissionsManager.requestLocationPermissions(this);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+
+ @Override
+ public void onMapReady(MapboxMap mapboxMap) {
+ this.mapboxMap = mapboxMap;
+ activateLocationLayer();
+ }
+
+ @SuppressLint("MissingPermission")
+ private void activateLocationLayer() {
+ LocationLayerPlugin locationPlugin = mapboxMap.getLocationLayerPlugin();
+ locationPlugin.activateLocationLayerPlugin(this);
+ locationPlugin.setRenderMode(RenderMode.COMPASS);
+ }
+
+ @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();
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java
new file mode 100644
index 0000000000..ce005c1825
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationLayerModesActivity.java
@@ -0,0 +1,393 @@
+package com.mapbox.mapboxsdk.testapp.activity.location;
+
+import android.annotation.SuppressLint;
+import android.content.res.Configuration;
+import android.location.Location;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.ListPopupWindow;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.Toast;
+
+import com.mapbox.android.core.location.LocationEngine;
+import com.mapbox.android.core.location.LocationEngineListener;
+import com.mapbox.android.core.location.LocationEnginePriority;
+import com.mapbox.android.core.location.LocationEngineProvider;
+import com.mapbox.android.core.permissions.PermissionsListener;
+import com.mapbox.android.core.permissions.PermissionsManager;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerOptions;
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
+import com.mapbox.mapboxsdk.plugins.locationlayer.OnCameraTrackingChangedListener;
+import com.mapbox.mapboxsdk.plugins.locationlayer.OnLocationLayerClickListener;
+import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode;
+import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
+import com.mapbox.mapboxsdk.testapp.R;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class LocationLayerModesActivity extends AppCompatActivity implements OnMapReadyCallback,
+ LocationEngineListener, OnLocationLayerClickListener, OnCameraTrackingChangedListener {
+
+ private MapView mapView;
+ private Button locationModeBtn;
+ private Button locationTrackingBtn;
+
+ private PermissionsManager permissionsManager;
+
+ private LocationLayerPlugin locationLayerPlugin;
+ private LocationEngine locationEngine;
+ private MapboxMap mapboxMap;
+ private boolean customStyle;
+
+ private static final String SAVED_STATE_CAMERA = "saved_state_camera";
+ private static final String SAVED_STATE_RENDER = "saved_state_render";
+
+ @CameraMode.Mode
+ private int cameraMode = CameraMode.TRACKING;
+
+ @RenderMode.Mode
+ private int renderMode = RenderMode.NORMAL;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_location_layer_mode);
+
+ mapView = findViewById(R.id.mapView);
+
+ locationModeBtn = findViewById(R.id.button_location_mode);
+ locationModeBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (locationLayerPlugin == null) {
+ return;
+ }
+ showModeListDialog();
+ }
+ });
+
+ locationTrackingBtn = findViewById(R.id.button_location_tracking);
+ locationTrackingBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (locationLayerPlugin == null) {
+ return;
+ }
+ showTrackingListDialog();
+ }
+ });
+
+
+ if (savedInstanceState != null) {
+ cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA);
+ renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER);
+ }
+
+ mapView.onCreate(savedInstanceState);
+
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this);
+ } else {
+ permissionsManager = new PermissionsManager(new PermissionsListener() {
+ @Override
+ public void onExplanationNeeded(List<String> permissionsToExplain) {
+ Toast.makeText(LocationLayerModesActivity.this, "You need to accept location permissions.",
+ Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onPermissionResult(boolean granted) {
+ if (granted) {
+ mapView.getMapAsync(LocationLayerModesActivity.this);
+ } else {
+ finish();
+ }
+ }
+ });
+ permissionsManager.requestLocationPermissions(this);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+
+ @SuppressLint("MissingPermission")
+ @Override
+ public void onMapReady(MapboxMap mapboxMap) {
+ this.mapboxMap = mapboxMap;
+
+ locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
+ locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
+ locationEngine.setFastestInterval(1000);
+ locationEngine.addLocationEngineListener(this);
+ locationEngine.activate();
+
+ locationLayerPlugin = mapboxMap.getLocationLayerPlugin();
+ locationLayerPlugin.addOnLocationClickListener(this);
+ locationLayerPlugin.addOnCameraTrackingChangedListener(this);
+ locationLayerPlugin.setCameraMode(cameraMode);
+ setRendererMode(renderMode);
+ activateLocationLayer();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_location_mode, menu);
+ return true;
+ }
+
+ @SuppressLint("MissingPermission")
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (locationLayerPlugin == null) {
+ return super.onOptionsItemSelected(item);
+ }
+
+ int id = item.getItemId();
+ if (id == R.id.action_style_change) {
+ toggleStyle();
+ return true;
+ } else if (id == R.id.action_map_style_change) {
+ toggleMapStyle();
+ return true;
+ } else if (id == R.id.action_plugin_disable) {
+ locationLayerPlugin.deactivateLocationLayerPlugin();
+ return true;
+ } else if (id == R.id.action_plugin_enabled) {
+ activateLocationLayer();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void activateLocationLayer() {
+ if (locationLayerPlugin != null) {
+ int[] padding;
+ if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
+ padding = new int[] {0, 750, 0, 0};
+ } else {
+ padding = new int[] {0, 250, 0, 0};
+ }
+
+ LocationLayerOptions options = LocationLayerOptions.builder(this)
+ .padding(padding)
+ .layerBelow("waterway-label")
+ .build();
+
+ locationLayerPlugin.activateLocationLayerPlugin(locationEngine, options);
+ }
+ }
+
+ public void toggleStyle() {
+ customStyle = !customStyle;
+ locationLayerPlugin.applyStyle(
+ this,
+ customStyle ? R.style.CustomLocationLayer : R.style.mapbox_LocationLayer);
+ }
+
+ public void toggleMapStyle() {
+ String styleUrl = mapboxMap.getStyleUrl().contentEquals(Style.DARK) ? Style.LIGHT : Style.DARK;
+ mapboxMap.setStyle(styleUrl);
+ }
+
+ public LocationLayerPlugin getLocationLayerPlugin() {
+ return locationLayerPlugin;
+ }
+
+ @Override
+ @SuppressWarnings( {"MissingPermission"})
+ protected void onStart() {
+ super.onStart();
+ mapView.onStart();
+ if (locationEngine != null) {
+ locationEngine.addLocationEngineListener(this);
+ if (locationEngine.isConnected()) {
+ locationEngine.requestLocationUpdates();
+ } else {
+ locationEngine.activate();
+ }
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mapView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mapView.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mapView.onStop();
+ if (locationEngine != null) {
+ locationEngine.removeLocationEngineListener(this);
+ locationEngine.removeLocationUpdates();
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mapView.onSaveInstanceState(outState);
+ outState.putInt(SAVED_STATE_CAMERA, cameraMode);
+ outState.putInt(SAVED_STATE_RENDER, renderMode);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mapView.onDestroy();
+ if (locationEngine != null) {
+ locationEngine.deactivate();
+ }
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mapView.onLowMemory();
+ }
+
+ @Override
+ @SuppressWarnings( {"MissingPermission"})
+ public void onConnected() {
+ locationEngine.requestLocationUpdates();
+ }
+
+ @Override
+ public void onLocationChanged(Location location) {
+ // no impl
+ }
+
+ @Override
+ public void onLocationLayerClick() {
+ Toast.makeText(this, "OnLocationLayerClick", Toast.LENGTH_LONG).show();
+ }
+
+ private void showModeListDialog() {
+ List<String> modes = new ArrayList<>();
+ modes.add("Normal");
+ modes.add("Compass");
+ modes.add("GPS");
+ ArrayAdapter<String> profileAdapter = new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1, modes);
+ ListPopupWindow listPopup = new ListPopupWindow(this);
+ listPopup.setAdapter(profileAdapter);
+ listPopup.setAnchorView(locationModeBtn);
+ listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
+ String selectedMode = modes.get(position);
+ locationModeBtn.setText(selectedMode);
+ if (selectedMode.contentEquals("Normal")) {
+ setRendererMode(RenderMode.NORMAL);
+ } else if (selectedMode.contentEquals("Compass")) {
+ setRendererMode(RenderMode.COMPASS);
+ } else if (selectedMode.contentEquals("GPS")) {
+ setRendererMode(RenderMode.GPS);
+ }
+ listPopup.dismiss();
+ });
+ listPopup.show();
+ }
+
+ private void setRendererMode(@RenderMode.Mode int mode) {
+ renderMode = mode;
+ locationLayerPlugin.setRenderMode(mode);
+ if (mode == RenderMode.NORMAL) {
+ locationModeBtn.setText("Normal");
+ } else if (mode == RenderMode.COMPASS) {
+ locationModeBtn.setText("Compass");
+ } else if (mode == RenderMode.GPS) {
+ locationModeBtn.setText("Gps");
+ }
+ }
+
+ private void showTrackingListDialog() {
+ List<String> trackingTypes = new ArrayList<>();
+ trackingTypes.add("None");
+ trackingTypes.add("Tracking");
+ trackingTypes.add("Tracking Compass");
+ trackingTypes.add("Tracking GPS");
+ trackingTypes.add("Tracking GPS North");
+ ArrayAdapter<String> profileAdapter = new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1, trackingTypes);
+ ListPopupWindow listPopup = new ListPopupWindow(this);
+ listPopup.setAdapter(profileAdapter);
+ listPopup.setAnchorView(locationTrackingBtn);
+ listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
+ String selectedTrackingType = trackingTypes.get(position);
+ locationTrackingBtn.setText(selectedTrackingType);
+ if (selectedTrackingType.contentEquals("None")) {
+ locationLayerPlugin.setCameraMode(CameraMode.NONE);
+ } else if (selectedTrackingType.contentEquals("Tracking")) {
+ locationLayerPlugin.setCameraMode(CameraMode.TRACKING);
+ } else if (selectedTrackingType.contentEquals("Tracking Compass")) {
+ locationLayerPlugin.setCameraMode(CameraMode.TRACKING_COMPASS);
+ } else if (selectedTrackingType.contentEquals("Tracking GPS")) {
+ locationLayerPlugin.setCameraMode(CameraMode.TRACKING_GPS);
+ } else if (selectedTrackingType.contentEquals("Tracking GPS North")) {
+ locationLayerPlugin.setCameraMode(CameraMode.TRACKING_GPS_NORTH);
+ }
+ listPopup.dismiss();
+
+ if (locationLayerPlugin.getCameraMode() != CameraMode.NONE) {
+ locationLayerPlugin.zoomWhileTracking(15, 750, new MapboxMap.CancelableCallback() {
+ @Override
+ public void onCancel() {
+ // No impl
+ }
+
+ @Override
+ public void onFinish() {
+ locationLayerPlugin.tiltWhileTracking(45);
+ }
+ });
+ } else {
+ mapboxMap.easeCamera(CameraUpdateFactory.tiltTo(0));
+ }
+ });
+ listPopup.show();
+ }
+
+ @Override
+ public void onCameraTrackingDismissed() {
+ locationTrackingBtn.setText("None");
+ }
+
+ @Override
+ public void onCameraTrackingChanged(int currentMode) {
+ this.cameraMode = currentMode;
+
+ if (cameraMode == CameraMode.NONE) {
+ locationTrackingBtn.setText("None");
+ } else if (cameraMode == CameraMode.TRACKING) {
+ locationTrackingBtn.setText("Tracking");
+ } else if (cameraMode == CameraMode.TRACKING_COMPASS) {
+ locationTrackingBtn.setText("Tracking Compass");
+ } else if (cameraMode == CameraMode.TRACKING_GPS) {
+ locationTrackingBtn.setText("Tracking GPS");
+ } else if (cameraMode == CameraMode.TRACKING_GPS_NORTH) {
+ locationTrackingBtn.setText("Tracking GPS North");
+ }
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
new file mode 100644
index 0000000000..3e9f0853ea
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
@@ -0,0 +1,190 @@
+package com.mapbox.mapboxsdk.testapp.activity.location;
+
+import android.location.Location;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.design.widget.FloatingActionButton;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.Toast;
+
+import com.mapbox.android.core.location.LocationEngine;
+import com.mapbox.android.core.location.LocationEngineListener;
+import com.mapbox.android.core.location.LocationEnginePriority;
+import com.mapbox.android.core.location.LocationEngineProvider;
+import com.mapbox.android.core.permissions.PermissionsListener;
+import com.mapbox.android.core.permissions.PermissionsManager;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
+import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
+import com.mapbox.mapboxsdk.testapp.R;
+
+import java.util.List;
+
+import timber.log.Timber;
+
+public class ManualLocationUpdatesActivity extends AppCompatActivity implements OnMapReadyCallback,
+ LocationEngineListener {
+
+ private MapView mapView;
+ private LocationLayerPlugin locationLayerPlugin;
+ private LocationEngine locationEngine;
+ private PermissionsManager permissionsManager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_location_manual_update);
+
+ FloatingActionButton fabManualUpdate = findViewById(R.id.fabManualLocationChange);
+ fabManualUpdate.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (locationLayerPlugin != null && locationLayerPlugin.getLocationEngine() == null) {
+ locationLayerPlugin.forceLocationUpdate(
+ Utils.getRandomLocation(LatLngBounds.from(60, 25, 40, -5)));
+ }
+ }
+ });
+ fabManualUpdate.setEnabled(false);
+
+ FloatingActionButton fabToggle = findViewById(R.id.fabToggleManualLocation);
+ fabToggle.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (locationLayerPlugin != null) {
+ locationLayerPlugin.setLocationEngine(locationLayerPlugin.getLocationEngine() == null ? locationEngine :
+ null);
+
+ if (locationLayerPlugin.getLocationEngine() == null) {
+ fabToggle.setImageResource(R.drawable.ic_layers_clear);
+ fabManualUpdate.setEnabled(true);
+ fabManualUpdate.setAlpha(1f);
+ Toast.makeText(
+ ManualLocationUpdatesActivity.this,
+ "LocationEngine disable, use manual updates",
+ Toast.LENGTH_SHORT).show();
+ } else {
+ fabToggle.setImageResource(R.drawable.ic_layers);
+ fabManualUpdate.setEnabled(false);
+ fabManualUpdate.setAlpha(0.5f);
+ Toast.makeText(
+ ManualLocationUpdatesActivity.this,
+ "LocationEngine enabled",
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+ });
+
+ mapView = findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this);
+ } else {
+ permissionsManager = new PermissionsManager(new PermissionsListener() {
+ @Override
+ public void onExplanationNeeded(List<String> permissionsToExplain) {
+ Toast.makeText(ManualLocationUpdatesActivity.this, "You need to accept location permissions.",
+ Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onPermissionResult(boolean granted) {
+ if (granted) {
+ mapView.getMapAsync(ManualLocationUpdatesActivity.this);
+ } else {
+ finish();
+ }
+ }
+ });
+ permissionsManager.requestLocationPermissions(this);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+
+ @Override
+ public void onMapReady(MapboxMap mapboxMap) {
+ locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
+ locationEngine.addLocationEngineListener(this);
+ locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
+ locationEngine.activate();
+ locationLayerPlugin = mapboxMap.getLocationLayerPlugin();
+ locationLayerPlugin.activateLocationLayerPlugin(this, locationEngine);
+ locationLayerPlugin.setRenderMode(RenderMode.COMPASS);
+ }
+
+ @Override
+ @SuppressWarnings( {"MissingPermission"})
+ public void onConnected() {
+ locationEngine.requestLocationUpdates();
+ }
+
+ @Override
+ public void onLocationChanged(Location location) {
+ Timber.d("Location change occurred: %s", location.toString());
+ }
+
+ @Override
+ @SuppressWarnings( {"MissingPermission"})
+ protected void onStart() {
+ super.onStart();
+ mapView.onStart();
+ if (locationEngine != null) {
+ locationEngine.requestLocationUpdates();
+ locationEngine.addLocationEngineListener(this);
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mapView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mapView.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mapView.onStop();
+ if (locationEngine != null) {
+ locationEngine.removeLocationEngineListener(this);
+ locationEngine.removeLocationUpdates();
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mapView.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mapView.onDestroy();
+ if (locationEngine != null) {
+ locationEngine.deactivate();
+ }
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mapView.onLowMemory();
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java
new file mode 100644
index 0000000000..41c308c696
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java
@@ -0,0 +1,59 @@
+package com.mapbox.mapboxsdk.testapp.activity.location;
+
+import android.location.Location;
+
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+
+import java.util.Random;
+
+import timber.log.Timber;
+
+/**
+ * Useful utilities used throughout the testapp.
+ */
+public class Utils {
+
+ private static final String[] STYLES = new String[] {
+ Style.MAPBOX_STREETS,
+ Style.OUTDOORS,
+ Style.LIGHT,
+ Style.DARK,
+ Style.SATELLITE_STREETS
+ };
+
+ private static int index;
+
+ /**
+ * Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new
+ * style.
+ *
+ * @return a string ID representing the map style
+ */
+ public static String getNextStyle() {
+ index++;
+ if (index == STYLES.length) {
+ index = 0;
+ }
+ return STYLES[index];
+ }
+
+ /**
+ * Utility for getting a random coordinate inside a provided bounds and creates a {@link Location} from it.
+ *
+ * @param bounds bounds of the generated location
+ * @return a {@link Location} object using the random coordinate
+ */
+ public static Location getRandomLocation(LatLngBounds bounds) {
+ Random random = new Random();
+
+ double randomLat = bounds.getLatSouth() + (bounds.getLatNorth() - bounds.getLatSouth()) * random.nextDouble();
+ double randomLon = bounds.getLonWest() + (bounds.getLonEast() - bounds.getLonWest()) * random.nextDouble();
+
+ Location location = new Location("random-loc");
+ location.setLongitude(randomLon);
+ location.setLatitude(randomLat);
+ Timber.d("getRandomLatLng: %s", location.toString());
+ return location;
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_arrow.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_arrow.xml
new file mode 100644
index 0000000000..65c3b4aae3
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_arrow.xml
@@ -0,0 +1,11 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="36dp"
+ android:height="36dp"
+ android:viewportHeight="36.0"
+ android:viewportWidth="36.0">
+ <path
+ android:fillColor="#FF82C6"
+ android:pathData="M18,0L23,7L13,7L18,0ZM22.8,7C21.33,6.36 19.71,6 18,6C16.29,6 14.67,6.36 13.2,7L22.8,7Z"
+ android:strokeColor="#00000000"
+ android:strokeWidth="1"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_icon.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_icon.xml
new file mode 100644
index 0000000000..37f1d4de09
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_icon.xml
@@ -0,0 +1,10 @@
+<vector
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="14dp"
+ android:height="14dp"
+ android:viewportHeight="14.0"
+ android:viewportWidth="14.0">
+ <path
+ android:fillColor="#fff"
+ android:pathData="M7,7m-7,0a7,7 0,1 1,14 0a7,7 0,1 1,-14 0"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_puck_icon.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_puck_icon.xml
new file mode 100644
index 0000000000..31d93f1ed4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/custom_user_puck_icon.xml
@@ -0,0 +1,23 @@
+<vector
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="75dp"
+ android:height="75dp"
+ android:viewportHeight="75.0"
+ android:viewportWidth="75.0">
+ <path
+ android:fillAlpha="0.16"
+ android:fillColor="#FF3D57"
+ android:pathData="M37.5,37.5m-37.5,0a37.5,37.5 0,1 1,75 0a37.5,37.5 0,1 1,-75 0"
+ android:strokeColor="#00000000"
+ android:strokeWidth="1"/>
+ <path
+ android:fillColor="#000000"
+ android:pathData="M37.5,37.5m-28.5,0a28.5,28.5 0,1 1,57 0a28.5,28.5 0,1 1,-57 0"
+ android:strokeColor="#00000000"
+ android:strokeWidth="1"/>
+ <path
+ android:fillColor="#FF82C6"
+ android:pathData="M39.2,28.46C39.01,27.99 38.54,27.68 38.02,27.69C37.5,27.7 37.02,28.01 36.81,28.49L27.05,45.83C26.83,46.32 26.92,46.89 27.28,47.26C27.65,47.64 28.21,47.75 28.71,47.54L37.07,44.03C37.39,43.89 37.75,43.89 38.06,44.02L46.27,47.34C46.75,47.54 47.33,47.42 47.71,47.03C48.09,46.64 48.21,46.07 48,45.59L39.2,28.46Z"
+ android:strokeColor="#00000000"
+ android:strokeWidth="1"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_location_disabled.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_location_disabled.xml
new file mode 100644
index 0000000000..16f058f322
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_location_disabled.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="#FFFFFFFF"
+ android:pathData="M20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06c-1.13,0.12 -2.19,0.46 -3.16,0.97l1.5,1.5C10.16,5.19 11.06,5 12,5c3.87,0 7,3.13 7,7 0,0.94 -0.19,1.84 -0.52,2.65l1.5,1.5c0.5,-0.96 0.84,-2.02 0.97,-3.15L23,13v-2h-2.06zM3,4.27l2.04,2.04C3.97,7.62 3.25,9.23 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c1.77,-0.2 3.38,-0.91 4.69,-1.98L19.73,21 21,19.73 4.27,3 3,4.27zM16.27,17.54C15.09,18.45 13.61,19 12,19c-3.87,0 -7,-3.13 -7,-7 0,-1.61 0.55,-3.09 1.46,-4.27l9.81,9.81z"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_fragment.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_fragment.xml
new file mode 100644
index 0000000000..3c1436a1a8
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_fragment.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout 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">
+
+ <FrameLayout
+ android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/fab"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom|end"
+ android:layout_margin="@dimen/fab_margin"
+ android:tint="@android:color/white"
+ app:backgroundTint="@color/accent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ app:srcCompat="@drawable/ic_layers" />
+
+</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_map_change.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_map_change.xml
new file mode 100644
index 0000000000..54171a073d
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_map_change.xml
@@ -0,0 +1,30 @@
+<?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"
+ android:orientation="vertical">
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:id="@+id/mapView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginBottom="0dp"
+ app:mapbox_uiAttribution="false"/>
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/fabStyles"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="end|bottom"
+ android:layout_marginBottom="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginRight="16dp"
+ android:src="@drawable/ic_layers"
+ android:tint="@android:color/white"
+ app:backgroundTint="@color/accent"
+ app:layout_anchorGravity="top"/>
+
+</android.support.design.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_mode.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_mode.xml
new file mode 100644
index 0000000000..e23d876e3a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_mode.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ 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"
+ android:layout_marginBottom="0dp"
+ app:layout_constraintBottom_toTopOf="@+id/linearLayout"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:mapbox_uiAttribution="false" />
+
+ <LinearLayout
+ android:id="@+id/linearLayout"
+ style="?android:attr/buttonBarStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:background="@color/primary"
+ android:orientation="horizontal"
+ android:weightSum="4"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ tools:layout_constraintBottom_creator="1"
+ tools:layout_constraintLeft_creator="1"
+ tools:layout_constraintRight_creator="1">
+
+ <TextView
+ android:id="@+id/tv_mode"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight=".75"
+ android:gravity="center"
+ android:text="Mode:"
+ android:textColor="@color/white"
+ android:textSize="18sp"
+ android:textStyle="bold" />
+
+ <Button
+ android:id="@+id/button_location_mode"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1.25"
+ android:gravity="center"
+ android:text="Normal"
+ android:textColor="@android:color/white" />
+
+ <TextView
+ android:id="@+id/tv_tracking"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight=".85"
+ android:gravity="center"
+ android:text="Tracking:"
+ android:textColor="@color/white"
+ android:textSize="18sp"
+ android:textStyle="bold" />
+
+ <Button
+ android:id="@+id/button_location_tracking"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1.15"
+ android:gravity="center"
+ android:text="None"
+ android:textColor="@android:color/white" />
+
+ </LinearLayout>
+
+</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_manual_update.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_manual_update.xml
new file mode 100644
index 0000000000..3aac74a1e2
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_manual_update.xml
@@ -0,0 +1,43 @@
+<?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"
+ android:orientation="vertical">
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:id="@+id/mapView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginBottom="0dp"
+ app:mapbox_uiAttribution="false" />
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/fabToggleManualLocation"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="end|bottom"
+ android:layout_marginBottom="82dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginRight="16dp"
+ android:tint="@android:color/white"
+ app:backgroundTint="@color/accent"
+ app:layout_anchorGravity="top"
+ app:srcCompat="@drawable/ic_layers" />
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/fabManualLocationChange"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="end|bottom"
+ android:layout_marginBottom="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginRight="16dp"
+ android:alpha="0.5"
+ android:tint="@android:color/white"
+ app:backgroundTint="@color/accent"
+ app:layout_anchorGravity="top"
+ app:srcCompat="@drawable/ic_my_location" />
+
+</android.support.design.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_location_mode.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_location_mode.xml
new file mode 100644
index 0000000000..7ce217ecd9
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_location_mode.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item android:id="@+id/action_style_change"
+ android:title="Toggle custom LocationLayer style"
+ app:showAsAction="never"/>
+
+ <item android:id="@+id/action_map_style_change"
+ android:title="Toggle custom Map style"
+ app:showAsAction="never"/>
+
+ <item android:id="@+id/action_plugin_disable"
+ android:title="Disable"
+ app:showAsAction="never"/>
+
+
+ <item android:id="@+id/action_plugin_enabled"
+ android:title="Enabled"
+ app:showAsAction="never"/>
+</menu> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml
index aafeb1cd9c..a4403a34f7 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/categories.xml
@@ -14,4 +14,5 @@
<string name="category_features">Features</string>
<string name="category_storage">Storage</string>
<string name="category_textureview">Texture View</string>
+ <string name="category_location">Location</string>
</resources> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 6c68edc4d2..05035760f9 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -71,4 +71,8 @@
<string name="description_heatmaplayer">Use HeatmapLayer to visualise earthquakes</string>
<string name="description_gesture_detector">Manipulate gestures detector\'s settings</string>
<string name="description_draggable_marker">Click to add a marker, long-click to drag</string>
+ <string name="description_location_map_change">Change map\'s style while location is displayed</string>
+ <string name="description_location_modes">Showcases location render and tracking modes</string>
+ <string name="description_location_fragment">Uses LocationLayer in a Fragment</string>
+ <string name="description_location_manual">Force location updates and don\'t rely on the engine</string>
</resources>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml
index 777d8a5f56..facc169299 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml
@@ -38,4 +38,16 @@
<style name="AppTheme" parent="AppBaseTheme" />
+ <style name="CustomLocationLayer" parent="mapbox_LocationLayer">
+ <item name="mapbox_foregroundDrawable">@drawable/custom_user_icon</item>
+
+ <item name="mapbox_bearingDrawable">@drawable/custom_user_arrow</item>
+ <item name="mapbox_gpsDrawable">@drawable/custom_user_puck_icon</item>
+
+ <item name="mapbox_accuracyAlpha">0.15</item>
+ <item name="mapbox_accuracyColor">#FF82C6</item>
+
+ <item name="mapbox_elevation">0dp</item>
+ </style>
+
</resources>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index ddf3518863..f094a67b39 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -71,4 +71,8 @@
<string name="activity_heatmaplayer">Heatmap layer</string>
<string name="activity_gesture_detector">Gestures detector</string>
<string name="activity_draggable_maker">Draggable marker</string>
+ <string name="activity_location_map_change">Simple Location Activity</string>
+ <string name="activity_location_modes">Location Modes Activity</string>
+ <string name="activity_location_fragment">Location Fragment</string>
+ <string name="activity_location_manual">Manual Location updates</string>
</resources> \ No newline at end of file
diff --git a/platform/android/gradle/dependencies.gradle b/platform/android/gradle/dependencies.gradle
index 86571bb05a..af9b7e00b8 100644
--- a/platform/android/gradle/dependencies.gradle
+++ b/platform/android/gradle/dependencies.gradle
@@ -8,62 +8,64 @@ ext {
]
versions = [
- mapboxServices : '3.4.1',
- mapboxTelemetry: '3.1.5',
- mapboxGestures : '0.2.0',
- supportLib : '27.1.1',
- espresso : '3.0.2',
- testRunner : '1.0.2',
- leakCanary : '1.6.1',
- junit : '4.12',
- mockito : '2.18.3',
- robolectric : '3.8',
- timber : '4.7.1',
- okhttp : '3.11.0',
- kotlin : '1.2.51',
- licenses : '0.8.41',
- lint : '26.1.3'
+ mapboxServices : '3.4.1',
+ mapboxTelemetry : '3.1.5',
+ mapboxGestures : '0.2.0',
+ supportLib : '27.1.1',
+ constraintLayout: '1.1.2',
+ espresso : '3.0.2',
+ testRunner : '1.0.2',
+ leakCanary : '1.6.1',
+ junit : '4.12',
+ mockito : '2.18.3',
+ robolectric : '3.8',
+ timber : '4.7.1',
+ okhttp : '3.11.0',
+ kotlin : '1.2.51',
+ licenses : '0.8.41',
+ lint : '26.1.3'
]
dependenciesList = [
- mapboxJavaServices : "com.mapbox.mapboxsdk:mapbox-sdk-services:${versions.mapboxServices}",
- mapboxJavaGeoJSON : "com.mapbox.mapboxsdk:mapbox-sdk-geojson:${versions.mapboxServices}",
- mapboxAndroidTelemetry: "com.mapbox.mapboxsdk:mapbox-android-telemetry:${versions.mapboxTelemetry}",
- mapboxAndroidGestures : "com.mapbox.mapboxsdk:mapbox-android-gestures:${versions.mapboxGestures}",
+ mapboxJavaServices : "com.mapbox.mapboxsdk:mapbox-sdk-services:${versions.mapboxServices}",
+ mapboxJavaGeoJSON : "com.mapbox.mapboxsdk:mapbox-sdk-geojson:${versions.mapboxServices}",
+ mapboxAndroidTelemetry : "com.mapbox.mapboxsdk:mapbox-android-telemetry:${versions.mapboxTelemetry}",
+ mapboxAndroidGestures : "com.mapbox.mapboxsdk:mapbox-android-gestures:${versions.mapboxGestures}",
// for testApp
- mapboxJavaTurf : "com.mapbox.mapboxsdk:mapbox-sdk-turf:${versions.mapboxServices}",
+ mapboxJavaTurf : "com.mapbox.mapboxsdk:mapbox-sdk-turf:${versions.mapboxServices}",
- junit : "junit:junit:${versions.junit}",
- mockito : "org.mockito:mockito-core:${versions.mockito}",
- robolectric : "org.robolectric:robolectric:${versions.robolectric}",
+ junit : "junit:junit:${versions.junit}",
+ mockito : "org.mockito:mockito-core:${versions.mockito}",
+ robolectric : "org.robolectric:robolectric:${versions.robolectric}",
- testRunner : "com.android.support.test:runner:${versions.testRunner}",
- testRules : "com.android.support.test:rules:${versions.testRunner}",
- testEspressoCore : "com.android.support.test.espresso:espresso-core:${versions.espresso}",
- testEspressoIntents : "com.android.support.test.espresso:espresso-intents:${versions.espresso}",
- testEspressoContrib : "com.android.support.test.espresso:espresso-contrib:${versions.espresso}",
+ testRunner : "com.android.support.test:runner:${versions.testRunner}",
+ testRules : "com.android.support.test:rules:${versions.testRunner}",
+ testEspressoCore : "com.android.support.test.espresso:espresso-core:${versions.espresso}",
+ testEspressoIntents : "com.android.support.test.espresso:espresso-intents:${versions.espresso}",
+ testEspressoContrib : "com.android.support.test.espresso:espresso-contrib:${versions.espresso}",
- supportAnnotations : "com.android.support:support-annotations:${versions.supportLib}",
- supportAppcompatV7 : "com.android.support:appcompat-v7:${versions.supportLib}",
- supportFragmentV4 : "com.android.support:support-fragment:${versions.supportLib}",
- supportUtilV4 : "com.android.support:support-core-utils:${versions.supportLib}",
- supportDesign : "com.android.support:design:${versions.supportLib}",
- supportRecyclerView : "com.android.support:recyclerview-v7:${versions.supportLib}",
+ supportAnnotations : "com.android.support:support-annotations:${versions.supportLib}",
+ supportAppcompatV7 : "com.android.support:appcompat-v7:${versions.supportLib}",
+ supportFragmentV4 : "com.android.support:support-fragment:${versions.supportLib}",
+ supportUtilV4 : "com.android.support:support-core-utils:${versions.supportLib}",
+ supportDesign : "com.android.support:design:${versions.supportLib}",
+ supportRecyclerView : "com.android.support:recyclerview-v7:${versions.supportLib}",
+ supportConstraintLayout: "com.android.support.constraint:constraint-layout:${versions.constraintLayout}",
- gmsLocation : 'com.google.android.gms:play-services-location:11.0.4',
- timber : "com.jakewharton.timber:timber:${versions.timber}",
- okhttp3 : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
- leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${versions.leakCanary}",
- leakCanaryRelease : "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leakCanary}",
+ gmsLocation : 'com.google.android.gms:play-services-location:11.0.4',
+ timber : "com.jakewharton.timber:timber:${versions.timber}",
+ okhttp3 : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
+ leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${versions.leakCanary}",
+ leakCanaryRelease : "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leakCanary}",
- kotlinLib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}",
- kotlinPlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
- licensesPlugin : "com.jaredsburrows:gradle-license-plugin:${versions.licenses}",
+ kotlinLib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}",
+ kotlinPlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
+ licensesPlugin : "com.jaredsburrows:gradle-license-plugin:${versions.licenses}",
- lint : "com.android.tools.lint:lint:${versions.lint}",
- lintApi : "com.android.tools.lint:lint-api:${versions.lint}",
- lintChecks : "com.android.tools.lint:lint-checks:${versions.lint}",
- lintTests : "com.android.tools.lint:lint-tests:${versions.lint}"
+ lint : "com.android.tools.lint:lint:${versions.lint}",
+ lintApi : "com.android.tools.lint:lint-api:${versions.lint}",
+ lintChecks : "com.android.tools.lint:lint-checks:${versions.lint}",
+ lintTests : "com.android.tools.lint:lint-tests:${versions.lint}"
]
}