Search in sources :

Example 21 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class Launcher method addAppWidgetFromDrop.

/**
 * Process a widget drop.
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
    AppWidgetHostView hostView = info.boundWidget;
    final int appWidgetId;
    WidgetAddFlowHandler addFlowHandler = info.getHandler();
    if (hostView != null) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        if (LOGD) {
            Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
        }
        getDragLayer().removeView(hostView);
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // the widget, or we need to start an activity to configure the widget, or both.
        if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
            appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(info.componentName);
        } else {
            appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        }
        Bundle options = info.bindOptions;
        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
        } else {
            addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
        }
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) Bundle(android.os.Bundle) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler)

Example 22 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class ButtonDropTarget method getIconRect.

public Rect getIconRect(DragObject dragObject) {
    int viewWidth = dragObject.dragView.getMeasuredWidth();
    int viewHeight = dragObject.dragView.getMeasuredHeight();
    int drawableWidth = mDrawable.getIntrinsicWidth();
    int drawableHeight = mDrawable.getIntrinsicHeight();
    DragLayer dragLayer = mLauncher.getDragLayer();
    // Find the rect to animate to (the view is center aligned)
    Rect to = new Rect();
    dragLayer.getViewRectRelativeToSelf(this, to);
    final int width = drawableWidth;
    final int height = drawableHeight;
    final int left;
    final int right;
    if (Utilities.isRtl(getResources())) {
        right = to.right - getPaddingRight();
        left = right - width;
    } else {
        left = to.left + getPaddingLeft();
        right = left + width;
    }
    final int top = to.top + (getMeasuredHeight() - height) / 2;
    final int bottom = top + height;
    to.set(left, top, right, bottom);
    // Center the destination rect about the trash icon
    final int xOffset = -(viewWidth - width) / 2;
    final int yOffset = -(viewHeight - height) / 2;
    to.offset(xOffset, yOffset);
    return to;
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect)

Example 23 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class ButtonDropTarget method onDrop.

/**
 * On drop animate the dropView to the icon.
 */
@Override
public void onDrop(final DragObject d, final DragOptions options) {
    if (options.isFlingToDelete) {
        // FlingAnimation handles the animation and then calls completeDrop().
        return;
    }
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    final Rect to = getIconRect(d);
    final float scale = (float) to.width() / from.width();
    mDropTargetBar.deferOnDragEnd();
    Runnable onAnimationEndRunnable = () -> {
        completeDrop(d);
        mDropTargetBar.onDragEnd();
        mLauncher.getStateManager().goToState(NORMAL);
    };
    dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, DRAG_VIEW_DROP_DURATION, Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect)

Example 24 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer 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 25 with DragLayer

use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.

the class AppWidgetResizeFrame method showForWidget.

public static void showForWidget(LauncherAppWidgetHostView widget, CellLayout cellLayout) {
    Launcher launcher = Launcher.getLauncher(cellLayout.getContext());
    AbstractFloatingView.closeAllOpenViews(launcher);
    DragLayer dl = launcher.getDragLayer();
    AppWidgetResizeFrame frame = (AppWidgetResizeFrame) launcher.getLayoutInflater().inflate(R.layout.app_widget_resize_frame, dl, false);
    frame.setupForWidget(widget, cellLayout, dl);
    ((DragLayer.LayoutParams) frame.getLayoutParams()).customPosition = true;
    dl.addView(frame);
    frame.mIsOpen = true;
    frame.snapToWidget(false);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer)

Aggregations

DragLayer (com.android.launcher3.dragndrop.DragLayer)100 Rect (android.graphics.Rect)67 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)33 ViewGroup (android.view.ViewGroup)23 Resources (android.content.res.Resources)22 AnimatorSet (android.animation.AnimatorSet)20 View (android.view.View)18 SuppressLint (android.annotation.SuppressLint)16 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)15 DeviceProfile (com.android.launcher3.DeviceProfile)15 Workspace (com.android.launcher3.Workspace)15 Animator (android.animation.Animator)14 ObjectAnimator (android.animation.ObjectAnimator)14 Point (android.graphics.Point)12 ItemInfo (com.android.launcher3.model.data.ItemInfo)12 CellLayout (com.android.launcher3.CellLayout)11 DragView (com.android.launcher3.dragndrop.DragView)11 ArrayList (java.util.ArrayList)11 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)10 Drawable (android.graphics.drawable.Drawable)10