Commit ddb87c8e authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Add createFolder and addToFolder methods

parent a5627361
Pipeline #122588 passed with stage
in 8 minutes and 15 seconds
......@@ -35,6 +35,7 @@ import foundation.e.blisslauncher.core.database.model.ShortcutItem;
import foundation.e.blisslauncher.core.touch.ItemClickHandler;
import foundation.e.blisslauncher.core.touch.ItemLongClickListener;
import foundation.e.blisslauncher.core.utils.Constants;
import foundation.e.blisslauncher.core.utils.GraphicsUtil;
import foundation.e.blisslauncher.core.utils.LongArrayMap;
import foundation.e.blisslauncher.features.launcher.Hotseat;
import foundation.e.blisslauncher.features.test.Alarm;
......@@ -1101,10 +1102,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
@Override
public void onDrop(DragObject d, DragOptions options) {
Log.d(
TAG,
"onDrop() called with: dragObject = [" + d + "], options = [" + options + "]"
);
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
CellLayout dropTargetLayout = mDropToLayout;
......@@ -1152,17 +1149,14 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
// If the item being dropped is a shortcut and the nearest drop
// cell also contains a shortcut, then create a folder with the two shortcuts.
//TODO: uncomment when adding folder support.
/*if (createUserFolderIfNecessary(cell, container,
if (createUserFolderIfNecessary(cell, container,
dropTargetLayout, mTargetCell, distance, false, d.dragView
) ||
addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell,
distance, d, false
)) {
mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
return;
}*/
}
// Aside from the special case where we're dropping a shortcut onto a shortcut,
// we need to find the nearest cell location that is vacant
......@@ -1269,6 +1263,112 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
}
}
boolean createUserFolderIfNecessary(
View newView, long container, CellLayout target,
int[] targetCell, float distance, boolean external, DragView dragView
) {
if (distance > mMaxDistanceForFolderCreation) return false;
View v = target.getChildAt(targetCell[0], targetCell[1]);
boolean hasntMoved = false;
if (mDragInfo != null) {
CellLayout cellParent = getParentCellLayoutForView(mDragInfo.getCell());
hasntMoved = (mDragInfo.getRank() % cellParent.getMCountX() == targetCell[0] &&
mDragInfo.getRank() / cellParent
.getMCountX() == targetCell[1]) && (cellParent == target);
}
if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false;
mCreateUserFolderOnDrop = false;
final long screenId = getIdForScreen(target);
boolean aboveShortcut =
(v.getTag() instanceof ApplicationItem) || (v.getTag() instanceof ShortcutItem);
boolean willBecomeShortcut =
(v.getTag() instanceof ApplicationItem) || (v.getTag() instanceof ShortcutItem);
if (aboveShortcut && willBecomeShortcut) {
LauncherItem sourceItem = (LauncherItem) newView.getTag();
LauncherItem destItem = (LauncherItem) v.getTag();
Rect folderLocation = new Rect();
target.removeView(v);
FolderItem fi = new FolderItem();
fi.title = getResources().getString(R.string.untitled);
fi.id = String.valueOf(System.currentTimeMillis());
fi.items = new ArrayList<>();
sourceItem.container = Long.parseLong(fi.id);
destItem.container = Long.parseLong(fi.id);
sourceItem.screenId = -1;
destItem.screenId = -1;
sourceItem.cell = fi.items.size();
fi.items.add(sourceItem);
destItem.cell = fi.items.size();
fi.items.add(destItem);
Drawable folderIcon = new GraphicsUtil(getContext()).generateFolderIcon(getContext(),
sourceItem.icon, destItem.icon
);
fi.icon = folderIcon;
fi.container = container;
fi.screenId = screenId;
fi.cell = targetCell[1] * mLauncher.getDeviceProfile().getInv()
.getNumColumns() + targetCell[0];
IconTextView folderView = (IconTextView) LayoutInflater.from(getContext())
.inflate(R.layout.app_icon, null, false);
folderView.applyFromShortcutItem(fi);
folderView.setOnClickListener(ItemClickHandler.INSTANCE);
folderView.setOnLongClickListener(ItemLongClickListener.INSTANCE_WORKSPACE);
addInScreen(folderView, fi);
// if the drag started here, we need to remove it from the workspace
if (!external) {
getParentCellLayoutForView(mDragInfo.getCell()).removeView(mDragInfo.getCell());
}
//Add animation here.
dragView.remove();
dragView = null;
invalidate();
return true;
}
return false;
}
private void addInScreen(IconTextView child, LauncherItem item) {
addInScreen(child, item.container, item.screenId, item.cell);
}
boolean addToExistingFolderIfNecessary(
View newView, CellLayout target, int[] targetCell,
float distance, DragObject d, boolean external
) {
if (distance > mMaxDistanceForFolderCreation) return false;
View dropOverView = target.getChildAt(targetCell[0], targetCell[1]);
if (!mAddToExistingFolderOnDrop) return false;
mAddToExistingFolderOnDrop = false;
if ((dropOverView instanceof IconTextView) && (dropOverView
.getTag() instanceof FolderItem)) {
FolderItem fi = (FolderItem) dropOverView.getTag();
LauncherItem sourceItem = (LauncherItem) newView.getTag();
sourceItem.container = Long.parseLong(fi.id);
sourceItem.screenId = -1;
sourceItem.cell = fi.items.size();
fi.items.add(sourceItem);
fi.icon = new GraphicsUtil(getContext()).generateFolderIcon(getContext(), fi);
((IconTextView) dropOverView).applyFromShortcutItem(fi);
// if the drag started here, we need to remove it from the workspace
if (!external) {
getParentCellLayoutForView(mDragInfo.getCell()).removeView(mDragInfo.getCell());
}
//Add animation here.
d.dragView.remove();
d.dragView = null;
invalidate();
return true;
}
return false;
}
public void onNoCellFound(View dropTargetLayout) {
Log.d(TAG, "onNoCellFound() called with: dropTargetLayout = [" + dropTargetLayout + "]");
if (mLauncher.isHotseatLayout(dropTargetLayout)) {
......@@ -1403,7 +1503,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
}
private void cleanupFolderCreation() {
if(parentFolderCell != null) {
if (parentFolderCell != null) {
parentFolderCell.setScaleX(1f);
parentFolderCell.setScaleY(1f);
}
......@@ -1615,10 +1715,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
}
public void startDrag(CellLayout.CellInfo cellInfo, DragOptions dragOptions) {
Log.d(
TAG,
"startDrag() called with: longClickCellInfo = [" + cellInfo + "], dragOptions = [" + dragOptions + "]"
);
View child = cellInfo.getCell();
mDragInfo = cellInfo;
child.setVisibility(GONE);
......@@ -1629,7 +1725,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
Object dragObject = child.getTag();
if (!(dragObject instanceof LauncherItem)) {
String msg = "Drag started with a view that has no tag set. This "
+ "will cause a crash (issue 11627249) down the line. "
+ "will cause a crash down the line. "
+ "View: " + child + " tag: " + child.getTag();
throw new IllegalStateException(msg);
}
......@@ -1667,6 +1763,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
int dragLayerX = mTempXY[0];
int dragLayerY = mTempXY[1];
Log.i(TAG, "beginDragShared: " + dragLayerY);
VariantDeviceProfile grid = mLauncher.getDeviceProfile();
Point dragVisualizeOffset = null;
Rect dragRect = null;
......@@ -1674,6 +1772,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
dragRect =
((IconTextView) child).getIconBounds();
dragLayerY += dragRect.top;
Log.i(TAG, "beginDragShared: " + dragLayerY + " " + dragRect);
// Note: The dragRect is used to calculate drag layer offsets, but the
// dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
dragVisualizeOffset = new Point(-halfPadding, halfPadding);
......@@ -1761,15 +1861,15 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
);
if (distance > mMaxDistanceForFolderCreation) return;
final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[1], mTargetCell[1]);
final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);
LauncherItem info = dragObject.dragInfo;
boolean userFolderPending = willCreateUserFolder(info, dragOverView, false);
Log.i(TAG, "manageFolderFeedback: userFolderPending: "+userFolderPending);
Log.i(TAG, "manageFolderFeedback: userFolderPending: " + userFolderPending);
if (mDragMode == DRAG_MODE_NONE && userFolderPending &&
!mFolderCreationAlarm.alarmPending()) {
FolderCreationAlarmListener listener = new
FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1]);
FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1], true);
if (!dragObject.accessibleDrag) {
mFolderCreationAlarm.setOnAlarmListener(listener);
......@@ -1787,15 +1887,20 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
}
boolean willAddToFolder = willAddToExistingUserFolder(info, dragOverView);
/*if (willAddToFolder && mDragMode == DRAG_MODE_NONE) {
mDragOverFolderIcon = ((FolderIcon) dragOverView);
mDragOverFolderIcon.onDragEnter(info);
if (targetLayout != null) {
targetLayout.clearDragOutlines();
if (willAddToFolder && mDragMode == DRAG_MODE_NONE && !mFolderCreationAlarm
.alarmPending()) {
FolderCreationAlarmListener listener = new
FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1], false);
if (!dragObject.accessibleDrag) {
mFolderCreationAlarm.setOnAlarmListener(listener);
mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT);
} else {
listener.onAlarm(mFolderCreationAlarm);
}
setDragMode(DRAG_MODE_ADD_TO_FOLDER);
return;
}*/
}
if (mDragMode == DRAG_MODE_ADD_TO_FOLDER && !willAddToFolder) {
setDragMode(DRAG_MODE_NONE);
......@@ -1810,13 +1915,19 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
final IconTextView cell;
final int cellX;
final int cellY;
public FolderCreationAlarmListener(CellLayout layout, int cellX, int cellY) {
final boolean createFolder;
public FolderCreationAlarmListener(
CellLayout layout,
int cellX,
int cellY,
boolean createFolder
) {
this.layout = layout;
this.cellX = cellX;
this.cellY = cellY;
this.cell = (IconTextView) layout.getChildAt(cellX, cellY);
this.createFolder = createFolder;
}
public void onAlarm(Alarm alarm) {
......@@ -1824,7 +1935,11 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
parentFolderCell = cell;
parentFolderCell.setScaleX(1.2f);
parentFolderCell.setScaleY(1.2f);
setDragMode(DRAG_MODE_CREATE_FOLDER);
if (createFolder) {
setDragMode(DRAG_MODE_CREATE_FOLDER);
} else {
setDragMode(DRAG_MODE_ADD_TO_FOLDER);
}
}
}
......
......@@ -16,6 +16,7 @@
package foundation.e.blisslauncher.core.touch;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
......@@ -23,6 +24,7 @@ import foundation.e.blisslauncher.core.database.model.ApplicationItem;
import foundation.e.blisslauncher.core.database.model.FolderItem;
import foundation.e.blisslauncher.core.database.model.LauncherItem;
import foundation.e.blisslauncher.core.database.model.ShortcutItem;
import foundation.e.blisslauncher.features.test.IconTextView;
import foundation.e.blisslauncher.features.test.TestActivity;
/**
......@@ -52,11 +54,7 @@ public class ItemClickHandler {
if (tag instanceof ShortcutItem) {
onClickAppShortcut(v, (ShortcutItem) tag, launcher);
} else if (tag instanceof FolderItem) {
//TODO:
/*if (v instanceof FolderIcon) {
onClickFolderIcon(v);
}*/
onClickFolderIcon(v);
} else if (tag instanceof ApplicationItem) {
startAppShortcutOrInfoActivity(v, (ApplicationItem) tag, launcher);
}
......@@ -65,16 +63,16 @@ public class ItemClickHandler {
/**
* Event handler for a folder icon click.
*
* @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
* @param v The view that was clicked. Must be an instance of {@link IconTextView}.
*/
//TODO:
/*private static void onClickFolderIcon(View v) {
Folder folder = ((FolderIcon) v).getFolder();
private static void onClickFolderIcon(View v) {
Log.d("ItemClick", "onClickFolderIcon() called with: v = [" + v + "]");
/*Folder folder = ((FolderIcon) v).getFolder();
if (!folder.isOpen() && !folder.isDestroyed()) {
// Open the requested folder
folder.animateOpen();
}
}*/
}*/
}
/**
* Event handler for the app widget view which has not fully restored.
......
......@@ -15,6 +15,7 @@
*/
package foundation.e.blisslauncher.core.touch;
import android.util.Log;
import android.view.View;
import android.view.View.OnLongClickListener;
......@@ -29,9 +30,16 @@ import foundation.e.blisslauncher.features.test.dragndrop.DragOptions;
public class ItemLongClickListener {
public static OnLongClickListener INSTANCE_WORKSPACE =
ItemLongClickListener::onWorkspaceItemLongClick;
ItemLongClickListener::onWorkspaceItemLongClick;
private static final String TAG = "ItemLongClickListener";
private static boolean onWorkspaceItemLongClick(View v) {
int[] temp = new int[2];
v.getLocationOnScreen(temp);
Log.i(TAG,
"onWorkspaceItemLongClick: [" + v.getLeft() + ", " + v.getTop() + "] ["+temp[0]+", "+temp[1]+"]"
);
TestActivity launcher = TestActivity.Companion.getLauncher(v.getContext());
if (!canStartDrag(launcher)) return false;
//if (!launcher.isInState(NORMAL) && !launcher.isInState(OVERVIEW)) return false;
......@@ -44,7 +52,8 @@ public class ItemLongClickListener {
public static void beginDrag(
View v, TestActivity launcher, LauncherItem info,
DragOptions dragOptions) {
DragOptions dragOptions
) {
//TODO: Enable when supporting folders
/* if (info.container >= 0) {
Folder folder = Folder.getOpen(launcher);
......
......@@ -585,7 +585,6 @@ open class CellLayout @JvmOverloads constructor(
result: IntArray?,
resultSpan: IntArray?
): IntArray? {
var pixelX = pixelX
var pixelY = pixelY
lazyInitTempRectStack()
......@@ -676,7 +675,6 @@ open class CellLayout @JvmOverloads constructor(
validRegions.push(currentRect)
val distance =
hypot((cellXY[0] - pixelX).toDouble(), (cellXY[1] - pixelY).toDouble())
if (distance <= bestDistance && !contained ||
currentRect.contains(bestRect)
) {
......@@ -725,6 +723,7 @@ open class CellLayout @JvmOverloads constructor(
open fun regionToCenterPoint(cellX: Int, cellY: Int, spanX: Int, spanY: Int, result: IntArray) {
val hStartPadding = paddingLeft
val vStartPadding = paddingTop
Log.i(TAG, "regionToCenterPoint: $hStartPadding $vStartPadding")
result[0] = hStartPadding + cellX * cellWidth + spanX * cellWidth / 2
result[1] = vStartPadding + cellY * cellHeight + spanY * cellHeight / 2
}
......@@ -778,6 +777,7 @@ open class CellLayout @JvmOverloads constructor(
fun getChildAt(x: Int, y: Int): View {
return getChildAt(y * mCountX + x)
}
open fun performReorder(
pixelX: Int,
pixelY: Int,
......
......@@ -24,7 +24,6 @@ import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.KeyEvent;
......@@ -81,7 +80,6 @@ public class DragLayer extends BaseDragLayer<TestActivity> {
// Disable multitouch across the workspace/all apps/customize tray
setMotionEventSplittingEnabled(false);
setChildrenDrawingOrderEnabled(true);
setBackgroundColor(Color.BLUE);
}
public void setup(DragController dragController, LauncherPagedView workspace) {
......
......@@ -127,20 +127,17 @@ public class DragView extends View {
// Animate the view into the correct position
mAnim = LauncherAnimUtils.ofFloat(0f, 1f);
mAnim.setDuration(VIEW_ZOOM_DURATION);
mAnim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float value = (Float) animation.getAnimatedValue();
mAnim.addUpdateListener(animation -> {
final float value = (Float) animation.getAnimatedValue();
setScaleX(initialScale + (value * (scale - initialScale)));
setScaleY(initialScale + (value * (scale - initialScale)));
if (sDragAlpha != 1f) {
setAlpha(sDragAlpha * value + (1f - value));
}
setScaleX(initialScale + (value * (scale - initialScale)));
setScaleY(initialScale + (value * (scale - initialScale)));
if (sDragAlpha != 1f) {
setAlpha(sDragAlpha * value + (1f - value));
}
if (getParent() == null) {
animation.cancel();
}
if (getParent() == null) {
animation.cancel();
}
});
......
......@@ -26,6 +26,7 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import java.nio.ByteBuffer;
......@@ -68,6 +69,7 @@ public class DragPreviewProvider {
} else {
previewPadding = blurSizeOutline;
}
Log.i("DragPreview", "PreviewPadding: "+previewPadding);
}
/**
......@@ -123,15 +125,7 @@ public class DragPreviewProvider {
Rect bounds = getDrawableBounds(d);
width = bounds.width();
height = bounds.height();
} /*else if (mView instanceof LauncherAppWidgetHostView) {
float scale = ((LauncherAppWidgetHostView) mView).getScaleToFit();
width = (int) (mView.getWidth() * scale);
height = (int) (mView.getHeight() * scale);
// Use software renderer for widgets as we know that they already work
return BitmapRenderer.createSoftwareBitmap(width + blurSizeOutline,
height + blurSizeOutline, (c) -> drawDragView(c, scale));
}*/
}
return BitmapRenderer.createHardwareBitmap(width + blurSizeOutline,
height + blurSizeOutline, (c) -> drawDragView(c, 1));
......@@ -160,10 +154,14 @@ public class DragPreviewProvider {
public float getScaleAndPosition(Bitmap preview, int[] outPos) {
float scale = TestActivity.Companion.getLauncher(mView.getContext())
.getDragLayer().getLocationInDragLayer(mView, outPos);
Log.i("DragPreview", "getScaleAndPosition: "+outPos[0]+" "+outPos[1]+" "+preview.getWidth()+" "+mView.getWidth());
outPos[0] = Math.round(outPos[0] -
(preview.getWidth() - scale * mView.getWidth() * mView.getScaleX()) / 2);
outPos[1] = Math.round(outPos[1] - (1 - scale) * preview.getHeight() / 2
- previewPadding / 2);
Log.i("DragPreview", "getScaleAndPosition: "+outPos[0]+" "+outPos[1] + " "+scale);
return scale;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment