Search in sources :

Example 11 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Trebuchet by LineageOS.

the class Workspace method beginDragShared.

/**
 * Core functionality for beginning a drag operation for an item that will be dropped within
 * the workspace
 */
public DragView beginDragShared(View child, DraggableView draggableView, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    // Clear the pressed state if necessary
    child.clearFocus();
    child.setPressed(false);
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    mOutlineProvider = previewProvider;
    if (draggableView == null && child instanceof DraggableView) {
        draggableView = (DraggableView) child;
    }
    // The drag bitmap follows the touch point around on the screen
    final Bitmap b = previewProvider.createDragBitmap();
    int halfPadding = previewProvider.previewPadding / 2;
    float scale = previewProvider.getScaleAndPosition(b, mTempXY);
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    Point dragVisualizeOffset = null;
    Rect dragRect = new Rect();
    if (draggableView != null) {
        draggableView.getSourceVisualDragBounds(dragRect);
        dragLayerY += dragRect.top;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
            mLauncher.getUserEventDispatcher().resetElapsedContainerMillis("dragging started");
        }
    }
    DragView dv = mDragController.startDrag(b, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    dv.setIntrinsicIconScaleFactor(dragOptions.intrinsicIconScaleFactor);
    return dv;
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) DragView(com.android.launcher3.dragndrop.DragView) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 12 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Trebuchet by LineageOS.

the class FocusHelper method handleIconKeyEvent.

/**
 * Handles key events in a workspace containing icons.
 */
static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) {
    boolean consume = FocusLogic.shouldConsume(keyCode);
    if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
        return consume;
    }
    Launcher launcher = Launcher.getLauncher(v.getContext());
    DeviceProfile profile = launcher.getDeviceProfile();
    if (DEBUG) {
        Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s", KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout()));
    }
    // Initialize the variables.
    ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
    CellLayout iconLayout = (CellLayout) parent.getParent();
    final Workspace workspace = (Workspace) iconLayout.getParent();
    final ViewGroup dragLayer = (ViewGroup) workspace.getParent();
    final ViewGroup tabs = (ViewGroup) dragLayer.findViewById(R.id.drop_target_bar);
    final Hotseat hotseat = (Hotseat) dragLayer.findViewById(R.id.hotseat);
    final ItemInfo itemInfo = (ItemInfo) v.getTag();
    final int iconIndex = parent.indexOfChild(v);
    final int pageIndex = workspace.indexOfChild(iconLayout);
    final int pageCount = workspace.getChildCount();
    CellLayout hotseatLayout = (CellLayout) hotseat.getChildAt(0);
    ShortcutAndWidgetContainer hotseatParent = hotseatLayout.getShortcutsAndWidgets();
    int[][] matrix;
    // with the hotseat.
    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) {
        matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && profile.isVerticalBarLayout()) {
        matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
    } else {
        matrix = FocusLogic.createSparseMatrix(iconLayout);
    }
    // Process the focus.
    int newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, iconIndex, pageIndex, pageCount, Utilities.isRtl(v.getResources()));
    boolean isRtl = Utilities.isRtl(v.getResources());
    View newIcon = null;
    CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex);
    switch(newIconIndex) {
        case FocusLogic.NOOP:
            if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                newIcon = tabs;
            }
            break;
        case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
        case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
            int newPageIndex = pageIndex - 1;
            if (newIconIndex == FocusLogic.NEXT_PAGE_RIGHT_COLUMN) {
                newPageIndex = pageIndex + 1;
            }
            int row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY;
            parent = getCellLayoutChildrenForIndex(workspace, newPageIndex);
            if (parent != null) {
                iconLayout = (CellLayout) parent.getParent();
                matrix = FocusLogic.createSparseMatrixWithPivotColumn(iconLayout, iconLayout.getCountX(), row);
                newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, FocusLogic.PIVOT, newPageIndex, pageCount, Utilities.isRtl(v.getResources()));
                if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
                    newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
                    newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else {
                    newIcon = parent.getChildAt(newIconIndex);
                }
            }
            break;
        case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
            workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex - 1);
            newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
            if (newIcon == null) {
                // Check the hotseat if no focusable item was found on the workspace.
                newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
                workspace.snapToPage(pageIndex - 1);
            }
            break;
        case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
            newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
            break;
        case FocusLogic.NEXT_PAGE_FIRST_ITEM:
            newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
            break;
        case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
        case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN:
            newPageIndex = pageIndex + 1;
            if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN) {
                newPageIndex = pageIndex - 1;
            }
            row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY;
            parent = getCellLayoutChildrenForIndex(workspace, newPageIndex);
            if (parent != null) {
                iconLayout = (CellLayout) parent.getParent();
                matrix = FocusLogic.createSparseMatrixWithPivotColumn(iconLayout, -1, row);
                newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, FocusLogic.PIVOT, newPageIndex, pageCount, Utilities.isRtl(v.getResources()));
                if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
                    newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
                    newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
                } else {
                    newIcon = parent.getChildAt(newIconIndex);
                }
            }
            break;
        case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
            newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
            if (newIcon == null) {
                // Check the hotseat if no focusable item was found on the workspace.
                newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
            }
            break;
        case FocusLogic.CURRENT_PAGE_LAST_ITEM:
            newIcon = getFirstFocusableIconInReverseReadingOrder(workspaceLayout, isRtl);
            if (newIcon == null) {
                // Check the hotseat if no focusable item was found on the workspace.
                newIcon = getFirstFocusableIconInReverseReadingOrder(hotseatLayout, isRtl);
            }
            break;
        default:
            // current page, some item.
            if (0 <= newIconIndex && newIconIndex < parent.getChildCount()) {
                newIcon = parent.getChildAt(newIconIndex);
            } else if (parent.getChildCount() <= newIconIndex && newIconIndex < parent.getChildCount() + hotseatParent.getChildCount()) {
                newIcon = hotseatParent.getChildAt(newIconIndex - parent.getChildCount());
            }
            break;
    }
    if (newIcon != null) {
        newIcon.requestFocus();
        playSoundEffect(keyCode, v);
    }
    return consume;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) ViewGroup(android.view.ViewGroup) View(android.view.View) FolderPagedView(com.android.launcher3.folder.FolderPagedView)

