Commit 70dd10f2 authored by Yaron Friedman's avatar Yaron Friedman Committed by Commit Bot

Remove support from KK in ApiCompatibilityUtils

KitKat is no longer supported.
BUG=1073043

Change-Id: I16b0b5179818bd3b32f70cf80f9b6455f4daa50e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2296002
Commit-Queue: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787935}
parent bea30861
...@@ -23,8 +23,6 @@ import android.graphics.ImageDecoder; ...@@ -23,8 +23,6 @@ import android.graphics.ImageDecoder;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
...@@ -68,7 +66,7 @@ import java.util.ArrayList; ...@@ -68,7 +66,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Utility class to use new APIs that were added after KitKat (API level 19). * Utility class to use APIs not in all supported Android versions.
* *
* Do not inline because we use many new APIs, and if they are inlined, they could cause dex * Do not inline because we use many new APIs, and if they are inlined, they could cause dex
* validation errors on low Android versions. * validation errors on low Android versions.
...@@ -669,32 +667,6 @@ public class ApiCompatibilityUtils { ...@@ -669,32 +667,6 @@ public class ApiCompatibilityUtils {
} }
} }
/**
* Creates regular LayerDrawable on Android L+. On older versions creates a helper class that
* fixes issues around {@link LayerDrawable#mutate()}. See https://crbug.com/890317 for details.
* See also {@link #createTransitionDrawable}.
* @param layers A list of drawables to use as layers in this new drawable.
*/
public static LayerDrawable createLayerDrawable(@NonNull Drawable[] layers) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
return new LayerDrawableCompat(layers);
}
return new LayerDrawable(layers);
}
/**
* Creates regular TransitionDrawable on Android L+. On older versions creates a helper class
* that fixes issues around {@link TransitionDrawable#mutate()}. See https://crbug.com/892061
* for details. See also {@link #createLayerDrawable}.
* @param layers A list of drawables to use as layers in this new drawable.
*/
public static TransitionDrawable createTransitionDrawable(@NonNull Drawable[] layers) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
return new TransitionDrawableCompat(layers);
}
return new TransitionDrawable(layers);
}
/** /**
* Adds a content description to the provided EditText password field on versions of Android * Adds a content description to the provided EditText password field on versions of Android
* where the hint text is not used for accessibility. Does nothing if the EditText field does * where the hint text is not used for accessibility. Does nothing if the EditText field does
...@@ -742,80 +714,6 @@ public class ApiCompatibilityUtils { ...@@ -742,80 +714,6 @@ public class ApiCompatibilityUtils {
return false; return false;
} }
private static class LayerDrawableCompat extends LayerDrawable {
private boolean mMutated;
LayerDrawableCompat(@NonNull Drawable[] layers) {
super(layers);
}
@NonNull
@Override
public Drawable mutate() {
// LayerDrawable in Android K loses bounds of layers, so this method works around that.
if (mMutated) {
// This object has already been mutated and shouldn't have any shared state.
return this;
}
Rect[] oldBounds = getLayersBounds(this);
Drawable superResult = super.mutate();
// LayerDrawable.mutate() always returns this, bail out if this isn't the case.
if (superResult != this) return superResult;
restoreLayersBounds(this, oldBounds);
mMutated = true;
return this;
}
}
private static class TransitionDrawableCompat extends TransitionDrawable {
private boolean mMutated;
TransitionDrawableCompat(@NonNull Drawable[] layers) {
super(layers);
}
@NonNull
@Override
public Drawable mutate() {
// LayerDrawable in Android K loses bounds of layers, so this method works around that.
if (mMutated) {
// This object has already been mutated and shouldn't have any shared state.
return this;
}
Rect[] oldBounds = getLayersBounds(this);
Drawable superResult = super.mutate();
// TransitionDrawable.mutate() always returns this, bail out if this isn't the case.
if (superResult != this) return superResult;
restoreLayersBounds(this, oldBounds);
mMutated = true;
return this;
}
}
/**
* Helper for {@link LayerDrawableCompat#mutate} and {@link TransitionDrawableCompat#mutate}.
* Obtains the bounds of layers so they can be restored after a mutation.
*/
private static Rect[] getLayersBounds(LayerDrawable layerDrawable) {
Rect[] result = new Rect[layerDrawable.getNumberOfLayers()];
for (int i = 0; i < layerDrawable.getNumberOfLayers(); i++) {
result[i] = layerDrawable.getDrawable(i).getBounds();
}
return result;
}
/**
* Helper for {@link LayerDrawableCompat#mutate} and {@link TransitionDrawableCompat#mutate}.
* Restores the bounds of layers after a mutation.
*/
private static void restoreLayersBounds(LayerDrawable layerDrawable, Rect[] oldBounds) {
assert layerDrawable.getNumberOfLayers() == oldBounds.length;
for (int i = 0; i < layerDrawable.getNumberOfLayers(); i++) {
layerDrawable.getDrawable(i).setBounds(oldBounds[i]);
}
}
/** /**
* Retrieves an image for the given url as a Bitmap. * Retrieves an image for the given url as a Bitmap.
*/ */
......
...@@ -157,8 +157,8 @@ public class EphemeralTabSheetContent implements BottomSheetContent { ...@@ -157,8 +157,8 @@ public class EphemeralTabSheetContent implements BottomSheetContent {
// TODO(shaktisahu): Find out if there is a better way for this animation. // TODO(shaktisahu): Find out if there is a better way for this animation.
Drawable presentedDrawable = favicon; Drawable presentedDrawable = favicon;
if (mCurrentFavicon != null && !(mCurrentFavicon instanceof TransitionDrawable)) { if (mCurrentFavicon != null && !(mCurrentFavicon instanceof TransitionDrawable)) {
TransitionDrawable transitionDrawable = ApiCompatibilityUtils.createTransitionDrawable( TransitionDrawable transitionDrawable =
new Drawable[] {mCurrentFavicon, favicon}); new TransitionDrawable(new Drawable[] {mCurrentFavicon, favicon});
transitionDrawable.setCrossFadeEnabled(true); transitionDrawable.setCrossFadeEnabled(true);
transitionDrawable.startTransition(BASE_ANIMATION_DURATION_MS); transitionDrawable.startTransition(BASE_ANIMATION_DURATION_MS);
presentedDrawable = transitionDrawable; presentedDrawable = transitionDrawable;
......
...@@ -9,6 +9,7 @@ import android.graphics.Bitmap; ...@@ -9,6 +9,7 @@ import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
...@@ -83,7 +84,7 @@ public class ThumbnailGradient { ...@@ -83,7 +84,7 @@ public class ThumbnailGradient {
? R.drawable.thumbnail_gradient_top_left ? R.drawable.thumbnail_gradient_top_left
: R.drawable.thumbnail_gradient_top_right); : R.drawable.thumbnail_gradient_top_right);
return ApiCompatibilityUtils.createLayerDrawable( return new LayerDrawable(
new Drawable[] {new BitmapDrawable(resources, bitmap), gradient}); new Drawable[] {new BitmapDrawable(resources, bitmap), gradient});
} }
......
...@@ -103,10 +103,9 @@ public abstract class PromoDialog extends AlwaysDismissedDialog ...@@ -103,10 +103,9 @@ public abstract class PromoDialog extends AlwaysDismissedDialog
* Force the promo dialog to have a fully opaque background hiding any underlying content. * Force the promo dialog to have a fully opaque background hiding any underlying content.
*/ */
protected void forceOpaqueBackground() { protected void forceOpaqueBackground() {
LayerDrawable background = ApiCompatibilityUtils.createLayerDrawable( LayerDrawable background = new LayerDrawable(new Drawable[] {new ColorDrawable(Color.WHITE),
new Drawable[] {new ColorDrawable(Color.WHITE), new ColorDrawable(ApiCompatibilityUtils.getColor(
new ColorDrawable(ApiCompatibilityUtils.getColor( getContext().getResources(), R.color.modal_dialog_scrim_color))});
getContext().getResources(), R.color.modal_dialog_scrim_color))});
mScrimView.setBackground(background); mScrimView.setBackground(background);
} }
......
...@@ -11,7 +11,6 @@ import android.graphics.drawable.Drawable; ...@@ -11,7 +11,6 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.view.View; import android.view.View;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.components.browser_ui.widget.R; import org.chromium.components.browser_ui.widget.R;
...@@ -95,9 +94,9 @@ public class ViewHighlighter { ...@@ -95,9 +94,9 @@ public class ViewHighlighter {
background = background.getConstantState().newDrawable(resources); background = background.getConstantState().newDrawable(resources);
} }
LayerDrawable drawable = ApiCompatibilityUtils.createLayerDrawable(background == null Drawable[] layers = background == null ? new Drawable[] {pulseDrawable}
? new Drawable[] {pulseDrawable} : new Drawable[] {background, pulseDrawable};
: new Drawable[] {background, pulseDrawable}); LayerDrawable drawable = new LayerDrawable(layers);
view.setBackground(drawable); view.setBackground(drawable);
view.setTag(R.id.highlight_state, true); view.setTag(R.id.highlight_state, true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment