Search in sources :

Example 86 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project Neo-Launcher by NeoApplications.

the class FocusHelper method handleHotseatButtonKeyEvent.

/**
 * Handles key events in the workspace hotseat (bottom of the screen).
 * <p>Currently we don't special case for the phone UI in different orientations, even though
 * the hotseat is on the side in landscape mode. This is to ensure that accessibility
 * consistency is maintained across rotations.
 */
static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e) {
    boolean consume = FocusLogic.shouldConsume(keyCode);
    if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
        return consume;
    }
    final Launcher launcher = Launcher.getLauncher(v.getContext());
    final DeviceProfile profile = launcher.getDeviceProfile();
    if (DEBUG) {
        Log.v(TAG, String.format("Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, isVertical=%s", KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout()));
    }
    // Initialize the variables.
    final Workspace workspace = (Workspace) v.getRootView().findViewById(R.id.workspace);
    final ShortcutAndWidgetContainer hotseatParent = (ShortcutAndWidgetContainer) v.getParent();
    final CellLayout hotseatLayout = (CellLayout) hotseatParent.getParent();
    final ItemInfo itemInfo = (ItemInfo) v.getTag();
    int pageIndex = workspace.getNextPage();
    int pageCount = workspace.getChildCount();
    int iconIndex = hotseatParent.indexOfChild(v);
    int iconRank = ((CellLayout.LayoutParams) hotseatLayout.getShortcutsAndWidgets().getChildAt(iconIndex).getLayoutParams()).cellX;
    final CellLayout iconLayout = (CellLayout) workspace.getChildAt(pageIndex);
    if (iconLayout == null) {
        // animation.)
        return consume;
    }
    final ViewGroup iconParent = iconLayout.getShortcutsAndWidgets();
    ViewGroup parent = null;
    int[][] matrix = null;
    if (keyCode == KeyEvent.KEYCODE_DPAD_UP && !profile.isVerticalBarLayout()) {
        matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
        iconIndex += iconParent.getChildCount();
        parent = iconParent;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && profile.isVerticalBarLayout()) {
        matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
        iconIndex += iconParent.getChildCount();
        parent = iconParent;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && profile.isVerticalBarLayout()) {
        keyCode = KeyEvent.KEYCODE_PAGE_DOWN;
    } else {
        // For other KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT navigation, do not use the
        // matrix extended with hotseat.
        matrix = FocusLogic.createSparseMatrix(hotseatLayout);
        parent = hotseatParent;
    }
    // Process the focus.
    int newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, iconIndex, pageIndex, pageCount, Utilities.isRtl(v.getResources()));
    View newIcon = null;
    switch(newIconIndex) {
        case FocusLogic.NEXT_PAGE_FIRST_ITEM:
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
            newIcon = parent.getChildAt(0);
            // TODO(hyunyoungs): handle cases where the child is not an icon but
            // a folder or a widget.
            workspace.snapToPage(pageIndex + 1);
            break;
        case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
            newIcon = parent.getChildAt(0);
            // TODO(hyunyoungs): handle cases where the child is not an icon but
            // a folder or a widget.
            workspace.snapToPage(pageIndex - 1);
            break;
        case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
            newIcon = parent.getChildAt(parent.getChildCount() - 1);
            // TODO(hyunyoungs): handle cases where the child is not an icon but
            // a folder or a widget.
            workspace.snapToPage(pageIndex - 1);
            break;
        case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN:
        case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
            // Go to the previous page but keep the focus on the same hotseat icon.
            workspace.snapToPage(pageIndex - 1);
            break;
        case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
        case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
            // Go to the next page but keep the focus on the same hotseat icon.
            workspace.snapToPage(pageIndex + 1);
            break;
    }
    if (parent == iconParent && newIconIndex >= iconParent.getChildCount()) {
        newIconIndex -= iconParent.getChildCount();
    }
    if (parent != null) {
        if (newIcon == null && newIconIndex >= 0) {
            newIcon = parent.getChildAt(newIconIndex);
        }
        if (newIcon != null) {
            newIcon.requestFocus();
            playSoundEffect(keyCode, v);
        }
    }
    return consume;
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) FolderPagedView(com.android.launcher3.folder.FolderPagedView)

Example 87 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project Neo-Launcher by NeoApplications.

the class Workspace method beginDragShared.

public DragView beginDragShared(View child, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.NO_CONTEXT_MENU, "beginDragShared");
    }
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    child.clearFocus();
    child.setPressed(false);
    mOutlineProvider = previewProvider;
    // 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];
    DeviceProfile grid = mLauncher.getDeviceProfile();
    Point dragVisualizeOffset = null;
    Rect dragRect = null;
    if (child instanceof BubbleTextView) {
        dragRect = new Rect();
        BubbleTextView.getIconBounds(child, dragRect, grid.iconSizePx);
        dragLayerY += dragRect.top;
        // Note: The dragRect is used to calculate drag layer offsets, but the
        // dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    } else if (child instanceof FolderIcon) {
        int previewSize = grid.folderIconSizePx;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding - child.getPaddingTop());
        dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize);
    } else if (previewProvider instanceof ShortcutDragPreviewProvider) {
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    // Clear the pressed state if necessary
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    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, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    dv.setIntrinsicIconScaleFactor(dragOptions.intrinsicIconScaleFactor);
    return dv;
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Bitmap(android.graphics.Bitmap) FolderIcon(com.android.launcher3.folder.FolderIcon) ShortcutDragPreviewProvider(com.android.launcher3.shortcuts.ShortcutDragPreviewProvider) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow)

