@@ -10,6 +10,7 @@ import android.view.ViewPropertyAnimator
10
10
import android.view.animation.AccelerateDecelerateInterpolator
11
11
import android.view.animation.Interpolator
12
12
import android.widget.Button
13
+ import android.widget.Toast
13
14
import androidx.appcompat.app.AppCompatActivity
14
15
import androidx.dynamicanimation.animation.DynamicAnimation
15
16
import androidx.dynamicanimation.animation.SpringAnimation
@@ -133,6 +134,21 @@ class Activity3_5ElasticScale : AppCompatActivity() {
133
134
134
135
fab.setElasticTouchListener(duration = 300 )
135
136
137
+ fab.setOnClickListener {
138
+ Toast .makeText(applicationContext, " TOAST" , Toast .LENGTH_SHORT ).show()
139
+ }
140
+
141
+ }
142
+ }
143
+
144
+ fun View.setElasticOnClickListener (
145
+ grow : Boolean = false,
146
+ scaleBy : Float = 0.1f,
147
+ duration : Long = 200,
148
+ interpolator : Interpolator = LinearOutSlowInInterpolator ()
149
+ ) {
150
+ setOnClickListener {
151
+ elasticAnimation(grow, scaleBy, duration, interpolator)
136
152
}
137
153
}
138
154
@@ -175,12 +191,12 @@ fun View.elasticAnimation(
175
191
scaleY = initialScaleY
176
192
viewPropertyAnimator.setListener(null )
177
193
}
178
-
179
194
})
180
195
}
181
196
182
197
@SuppressLint(" ClickableViewAccessibility" )
183
198
fun View.setElasticTouchListener (
199
+ onTouchStart : (() -> Unit )? = null,
184
200
grow : Boolean = false,
185
201
scaleBy : Float = 0.1f,
186
202
duration : Long = 200,
@@ -209,6 +225,8 @@ fun View.setElasticTouchListener(
209
225
210
226
MotionEvent .ACTION_DOWN -> {
211
227
228
+ onTouchStart?.invoke()
229
+
212
230
startPropertyAnimator = animate()
213
231
214
232
startPropertyAnimator
@@ -247,7 +265,6 @@ fun View.setElasticTouchListener(
247
265
})
248
266
}
249
267
}
250
-
251
- true
268
+ false
252
269
}
253
270
}
0 commit comments