| Index: base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
|
| diff --git a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
|
| index 406f328c18058b11c6c8d72d85d429df38a368ad..d76994bf7ca198f0880ca2575e0d47e74990b75e 100644
|
| --- a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
|
| +++ b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
|
| @@ -36,12 +36,15 @@ import android.view.inputmethod.InputMethodSubtype;
|
| import android.widget.TextView;
|
|
|
| import java.io.File;
|
| +import java.util.concurrent.atomic.AtomicInteger;
|
|
|
| /**
|
| * Utility class to use new APIs that were added after ICS (API level 14).
|
| */
|
| @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
| public class ApiCompatibilityUtils {
|
| + private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
|
| +
|
| private ApiCompatibilityUtils() {
|
| }
|
|
|
| @@ -643,4 +646,22 @@ public class ApiCompatibilityUtils {
|
| public static boolean objectEquals(Object a, Object b) {
|
| return (a == null) ? (b == null) : a.equals(b);
|
| }
|
| +
|
| + /**
|
| + * @see android.view.View.generateViewId();
|
| + */
|
| + public static int generateViewId() {
|
| + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
| + return View.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;
|
| + }
|
| + }
|
| + }
|
| }
|
|
|