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
This commit is contained in:
Jon Miranda
2019-03-04 20:16:18 -08:00
parent 34691cffe3
commit 69b35e0195
6 changed files with 104 additions and 40 deletions
+3 -2
View File
@@ -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());
}
@@ -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;
}
}
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
}
@@ -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);
});
}