Parcourir la source

Add TitleButton.OnTitleButtonClickListener

cooperku_kdanmobile il y a 5 ans
Parent
commit
31d38689cf

+ 35 - 28
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/ShapeTabView.kt

@@ -9,16 +9,21 @@ import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
-import com.kdanmobile.kmpdfkit.annotation.bean.KMPDFArrowAnnotationBean
-import com.kdanmobile.kmpdfkit.annotation.bean.KMPDFCircleAnnotationBean
-import com.kdanmobile.kmpdfkit.annotation.bean.KMPDFLineAnnotationBean
-import com.kdanmobile.kmpdfkit.annotation.bean.KMPDFSquareAnnotationBean
 import com.kdanmobile.kmpdfkit.globaldata.AnnotConfig
 import com.kdanmobile.reader.R
+import com.kdanmobile.reader.screen.data.ShapeAttribute
+import kotlinx.android.synthetic.main.view_viewer_edit_item_shape_border.view.*
+import kotlinx.android.synthetic.main.view_viewer_edit_item_shape_fill.view.*
 import kotlinx.android.synthetic.main.view_viewer_edit_tab_shape.view.*
 
 class ShapeTabView : ConstraintLayout {
 
+    var onTitleButtonClickListener: TitleButton.OnTitleButtonClickListener? = null
+        set(value) {
+            field = value
+            titleButton_shape?.onTitleButtonClickListener = field
+        }
+
     var shapeType = AnnotConfig.ShapeAnnotationType.CIRCLE
         set(value) {
             field = value
@@ -41,9 +46,12 @@ class ShapeTabView : ConstraintLayout {
                     btn_arrow?.setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN)
                 }
             }
-            println(value.toString())
         }
 
+    private var seekBarShapeBorderOpacity: TextSeekBar? = null
+    private var seekBarShapeBorderThickness: TextSeekBar? = null
+    private var seekBarShapeFillOpacity: TextSeekBar? = null
+
     constructor(context: Context) : super(context) {
         initView()
     }
