Skip to content

Commit f5999f5

Browse files
committed
disableClickOnLoading 实现方式修改
1 parent f5a9087 commit f5999f5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Loadingbutton/src/main/java/com/flod/loadingbutton/LoadingButton.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.animation.AnimatorListenerAdapter;
55
import android.animation.ObjectAnimator;
66
import android.animation.ValueAnimator;
7+
import android.annotation.SuppressLint;
78
import android.content.Context;
89
import android.content.res.TypedArray;
910
import android.graphics.Bitmap;
@@ -13,6 +14,7 @@
1314
import android.graphics.Rect;
1415
import android.graphics.drawable.Drawable;
1516
import android.util.AttributeSet;
17+
import android.view.MotionEvent;
1618
import android.view.View;
1719

1820
import androidx.annotation.ColorInt;
@@ -28,7 +30,7 @@
2830
* Creator: Flood
2931
* Date: 2019-06-13
3032
* UseDes:
31-
*
33+
* <p>
3234
* 1、改变loading的大小 √
3335
* 2、收缩动画后不居中 √
3436
* 3、收缩后的大小随loading的大小决定 √
@@ -46,6 +48,7 @@
4648
@SuppressWarnings({"UnusedReturnValue,SameParameterValue", "unused"})
4749
public class LoadingButton extends DrawableTextView {
4850
private int curStatus = STATE.IDE; //当前的状态
51+
4952
interface STATE {
5053
int IDE = 0;
5154
int SHRINKING = 1;
@@ -134,6 +137,8 @@ private void init(Context context, AttributeSet attrs) {
134137

135138
}
136139

140+
141+
137142
/**
138143
* 设置收缩动画,主要用来收缩和恢复布局的宽度,动画开始前会保存一些收缩前的参数(文字,其他Drawable等)
139144
*/
@@ -240,9 +245,6 @@ private void restoreStatus() {
240245
getLayoutParams().width = mRootViewSizeSaved[0];
241246
getLayoutParams().height = mRootViewSizeSaved[1];
242247
requestLayout();
243-
if (disableClickOnLoading) {
244-
super.setEnabled(true);
245-
}
246248

247249
addOnLayoutChangeListener(new OnLayoutChangeListener() {
248250
@Override
@@ -256,6 +258,21 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
256258
}
257259

258260

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+
259276
/**
260277
* 开始收缩或恢复
261278
*
@@ -349,9 +366,9 @@ private void cancelAllRunning(boolean withAnim) {
349366
*/
350367
public void start() {
351368
//disable click
352-
if (disableClickOnLoading) {
369+
/*if (disableClickOnLoading) {
353370
super.setEnabled(false);
354-
}
371+
}*/
355372

356373
//cancel last loading
357374
if (curStatus == STATE.SHRINKING || curStatus == STATE.LOADING)

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
app:enableShrink="true"
3131
app:endCompleteDrawable="@drawable/ic_successful"
3232
app:endFailDrawable="@drawable/ic_fail"
33-
app:loadingDrawablePosition="Start"
34-
app/>
33+
app:loadingDrawablePosition="Start" />
3534

3635
<RelativeLayout
3736
android:layout_width="match_parent"

0 commit comments

Comments
 (0)