|
@@ -0,0 +1,87 @@
|
|
1
|
+package com.xhly.manageapp.customview
|
|
2
|
+
|
|
3
|
+import android.annotation.SuppressLint
|
|
4
|
+import android.content.Context
|
|
5
|
+import android.graphics.drawable.Drawable
|
|
6
|
+import android.util.AttributeSet
|
|
7
|
+import android.view.LayoutInflater
|
|
8
|
+import android.view.MotionEvent
|
|
9
|
+import android.view.View
|
|
10
|
+import android.widget.FrameLayout
|
|
11
|
+import android.widget.ImageView
|
|
12
|
+import android.widget.LinearLayout
|
|
13
|
+import android.widget.TextView
|
|
14
|
+import com.xhly.manageapp.R
|
|
15
|
+
|
|
16
|
+class CombinationCardView : FrameLayout {
|
|
17
|
+ private var cv: LinearLayout
|
|
18
|
+ private var root: View
|
|
19
|
+ private var iv: ImageView
|
|
20
|
+ private var tv:TextView
|
|
21
|
+ private var x = 0f
|
|
22
|
+ private var y = 0f
|
|
23
|
+ private var listener: OnClickListener?=null
|
|
24
|
+ constructor(mContext: Context) : this(mContext, null)
|
|
25
|
+
|
|
26
|
+ constructor(mContext: Context, mAttributeSet: AttributeSet?) : this(mContext, mAttributeSet, 0)
|
|
27
|
+ constructor(
|
|
28
|
+ mContext: Context,
|
|
29
|
+ mAttributeSet: AttributeSet?,
|
|
30
|
+ defStyleAttr: Int
|
|
31
|
+ ) : super(mContext, mAttributeSet, defStyleAttr) {
|
|
32
|
+ root= LayoutInflater.from(mContext).inflate(R.layout.btncardview, this)
|
|
33
|
+ cv =root.findViewById(R.id.llayout_cv)
|
|
34
|
+ iv =root.findViewById(R.id.iv)
|
|
35
|
+ tv=root.findViewById(R.id.tv)
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
40
|
+ override fun onTouchEvent(event: MotionEvent?): Boolean {
|
|
41
|
+
|
|
42
|
+ when (event!!.action) {
|
|
43
|
+ MotionEvent.ACTION_DOWN -> {
|
|
44
|
+ x = event!!.x
|
|
45
|
+ y = event!!.y
|
|
46
|
+ cv.animate().scaleX(0.93f).scaleY(0.93f).setDuration(500).start()
|
|
47
|
+ changeState(0)
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ MotionEvent.ACTION_UP -> {
|
|
51
|
+ cv.postDelayed({
|
|
52
|
+ cv.animate().scaleX(1f).scaleY(1f).setDuration(500).start()
|
|
53
|
+ changeState(1)
|
|
54
|
+ },120)
|
|
55
|
+ listener?.let {
|
|
56
|
+ it.onClick(root)
|
|
57
|
+ }
|
|
58
|
+ }
|
|
59
|
+ MotionEvent.ACTION_CANCEL->{
|
|
60
|
+ cv.animate().scaleX(1f).scaleY(1f).setDuration(500).start()
|
|
61
|
+ changeState(1)
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+ return true
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ override fun setOnClickListener(l: OnClickListener?) {
|
|
68
|
+ this.listener=l
|
|
69
|
+ super.setOnClickListener(l)
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+ private fun changeState(states:Int) {
|
|
74
|
+ if (states == 0) {
|
|
75
|
+ //iv.visibility = View.INVISIBLE
|
|
76
|
+ } else {
|
|
77
|
+ //iv.visibility = View.INVISIBLE
|
|
78
|
+ }
|
|
79
|
+ }
|
|
80
|
+ fun setText(s:String){
|
|
81
|
+ tv.text = s
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ fun setImageDrawable(drawable:Drawable){
|
|
85
|
+ iv.setImageDrawable(drawable)
|
|
86
|
+ }
|
|
87
|
+}
|