Split out Android examples to separate documentation site (#2978)
This commit is contained in:
@@ -65,6 +65,9 @@ public class AttributionParser {
|
||||
*/
|
||||
@NonNull
|
||||
public String createAttributionString(boolean shortenedOutput) {
|
||||
if (attributions.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(withCopyrightSign ? "" : "© ");
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributions) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.maplibre.android.snapshotter
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.Html
|
||||
@@ -515,15 +516,7 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
drawAttribution(canvas, measure, anchorPoint)
|
||||
} else {
|
||||
val snapshot = mapSnapshot.bitmap
|
||||
Logger.e(
|
||||
TAG,
|
||||
String.format(
|
||||
"Could not generate attribution for snapshot size: %s x %s." + " You are required to provide your own attribution for the used sources: %s",
|
||||
snapshot.width,
|
||||
snapshot.height,
|
||||
mapSnapshot.attributions
|
||||
)
|
||||
)
|
||||
Logger.e(TAG, "Could not generate attribution for snapshot size: ${snapshot.width} x ${snapshot.height}. You are required to provide your own attribution for the used sources: ${mapSnapshot.attributions.joinToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,7 +537,17 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
textView.textSize = 10 * scale
|
||||
textView.setTextColor(textColor)
|
||||
textView.setBackgroundResource(R.drawable.maplibre_rounded_corner)
|
||||
textView.text = Html.fromHtml(createAttributionString(mapSnapshot, shortText))
|
||||
val attributionString = createAttributionString(mapSnapshot, shortText)
|
||||
if (attributionString == "") {
|
||||
Logger.w(
|
||||
TAG,
|
||||
String.format(
|
||||
"Attribution string is empty. Make sure you provide your own attribution for the used sources if needed.",
|
||||
)
|
||||
)
|
||||
return TextView(context)
|
||||
}
|
||||
textView.text = fromHTML(attributionString)
|
||||
textView.measure(widthMeasureSpec, heightMeasureSpec)
|
||||
textView.layout(0, 0, textView.measuredWidth, textView.measuredHeight)
|
||||
return textView
|
||||
@@ -770,3 +773,9 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
private const val LOGO_MARGIN_DP = 4
|
||||
}
|
||||
}
|
||||
|
||||
fun fromHTML(source: String) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
Html.fromHtml(source)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user