Search in sources :

Example 91 with CellLayout

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

the class FocusHelper method getFirstFocusableIconInReverseReadingOrder.

private static View getFirstFocusableIconInReverseReadingOrder(CellLayout cellLayout, boolean isRtl) {
    View icon;
    int countX = cellLayout.getCountX();
    for (int y = cellLayout.getCountY() - 1; y >= 0; y--) {
        int increment = isRtl ? 1 : -1;
        for (int x = isRtl ? 0 : countX - 1; 0 <= x && x < countX; x += increment) {
            if ((icon = cellLayout.getChildAt(x, y)) != null && icon.isFocusable()) {
                return icon;
            }
        }
    }
    return null;
}
Also used : View(android.view.View) FolderPagedView(com.android.launcher3.folder.FolderPagedView)

Example 92 with CellLayout

use of com.android.launcher3.CellLayout 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 93 with CellLayout

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

the class FocusHelper method handlePreviousPageLastItem.

private static View handlePreviousPageLastItem(Workspace workspace, CellLayout hotseatLayout, int pageIndex, boolean isRtl) {
    if (pageIndex - 1 < 0) {
        return null;
    }
    CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex - 1);
    View newIcon = getFirstFocusableIconInReverseReadingOrder(workspaceLayout, isRtl);
    if (newIcon == null) {
        // Check the hotseat if no focusable item was found on the workspace.
        newIcon = getFirstFocusableIconInReverseReadingOrder(hotseatLayout, isRtl);
        workspace.snapToPage(pageIndex - 1);
    }
    return newIcon;
}
Also used : View(android.view.View) FolderPagedView(com.android.launcher3.folder.FolderPagedView)

Example 94 with CellLayout

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

the class Workspace method manageFolderFeedback.

private void manageFolderFeedback(CellLayout targetLayout, int[] targetCell, float distance, DragObject dragObject) {
    if (distance > mMaxDistanceForFolderCreation) {
        if (mDragMode != DRAG_MODE_NONE) {
            setDragMode(DRAG_MODE_NONE);
        }
        return;
    }
    final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);
    ItemInfo info = dragObject.dragInfo;
    boolean userFolderPending = willCreateUserFolder(info, dragOverView, false);
    if (mDragMode == DRAG_MODE_NONE && userFolderPending && !mFolderCreationAlarm.alarmPending()) {
        FolderCreationAlarmListener listener = new FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1]);
        if (!dragObject.accessibleDrag) {
            mFolderCreationAlarm.setOnAlarmListener(listener);
            mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT);
        } else {
            listener.onAlarm(mFolderCreationAlarm);
        }
        if (dragObject.stateAnnouncer != null) {
            dragObject.stateAnnouncer.announce(WorkspaceAccessibilityHelper.getDescriptionForDropOver(dragOverView, getContext()));
        }
        return;
    }
    boolean willAddToFolder = willAddToExistingUserFolder(info, dragOverView);
    if (willAddToFolder && mDragMode == DRAG_MODE_NONE) {
        mDragOverFolderIcon = ((FolderIcon) dragOverView);
        mDragOverFolderIcon.onDragEnter(info);
        if (targetLayout != null) {
            targetLayout.clearDragOutlines();
        }
        setDragMode(DRAG_MODE_ADD_TO_FOLDER);
        if (dragObject.stateAnnouncer != null) {
            dragObject.stateAnnouncer.announce(WorkspaceAccessibilityHelper.getDescriptionForDropOver(dragOverView, getContext()));
        }
        return;
    }
    if (mDragMode == DRAG_MODE_ADD_TO_FOLDER && !willAddToFolder) {
        setDragMode(DRAG_MODE_NONE);
    }
    if (mDragMode == DRAG_MODE_CREATE_FOLDER && !userFolderPending) {
        setDragMode(DRAG_MODE_NONE);
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) OmegaBackgroundView(com.saggitt.omega.views.OmegaBackgroundView)

Example 95 with CellLayout

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

the class Workspace method stripEmptyScreens.

public void stripEmptyScreens() {
    if (mLauncher.isWorkspaceLoading()) {
        // This is dangerous and can result in data loss.
        return;
    }
    if (isPageInTransition()) {
        mStripScreensOnPageStopMoving = true;
        return;
    }
    int currentPage = getNextPage();
    IntArray removeScreens = new IntArray();
    int total = mWorkspaceScreens.size();
    for (int i = 0; i < total; i++) {
        int id = mWorkspaceScreens.keyAt(i);
        CellLayout cl = mWorkspaceScreens.valueAt(i);
        // FIRST_SCREEN_ID can never be removed.
        if ((!FeatureFlags.QSB_ON_FIRST_SCREEN || id > FIRST_SCREEN_ID) && cl.getShortcutsAndWidgets().getChildCount() == 0) {
            removeScreens.add(id);
        }
    }
    boolean isInAccessibleDrag = mLauncher.getAccessibilityDelegate().isInAccessibleDrag();
    // We enforce at least one page to add new items to. In the case that we remove the last
    // such screen, we convert the last screen to the empty screen
    int minScreens = 1;
    int pageShift = 0;
    for (int i = 0; i < removeScreens.size(); i++) {
        int id = removeScreens.get(i);
        CellLayout cl = mWorkspaceScreens.get(id);
        mWorkspaceScreens.remove(id);
        mScreenOrder.removeValue(id);
        if (getChildCount() > minScreens) {
            if (indexOfChild(cl) < currentPage) {
                pageShift++;
            }
            if (isInAccessibleDrag) {
                cl.enableAccessibleDrag(false, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG);
            }
            removeView(cl);
        } else {
            // if this is the last screen, convert it to the empty screen
            mRemoveEmptyScreenRunnable = null;
            mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, cl);
            mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID);
        }
    }
    if (pageShift >= 0) {
        setCurrentPage(currentPage - pageShift);
    }
}
Also used : IntArray(com.android.launcher3.util.IntArray) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

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