Browse Source

Apply ColorSelectView to TextBoxTabView & ShapeTabView

cooperku_kdanmobile 5 years ago
parent
commit
18983be221

+ 3 - 5
reader/src/main/java/com/kdanmobile/reader/screen/view/ColorOvalView.kt

@@ -13,7 +13,7 @@ import kotlinx.android.synthetic.main.view_color_oval.view.*
 
 
 class ColorOvalView : ConstraintLayout {
 class ColorOvalView : ConstraintLayout {
 
 
-    var color: Int? = null
+    var color: Int = android.R.color.black
         set(value) {
         set(value) {
             field = value
             field = value
 
 
@@ -51,14 +51,12 @@ class ColorOvalView : ConstraintLayout {
         initColor(color)
         initColor(color)
     }
     }
 
 
-    private fun initColor(color: Int?) {
+    private fun initColor(color: Int) {
         colorOval?.apply {
         colorOval?.apply {
             val stateListDrawable = background.mutate() as StateListDrawable
             val stateListDrawable = background.mutate() as StateListDrawable
             val layerDrawable = stateListDrawable.current.mutate() as LayerDrawable
             val layerDrawable = stateListDrawable.current.mutate() as LayerDrawable
             val gradientDrawable = layerDrawable.findDrawableByLayerId(R.id.ovalColor).mutate() as GradientDrawable
             val gradientDrawable = layerDrawable.findDrawableByLayerId(R.id.ovalColor).mutate() as GradientDrawable
-            color?.let {
-                gradientDrawable.setColor(it)
-            }
+            gradientDrawable.setColor(color)
         }
         }
     }
     }
 }
 }

+ 32 - 1
reader/src/main/java/com/kdanmobile/reader/screen/view/ColorSelectView.kt

@@ -11,11 +11,13 @@ import kotlinx.android.synthetic.main.view_color_select.view.*
 class ColorSelectView : ConstraintLayout {
 class ColorSelectView : ConstraintLayout {
 
 
     interface OnColorSelectedListener {
     interface OnColorSelectedListener {
-        fun onColorSelected(color: Int?)
+        fun onColorSelected(color: Int)
     }
     }
 
 
     var onColorSelectedListener: OnColorSelectedListener? = null
     var onColorSelectedListener: OnColorSelectedListener? = null
 
 
+    private var selectedColor: Int = android.R.color.black
+
     constructor(context: Context) : super(context) {
     constructor(context: Context) : super(context) {
         initView()
         initView()
     }
     }
@@ -56,5 +58,34 @@ class ColorSelectView : ConstraintLayout {
         colorSelect_column8.isSelected = (colorOvalView == colorSelect_column8)
         colorSelect_column8.isSelected = (colorOvalView == colorSelect_column8)
 
 
         onColorSelectedListener?.onColorSelected(colorOvalView.color)
         onColorSelectedListener?.onColorSelected(colorOvalView.color)
+        selectedColor = colorOvalView.color
+    }
+
+    fun getSelectedColor() : Int {
+        return selectedColor
+    }
+
+    fun setSelectedColor(color: Int) : Boolean {
+        val columnArray = arrayOf(colorSelect_column1, colorSelect_column2, colorSelect_column3, colorSelect_column4, colorSelect_column5, colorSelect_column6, colorSelect_column7, colorSelect_column8)
+        for (column in columnArray) {
+            if (column.color == color) {
+                setColorSelect(column)
+                return true
+            }
+        }
+        return false
+    }
+
+    fun getColor(index: Int) : Int {
+        return when (index) {
+            0 -> colorSelect_column1.color
+            1 -> colorSelect_column2.color
+            2 -> colorSelect_column3.color
+            3 -> colorSelect_column4.color
+            4 -> colorSelect_column5.color
+            5 -> colorSelect_column6.color
+            6 -> colorSelect_column7.color
+            else -> colorSelect_column8.color
+        }
     }
     }
 }
 }

+ 7 - 16
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/ShapeTabView.kt

@@ -48,10 +48,6 @@ class ShapeTabView : ConstraintLayout {
             }
             }
         }
         }
 
 
