4
4
import android .animation .AnimatorListenerAdapter ;
5
5
import android .animation .ObjectAnimator ;
6
6
import android .animation .ValueAnimator ;
7
+ import android .annotation .SuppressLint ;
7
8
import android .content .Context ;
8
9
import android .content .res .TypedArray ;
9
10
import android .graphics .Bitmap ;
20
21
import android .support .v4 .content .ContextCompat ;
21
22
import android .support .v4 .widget .CircularProgressDrawable ;
22
23
import android .util .AttributeSet ;
24
+ import android .view .MotionEvent ;
23
25
import android .view .View ;
24
26
25
27
46
48
@ SuppressWarnings ({"UnusedReturnValue,SameParameterValue" , "unused" })
47
49
public class LoadingButton extends DrawableTextView {
48
50
private int curStatus = STATE .IDE ; //当前的状态
51
+
49
52
interface STATE {
50
53
int IDE = 0 ;
51
54
int SHRINKING = 1 ;
@@ -134,6 +137,8 @@ private void init(Context context, AttributeSet attrs) {
134
137
135
138
}
136
139
140
+
141
+
137
142
/**
138
143
* 设置收缩动画,主要用来收缩和恢复布局的宽度,动画开始前会保存一些收缩前的参数(文字,其他Drawable等)
139
144
*/
@@ -240,9 +245,6 @@ private void restoreStatus() {
240
245
getLayoutParams ().width = mRootViewSizeSaved [0 ];
241
246
getLayoutParams ().height = mRootViewSizeSaved [1 ];
242
247
requestLayout ();
243
- if (disableClickOnLoading ) {
244
- super .setEnabled (true );
245
- }
246
248
247
249
addOnLayoutChangeListener (new OnLayoutChangeListener () {
248
250
@ Override
@@ -256,6 +258,21 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
256
258
}
257
259
258
260
261
+ /**
262
+ * 如果disableClickOnLoading==true,点击会无效
263
+ */
264
+ @ SuppressLint ("ClickableViewAccessibility" )
265
+ @ Override
266
+ public boolean onTouchEvent (MotionEvent event ) {
267
+ if (event .getAction () == MotionEvent .ACTION_UP ) {
268
+ //disable click
269
+ if (disableClickOnLoading && curStatus != STATE .IDE )
270
+ return true ;
271
+ }
272
+ return super .onTouchEvent (event );
273
+ }
274
+
275
+
259
276
/**
260
277
* 开始收缩或恢复
261
278
*
@@ -348,11 +365,6 @@ private void cancelAllRunning(boolean withAnim) {
348
365
* shrink -> startLoading
349
366
*/
350
367
public void start () {
351
- //disable click
352
- if (disableClickOnLoading ) {
353
- super .setEnabled (false );
354
- }
355
-
356
368
//cancel last loading
357
369
if (curStatus == STATE .SHRINKING || curStatus == STATE .LOADING )
358
370
isCancel = true ;
0 commit comments