Skip to content

Commit

Permalink
Add accuracy radius support for LocationComponent (#1016)
Browse files Browse the repository at this point in the history
* Add interface for Accuracy Radius

* Revert to settings2
  • Loading branch information
Kevin Li authored Feb 9, 2022
1 parent e8c017a commit cea9976
Show file tree
Hide file tree
Showing 37 changed files with 869 additions and 59 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Mapbox welcomes participation and contributions from everyone.

## Features ✨ and improvements 🏁
* Add accuracy radius support for LocationComponent. ([#1016](https://github.com/mapbox/mapbox-maps-android/pull/1016))

# 10.4.0-beta.1

## Features ✨ and improvements 🏁
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin;
import com.mapbox.maps.plugin.locationcomponent.LocationComponentUtils;
import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings;
import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings2;
import com.mapbox.maps.plugin.logo.LogoPlugin;
import com.mapbox.maps.plugin.logo.LogoUtils;
import com.mapbox.maps.plugin.logo.generated.LogoSettings;
Expand Down Expand Up @@ -157,6 +158,13 @@ private void locationComponentSettings(LocationPuck locationPuck) {
locationComponentSettings = new LocationComponentSettings(true, true, Color.BLACK, 1f, "id", "id", locationPuck);
}

private void locationComponentSettings2() {
LocationComponentSettings2 locationComponentSettings2 = new LocationComponentSettings2();
locationComponentSettings2 = new LocationComponentSettings2(true);
locationComponentSettings2 = new LocationComponentSettings2(true, Color.BLUE);
locationComponentSettings2 = new LocationComponentSettings2(true, Color.BLUE, Color.RED);
}

private void locationComponent(Context context, MapView mapView) {
LocationComponentPlugin locationComponent = LocationComponentUtils.getLocationComponent(mapView);
locationComponent.setLocationPuck(LocationComponentUtils.createDefault2DPuck(locationComponent, context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ class LocationComponentActivity : AppCompatActivity() {
}
return true
}
R.id.action_accuracy_enabled -> {
binding.mapView.location2.updateSettings2 { showAccuracyRing = true }
item.isChecked = true
return true
}
R.id.action_accuracy_disable -> {
binding.mapView.location2.updateSettings2 { showAccuracyRing = false }
item.isChecked = true
return true
}
else -> return super.onOptionsItemSelected(item)
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/generated_test_locationcomponent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
mapbox:mapbox_locationComponentPulsingEnabled = "false"
mapbox:mapbox_locationComponentPulsingColor = "#000000"
mapbox:mapbox_locationComponentPulsingMaxRadius = "10dp"
mapbox:mapbox_locationComponentShowAccuracyRing = "false"
mapbox:mapbox_locationComponentAccuracyRingColor = "#000000"
mapbox:mapbox_locationComponentAccuracyRingBorderColor = "#000000"
mapbox:mapbox_locationComponentLayerAbove = "testString"
mapbox:mapbox_locationComponentLayerBelow = "testString"
android:layout_width="match_parent"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/menu/menu_location_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@
<item android:id="@+id/action_hide_bearing"
android:title="@string/location_hide_bearing"
app:showAsAction="never"/>

<item android:id="@+id/action_accuracy_disable"
android:title="@string/location_disable_accuracy"
app:showAsAction="never"/>

<item android:id="@+id/action_accuracy_enabled"
android:title="@string/location_enable_accuracy"
app:showAsAction="never"/>
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<string name="location_hide_bearing">Hide bearing image</string>
<string name="location_stop_pulsing">Stop pulsing</string>
<string name="location_start_pulsing">Start pulsing</string>
<string name="location_disable_accuracy">Disable Accuracy Ring</string>
<string name="location_enable_accuracy">Enable Accuracy Ring</string>

<!--RestrictBounds-->
<string name="restrict_san_francisco">Restrict San Francisco</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ val MapPluginProviderDelegate.location: LocationComponentPlugin
@JvmName("getLocationComponent")
get() = this.getPlugin(Plugin.MAPBOX_LOCATION_COMPONENT_PLUGIN_ID)!!

/**
* Extension val to get the LocationComponentPlugin instance with interface LocationComponentPlugin2 to handle accuracy ring.
*/
val MapPluginProviderDelegate.location2: LocationComponentPlugin2
@JvmName("getLocationComponent2")
get() = this.getPlugin(Plugin.MAPBOX_LOCATION_COMPONENT_PLUGIN_ID)!!

private fun Context.getCompatDrawable(@DrawableRes resId: Int) = ResourcesCompat.getDrawable(
this.resources,
resId,
Expand Down
Loading

0 comments on commit cea9976

Please sign in to comment.