Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

cooperku_kdanmobile vor 5 Jahren
Ursprung
Commit
e34d6a828c

+ 10 - 10
reader/src/main/java/com/kdanmobile/reader/annotationattribute/AnnotationColor.kt

@@ -3,14 +3,14 @@ package com.kdanmobile.reader.annotationattribute
 import com.kdanmobile.reader.R
 
 enum class AnnotationColor(val colorResId: Int) {
-    Color1(R.color.reader_annotation_color_1),
-    Color2(R.color.reader_annotation_color_2),
-    Color3(R.color.reader_annotation_color_3),
-    Color4(R.color.reader_annotation_color_4),
-    Color5(R.color.reader_annotation_color_5),
-    Color6(R.color.reader_annotation_color_6),
-    Color7(R.color.reader_annotation_color_7),
-    Color8(R.color.reader_annotation_color_8),
-    Color9(R.color.reader_annotation_color_9),
-    Color10(R.color.reader_annotation_color_10),
+    Color1(R.color.reader_color_selector_color_1),
+    Color2(R.color.reader_color_selector_color_2),
+    Color3(R.color.reader_color_selector_color_3),
+    Color4(R.color.reader_color_selector_color_4),
+    Color5(R.color.reader_color_selector_color_5),
+    Color6(R.color.reader_color_selector_color_6),
+    Color7(R.color.reader_color_selector_color_7),
+    Color8(R.color.reader_color_selector_color_8),
+    Color9(R.color.reader_color_selector_color_9),
+    Color10(R.color.reader_color_selector_color_10),
 }

+ 21 - 4
reader/src/main/java/com/kdanmobile/reader/screen/view/ColorSelectView.kt

@@ -1,14 +1,14 @@
 package com.kdanmobile.reader.screen.view
 
 import android.content.Context
-import android.support.constraint.ConstraintLayout
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.view.View
+import android.widget.HorizontalScrollView
 import com.kdanmobile.reader.R
 import kotlinx.android.synthetic.main.view_color_select.view.*
 
