Преглед изворни кода

Merge branch 'fixWrongAnnotationAttributeSeekbarValue' into 'master'

修正AnnotationAttributeWindow的SeekBar數值範圍錯誤

See merge request kdanandroid/pdf/pdfreaderreadermodule!27
Wayne Huang пре 5 година
родитељ
комит
646c847507

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

@@ -0,0 +1,88 @@
+package com.kdanmobile.reader.annotationattribute
+
+import android.content.Context
+import android.support.constraint.ConstraintLayout
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.widget.SeekBar
+import com.kdanmobile.reader.R
+import kotlinx.android.synthetic.main.view_annotation_attribute_window_seekbar.view.*
+
+class AnnotationAttributeWindowSeekBar : ConstraintLayout {
+
+    var max = 100
+        set(value) {
+            field = value
+            seekBar?.max = max - min
+        }
+    var min = 0
+        set(value) {
+            field = value
+            seekBar?.max = max - min
+        }
+    var progress = 0
+        set(value) {
+            field = Math.max(Math.min(value, max), min)
+            seekBar?.progress = field - min
+        }
+
+    override fun isEnabled(): Boolean {
+        return seekBar?.isEnabled ?: false
+    }
+
+    override fun setEnabled(enabled: Boolean) {
+        super.setEnabled(enabled)
+        seekBar?.isEnabled = enabled
+    }
+
+    private var onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener? = null
+
+    fun setOnSeekBarChangeListener(onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener) {
+        this.onSeekBarChangeListener = onSeekBarChangeListener
+    }
+
+    constructor(context: Context) : super(context) {
+        initView()
+    }
+
+    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
+        initAttr(attrs)
+        initView()
+    }
+
+    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
+        initAttr(attrs)
+        initView()
+    }
+
+    private fun initAttr(attributeSet: AttributeSet) {
+        val typedArray = context.theme.obtainStyledAttributes(attributeSet, R.styleable.AnnotationAttributeWindowSeekBar, 0, 0)
+        max = typedArray.getInteger(R.styleable.AnnotationAttributeWindowSeekBar_maxValue, 100)
+        min = typedArray.getInteger(R.styleable.AnnotationAttributeWindowSeekBar_minValue, 0)
+        if (max < min)
+            max = min
+        progress = typedArray.getInteger(R.styleable.AnnotationAttributeWindowSeekBar_initValue, 0)
+        progress = Math.max(Math.min(progress, max), min)
+    }
+
+    private fun initView() {
+        LayoutInflater.from(context).inflate(R.layout.view_annotation_attribute_window_seekbar, this)
+
+        seekBar.max = max - min
+        seekBar.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
+            override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
+                this@AnnotationAttributeWindowSeekBar.progress = progress + min
+                onSeekBarChangeListener?.onProgressChanged(seekBar, this@AnnotationAttributeWindowSeekBar.progress, fromUser)
+            }
+
+            override fun onStartTrackingTouch(seekBar: SeekBar) {
+                onSeekBarChangeListener?.onStartTrackingTouch(seekBar)
+            }
+
+            override fun onStopTrackingTouch(seekBar: SeekBar) {
+                onSeekBarChangeListener?.onStopTrackingTouch(seekBar)
+            }
+        })
+        this.progress = progress
+    }
+}

+ 1 - 1
src/main/res/color/selector_annotation_attribute_seek_bar.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_enabled="false" android:color="@color/reader_annotation_attribute_seek_bar_tint_disable"/>
     <item android:state_enabled="true" android:color="@color/reader_annotation_attribute_seek_bar_tint_enable"/>
+    <item android:state_enabled="false" android:color="@color/reader_annotation_attribute_seek_bar_tint_disable"/>
 </selector>

+ 1 - 1
src/main/res/color/selector_annotation_attribute_seek_bar_background.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_enabled="false" android:color="@color/reader_annotation_attribute_seek_bar_tint_background_disable"/>
     <item android:state_enabled="true" android:color="@color/reader_annotation_attribute_seek_bar_tint_background_enable"/>
+    <item android:state_enabled="false" android:color="@color/reader_annotation_attribute_seek_bar_tint_background_disable"/>
 </selector>

