File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
utilcode/lib/src/main/java/com/blankj/utilcode/util Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 3
3
import android .app .Activity ;
4
4
import android .content .ComponentName ;
5
5
import android .content .Context ;
6
+ import android .content .ContextWrapper ;
6
7
import android .content .Intent ;
7
8
import android .content .pm .PackageManager ;
8
9
import android .content .pm .ResolveInfo ;
@@ -32,6 +33,23 @@ private ActivityUtils() {
32
33
throw new UnsupportedOperationException ("u can't instantiate me..." );
33
34
}
34
35
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
+
35
53
/**
36
54
* Return whether the activity exists.
37
55
*
Original file line number Diff line number Diff line change @@ -28,9 +28,10 @@ public static boolean isValid(@NonNull View view) {
28
28
public static boolean isValid (@ NonNull View view , @ IntRange (from = 0 ) long duration ) {
29
29
long curTime = System .currentTimeMillis ();
30
30
Object tag = view .getTag (TAG_KEY );
31
- view .setTag (TAG_KEY , curTime );
32
31
if (!(tag instanceof Long )) return true ;
33
32
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 ;
35
36
}
36
37
}
You can’t perform that action at this time.
0 commit comments