-class ColorSelectView : ConstraintLayout {
+class ColorSelectView : HorizontalScrollView {
 
     interface OnColorSelectedListener {
         fun onColorSelected(color: Int)
@@ -41,6 +41,8 @@ class ColorSelectView : ConstraintLayout {
         colorSelect_column6.setOnClickListener(this::setColorSelect)
         colorSelect_column7.setOnClickListener(this::setColorSelect)
         colorSelect_column8.setOnClickListener(this::setColorSelect)
+        colorSelect_column9.setOnClickListener(this::setColorSelect)
+        colorSelect_column10.setOnClickListener(this::setColorSelect)
 
         setColorSelect(colorSelect_column1)
     }
@@ -56,6 +58,8 @@ class ColorSelectView : ConstraintLayout {
         colorSelect_column6.isSelected = (colorOvalView == colorSelect_column6)
         colorSelect_column7.isSelected = (colorOvalView == colorSelect_column7)
         colorSelect_column8.isSelected = (colorOvalView == colorSelect_column8)
+        colorSelect_column9.isSelected = (colorOvalView == colorSelect_column9)
+        colorSelect_column10.isSelected = (colorOvalView == colorSelect_column10)
 
         onColorSelectedListener?.onColorSelected(colorOvalView.color)
         selectedColor = colorOvalView.color
@@ -66,7 +70,18 @@ class ColorSelectView : ConstraintLayout {
     }
 
     fun setSelectedColor(color: Int) : Boolean {
-        val columnArray = arrayOf(colorSelect_column1, colorSelect_column2, colorSelect_column3, colorSelect_column4, colorSelect_column5, colorSelect_column6, colorSelect_column7, colorSelect_column8)
+        val columnArray = arrayOf(
+                colorSelect_column1,
+                colorSelect_column2,
+                colorSelect_column3,
+                colorSelect_column4,
+                colorSelect_column5,
+                colorSelect_column6,
+                colorSelect_column7,
+                colorSelect_column8,
+                colorSelect_column9,
+                colorSelect_column10
+        )
         for (column in columnArray) {
             if (column.color == color) {
                 setColorSelect(column)
@@ -85,7 +100,9 @@ class ColorSelectView : ConstraintLayout {
             4 -> colorSelect_column5.color
             5 -> colorSelect_column6.color
             6 -> colorSelect_column7.color
-            else -> colorSelect_column8.color
+            7 -> colorSelect_column8.color
+            8 -> colorSelect_column9.color
+            else -> colorSelect_column10.color
         }
     }
 }

+ 13 - 31
reader/src/main/java/com/kdanmobile/reader/view/AnnotationAttributeView.kt

@@ -4,7 +4,6 @@ import android.content.Context
 import android.support.v4.graphics.ColorUtils
 import android.util.AttributeSet
 import android.view.View
-import android.widget.ImageView
 import android.widget.LinearLayout
 import android.widget.SeekBar
 import com.kdanmobile.reader.R
@@ -12,6 +11,7 @@ import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
 import com.kdanmobile.reader.annotationattribute.AnnotationColor
 import com.kdanmobile.reader.annotationattribute.Brush
 import com.kdanmobile.reader.annotationattribute.InkAttribute
+import com.kdanmobile.reader.screen.view.ColorSelectView
 import kotlinx.android.synthetic.main.view_reader_annotation_property.view.*
 
 class AnnotationAttributeView @JvmOverloads constructor(
@@ -53,18 +53,6 @@ class AnnotationAttributeView @JvmOverloads constructor(
             update()
         }
     var onChangeListener: OnChangeListener? = null
-    private val colorBtnMap = HashMap<AnnotationColor, ImageView>().apply {
-        put(AnnotationColor.Color1, iv_readerAnnotationProperty_color1)
-        put(AnnotationColor.Color2, iv_readerAnnotationProperty_color2)
-        put(AnnotationColor.Color3, iv_readerAnnotationProperty_color3)
-        put(AnnotationColor.Color4, iv_readerAnnotationProperty_color4)
-        put(AnnotationColor.Color5, iv_readerAnnotationProperty_color5)
-        put(AnnotationColor.Color6, iv_readerAnnotationProperty_color6)
-        put(AnnotationColor.Color7, iv_readerAnnotationProperty_color7)
-        put(AnnotationColor.Color8, iv_readerAnnotationProperty_color8)
-        put(AnnotationColor.Color9, iv_readerAnnotationProperty_color9)
-        put(AnnotationColor.Color10, iv_readerAnnotationProperty_color10)
-    }
     private var thickness: Int = DEFAULT_THICKNESS
         set(value) {
             field = value
@@ -100,6 +88,7 @@ class AnnotationAttributeView @JvmOverloads constructor(
         }
     private var colorEnum: AnnotationColor = AnnotationColor.Color1
         set(value) {
+            if (field == value) return
             field = value
             updateColor()
             updateColorButtons()
@@ -154,8 +143,15 @@ class AnnotationAttributeView @JvmOverloads constructor(
     }
 
     private fun setupColorButtons() {
-        colorBtnMap.values.forEach {
-            it.setOnClickListener(this::onClickColorBtn)
+        viewGroup_readerAnnotationProperty_color.onColorSelectedListener = object : ColorSelectView.OnColorSelectedListener {
+            override fun onColorSelected(color: Int) {
+                AnnotationColor.values().forEach { annotationColor ->
+                    val c = resources.getColor(annotationColor.colorResId)
+                    if (c == color) {
+                        colorEnum = annotationColor
+                    }
+                }
+            }
         }
     }
 
@@ -221,15 +217,6 @@ class AnnotationAttributeView @JvmOverloads constructor(
         })
     }
 
-    private fun onClickColorBtn(view: View) {
-        colorBtnMap.entries.forEach {
-            if (it.value == view) {
-                colorEnum = it.key
-                return
-            }
-        }
-    }
-
     private fun update() {
         updateOpacity()
         updateThickness()
@@ -277,13 +264,8 @@ class AnnotationAttributeView @JvmOverloads constructor(
     }
 
     private fun updateColorButtons() {
-        colorBtnMap.entries.forEach {
-            if (it.key == colorEnum) {
-                it.value.setImageResource(R.drawable.reader_annotation_property_color_border_select)
-            } else {
-                it.value.setImageResource(R.drawable.reader_annotation_property_color_border)
-            }
-        }
+        val c = resources.getColor(colorEnum.colorResId)
+        viewGroup_readerAnnotationProperty_color.setSelectedColor(c)
     }
 
     interface OnChangeListener {

+ 12 - 12
reader/src/main/res/drawable/shape_color_oval.xml

@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:id="@+id/ovalBorder">
+
+    <item
+        android:id="@+id/ovalColor"
+        android:left="2dp"
+        android:right="2dp"
+        android:top="2dp"
+        android:bottom="2dp">
         <shape android:shape="oval">
-            <stroke
-                android:width="2dp"
-                android:color="#ffffff" />
-            <padding
-                android:bottom="4dp"
-                android:left="4dp"
-                android:right="4dp"
-                android:top="4dp" />
+            <solid android:color="#000000" />
             <corners android:radius="16dp" />
         </shape>
     </item>
-
-    <item android:id="@+id/ovalColor">
+    <item android:id="@+id/ovalBorder">
         <shape android:shape="oval">
-            <solid android:color="#000000" />
+            <stroke
+                android:width="1dp"
+                android:color="#EEEEEE" />
             <corners android:radius="16dp" />
         </shape>
     </item>

+ 11 - 11
reader/src/main/res/drawable/shape_color_oval_checked.xml

@@ -1,22 +1,22 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:id="@+id/ovalBorder">
+    <item
+        android:id="@+id/ovalColor"
+        android:left="4dp"
+        android:right="4dp"
+        android:top="4dp"
+        android:bottom="4dp">
         <shape android:shape="oval">
-            <stroke
-                android:width="2dp"
-                android:color="#0077fd" />
-            <padding
-                android:bottom="4dp"
-                android:left="4dp"
-                android:right="4dp"
-                android:top="4dp" />
+            <solid android:color="#000000" />
             <corners android:radius="16dp" />
         </shape>
     </item>
 
-    <item android:id="@+id/ovalColor">
+    <item android:id="@+id/ovalBorder">
         <shape android:shape="oval">
-            <solid android:color="#000000" />
+            <stroke
+                android:width="2dp"
+                android:color="#0077fd" />
             <corners android:radius="16dp" />
         </shape>
     </item>

+ 54 - 59
reader/src/main/res/layout/view_color_select.xml

@@ -1,70 +1,65 @@
 <?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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"
+    tools:parentTag="android.widget.HorizontalScrollView"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:background="@android:color/white">
+    android:layout_height="wrap_content">
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column1"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#d0021b"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column2" />
+    <LinearLayout
+        android:orientation="horizontal"
+        android:gravity="center"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content">
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column2"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#f5a623"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column1"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column3" />
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column1"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_1" />
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column3"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#f8e71c"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column2"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column4" />
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column2"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_2" />
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column4"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#8b572a"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column3"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column5" />
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column3"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_3" />
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column5"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#7ed321"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column4"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column6" />
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column4"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_4" />
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column6"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#417505"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column5"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column7" />
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column5"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_5" />
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column7"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:color="#4a90e2"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column6"
-        app:layout_constraintRight_toLeftOf="@id/colorSelect_column8" />
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column6"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_6" />
 
-    <com.kdanmobile.reader.screen.view.ColorOvalView
-        android:id="@+id/colorSelect_column8"
-        android:layout_width="24dp"
-        android:layout_height="24dp"
-        app:layout_constraintLeft_toRightOf="@id/colorSelect_column7"
-        app:layout_constraintRight_toRightOf="parent"/>
-</android.support.constraint.ConstraintLayout>
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column7"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_7" />
+
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column8"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_8" />
+
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column9"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_9" />
+
+        <com.kdanmobile.reader.screen.view.ColorOvalView
+            android:id="@+id/colorSelect_column10"
+            style="@style/ReaderColorSelectorItemStyle"
+            app:color="@color/reader_color_selector_color_10" />
+    </LinearLayout>
+</merge>

+ 4 - 2
reader/src/main/res/layout/view_media_box_item_text_attr.xml

@@ -29,10 +29,10 @@
         android:src="@drawable/ic_italic"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toRightOf="@+id/btn_text_bold"
-        app:layout_constraintRight_toLeftOf="@+id/btn_text_align_left" />
+        app:layout_constraintLeft_toRightOf="@+id/btn_text_bold" />
     <ImageButton
         android:id="@+id/btn_text_align_left"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:padding="12dp"
@@ -44,6 +44,7 @@
         app:layout_constraintRight_toLeftOf="@+id/btn_text_align_center" />
     <ImageButton
         android:id="@+id/btn_text_align_center"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:padding="12dp"
@@ -55,6 +56,7 @@
         app:layout_constraintRight_toLeftOf="@+id/btn_text_align_right" />
     <ImageButton
         android:id="@+id/btn_text_align_right"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:padding="12dp"

+ 4 - 59
reader/src/main/res/layout/view_reader_annotation_property.xml

@@ -127,69 +127,14 @@
         android:layout_width="32dp"
         android:layout_height="wrap_content" />
 
-    <HorizontalScrollView
+    <com.kdanmobile.reader.screen.view.ColorSelectView
         android:id="@+id/viewGroup_readerAnnotationProperty_color"
         app:layout_constraintTop_toBottomOf="@id/seekBar_readerAnnotationProperty_opacity"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
         android:layout_marginTop="16dp"
         android:layout_width="0dp"
-        android:layout_height="wrap_content">
-        <LinearLayout
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:gravity="center"
-            android:orientation="horizontal">
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color1"
-                android:background="@color/reader_annotation_color_1" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color2"
-                android:background="@color/reader_annotation_color_2" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color3"
-                android:background="@color/reader_annotation_color_3" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color4"
-                android:background="@color/reader_annotation_color_4" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color5"
-                android:background="@color/reader_annotation_color_5" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color6"
-                android:background="@color/reader_annotation_color_6" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color7"
-                android:background="@color/reader_annotation_color_7" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color8"
-                android:background="@color/reader_annotation_color_8" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color9"
-                android:background="@color/reader_annotation_color_9" />
-
-            <ImageView
-                style="@style/AnnotationPropertyColorImageView"
-                android:id="@+id/iv_readerAnnotationProperty_color10"
-                android:background="@color/reader_annotation_color_10" />
-        </LinearLayout>
-    </HorizontalScrollView>
+        android:layout_height="wrap_content"/>
 
     <ImageView
         android:id="@+id/iv_readerAnnotationProperty_triangle1"

+ 10 - 10
reader/src/main/res/values/colors.xml

@@ -21,16 +21,16 @@
     <color name="reader_annotation_attribute_seek_bar_tint_disable">@color/black_38</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_color_1">#000000</color>
-    <color name="reader_annotation_color_2">#296dd2</color>
-    <color name="reader_annotation_color_3">#57d214</color>
-    <color name="reader_annotation_color_4">#ffdc1b</color>
-    <color name="reader_annotation_color_5">#ff7e00</color>
-    <color name="reader_annotation_color_6">#fe866a</color>
-    <color name="reader_annotation_color_7">#d11bff</color>
-    <color name="reader_annotation_color_8">#ff1b89</color>
-    <color name="reader_annotation_color_9">#dd0202</color>
-    <color name="reader_annotation_color_10">#ffffff</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>
+    <color name="reader_color_selector_color_4">#ffdc1b</color>
+    <color name="reader_color_selector_color_5">#ff7e00</color>
+    <color name="reader_color_selector_color_6">#fe866a</color>
+    <color name="reader_color_selector_color_7">#d11bff</color>
+    <color name="reader_color_selector_color_8">#ff1b89</color>
+    <color name="reader_color_selector_color_9">#dd0202</color>
+    <color name="reader_color_selector_color_10">#ffffff</color>
 
     <color name="highlight_default_color">#FFFF00</color>
     <color name="strike_default_color">#FF0000</color>

+ 5 - 0
reader/src/main/res/values/styles.xml

@@ -32,4 +32,9 @@
         <item name="android:layout_height">48dp</item>
         <item name="android:textColor">@color/reader_bota_title_color</item>
     </style>
+    <style name="ReaderColorSelectorItemStyle">
+        <item name="android:layout_width">48dp</item>
+        <item name="android:layout_height">48dp</item>
+        <item name="android:padding">6dp</item>
+    </style>
 </resources>