[android] #4930 - added invalidate to change tint colors
This commit is contained in:
@@ -135,6 +135,7 @@ public class MyLocationView extends View {
|
||||
foregroundBearingDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public final void setShadowDrawable(Drawable drawable) {
|
||||
@@ -164,16 +165,19 @@ public class MyLocationView extends View {
|
||||
}
|
||||
backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public final void setAccuracyTint(@ColorInt int color) {
|
||||
int alpha = accuracyPaint.getAlpha();
|
||||
accuracyPaint.setColor(color);
|
||||
accuracyPaint.setAlpha(alpha);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public final void setAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) {
|
||||
accuracyPaint.setAlpha(alpha);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void invalidateBounds() {
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationCustomizationActivity"
|
||||
android:name=".activity.userlocation.MyLocationDrawableActivity"
|
||||
android:description="@string/description_user_location_customization"
|
||||
android:label="@string/activity_user_tracking_customization">
|
||||
<meta-data
|
||||
@@ -148,7 +148,7 @@
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationDotColor"
|
||||
android:name=".activity.userlocation.MyLocationTintActivity"
|
||||
android:description="@string/description_user_location_dot_color"
|
||||
android:label="@string/activity_user_dot_color">
|
||||
<meta-data
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
|
||||
|
||||
public class MyLocationCustomizationActivity extends AppCompatActivity implements LocationListener {
|
||||
public class MyLocationDrawableActivity extends AppCompatActivity implements LocationListener {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.userlocation;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
@@ -22,9 +24,10 @@ import com.mapbox.mapboxsdk.location.LocationServices;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class MyLocationDotColor extends AppCompatActivity implements LocationListener {
|
||||
public class MyLocationTintActivity extends AppCompatActivity implements LocationListener {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap map;
|
||||
@@ -52,49 +55,41 @@ public class MyLocationDotColor extends AppCompatActivity implements LocationLis
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
|
||||
map = mapboxMap;
|
||||
|
||||
toggleGps(!mapboxMap.isMyLocationEnabled());
|
||||
|
||||
}
|
||||
});
|
||||
final MyLocationViewSettings myLocationViewSettings = mapboxMap.getMyLocationViewSettings();
|
||||
|
||||
// handle default button clicks
|
||||
findViewById(R.id.default_user_dot_coloring_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// handle default button clicks
|
||||
ViewUtils.attachClickListener(MyLocationTintActivity.this, R.id.default_user_dot_coloring_button,new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
myLocationViewSettings.setAccuracyTintColor(ContextCompat.getColor(MyLocationTintActivity.this, R.color.my_location_ring));
|
||||
myLocationViewSettings.setForegroundTintColor(ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_blue));
|
||||
}
|
||||
});
|
||||
|
||||
map.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.my_location_ring));
|
||||
map.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_blue));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// handle tint user dot button clicks
|
||||
findViewById(R.id.tint_user_dot_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
map.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_green));
|
||||
map.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_green));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// handle tint accuracy ring button clicks
|
||||
findViewById(R.id.user_accuracy_ring_tint_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
map.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.accent));
|
||||
map.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_blue));
|
||||
// handle tint user dot button clicks
|
||||
ViewUtils.attachClickListener(MyLocationTintActivity.this, R.id.tint_user_dot_button,new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
myLocationViewSettings.setAccuracyTintColor(ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_green));
|
||||
myLocationViewSettings.setForegroundTintColor(ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_green));
|
||||
}
|
||||
});
|
||||
|
||||
// handle tint accuracy ring button clicks
|
||||
ViewUtils.attachClickListener(MyLocationTintActivity.this, R.id.user_accuracy_ring_tint_button,new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
myLocationViewSettings.setAccuracyTintColor(ContextCompat.getColor(MyLocationTintActivity.this, R.color.accent));
|
||||
myLocationViewSettings.setForegroundTintColor(ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_blue));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
LocationServices.getLocationServices(this).addLocationListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,4 +176,14 @@ public class MyLocationDotColor extends AppCompatActivity implements LocationLis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ViewUtils {
|
||||
|
||||
public static void attachClickListener(@NonNull Activity activity, @IdRes int buttonId, @Nullable View.OnClickListener clickListener) {
|
||||
View view = activity.findViewById(buttonId);
|
||||
if(view!=null){
|
||||
view.setOnClickListener(clickListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
@@ -16,8 +15,7 @@
|
||||
android:id="@id/mapView"
|
||||
android:layout_below="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:style_url="@string/style_mapbox_streets" />
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<string name="activity_snapshot">Snapshot Activity</string>
|
||||
<string name="activity_user_tracking_mode">User tracking mode</string>
|
||||
<string name="activity_user_tracking_customization">User location customization</string>
|
||||
<string name="activity_user_dot_color">User location dot color</string>
|
||||
<string name="activity_user_dot_color">User location tint color</string>
|
||||
<string name="activity_user_location_toggle">User location toggle</string>
|
||||
<string name="activity_custom_layer">Custom Layer</string>
|
||||
<string name="activity_map_padding">Map Padding</string>
|
||||
@@ -48,7 +48,7 @@
|
||||
<!-- Description -->
|
||||
<string name="description_user_location_tracking">Tracks the location of the user</string>
|
||||
<string name="description_user_location_customization">Customize the location of the user</string>
|
||||
<string name="description_user_location_dot_color">Customize the user dot color</string>
|
||||
<string name="description_user_location_dot_color">Customize the user location color</string>
|
||||
<string name="description_user_location_toggle">Toggle location of the user on and off</string>
|
||||
<string name="description_custom_layer">Overlay a custom native layer on the map</string>
|
||||
<string name="description_info_window_adapter">Learn how to create a custom InfoWindow</string>
|
||||
|
||||
Reference in New Issue
Block a user