am 0c2918f4: Use View.generateViewId if available

* commit '0c2918f4f4c4a9a6609b82cf23155ed51840f2c8':
  Use View.generateViewId if available
This commit is contained in:
Ian Parkinson
2014-10-18 16:05:46 +00:00
committed by Android Git Automerger
+13 -12
View File
@@ -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() { public static int generateViewId() {
for (;;) { if (Build.VERSION.SDK_INT >= 17) {
final int result = sNextGeneratedId.get(); return View.generateViewId();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that. } else {
int newValue = result + 1; // View.generateViewId() is not available. The following fallback logic is a copy
if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. // of its implementation.
if (sNextGeneratedId.compareAndSet(result, newValue)) { for (;;) {
return result; 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;
}
} }
} }
} }