Example 88 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project Neo-Launcher by NeoApplications.

the class ShortcutAndWidgetContainer method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
            if (child instanceof LauncherAppWidgetHostView) {
                LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;
                // Scale and center the widget to fit within its cells.
                DeviceProfile profile = mActivity.getDeviceProfile();
                float scaleX = profile.appWidgetScale.x;
                float scaleY = profile.appWidgetScale.y;
                lahv.setScaleToFit(Math.min(scaleX, scaleY));
                lahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f, -(lp.height - (lp.height * scaleY)) / 2.0f);
            }
            int childLeft = lp.x;
            int childTop = lp.y;
            child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
            if (lp.dropped) {
                lp.dropped = false;
                final int[] cellXY = mTmpCellXY;
                getLocationOnScreen(cellXY);
                mWallpaperManager.sendWallpaperCommand(getWindowToken(), WallpaperManager.COMMAND_DROP, cellXY[0] + childLeft + lp.width / 2, cellXY[1] + childTop + lp.height / 2, 0, null);
            }
        }
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 89 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project Neo-Launcher by NeoApplications.

the class Folder method centerAboutIcon.

private void centerAboutIcon() {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    DragLayer parent = mLauncher.getDragLayer();
    int width = getFolderWidth();
    int height = getFolderHeight();
    parent.getDescendantRectRelativeToSelf(mFolderIcon, sTempRect);
    int centerX = sTempRect.centerX();
    int centerY = sTempRect.centerY();
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;
    // We need to bound the folder to the currently visible workspace area
    if (mLauncher.getStateManager().getState().overviewUi) {
        parent.getDescendantRectRelativeToSelf(mLauncher.getOverviewPanel(), sTempRect);
    } else {
        mLauncher.getWorkspace().getPageAreaRelativeToDragLayer(sTempRect);
    }
    int left = Math.min(Math.max(sTempRect.left, centeredLeft), sTempRect.right - width);
    int top = Math.min(Math.max(sTempRect.top, centeredTop), sTempRect.bottom - height);
    int distFromEdgeOfScreen = mLauncher.getWorkspace().getPaddingLeft() + getPaddingLeft();
    if (grid.isPhone && (grid.availableWidthPx - width) < 4 * distFromEdgeOfScreen) {
        // Center the folder if it is very close to being centered anyway, by virtue of
        // filling the majority of the viewport. ie. remove it from the uncanny valley
        // of centeredness.
        left = (grid.availableWidthPx - width) / 2;
    } else if (width >= sTempRect.width()) {
        // If the folder doesn't fit within the bounds, center it about the desired bounds
        left = sTempRect.left + (sTempRect.width() - width) / 2;
    }
    if (height >= sTempRect.height()) {
        // Folder height is greater than page height, center on page
        top = sTempRect.top + (sTempRect.height() - height) / 2;
    } else {
        // Folder height is less than page height, so bound it to the absolute open folder
        // bounds if necessary
        Rect folderBounds = grid.getAbsoluteOpenFolderBounds();
        left = Math.max(folderBounds.left, Math.min(left, folderBounds.right - width));
        top = Math.max(folderBounds.top, Math.min(top, folderBounds.bottom - height));
    }
    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) SuppressLint(android.annotation.SuppressLint)

Example 90 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project Neo-Launcher by NeoApplications.

the class Folder method getContentAreaHeight.

protected int getContentAreaHeight() {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    int maxContentAreaHeight = grid.availableHeightPx - grid.getTotalWorkspacePadding().y - mFooterHeight;
    int height = Math.min(maxContentAreaHeight, mContent.getDesiredHeight());
    return Math.max(height, MIN_CONTENT_DIMEN);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) SuppressLint(android.annotation.SuppressLint)

Aggregations

DeviceProfile (com.android.launcher3.DeviceProfile)333 Rect (android.graphics.Rect)123 Point (android.graphics.Point)83 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)61 Paint (android.graphics.Paint)40 ArrayList (java.util.ArrayList)38 View (android.view.View)31 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)31 Context (android.content.Context)28 SuppressLint (android.annotation.SuppressLint)27 Size (android.util.Size)25 DragLayer (com.android.launcher3.dragndrop.DragLayer)25 ViewGroup (android.view.ViewGroup)23 Launcher (com.android.launcher3.Launcher)23 RecentsView (com.android.quickstep.views.RecentsView)23 RectF (android.graphics.RectF)22 PendingAnimation (com.android.launcher3.anim.PendingAnimation)22 FrameLayout (android.widget.FrameLayout)21 AnimatorPlaybackController (com.android.launcher3.anim.AnimatorPlaybackController)21 Drawable (android.graphics.drawable.Drawable)20