6039 focal point uses MyLocationView padding (#6108)
* [android] - don't auto tint drawables + formatting * [android] - formatting * [android] #6039 - fixes focal point when padding mylocationview * [android] #5977 - MyLocationView.setPadding example + formatting Manifest * [android] - Reset to default configuration, cleanup class
This commit is contained in:
@@ -124,7 +124,7 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
if(isInEditMode()){
|
||||
if (isInEditMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,6 @@ public class MyLocationView extends View {
|
||||
|
||||
foregroundDrawable = defaultDrawable;
|
||||
foregroundBearingDrawable = bearingDrawable;
|
||||
setForegroundDrawableTint(foregroundTintColor);
|
||||
|
||||
invalidateBounds();
|
||||
}
|
||||
@@ -199,7 +198,6 @@ public class MyLocationView extends View {
|
||||
backgroundOffsetTop = top;
|
||||
backgroundOffsetRight = right;
|
||||
backgroundOffsetBottom = bottom;
|
||||
setShadowDrawableTint(backgroundTintColor);
|
||||
|
||||
invalidateBounds();
|
||||
}
|
||||
@@ -389,8 +387,8 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state){
|
||||
if (state instanceof Bundle){
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
if (state instanceof Bundle) {
|
||||
Bundle bundle = (Bundle) state;
|
||||
tilt = bundle.getFloat("tilt");
|
||||
state = bundle.getParcelable("superState");
|
||||
@@ -496,11 +494,11 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
public float getCenterX() {
|
||||
return getX() + getMeasuredWidth() / 2;
|
||||
return (getX() + contentPadding[0] - contentPadding[2] + getMeasuredWidth()) / 2;
|
||||
}
|
||||
|
||||
public float getCenterY() {
|
||||
return getY() + getMeasuredHeight() / 2;
|
||||
return (getY() + contentPadding[1] - contentPadding[3] + getMeasuredHeight()) / 2;
|
||||
}
|
||||
|
||||
public void setContentPadding(int[] padding) {
|
||||
@@ -564,19 +562,19 @@ public class MyLocationView extends View {
|
||||
return;
|
||||
}
|
||||
|
||||
if( event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR ){
|
||||
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
|
||||
|
||||
// calculate the rotation matrix
|
||||
SensorManager.getRotationMatrixFromVector(matrix, event.values );
|
||||
SensorManager.getOrientation(matrix, orientation );
|
||||
SensorManager.getRotationMatrixFromVector(matrix, event.values);
|
||||
SensorManager.getOrientation(matrix, orientation);
|
||||
|
||||
float magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation )[0]);
|
||||
float magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation)[0]);
|
||||
currentDegree = (int) (magneticHeading);
|
||||
|
||||
// Change the user location view orientation to reflect the device orientation
|
||||
setCompass(currentDegree);
|
||||
|
||||
if(myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW){
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
rotateCamera();
|
||||
}
|
||||
|
||||
@@ -584,14 +582,15 @@ public class MyLocationView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
private void rotateCamera(){
|
||||
private void rotateCamera() {
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder();
|
||||
builder.bearing(currentDegree);
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), COMPASS_UPDATE_RATE_MS, false /*linear interpolator*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.mapbox.mapboxsdk.testapp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mapbox.mapboxsdk.testapp">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:name=".MapboxApplication"
|
||||
@@ -20,8 +20,8 @@
|
||||
android:name=".activity.FeatureOverviewActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
@@ -30,7 +30,7 @@
|
||||
android:label="@string/activity_info_window">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_infowindow"/>
|
||||
android:value="@string/category_infowindow" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.infowindow.InfoWindowAdapterActivity"
|
||||
@@ -38,7 +38,7 @@
|
||||
android:label="@string/activity_infowindow_adapter">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_infowindow"/>
|
||||
android:value="@string/category_infowindow" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.infowindow.DynamicInfoWindowAdapterActivity"
|
||||
@@ -46,7 +46,7 @@
|
||||
android:label="@string/activity_dynamic_infowindow_adapter">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_infowindow"/>
|
||||
android:value="@string/category_infowindow" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.BulkMarkerActivity"
|
||||
@@ -55,7 +55,7 @@
|
||||
android:label="@string/activity_add_bulk_markers">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.AnimatedMarkerActivity"
|
||||
@@ -63,7 +63,7 @@
|
||||
android:label="@string/activity_animated_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.DynamicMarkerChangeActivity"
|
||||
@@ -71,7 +71,7 @@
|
||||
android:label="@string/activity_dynamic_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PressForMarkerActivity"
|
||||
@@ -79,7 +79,7 @@
|
||||
android:label="@string/activity_press_for_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.CameraAnimationTypeActivity"
|
||||
@@ -87,7 +87,7 @@
|
||||
android:label="@string/activity_camera_animation_types">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera"/>
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.CameraPositionActivity"
|
||||
@@ -95,7 +95,7 @@
|
||||
android:label="@string/activity_camera_position">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera"/>
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.LatLngBoundsActivity"
|
||||
@@ -104,7 +104,7 @@
|
||||
android:screenOrientation="portrait">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera"/>
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.fragment.MapFragmentActivity"
|
||||
@@ -112,7 +112,7 @@
|
||||
android:label="@string/activity_map_fragment">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment"/>
|
||||
android:value="@string/category_fragment" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.fragment.SupportMapFragmentActivity"
|
||||
@@ -120,7 +120,7 @@
|
||||
android:label="@string/activity_map_fragment_suport">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment"/>
|
||||
android:value="@string/category_fragment" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.ManualZoomActivity"
|
||||
@@ -128,7 +128,7 @@
|
||||
android:label="@string/activity_camera_zoom">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera"/>
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.MaxMinZoomActivity"
|
||||
@@ -136,7 +136,7 @@
|
||||
android:label="@string/activity_minmax_zoom">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera"/>
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.customlayer.CustomLayerActivity"
|
||||
@@ -144,7 +144,7 @@
|
||||
android:label="@string/activity_custom_layer">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_custom_layer"/>
|
||||
android:value="@string/category_custom_layer" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationTrackingModeActivity"
|
||||
@@ -152,7 +152,7 @@
|
||||
android:label="@string/activity_user_tracking_mode">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation"/>
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationDrawableActivity"
|
||||
@@ -160,7 +160,7 @@
|
||||
android:label="@string/activity_user_tracking_customization">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation"/>
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationTintActivity"
|
||||
@@ -168,7 +168,7 @@
|
||||
android:label="@string/activity_user_dot_color">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation"/>
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationToggleActivity"
|
||||
@@ -176,7 +176,7 @@
|
||||
android:label="@string/activity_user_location_toggle">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation"/>
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PolygonActivity"
|
||||
@@ -184,7 +184,7 @@
|
||||
android:label="@string/activity_polygon">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PolylineActivity"
|
||||
@@ -192,7 +192,7 @@
|
||||
android:label="@string/activity_polyline">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.directions.DirectionsActivity"
|
||||
@@ -200,7 +200,7 @@
|
||||
android:label="@string/activity_directions">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_directions"/>
|
||||
android:value="@string/category_directions" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.geocoding.GeocoderActivity"
|
||||
@@ -208,7 +208,7 @@
|
||||
android:label="@string/activity_geocoder">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_geocoding"/>
|
||||
android:value="@string/category_geocoding" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.ScrollByActivity"
|
||||
@@ -216,7 +216,7 @@
|
||||
android:label="@string/activity_scroll_by">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera"/>
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.MapPaddingActivity"
|
||||
@@ -225,7 +225,7 @@
|
||||
android:screenOrientation="portrait">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
android:value="@string/category_maplayout" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.DebugModeActivity"
|
||||
@@ -233,7 +233,7 @@
|
||||
android:label="@string/activity_debug_mode">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
android:value="@string/category_maplayout" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.offline.OfflineActivity"
|
||||
@@ -241,7 +241,7 @@
|
||||
android:label="@string/activity_offline">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_offline"/>
|
||||
android:value="@string/category_offline" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.imagegenerator.SnapshotActivity"
|
||||
@@ -249,7 +249,7 @@
|
||||
android:label="@string/activity_snapshot">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
android:value="@string/category_imagegenerator" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.DoubleMapActivity"
|
||||
@@ -257,7 +257,7 @@
|
||||
android:label="@string/activity_double_map">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
android:value="@string/category_maplayout" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.MarkerViewActivity"
|
||||
@@ -265,7 +265,7 @@
|
||||
android:label="@string/activity_view_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.MarkerViewScaleActivity"
|
||||
@@ -273,7 +273,7 @@
|
||||
android:label="@string/activity_view_marker_scale">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation"/>
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.navigation.LocationPickerActivity"
|
||||
@@ -281,7 +281,7 @@
|
||||
android:label="@string/activity_location_picker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_navigation"/>
|
||||
android:value="@string/category_navigation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.fragment.ViewPagerActivity"
|
||||
@@ -289,7 +289,7 @@
|
||||
android:label="@string/activity_viewpager">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment"/>
|
||||
android:value="@string/category_fragment" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.NavigationDrawerActivity"
|
||||
@@ -298,7 +298,7 @@
|
||||
android:theme="@style/AppTheme.ActionBar.Transparent">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment"/>
|
||||
android:value="@string/category_fragment" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.RuntimeStyleActivity"
|
||||
@@ -306,7 +306,7 @@
|
||||
android:label="@string/activity_runtime_style">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style"/>
|
||||
android:value="@string/category_style" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.GeoJsonClusteringActivity"
|
||||
@@ -323,7 +323,7 @@
|
||||
android:label="@string/activity_print">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
android:value="@string/category_imagegenerator" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.SurfaceViewMediaControlActivity"
|
||||
@@ -331,7 +331,7 @@
|
||||
android:label="@string/activity_surfaceview_overlay">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
android:value="@string/category_maplayout" />
|
||||
</activity>
|
||||
|
||||
<!-- Features -->
|
||||
@@ -359,25 +359,32 @@
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_features" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.navigation.CarDrivingActivity"
|
||||
android:description="@string/description_car_driving"
|
||||
android:label="@string/activity_car_driving">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_navigation" />
|
||||
</activity>
|
||||
<!-- For Unit tests -->
|
||||
<activity android:name=".activity.style.RuntimeStyleTestActivity"/>
|
||||
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity"/>
|
||||
<activity android:name=".activity.style.RuntimeStyleTestActivity" />
|
||||
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity" />
|
||||
|
||||
<!-- Configuration Settings -->
|
||||
<meta-data
|
||||
android:name="com.mapbox.TestEventsServer"
|
||||
android:value="https://cloudfront-staging.tilestream.net"/>
|
||||
android:value="https://cloudfront-staging.tilestream.net" />
|
||||
<meta-data
|
||||
android:name="com.mapbox.TestEventsAccessToken"
|
||||
android:value="sk.eyJ1IjoiYmxlZWdlIiwiYSI6InNpcml1c2x5In0.KyT-boMyC_xZYTYojTc8zg"/>
|
||||
android:value="sk.eyJ1IjoiYmxlZWdlIiwiYSI6InNpcml1c2x5In0.KyT-boMyC_xZYTYojTc8zg" />
|
||||
|
||||
<!-- Comment out this setting to switch to external storage (and disable internal) in your app -->
|
||||
<!-- <meta-data -->
|
||||
<!-- android:name="com.mapbox.SetStorageExternal" -->
|
||||
<!-- android:value="true" /> -->
|
||||
|
||||
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService"/>
|
||||
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
@@ -208,6 +208,7 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
{
|
||||
add(resources.getString(R.string.activity_double_map));
|
||||
add(getString(R.string.activity_location_picker));
|
||||
add(getString(R.string.activity_car_driving));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.navigation;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
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.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class CarDrivingActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener {
|
||||
|
||||
private static final int PERMISSIONS_LOCATION = 0;
|
||||
|
||||
private MapView mMapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Location location;
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_car_driving);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
CarDrivingActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
// view settings
|
||||
MyLocationViewSettings settings = mapboxMap.getMyLocationViewSettings();
|
||||
settings.setPadding(0, getWindow().getDecorView().getMeasuredHeight() / 3, 0, 0);
|
||||
|
||||
// get car
|
||||
Drawable car = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_taxi_top_small, getTheme());
|
||||
settings.setForegroundTintColor(Color.TRANSPARENT);
|
||||
settings.setForegroundDrawable(car, car);
|
||||
|
||||
// remove accuracy circle
|
||||
settings.setAccuracyAlpha(0);
|
||||
|
||||
// disable dismissal when a gesture occurs
|
||||
TrackingSettings trackingSettings = mapboxMap.getTrackingSettings();
|
||||
trackingSettings.setDismissLocationTrackingOnGesture(false);
|
||||
trackingSettings.setDismissBearingTrackingOnGesture(false);
|
||||
|
||||
mapboxMap.setOnMyLocationChangeListener(CarDrivingActivity.this);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
toggleGps(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void toggleGps(boolean enableGps) {
|
||||
if (enableGps) {
|
||||
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
|
||||
(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_LOCATION);
|
||||
} else {
|
||||
enableLocation(true);
|
||||
}
|
||||
} else {
|
||||
enableLocation(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void enableLocation(boolean enabled) {
|
||||
if (enabled) {
|
||||
mapboxMap.setMyLocationEnabled(true);
|
||||
Location location = mapboxMap.getMyLocation();
|
||||
if (location != null) {
|
||||
setInitialPosition(new LatLng(location));
|
||||
}
|
||||
} else {
|
||||
mapboxMap.setMyLocationEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case PERMISSIONS_LOCATION: {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
enableLocation(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setInitialPosition(LatLng latLng) {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder().target(latLng).zoom(15).tilt(20f).build()));
|
||||
mapboxMap.setMyLocationEnabled(true);
|
||||
|
||||
TrackingSettings trackingSettings = mapboxMap.getTrackingSettings();
|
||||
trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
|
||||
trackingSettings.setMyBearingTrackingMode(MyBearingTracking.GPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMyLocationChange(@Nullable Location location) {
|
||||
if (location != null) {
|
||||
if (this.location == null) {
|
||||
// initial location to reposition map
|
||||
setInitialPosition(new LatLng(location));
|
||||
}
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:my_location_foreground_tint="@color/primary"
|
||||
app:my_location_accuracy_tint="@color/primary"
|
||||
app:style_url="@string/style_mapbox_streets"
|
||||
app:zoom="15" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
<!-- Navigation -->
|
||||
<string name="activity_location_picker">Location Picker</string>
|
||||
<string name="activity_car_driving">Driving animation</string>
|
||||
|
||||
<!-- Other -->
|
||||
<string name="activity_double_map">Double Map Activity</string>
|
||||
@@ -106,6 +107,7 @@
|
||||
<string name="description_query_rendered_feature_properties_point">Query rendered feature properties on click</string>
|
||||
<string name="description_query_rendered_features_box_count">Count all rendered features in box</string>
|
||||
<string name="description_query_rendered_features_box_highlight">Hightligh buildings in box</string>
|
||||
<string name="description_car_driving">MyLocationView follow map update example</string>
|
||||
|
||||
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
|
||||
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>
|
||||
|
||||
@@ -14,7 +14,7 @@ global.camelize = function (str) {
|
||||
}
|
||||
|
||||
|
||||
const excludeActivities = ["MyLocationTrackingModeActivity","MyLocationToggleActivity","MyLocationTintActivity","MyLocationDrawableActivity","DoubleMapActivity", "LocationPickerActivity","GeoJsonClusteringActivity","RuntimeStyleTestActivity", "AnimatedMarkerActivity", "ViewPagerActivity","MapFragmentActivity","SupportMapFragmentActivity","SnapshotActivity","NavigationDrawerActivity"];
|
||||
const excludeActivities = ["CarDrivingActivity","MyLocationTrackingModeActivity","MyLocationToggleActivity","MyLocationTintActivity","MyLocationDrawableActivity","DoubleMapActivity", "LocationPickerActivity","GeoJsonClusteringActivity","RuntimeStyleTestActivity", "AnimatedMarkerActivity", "ViewPagerActivity","MapFragmentActivity","SupportMapFragmentActivity","SnapshotActivity","NavigationDrawerActivity"];
|
||||
const appBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity';
|
||||
const testBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/activity/gen';
|
||||
const subPackages = fs.readdirSync(appBasePath);
|
||||
|
||||
Reference in New Issue
Block a user