-    private var seekBarShapeBorderOpacity: TextSeekBar? = null
-    private var seekBarShapeBorderThickness: TextSeekBar? = null
-    private var seekBarShapeFillOpacity: TextSeekBar? = null
-
     constructor(context: Context) : super(context) {
     constructor(context: Context) : super(context) {
         initView()
         initView()
     }
     }
@@ -89,11 +85,11 @@ class ShapeTabView : ConstraintLayout {
     }
     }
 
 
     fun getShapeAttribute() : ShapeAttribute {
     fun getShapeAttribute() : ShapeAttribute {
-        val lineColor = 0xffff0000.toInt()
-        val lineWidth = seekBarShapeBorderThickness?.currentValue?.toFloat() ?: 3f
-        val lineAlpha = seekBarShapeBorderOpacity?.currentValue ?: 255
-        val fillColor = 0xff00ff00.toInt()
-        val fillAlpha = seekBarShapeFillOpacity?.currentValue ?: 0
+        val lineColor = colorChooser_shapeBorder.getSelectedColor()
+        val lineWidth = seekBar_shapeBorder_thickness.currentValue.toFloat()
+        val lineAlpha = seekBar_shapeBorder_opacity.currentValue
+        val fillColor = colorChooser_shapeFill.getSelectedColor()
+        val fillAlpha = seekBar_shapeFill_opacity.currentValue
         return ShapeAttribute(shapeType, lineColor, lineWidth, lineAlpha, fillColor, fillAlpha)
         return ShapeAttribute(shapeType, lineColor, lineWidth, lineAlpha, fillColor, fillAlpha)
     }
     }
 
 
@@ -107,18 +103,13 @@ class ShapeTabView : ConstraintLayout {
             }
             }
             val view = layoutInflater.inflate(resourceId, container, false)
             val view = layoutInflater.inflate(resourceId, container, false)
             if (position == 0) {
             if (position == 0) {
-                seekBarShapeBorderOpacity = view.seekBar_shapeBorder_opacity
-                seekBarShapeBorderThickness = view.seekBar_shapeBorder_thickness
-
-                seekBarShapeBorderOpacity?.formatter = object : TextSeekBar.SeekBarFormatter {
+                view.seekBar_shapeBorder_opacity.formatter = object : TextSeekBar.SeekBarFormatter {
                     override fun format(value: Int): String {
                     override fun format(value: Int): String {
                         return Math.round(value / 2.55).toInt().toString()
                         return Math.round(value / 2.55).toInt().toString()
                     }
                     }
                 }
                 }
             } else {
             } else {
-                seekBarShapeFillOpacity = view.seekBar_shapeFill_opacity
-
-                seekBarShapeFillOpacity?.formatter = object : TextSeekBar.SeekBarFormatter {
+                view.seekBar_shapeFill_opacity.formatter = object : TextSeekBar.SeekBarFormatter {
                     override fun format(value: Int): String {
                     override fun format(value: Int): String {
                         return Math.round(value / 2.55).toInt().toString()
                         return Math.round(value / 2.55).toInt().toString()
                     }
                     }

+ 10 - 1
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/TextBoxTabView.kt

@@ -8,6 +8,7 @@ import android.view.LayoutInflater
 import android.widget.SeekBar
 import android.widget.SeekBar
 import com.kdanmobile.reader.R
 import com.kdanmobile.reader.R
 import com.kdanmobile.reader.screen.data.TextBoxAttribute
 import com.kdanmobile.reader.screen.data.TextBoxAttribute
+import com.kdanmobile.reader.screen.view.ColorSelectView
 import kotlinx.android.synthetic.main.view_viewer_edit_tab_text_box.view.*
 import kotlinx.android.synthetic.main.view_viewer_edit_tab_text_box.view.*
 
 
 class TextBoxTabView : ConstraintLayout {
 class TextBoxTabView : ConstraintLayout {
@@ -61,6 +62,12 @@ class TextBoxTabView : ConstraintLayout {
             }
             }
         }
         }
 
 
+        colorChooser_textBox.onColorSelectedListener = object : ColorSelectView.OnColorSelectedListener {
+            override fun onColorSelected(color: Int) {
+                tv_preview.setTextColor(color)
+            }
+        }
+
         seekBar_textBox_textSize.onSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
         seekBar_textBox_textSize.onSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
             override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
             override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
 //                tv_preview.textSize = seekBar_textBox_textSize.currentValue.toFloat()
 //                tv_preview.textSize = seekBar_textBox_textSize.currentValue.toFloat()
@@ -73,13 +80,15 @@ class TextBoxTabView : ConstraintLayout {
 //                tv_preview.textSize = seekBar_textBox_textSize.currentValue.toFloat()
 //                tv_preview.textSize = seekBar_textBox_textSize.currentValue.toFloat()
             }
             }
         }
         }
