Search in sources :

Example 46 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class AppWidgetResizeFrame method snapToWidget.

private void snapToWidget(boolean animate) {
    getSnappedRectRelativeToDragLayer(sTmpRect);
    int newWidth = sTmpRect.width();
    int newHeight = sTmpRect.height();
    int newX = sTmpRect.left;
    int newY = sTmpRect.top;
    // down accordingly to provide a proper touch target.
    if (newY < 0) {
        // In this case we shift the touch region down to start at the top of the DragLayer
        mTopTouchRegionAdjustment = -newY;
    } else {
        mTopTouchRegionAdjustment = 0;
    }
    if (newY + newHeight > mDragLayer.getHeight()) {
        // In this case we shift the touch region up to end at the bottom of the DragLayer
        mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight());
    } else {
        mBottomTouchRegionAdjustment = 0;
    }
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    final CellLayout pairedCellLayout;
    if (mCellLayout.getParent() instanceof Workspace) {
        Workspace workspace = (Workspace) mCellLayout.getParent();
        pairedCellLayout = workspace.getScreenPair(mCellLayout);
    } else {
        pairedCellLayout = null;
    }
    if (!animate) {
        lp.width = newWidth;
        lp.height = newHeight;
        lp.x = newX;
        lp.y = newY;
        for (int i = 0; i < HANDLE_COUNT; i++) {
            mDragHandles[i].setAlpha(1f);
        }
        if (pairedCellLayout != null) {
            updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */
            1f, /* springLoadedProgress= */
            0f);
        }
        requestLayout();
    } else {
        ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, PropertyValuesHolder.ofInt(LAYOUT_WIDTH, lp.width, newWidth), PropertyValuesHolder.ofInt(LAYOUT_HEIGHT, lp.height, newHeight), PropertyValuesHolder.ofInt(LAYOUT_X, lp.x, newX), PropertyValuesHolder.ofInt(LAYOUT_Y, lp.y, newY));
        mFirstFrameAnimatorHelper.addTo(oa).addUpdateListener(a -> requestLayout());
        AnimatorSet set = new AnimatorSet();
        set.play(oa);
        for (int i = 0; i < HANDLE_COUNT; i++) {
            set.play(mFirstFrameAnimatorHelper.addTo(ObjectAnimator.ofFloat(mDragHandles[i], ALPHA, 1f)));
        }
        if (pairedCellLayout != null) {
            updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */
            1f, /* springLoadedProgress= */
            0f, /* animatorSet= */
            set);
        }
        set.setDuration(SNAP_DURATION);
        set.start();
    }
    setFocusableInTouchMode(true);
    requestFocus();
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet)

Example 47 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class StaggeredWorkspaceAnim method addAnimationForPage.

private void addAnimationForPage(CellLayout page, int totalRows) {
    ShortcutAndWidgetContainer itemsContainer = page.getShortcutsAndWidgets();
    boolean pageClipChildren = page.getClipChildren();
    boolean pageClipToPadding = page.getClipToPadding();
    page.setClipChildren(false);
    page.setClipToPadding(false);
    // Set up springs on workspace items.
    for (int i = itemsContainer.getChildCount() - 1; i >= 0; i--) {
        View child = itemsContainer.getChildAt(i);
        CellLayout.LayoutParams lp = ((CellLayout.LayoutParams) child.getLayoutParams());
        addStaggeredAnimationForView(child, lp.cellY + lp.cellVSpan, totalRows);
    }
    mAnimators.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            page.setClipChildren(pageClipChildren);
            page.setClipToPadding(pageClipToPadding);
        }
    });
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) View(android.view.View) RecentsView(com.android.quickstep.views.RecentsView)

Example 48 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

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;
}
Also used : Rect(android.graphics.Rect) PagedView(com.android.launcher3.PagedView) Folder(com.android.launcher3.folder.Folder)

Example 49 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class KeyboardDragAndDropView method showForIcon.

/**
 * Shows the keyboard drag popup for the provided view
 */
public void showForIcon(View icon, ItemInfo item, DragOptions dragOptions) {
    mIsOpen = true;
    mLauncher.getDragLayer().addView(this);
    mLauncher.getStateManager().addStateListener(this);
    // Find current selection
    CellLayout currentParent = (CellLayout) icon.getParent().getParent();
    float[] iconPos = new float[] { currentParent.getCellWidth() / 2, currentParent.getCellHeight() / 2 };
    Utilities.getDescendantCoordRelativeToAncestor(icon, currentParent, iconPos, false);
    ItemLongClickListener.beginDrag(icon, mLauncher, item, dragOptions);
    DragAndDropAccessibilityDelegate dndDelegate = currentParent.getDragAndDropAccessibilityDelegate();
    setCurrentSelection(new VirtualNodeInfo(dndDelegate, dndDelegate.getVirtualViewAt(iconPos[0], iconPos[1])));
    mLauncher.setDefaultKeyMode(Activity.DEFAULT_KEYS_DISABLE);
    requestFocus();
}
Also used : CellLayout(com.android.launcher3.CellLayout) DragAndDropAccessibilityDelegate(com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate)

Example 50 with CellLayout

use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherPreviewRenderer method inflateAndAddPredictedIcon.

private void inflateAndAddPredictedIcon(WorkspaceItemInfo info) {
    CellLayout screen = mWorkspaceScreens.get(info.screenId);
    View view = PredictedAppIconInflater.inflate(mHomeElementInflater, screen, info);
    if (view != null) {
        addInScreenFromBind(view, info);
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) BaseLauncherAppWidgetHostView(com.android.launcher3.widget.BaseLauncherAppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Aggregations

CellLayout (com.android.launcher3.CellLayout)178 View (android.view.View)169 SuppressLint (android.annotation.SuppressLint)126 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)124 AppWidgetHostView (android.appwidget.AppWidgetHostView)105 Point (android.graphics.Point)95 DragView (com.android.launcher3.dragndrop.DragView)91 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)87 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)73 BubbleTextView (com.android.launcher3.BubbleTextView)62 Rect (android.graphics.Rect)60 FolderIcon (com.android.launcher3.folder.FolderIcon)52 DragLayer (com.android.launcher3.dragndrop.DragLayer)50 ArrayList (java.util.ArrayList)48 FolderInfo (com.android.launcher3.model.data.FolderInfo)45 Workspace (com.android.launcher3.Workspace)43 DraggableView (com.android.launcher3.dragndrop.DraggableView)43 Animator (android.animation.Animator)42 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)40