Example 13 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Trebuchet by LineageOS.

the class FocusLogic method createSparseMatrix.

/**
 * Returns a matrix of size same as the {@link CellLayout} dimension that is initialized with the
 * index of the child view.
 */
// TODO: get rid of the dynamic matrix creation
public static int[][] createSparseMatrix(CellLayout layout) {
    ShortcutAndWidgetContainer parent = layout.getShortcutsAndWidgets();
    final int m = layout.getCountX();
    final int n = layout.getCountY();
    final boolean invert = parent.invertLayoutHorizontally();
    int[][] matrix = createFullMatrix(m, n);
    // Iterate thru the children.
    for (int i = 0; i < parent.getChildCount(); i++) {
        View cell = parent.getChildAt(i);
        if (!cell.isFocusable()) {
            continue;
        }
        int cx = ((CellLayout.LayoutParams) cell.getLayoutParams()).cellX;
        int cy = ((CellLayout.LayoutParams) cell.getLayoutParams()).cellY;
        int x = invert ? (m - cx - 1) : cx;
        if (x < m && cy < n) {
            // check if view fits into matrix, else skip
            matrix[x][cy] = i;
        }
    }
    if (DEBUG) {
        printMatrix(matrix);
    }
    return matrix;
}
Also used : ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) View(android.view.View)

Example 14 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Trebuchet by LineageOS.

the class DragLayer method animateViewIntoPosition.

