Hybrid hotseat predicted icon visuals
Bug:142753423
Test: Manual
Change-Id: I6f056aaec905c8ca357b7cf78a657cdaac84e2f1
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 976ccd5..89bec98 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -110,7 +110,7 @@
private OnTouchListener mInterceptTouchListener;
- private final ArrayList<PreviewBackground> mFolderBackgrounds = new ArrayList<>();
+ private final ArrayList<DelegatedCellDrawing> mDelegatedCellDrawings = new ArrayList<>();
final PreviewBackground mFolderLeaveBehind = new PreviewBackground();
private static final int[] BACKGROUND_STATE_ACTIVE = new int[] { android.R.attr.state_active };
@@ -219,8 +219,8 @@
mPreviousReorderDirection[0] = INVALID_DIRECTION;
mPreviousReorderDirection[1] = INVALID_DIRECTION;
- mFolderLeaveBehind.delegateCellX = -1;
- mFolderLeaveBehind.delegateCellY = -1;
+ mFolderLeaveBehind.mDelegateCellX = -1;
+ mFolderLeaveBehind.mDelegateCellY = -1;
setAlwaysDrawnWithCacheEnabled(false);
final Resources res = getResources();
@@ -466,21 +466,18 @@
}
}
- for (int i = 0; i < mFolderBackgrounds.size(); i++) {
- PreviewBackground bg = mFolderBackgrounds.get(i);
- cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation);
+ for (int i = 0; i < mDelegatedCellDrawings.size(); i++) {
+ DelegatedCellDrawing cellDrawing = mDelegatedCellDrawings.get(i);
+ cellToPoint(cellDrawing.mDelegateCellX, cellDrawing.mDelegateCellY, mTempLocation);
canvas.save();
canvas.translate(mTempLocation[0], mTempLocation[1]);
- bg.drawBackground(canvas);
- if (!bg.isClipping) {
- bg.drawBackgroundStroke(canvas);
- }
+ cellDrawing.drawUnderItem(canvas);
canvas.restore();
}
- if (mFolderLeaveBehind.delegateCellX >= 0 && mFolderLeaveBehind.delegateCellY >= 0) {
- cellToPoint(mFolderLeaveBehind.delegateCellX,
- mFolderLeaveBehind.delegateCellY, mTempLocation);
+ if (mFolderLeaveBehind.mDelegateCellX >= 0 && mFolderLeaveBehind.mDelegateCellY >= 0) {
+ cellToPoint(mFolderLeaveBehind.mDelegateCellX,
+ mFolderLeaveBehind.mDelegateCellY, mTempLocation);
canvas.save();
canvas.translate(mTempLocation[0], mTempLocation[1]);
mFolderLeaveBehind.drawLeaveBehind(canvas);
@@ -492,23 +489,28 @@
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
- for (int i = 0; i < mFolderBackgrounds.size(); i++) {
- PreviewBackground bg = mFolderBackgrounds.get(i);
- if (bg.isClipping) {
- cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation);
- canvas.save();
- canvas.translate(mTempLocation[0], mTempLocation[1]);
- bg.drawBackgroundStroke(canvas);
- canvas.restore();
- }
+ for (int i = 0; i < mDelegatedCellDrawings.size(); i++) {
+ DelegatedCellDrawing bg = mDelegatedCellDrawings.get(i);
+ cellToPoint(bg.mDelegateCellX, bg.mDelegateCellY, mTempLocation);
+ canvas.save();
+ canvas.translate(mTempLocation[0], mTempLocation[1]);
+ bg.drawOverItem(canvas);
+ canvas.restore();
}
}
- public void addFolderBackground(PreviewBackground bg) {
- mFolderBackgrounds.add(bg);
+ /**
+ * Add Delegated cell drawing
+ */
+ public void addDelegatedCellDrawing(DelegatedCellDrawing bg) {
+ mDelegatedCellDrawings.add(bg);
}
- public void removeFolderBackground(PreviewBackground bg) {
- mFolderBackgrounds.remove(bg);
+
+ /**
+ * Remove item from DelegatedCellDrawings
+ */
+ public void removeDelegatedCellDrawing(DelegatedCellDrawing bg) {
+ mDelegatedCellDrawings.remove(bg);
}
public void setFolderLeaveBehindCell(int x, int y) {
@@ -516,14 +518,14 @@
mFolderLeaveBehind.setup(getContext(), mActivity, null,
child.getMeasuredWidth(), child.getPaddingTop());
- mFolderLeaveBehind.delegateCellX = x;
- mFolderLeaveBehind.delegateCellY = y;
+ mFolderLeaveBehind.mDelegateCellX = x;
+ mFolderLeaveBehind.mDelegateCellY = y;
invalidate();
}
public void clearFolderLeaveBehind() {
- mFolderLeaveBehind.delegateCellX = -1;
- mFolderLeaveBehind.delegateCellY = -1;
+ mFolderLeaveBehind.mDelegateCellX = -1;
+ mFolderLeaveBehind.mDelegateCellY = -1;
invalidate();
}
@@ -2744,6 +2746,24 @@
}
/**
+ * A Delegated cell Drawing for drawing on CellLayout
+ */
+ public abstract static class DelegatedCellDrawing {
+ public int mDelegateCellX;
+ public int mDelegateCellY;
+
+ /**
+ * Draw under CellLayout
+ */
+ public abstract void drawUnderItem(Canvas canvas);
+
+ /**
+ * Draw over CellLayout
+ */
+ public abstract void drawOverItem(Canvas canvas);
+ }
+
+ /**
* Returns whether an item can be placed in this CellLayout (after rearranging and/or resizing
* if necessary).
*/
diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java
index b2c0ca7..2d177d2 100644
--- a/src/com/android/launcher3/folder/PreviewBackground.java
+++ b/src/com/android/launcher3/folder/PreviewBackground.java
@@ -48,7 +48,7 @@
* This object represents a FolderIcon preview background. It stores drawing / measurement
* information, handles drawing, and animation (accept state <--> rest state).
*/
-public class PreviewBackground {
+public class PreviewBackground extends CellLayout.DelegatedCellDrawing {
private static final int CONSUMPTION_ANIMATION_DURATION = 100;
@@ -76,8 +76,6 @@
int basePreviewOffsetY;
private CellLayout mDrawingDelegate;
- public int delegateCellX;
- public int delegateCellY;
// When the PreviewBackground is drawn under an icon (for creating a folder) the border
// should not occlude the icon
@@ -124,6 +122,27 @@
}
};
+ /**
+ * Draws folder background under cell layout
+ */
+ @Override
+ public void drawUnderItem(Canvas canvas) {
+ drawBackground(canvas);
+ if (!isClipping) {
+ drawBackgroundStroke(canvas);
+ }
+ }
+
+ /**
+ * Draws folder background on cell layout
+ */
+ @Override
+ public void drawOverItem(Canvas canvas) {
+ if (isClipping) {
+ drawBackgroundStroke(canvas);
+ }
+ }
+
public void setup(Context context, ActivityContext activity, View invalidateDelegate,
int availableSpaceX, int topPadding) {
mInvalidateDelegate = invalidateDelegate;
@@ -317,19 +336,19 @@
private void delegateDrawing(CellLayout delegate, int cellX, int cellY) {
if (mDrawingDelegate != delegate) {
- delegate.addFolderBackground(this);
+ delegate.addDelegatedCellDrawing(this);
}
mDrawingDelegate = delegate;
- delegateCellX = cellX;
- delegateCellY = cellY;
+ mDelegateCellX = cellX;
+ mDelegateCellY = cellY;
invalidate();
}
private void clearDrawingDelegate() {
if (mDrawingDelegate != null) {
- mDrawingDelegate.removeFolderBackground(this);
+ mDrawingDelegate.removeDelegatedCellDrawing(this);
}
mDrawingDelegate = null;
@@ -395,8 +414,8 @@
// is saved and restored at the beginning of the animation, since cancelling the
// existing animation can clear the delgate.
CellLayout cl = mDrawingDelegate;
- int cellX = delegateCellX;
- int cellY = delegateCellY;
+ int cellX = mDelegateCellX;
+ int cellY = mDelegateCellY;
animateScale(1f, 1f, () -> delegateDrawing(cl, cellX, cellY), this::clearDrawingDelegate);
}