Skip to content

Commit

Permalink
Remove redundant Android version checks
Browse files Browse the repository at this point in the history
Summary: As per title - Litho is now minSdk 21.

Reviewed By: luluwu2032

Differential Revision: D55682553

fbshipit-source-id: 3ded7fff3c29a3bf00d3cf4f6a64bb4d90155708
  • Loading branch information
zielinskimz authored and facebook-github-bot committed Apr 4, 2024
1 parent 140784e commit 902fefd
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 188 deletions.
14 changes: 4 additions & 10 deletions litho-core/src/main/java/com/facebook/litho/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -2034,9 +2034,7 @@ public T shadowElevationRes(@DimenRes int resId) {
* @param value controller for the elevation value
*/
public T shadowElevation(DynamicValue<Float> value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mComponent.getOrCreateCommonDynamicProps().put(KEY_ELEVATION, value);
}
mComponent.getOrCreateCommonDynamicProps().put(KEY_ELEVATION, value);
return getThis();
}

Expand All @@ -2048,9 +2046,7 @@ public T shadowElevation(DynamicValue<Float> value) {
* into a view
*/
public T stateListAnimator(@Nullable StateListAnimator stateListAnimator) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mComponent.getOrCreateCommonProps().stateListAnimator(stateListAnimator);
}
mComponent.getOrCreateCommonProps().stateListAnimator(stateListAnimator);
return getThis();
}

Expand All @@ -2062,16 +2058,14 @@ public T stateListAnimator(@Nullable StateListAnimator stateListAnimator) {
* into a view
*/
public T stateListAnimatorRes(@DrawableRes int resId) {
if (Build.VERSION.SDK_INT >= 26) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// We cannot do it on the versions prior to Android 8.0 since there is a possible race
// condition when loading state list animators, thus we will avoid doing it off the UI
// thread
return stateListAnimator(
AnimatorInflater.loadStateListAnimator(mContext.getAndroidContext(), resId));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mComponent.getOrCreateCommonProps().stateListAnimatorRes(resId);
}
mComponent.getOrCreateCommonProps().stateListAnimatorRes(resId);
return getThis();
}

Expand Down
28 changes: 1 addition & 27 deletions litho-core/src/main/java/com/facebook/litho/ComponentHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
Expand Down Expand Up @@ -111,12 +110,6 @@ interface ExceptionLogMessageProvider {
StringBuilder getLogMessage();
}

/**
* {@link ViewGroup#getClipChildren()} was only added in API 18, will need to keep track of this
* flag ourselves on the lower versions
*/
private boolean mClipChildren = true;

private boolean mClippingTemporaryDisabled = false;
private boolean mClippingToRestore = false;

Expand Down Expand Up @@ -1050,24 +1043,9 @@ public void setClipChildren(boolean clipChildren) {
mClippingToRestore = clipChildren;
return;
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
// There is no ViewGroup.getClipChildren() method on API < 18, will keep track this way
mClipChildren = clipChildren;
}
super.setClipChildren(clipChildren);
}

@Override
public boolean getClipChildren() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
// There is no ViewGroup.getClipChildren() method on API < 18
return mClipChildren;
} else {
return super.getClipChildren();
}
}

/**
* Temporary disables child clipping, the previous state could be restored by calling {@link
* #restoreChildClipping()}. While clipping is disabled calling {@link #setClipChildren(boolean)}
Expand All @@ -1078,11 +1056,7 @@ void temporaryDisableChildClipping() {
return;
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mClippingToRestore = getClipChildren();
} else {
mClippingToRestore = mClipChildren;
}
mClippingToRestore = getClipChildren();

// The order here is crucial, we first need to set clipping then update
// mClippingTemporaryDisabled flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static void resetDynamicValues(int key, Object content) {
break;

case KEY_ELEVATION:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && target.getElevation() != 0) {
if (target.getElevation() != 0) {
target.setElevation(0);
}
break;
Expand Down Expand Up @@ -270,9 +270,7 @@ private static void bindCommonDynamicProp(int key, @Nullable DynamicValue<?> val
break;

case KEY_ELEVATION:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
target.setElevation(DynamicPropsManager.<Float>resolve(value));
}
target.setElevation(DynamicPropsManager.<Float>resolve(value));
break;

case KEY_BACKGROUND_COLOR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.facebook.litho
import android.animation.AnimatorInflater
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.os.Build
import android.util.SparseArray
import android.view.View
Expand Down Expand Up @@ -846,23 +845,14 @@ class LithoViewAttributesExtension private constructor() :
private fun setViewBackground(view: View, attributes: ViewAttributes) {
val background = attributes.background
if (background != null) {
setBackgroundCompat(view, background)
view.background = background
}
}

private fun unsetViewBackground(view: View, attributes: ViewAttributes) {
val background = attributes.background
if (background != null) {
setBackgroundCompat(view, null)
}
}

@Suppress("deprecation")
private fun setBackgroundCompat(view: View, drawable: Drawable?) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
view.setBackgroundDrawable(drawable)
} else {
view.background = drawable
view.background = null
}
}

Expand All @@ -877,16 +867,10 @@ class LithoViewAttributesExtension private constructor() :
}

private fun setViewLayoutDirection(view: View, attributes: ViewAttributes) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return
}
view.layoutDirection = attributes.layoutDirection.getLayoutDirectionForView()
}

private fun unsetViewLayoutDirection(view: View) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return
}
view.layoutDirection = View.LAYOUT_DIRECTION_INHERIT
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.facebook.litho.config

import android.os.Build
import java.io.BufferedReader
import java.io.File
import java.io.FileFilter
Expand Down Expand Up @@ -50,13 +49,6 @@ object DeviceInfoUtils {
if (numCores != NUM_CORES_NOT_SET) {
return numCores
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// Gingerbread doesn't support giving a single application access to both cores, but a
// handful of devices (Atrix 4G and Droid X2 for example) were released with a dual-core
// chipset and Gingerbread; that can let an app in the background run without impacting
// the foreground application. But for our purposes, it makes them single core.
return 1
}
var cores: Int
try {
cores = getCoresFromFileInfo("/sys/devices/system/cpu/possible")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.facebook.litho.drawable

import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable
import android.os.Build
import androidx.annotation.ColorInt
import com.facebook.rendercore.utils.equals
import java.util.Arrays
Expand Down Expand Up @@ -73,7 +72,7 @@ open class ComparableGradientDrawable(
strokeDashWidth == that.strokeDashWidth &&
strokeDashGap == that.strokeDashGap &&
strokeColor == that.strokeColor &&
orientationOrNullOnAPI15 == that.orientationOrNullOnAPI15 &&
orientation == that.orientation &&
Arrays.equals(colors, that.colors) &&
Arrays.equals(cornerRadii, that.cornerRadii) &&
equals(strokeColorStateList, that.strokeColorStateList)
Expand All @@ -82,7 +81,7 @@ open class ComparableGradientDrawable(
override fun hashCode(): Int {
var result =
arrayOf(
orientationOrNullOnAPI15,
orientation,
color,
colorStateList,
cornerRadius,
Expand All @@ -102,16 +101,6 @@ open class ComparableGradientDrawable(
return result
}

private val orientationOrNullOnAPI15: Orientation?
/**
* On API 15, get/setOrientation didn't exist so we need to not call it. It also wasn't possible
* to change the orientation so we don't need to compare it anyway.
*/
get() =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
null
} else orientation

