I want to customize line join style as in the picture below:
How can I do it?
My source code:
val lineString = LineString.fromLngLats(tempCoordinateList)
val geoJsonSource = GeoJsonSource(DASHED_LINE_SOURCE_ID, Feature.fromGeometry(lineString))
mapboxMap?.addSource(geoJsonSource)
val lineLayer = LineLayer(DASHED_LINE_LAYER_ID, DASHED_LINE_SOURCE_ID).apply {
setProperties(
PropertyFactory.lineDasharray(arrayOf(2f, 1f)),
PropertyFactory.lineCap(Property.LINE_CAP_SQUARE),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineWidth(3f),
PropertyFactory.lineColor(Color.parseColor("#e55e5e")))
}
mapboxMap?.addLayer(lineLayer)
I didn't find a solution to how to achieve this with standard LineLayer's properties. Therefore, I decided to add these points in a separate layer with markers.
val markerCoordinates = arrayListOf<Feature>()
tempCoordinateList
.forEach {
val feature = Feature.fromGeometry(
Point.fromLngLat(it.longitude, it.latitude))
markerCoordinates.add(feature)
}
val geoJsonSource = GeoJsonSource(MARKER_POINTS_SOURCE_ID, FeatureCollection.fromFeatures(markerCoordinates))
mapboxMap?.addSource(geoJsonSource)
mapboxMap?.addImage(MARKER_POINTS_IMAGE_ID, pointIcon)
val markers = SymbolLayer(MARKER_POINTS_LAYER_ID, MARKER_POINTS_SOURCE_ID)
.withProperties(PropertyFactory.iconImage(MARKER_POINTS_IMAGE_ID))
mapboxMap?.addLayer(markers)
Related
val arrowUp = rememberVectorPainter(image = ImageVector.vectorResource(R.drawable.ds_icon_arrowup))
val arrowDown = rememberVectorPainter(image = ImageVector.vectorResource(R.drawable.ds_icon_arrowdown))
val arrowRight = rememberVectorPainter(image = ImageVector.vectorResource(R.drawable.ds_icon_arrowright))
val iconSize = CustomTypography.xSmall.fontSize
val accent = CustomColors.iconAccent
val attention = CustomColors.iconAttention
val tertiary = CustomColors.iconTertiary
val inlineContentMap = remember(iconSize, accent, attention, tertiary) {
mapOf(
"increase" to inlineIcon(iconSize, arrowUp, accent),
"decrease" to inlineIcon(iconSize, arrowDown, attention),
"nochange" to inlineIcon(iconSize, arrowRight, tertiary),
)
}
Is this the best way to write this?
Should I used derviedStateOf when creating inlineContentMap?
Does it make sense to use rememberVectorPainter since we already use remember on inlineMap?
Can we increase its performance taking into account that this will be rendered into an annotedString in Text ?
Thanks!
I'm trying to dynamically swap a text inside a LottieAnimation in jetpack compose.
The lottie file is exported without glyphs
It's working when using the old android view inside a
AndroidView(factory = { context ->
val view = LottieAnimationView(context).apply {
setAnimation(R.raw.testing_no_glyphs)
playAnimation()
repeatCount = LottieConstants.IterateForever
}
val textDel = object : TextDelegate(view) {
override fun getText(layerName: String?, input: String?): String {
return when (layerName) {
"Test234" -> "OtherLettersHere"
else -> super.getText(layerName, input)
}
}
}
val fontDel = object : FontAssetDelegate() {
override fun getFontPath(fontFamily: String?, fontStyle: String?, fontName: String?): String {
return "fonts/[MyFontInside /assets].ttf"
}
}
view.setTextDelegate(textDel)
view.setFontAssetDelegate(fontDel)
return#AndroidView view
})
But I can't find the correct handles in the JetpackCompose version of Lottie to get the same result.
If we export the lottie with glyphs, it's works for the letters in the chars array inside the lottie json. But we want to be able to replace with any letters/symbols, so this isn't a viable solution.
I've noticed in the 5.3.0-SNAPSHOT that a fontMap parameter has been added, but I can't figure out which key to hit with it.
Here is my code:
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, value = "AaBbCcEeFf", keyPath = arrayOf("Test234"))
)
val composition by rememberLottieComposition(
spec = LottieCompositionSpec.RawRes(R.raw.testing)
)
val progress by animateLottieCompositionAsState(composition, iterations = LottieConstants.IterateForever)
LottieAnimation(
composition,
{ progress },
dynamicProperties = dynamicProperties,
fontMap = mapOf("fName" to Typeface.createFromAsset(LocalContext.current.assets, "fonts/[MyFontInside /assets].ttf"))
)
It just shows a blank for all the texts inside the Lottie Animation - so this is kinda where i'm stuck.
After some trial an error I found a way to add the typeface for a specific layer:
val typeface = Typeface.createFromAsset(LocalContext.current.assets, "fonts/[MyFontInside /assets].ttf")
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, value = "AaBbCcEeFf", keyPath = arrayOf("Test234")),
--> rememberLottieDynamicProperty(LottieProperty.TYPEFACE, value = typeface, keyPath = arrayOf("Test234")),
)
Hence there is no need for the fontMap in my case
I am having a hard time converting the result of map in to its model type
val options = message.options.map {{
it.lastShare = user?.lastShare
it.lastWatch = user?.lastWatch
}}
I want the options to return as type ArrayList<Option> but I can't find anything on the internet. The message.options is of type List. when I do .map it returns List<() -> Unit>.
Please try next code:
val options = message.options.map {
it.lastShare = user?.lastShare
it.lastWatch = user?.lastWatch
it
}
or in your case I think you don't need to use map function, you can simply use forEach to update properties of each object in the list:
message.options.forEach {
it.lastShare = user?.lastShare
it.lastWatch = user?.lastWatch
}
val optionsArrayList: ArrayList<Option> = arrayListOf(*message.options.toTypedArray())
* - is a spread operator.
Or simpler way to create an ArrayList is just use its constructor:
val optionsArrayList: ArrayList<Option> = ArrayList(message.options)
Just write
val options = message.options.map {{
it.lastShare = user?.lastShare
it.lastWatch = user?.lastWatch
}}.toMutableList()
I try to set color in PieChart of MPAndroidChart.But its not set it.I want to add custom color in my partition . Here is my code :-
fun setupPieChartView() {
mPie = findViewById(R.id.piechart)
mPie?.setUsePercentValues(true)
val desc: Description = Description()
desc.text = "PieChart"
mPie?.description = desc
val legend: Legend? = mPie?.legend
legend?.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
val value = Arrays.asList(trueAns.toFloat(), wrongAns.toFloat(), noAns.toFloat())
val label = Arrays.asList("True", "false", "Not")
val entry = ArrayList<PieEntry>()
for (i in value.indices) {
entry.add(PieEntry(value.get(i), label.get(i)))
}
val dataSet = PieDataSet(entry, "Result")
dataSet.setDrawValues(true)
val pieData = PieData(dataSet)
pieData.setValueFormatter(PercentFormatter())
pieData.setValueTextSize(10f)
pieData.setValueTextColor(Color.WHITE)
mPie?.data = pieData
}
Instead of this
dataSet.colors = ColorTemplate.COLORFUL_COLORS.toList()
it should be
dataSet.setColors(Color.RED, Color.GREEN, Color.BLUE);
Because first one gives default colors, that's why you can't override colors. Here is result of your code :
I try to manage text in PieChart of MPAndroidChart. But when my text is difficult situation like True = 2, False = 3 , Not = 95, in this situation my pie chart layout is very bad.
Here is my code :-
fun setupPieChartView() {
mPie = findViewById(R.id.piechart)
mPie?.setUsePercentValues(true)
val desc: Description = Description()
desc.text = "PieChart"
mPie?.description = desc
val legend: Legend? = mPie?.legend
legend?.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
val value = Arrays.asList(trueAns.toFloat(), wrongAns.toFloat(), noAns.toFloat())
val label = Arrays.asList("True", "false", "Not")
val entry = ArrayList<PieEntry>()
for (i in value.indices) {
entry.add(PieEntry(value.get(i), label.get(i)))
}
val dataSet = PieDataSet(entry, "Result")
dataSet.setColors(Color.GREEN, Color.RED, Color.GRAY);
dataSet.setDrawValues(true)
val pieData = PieData(dataSet)
pieData.setValueFormatter(PercentFormatter())
pieData.setValueTextSize(10f)
pieData.setValueTextColor(Color.WHITE)
mPie?.data = pieData
}
Result is like that :-
here in my Pie-Chart data is not set in good format . Help me for this
You need this line, so your labels will be outside graph:
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
And value will be outside . You can also control position, line length and coloring like this:
pieData.setValueTextColor(Color.BLACK);
dataSet.setValueLinePart1OffsetPercentage(10.f);
dataSet.setValueLinePart1Length(0.43f);
dataSet.setValueLinePart2Length(.1f);
dataSet.setValueTextColor(Color.BLACK);
dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
mPie.setEntryLabelColor(Color.BLUE);
Here is result: