Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,9 @@ private void setInitialState(MapboxMapOptions options) {
// MyLocationView
MyLocationViewSettings myLocationViewSettings = mMapboxMap.getMyLocationViewSettings();
myLocationViewSettings.setForegroundDrawable(options.getMyLocationForegroundDrawable(), options.getMyLocationForegroundBearingDrawable());
myLocationViewSettings.setForegroundTintColor(options.getMyLocationForegroundTintColor());
myLocationViewSettings.setBackgroundDrawable(options.getMyLocationBackgroundDrawable(), options.getMyLocationBackgroundPadding());
if (options.getMyLocationForegroundTintColor() != -1) {
myLocationViewSettings.setForegroundTintColor(options.getMyLocationForegroundTintColor());
}
if (options.getMyLocationBackgroundTintColor() != -1) {
myLocationViewSettings.setBackgroundTintColor(options.getMyLocationBackgroundTintColor());
}
myLocationViewSettings.setBackgroundTintColor(options.getMyLocationBackgroundTintColor());
myLocationViewSettings.setAccuracyAlpha(options.getMyLocationAccuracyAlpha());
myLocationViewSettings.setAccuracyTintColor(options.getMyLocationAccuracyTintColor());
mMapboxMap.setMyLocationEnabled(options.getLocationEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.Gravity;

Expand Down Expand Up @@ -65,8 +67,8 @@ public class MapboxMapOptions implements Parcelable {
private Drawable myLocationForegroundDrawable;
private Drawable myLocationForegroundBearingDrawable;
private Drawable myLocationBackgroundDrawable;
private int myLocationForegroundTintColor = -1;
private int myLocationBackgroundTintColor = -1;
private int myLocationForegroundTintColor;
private int myLocationBackgroundTintColor;
private int[] myLocationBackgroundPadding;
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
Expand Down Expand Up @@ -171,16 +173,32 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
, (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * screenDensity)});

mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
mapboxMapOptions.myLocationForegroundDrawables(typedArray.getDrawable(R.styleable.MapView_my_location_foreground), typedArray.getDrawable(R.styleable.MapView_my_location_foreground_bearing));
mapboxMapOptions.myLocationBackgroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_background));
mapboxMapOptions.myLocationForegroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_foreground_tint, -1));
mapboxMapOptions.myLocationBackgroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_background_tint, -1));
mapboxMapOptions.myLocationForegroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_foreground_tint, Color.TRANSPARENT));
mapboxMapOptions.myLocationBackgroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_background_tint, Color.WHITE));

Drawable foregroundDrawable = typedArray.getDrawable(R.styleable.MapView_my_location_foreground);
if(foregroundDrawable==null){
foregroundDrawable = ContextCompat.getDrawable(context,R.drawable.ic_mylocationview_normal);
}

Drawable foregroundBearingDrawable = typedArray.getDrawable(R.styleable.MapView_my_location_foreground_bearing);
if(foregroundBearingDrawable==null){
foregroundBearingDrawable = ContextCompat.getDrawable(context,R.drawable.ic_mylocationview_bearing);
}

Drawable backgroundDrawable = typedArray.getDrawable(R.styleable.MapView_my_location_background);
if(backgroundDrawable==null){
backgroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_background);
}

