Commit 21c70343 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Fix drag drop between pages and hotseat

parent 988386f8
Pipeline #109921 failed with stage
in 1 minute and 37 seconds
package foundation.e.blisslauncher.core.customviews;
import static foundation.e.blisslauncher.features.test.anim.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
......@@ -24,6 +22,13 @@ import android.view.View;
import android.view.WindowInsets;
import android.widget.GridLayout;
import android.widget.Toast;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import foundation.e.blisslauncher.BuildConfig;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.customviews.pageindicators.PageIndicatorDots;
......@@ -47,10 +52,8 @@ import foundation.e.blisslauncher.features.test.dragndrop.DragView;
import foundation.e.blisslauncher.features.test.dragndrop.DropTarget;
import foundation.e.blisslauncher.features.test.dragndrop.SpringLoadedDragController;
import foundation.e.blisslauncher.features.test.graphics.DragPreviewProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import static foundation.e.blisslauncher.features.test.anim.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS;
public class LauncherPagedView extends PagedView<PageIndicatorDots> implements View.OnTouchListener,
Insettable, DropTarget, DragSource, DragController.DragListener {
......@@ -271,7 +274,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
GridLayout.LayoutParams iconLayoutParams =
new GridLayout.LayoutParams(rowSpec, colSpec);
iconLayoutParams.setGravity(Gravity.CENTER);
iconLayoutParams.height = mLauncher.getDeviceProfile().getCellHeightPx();
iconLayoutParams.height = mLauncher.getDeviceProfile().getHotseatCellHeightPx();
iconLayoutParams.width = mLauncher.getDeviceProfile().getCellWidthPx();
appView.setLayoutParams(iconLayoutParams);
//appView.setWithText(false);
......@@ -664,10 +667,18 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
* @param y The Y position of the child in the screen's grid.
*/
private void addInScreen(View child, long container, long screenId, int x, int y) {
Log.d(
TAG,
"addInScreen() called with: child = [" + child + "], container = [" + container + "], screenId = [" + screenId + "], x = [" + x + "], y = [" + y + "]"
);
addInScreen(child, container, screenId, y * mLauncher.getDeviceProfile().getInv().getNumColumns() + x);
}
/**
* Adds the specified child in the specified screen. The position and dimension of
* the child are defined by x, y, spanX and spanY.
*
* @param child The child to add in one of the workspace's screens.
* @param screenId The screen in which to add the child.
* @param index The index of the child in grid.
*/
private void addInScreen(View child, long container, long screenId, int index) {
if (container == Constants.CONTAINER_DESKTOP) {
if (getScreenWithId(screenId) == null) {
Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
......@@ -714,7 +725,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
boolean markCellsAsOccupied = true;
if (!layout.addViewToCellLayout(
child,
y * mLauncher.getDeviceProfile().getInv().getNumColumns() + x,
index,
childId,
((CellLayout.LayoutParams) genericLp),
markCellsAsOccupied
......@@ -722,7 +733,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
// TODO: This branch occurs when the workspace is adding views
// outside of the defined grid
// maybe we should be deleting these items from the LauncherModel?
Log.e(TAG, "Failed to add to item at (" + x + "," + y + ") to CellLayout");
}
child.setHapticFeedbackEnabled(false);
......@@ -1196,11 +1206,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
onNoCellFound(dropTargetLayout);
// If we can't find a drop location, we return the item to its original position
/*CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
mTargetCell[0] = lp.cellX;
mTargetCell[1] = lp.cellY;
CellLayout layout = (CellLayout) cell.getParent().getParent();
layout.markCellsAsOccupiedForView(cell);*/
addInScreen(cell, mDragInfo.getContainer(), mDragInfo.getScreenId(), mDragInfo.getRank());
}
}
......@@ -1247,6 +1253,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
@Override
public void onDragEnter(DragObject dragObject) {
Log.d(TAG, "onDragEnter() called with: dragObject = [" + dragObject + "]");
mCreateUserFolderOnDrop = false;
mAddToExistingFolderOnDrop = false;
......
......@@ -115,7 +115,8 @@ open class CellLayout @JvmOverloads constructor(
init {
val a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyleAttr, 0)
mContainerType = a.getInteger(R.styleable.CellLayout_containerType, CellLayout.WORKSPACE)
mContainerType = a.getInteger(R.styleable.CellLayout_containerType, WORKSPACE)
Log.i(TAG, "Container type: $mContainerType")
a.recycle()
setWillNotDraw(false)
......@@ -288,13 +289,14 @@ open class CellLayout @JvmOverloads constructor(
// Hotseat icons - remove text
if (child is IconTextView) {
val bubbleChild: IconTextView = child
bubbleChild.setTextVisibility(mContainerType != HOTSEAT)
}
child.scaleX = 1f
child.scaleY = 1f
Log.d(TAG, "Adding view at index: ")
Log.d(TAG, "Adding view at index: $mContainerType")
// Generate an id for each view, this assumes we have at most 256x256 cells
// per workspace screen
......@@ -700,13 +702,8 @@ open class CellLayout @JvmOverloads constructor(
}
}
validRegions.push(currentRect)
Log.d(TAG, "Current Cell: [$x, $y] ")
Log.d(TAG, "Current Cell Center: [" + cellXY[0] + ", " + cellXY[1] + "] ")
Log.d(TAG, "Pixel Center: [" + pixelX + ", " + pixelY + "] ")
val distance =
hypot((cellXY[0] - pixelX).toDouble(), (cellXY[1] - pixelY).toDouble())
Log.d(TAG, "Distance: " + distance)
if (distance <= bestDistance && !contained ||
currentRect.contains(bestRect)
......@@ -842,15 +839,33 @@ open class CellLayout @JvmOverloads constructor(
if (mode == MODE_DRAG_OVER || mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL) {
val parent = (dragView?.parent as ViewGroup?)
parent?.removeView(dragView)
if (childCount == mCountX * mCountY) {
return intArrayOf(-1, -1)
}
var index = result[1] * mCountX + result[0]
Log.d("REORDER", "Index: " + index + " " + rowCount + " " + columnCount)
Log.d(
"REORDER",
"Index: $index $rowCount == $mCountX $columnCount == $mCountY ${result[0]} ${result[1]}"
)
// Handles the case when the icon is being dragged after the last item on the grid.
if (index > childCount) {
index = childCount
}
//appView.findViewById(R.id.app_label).setVisibility(GONE);
val rowSpec = spec(UNDEFINED)
val colSpec = spec(UNDEFINED)
val iconLayoutParams = LayoutParams(rowSpec, colSpec)
//iconLayoutParams.setGravity(Gravity.CENTER)
iconLayoutParams.height = if (mContainerType == HOTSEAT)
dp.hotseatCellHeightPx else dp.cellHeightPx
iconLayoutParams.width = dp.cellWidthPx
dragView?.also {
if(it is IconTextView) it.setTextVisibility(mContainerType != HOTSEAT)
}
dragView?.setLayoutParams(iconLayoutParams)
addView(dragView, index)
/*copySolutionToTempState(finalSolution, dragView)
......
<?xml version="1.0" encoding="utf-8"?>
<foundation.e.blisslauncher.features.test.LauncherRootView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:launcher="http://schemas.android.com/tools"
xmlns:launcher="http://schemas.android.com/apk/res-auto"
android:id="@+id/launcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
......
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