override fun isEquivalentTo(other: ComparableDrawable): Boolean {
return equals(other)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.animation.StateListAnimator
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.os.Build
import android.util.SparseArray
import android.view.ViewOutlineProvider
import androidx.annotation.ColorInt
Expand Down Expand Up @@ -437,11 +436,7 @@ inline fun Style.selected(isSelected: Boolean): Style =
* NOTE: This style will be ignored pre-API 21.
*/
inline fun Style.stateListAnimator(stateListAnimator: StateListAnimator?): Style =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
this + ObjectStyleItem(ObjectField.STATE_LIST_ANIMATOR, stateListAnimator)
} else {
this
}
this + ObjectStyleItem(ObjectField.STATE_LIST_ANIMATOR, stateListAnimator)

/**
* Sets testKey on the View this Component mounts to. Setting this property will cause the Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,7 @@ static void onMeasure(
// Padding from the background will be added to the layout separately, so does not need to
// be a part of this measurement.
editText.setPadding(0, 0, 0, 0);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
editText.setBackgroundDrawable(null);
} else {
editText.setBackground(null);
}
editText.setBackground(null);
}
}

Expand Down Expand Up @@ -883,7 +878,7 @@ static class EditTextForMeasure extends EditText {
}

@Override
public void setBackground(Drawable background) {
public void setBackground(@Nullable Drawable background) {
if (background != null) {
background.mutate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static com.facebook.litho.widget.RenderInfoViewCreatorController.DEFAULT_COMPONENT_VIEW_TYPE;

import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
Expand Down Expand Up @@ -2855,11 +2854,6 @@ private void enableStickyHeader(RecyclerView recyclerView) {
Log.w(TAG, "Sticky header is not supported for circular RecyclerViews");
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// Sticky header needs view translation APIs which are not available in Gingerbread and below.
Log.w(TAG, "Sticky header is supported only on ICS (API14) and above");
return;
}
if (recyclerView == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ private static Layout createTextLayout(
layoutBuilder.setLineHeight(lineHeight);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
layoutBuilder.setLetterSpacing(letterSpacing);
}
layoutBuilder.setLetterSpacing(letterSpacing);

if (minEms != DEFAULT_EMS) {
layoutBuilder.setMinEms(minEms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ private static void resolveStyleAttrsForTypedArray(
ellipsize.set(TRUNCATE_AT[index - 1]);
}
} else if (attr == R.styleable.Text_android_textAlignment) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
viewTextAlignment = a.getInt(attr, -1);
textAlignment.set(getTextAlignment(viewTextAlignment, gravity));
}
viewTextAlignment = a.getInt(attr, -1);
textAlignment.set(getTextAlignment(viewTextAlignment, gravity));
} else if (attr == R.styleable.Text_android_gravity) {
gravity = a.getInt(attr, -1);
textAlignment.set(getTextAlignment(viewTextAlignment, gravity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.Build;
import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
import com.facebook.litho.Wrapper;
Expand Down Expand Up @@ -62,29 +60,15 @@ static Drawable onCalculateCachedValue(
}

public static Drawable getRippleDrawable(int normalColor, int pressedColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new RippleDrawable(
ColorStateList.valueOf(pressedColor),
new ColorDrawable(normalColor),
getRippleMask(pressedColor));
} else {
return getStateListDrawable(normalColor, pressedColor);
}
return new RippleDrawable(
ColorStateList.valueOf(pressedColor),
new ColorDrawable(normalColor),
getRippleMask(pressedColor));
}

private static Drawable getRippleMask(int color) {
final ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}

public static StateListDrawable getStateListDrawable(int normalColor, int pressedColor) {
final StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed}, new ColorDrawable(pressedColor));
states.addState(new int[] {android.R.attr.state_focused}, new ColorDrawable(pressedColor));
states.addState(new int[] {android.R.attr.state_activated}, new ColorDrawable(pressedColor));
states.addState(new int[] {}, new ColorDrawable(normalColor));

return states;
}
}
Loading

0 comments on commit 902fefd

Please sign in to comment.