public void animateViewIntoPosition(DragView dragView, final View child, int duration, View anchorView) {
    ShortcutAndWidgetContainer parentChildren = (ShortcutAndWidgetContainer) child.getParent();
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    parentChildren.measureChild(child);
    parentChildren.layoutChild(child);
    Rect dragViewBounds = new Rect();
    getViewRectRelativeToSelf(dragView, dragViewBounds);
    final int fromX = dragViewBounds.left;
    final int fromY = dragViewBounds.top;
    float[] coord = new float[2];
    float childScale = child.getScaleX();
    coord[0] = lp.x + (child.getMeasuredWidth() * (1 - childScale) / 2);
    coord[1] = lp.y + (child.getMeasuredHeight() * (1 - childScale) / 2);
    // Since the child hasn't necessarily been laid out, we force the lp to be updated with
    // the correct coordinates (above) and use these to determine the final location
    float scale = getDescendantCoordRelativeToSelf((View) child.getParent(), coord);
    // We need to account for the scale of the child itself, as the above only accounts for
    // for the scale in parents.
    scale *= childScale;
    int toX = Math.round(coord[0]);
    int toY = Math.round(coord[1]);
    float toScale = scale;
    if (child instanceof DraggableView) {
        // This code is fairly subtle. Please verify drag and drop is pixel-perfect in a number
        // of scenarios before modifying (from all apps, from workspace, different grid-sizes,
        // shortcuts from in and out of Launcher etc).
        DraggableView d = (DraggableView) child;
        Rect destRect = new Rect();
        d.getWorkspaceVisualDragBounds(destRect);
        // In most cases this additional scale factor should be a no-op (1). It mainly accounts
        // for alternate grids where the source and destination icon sizes are different
        toScale *= ((1f * destRect.width()) / (dragView.getMeasuredWidth() - dragView.getBlurSizeOutline()));
        // This accounts for the offset of the DragView created by scaling it about its
        // center as it animates into place.
        float scaleShiftX = dragView.getMeasuredWidth() * (1 - toScale) / 2;
        float scaleShiftY = dragView.getMeasuredHeight() * (1 - toScale) / 2;
        toX += scale * destRect.left - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftX;
        toY += scale * destRect.top - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftY;
    }
    child.setVisibility(INVISIBLE);
    Runnable onCompleteRunnable = () -> child.setVisibility(VISIBLE);
    animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale, onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView);
}
Also used : Rect(android.graphics.Rect) CellLayout(com.android.launcher3.CellLayout) ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer)

Example 15 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Trebuchet by LineageOS.

the class Folder method shouldUseHardwareLayerForAnimation.

private boolean shouldUseHardwareLayerForAnimation(CellLayout currentCellLayout) {
    if (ALWAYS_USE_HARDWARE_OPTIMIZATION_FOR_FOLDER_ANIMATIONS.get())
        return true;
    int folderCount = 0;
    final ShortcutAndWidgetContainer container = currentCellLayout.getShortcutsAndWidgets();
    for (int i = container.getChildCount() - 1; i >= 0; --i) {
        final View child = container.getChildAt(i);
        if (child instanceof AppWidgetHostView)
            return false;
        if (child instanceof FolderIcon)
            ++folderCount;
    }
    return folderCount >= MIN_FOLDERS_FOR_HARDWARE_OPTIMIZATION;
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)63 ShortcutAndWidgetContainer (com.android.launcher3.ShortcutAndWidgetContainer)54 View (android.view.View)44 CellLayout (com.android.launcher3.CellLayout)38 Point (android.graphics.Point)36 AppWidgetHostView (android.appwidget.AppWidgetHostView)28 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)26 DragView (com.android.launcher3.dragndrop.DragView)23 BubbleTextView (com.android.launcher3.BubbleTextView)21 DraggableView (com.android.launcher3.dragndrop.DraggableView)21 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)21 Animator (android.animation.Animator)20 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)20 ObjectAnimator (android.animation.ObjectAnimator)19 Rect (android.graphics.Rect)14 Drawable (android.graphics.drawable.Drawable)14 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 ValueAnimator (android.animation.ValueAnimator)13 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)8 Paint (android.graphics.Paint)8