Showing subtitle on Exoplayer (Leanback) - android

Previously I was using Xam.Plugins.Android.ExoPlayer.Leanback version 2.11.8. I was able to load the subtitles using the following code
var subtitleView = RequireActivity().FindViewById(Resource.Id.leanback_subtitles) as SubtitleView;
var style = new CaptionStyleCompat(
Color.White,
Color.Transparent,
Color.Transparent,
CaptionStyleCompat.EdgeTypeDropShadow,
Color.Black,
Typeface.Default!);
var subtitleSize = GlobalSettings.GetFloat(GlobalSettings.KeySubtitleSize);
if (subtitleSize != null)
{
subtitleView?.SetFixedTextSize((int)ComplexUnitType.Sp, subtitleSize.Value);
}
subtitleView?.SetApplyEmbeddedStyles(false);
subtitleView?.SetStyle(style);
if (subtitleView != null)
{
var textComponent = _player.TextComponent;
textComponent.AddTextOutput(subtitleView);
}
Now after upgrading to version 2.18.9 I am not able to call textComponent.AddTextOutput(subtitleView); Seems like AddTextOutput function isn't available anymore. Can anyone please help how can I make subtitles work.
Thanks

Related

Does it make sense to put an InlineMap within a remember block in jetpack compose?

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!

Index out of bound in painterResource() when updating BottomNavigation

I'm currently getting an index out of bound which I can't figure out why...
Following situation:
Sometimes I update my compose bottom navigation to add an item or to change tint color etc. When the app is running and the update is happening it works. But when i close the app and it starts to initialize the navigation with the new state I get an index out of bound exception on the painterResource...
Would be nice if anyone has a hint for me. Another thing to add is i wire the compose currently to xml but i can't see a problem with that.
Thanks in advance
BottomNavigation(
backgroundColor = backgroundColor,
) {
navigation.navigationItems.forEach { navigationItem ->
val isSelected = selectedItem == navigationItem.destination
val iconResId =
if (isSelected) navigationItem.selectedIconRes else navigationItem.iconRes
val hasBadge = badges.contains(navigationItem.destination)
BottomNavigationItem(
icon = {
if (hasBadge) {
BadgedBox(
modifier = Modifier.background(badgeBackgroundColor),
badge = { Badge(backgroundColor = badgeColor) }
) {
Icon(
painterResource(iconResId),
contentDescription = null
)
}
} else {
Icon(
painterResource(iconResId),
contentDescription = null
)
}
},
selected = isSelected,
onClick = { onItemSelected(navigationItem.destination) },
alwaysShowLabel = true,
selectedContentColor = selectedTintColor,
unselectedContentColor = tintColor
)
}
}
Update:
I found now out why it happens but it’s still strange. The drawable itself produced somehow that error. After putting a different one there it worked all the time. The question is why did it not work after restarting the app but when running on the dynamic change… I have no idea…
Update 2:
After the dynamic change there are artifacts happening within the icons… For example 3rd icon has artifacts of 4th etc. What could cause that? Any idea?

Android Camera2 API contrast/gamma is not working for video preview

I was inspired by this topic to implement brightness and contrass in my camera app, but when I playing with gamma/contrast it doesn't work at all.
Im using createCaptureRequest(CameraDevice.TEMPLATE_RECORD) mode in Android Camera2 API.
The problem is the bellow code has no effect on the video preview:
captureRequestBuilder.set(CaptureRequest.TONEMAP_MODE, CaptureRequest.TONEMAP_MODE_GAMMA_VALUE)
captureRequestBuilder.set(CaptureRequest.TONEMAP_GAMMA, level)
captureSession.setRepeatingRequest(
captureRequestBuilder.build(), null, null)
Whatever level value I set it's just nothing.
Another problem with contrast:
private val channels by lazy {
val tc = captureRequestBuilder.get(CaptureRequest.TONEMAP_CURVE) ?: return#lazy null
val channels = arrayOf(floatArrayOf(), floatArrayOf(), floatArrayOf())
for(channel in TonemapCurve.CHANNEL_RED .. TonemapCurve.CHANNEL_BLUE) {
val contrast = FloatArray(tc.getPointCount(channel) * 2)
tc.copyColorCurve(channel, contrast, 0)
channels[channel] = contrast
}
channels
}
fun setContrast(level: Float) {
val level = level.coerceIn(0f, 1f)
val channels = channels ?: return
val newContrast = arrayOf(floatArrayOf(), floatArrayOf(), floatArrayOf())
for(channel in TonemapCurve.CHANNEL_RED .. TonemapCurve.CHANNEL_BLUE) {
val contrast = FloatArray(channels[channel].size)
System.arraycopy(channels[channel], 0, contrast, 0, contrast.size)
contrast.forEachIndexed { index, _ ->
contrast[index] *= level
}
newContrast[channel] = contrast
}
val newValue = TonemapCurve(newContrast[TonemapCurve.CHANNEL_RED],
newContrast[TonemapCurve.CHANNEL_GREEN],
newContrast[TonemapCurve.CHANNEL_BLUE])
captureRequestBuilder.set(CaptureRequest.TONEMAP_MODE, CaptureRequest.TONEMAP_MODE_CONTRAST_CURVE)
captureRequestBuilder.set(CaptureRequest.TONEMAP_CURVE, newValue)
captureSession.setRepeatingRequest(
captureRequestBuilder.build(), null, null)
}
captureRequestBuilder.get(CaptureRequest.TONEMAP_CURVE) always return null and even if try to set manually captureRequestBuilder.set(CaptureRequest.TONEMAP_CURVE, newValue) is still no any changes on video preview.
There is any solution how to implement contrast and gamma properly on Android camera video preview with CameraDevice.TEMPLATE_RECORD ?

