From fc68cd402a5cf3b04ce747d51e78f080ef0c45b6 Mon Sep 17 00:00:00 2001 From: Federico Baron Date: Fri, 16 May 2025 22:32:00 +0000 Subject: [PATCH] Adding interfaces for long press menu updates Bug: 416087474 Test: EXEMPT adding interfaces only Flag: EXEMPT adding interfaces only Change-Id: I50d73b655622a249ce293e1dc456b6a2a27fe810 --- src/com/android/launcher3/GridHighlighter.kt | 72 +++++++++++++++++++ src/com/android/launcher3/popup/Poppable.kt | 38 ++++++++++ src/com/android/launcher3/popup/Popup.kt | 30 ++++++++ .../launcher3/popup/PopupController.kt | 51 +++++++++++++ .../launcher3/popup/PopupDataRepository.kt | 67 +++++++++++++++++ 5 files changed, 258 insertions(+) create mode 100644 src/com/android/launcher3/GridHighlighter.kt create mode 100644 src/com/android/launcher3/popup/Poppable.kt create mode 100644 src/com/android/launcher3/popup/Popup.kt create mode 100644 src/com/android/launcher3/popup/PopupController.kt create mode 100644 src/com/android/launcher3/popup/PopupDataRepository.kt diff --git a/src/com/android/launcher3/GridHighlighter.kt b/src/com/android/launcher3/GridHighlighter.kt new file mode 100644 index 0000000000..6904eed282 --- /dev/null +++ b/src/com/android/launcher3/GridHighlighter.kt @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2025 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 + +import com.android.launcher3.model.data.ItemInfo + +/** + * Data class containing which cells should be highlighted and the container in which we are trying + * to highlight the cell. Depending on the container we may or may not want to show the highlight. + */ +data class CellsToHighlight(val cells: List, val container: Int) + +/** Data class for the position of a cell which we would want to highlight. */ +data class CellPosition(val col: Int, val row: Int) + +/** Interface for highlighting items on the home screen grid. */ +interface GridHighlighter { + /** Show the highlight when called. */ + fun showHighlight() + + /** Dismiss the highlight when called. */ + fun dismissHighlight() + + /** Factory for creating a GridHighlighter to highlight certain cells in a grid. */ + companion object GridHighlighterFactory { + + /** + * Creates a highlighter for the grid cell we want to highlight. + * + * @param cellsToHighlight is the cells that we should highlight, along with the container + * to which they belong. + * @param shouldAddPadding tells us whether we want to add padding to the highlighted cells. + * @param cellLayout is used to add/remove the highlights inside of the correct CellLayout + * @return GridHighlighter that we create when calling this function. + */ + fun createGridHighlighter( + cellsToHighlight: CellsToHighlight, + shouldAddPadding: Boolean, + cellLayout: CellLayout, + ): GridHighlighter? { + return TODO("Provide the return value") + } + + /** + * Creates a highlighter for the grid item we want to highlight. This would be used to + * highlight items that might have a different highlighting logic, such as widgets where we + * would open their AppWidgetResizeFrame instead of using the general grid highlighting + * logic. + * + * @param itemInfo is used to get certain specifics about the item we are trying to + * highlight, such as its spanX, spanY. + * @return GridHighlighter that we create when calling this function. + */ + fun createGridHighlighter(itemInfo: ItemInfo): GridHighlighter? { + return TODO("Provide the return value") + } + } +} diff --git a/src/com/android/launcher3/popup/Poppable.kt b/src/com/android/launcher3/popup/Poppable.kt new file mode 100644 index 0000000000..c6bd974996 --- /dev/null +++ b/src/com/android/launcher3/popup/Poppable.kt @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2025 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.popup + +/** Enum for the type of poppable. Based on this we want to show different shortcuts */ +enum class PoppableType { + APP, + FOLDER, + WIDGET, + APP_PAIR, +} + +/** Items for which we can trigger a popup menu would implement this interface. */ +interface Poppable { + + /** @return a controller to handle actions for the popup. */ + fun getPopupController(): PopupController? + + /** Sets the popup controller to help us handle actions for the popup. */ + fun setPopupController(popupController: PopupController) + + /** @return the type of poppable that this item is. */ + fun getPoppableType(): PoppableType +} diff --git a/src/com/android/launcher3/popup/Popup.kt b/src/com/android/launcher3/popup/Popup.kt new file mode 100644 index 0000000000..db5855dc9f --- /dev/null +++ b/src/com/android/launcher3/popup/Popup.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2025 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.popup + +import com.android.launcher3.dragndrop.DragOptions + +/** Interface that handles drag related actions. */ +interface Popup { + + /** + * Creates a PreDragCondition and returns it. + * + * @return a PreDragCondition which helps handle dragging behavior. + */ + fun createPreDragCondition(): DragOptions.PreDragCondition? +} diff --git a/src/com/android/launcher3/popup/PopupController.kt b/src/com/android/launcher3/popup/PopupController.kt new file mode 100644 index 0000000000..87c5d0169e --- /dev/null +++ b/src/com/android/launcher3/popup/PopupController.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2025 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.popup + +import com.android.launcher3.model.data.ItemInfo + +/** + * Controller interface for popups. It handles actions for the popups such as showing and dismissing + * popups. + */ +interface PopupController { + /** + * Shows the popup when called. + * + * @param popupDataRepository is the repository which has all the data we need to show the + * correct long press menu shortcuts. + * @return PopupDragController which handles drag related actions due to showing the popup. + */ + fun show(popupDataRepository: PopupDataRepository): Popup? + + /** Dismisses the popup when called. */ + fun dismiss() + + /** Factory for making a popup controller. */ + companion object PopupControllerFactory { + /** + * Creates a popup controller. + * + * @param itemInfo is the item info for the popup controller for which we create the popup + * controller. + * @return a new PopupController. + */ + fun createPopupControllerFactory(itemInfo: ItemInfo): PopupController { + return TODO("Provide the return value") + } + } +} diff --git a/src/com/android/launcher3/popup/PopupDataRepository.kt b/src/com/android/launcher3/popup/PopupDataRepository.kt new file mode 100644 index 0000000000..032aecd803 --- /dev/null +++ b/src/com/android/launcher3/popup/PopupDataRepository.kt @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2025 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.popup + +import android.content.Intent +import com.android.launcher3.model.data.ItemInfo +import java.util.stream.Stream + +/** + * Enum for the category of popup we have, as we handle different categories of shortcuts + * differently depending on the category. + */ +enum class PopupCategory { + SYSTEM_SHORTCUT, + SYSTEM_SHORTCUT_FIXED, +} + +/** Data class which stores all the values we need to create a long press menu shortcut. */ +data class PopupData( + val iconResId: Int, + val labelResId: Int, + val intent: Intent, + val category: PopupCategory, +) + +/** Repository to get all the popup data needed for the long press menu. */ +interface PopupDataRepository { + /** + * @return a map where we the key is the type of poppable and the value is a stream of popup + * data belonging to that type. + */ + fun getAllPopupData(): Map> + + /** + * @param type of PoppableType is what we use to filter shortcuts to only show the ones for that + * type of shortcut (e.g: only show long press shortcuts that belong to Folder type). + * @return a stream of popup data belonging to that type. + */ + fun getPopupDataByType(type: PoppableType): Stream + + /** Factory for creating a popup data repository */ + companion object PopupDataRepositoryFactory { + /** + * Creates a popup data repository. + * + * @param itemInfo is all the items for which we want to aggregate their popup data. + * @return a new PopupDataRepository. + */ + fun createRepository(vararg itemInfo: ItemInfo): PopupDataRepository { + return TODO("Provide the return value") + } + } +}