|
@@ -1,43 +1,146 @@
|
|
package com.kdanmobile.reader.screen.view
|
|
package com.kdanmobile.reader.screen.view
|
|
|
|
|
|
|
|
+import android.animation.*
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
|
+import android.graphics.Color
|
|
import android.support.constraint.ConstraintLayout
|
|
import android.support.constraint.ConstraintLayout
|
|
import android.support.v4.content.ContextCompat
|
|
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.view.View.OnClickListener
|
|
|
|
+import android.view.animation.AccelerateDecelerateInterpolator
|
|
import android.widget.ImageButton
|
|
import android.widget.ImageButton
|
|
import com.kdanmobile.reader.R
|
|
import com.kdanmobile.reader.R
|
|
import com.kdanmobile.reader.screen.view.edit.*
|
|
import com.kdanmobile.reader.screen.view.edit.*
|
|
import kotlinx.android.synthetic.main.view_viewer_edit.view.*
|
|
import kotlinx.android.synthetic.main.view_viewer_edit.view.*
|
|
import kotlinx.android.synthetic.main.view_viewer_edit_tab.view.*
|
|
import kotlinx.android.synthetic.main.view_viewer_edit_tab.view.*
|
|
|
|
|
|
-class ViewerEditView : ConstraintLayout {
|
|
|
|
|
|
+class ViewerEditView @JvmOverloads constructor(
|
|
|
|
+ context: Context,
|
|
|
|
+ attrs: AttributeSet? = null,
|
|
|
|
+ defStyleAttr: Int = 0
|
|
|
|
+): ConstraintLayout(context, attrs, defStyleAttr) {
|
|
|
|
+
|
|
|
|
+ private companion object {
|
|
|
|
+ const val COLOR_DISMISS = Color.TRANSPARENT
|
|
|
|
+ val COLOR_SHOW = Color.parseColor("#42000000")
|
|
|
|
+ const val DEFAULT_DURATION_ANIMATION = 300L
|
|
|
|
+ }
|
|
|
|
|
|
private enum class ViewerEditTabType {
|
|
private enum class ViewerEditTabType {
|
|
NONE, TEXT_BOX, SIGNATURE, STAMP, SHAPE, FORM
|
|
NONE, TEXT_BOX, SIGNATURE, STAMP, SHAPE, FORM
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var onShowListener: Runnable? = null
|
|
|
|
+ var onDismissListener: Runnable? = null
|
|
|
|
+ var animationDuration = DEFAULT_DURATION_ANIMATION
|
|
|
|
+
|
|
|
|
+ private var mediaBoxAnimator: ObjectAnimator? = null
|
|
|
|
+ private var maskAnimator: ValueAnimator? = null
|
|
private var tabType = ViewerEditTabType.NONE
|
|
private var tabType = ViewerEditTabType.NONE
|
|
private var selected: ImageButton? = null
|
|
private var selected: ImageButton? = null
|
|
var onViewerEditTabAddButtonClickListener: OnViewerEditTabAddButtonClickListener? = null
|
|
var onViewerEditTabAddButtonClickListener: OnViewerEditTabAddButtonClickListener? = null
|
|
|
|
|
|
- constructor(context: Context) : super(context) {
|
|
|
|
- initView()
|
|
|
|
|
|
+ init {
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.view_viewer_edit, this)
|
|
|
|
+ visibility = View.INVISIBLE
|
|
|
|
+ setupTabView()
|
|
|
|
+
|
|
|
|
+ /** Set empty listener to prevent dismissing by clicking box **/
|
|
|
|
+ view_viewEdit_content.setOnClickListener {}
|
|
|
|
+
|
|
|
|
+ /** Move media box view to bottom of parent(hide it) **/
|
|
|
|
+ val size = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
|
|
|
+ val v = view_viewEdit_content
|
|
|
|
+ v.measure(size, size)
|
|
|
|
+ v.y = v.top + v.measuredHeight.toFloat()
|
|
}
|
|
}
|
|
|
|
|
|
- constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
|
|
|
- initView()
|
|
|
|
|
|
+ fun show() {
|
|
|
|
+ visibility = View.VISIBLE
|
|
|
|
+ setOnClickListener { dismiss() }
|
|
|
|
+ post {
|
|
|
|
+ showMaskWithAnimation()
|
|
|
|
+ showMediaBoxWithAnimation()
|
|
|
|
+ }
|
|
|
|
+ onShowListener?.run()
|
|
}
|
|
}
|
|
|
|
|
|
- constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
|
|
|
|
- initView()
|
|
|
|
|
|
+ fun dismiss() {
|
|
|
|
+ setOnClickListener(null)
|
|
|
|
+ hideMaskWithAnimation()
|
|
|
|
+ hideMediaBoxWithAnimation()
|
|
|
|
+ onDismissListener?.run()
|
|
}
|
|
}
|
|
|
|
|
|
- private fun initView() {
|
|
|
|
- LayoutInflater.from(context).inflate(R.layout.view_viewer_edit, this)
|
|
|
|
|
|
+ private fun showMaskWithAnimation() {
|
|
|
|
+ maskAnimator?.cancel()
|
|
|
|
+ val from = maskAnimator?.animatedValue ?: COLOR_DISMISS
|
|
|
|
+ val to = COLOR_SHOW
|
|
|
|
+ maskAnimator = ValueAnimator.ofObject(ArgbEvaluator(), from, to).apply {
|
|
|
|
+ duration = DEFAULT_DURATION_ANIMATION
|
|
|
|
+ interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
+ addUpdateListener {
|
|
|
|
+ setBackgroundColor(it.animatedValue as Int)
|
|
|
|
+ }
|
|
|
|
+ start()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- setupTabView()
|
|
|
|
|
|
+ private fun hideMaskWithAnimation() {
|
|
|
|
+ maskAnimator?.cancel()
|
|
|
|
+ val from = maskAnimator?.animatedValue ?: COLOR_SHOW
|
|
|
|
+ val to = COLOR_DISMISS
|
|
|
|
+ maskAnimator = ValueAnimator.ofObject(ArgbEvaluator(), from, to).apply {
|
|
|
|
+ duration = DEFAULT_DURATION_ANIMATION
|
|
|
|
+ interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
+ addUpdateListener {
|
|
|
|
+ setBackgroundColor(it.animatedValue as Int)
|
|
|
|
+ }
|
|
|
|
+ start()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun showMediaBoxWithAnimation() {
|
|
|
|
+ mediaBoxAnimator?.cancel()
|
|
|
|
+ val v = view_viewEdit_content
|
|
|
|
+ v.visibility = View.VISIBLE
|
|
|
|
+ val from = v.y
|
|
|
|
+ val to = v.top.toFloat()
|
|
|
|
+ val holder = PropertyValuesHolder.ofFloat("Y", from, to)
|
|
|
|
+ mediaBoxAnimator = ObjectAnimator.ofPropertyValuesHolder(v, holder).apply {
|
|
|
|
+ interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
+ duration = animationDuration
|
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
|
+ override fun onAnimationEnd(animation: Animator?) {
|
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
|
+ removeListener(this)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ start()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun hideMediaBoxWithAnimation() {
|
|
|
|
+ mediaBoxAnimator?.cancel()
|
|
|
|
+ val v = view_viewEdit_content
|
|
|
|
+ val from = v.y
|
|
|
|
+ val to = v.top.toFloat() + v.height
|
|
|
|
+ val holder = PropertyValuesHolder.ofFloat("Y", from, to)
|
|
|
|
+ mediaBoxAnimator = ObjectAnimator.ofPropertyValuesHolder(v, holder).apply {
|
|
|
|
+ interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
+ duration = animationDuration
|
|
|
|
+ addListener(object : AnimatorListenerAdapter() {
|
|
|
|
+ override fun onAnimationEnd(animation: Animator?) {
|
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
|
+ removeListener(this)
|
|
|
|
+ v.visibility = View.INVISIBLE
|
|
|
|
+ this@ViewerEditView.visibility = View.GONE
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ start()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private fun setupTabView() {
|
|
private fun setupTabView() {
|