Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 066ace1b authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Replacing setAlphaComponent with setAlphaComponentBound for better animation interpolation

setAlphaComponent throws expetion for invalid range, which can cause brashes in overshoot
interpolation

Bug: 118390004
Change-Id: Ic9c5ff3d660eba353b982c4c47ccfaf329b3e296
parent 5bd44153
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ import android.os.Build;
import android.os.Process;
import android.os.UserHandle;

import com.android.launcher3.icons.R;

import static android.graphics.Paint.DITHER_FLAG;
import static android.graphics.Paint.FILTER_BITMAP_FLAG;
import static com.android.launcher3.icons.ShadowGenerator.BLUR_FACTOR;
@@ -81,6 +79,7 @@ public class BaseIconFactory {
        return mNormalizer;
    }

    @SuppressWarnings("deprecation")
    public BitmapInfo createIconBitmap(Intent.ShortcutIconResource iconRes) {
        try {
            Resources resources = mPm.getResourcesForApplication(iconRes.packageName);
@@ -184,8 +183,7 @@ public class BaseIconFactory {
            RectF outIconBounds, float[] outScale) {
        float scale = 1f;

        if (shrinkNonAdaptiveIcons) {
            boolean[] outShape = new boolean[1];
        if (shrinkNonAdaptiveIcons && ATLEAST_OREO) {
            if (mWrapperIcon == null) {
                mWrapperIcon = mContext.getDrawable(R.drawable.adaptive_icon_drawable_wrapper)
                        .mutate();
@@ -193,7 +191,7 @@ public class BaseIconFactory {
            AdaptiveIconDrawable dr = (AdaptiveIconDrawable) mWrapperIcon;
            dr.setBounds(0, 0, 1, 1);
            scale = getNormalizer().getScale(icon, outIconBounds);
            if (ATLEAST_OREO && !(icon instanceof AdaptiveIconDrawable)) {
            if (!(icon instanceof AdaptiveIconDrawable)) {
                FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground());
                fsd.setDrawable(icon);
                fsd.setScale(scale);
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.icons;

import androidx.annotation.ColorInt;

public class GraphicsUtils {

    /**
     * Set the alpha component of {@code color} to be {@code alpha}. Unlike the support lib version,
     * it bounds the alpha in valid range instead of throwing an exception to allow for safer
     * interpolation of color animations
     */
    @ColorInt
    public static int setColorAlphaBound(int color, int alpha) {
        if (alpha < 0) {
            alpha = 0;
        } else if (alpha > 255) {
            alpha = 255;
        }
        return (color & 0x00ffffff) | (alpha << 24);
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3.icons;

import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BlurMaskFilter;
@@ -27,8 +29,6 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;

import androidx.core.graphics.ColorUtils;

/**
 * Utility class to add shadows to bitmaps.
 */
@@ -142,12 +142,12 @@ public class ShadowGenerator {

            // Key shadow
            p.setShadowLayer(shadowBlur, 0, keyShadowDistance,
                    ColorUtils.setAlphaComponent(Color.BLACK, keyShadowAlpha));
                    setColorAlphaBound(Color.BLACK, keyShadowAlpha));
            c.drawRoundRect(bounds, radius, radius, p);

            // Ambient shadow
            p.setShadowLayer(shadowBlur, 0, 0,
                    ColorUtils.setAlphaComponent(Color.BLACK, ambientShadowAlpha));
                    setColorAlphaBound(Color.BLACK, ambientShadowAlpha));
            c.drawRoundRect(bounds, radius, radius, p);

            if (Color.alpha(color) < 255) {
+4 −5
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ package com.android.quickstep.views;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.ACCEL;
import static com.android.launcher3.anim.Interpolators.LINEAR;

import static androidx.core.graphics.ColorUtils.setAlphaComponent;
import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;

import android.content.Context;
import android.graphics.Canvas;
@@ -141,7 +140,7 @@ public class ShelfScrimView extends ScrimView {

            int alpha = Math.round(Utilities.mapToRange(
                    mProgress, mMidProgress, 1, mMidAlpha, 0, ACCEL));
            mShelfColor = setAlphaComponent(mEndScrim, alpha);
            mShelfColor = setColorAlphaBound(mEndScrim, alpha);
        } else {
            mDragHandleOffset += mShiftRange * (mMidProgress - mProgress);

@@ -149,12 +148,12 @@ public class ShelfScrimView extends ScrimView {
            int alpha = Math.round(
                    Utilities.mapToRange(mProgress, (float) 0, mMidProgress, (float) mEndAlpha,
                            (float) mMidAlpha, Interpolators.clampToProgress(ACCEL, 0.5f, 1f)));
            mShelfColor = setAlphaComponent(mEndScrim, alpha);
            mShelfColor = setColorAlphaBound(mEndScrim, alpha);

            int remainingScrimAlpha = Math.round(
                    Utilities.mapToRange(mProgress, (float) 0, mMidProgress, mMaxScrimAlpha,
                            (float) 0, LINEAR));
            mRemainingScreenColor = setAlphaComponent(mScrimColor, remainingScrimAlpha);
            mRemainingScreenColor = setColorAlphaBound(mScrimColor, remainingScrimAlpha);
        }
    }

+3 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3;

import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
@@ -53,8 +55,6 @@ import com.android.launcher3.model.PackageItemInfo;

import java.text.NumberFormat;

import androidx.core.graphics.ColorUtils;

/**
 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
 * because we want to make the bubble taller than the text and TextView's clip is
@@ -473,8 +473,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
            // Special case to prevent text shadows in high contrast mode
            return Color.TRANSPARENT;
        }
        return ColorUtils.setAlphaComponent(
                mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
        return setColorAlphaBound(mTextColor, Math.round(Color.alpha(mTextColor) * mTextAlpha));
    }

    /**
Loading