Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea73bf5d authored by Sebastián Franco's avatar Sebastián Franco Committed by Android (Google) Code Review
Browse files

Merge "Removing the Worskapce as a dependency of CellLayout" into main

parents 43a826c5 2986e0b4
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.launcher3;

import static com.android.launcher3.LauncherState.EDIT_MODE;
import static com.android.launcher3.dragndrop.DraggableView.DRAGGABLE_ICON;
import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_REORDER_PREVIEW_OFFSET;
@@ -214,6 +213,7 @@ public class CellLayout extends ViewGroup {
    // Related to accessible drag and drop
    DragAndDropAccessibilityDelegate mTouchHelper;

    CellLayoutContainer mCellLayoutContainer;

    public static final FloatProperty<CellLayout> SPRING_LOADED_PROGRESS =
            new FloatProperty<CellLayout>("spring_loaded_progress") {
@@ -228,8 +228,9 @@ public class CellLayout extends ViewGroup {
                }
            };

    public CellLayout(Context context) {
        this(context, null);
    public CellLayout(Context context, CellLayoutContainer container) {
        this(context, (AttributeSet) null);
        this.mCellLayoutContainer = container;
    }

    public CellLayout(Context context, AttributeSet attrs) {
@@ -316,6 +317,14 @@ public class CellLayout extends ViewGroup {
        addView(mShortcutsAndWidgets);
    }

    public CellLayoutContainer getCellLayoutContainer() {
        return mCellLayoutContainer;
    }

    public void setCellLayoutContainer(CellLayoutContainer cellLayoutContainer) {
        mCellLayoutContainer = cellLayoutContainer;
    }

    /**
     * Sets or clears a delegate used for accessible drag and drop
     */
@@ -573,10 +582,8 @@ public class CellLayout extends ViewGroup {
    }

    protected void updateBgAlpha() {
        if (!getWorkspace().mLauncher.isInState(EDIT_MODE)) {
        mBackground.setAlpha((int) (mSpringLoadedProgress * 255));
    }
    }

    /**
     * Set the progress of this page's scroll
@@ -1187,7 +1194,7 @@ public class CellLayout extends ViewGroup {
        // Apply local extracted color if the DragView is an AppWidgetHostViewDrawable.
        View view = dragObject.dragView.getContentView();
        if (view instanceof LauncherAppWidgetHostView) {
            int screenId = getWorkspace().getIdForScreen(this);
            int screenId = mCellLayoutContainer.getCellLayoutId(this);
            cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect);

            ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, this, screenId);
@@ -1200,23 +1207,17 @@ public class CellLayout extends ViewGroup {
            return getContext().getString(R.string.move_to_hotseat_position,
                    Math.max(cellX, cellY) + 1);
        } else {
            Workspace<?> workspace = getWorkspace();
            int row = cellY + 1;
            int col = workspace.mIsRtl ? mCountX - cellX : cellX + 1;
            int panelCount = workspace.getPanelCount();
            int screenId = workspace.getIdForScreen(this);
            int pageIndex = workspace.getPageIndexForScreenId(screenId);
            int col = Utilities.isRtl(getResources()) ? mCountX - cellX : cellX + 1;
            int panelCount = mCellLayoutContainer.getPanelCount();
            int pageIndex = mCellLayoutContainer.getCellLayoutIndex(this);
            if (panelCount > 1) {
                // Increment the column if the target is on the right side of a two panel home
                col += (pageIndex % panelCount) * mCountX;
            }
            return getContext().getString(R.string.move_to_empty_cell_description, row, col,
                    workspace.getPageDescription(pageIndex));
        }
                    mCellLayoutContainer.getPageDescription(pageIndex));
        }

    private Workspace<?> getWorkspace() {
        return Launcher.cast(mActivity).getWorkspace();
    }

    public void clearDragOutlines() {
@@ -1452,7 +1453,7 @@ public class CellLayout extends ViewGroup {
    private void commitTempPlacement(View dragView) {
        mTmpOccupied.copyTo(mOccupied);

        int screenId = getWorkspace().getIdForScreen(this);
        int screenId = mCellLayoutContainer.getCellLayoutId(this);
        int container = Favorites.CONTAINER_DESKTOP;

        if (mContainerType == HOTSEAT) {
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3;

/**
 * This interface should be implemented for any container/view that has a CellLayout as a children.
 */
public interface CellLayoutContainer {

    /**
     * Get the CellLayoutId for the given cellLayout.
     */
    int getCellLayoutId(CellLayout cellLayout);

    /**
     * Get the index of the given CellLayout out of all the other CellLayouts.
     */
    int getCellLayoutIndex(CellLayout cellLayout);

    /**
     * The total number of CellLayouts in the container.
     */
    int getPanelCount();

    /**
     * Used for accessibility, it returns the string that the assistant is going to say when
     * referring to the given CellLayout.
     */
    String getPageDescription(int pageIndex);
}
+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ public class Hotseat extends CellLayout implements Insettable {

    public void setWorkspace(Workspace<?> w) {
        mWorkspace = w;
        setCellLayoutContainer(w);
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -522,7 +522,7 @@ public class Launcher extends StatefulActivity<LauncherState>
        mAppWidgetHolder.startListening();
        mAppWidgetHolder.addProviderChangeListener(() -> refreshAndBindWidgetsForPackageUser(null));
        mItemInflater = new ItemInflater<>(this, mAppWidgetHolder, getItemOnClickListener(),
                mFocusHandler, new CellLayout(mWorkspace.getContext()));
                mFocusHandler, new CellLayout(mWorkspace.getContext(), mWorkspace));

        mPopupDataProvider = new PopupDataProvider(this::updateNotificationDots);

+22 −14
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ import java.util.stream.Collectors;
 * @param <T> Class that extends View and PageIndicator
 */
public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        implements DropTarget, DragSource, View.OnTouchListener,
        implements DropTarget, DragSource, View.OnTouchListener, CellLayoutContainer,
        DragController.DragListener, Insettable, StateHandler<LauncherState>,
        WorkspaceLayoutManager, LauncherBindableItemsContainer, LauncherOverlayCallbacks {

@@ -511,11 +511,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        return !FOLDABLE_SINGLE_PAGE.get() && mLauncher.mDeviceProfile.isTwoPanels;
    }

    @Override
    public int getPanelCount() {
        return isTwoPanelEnabled() ? 2 : super.getPanelCount();
    }

    public void deferRemoveExtraEmptyScreen() {
        mDeferRemoveExtraEmptyScreen = true;
    }
@@ -683,6 +678,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
            newScreen = (CellLayout) LayoutInflater.from(getContext()).inflate(
                    R.layout.workspace_screen, this, false /* attachToRoot */);
        }
        newScreen.setCellLayoutContainer(this);

        mWorkspaceScreens.put(screenId, newScreen);
        mScreenOrder.add(insertIndex, screenId);
@@ -949,7 +945,8 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        return mWorkspaceScreens.get(screenId);
    }

    public int getIdForScreen(CellLayout layout) {
    @Override
    public int getCellLayoutId(CellLayout layout) {
        int index = mWorkspaceScreens.indexOfValue(layout);
        if (index != -1) {
            return mWorkspaceScreens.keyAt(index);
@@ -961,6 +958,16 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        return indexOfChild(mWorkspaceScreens.get(screenId));
    }

    @Override
    public int getCellLayoutIndex(CellLayout cellLayout) {
        return indexOfChild(mWorkspaceScreens.get(getCellLayoutId(cellLayout)));
    }

    @Override
    public int getPanelCount() {
        return isTwoPanelEnabled() ? 2 : super.getPanelCount();
    }

    public IntSet getCurrentPageScreenIds() {
        return IntSet.wrap(getScreenIdForPageIndex(getCurrentPage()));
    }
@@ -1001,7 +1008,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        if (!isTwoPanelEnabled()) {
            return null;
        }
        int screenId = getIdForScreen(cellLayout);
        int screenId = getCellLayoutId(cellLayout);
        if (screenId == -1) {
            return null;
        }
@@ -1826,7 +1833,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
            }
        }

        int screenId = getIdForScreen(dropTargetLayout);
        int screenId = getCellLayoutId(dropTargetLayout);
        if (Workspace.EXTRA_EMPTY_SCREEN_IDS.contains(screenId)) {
            commitExtraEmptyScreens();
        }
@@ -1909,7 +1916,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>

        if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false;
        mCreateUserFolderOnDrop = false;
        final int screenId = getIdForScreen(target);
        final int screenId = getCellLayoutId(target);

        boolean aboveShortcut = (v.getTag() instanceof WorkspaceItemInfo);
        boolean willBecomeShortcut = (newView.getTag() instanceof WorkspaceItemInfo);
@@ -2010,7 +2017,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
                        LauncherSettings.Favorites.CONTAINER_HOTSEAT :
                        LauncherSettings.Favorites.CONTAINER_DESKTOP;
                int screenId = (mTargetCell[0] < 0) ?
                        mDragInfo.screenId : getIdForScreen(dropTargetLayout);
                        mDragInfo.screenId : getCellLayoutId(dropTargetLayout);
                int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
                int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
                // First we find the cell nearest to point at which the item is
@@ -2766,7 +2773,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
        final int container = mLauncher.isHotseatLayout(cellLayout)
                ? LauncherSettings.Favorites.CONTAINER_HOTSEAT
                : LauncherSettings.Favorites.CONTAINER_DESKTOP;
        final int screenId = getIdForScreen(cellLayout);
        final int screenId = getCellLayoutId(cellLayout);
        if (!mLauncher.isHotseatLayout(cellLayout)
                && screenId != getScreenIdForPageIndex(mCurrentPage)
                && !mLauncher.isInState(SPRING_LOADED)
@@ -3480,14 +3487,15 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>

    @Override
    protected String getCurrentPageDescription() {
        int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
        return getPageDescription(page);
        int pageIndex = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
        return getPageDescription(pageIndex);
    }

    /**
     * @param page page index.
     * @return Description of the page at the given page index.
     */
    @Override
    public String getPageDescription(int page) {
        int nScreens = getChildCount();
        int extraScreenId = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID);
Loading