Remove Legend default keyword "Stack" from MpAndroidChart

I am using MpAndroidChart library for android. I am able to give different color for the region below and above of the limit line. but i am getting a keyword "Stack" in legend(please check the attached screen shot).
Without limit line everything working perfectly. But if i am using limit line (red for region right of the limit line and green for otherside ) i am getting two legend and keyword "Stack" is appending along with legend.
if (yAxisValue != null) {
var progressData = progressLayoutData
val barDatasets: MutableList<IBarDataSet> = java.util.ArrayList()
for (yValues in yAxisValue) {
val entries: MutableList<BarEntry> = java.util.ArrayList()
var i = 0f
var isHaveLimitLine = false
val colorList: MutableList<Int> = java.util.ArrayList()
for (value in yValues?.dataSet) {
if(progressData?.limitLine!=null && progressData?.limitLine!=0) {
if (value > progressData?.limitLine ?: 0) {
var differenceValue = value?.toFloat() - progressData?.limitLine?.toFloat()!!
entries.add(BarEntry(i, floatArrayOf(progressData?.limitLine?.toFloat()!!, differenceValue)))
colorList.add(fhuiManager?.getParsedColor(yValues?.color,context))
colorList.add(fhuiManager?.getParsedColor(progressData?.limitExceedColor ?: "#FE2020",context))
} else {
colorList.add(fhuiManager?.getParsedColor(yValues?.color,context))
entries.add(BarEntry(i, value?.toFloat()))
}
isHaveLimitLine = true
}else{
entries.add(BarEntry(i, value?.toFloat()))
}
i++
}
val barDataSet = BarDataSet(entries, "" + yValues?.datasetName)
if(isHaveLimitLine)
barDataSet?.colors = colorList
else
barDataSet?.color = fhuiManager?.getParsedColor(yValues?.color,context)
barDataSet?.setDrawValues(false)
// add to line data set
barDatasets?.add(barDataSet)
}
return barDatasets
}
Please see the screenshot of issue here

android mapbox select feature on click

I'm using mapbox, with GeoJsonSource and symbollayer. When user clicks on feature it should change a color. I handle this logic with following code and it works, but it is too slow and takes several second to change icon color.
Here I configure symbol layer, add icon changelogic for 'PROPERTY_SELECTED':
mapBoxMap?.addLayer(SymbolLayer(markerStyleLayerIdentifier, markerSourceIdentifier)
.withProperties(
PropertyFactory.iconImage(markerImage),
PropertyFactory.iconAllowOverlap(false),
PropertyFactory.iconImage(match(
get(PROPERTY_SELECTED), literal(0),
literal(markerImage),
literal(markerImageSelected)
))
))
on map click features objects are update:
override fun onMapClick(point: LatLng) {
val screenPoint = mapBoxMap?.projection?.toScreenLocation(point)
var features = mapBoxMap?.queryRenderedFeatures(screenPoint
?: return, markerStyleLayerIdentifier)
if ((features ?: return).isNotEmpty()) {
var feature = features[0]
showMarkerInfo(feature)
doAsync {
var featureList = featureCollection?.features()
var id = feature.getNumberProperty(PROPERTY_STOP_ID)
if (featureList != null) {
for (i in 0 until featureList.size) {
var fId = featureList[i].getNumberProperty(PROPERTY_STOP_ID)
if (fId == id) {
featureList[i].properties()?.addProperty(PROPERTY_SELECTED, 1)
} else {
featureList[i].properties()?.addProperty(PROPERTY_SELECTED, 0)
}
}
uiThread {
refreshSource()
}
}
}
}
}
and refresh source :
private fun refreshSource() {
var source = mapBoxMap?.getSource(markerSourceIdentifier) as GeoJsonSource?
if (source != null && featureCollection != null) {
source.setGeoJson(featureCollection)
}
}
after 'refreshSource' is called , it takes several time before icon update. In my case there are 2050 features is source. Is there any better way to implement it ? Or any way to optimise this solution ?
here is a second , faster way from github answer:
var selectedLayer = mapBoxMap?.getLayer(markerSelectedStyleLayerIdentifier) as SymbolLayer?
var id = feature.getNumberProperty(PROPERTY_STOP_ID)
var selectedExpression = any(
eq(get(PROPERTY_STOP_ID), literal(id.toString()))
)
selectedLayer?.filter = selectedExpression
you can see whole issue there
https://github.com/mapbox/mapbox-java/issues/892

Categories

Resources