Skip to content

Commit

Permalink
PR #1716 port to release branch v10.9 (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
jush authored Oct 4, 2022
1 parent 2fd7437 commit fdfc825
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# Changelog for Mapbox Maps SDK v10 for Android

Mapbox welcomes participation and contributions from everyone.

# main

# 10.9.0-rc.1

## Bug fixes 🐞

* Fix scale bar text being cut. ([1716](https://github.com/mapbox/mapbox-maps-android/pull/1716))

# 10.8.1 September 30, 2022

## Bug fixes 🐞

* Fix incorrect `MapView` dimensions after background orientation change. ([1658](https://github.com/mapbox/mapbox-maps-android/pull/1658))
* Throw an exception with the meaningful stacktrace when constructing `Value` from an infinite or NaN number. ([1681](https://github.com/mapbox/mapbox-maps-android/pull/1681))
* Make telemetry a single instance. Avoids module recreation when coming from background. ([1695](https://github.com/mapbox/mapbox-maps-android/pull/1695))
* Fix a potential style load error when non-ASCII characters are used in the version name, by escaping non US ASCII characters in user-agent header. ([1709](https://github.com/mapbox/mapbox-maps-android/pull/1709))

## Dependencies
* Bump common to v23.0.1. ([1709](https://github.com/mapbox/mapbox-maps-android/pull/1709))

# 10.9.0-beta.2 September 28, 2022

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,18 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".ExampleOverviewActivity" />
</activity>
<activity
android:name=".examples.ScaleBarActivity"
android:description="@string/description_scale_bar"
android:exported="true"
android:label="@string/activity_scale_bar">
<meta-data
android:name="@string/category"
android:value="@string/category_config" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ExampleOverviewActivity" />
</activity>
<activity
android:name=".examples.LargeGeojsonPerformanceActivity"
android:description="@string/description_large_geojson"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mapbox.maps.testapp.examples

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.maps.testapp.R

/**
* Activity to showcase scale bar custom configuration using xml attributes.
*/
class ScaleBarActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scale_bar)
}
}
24 changes: 24 additions & 0 deletions app/src/main/res/layout/activity_scale_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapbox.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapbox_cameraTargetLat="61.489557808394814"
app:mapbox_cameraTargetLng="23.735379149896005"
app:mapbox_cameraZoom="14.940602577615023"

app:mapbox_scaleBarBorderWidth="1dp"
app:mapbox_scaleBarHeight="5dp"
app:mapbox_scaleBarGravity="bottom|center_horizontal"
app:mapbox_scaleBarIsMetricUnits="true"
app:mapbox_scaleBarMarginBottom="50dp"
app:mapbox_scaleBarMarginRight="0dp"
app:mapbox_scaleBarPrimaryColor="@android:color/black"
app:mapbox_scaleBarRatio="0.8"
app:mapbox_scaleBarSecondaryColor="@android:color/white"
app:mapbox_scaleBarShowTextBorder="true"
app:mapbox_scaleBarTextBarMargin="10dp"
app:mapbox_scaleBarTextBorderWidth="5dp"
app:mapbox_scaleBarTextColor="@android:color/black"
app:mapbox_scaleBarTextSize="10dp" />
1 change: 1 addition & 0 deletions app/src/main/res/values/example_descriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<string name="description_multiple_display">Display the map on a secondary display</string>
<string name="description_map_view_customization">Customize your map view</string>
<string name="description_ornaments_margin">Update margins of ornaments when the map rotates</string>
<string name="description_scale_bar">Show scale bar at custom position</string>
<string name="description_large_geojson">Display long route as large geojson</string>
<string name="description_nine_patch">Add 9-patch image to the style</string>
<string name="description_feature_state">Create interactive hover effects with feature state</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/example_titles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<string name="activity_multiple_display">Multi display</string>
<string name="activity_map_view_customization">Creating a map view</string>
<string name="activity_ornaments">Ornaments</string>
<string name="activity_scale_bar">Scale Bar</string>
<string name="activity_large_geojson">Geojson performance</string>
<string name="activity_nine_patch">9-patch image</string>
<string name="activity_feature_state">Feature state</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ScaleBarImpl : ScaleBar, View {
strokePaint.textSize = value.textSize
scaleTable = if (value.isMetricUnits) metricTable else imperialTable
unit = if (value.isMetricUnits) METER_UNIT else FEET_UNIT
strokePaint.strokeWidth = value.textBorderWidth
strokePaint.strokeWidth = if (value.showTextBorder) value.textBorderWidth else 0F
enable = value.enabled
if (useContinuousRendering) {
reusableCanvas = null
Expand Down Expand Up @@ -276,7 +276,13 @@ class ScaleBarImpl : ScaleBar, View {
}
}

drawText(canvas, distanceText, (unitBarWidth * rectIndex), textSize)
drawText(
canvas = canvas,
text = distanceText,
x = (unitBarWidth * rectIndex),
y = textSize,
lastUnitBarText = (rectIndex == rectCount)
)

if (rectIndex != rectCount) {
canvas.drawRect(
Expand All @@ -294,11 +300,33 @@ class ScaleBarImpl : ScaleBar, View {
}
}

private fun drawText(canvas: Canvas, text: String, x: Float, y: Float) {
private fun drawText(canvas: Canvas, text: String, x: Float, y: Float, lastUnitBarText: Boolean) {
var safeX = x

// As an optimization only check if it goes beyond right view for the last unit bar text
if (lastUnitBarText) {
// Check if it goes beyond the right margin of the view
val textWidthPx = textPaint.measureText(text)
val textMaxRightPx = x + strokePaint.strokeWidth + when (textPaint.textAlign) {
Paint.Align.LEFT -> textWidthPx
Paint.Align.CENTER -> textWidthPx / 2
Paint.Align.RIGHT, null -> 0F
}
if (textMaxRightPx > width) {
// Move it away from right margin enough to fit
safeX -= (textMaxRightPx - width)
}
}

// Check if it goes beyond the left margin of the view
if (safeX - (strokePaint.strokeWidth / 2) < 0) {
safeX += (strokePaint.strokeWidth / 2)
}

if (settings.showTextBorder) {
canvas.drawText(text, x, y, strokePaint)
canvas.drawText(text, safeX, y, strokePaint)
}
canvas.drawText(text, x, y, textPaint)
canvas.drawText(text, safeX, y, textPaint)
}

/**
Expand Down

0 comments on commit fdfc825

Please sign in to comment.