summaryrefslogtreecommitdiffstats
path: root/iconloaderlib
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2018-11-05 11:08:31 -0800
committerSunny Goyal <sunnygoyal@google.com>2018-11-06 09:59:03 -0800
commit066ace1b8897229445c0fb3515156ef70bdb05e2 (patch)
tree62dd45b95ed2bd2357368c1fd2c82a31da328ffd /iconloaderlib
parent5bd44153fdc76a4ea96ede8aa6646f7f067bb0d5 (diff)
downloadandroid_packages_apps_Trebuchet-066ace1b8897229445c0fb3515156ef70bdb05e2.tar.gz
android_packages_apps_Trebuchet-066ace1b8897229445c0fb3515156ef70bdb05e2.tar.bz2
android_packages_apps_Trebuchet-066ace1b8897229445c0fb3515156ef70bdb05e2.zip
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
Diffstat (limited to 'iconloaderlib')
-rw-r--r--iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java8
-rw-r--r--iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java36
-rw-r--r--iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java8
3 files changed, 43 insertions, 9 deletions
diff --git a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
index 681c03c7c..243903cc8 100644
--- a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
+++ b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
@@ -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);
diff --git a/iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java b/iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java
new file mode 100644
index 000000000..b096cecb5
--- /dev/null
+++ b/iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java
@@ -0,0 +1,36 @@
+/*
+ * 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);
+ }
+}
diff --git a/iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java b/iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java
index 6491b7ec1..455c58c91 100644
--- a/iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java
+++ b/iconloaderlib/src/com/android/launcher3/icons/ShadowGenerator.java
@@ -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) {