use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by ArrowOS.
the class PagedView method getNeighbourPageIndices.
/**
* Returns an IntSet with the indices of the neighbour pages that are in the focus direction.
*/
private IntSet getNeighbourPageIndices(int focus) {
int panelCount = getPanelCount();
// getNextPage is more reliable than getCurrentPage
int currentPage = getNextPage();
int nextPage;
if (focus == View.FOCUS_LEFT) {
nextPage = currentPage - panelCount;
} else if (focus == View.FOCUS_RIGHT) {
nextPage = currentPage + panelCount;
} else {
// no neighbours to other directions
return new IntSet();
}
nextPage = validateNewPage(nextPage);
if (nextPage == currentPage) {
// We reached the end of the pages
return new IntSet();
}
return getPageIndices(nextPage);
}
use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by ArrowOS.
the class KeyboardDragAndDropView method getNextSelection.
/**
* Focus finding logic:
* Collect all virtual nodes in reading order (used for forward and backwards).
* Then find the closest view by comparing the distances spatially. Since it is a move
* operation. consider all cell sizes to be approximately of the same size.
*/
private VirtualNodeInfo getNextSelection(int direction) {
// Collect all virtual nodes
mDelegates.clear();
mNodes.clear();
Folder openFolder = Folder.getOpen(mLauncher);
PagedView pv = openFolder == null ? mLauncher.getWorkspace() : openFolder.getContent();
int count = pv.getPageCount();
for (int i = 0; i < count; i++) {
mDelegates.add(((CellLayout) pv.getChildAt(i)).getDragAndDropAccessibilityDelegate());
}
if (openFolder == null) {
mDelegates.add(pv.getNextPage() + 1, mLauncher.getHotseat().getDragAndDropAccessibilityDelegate());
}
mDelegates.forEach(delegate -> {
mIntList.clear();
delegate.getVisibleVirtualViews(mIntList);
mIntList.forEach(id -> mNodes.add(new VirtualNodeInfo(delegate, id)));
});
if (mNodes.isEmpty()) {
return null;
}
int index = mNodes.indexOf(mCurrentSelection);
if (mCurrentSelection == null || index < 0) {
return null;
}
int totalNodes = mNodes.size();
final ToIntBiFunction<Rect, Rect> majorAxis;
final ToIntFunction<Rect> minorAxis;
switch(direction) {
case View.FOCUS_RIGHT:
majorAxis = (source, dest) -> dest.left - source.left;
minorAxis = Rect::centerY;
break;
case View.FOCUS_LEFT:
majorAxis = (source, dest) -> source.left - dest.left;
minorAxis = Rect::centerY;
break;
case View.FOCUS_UP:
majorAxis = (source, dest) -> source.top - dest.top;
minorAxis = Rect::centerX;
break;
case View.FOCUS_DOWN:
majorAxis = (source, dest) -> dest.top - source.top;
minorAxis = Rect::centerX;
break;
case View.FOCUS_FORWARD:
return mNodes.get((index + 1) % totalNodes);
case View.FOCUS_BACKWARD:
return mNodes.get((index + totalNodes - 1) % totalNodes);
default:
// Unknown direction
return null;
}
mCurrentSelection.populate(mTempNodeInfo).getBoundsInScreen(mTempRect);
float minWeight = Float.MAX_VALUE;
VirtualNodeInfo match = null;
for (int i = 0; i < totalNodes; i++) {
VirtualNodeInfo node = mNodes.get(i);
node.populate(mTempNodeInfo).getBoundsInScreen(mTempRect2);
int majorAxisWeight = majorAxis.applyAsInt(mTempRect, mTempRect2);
if (majorAxisWeight <= 0) {
continue;
}
int minorAxisWeight = minorAxis.applyAsInt(mTempRect2) - minorAxis.applyAsInt(mTempRect);
float weight = majorAxisWeight * majorAxisWeight + minorAxisWeight * minorAxisWeight * MINOR_AXIS_WEIGHT;
if (weight < minWeight) {
minWeight = weight;
match = node;
}
}
return match;
}
use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by ProtonAOSP.
the class TaskViewTouchController method reInitAnimationController.
private void reInitAnimationController(boolean goingUp) {
if (mCurrentAnimation != null && mCurrentAnimationIsGoingUp == goingUp) {
// No need to init
return;
}
if ((goingUp && !mAllowGoingUp) || (!goingUp && !mAllowGoingDown)) {
// Trying to re-init in an unsupported direction.
return;
}
if (mCurrentAnimation != null) {
mCurrentAnimation.setPlayFraction(0);
mCurrentAnimation.getTarget().removeListener(this);
mCurrentAnimation.dispatchOnCancel();
}
PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
mCurrentAnimationIsGoingUp = goingUp;
BaseDragLayer dl = mActivity.getDragLayer();
final int secondaryLayerDimension = orientationHandler.getSecondaryDimension(dl);
long maxDuration = 2 * secondaryLayerDimension;
int verticalFactor = orientationHandler.getTaskDragDisplacementFactor(mIsRtl);
int secondaryTaskDimension = orientationHandler.getSecondaryDimension(mTaskBeingDragged);
// The interpolator controlling the most prominent visual movement. We use this to determine
// whether we passed SUCCESS_TRANSITION_PROGRESS.
final Interpolator currentInterpolator;
PendingAnimation pa;
if (goingUp) {
currentInterpolator = Interpolators.LINEAR;
pa = mRecentsView.createTaskDismissAnimation(mTaskBeingDragged, true, /* animateTaskView */
true, /* removeTask */
maxDuration, false);
mEndDisplacement = -secondaryTaskDimension;
} else {
currentInterpolator = Interpolators.ZOOM_IN;
pa = mRecentsView.createTaskLaunchAnimation(mTaskBeingDragged, maxDuration, currentInterpolator);
// Since the thumbnail is what is filling the screen, based the end displacement on it.
View thumbnailView = mTaskBeingDragged.getThumbnail();
mTempCords[1] = orientationHandler.getSecondaryDimension(thumbnailView);
dl.getDescendantCoordRelativeToSelf(thumbnailView, mTempCords);
mEndDisplacement = secondaryLayerDimension - mTempCords[1];
}
mEndDisplacement *= verticalFactor;
mCurrentAnimation = pa.createPlaybackController();
// Setting this interpolator doesn't affect the visual motion, but is used to determine
// whether we successfully reached the target state in onDragEnd().
mCurrentAnimation.getTarget().setInterpolator(currentInterpolator);
onUserControlledAnimationCreated(mCurrentAnimation);
mCurrentAnimation.getTarget().addListener(this);
mCurrentAnimation.dispatchOnStart();
mProgressMultiplier = 1 / mEndDisplacement;
}
use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by ProtonAOSP.
the class CellLayout method addViewToTempLocation.
private boolean addViewToTempLocation(View v, Rect rectOccupiedByPotentialDrop, int[] direction, ItemConfiguration currentState) {
CellAndSpan c = currentState.map.get(v);
boolean success = false;
mTmpOccupied.markCells(c, false);
mTmpOccupied.markCells(rectOccupiedByPotentialDrop, true);
findNearestArea(c.cellX, c.cellY, c.spanX, c.spanY, direction, mTmpOccupied.cells, null, mTempLocation);
if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
c.cellX = mTempLocation[0];
c.cellY = mTempLocation[1];
success = true;
}
mTmpOccupied.markCells(c, true);
return success;
}
use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction in project android_packages_apps_Launcher3 by ProtonAOSP.
the class CellLayout method addViewsToTempLocation.
private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction, View dragView, ItemConfiguration currentState) {
if (views.size() == 0)
return true;
boolean success = false;
Rect boundingRect = new Rect();
// We construct a rect which represents the entire group of views passed in
currentState.getBoundingRectForViews(views, boundingRect);
// Mark the occupied state as false for the group of views we want to move.
for (View v : views) {
CellAndSpan c = currentState.map.get(v);
mTmpOccupied.markCells(c, false);
}
GridOccupancy blockOccupied = new GridOccupancy(boundingRect.width(), boundingRect.height());
int top = boundingRect.top;
int left = boundingRect.left;
// for interlocking.
for (View v : views) {
CellAndSpan c = currentState.map.get(v);
blockOccupied.markCells(c.cellX - left, c.cellY - top, c.spanX, c.spanY, true);
}
mTmpOccupied.markCells(rectOccupiedByPotentialDrop, true);
findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction, mTmpOccupied.cells, blockOccupied.cells, mTempLocation);
// If we successfuly found a location by pushing the block of views, we commit it
if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
int deltaX = mTempLocation[0] - boundingRect.left;
int deltaY = mTempLocation[1] - boundingRect.top;
for (View v : views) {
CellAndSpan c = currentState.map.get(v);
c.cellX += deltaX;
c.cellY += deltaY;
}
success = true;
}
// In either case, we set the occupied array as marked for the location of the views
for (View v : views) {
CellAndSpan c = currentState.map.get(v);
mTmpOccupied.markCells(c, true);
}
return success;
}
Aggregations