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 33import android .app .Activity ;
44import android .content .ComponentName ;
55import android .content .Context ;
6+ import android .content .ContextWrapper ;
67import android .content .Intent ;
78import android .content .pm .PackageManager ;
89import 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 *
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments