|
@@ -5,6 +5,7 @@ import android.graphics.Color;
|
5
|
5
|
import android.graphics.PorterDuff;
|
6
|
6
|
import android.graphics.PorterDuffColorFilter;
|
7
|
7
|
import android.graphics.drawable.Drawable;
|
|
8
|
+import android.os.Build;
|
8
|
9
|
import android.util.DisplayMetrics;
|
9
|
10
|
import android.view.View;
|
10
|
11
|
import android.view.ViewTreeObserver;
|
|
@@ -41,7 +42,11 @@ public class ViewUtils {
|
41
|
42
|
}
|
42
|
43
|
|
43
|
44
|
public static int generateViewId() {
|
44
|
|
- return viewId.incrementAndGet();
|
|
45
|
+ if (Build.VERSION.SDK_INT >= 17) {
|
|
46
|
+ return View.generateViewId();
|
|
47
|
+ } else {
|
|
48
|
+ return compatGenerateViewId();
|
|
49
|
+ }
|
45
|
50
|
}
|
46
|
51
|
|
47
|
52
|
public static float getScreenHeight() {
|
|
@@ -50,5 +55,18 @@ public class ViewUtils {
|
50
|
55
|
wm.getDefaultDisplay().getMetrics(metrics);
|
51
|
56
|
return metrics.heightPixels;
|
52
|
57
|
}
|
|
58
|
+
|
|
59
|
+ private static int compatGenerateViewId() {
|
|
60
|
+ for (; ; ) {
|
|
61
|
+ final int result = viewId.get();
|
|
62
|
+ // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
|
|
63
|
+ int newValue = result + 1;
|
|
64
|
+ if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
|
|
65
|
+ if (viewId.compareAndSet(result, newValue)) {
|
|
66
|
+ return result;
|
|
67
|
+ }
|
|
68
|
+ }
|
|
69
|
+ }
|
|
70
|
+
|
53
|
71
|
}
|
54
|
72
|
|