+
+        tv_preview.setTextColor(colorChooser_textBox.getSelectedColor())
     }
     }
 
 
     fun getTextBoxAttribute(): TextBoxAttribute {
     fun getTextBoxAttribute(): TextBoxAttribute {
         val isBold = textAttrView_textBox.isTextBold
         val isBold = textAttrView_textBox.isTextBold
         val isItalic = textAttrView_textBox.isTextItalic
         val isItalic = textAttrView_textBox.isTextItalic
         val textAlignment = textAttrView_textBox.alignment
         val textAlignment = textAttrView_textBox.alignment
-        val textColor = 0xff000000.toInt()
+        val textColor = tv_preview.currentTextColor
         val textSize = seekBar_textBox_textSize.currentValue
         val textSize = seekBar_textBox_textSize.currentValue
         return TextBoxAttribute(isBold, isItalic, textAlignment, textColor, textSize)
         return TextBoxAttribute(isBold, isItalic, textAlignment, textColor, textSize)
     }
     }

+ 3 - 4
reader/src/main/res/layout/view_viewer_edit_item_shape_border.xml

@@ -4,13 +4,12 @@
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
     android:layout_height="match_parent">
 
 
-    <TextView
+    <com.kdanmobile.reader.screen.view.ColorSelectView
         android:id="@+id/colorChooser_shapeBorder"
         android:id="@+id/colorChooser_shapeBorder"
-        android:layout_width="match_parent"
+        android:layout_width="wrap_content"
         android:layout_height="50dp"
         android:layout_height="50dp"
-        android:text="Color Chooser"
         android:gravity="center"
         android:gravity="center"
-        android:background="#00ff00"
+        android:paddingTop="12dp"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintTop_toTopOf="parent"

+ 3 - 4
reader/src/main/res/layout/view_viewer_edit_item_shape_fill.xml

@@ -4,13 +4,12 @@
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
     android:layout_height="match_parent">
 
 
-    <TextView
+    <com.kdanmobile.reader.screen.view.ColorSelectView
         android:id="@+id/colorChooser_shapeFill"
         android:id="@+id/colorChooser_shapeFill"
-        android:layout_width="match_parent"
+        android:layout_width="wrap_content"
         android:layout_height="50dp"
         android:layout_height="50dp"
-        android:text="Color Chooser"
         android:gravity="center"
         android:gravity="center"
-        android:background="#00ff00"
+        android:paddingTop="12dp"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintTop_toTopOf="parent"

+ 3 - 4
reader/src/main/res/layout/view_viewer_edit_tab_text_box.xml

@@ -56,13 +56,12 @@
         app:layout_constraintTop_toBottomOf="@+id/editTextView_textBox"
         app:layout_constraintTop_toBottomOf="@+id/editTextView_textBox"
         app:layout_constraintBottom_toTopOf="@+id/colorChooser_textBox" />
         app:layout_constraintBottom_toTopOf="@+id/colorChooser_textBox" />
 
 
-    <TextView
+    <com.kdanmobile.reader.screen.view.ColorSelectView
         android:id="@+id/colorChooser_textBox"
         android:id="@+id/colorChooser_textBox"
-        android:layout_width="match_parent"
+        android:layout_width="wrap_content"
         android:layout_height="48dp"
         android:layout_height="48dp"
-        android:text="Color Chooser"
         android:gravity="center"
         android:gravity="center"
-        android:background="#00ff00"
+        android:paddingTop="12dp"
         android:layout_marginTop="16dp"
         android:layout_marginTop="16dp"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintRight_toRightOf="parent"