This source file includes following definitions.
- isLayoutRtl
- getLayoutDirection
- isPrintingSupported
- isHTMLClipboardSupported
- setLayoutDirection
- setTextAlignment
- setMarginEnd
- getMarginEnd
- setMarginStart
- getMarginStart
- setPaddingRelative
- getPaddingStart
- getPaddingEnd
- setCompoundDrawablesRelative
- setCompoundDrawablesRelativeWithIntrinsicBounds
- setCompoundDrawablesRelativeWithIntrinsicBounds
- postInvalidateOnAnimation
- setContentDescriptionForRemoteView
- SuppressWarnings
- setBackgroundForView
- SuppressWarnings
- removeOnGlobalLayoutListener
- SuppressWarnings
- setImageAlpha
- SuppressWarnings
- getCreatorPackage
package org.chromium.base;
import android.app.PendingIntent;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.TextView;
public class ApiCompatibilityUtils {
private ApiCompatibilityUtils() {
}
public static boolean isLayoutRtl(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
} else {
return false;
}
}
public static int getLayoutDirection(Configuration configuration) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return configuration.getLayoutDirection();
} else {
return View.LAYOUT_DIRECTION_LTR;
}
}
public static boolean isPrintingSupported() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
public static boolean isHTMLClipboardSupported() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
}
public static void setLayoutDirection(View view, int layoutDirection) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
view.setLayoutDirection(layoutDirection);
} else {
}
}
public static void setTextAlignment(View view, int textAlignment) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
view.setTextAlignment(textAlignment);
} else {
}
}
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;
}
}
public static int getMarginEnd(MarginLayoutParams layoutParams) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return layoutParams.getMarginEnd();
} else {
return layoutParams.rightMargin;
}
}
public static void setMarginStart(MarginLayoutParams layoutParams, int start) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.setMarginStart(start);
} else {
layoutParams.leftMargin = start;
}
}
public static int getMarginStart(MarginLayoutParams layoutParams) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return layoutParams.getMarginStart();
} else {
return layoutParams.leftMargin;
}
}
public static void setPaddingRelative(View view, int start, int top, int end, int bottom) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
view.setPaddingRelative(start, top, end, bottom);
} else {
view.setPadding(start, top, end, bottom);
}
}
public static int getPaddingStart(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return view.getPaddingStart();
} else {
return view.getPaddingLeft();
}
}
public static int getPaddingEnd(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return view.getPaddingEnd();
} else {
return view.getPaddingRight();
}
}
public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top,
Drawable end, Drawable bottom) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelative(start, top, bottom, end);
} else {
textView.setCompoundDrawables(start, top, bottom, end);
}
}
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView,
Drawable start, Drawable top, Drawable end, Drawable bottom) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, bottom, end);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(start, top, bottom, end);
}
}
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView,
int start, int top, int end, int bottom) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, bottom, end);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(start, top, bottom, end);
}
}
public static void postInvalidateOnAnimation(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.postInvalidateOnAnimation();
} else {
view.postInvalidate();
}
}
public static void setContentDescriptionForRemoteView(RemoteViews remoteViews, int viewId,
CharSequence contentDescription) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
remoteViews.setContentDescription(viewId, contentDescription);
} else {
}
}
@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);
}
}
@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);
}
}
@SuppressWarnings("deprecation")
public static void setImageAlpha(ImageView iv, int alpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
iv.setImageAlpha(alpha);
} else {
iv.setAlpha(alpha);
}
}
@SuppressWarnings("deprecation")
public static String getCreatorPackage(PendingIntent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return intent.getCreatorPackage();
} else {
return intent.getTargetPackage();
}
}
}