Просмотр исходного кода

Fix: wrong thumb color below Android 5.0

cooperku_kdanmobile 5 лет назад
Родитель
Сommit
3e896e922d

+ 17 - 0
src/main/java/com/kdanmobile/reader/annotationattribute/AnnotationAttributeWindowSeekBar.kt

@@ -1,7 +1,10 @@
 package com.kdanmobile.reader.annotationattribute
 
 import android.content.Context
+import android.graphics.PorterDuff
+import android.os.Build
 import android.support.constraint.ConstraintLayout
+import android.support.v4.content.ContextCompat
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.widget.SeekBar
@@ -33,6 +36,10 @@ class AnnotationAttributeWindowSeekBar : ConstraintLayout {
     override fun setEnabled(enabled: Boolean) {
         super.setEnabled(enabled)
         seekBar?.isEnabled = enabled
+
+        if (enabled) {
+            setSeekBarThumbColor(seekBar, ContextCompat.getColor(context, R.color.reader_annotation_attribute_seek_bar_thumb_tint))
+        }
     }
 
     private var onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener? = null
@@ -84,5 +91,15 @@ class AnnotationAttributeWindowSeekBar : ConstraintLayout {
             }
         })
         this.progress = progress
+
+        setSeekBarThumbColor(seekBar, ContextCompat.getColor(context, R.color.reader_annotation_attribute_seek_bar_thumb_tint))
+    }
+
+    private fun setSeekBarThumbColor(seekBar: SeekBar?, color: Int) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            seekBar?.thumb?.setTint(color)
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+            seekBar?.thumb?.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
+        }
     }
 }

+ 9 - 0
src/main/java/com/kdanmobile/reader/screen/reader/mediabox/common/MediaBoxSeekBar.kt

@@ -1,7 +1,10 @@
 package com.kdanmobile.reader.screen.reader.mediabox.common
 
 import android.content.Context
+import android.graphics.PorterDuff
+import android.os.Build
 import android.support.constraint.ConstraintLayout
+import android.support.v4.content.ContextCompat
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.widget.SeekBar
@@ -86,5 +89,11 @@ class MediaBoxSeekBar : ConstraintLayout {
             }
         })
         currentValue = initValue
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            seekBar_mediaBoxSeekBar.thumb.setTint(ContextCompat.getColor(context, R.color.mediaBox_seek_bar_thumb_tint))
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+            seekBar_mediaBoxSeekBar.thumb.setColorFilter(ContextCompat.getColor(context, R.color.mediaBox_seek_bar_thumb_tint), PorterDuff.Mode.SRC_ATOP)
+        }
     }
 }

+ 0 - 1
src/main/res/layout/view_annotation_attribute_window_seekbar.xml

@@ -14,7 +14,6 @@
         android:maxHeight="2dp"
         android:minHeight="2dp"
         android:progressDrawable="@drawable/annotation_attribute_window_seekbar_progress"
-        android:thumbTint="#0077fd"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"

+ 0 - 1
src/main/res/layout/view_media_box_seekbar.xml

@@ -29,7 +29,6 @@
         android:maxHeight="2dp"
         android:minHeight="2dp"
         android:progressDrawable="@drawable/blue_seekbar_progress"
-        android:thumbTint="#0077fd"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toLeftOf="@+id/tv_mediaBoxSeekBar_value"

+ 2 - 0
src/main/res/values/colors.xml

@@ -25,6 +25,7 @@
     <color name="reader_annotation_attribute_seek_bar_tint_disable">#FFCFCFCF</color>
     <color name="reader_annotation_attribute_seek_bar_tint_background_enable">@color/bright_blue_38</color>
     <color name="reader_annotation_attribute_seek_bar_tint_background_disable">#FFCFCFCF</color>
+    <color name="reader_annotation_attribute_seek_bar_thumb_tint">#FF0077fd</color>
     <color name="reader_color_selector_color_1">#000000</color>
     <color name="reader_color_selector_color_2">#296dd2</color>
     <color name="reader_color_selector_color_3">#57d214</color>
@@ -60,6 +61,7 @@
 
     <color name="mediaBox_standardStamp_normal">#ffffff</color>
     <color name="mediaBox_standardStamp_selected">@color/reader_right_toolbar_selected_bg</color>
+    <color name="mediaBox_seek_bar_thumb_tint">#FF0077fd</color>
 
     <color name="color_0000">#0000</color>