mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 11:18:21 +00:00
Folder support in Taskbar
- Add TaskbarActivityContext which allows shared Launcher elements to "just work" using existing generic ActivityContext. - TaskbarContainerView extends BaseDragLayer<TaskbarActivityContext>. - Inflate FolderIcon and Folder using TaskbarActivityContext to be shown in TaskbarContainerView. - Use TaskbarActivityContext's DeviceProfile to determine icon size instead of overriding in styles. This also ensures that normal BubbleTextView icons have the same size as FolderIcons. Test: Place a folder in home screen hotseat, ensure it shows up in taskbar and can be opened, and that apps inside it can be launched or dragged. Bug: 171917176 Change-Id: Ic25d2f84bcd7e3399c88989305ea565497c030d9
This commit is contained in:
@@ -22,7 +22,6 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.DragEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
@@ -32,10 +31,14 @@ import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.systemui.shared.recents.model.Task;
|
||||
|
||||
/**
|
||||
@@ -51,6 +54,9 @@ public class TaskbarView extends LinearLayout {
|
||||
private final RectF mDelegateSlopBounds = new RectF();
|
||||
private final int[] mTempOutLocation = new int[2];
|
||||
|
||||
// Initialized in TaskbarController constructor.
|
||||
private TaskbarController.TaskbarViewCallbacks mControllerCallbacks;
|
||||
|
||||
// Initialized in init().
|
||||
private int mHotseatStartIndex;
|
||||
private int mHotseatEndIndex;
|
||||
@@ -58,8 +64,6 @@ public class TaskbarView extends LinearLayout {
|
||||
private int mRecentsStartIndex;
|
||||
private int mRecentsEndIndex;
|
||||
|
||||
private TaskbarController.TaskbarViewCallbacks mControllerCallbacks;
|
||||
|
||||
// Delegate touches to the closest view if within mIconTouchSize.
|
||||
private boolean mDelegateTargeted;
|
||||
private View mDelegateView;
|
||||
@@ -90,7 +94,7 @@ public class TaskbarView extends LinearLayout {
|
||||
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
}
|
||||
|
||||
protected void setCallbacks(TaskbarController.TaskbarViewCallbacks taskbarViewCallbacks) {
|
||||
protected void construct(TaskbarController.TaskbarViewCallbacks taskbarViewCallbacks) {
|
||||
mControllerCallbacks = taskbarViewCallbacks;
|
||||
}
|
||||
|
||||
@@ -130,17 +134,37 @@ public class TaskbarView extends LinearLayout {
|
||||
|
||||
// Replace any Hotseat views with the appropriate type if it's not already that type.
|
||||
final int expectedLayoutResId;
|
||||
boolean isFolder = false;
|
||||
boolean needsReinflate = false;
|
||||
if (hotseatItemInfo != null && hotseatItemInfo.isPredictedItem()) {
|
||||
expectedLayoutResId = R.layout.taskbar_predicted_app_icon;
|
||||
} else if (hotseatItemInfo instanceof FolderInfo) {
|
||||
expectedLayoutResId = R.layout.folder_icon;
|
||||
isFolder = true;
|
||||
// Unlike for BubbleTextView, we can't reapply a new FolderInfo after inflation, so
|
||||
// if the info changes we need to reinflate. This should only happen if a new folder
|
||||
// is dragged to the position that another folder previously existed.
|
||||
needsReinflate = hotseatView != null && hotseatView.getTag() != hotseatItemInfo;
|
||||
} else {
|
||||
expectedLayoutResId = R.layout.taskbar_app_icon;
|
||||
}
|
||||
if (hotseatView == null || hotseatView.getSourceLayoutResId() != expectedLayoutResId) {
|
||||
if (hotseatView == null || hotseatView.getSourceLayoutResId() != expectedLayoutResId
|
||||
|| needsReinflate) {
|
||||
removeView(hotseatView);
|
||||
BubbleTextView btv = (BubbleTextView) inflate(expectedLayoutResId);
|
||||
LayoutParams lp = new LayoutParams(btv.getIconSize(), btv.getIconSize());
|
||||
TaskbarActivityContext activityContext =
|
||||
ActivityContext.lookupContext(getContext());
|
||||
if (isFolder) {
|
||||
FolderInfo folderInfo = (FolderInfo) hotseatItemInfo;
|
||||
FolderIcon folderIcon = FolderIcon.inflateFolderAndIcon(expectedLayoutResId,
|
||||
activityContext, this, folderInfo);
|
||||
folderIcon.setTextVisible(false);
|
||||
hotseatView = folderIcon;
|
||||
} else {
|
||||
hotseatView = inflate(expectedLayoutResId);
|
||||
}
|
||||
int iconSize = activityContext.getDeviceProfile().iconSizePx;
|
||||
LayoutParams lp = new LayoutParams(iconSize, iconSize);
|
||||
lp.setMargins(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
|
||||
hotseatView = btv;
|
||||
addView(hotseatView, hotseatIndex, lp);
|
||||
}
|
||||
|
||||
@@ -153,6 +177,11 @@ public class TaskbarView extends LinearLayout {
|
||||
hotseatView.setOnClickListener(mControllerCallbacks.getItemOnClickListener());
|
||||
hotseatView.setOnLongClickListener(
|
||||
mControllerCallbacks.getItemOnLongClickListener());
|
||||
} else if (isFolder) {
|
||||
hotseatView.setVisibility(VISIBLE);
|
||||
hotseatView.setOnClickListener(mControllerCallbacks.getItemOnClickListener());
|
||||
hotseatView.setOnLongClickListener(
|
||||
mControllerCallbacks.getItemOnLongClickListener());
|
||||
} else {
|
||||
hotseatView.setVisibility(GONE);
|
||||
hotseatView.setOnClickListener(null);
|
||||
@@ -345,6 +374,7 @@ public class TaskbarView extends LinearLayout {
|
||||
switch (event.getAction()) {
|
||||
case DragEvent.ACTION_DRAG_STARTED:
|
||||
mIsDraggingItem = true;
|
||||
AbstractFloatingView.closeAllOpenViews(ActivityContext.lookupContext(getContext()));
|
||||
return true;
|
||||
case DragEvent.ACTION_DRAG_ENDED:
|
||||
mIsDraggingItem = false;
|
||||
@@ -358,6 +388,7 @@ public class TaskbarView extends LinearLayout {
|
||||
}
|
||||
|
||||
private View inflate(@LayoutRes int layoutResId) {
|
||||
return LayoutInflater.from(getContext()).inflate(layoutResId, this, false);
|
||||
TaskbarActivityContext taskbarActivityContext = ActivityContext.lookupContext(getContext());
|
||||
return taskbarActivityContext.getLayoutInflater().inflate(layoutResId, this, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user