mapboxMapOptions.myLocationForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
mapboxMapOptions.myLocationBackgroundDrawable(backgroundDrawable);
mapboxMapOptions.myLocationBackgroundPadding(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_my_location_background_left, 0) * screenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_top, 0) * screenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_right, 0) * screenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_bottom, 0) * screenDensity)});
mapboxMapOptions.myLocationAccuracyAlpha(typedArray.getInt(R.styleable.MapView_my_location_accuracy_alpha, 100));
mapboxMapOptions.myLocationAccuracyTint(typedArray.getColor(R.styleable.MapView_my_location_accuracy_tint, ColorUtils.getAccentColor(context)));
mapboxMapOptions.myLocationAccuracyTint(typedArray.getColor(R.styleable.MapView_my_location_accuracy_tint, ColorUtils.getPrimaryColor(context)));
} finally {
typedArray.recycle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
Expand All @@ -19,16 +20,13 @@
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
Expand All @@ -37,7 +35,6 @@
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Projection;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ColorUtils;

import java.lang.ref.WeakReference;

Expand Down Expand Up @@ -72,6 +69,9 @@ public class MyLocationView extends View {
private Drawable foregroundBearingDrawable;
private Drawable backgroundDrawable;

private int foregroundTintColor;
private int backgroundTintColor;

private Rect foregroundBounds;
private Rect backgroundBounds;

Expand Down Expand Up @@ -106,38 +106,36 @@ public MyLocationView(Context context, AttributeSet attrs, int defStyleAttr) {

private void init(Context context) {
setEnabled(false);

// behavioural model
myLocationBehaviour = new MyLocationBehaviourFactory().getBehaviouralModel(MyLocationTracking.TRACKING_NONE);
compassListener = new CompassListener(context);
maxSize = (int) context.getResources().getDimension(R.dimen.userlocationview_size);

// default implementation
setShadowDrawable(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_shadow));
setForegroundDrawables(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_normal), ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_bearing));
setAccuracyTint(ColorUtils.getAccentColor(context));
setAccuracyAlpha(100);
maxSize = (int) context.getResources().getDimension(R.dimen.my_locationview_size);
}

public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bearingDrawable) {
if (defaultDrawable == null || bearingDrawable == null) {
Log.e(MapboxConstants.TAG, "Not setting foreground drawables MyLocationView: default = " + defaultDrawable + " bearing = " + bearingDrawable);
return;
}
if (defaultDrawable.getIntrinsicWidth() != bearingDrawable.getIntrinsicWidth() || defaultDrawable.getIntrinsicHeight() != bearingDrawable.getIntrinsicHeight()) {
throw new RuntimeException("The dimensions from location and bearing drawables should be match");
}


foregroundDrawable = defaultDrawable;
foregroundBearingDrawable = bearingDrawable;
setForegroundDrawableTint(foregroundTintColor);

invalidateBounds();
}

public final void setForegroundDrawableTint(@ColorInt int color) {
if (foregroundDrawable != null) {
foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
if (foregroundBearingDrawable != null) {
foregroundBearingDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
if (color != Color.TRANSPARENT) {
foregroundTintColor = color;
if (foregroundDrawable != null) {
foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
if (foregroundBearingDrawable != null) {
foregroundBearingDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
}

Expand All @@ -155,15 +153,19 @@ public final void setShadowDrawable(Drawable drawable, int left, int top, int ri
backgroundOffsetRight = right;
backgroundOffsetBottom = bottom;

setShadowDrawableTint(backgroundTintColor);

invalidateBounds();
}

public final void setShadowDrawableTint(@ColorInt int color) {
if (backgroundDrawable == null) {
return;
if (color != Color.TRANSPARENT) {
backgroundTintColor = color;
if (backgroundDrawable == null) {
return;
}
backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}

backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}

public final void setAccuracyTint(@ColorInt int color) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid android:color="?attr/colorPrimaryDark" />

<size
android:width="@dimen/my_locationview_outer_circle"
android:height="@dimen/my_locationview_outer_circle" />
</shape>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<dimen name="ten_dp">10dp</dimen>
<dimen name="sixteen_dp">16dp</dimen>
<dimen name="seventy_six_dp">76dp</dimen>
<dimen name="userlocationview_size">64dp</dimen>
<dimen name="userlocationview_inner_circle">18dp</dimen>
<dimen name="userlocationview_outer_circle">22dp</dimen>
<dimen name="my_locationview_size">64dp</dimen>
<dimen name="my_locationview_outer_circle">18dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onMapReady(MapboxMap map) {
mapboxMap = map;
mapboxMap.setStyle(Style.MAPBOX_STREETS);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/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"/>
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:id="@id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:access_token="@string/mapbox_access_token"
/>
mapbox:access_token="@string/mapbox_access_token" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobrun Is it expected that most apps will also have to set a my_location_background_tint in their apps to get the default blue dot and blue accuracy ring?


<android.support.design.widget.FloatingActionButton
android:id="@+id/fabLocationToggle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:my_location_foreground_tint="@color/primary"
app:my_location_background_tint="@android:color/white"
app:my_location_accuracy_tint="@color/primary"
app:access_token="@string/mapbox_access_token"
app:style_url="@string/style_mapbox_streets"
app:zoom="15" />

</LinearLayout>
</LinearLayout>