@@ -59,25 +67,6 @@ class ShapeTabView : ConstraintLayout {
     private fun initView() {
         LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab_shape, this)
 
-        titleButton_shape.onButtonClickListener = OnClickListener { _ ->
-            println("onButtonClick")
-
-            when (shapeType) {
-                AnnotConfig.ShapeAnnotationType.CIRCLE -> {
-
-                }
-                AnnotConfig.ShapeAnnotationType.SQUARE -> {
-
-                }
-                AnnotConfig.ShapeAnnotationType.LINE -> {
-
-                }
-                AnnotConfig.ShapeAnnotationType.ARROW -> {
-
-                }
-            }
-        }
-
         btn_circle.setOnClickListener { _ ->
             shapeType = AnnotConfig.ShapeAnnotationType.CIRCLE
         }
@@ -99,15 +88,33 @@ class ShapeTabView : ConstraintLayout {
         tabLayout.setupWithViewPager(viewPager)
     }
 
-    private class ViewPagerAdapter(context: Context, private val tabs: ArrayList<String>) : PagerAdapter() {
+    private inner class ViewPagerAdapter(context: Context, private val tabs: ArrayList<String>) : PagerAdapter() {
         private val layoutInflater = LayoutInflater.from(context)
 
         override fun instantiateItem(container: ViewGroup, position: Int): Any {
-            val resourceId = when (position) {
-                0 -> R.layout.view_viewer_edit_item_shape_border
-                else -> R.layout.view_viewer_edit_item_shape_fill
+            val resourceId = when (position == 0) {
+                true -> R.layout.view_viewer_edit_item_shape_border
+                false -> R.layout.view_viewer_edit_item_shape_fill
             }
             val view = layoutInflater.inflate(resourceId, container, false)
+            if (position == 0) {
+                seekBarShapeBorderOpacity = view.seekBar_shapeBorder_opacity
+                seekBarShapeBorderThickness = view.seekBar_shapeBorder_thickness
+
+                seekBarShapeBorderOpacity?.formatter = object : TextSeekBar.SeekBarFormatter {
+                    override fun format(value: Int): String {
+                        return Math.round(value / 2.55).toInt().toString()
+                    }
+                }
+            } else {
+                seekBarShapeFillOpacity = view.seekBar_shapeFill_opacity
+
+                seekBarShapeFillOpacity?.formatter = object : TextSeekBar.SeekBarFormatter {
+                    override fun format(value: Int): String {
+                        return Math.round(value / 2.55).toInt().toString()
+                    }
+                }
+            }
             container.addView(view)
             return view
         }

+ 6 - 6
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/StampTabView.kt

@@ -22,6 +22,12 @@ class StampTabView : ConstraintLayout {
     private var selectedCustomStampIndex = 0
     private var selectedStandardStampIndex = 0
 
+    var onTitleButtonClickListener: TitleButton.OnTitleButtonClickListener? = null
+        set(value) {
+            field = value
+            titleButton_stamp?.onTitleButtonClickListener = field
+        }
+
     constructor(context: Context) : super(context) {
         initView()
     }
@@ -37,12 +43,6 @@ class StampTabView : ConstraintLayout {
     private fun initView() {
         LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab_stamp, this)
 
-        titleButton_stamp.onButtonClickListener = OnClickListener { _ ->
-            println("onButtonClick\tpage = ${viewPager.currentItem}\tselectedIndex = ${when(viewPager.currentItem == 0) { true -> selectedCustomStampIndex; false -> selectedStandardStampIndex }}")
-
-
-        }
-
         viewPager.adapter = StampViewPagerAdapter(arrayListOf("Custom", "Standard"))
         tabLayout.setupWithViewPager(viewPager)
     }

+ 27 - 8
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/TextBoxTabView.kt

@@ -1,15 +1,23 @@
 package com.kdanmobile.reader.screen.view.edit
 
 import android.content.Context
+import android.graphics.Typeface
 import android.support.constraint.ConstraintLayout
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.widget.SeekBar
 import com.kdanmobile.reader.R
+import com.kdanmobile.reader.screen.data.TextBoxAttribute
 import kotlinx.android.synthetic.main.view_viewer_edit_tab_text_box.view.*
 
 class TextBoxTabView : ConstraintLayout {
 
+    var onTitleButtonClickListener: TitleButton.OnTitleButtonClickListener? = null
+        set(value) {
+            field = value
+            titleButton_textBox?.onTitleButtonClickListener = field
+        }
+
     constructor(context: Context) : super(context) {
         initView()
     }
@@ -25,33 +33,44 @@ class TextBoxTabView : ConstraintLayout {
     private fun initView() {
         LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab_text_box, this)
 
-        titleButton_textBox.onButtonClickListener = OnClickListener { _ ->
-            println("onButtonClick")
-        }
-
         textAttrView_textBox.onTextAttrClickListener = object : TextAttrView.OnTextAttrClickListener {
+
+            private fun getTypeface(): Int {
+                return when (textAttrView_textBox.isTextBold) {
+                    true -> when (textAttrView_textBox.isTextItalic) {
+                        true -> Typeface.BOLD_ITALIC
+                        false -> Typeface.BOLD
+                    }
+                    false -> when (textAttrView_textBox.isTextItalic) {
+                        true -> Typeface.ITALIC
+                        false -> Typeface.NORMAL
+                    }
+                }
+            }
+
             override fun onBoldClick(isSelected: Boolean) {
-                println("onBoldClick $isSelected")
+                tv_preview.setTypeface(null, getTypeface())
             }
 
             override fun onItalicClick(isSelected: Boolean) {
-                println("onItalicClick $isSelected")
+                tv_preview.setTypeface(null, getTypeface())
             }
 
             override fun onAlignmentClick(gravity: Int) {
-                println("onAlignmentClick $gravity")
+                tv_preview.gravity = gravity
             }
         }
 
         seekBar_textBox_textSize.onSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
             override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
-                println("onProgressChanged $progress")
+//                tv_preview.textSize = seekBar_textBox_textSize.currentValue.toFloat()
             }
 
             override fun onStartTrackingTouch(seekBar: SeekBar) {
             }
 
             override fun onStopTrackingTouch(seekBar: SeekBar) {
+//                tv_preview.textSize = seekBar_textBox_textSize.currentValue.toFloat()
             }
         }
     }

+ 6 - 2
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/TitleButton.kt

@@ -12,10 +12,10 @@ class TitleButton : ConstraintLayout {
     private var title = ""
     private var buttonText = ""
 
-    var onButtonClickListener: OnClickListener? = null
+    var onTitleButtonClickListener: OnTitleButtonClickListener? = null
         set(value) {
             field = value
-            btn_add?.setOnClickListener(value)
+            btn_add?.setOnClickListener{field?.onTitleButtonClick()}
         }
 
     constructor(context: Context) : super(context) {
@@ -44,4 +44,8 @@ class TitleButton : ConstraintLayout {
         tv_title.text = title
         btn_add.text = buttonText
     }
+
+    interface OnTitleButtonClickListener {
+        fun onTitleButtonClick()
+    }
 }

+ 5 - 5
reader/src/main/res/layout/view_viewer_edit_tab_text_box.xml

@@ -30,8 +30,8 @@
         app:layout_constraintTop_toBottomOf="@+id/titleButton_textBox"
         app:layout_constraintBottom_toTopOf="@+id/textAttrView_textBox" >
 
-        <EditText
-            android:id="@+id/et_input"
+        <TextView
+            android:id="@+id/tv_preview"
             style="@style/Base.TextAppearance.Widget.AppCompat.Toolbar.Subtitle"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
@@ -76,9 +76,9 @@
         android:layout_marginTop="16dp"
         app:title="Size"
         app:unit="pt"
-        app:maxValue="24"
-        app:minValue="10"
-        app:initValue="12"
+        app:maxValue="96"
+        app:minValue="8"
+        app:initValue="24"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/colorChooser_textBox" />