summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Miranda <jonmiranda@google.com>2019-03-04 20:16:18 -0800
committerJon Miranda <jonmiranda@google.com>2019-03-05 12:23:28 -0800
commit69b35e0195aea3da0956dbf103e2146c36a6cfb2 (patch)
treeac6117267fe1c6879a06d2c37cae24eb39e9645c
parent34691cffe3c84c575de5f9342a6a70001920d418 (diff)
downloadandroid_packages_apps_Trebuchet-69b35e0195aea3da0956dbf103e2146c36a6cfb2.tar.gz
android_packages_apps_Trebuchet-69b35e0195aea3da0956dbf103e2146c36a6cfb2.tar.bz2
android_packages_apps_Trebuchet-69b35e0195aea3da0956dbf103e2146c36a6cfb2.zip
Fix app to folder icon animation.
- Needed to account for the preview bounds (similar to BubbleTextView icon bounds) - Also needed to update the bitmap shift amount so that it is re-centered - Moved ShiftedBitmapDrawable to its own class in graphics package Bug: 123900446 Change-Id: Ifa9e3f688e55d017cf86a0285f5cdb1b014f01e6
-rw-r--r--src/com/android/launcher3/Utilities.java5
-rw-r--r--src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java36
-rw-r--r--src/com/android/launcher3/folder/FolderIcon.java4
-rw-r--r--src/com/android/launcher3/folder/PreviewBackground.java9
-rw-r--r--src/com/android/launcher3/graphics/ShiftedBitmapDrawable.java74
-rw-r--r--src/com/android/launcher3/views/FloatingIconView.java16
6 files changed, 104 insertions, 40 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index c3edfe5d2..7c4a035bf 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -593,8 +593,9 @@ public final class Utilities {
int viewLocationTop = rect.top;
if (isBubbleTextView && !fromDeepShortcutView) {
- BubbleTextView btv = (BubbleTextView) v;
- btv.getIconBounds(rect);
+ ((BubbleTextView) v).getIconBounds(rect);
+ } else if (isFolderIcon) {
+ ((FolderIcon) v).getPreviewBounds(rect);
} else {
rect.set(0, 0, rect.width(), rect.height());
}
diff --git a/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java b/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
index 794ab4eb0..5e41bb70e 100644
--- a/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
+++ b/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
@@ -36,6 +36,7 @@ import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.PreviewBackground;
+import com.android.launcher3.graphics.ShiftedBitmapDrawable;
import com.android.launcher3.icons.BitmapRenderer;
import com.android.launcher3.util.Preconditions;
@@ -133,39 +134,4 @@ public class FolderAdaptiveIcon extends AdaptiveIconDrawable {
return new FolderAdaptiveIcon(new ColorDrawable(bg.getBgColor()), foreground, badge, mask);
}
-
- /**
- * A simple drawable which draws a bitmap at a fixed position irrespective of the bounds
- */
- private static class ShiftedBitmapDrawable extends Drawable {
-
- private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
- private final Bitmap mBitmap;
- private final float mShiftX;
- private final float mShiftY;
-
- ShiftedBitmapDrawable(Bitmap bitmap, float shiftX, float shiftY) {
- mBitmap = bitmap;
- mShiftX = shiftX;
- mShiftY = shiftY;
- }
-
- @Override
- public void draw(Canvas canvas) {
- canvas.drawBitmap(mBitmap, mShiftX, mShiftY, mPaint);
- }
-
- @Override
- public void setAlpha(int i) { }
-
- @Override
- public void setColorFilter(ColorFilter colorFilter) {
- mPaint.setColorFilter(colorFilter);
- }
-
- @Override
- public int getOpacity() {
- return PixelFormat.TRANSLUCENT;
- }
- }
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index 30dbe698c..67495ea75 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -189,6 +189,10 @@ public class FolderIcon extends FrameLayout implements FolderListener {
return icon;
}
+ public void getPreviewBounds(Rect outBounds) {
+ mBackground.getBounds(outBounds);
+ }
+
public Folder getFolder() {
return mFolder;
}
diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java
index fd4774f98..ac908f4ad 100644
--- a/src/com/android/launcher3/folder/PreviewBackground.java
+++ b/src/com/android/launcher3/folder/PreviewBackground.java
@@ -33,6 +33,7 @@ import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RadialGradient;
+import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Shader;
import android.util.Property;
@@ -154,6 +155,14 @@ public class PreviewBackground {
invalidate();
}
+ void getBounds(Rect outBounds) {
+ int top = basePreviewOffsetY;
+ int left = basePreviewOffsetX;
+ int right = left + previewSize;
+ int bottom = top + previewSize;
+ outBounds.set(left, top, right, bottom);
+ }
+
int getRadius() {
return previewSize / 2;
}
diff --git a/src/com/android/launcher3/graphics/ShiftedBitmapDrawable.java b/src/com/android/launcher3/graphics/ShiftedBitmapDrawable.java
new file mode 100644
index 000000000..52d45bb4e
--- /dev/null
+++ b/src/com/android/launcher3/graphics/ShiftedBitmapDrawable.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 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.graphics;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
+
+/**
+ * A simple drawable which draws a bitmap at a fixed position irrespective of the bounds
+ */
+public class ShiftedBitmapDrawable extends Drawable {
+
+ private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
+ private final Bitmap mBitmap;
+ private float mShiftX;
+ private float mShiftY;
+
+ public ShiftedBitmapDrawable(Bitmap bitmap, float shiftX, float shiftY) {
+ mBitmap = bitmap;
+ mShiftX = shiftX;
+ mShiftY = shiftY;
+ }
+
+ public float getShiftX() {
+ return mShiftX;
+ }
+
+ public float getShiftY() {
+ return mShiftY;
+ }
+
+ public void setShiftX(float shiftX) {
+ mShiftX = shiftX;
+ }
+
+ public void setShiftY(float shiftY) {
+ mShiftY = shiftY;
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ canvas.drawBitmap(mBitmap, mShiftX, mShiftY, mPaint);
+ }
+
+ @Override
+ public void setAlpha(int i) { }
+
+ @Override
+ public void setColorFilter(ColorFilter colorFilter) {
+ mPaint.setColorFilter(colorFilter);
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+} \ No newline at end of file
diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java
index 2b9e7b6e1..f6da01439 100644
--- a/src/com/android/launcher3/views/FloatingIconView.java
+++ b/src/com/android/launcher3/views/FloatingIconView.java
@@ -43,7 +43,9 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.FolderShape;
+import com.android.launcher3.graphics.ShiftedBitmapDrawable;
import com.android.launcher3.icons.LauncherIcons;
import androidx.annotation.Nullable;
@@ -57,6 +59,8 @@ import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANI
public class FloatingIconView extends View implements Animator.AnimatorListener, ClipPathView {
+ private static final Rect sTmpRect = new Rect();
+
private Runnable mStartRunnable;
private Runnable mEndRunnable;
@@ -181,7 +185,7 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
}
@WorkerThread
- private void getIcon(Launcher launcher, ItemInfo info, boolean useDrawableAsIs,
+ private void getIcon(Launcher launcher, View v, ItemInfo info, boolean useDrawableAsIs,
float aspectRatio) {
final LayoutParams lp = (LayoutParams) getLayoutParams();
mDrawable = Utilities.getFullDrawable(launcher, info, lp.width, lp.height, new Object[1]);
@@ -205,6 +209,12 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
int offset = getOffsetForAdaptiveIconBounds();
mFinalDrawableBounds.set(offset, offset, lp.width - offset, mOriginalHeight - offset);
+ if (mForeground instanceof ShiftedBitmapDrawable && v instanceof FolderIcon) {
+ ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
+ ((FolderIcon) v).getPreviewBounds(sTmpRect);
+ sbd.setShiftX(sbd.getShiftX() - sTmpRect.left);
+ sbd.setShiftY(sbd.getShiftY() - sTmpRect.top);
+ }
mForeground.setBounds(mFinalDrawableBounds);
mBackground.setBounds(mFinalDrawableBounds);
@@ -323,8 +333,8 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
// Must be called after matchPositionOf so that we know what size to load.
if (originalView.getTag() instanceof ItemInfo) {
new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(() -> {
- view.getIcon(launcher, (ItemInfo) originalView.getTag(), useDrawableAsIs,
- aspectRatio);
+ view.getIcon(launcher, originalView, (ItemInfo) originalView.getTag(),
+ useDrawableAsIs, aspectRatio);
});
}