+ 17 - 0
src/main/res/drawable/annotation_attribute_window_seekbar_progress.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+    <item android:id="@android:id/background">
+        <shape android:shape="rectangle" >
+            <solid
+                android:color="@color/selector_annotation_attribute_seek_bar_background" />
+        </shape>
+    </item>
+    <item android:id="@android:id/progress">
+        <clip>
+            <shape android:shape="rectangle" >
+                <solid
+                    android:color="@color/selector_annotation_attribute_seek_bar" />
+            </shape>
+        </clip>
+    </item>
+</layer-list>

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

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    tools:parentTag="android.support.constraint.ConstraintLayout">
+
+    <SeekBar
+        android:id="@+id/seekBar"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        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"
+        app:layout_constraintRight_toRightOf="parent" />
+
+</merge>

+ 8 - 19
src/main/res/layout/view_reader_annotation_property.xml

@@ -55,7 +55,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
 
-    <SeekBar
+    <com.kdanmobile.reader.annotationattribute.AnnotationAttributeWindowSeekBar
         android:id="@+id/seekBar_readerAnnotationProperty_thickness"
         android:layout_marginTop="8dp"
         app:layout_constraintLeft_toRightOf="@id/barrier_readerAnnotationProperty_thicknessOpacityText"
@@ -63,20 +63,14 @@
         app:layout_constraintTop_toBottomOf="@id/waveLineView_readerAnnotationProperty"
         android:layout_width="0dp"
         android:layout_height="32dp"
-        android:min="1"
-        android:max="16"
-        android:maxHeight="1dp"
-        android:minHeight="1dp"
+        app:minValue="1"
+        app:maxValue="16"
+        app:initValue="3"
         android:paddingLeft="10dp"
         android:paddingRight="10dp"
-        android:progress="3"
-        android:progressTint="@color/selector_annotation_attribute_seek_bar"
-        android:progressBackgroundTint="@color/selector_annotation_attribute_seek_bar_background"
-        android:thumbTint="@color/selector_annotation_attribute_seek_bar"
-        android:scrollbarStyle="insideOverlay"
         android:thumbOffset="7dp" />
 
-    <SeekBar
+    <com.kdanmobile.reader.annotationattribute.AnnotationAttributeWindowSeekBar
         android:id="@+id/seekBar_readerAnnotationProperty_opacity"
         android:layout_marginTop="8dp"
         app:layout_constraintLeft_toRightOf="@id/barrier_readerAnnotationProperty_thicknessOpacityText"
@@ -84,17 +78,12 @@
         app:layout_constraintTop_toBottomOf="@id/seekBar_readerAnnotationProperty_thickness"
         android:layout_width="0dp"
         android:layout_height="32dp"
-        android:min="1"
-        android:max="100"
+        app:minValue="1"
+        app:maxValue="100"
+        app:initValue="50"
         android:progress="50"
-        android:maxHeight="1dp"
-        android:minHeight="1dp"
         android:paddingLeft="10dp"
         android:paddingRight="10dp"
-        android:progressTint="@color/selector_annotation_attribute_seek_bar"
-        android:progressBackgroundTint="@color/selector_annotation_attribute_seek_bar_background"
-        android:thumbTint="@color/selector_annotation_attribute_seek_bar"
-        android:scrollbarStyle="insideOverlay"
         />
 
     <android.support.constraint.Barrier

+ 12 - 3
src/main/res/values/attrs.xml

@@ -7,13 +7,16 @@
     </declare-styleable>
 
     <attr name="title" format="string" />
+    <attr name="maxValue" format="integer" />
+    <attr name="minValue" format="integer" />
+    <attr name="initValue" format="integer" />
 
     <declare-styleable name="MediaBoxSeekBar">
         <attr name="title" />
         <attr name="unit" format="string" />
-        <attr name="maxValue" format="integer" />
-        <attr name="minValue" format="integer" />
-        <attr name="initValue" format="integer" />
+        <attr name="maxValue" />
+        <attr name="minValue" />
+        <attr name="initValue" />
     </declare-styleable>
 
     <declare-styleable name="MediaBoxHeader">
@@ -25,4 +28,10 @@
         <attr name="color" format="color" />
     </declare-styleable>
 
+    <declare-styleable name="AnnotationAttributeWindowSeekBar">
+        <attr name="maxValue" />
+        <attr name="minValue" />
+        <attr name="initValue" />
+    </declare-styleable>
+
 </resources>

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

@@ -22,9 +22,9 @@
     <color name="reader_right_toolbar_disabled_bg">#40000000</color>
 
     <color name="reader_annotation_attribute_seek_bar_tint_enable">@color/bright_blue</color>
-    <color name="reader_annotation_attribute_seek_bar_tint_disable">@color/black_38</color>
+    <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">@color/black_38</color>
+    <color name="reader_annotation_attribute_seek_bar_tint_background_disable">#FFCFCFCF</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>