Skip to content

Commit 71e69e2

Browse files
committed
see 01/16 log
1 parent f154d09 commit 71e69e2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

utilcode/lib/src/main/java/com/blankj/utilcode/util/ActivityUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.content.ComponentName;
55
import android.content.Context;
6+
import android.content.ContextWrapper;
67
import android.content.Intent;
78
import android.content.pm.PackageManager;
89
import android.content.pm.ResolveInfo;
@@ -32,6 +33,23 @@ private ActivityUtils() {
3233
throw new UnsupportedOperationException("u can't instantiate me...");
3334
}
3435

36+
/**
37+
* Return the activity by view.
38+
*
39+
* @param view The view.
40+
* @return the activity by view.
41+
*/
42+
public static Activity getActivityByView(@NonNull final View view) {
43+
Context context = view.getContext();
44+
while (context instanceof ContextWrapper) {
45+
if (context instanceof Activity) {
46+
return (Activity) context;
47+
}
48+
context = ((ContextWrapper) context).getBaseContext();
49+
}
50+
return null;
51+
}
52+
3553
/**
3654
* Return whether the activity exists.
3755
*

utilcode/lib/src/main/java/com/blankj/utilcode/util/AntiShakeUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ public static boolean isValid(@NonNull View view) {
2828
public static boolean isValid(@NonNull View view, @IntRange(from = 0) long duration) {
2929
long curTime = System.currentTimeMillis();
3030
Object tag = view.getTag(TAG_KEY);
31-
view.setTag(TAG_KEY, curTime);
3231
if (!(tag instanceof Long)) return true;
3332
long preTime = (Long) tag;
34-
return curTime - preTime > duration;
33+
if (curTime - preTime <= duration) return false;
34+
view.setTag(TAG_KEY, curTime);
35+
return true;
3536
}
3637
}

0 commit comments

Comments
 (0)