summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authornewt@chromium.org <newt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 13:41:08 +0000
committernewt@chromium.org <newt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 13:41:08 +0000
commitd4f22518668cf93deea14a5f23073258b0a1db25 (patch)
treefd8d316c2b31b8379ba27fdc38f9cbfd1ac39ee1 /base
parentdd5035e1af0824ba1e90710ca616faf6aa944ef8 (diff)
downloadchromium_src-d4f22518668cf93deea14a5f23073258b0a1db25.zip
chromium_src-d4f22518668cf93deea14a5f23073258b0a1db25.tar.gz
chromium_src-d4f22518668cf93deea14a5f23073258b0a1db25.tar.bz2
Upstream ApiCompatibilityUtils.java.
This also merges in DeprecationUtilities, whose function is closely related. BUG=245224 R=aurimas@chromium.org, kkimlabs@chromium.org, yfriedman@chromium.org Review URL: https://codereview.chromium.org/16093035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
new file mode 100644
index 0000000..0116c9b
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
@@ -0,0 +1,104 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base;
+
+import android.app.Notification;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.view.View;
+import android.view.ViewGroup.MarginLayoutParams;
+import android.view.ViewTreeObserver;
+
+/**
+ * Utility class to use new APIs that were added after ICS (API level 14).
+ */
+public class ApiCompatibilityUtils {
+
+ private ApiCompatibilityUtils() {
+ }
+
+ /**
+ * @see android.view.View#setLayoutDirection(int)
+ */
+ public static void setLayoutDirection(View view, int layoutDirection) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ view.setLayoutDirection(layoutDirection);
+ } else {
+ // Do nothing. RTL layouts aren't supported before JB MR1.
+ }
+ }
+
+ /**
+ * @see android.view.ViewGroup.MarginLayoutParams#setMarginEnd(int)
+ */
+ public static void setMarginEnd(MarginLayoutParams layoutParams, int end) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ layoutParams.setMarginEnd(end);
+ } else {
+ layoutParams.rightMargin = end;
+ }
+ }
+
+ /**
+ * @see android.view.ViewGroup.MarginLayoutParams#getMarginStart()
+ */
+ public static int getMarginStart(MarginLayoutParams layoutParams) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ return layoutParams.getMarginStart();
+ } else {
+ return layoutParams.leftMargin;
+ }
+ }
+
+ /**
+ * @see android.view.View#postInvalidateOnAnimation()
+ */
+ public static void postInvalidateOnAnimation(View view) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ view.postInvalidateOnAnimation();
+ } else {
+ view.invalidate();
+ }
+ }
+
+ // These methods have a new name, and the old name is deprecated.
+
+ /**
+ * @see android.view.View#setBackground(Drawable)
+ */
+ @SuppressWarnings("deprecation")
+ public static void setBackgroundForView(View view, Drawable drawable) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ view.setBackground(drawable);
+ } else {
+ view.setBackgroundDrawable(drawable);
+ }
+ }
+
+ /**
+ * @see android.view.ViewTreeObserver#removeOnGlobalLayoutListener()
+ */
+ @SuppressWarnings("deprecation")
+ public static void removeOnGlobalLayoutListener(
+ View view, ViewTreeObserver.OnGlobalLayoutListener listener) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ view.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
+ } else {
+ view.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
+ }
+ }
+
+ /**
+ * @see android.app.Notification.Builder#build()
+ */
+ @SuppressWarnings("deprecation")
+ public static Notification buildNotification(Notification.Builder builder) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ return builder.build();
+ } else {
+ return builder.getNotification();
+ }
+ }
+}