|
@@ -2,14 +2,26 @@ package com.kdanmobile.reader.screen.view
|
|
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.support.constraint.ConstraintLayout
|
|
import android.support.constraint.ConstraintLayout
|
|
|
|
+import android.support.v4.content.ContextCompat
|
|
import android.util.AttributeSet
|
|
import android.util.AttributeSet
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
|
|
+import android.widget.ImageButton
|
|
import com.kdanmobile.reader.R
|
|
import com.kdanmobile.reader.R
|
|
|
|
+import com.kdanmobile.reader.screen.view.edit.TextBoxTabView
|
|
import kotlinx.android.synthetic.main.view_viewer_edit.view.*
|
|
import kotlinx.android.synthetic.main.view_viewer_edit.view.*
|
|
|
|
|
|
class ViewerEditView : ConstraintLayout {
|
|
class ViewerEditView : ConstraintLayout {
|
|
|
|
|
|
|
|
+ private enum class ViewerEditTabType {
|
|
|
|
+ NONE, TEXT_BOX, SIGNATURE, STAMP, SHAPE, FORM
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private var tabType = ViewerEditTabType.NONE
|
|
|
|
+ private var selected: ImageButton? = null
|
|
|
|
+
|
|
|
|
+// private val selectedColor = ContextCompat.getColor(context, R.color.reader_viewer_edit_tab_color_selected)
|
|
|
|
+
|
|
constructor(context: Context) : super(context) {
|
|
constructor(context: Context) : super(context) {
|
|
initView()
|
|
initView()
|
|
}
|
|
}
|
|
@@ -30,9 +42,84 @@ class ViewerEditView : ConstraintLayout {
|
|
|
|
|
|
private fun setupTabView() {
|
|
private fun setupTabView() {
|
|
viewerEdit_tab.onClickListenerTabTextBox = OnClickListener(this::setupTextBoxView)
|
|
viewerEdit_tab.onClickListenerTabTextBox = OnClickListener(this::setupTextBoxView)
|
|
|
|
+ viewerEdit_tab.onClickListenerTabSignature = OnClickListener(this::setupSignatureView)
|
|
|
|
+ viewerEdit_tab.onClickListenerTabStamp = OnClickListener(this::setupStampView)
|
|
|
|
+ viewerEdit_tab.onClickListenerTabShape = OnClickListener(this::setupShapeView)
|
|
|
|
+ viewerEdit_tab.onClickListenerTabForm = OnClickListener(this::setupFormView)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun getButtonDrawable(tabType: ViewerEditTabType, isSelected: Boolean): Int {
|
|
|
|
+ when (tabType) {
|
|
|
|
+ ViewerEditTabType.NONE, ViewerEditTabType.TEXT_BOX ->
|
|
|
|
+ return if (isSelected) R.drawable.ic_textbox_selected else R.drawable.ic_textbox
|
|
|
|
+ ViewerEditTabType.SIGNATURE ->
|
|
|
|
+ return if (isSelected) R.drawable.ic_signature_selected else R.drawable.ic_signature
|
|
|
|
+ ViewerEditTabType.STAMP ->
|
|
|
|
+ return if (isSelected) R.drawable.ic_stamp_selected else R.drawable.ic_stamp
|
|
|
|
+ ViewerEditTabType.SHAPE ->
|
|
|
|
+ return if (isSelected) R.drawable.ic_shape_selected else R.drawable.ic_shape
|
|
|
|
+ ViewerEditTabType.FORM ->
|
|
|
|
+ return if (isSelected) R.drawable.ic_form_selected else R.drawable.ic_form
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupContent(button: ImageButton, tabType: ViewerEditTabType): Boolean {
|
|
|
|
+ var changed = false
|
|
|
|
+ if (this.tabType != tabType) {
|
|
|
|
+ selected?.setImageDrawable(ContextCompat.getDrawable(context, getButtonDrawable(this.tabType, false)))
|
|
|
|
+ this.tabType = tabType
|
|
|
|
+// selected?.clearColorFilter()
|
|
|
|
+ selected = button
|
|
|
|
+ button.setImageDrawable(ContextCompat.getDrawable(context, getButtonDrawable(this.tabType, true)))
|
|
|
|
+// button.drawable.setColorFilter(selectedColor, PorterDuff.Mode.SRC_IN)
|
|
|
|
+// button.setColorFilter(selectedColor, PorterDuff.Mode.SRC_IN)
|
|
|
|
+// button.setColorFilter(Color.BLACK, PorterDuff.Mode.SCREEN)
|
|
|
|
+
|
|
|
|
+ viewEdit_layout_tab_content.removeAllViews()
|
|
|
|
+ changed = true
|
|
|
|
+ }
|
|
|
|
+ return changed
|
|
}
|
|
}
|
|
|
|
|
|
private fun setupTextBoxView(view: View) {
|
|
private fun setupTextBoxView(view: View) {
|
|
//TODO implements tab view and add to viewEdit_layout_tab_content
|
|
//TODO implements tab view and add to viewEdit_layout_tab_content
|
|
|
|
+ val changed = setupContent(view as ImageButton, ViewerEditTabType.TEXT_BOX)
|
|
|
|
+ if (changed) {
|
|
|
|
+ val textBoxTabView = TextBoxTabView(context)
|
|
|
|
+ val params = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT)
|
|
|
|
+ viewEdit_layout_tab_content.addView(textBoxTabView, params)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupSignatureView(view: View) {
|
|
|
|
+ //TODO implements tab view and add to viewEdit_layout_tab_content
|
|
|
|
+ val changed = setupContent(view as ImageButton, ViewerEditTabType.SIGNATURE)
|
|
|
|
+ if (changed) {
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab, viewEdit_layout_tab_content)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupStampView(view: View) {
|
|
|
|
+ //TODO implements tab view and add to viewEdit_layout_tab_content
|
|
|
|
+ val changed = setupContent(view as ImageButton, ViewerEditTabType.STAMP)
|
|
|
|
+ if (changed) {
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab, viewEdit_layout_tab_content)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupShapeView(view: View) {
|
|
|
|
+ //TODO implements tab view and add to viewEdit_layout_tab_content
|
|
|
|
+ val changed = setupContent(view as ImageButton, ViewerEditTabType.SHAPE)
|
|
|
|
+ if (changed) {
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab, viewEdit_layout_tab_content)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupFormView(view: View) {
|
|
|
|
+//TODO implements tab view and add to viewEdit_layout_tab_content
|
|
|
|
+ val changed = setupContent(view as ImageButton, ViewerEditTabType.FORM)
|
|
|
|
+ if (changed) {
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab, viewEdit_layout_tab_content)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|