summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Parkinson <ianp@google.com>2014-10-06 13:24:31 (GMT)
committerIan Parkinson <ianp@google.com>2014-10-06 13:27:16 (GMT)
commit0c2918f4f4c4a9a6609b82cf23155ed51840f2c8 (patch)
treef62acb793468fe097d2b2c52526404f12c76f393
parent4b8d11fcb396760eca75cf2b055a7acd05c594ec (diff)
downloadandroid_packages_apps_Trebuchet-0c2918f4f4c4a9a6609b82cf23155ed51840f2c8.zip
android_packages_apps_Trebuchet-0c2918f4f4c4a9a6609b82cf23155ed51840f2c8.tar.gz
android_packages_apps_Trebuchet-0c2918f4f4c4a9a6609b82cf23155ed51840f2c8.tar.bz2
Use View.generateViewId if available
Bug: 17456181 Change-Id: Ib7e310ba38ed5e392c5c9b8734f197212f518389
-rw-r--r--src/com/android/launcher3/Launcher.java25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 6780812..6603dce 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -689,19 +689,20 @@ public class Launcher extends Activity
}
}
- /**
- * Copied from View -- the View version of the method isn't called
- * anywhere else in our process and only exists for API level 17+,
- * so it's ok to keep our own version with no API requirement.
- */
public static int generateViewId() {
- for (;;) {
- final int result = sNextGeneratedId.get();
- // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
- int newValue = result + 1;
- if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
- if (sNextGeneratedId.compareAndSet(result, newValue)) {
- return result;
+ if (Build.VERSION.SDK_INT >= 17) {
+ return View.generateViewId();
+ } else {
+ // View.generateViewId() is not available. The following fallback logic is a copy
+ // of its implementation.
+ for (;;) {
+ final int result = sNextGeneratedId.get();
+ // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
+ int newValue = result + 1;
+ if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
+ if (sNextGeneratedId.compareAndSet(result, newValue)) {
+ return result;
+ }
}
}
}