Wayne 5 rokov pred
rodič
commit
62d5055bec

+ 22 - 36
reader/src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -13,8 +13,8 @@ import android.support.constraint.ConstraintSet
 import android.widget.Toast
 import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
 import com.kdanmobile.reader.Utils.applyConstraintSet
-import com.kdanmobile.reader.view.AnnotationPropertySettingView
-import com.kdanmobile.reader.view.AnnotationPropertySettingWindow
+import com.kdanmobile.reader.view.AnnotationAttributeView
+import com.kdanmobile.reader.view.AnnotationAttributeWindow
 import android.support.v4.content.ContextCompat
 import android.support.v7.app.AlertDialog
 import android.view.Menu
@@ -428,16 +428,13 @@ abstract class ReaderActivity : AppCompatActivity() {
             setOnLongClickListener { btn ->
                 viewModel.onLongClickHighlightBtn()
                 val context = this@ReaderActivity
-                AnnotationPropertySettingWindow(context, true).also { window ->
+                AnnotationAttributeWindow(context, true).also { window ->
                     viewModel.highLightAttributeLiveData.value?.let { attr ->
-                        window.annotationPropertySettingView.color = attr.color
-                        window.annotationPropertySettingView.alpha = attr.alpha
+                        window.annotationAttributeView.annotationAttribute = attr
                     }
-                    window.annotationPropertySettingView.onPropertyChangeListener = object : AnnotationPropertySettingView.OnPropertyChangeListener {
-                        override fun onPropertyChange(annotationPropertySettingView: AnnotationPropertySettingView) {
-                            val color = annotationPropertySettingView.color
-                            val alpha = annotationPropertySettingView.alpha
-                            viewModel.setHighLightAttributes(color, alpha)
+                    window.annotationAttributeView.onPropertyChangeListener = object : AnnotationAttributeView.OnPropertyChangeListener {
+                        override fun onPropertyChange(annotationAttributeView: AnnotationAttributeView) {
+                            viewModel.setHighLightAttributes(annotationAttributeView.annotationAttribute)
                         }
                     }
                     val contentView = window.contentView.apply {
@@ -458,16 +455,13 @@ abstract class ReaderActivity : AppCompatActivity() {
             setOnLongClickListener { btn ->
                 viewModel.onLongClickStrikeBtn()
                 val context = this@ReaderActivity
-                AnnotationPropertySettingWindow(context, true).also { window ->
+                AnnotationAttributeWindow(context, true).also { window ->
                     viewModel.strikeAttributeLiveData.value?.let { attr ->
-                        window.annotationPropertySettingView.color = attr.color
-                        window.annotationPropertySettingView.alpha = attr.alpha
+                        window.annotationAttributeView.annotationAttribute = attr
                     }
-                    window.annotationPropertySettingView.onPropertyChangeListener = object : AnnotationPropertySettingView.OnPropertyChangeListener {
-                        override fun onPropertyChange(annotationPropertySettingView: AnnotationPropertySettingView) {
-                            val color = annotationPropertySettingView.color
-                            val alpha = annotationPropertySettingView.alpha
-                            viewModel.setStrikeOutAttributes(color, alpha)
+                    window.annotationAttributeView.onPropertyChangeListener = object : AnnotationAttributeView.OnPropertyChangeListener {
+                        override fun onPropertyChange(annotationAttributeView: AnnotationAttributeView) {
+                            viewModel.setStrikeOutAttributes(annotationAttributeView.annotationAttribute)
                         }
                     }
                     val contentView = window.contentView.apply {
@@ -488,16 +482,13 @@ abstract class ReaderActivity : AppCompatActivity() {
             setOnLongClickListener { btn ->
                 viewModel.onLongClickUnderlineBtn()
                 val context = this@ReaderActivity
-                AnnotationPropertySettingWindow(context, true).also { window ->
+                AnnotationAttributeWindow(context, true).also { window ->
                     viewModel.underLineAttributeLiveData.value?.let { attr ->
-                        window.annotationPropertySettingView.color = attr.color
-                        window.annotationPropertySettingView.alpha = attr.alpha
+                        window.annotationAttributeView.annotationAttribute = attr
                     }
-                    window.annotationPropertySettingView.onPropertyChangeListener = object : AnnotationPropertySettingView.OnPropertyChangeListener {
-                        override fun onPropertyChange(annotationPropertySettingView: AnnotationPropertySettingView) {
-                            val color = annotationPropertySettingView.color
-                            val alpha = annotationPropertySettingView.alpha
-                            viewModel.setUnderLineAttributes(color, alpha)
+                    window.annotationAttributeView.onPropertyChangeListener = object : AnnotationAttributeView.OnPropertyChangeListener {
+                        override fun onPropertyChange(annotationAttributeView: AnnotationAttributeView) {
+                            viewModel.setUnderLineAttributes(annotationAttributeView.annotationAttribute)
                         }
                     }
                     val contentView = window.contentView.apply {
@@ -518,18 +509,13 @@ abstract class ReaderActivity : AppCompatActivity() {
             setOnLongClickListener { btn ->
                 viewModel.onLongClickInkBtn()
                 val context = this@ReaderActivity
-                AnnotationPropertySettingWindow(context, false).also { window ->
+                AnnotationAttributeWindow(context, false).also { window ->
                     viewModel.inkAttributeLiveData.value?.let { attr ->
-                        window.annotationPropertySettingView.color = attr.color
-                        window.annotationPropertySettingView.thickness = attr.width.toInt()
-                        window.annotationPropertySettingView.alpha = attr.alpha
+                        window.annotationAttributeView.inkAttribute = attr
                     }
-                    window.annotationPropertySettingView.onPropertyChangeListener = object : AnnotationPropertySettingView.OnPropertyChangeListener {
-                        override fun onPropertyChange(annotationPropertySettingView: AnnotationPropertySettingView) {
-                            val color = annotationPropertySettingView.color
-                            val alpha = annotationPropertySettingView.alpha
-                            val thickness = (annotationPropertySettingView.thickness).toFloat()
-                            viewModel.setInkAttributes(color, alpha, thickness)
+                    window.annotationAttributeView.onPropertyChangeListener = object : AnnotationAttributeView.OnPropertyChangeListener {
+                        override fun onPropertyChange(annotationAttributeView: AnnotationAttributeView) {
+                            viewModel.setInkAttributes(annotationAttributeView.inkAttribute)
                         }
                     }
                     val contentView = window.contentView.apply {

+ 30 - 42
reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -16,6 +16,7 @@ import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
 import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
 import com.kdanmobile.reader.annotationattribute.InkAttribute
 import com.kdanmobile.kmpdfkit.pdfcommon.*
+import com.kdanmobile.reader.annotationattribute.Brush
 import com.kdanmobile.reader.screen.handler.*
 
 class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMsg: String) : ViewModel() {
@@ -35,15 +36,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
     }
 
     companion object {
-        val DEFAULT_HIGHLIGHT_COLOR = Color.parseColor("#ffdc1b")
-        val DEFAULT_STRIKE_COLOR = Color.parseColor("#dd0202")
-        val DEFAULT_UNDERLINE_COLOR = Color.parseColor("#dd0202")
-        val DEFAULT_INK_COLOR = Color.parseColor("#dd0202")
-        const val DEFAULT_HIGHLIGHT_ALPHA = 127
-        const val DEFAULT_STRIKE_ALPHA = 255
-        const val DEFAULT_UNDERLINE_ALPHA = 255
-        const val DEFAULT_INK_ALPHA = 255
-        const val DEFAULT_INK_WIDTH = 1f
+        val DEFAULT_HIGHLIGHT_ATTR = AnnotationAttribute(Color.parseColor("#ffdc1b"), 127)
+        val DEFAULT_STRIKE_ATTR = AnnotationAttribute(Color.parseColor("#dd0202"), 255)
+        val DEFAULT_UNDERLINE_ATTR = AnnotationAttribute(Color.parseColor("#dd0202"), 255)
+        val DEFAULT_INK_ATTR = InkAttribute(Color.parseColor("#dd0202"), 255, 1f, Brush.Fountain)
     }
 
     var viewDirection = ViewDirection.VerticalSinglePageContinues
@@ -56,18 +52,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
             field = value
             updateCrop()
         }
-    val highLightAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply {
-        value = AnnotationAttribute(DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_ALPHA)
-    }
-    val strikeAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply {
-        value = AnnotationAttribute(DEFAULT_STRIKE_COLOR, DEFAULT_STRIKE_ALPHA)
-    }
-    var underLineAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply {
-        value = AnnotationAttribute(DEFAULT_UNDERLINE_COLOR, DEFAULT_UNDERLINE_ALPHA)
-    }
-    var inkAttributeLiveData = MutableLiveData<InkAttribute>().apply {
-        value = InkAttribute(DEFAULT_INK_COLOR, DEFAULT_INK_ALPHA, DEFAULT_INK_WIDTH)
-    }
+    val highLightAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply { value = DEFAULT_HIGHLIGHT_ATTR }
+    val strikeAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply { value = DEFAULT_STRIKE_ATTR }
+    var underLineAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply { value = DEFAULT_UNDERLINE_ATTR }
+    var inkAttributeLiveData = MutableLiveData<InkAttribute>().apply { value = DEFAULT_INK_ATTR }
 
     private var isVerified = false
 
@@ -197,12 +185,12 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         isCopyModeLiveData.postValue(false)
     }
 
-    fun setHighLightAttributes(color: Int, alpha: Int) {
-        highLightAttributeLiveData.postValue(AnnotationAttribute(color, alpha))
-        kmpdfFactory?.setAnnotationAttribute(KMPDFHighlightAnnotationBean("", color, alpha))
+    fun setHighLightAttributes(annotationAttribute: AnnotationAttribute) {
+        highLightAttributeLiveData.postValue(annotationAttribute)
+        kmpdfFactory?.setAnnotationAttribute(KMPDFHighlightAnnotationBean("", annotationAttribute.color, annotationAttribute.alpha))
         kmpdfFactory?.annotConfig?.apply {
-            markerPenColor_hightlight = color
-            markerPenAlpha_hightlight = alpha
+            markerPenColor_hightlight = annotationAttribute.color
+            markerPenAlpha_hightlight = annotationAttribute.alpha
         }
     }
 
@@ -211,12 +199,12 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         annotationModeLiveData.postValue(AnnotationMode.Highlight)
     }
 
-    fun setStrikeOutAttributes(color: Int, alpha: Int) {
-        strikeAttributeLiveData.postValue(AnnotationAttribute(color, alpha))
-        kmpdfFactory?.setAnnotationAttribute(KMPDFStrikeoutAnnotationBean("", color, alpha))
+    fun setStrikeOutAttributes(annotationAttribute: AnnotationAttribute) {
+        strikeAttributeLiveData.postValue(annotationAttribute)
+        kmpdfFactory?.setAnnotationAttribute(KMPDFStrikeoutAnnotationBean("",annotationAttribute.color, annotationAttribute.alpha))
         kmpdfFactory?.annotConfig?.apply {
-            markerPenColor_strikeout = color
-            markerPenAlpha_strikeout = alpha
+            markerPenColor_strikeout = annotationAttribute.color
+            markerPenAlpha_strikeout = annotationAttribute.alpha
         }
     }
 
@@ -225,12 +213,12 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         annotationModeLiveData.postValue(AnnotationMode.Strike)
     }
 
-    fun setUnderLineAttributes(color: Int, alpha: Int) {
-        underLineAttributeLiveData.postValue(AnnotationAttribute(color, alpha))
-        kmpdfFactory?.setAnnotationAttribute(KMPDFUnderlineAnnotationBean("", color, alpha))
+    fun setUnderLineAttributes(annotationAttribute: AnnotationAttribute) {
+        underLineAttributeLiveData.postValue(annotationAttribute)
+        kmpdfFactory?.setAnnotationAttribute(KMPDFUnderlineAnnotationBean("", annotationAttribute.color, annotationAttribute.alpha))
         kmpdfFactory?.annotConfig?.apply {
-            markerPenColor_underline = color
-            markerPenAlpha_underline = alpha
+            markerPenColor_underline = annotationAttribute.color
+            markerPenAlpha_underline = annotationAttribute.alpha
         }
     }
 
@@ -239,14 +227,14 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         annotationModeLiveData.postValue(AnnotationMode.Underline)
     }
 
-    fun setInkAttributes(color: Int, alpha: Int, width: Float) {
-        inkAttributeLiveData.postValue(InkAttribute(color, alpha, width))
+    fun setInkAttributes(inkAttribute: InkAttribute) {
+        inkAttributeLiveData.postValue(inkAttribute)
         kmpdfFactory?.apply {
-            setAnnotationAttribute(KMPDFInkAnnotationBean("", color, width, alpha))
+            setAnnotationAttribute(KMPDFInkAnnotationBean("", inkAttribute.color, inkAttribute.width, inkAttribute.alpha))
             annotConfig?.apply {
-                markerPenColor_ink = color
-                markerPenAlpha_ink = alpha
-                markerPenSize_ink = width
+                markerPenColor_ink = inkAttribute.color
+                markerPenAlpha_ink = inkAttribute.alpha
+                markerPenSize_ink = inkAttribute.width
             }
         }
     }

+ 6 - 0
reader/src/main/java/com/kdanmobile/reader/annotationattribute/Brush.kt

@@ -0,0 +1,6 @@
+package com.kdanmobile.reader.annotationattribute
+
+enum class Brush(val size: Int) {
+    Fountain(5),
+    Marker(16),
+}

+ 2 - 2
reader/src/main/java/com/kdanmobile/reader/annotationattribute/InkAttribute.kt

@@ -1,9 +1,9 @@
 package com.kdanmobile.reader.annotationattribute
 
 import android.support.annotation.IntRange
-import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
 
 data class InkAttribute(
         override var color: Int,
         @IntRange(from = 0, to = 255) override var alpha: Int,
-        var width: Float) : AnnotationAttribute(color, alpha)
+        var width: Float,
+        var brush: Brush) : AnnotationAttribute(color, alpha)

+ 31 - 18
reader/src/main/java/com/kdanmobile/reader/view/AnnotationPropertySettingView.kt

@@ -1,7 +1,6 @@
 package com.kdanmobile.reader.view
 
 import android.content.Context
-import android.support.annotation.IntRange
 import android.support.v4.graphics.ColorUtils
 import android.util.AttributeSet
 import android.view.View
@@ -12,26 +11,22 @@ import android.widget.PopupWindow
 import android.widget.SeekBar
 import com.kdanmobile.reader.R
 import com.kdanmobile.reader.Utils
+import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
+import com.kdanmobile.reader.annotationattribute.Brush
+import com.kdanmobile.reader.annotationattribute.InkAttribute
 import kotlinx.android.synthetic.main.view_reader_annotation_property.view.*
 
-class AnnotationPropertySettingView @JvmOverloads constructor(
+class AnnotationAttributeView @JvmOverloads constructor(
         context: Context,
         attrs: AttributeSet? = null,
         defStyleAttr: Int = 0
 ) : LinearLayout(context, attrs, defStyleAttr) {
 
     companion object {
-        const val BRUSH_DEFAULT_THICKNESS_FOUNTAIN = 5
-        const val BRUSH_DEFAULT_THICKNESS_MARKER = 16
         const val DEFAULT_OPACITY = 50
         const val DEFAULT_THICKNESS = 5
     }
 
-    enum class Brush(val size: Int) {
-        Fountain(BRUSH_DEFAULT_THICKNESS_FOUNTAIN),
-        Marker(BRUSH_DEFAULT_THICKNESS_MARKER),
-    }
-
     private enum class Color(val colorResId: Int) {
         Color1(R.color.reader_annotation_color_1),
         Color2(R.color.reader_annotation_color_2),
@@ -48,6 +43,24 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
     init {
         inflate(context, R.layout.view_reader_annotation_property, this)
     }
+    var inkAttribute: InkAttribute
+        get() {
+            return InkAttribute(color, alpha, thickness.toFloat(), brush)
+        }
+        set(value) {
+            color = value.color
+            alpha = value.alpha
+            thickness = value.width.toInt()
+            brush = value.brush
+        }
+    var annotationAttribute: AnnotationAttribute
+        get() {
+            return AnnotationAttribute(color, alpha)
+        }
+        set(value) {
+            color = value.color
+            alpha = value.alpha
+        }
     var isSimpleMode = true
         set(value) {
             field = value
@@ -66,7 +79,7 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
         put(Color.Color9, iv_readerAnnotationProperty_color9)
         put(Color.Color10, iv_readerAnnotationProperty_color10)
     }
-    var thickness: Int = DEFAULT_THICKNESS
+    private var thickness: Int = DEFAULT_THICKNESS
         set(value) {
             field = value
             updateThickness()
@@ -74,7 +87,7 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
     /**
      * 1~255
      */
-    var alpha: Int
+    private var alpha: Int
         get() {
             return Math.round(opacity.toFloat() / 100 * 255)
         }
@@ -85,9 +98,9 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
     /**
      * 1~100
      */
-    var opacity: Int = DEFAULT_OPACITY
+    private var opacity: Int = DEFAULT_OPACITY
         private set
-    var color: Int
+    private var color: Int
         get() {
             return context.resources.getColor(colorEnum.colorResId)
         }
@@ -107,11 +120,11 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
             updateColorButtons()
             onPropertyChangeListener?.onPropertyChange(this)
         }
-    val colorWithAlpha: Int
+    private val colorWithAlpha: Int
         get() {
             return  ColorUtils.setAlphaComponent(color, alpha)
         }
-    var brush = Brush.Fountain
+    private var brush = Brush.Fountain
         set(value) {
             if (field == value) return
             field = value
@@ -146,7 +159,7 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
             }
 
             override fun onStopTrackingTouch(p0: SeekBar?) {
-                onPropertyChangeListener?.onPropertyChange(this@AnnotationPropertySettingView)
+                onPropertyChangeListener?.onPropertyChange(this@AnnotationAttributeView)
             }
         })
     }
@@ -189,7 +202,7 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
 
             override fun onStopTrackingTouch(p0: SeekBar?) {
                 window.dismiss()
-                onPropertyChangeListener?.onPropertyChange(this@AnnotationPropertySettingView)
+                onPropertyChangeListener?.onPropertyChange(this@AnnotationAttributeView)
             }
 
             private fun calculateOffsetX(seekBar: SeekBar): Int {
@@ -260,6 +273,6 @@ class AnnotationPropertySettingView @JvmOverloads constructor(
     }
 
     interface OnPropertyChangeListener {
-        fun onPropertyChange(annotationPropertySettingView: AnnotationPropertySettingView)
+        fun onPropertyChange(annotationAttributeView: AnnotationAttributeView)
     }
 }

+ 5 - 6
reader/src/main/java/com/kdanmobile/reader/view/AnnotationPropertySettingWindow.kt

@@ -3,11 +3,10 @@ package com.kdanmobile.reader.view
 import android.content.Context
 import android.os.Build
 import android.widget.PopupWindow
-import com.kdanmobile.reader.BuildConfig
 import com.kdanmobile.reader.R
 
-class AnnotationPropertySettingWindow(context: Context, isSimpleMode: Boolean) : PopupWindow(context) {
-    val annotationPropertySettingView: AnnotationPropertySettingView
+class AnnotationAttributeWindow(context: Context, isSimpleMode: Boolean) : PopupWindow(context) {
+    val annotationAttributeView: AnnotationAttributeView
 
     init {
         isOutsideTouchable = true
@@ -16,8 +15,8 @@ class AnnotationPropertySettingWindow(context: Context, isSimpleMode: Boolean) :
             elevation = context.resources.getDimension(R.dimen.reader_annotation_property_setting_window_elevation)
         }
         setBackgroundDrawable(context.resources.getDrawable(R.drawable.bg_annotation_property_setting_window))
-        annotationPropertySettingView = AnnotationPropertySettingView(context)
-        annotationPropertySettingView.isSimpleMode = isSimpleMode
-        contentView = annotationPropertySettingView
+        annotationAttributeView = AnnotationAttributeView(context)
+        annotationAttributeView.isSimpleMode = isSimpleMode
+        contentView = annotationAttributeView
     }
 }