Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3758)

Unified Diff: base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java

Issue 2801153003: [Contextual Search] Add a handle to the bar when Chrome Home is enabled (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698