[Android] Fix the video information legend attribute and crash
Nicolas Pomepuy
git at videolan.org
Tue Nov 9 07:43:34 UTC 2021
vlc-android | branch: 3.4.x | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Nov 9 08:31:04 2021 +0100| [b9929996f71f715446649024868eee02ea5a25b5] | committer: Nicolas Pomepuy
Fix the video information legend attribute and crash
Fixes #2237
(cherry picked from commit 06fff26c6a60206882f675d4b3e8a5f8f691737e)
> https://code.videolan.org/videolan/vlc-android/commit/b9929996f71f715446649024868eee02ea5a25b5
---
.../main/java/org/videolan/liveplotgraph/LegendView.kt | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/application/live-plot-graph/src/main/java/org/videolan/liveplotgraph/LegendView.kt b/application/live-plot-graph/src/main/java/org/videolan/liveplotgraph/LegendView.kt
index c8c091054..f721f7ed5 100644
--- a/application/live-plot-graph/src/main/java/org/videolan/liveplotgraph/LegendView.kt
+++ b/application/live-plot-graph/src/main/java/org/videolan/liveplotgraph/LegendView.kt
@@ -57,11 +57,11 @@ class LegendView : ConstraintLayout, PlotViewDataChangeListener {
private fun initAttributes(attrs: AttributeSet, defStyle: Int) {
attrs.let {
- val a = context.theme.obtainStyledAttributes(attrs, R.styleable.LPGPlotView, 0, defStyle)
+ val a = context.theme.obtainStyledAttributes(attrs, R.styleable.LPGLegendView, 0, defStyle)
try {
- plotViewId = a.getResourceId(a.getIndex(R.styleable.LPGLegendView_lpg_plot_view), -1)
+ plotViewId = a.getResourceId(R.styleable.LPGLegendView_lpg_plot_view, -1)
} catch (e: Exception) {
- Log.w("", e.message, e)
+ Log.w("LegendView", e.message, e)
} finally {
a.recycle()
}
@@ -72,11 +72,12 @@ class LegendView : ConstraintLayout, PlotViewDataChangeListener {
super.onAttachedToWindow()
//workaround for editor
if (!isInEditMode) {
- context?.let {
- plotView = (it as Activity).findViewById(plotViewId)
- if (!::plotView.isInitialized) throw IllegalStateException("A valid plot view has to be provided")
- plotView.addListener(this)
- }
+ (context as? Activity)?.let { activity ->
+ activity.findViewById<PlotView>(plotViewId)?.let {
+ plotView = it
+ plotView.addListener(this)
+ }
+ } ?: Log.w("LegendView", "Cannot find the plot view with id $plotViewId")
}
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
}
More information about the Android
mailing list