[Android] Mitigate the seekbar UI issue on kitkat
Nicolas Pomepuy
git at videolan.org
Thu Aug 8 13:35:02 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Aug 8 07:15:32 2019 +0200| [ace6980203a145cd02bab0f2a7c4d903555d8397] | committer: Geoffrey Métais
Mitigate the seekbar UI issue on kitkat
> https://code.videolan.org/videolan/vlc-android/commit/ace6980203a145cd02bab0f2a7c4d903555d8397
---
vlc-android/res/layout/equalizer_bar.xml | 1 -
.../src/org/videolan/vlc/gui/view/VerticalSeekBar.kt | 20 +++++++++++++++++---
.../vlc/gui/view/VerticalSeekBarContainer.kt | 9 +++++----
3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/vlc-android/res/layout/equalizer_bar.xml b/vlc-android/res/layout/equalizer_bar.xml
index 8d21616ab..ebef5895a 100644
--- a/vlc-android/res/layout/equalizer_bar.xml
+++ b/vlc-android/res/layout/equalizer_bar.xml
@@ -25,7 +25,6 @@
android:id="@+id/equalizer_seek"
android:layout_width="0dp"
android:layout_height="0dp"
- android:progressDrawable="@drawable/po_seekbar"
android:splitTrack="false"
android:thumb="@drawable/seekbar_thumb" />
</org.videolan.vlc.gui.view.VerticalSeekBarContainer>
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBar.kt b/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBar.kt
index 13a6f1ebd..6bd12a0b5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBar.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBar.kt
@@ -6,18 +6,32 @@ import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatSeekBar
+import androidx.core.content.ContextCompat
+import org.videolan.vlc.R
class VerticalSeekBar : AppCompatSeekBar {
private var listener: OnSeekBarChangeListener? = null
var fromUser = false
+ constructor(context: Context) : super(context) {
+ initialize()
+ }
- constructor(context: Context) : super(context)
+ constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
+ initialize()
+ }
- constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
+ constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
+ initialize()
+ }
- constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
+ private fun initialize() {
+ //The custom drawable looks not great for kitkat. So we use the default one to mitigate the issue
+ if (Build.VERSION.SDK_INT >= 21) {
+ progressDrawable = ContextCompat.getDrawable(context, R.drawable.po_seekbar)
+ }
+ }
override fun onTouchEvent(event: MotionEvent): Boolean {
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBarContainer.kt b/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBarContainer.kt
index 5a667e115..16b7bad86 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBarContainer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/view/VerticalSeekBarContainer.kt
@@ -5,6 +5,7 @@ import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
+import kotlin.math.max
class VerticalSeekBarContainer @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
@@ -22,8 +23,8 @@ class VerticalSeekBarContainer @JvmOverloads constructor(context: Context, attrs
val hPadding = paddingLeft + paddingRight
val vPadding = paddingTop + paddingBottom
seekBar.measure(
- MeasureSpec.makeMeasureSpec(Math.max(0, h - vPadding), MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec(Math.max(0, w - hPadding), MeasureSpec.AT_MOST))
+ MeasureSpec.makeMeasureSpec(max(0, h - vPadding), MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(max(0, w - hPadding), MeasureSpec.AT_MOST))
}
applyViewRotation(w, h)
@@ -66,10 +67,10 @@ class VerticalSeekBarContainer @JvmOverloads constructor(context: Context, attrs
val seekBarMeasuredHeight = seekBar.measuredHeight
val hPadding = paddingLeft + paddingRight
val vPadding = paddingTop + paddingBottom
- val hOffset = (Math.max(0, w - hPadding) - seekBarMeasuredHeight) / 2f
+ val hOffset = (max(0, w - hPadding) - seekBarMeasuredHeight) / 2f
val lp = seekBar.layoutParams
- lp.width = Math.max(0, h - vPadding)
+ lp.width = max(0, h - vPadding)
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT
seekBar.layoutParams = lp
More information about the Android
mailing list