Draw folder leave-behind when opening folder in taskbar
Previously there was only support for CellLayout to draw the leave-behind. Added FolderIconParent interface so any parent can draw the leave-behind, and implement that by TaskbarView. Test: Open folder in Taskber, ensure leave-behind draws Bug: 171917176 Change-Id: I08d1d939a34f971f893994fe05cac972d165ef53
This commit is contained in:
1 parent
7ba547cd2d
commit
bb4de85c25
3 files changed
+72
-18
No files matched your search
@@ -17,6 +17,7 @@ package com.android.launcher3.taskbar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -44,7 +45,7 @@ import com.android.systemui.shared.recents.model.Task;
|
||||
/**
|
||||
* Hosts the Taskbar content such as Hotseat and Recent Apps. Drawn on top of other apps.
|
||||
*/
|
||||
public class TaskbarView extends LinearLayout {
|
||||
public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconParent {
|
||||
|
||||
private final ColorDrawable mBackgroundDrawable;
|
||||
private final int mItemMarginLeftRight;
|
||||
@@ -69,6 +70,8 @@ public class TaskbarView extends LinearLayout {
|
||||
private View mDelegateView;
|
||||
|
||||
private boolean mIsDraggingItem;
|
||||
// Only non-null when the corresponding Folder is open.
|
||||
private @Nullable FolderIcon mLeaveBehindFolderIcon;
|
||||
|
||||
public TaskbarView(@NonNull Context context) {
|
||||
this(context, null);
|
||||
@@ -387,6 +390,33 @@ public class TaskbarView extends LinearLayout {
|
||||
return mIsDraggingItem;
|
||||
}
|
||||
|
||||
// FolderIconParent implemented methods.
|
||||
|
||||
@Override
|
||||
public void drawFolderLeaveBehindForIcon(FolderIcon child) {
|
||||
mLeaveBehindFolderIcon = child;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearFolderLeaveBehind(FolderIcon child) {
|
||||
mLeaveBehindFolderIcon = null;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
// End FolderIconParent implemented methods.
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mLeaveBehindFolderIcon != null) {
|
||||
canvas.save();
|
||||
canvas.translate(mLeaveBehindFolderIcon.getLeft(), mLeaveBehindFolderIcon.getTop());
|
||||
mLeaveBehindFolderIcon.getFolderBackground().drawLeaveBehind(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
private View inflate(@LayoutRes int layoutResId) {
|
||||
TaskbarActivityContext taskbarActivityContext = ActivityContext.lookupContext(getContext());
|
||||
return taskbarActivityContext.getLayoutInflater().inflate(layoutResId, this, false);
|
||||
|
||||
@@ -26,10 +26,11 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.launcher3.CellLayout.ContainerType;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
||||
|
||||
public class ShortcutAndWidgetContainer extends ViewGroup {
|
||||
public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.FolderIconParent {
|
||||
static final String TAG = "ShortcutAndWidgetContainer";
|
||||
|
||||
// These are temporary variables to prevent having to allocate a new object just to
|
||||
@@ -228,4 +229,24 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
|
||||
child.cancelLongPress();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFolderLeaveBehindForIcon(FolderIcon child) {
|
||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
||||
// While the folder is open, the position of the icon cannot change.
|
||||
lp.canReorder = false;
|
||||
if (mContainerType == CellLayout.HOTSEAT) {
|
||||
CellLayout cl = (CellLayout) getParent();
|
||||
cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearFolderLeaveBehind(FolderIcon child) {
|
||||
((CellLayout.LayoutParams) child.getLayoutParams()).canReorder = true;
|
||||
if (mContainerType == CellLayout.HOTSEAT) {
|
||||
CellLayout cl = (CellLayout) getParent();
|
||||
cl.clearFolderLeaveBehind();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -754,26 +754,14 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
}
|
||||
|
||||
public void clearLeaveBehindIfExists() {
|
||||
if (!(getLayoutParams() instanceof CellLayout.LayoutParams)) {
|
||||
return;
|
||||
}
|
||||
((CellLayout.LayoutParams) getLayoutParams()).canReorder = true;
|
||||
if (isInHotseat()) {
|
||||
CellLayout cl = (CellLayout) getParent().getParent();
|
||||
cl.clearFolderLeaveBehind();
|
||||
if (getParent() instanceof FolderIconParent) {
|
||||
((FolderIconParent) getParent()).clearFolderLeaveBehind(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawLeaveBehindIfExists() {
|
||||
if (!(getLayoutParams() instanceof CellLayout.LayoutParams)) {
|
||||
return;
|
||||
}
|
||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
|
||||
// While the folder is open, the position of the icon cannot change.
|
||||
lp.canReorder = false;
|
||||
if (isInHotseat()) {
|
||||
CellLayout cl = (CellLayout) getParent().getParent();
|
||||
cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
|
||||
if (getParent() instanceof FolderIconParent) {
|
||||
((FolderIconParent) getParent()).drawFolderLeaveBehindForIcon(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -842,4 +830,19 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
MAX_NUM_ITEMS_IN_PREVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface that provides callbacks to a parent ViewGroup that hosts this FolderIcon.
|
||||
*/
|
||||
public interface FolderIconParent {
|
||||
/**
|
||||
* Tells the FolderIconParent to draw a "leave-behind" when the Folder is open and leaving a
|
||||
* gap where the FolderIcon would be when the Folder is closed.
|
||||
*/
|
||||
void drawFolderLeaveBehindForIcon(FolderIcon child);
|
||||
/**
|
||||
* Tells the FolderIconParent to stop drawing the "leave-behind" as the Folder is closed.
|
||||
*/
|
||||
void clearFolderLeaveBehind(FolderIcon child);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user