Skip to content

Commit 67f087c

Browse files
committed
disableClickOnLoading 实现方式修改
1 parent 484b8bd commit 67f087c

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 20 additions & 8 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;
@@ -20,6 +21,7 @@
2021
import android.support.v4.content.ContextCompat;
2122
import android.support.v4.widget.CircularProgressDrawable;
2223
import android.util.AttributeSet;
24+
import android.view.MotionEvent;
2325
import android.view.View;
2426

2527

@@ -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
*
@@ -348,11 +365,6 @@ private void cancelAllRunning(boolean withAnim) {
348365
* shrink -> startLoading
349366
*/
350367
public void start() {
351-
//disable click
352-
if (disableClickOnLoading) {
353-
super.setEnabled(false);
354-
}
355-
356368
//cancel last loading
357369
if (curStatus == STATE.SHRINKING || curStatus == STATE.LOADING)
358370
isCancel = true;

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
dependencies {
2525
//Androidx
26-
implementation 'com.github.FlodCoding:LoadingButton:1.0.0-alpha1'
26+
implementation 'com.github.FlodCoding:LoadingButton:1.0.0-alpha2'
2727

2828
//Support-appcompat
29-
implementation 'com.github.FlodCoding:LoadingButton:1.0.0-alpha1-support'
29+
implementation 'com.github.FlodCoding:LoadingButton:1.0.0-alpha2-support'
3030
}
3131

3232

0 commit comments

Comments
 (0)