The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 19 | import static com.android.launcher3.LauncherState.EDIT_MODE; |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.dragndrop.DraggableView.DRAGGABLE_ICON; |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR; |
Sunny Goyal | 82dfc15 | 2023-02-24 16:50:09 -0800 | [diff] [blame] | 22 | import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_REORDER_PREVIEW_OFFSET; |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 23 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 24 | import android.animation.Animator; |
Michael Jurka | 629758f | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 25 | import android.animation.AnimatorListenerAdapter; |
Chet Haase | 00397b1 | 2010-10-07 11:13:10 -0700 | [diff] [blame] | 26 | import android.animation.TimeInterpolator; |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 27 | import android.animation.ValueAnimator; |
| 28 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 29 | import android.annotation.SuppressLint; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.content.Context; |
Joe Onorato | 79e5626 | 2009-09-21 15:23:04 -0400 | [diff] [blame] | 31 | import android.content.res.Resources; |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 32 | import android.content.res.TypedArray; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 33 | import android.graphics.Canvas; |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 34 | import android.graphics.Color; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 35 | import android.graphics.Paint; |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 36 | import android.graphics.Point; |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 37 | import android.graphics.PointF; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | import android.graphics.Rect; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 39 | import android.graphics.RectF; |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 40 | import android.graphics.drawable.Drawable; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 41 | import android.os.Parcelable; |
Rajeev Kumar | 9962dbe | 2017-06-12 12:16:20 -0700 | [diff] [blame] | 42 | import android.util.ArrayMap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.util.AttributeSet; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 44 | import android.util.FloatProperty; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 45 | import android.util.Log; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 46 | import android.util.SparseArray; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | import android.view.MotionEvent; |
| 48 | import android.view.View; |
| 49 | import android.view.ViewDebug; |
| 50 | import android.view.ViewGroup; |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 51 | import android.view.accessibility.AccessibilityEvent; |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 52 | |
vadimt | 04f356f | 2019-02-14 18:46:36 -0800 | [diff] [blame] | 53 | import androidx.annotation.IntDef; |
Sebastian Franco | 5c8f868 | 2023-11-14 09:52:41 -0600 | [diff] [blame] | 54 | import androidx.annotation.Nullable; |
Sebastian Franco | 9ea36d4 | 2023-09-21 13:56:42 -0700 | [diff] [blame] | 55 | import androidx.annotation.Px; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 56 | import androidx.core.graphics.ColorUtils; |
vadimt | 04f356f | 2019-02-14 18:46:36 -0800 | [diff] [blame] | 57 | import androidx.core.view.ViewCompat; |
| 58 | |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 59 | import com.android.app.animation.Interpolators; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 60 | import com.android.launcher3.LauncherSettings.Favorites; |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 61 | import com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate; |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 62 | import com.android.launcher3.celllayout.CellLayoutLayoutParams; |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 63 | import com.android.launcher3.celllayout.CellPosMapper.CellPos; |
Sebastian Franco | 5f0af4f | 2023-11-21 10:45:45 -0600 | [diff] [blame] | 64 | import com.android.launcher3.celllayout.DelegatedCellDrawing; |
| 65 | import com.android.launcher3.celllayout.ItemConfiguration; |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 66 | import com.android.launcher3.celllayout.ReorderAlgorithm; |
Sebastian Franco | 25f8e40 | 2023-12-02 13:54:05 -0600 | [diff] [blame] | 67 | import com.android.launcher3.celllayout.ReorderParameters; |
Sebastian Franco | f765425 | 2024-01-18 11:50:50 -0800 | [diff] [blame^] | 68 | import com.android.launcher3.celllayout.ReorderPreviewAnimation; |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 69 | import com.android.launcher3.config.FeatureFlags; |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 70 | import com.android.launcher3.dragndrop.DraggableView; |
Jon Miranda | a0233f7 | 2017-06-22 18:34:45 -0700 | [diff] [blame] | 71 | import com.android.launcher3.folder.PreviewBackground; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 72 | import com.android.launcher3.model.data.ItemInfo; |
Sebastian Franco | f153d91 | 2022-04-22 16:15:27 -0500 | [diff] [blame] | 73 | import com.android.launcher3.model.data.LauncherAppWidgetInfo; |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 74 | import com.android.launcher3.util.CellAndSpan; |
| 75 | import com.android.launcher3.util.GridOccupancy; |
Sunny Goyal | 82dfc15 | 2023-02-24 16:50:09 -0800 | [diff] [blame] | 76 | import com.android.launcher3.util.MultiTranslateDelegate; |
Sunny Goyal | e2fd14b | 2015-08-27 17:45:46 -0700 | [diff] [blame] | 77 | import com.android.launcher3.util.ParcelableSparseArray; |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 78 | import com.android.launcher3.util.Themes; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 79 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 80 | import com.android.launcher3.views.ActivityContext; |
Steven Ng | 3242720 | 2021-04-19 18:12:12 +0100 | [diff] [blame] | 81 | import com.android.launcher3.widget.LauncherAppWidgetHostView; |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 82 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 83 | import java.lang.annotation.Retention; |
| 84 | import java.lang.annotation.RetentionPolicy; |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 85 | import java.util.ArrayList; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 86 | import java.util.Arrays; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 87 | import java.util.Stack; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 88 | |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 89 | public class CellLayout extends ViewGroup { |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 90 | private static final String TAG = "CellLayout"; |
| 91 | private static final boolean LOGD = false; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 92 | |
Tony Wickham | ec6fd6f | 2023-03-11 02:08:57 +0000 | [diff] [blame] | 93 | /** The color of the "leave-behind" shape when a folder is opened from Hotseat. */ |
| 94 | private static final int FOLDER_LEAVE_BEHIND_COLOR = Color.argb(160, 245, 245, 245); |
| 95 | |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 96 | protected final ActivityContext mActivity; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 97 | @ViewDebug.ExportedProperty(category = "launcher") |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 98 | @Thunk int mCellWidth; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 99 | @ViewDebug.ExportedProperty(category = "launcher") |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 100 | @Thunk int mCellHeight; |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 101 | private int mFixedCellWidth; |
| 102 | private int mFixedCellHeight; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 103 | @ViewDebug.ExportedProperty(category = "launcher") |
Sebastian Franco | 2542386 | 2023-03-10 10:50:37 -0800 | [diff] [blame] | 104 | protected Point mBorderSpace; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 105 | |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 106 | @ViewDebug.ExportedProperty(category = "launcher") |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 107 | protected int mCountX; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 108 | @ViewDebug.ExportedProperty(category = "launcher") |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 109 | protected int mCountY; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | |
Adam Cohen | 917e388 | 2013-10-31 15:03:35 -0700 | [diff] [blame] | 111 | private boolean mDropPending = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 112 | |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 113 | // These are temporary variables to prevent having to allocate a new object just to |
| 114 | // return an (x, y) value from helper functions. Do NOT use them to maintain other state. |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 115 | @Thunk final int[] mTmpPoint = new int[2]; |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 116 | @Thunk final int[] mTempLocation = new int[2]; |
Sebastian Franco | 0dd5db8 | 2023-10-13 11:09:21 -0700 | [diff] [blame] | 117 | |
| 118 | @Thunk final Rect mTempOnDrawCellToRect = new Rect(); |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 119 | final PointF mTmpPointF = new PointF(); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 120 | |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 121 | protected GridOccupancy mOccupied; |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 122 | public GridOccupancy mTmpOccupied; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 124 | private OnTouchListener mInterceptTouchListener; |
| 125 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 126 | private final ArrayList<DelegatedCellDrawing> mDelegatedCellDrawings = new ArrayList<>(); |
Jon Miranda | a0233f7 | 2017-06-22 18:34:45 -0700 | [diff] [blame] | 127 | final PreviewBackground mFolderLeaveBehind = new PreviewBackground(); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 128 | |
Sunny Goyal | f5440cb | 2016-12-14 15:13:00 -0800 | [diff] [blame] | 129 | private static final int[] BACKGROUND_STATE_ACTIVE = new int[] { android.R.attr.state_active }; |
Sunny Goyal | e15e2a8 | 2017-12-15 13:05:42 -0800 | [diff] [blame] | 130 | private static final int[] BACKGROUND_STATE_DEFAULT = EMPTY_STATE_SET; |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 131 | protected final Drawable mBackground; |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 132 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 133 | // These values allow a fixed measurement to be set on the CellLayout. |
| 134 | private int mFixedWidth = -1; |
| 135 | private int mFixedHeight = -1; |
| 136 | |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 137 | // If we're actively dragging something over this screen, mIsDragOverlapping is true |
| 138 | private boolean mIsDragOverlapping = false; |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 139 | |
Winson Chung | 150fbab | 2010-09-29 17:14:26 -0700 | [diff] [blame] | 140 | // These arrays are used to implement the drag visualization on x-large screens. |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 141 | // They are used as circular arrays, indexed by mDragOutlineCurrent. |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 142 | @Thunk final CellLayoutLayoutParams[] mDragOutlines = new CellLayoutLayoutParams[4]; |
Rajeev Kumar | 9962dbe | 2017-06-12 12:16:20 -0700 | [diff] [blame] | 143 | @Thunk final float[] mDragOutlineAlphas = new float[mDragOutlines.length]; |
| 144 | private final InterruptibleInOutAnimator[] mDragOutlineAnims = |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 145 | new InterruptibleInOutAnimator[mDragOutlines.length]; |
Winson Chung | 150fbab | 2010-09-29 17:14:26 -0700 | [diff] [blame] | 146 | |
| 147 | // Used as an index into the above 3 arrays; indicates which is the most current value. |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 148 | private int mDragOutlineCurrent = 0; |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 149 | private final Paint mDragOutlinePaint = new Paint(); |
Winson Chung | 150fbab | 2010-09-29 17:14:26 -0700 | [diff] [blame] | 150 | |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 151 | @Thunk final ArrayMap<CellLayoutLayoutParams, Animator> mReorderAnimators = new ArrayMap<>(); |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 152 | @Thunk final ArrayMap<Reorderable, ReorderPreviewAnimation> mShakeAnimators = new ArrayMap<>(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 153 | |
| 154 | private boolean mItemPlacementDirty = false; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 155 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 156 | // Used to visualize the grid and drop locations |
| 157 | private boolean mVisualizeCells = false; |
| 158 | private boolean mVisualizeDropLocation = true; |
| 159 | private RectF mVisualizeGridRect = new RectF(); |
| 160 | private Paint mVisualizeGridPaint = new Paint(); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 161 | private int mGridVisualizationRoundingRadius; |
| 162 | private float mGridAlpha = 0f; |
| 163 | private int mGridColor = 0; |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 164 | protected float mSpringLoadedProgress = 0f; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 165 | private float mScrollProgress = 0f; |
| 166 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 167 | // When a drag operation is in progress, holds the nearest cell to the touch point |
| 168 | private final int[] mDragCell = new int[2]; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 169 | private final int[] mDragCellSpan = new int[2]; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 170 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 171 | private boolean mDragging = false; |
| 172 | |
Rajeev Kumar | 9962dbe | 2017-06-12 12:16:20 -0700 | [diff] [blame] | 173 | private final TimeInterpolator mEaseOutInterpolator; |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 174 | protected final ShortcutAndWidgetContainer mShortcutsAndWidgets; |
Sebastian Franco | 9ea36d4 | 2023-09-21 13:56:42 -0700 | [diff] [blame] | 175 | @Px |
| 176 | protected int mSpaceBetweenCellLayoutsPx = 0; |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 177 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 178 | @Retention(RetentionPolicy.SOURCE) |
| 179 | @IntDef({WORKSPACE, HOTSEAT, FOLDER}) |
| 180 | public @interface ContainerType{} |
| 181 | public static final int WORKSPACE = 0; |
| 182 | public static final int HOTSEAT = 1; |
| 183 | public static final int FOLDER = 2; |
| 184 | |
| 185 | @ContainerType private final int mContainerType; |
| 186 | |
Sebastian Franco | f765425 | 2024-01-18 11:50:50 -0800 | [diff] [blame^] | 187 | public static final float DEFAULT_SCALE = 1f; |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 188 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 189 | public static final int MODE_SHOW_REORDER_HINT = 0; |
| 190 | public static final int MODE_DRAG_OVER = 1; |
| 191 | public static final int MODE_ON_DROP = 2; |
| 192 | public static final int MODE_ON_DROP_EXTERNAL = 3; |
| 193 | public static final int MODE_ACCEPT_DROP = 4; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 194 | private static final boolean DESTRUCTIVE_REORDER = false; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 195 | private static final boolean DEBUG_VISUALIZE_OCCUPIED = false; |
| 196 | |
Sebastian Franco | f765425 | 2024-01-18 11:50:50 -0800 | [diff] [blame^] | 197 | public static final float REORDER_PREVIEW_MAGNITUDE = 0.12f; |
| 198 | public static final int REORDER_ANIMATION_DURATION = 150; |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 199 | @Thunk final float mReorderPreviewAnimationMagnitude; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 200 | |
Rajeev Kumar | 9962dbe | 2017-06-12 12:16:20 -0700 | [diff] [blame] | 201 | private final ArrayList<View> mIntersectingViews = new ArrayList<>(); |
| 202 | private final Rect mOccupiedRect = new Rect(); |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 203 | public final int[] mDirectionVector = new int[2]; |
Steven Ng | 30dd1d6 | 2021-03-15 21:45:49 +0000 | [diff] [blame] | 204 | |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 205 | ItemConfiguration mPreviousSolution = null; |
Adam Cohen | b209e63 | 2012-03-27 17:09:36 -0700 | [diff] [blame] | 206 | private static final int INVALID_DIRECTION = -100; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 207 | |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 208 | private final Rect mTempRect = new Rect(); |
Jonathan Miranda | 21930da | 2021-05-03 18:44:13 +0000 | [diff] [blame] | 209 | private final RectF mTempRectF = new RectF(); |
Jon Miranda | 88b7f6a | 2021-05-03 16:49:53 -0700 | [diff] [blame] | 210 | private final float[] mTmpFloatArray = new float[4]; |
Winson Chung | 3a6e7f3 | 2013-10-09 15:50:52 -0700 | [diff] [blame] | 211 | |
Sunny Goyal | 73b5a27 | 2019-12-09 14:55:56 -0800 | [diff] [blame] | 212 | private static final Paint sPaint = new Paint(); |
Romain Guy | 8a0bff5 | 2012-05-06 13:14:33 -0700 | [diff] [blame] | 213 | |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 214 | // Related to accessible drag and drop |
Adam Cohen | 6e7c37a | 2020-06-25 19:22:37 -0700 | [diff] [blame] | 215 | DragAndDropAccessibilityDelegate mTouchHelper; |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 216 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 217 | |
| 218 | public static final FloatProperty<CellLayout> SPRING_LOADED_PROGRESS = |
| 219 | new FloatProperty<CellLayout>("spring_loaded_progress") { |
| 220 | @Override |
| 221 | public Float get(CellLayout cl) { |
| 222 | return cl.getSpringLoadedProgress(); |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public void setValue(CellLayout cl, float progress) { |
| 227 | cl.setSpringLoadedProgress(progress); |
| 228 | } |
| 229 | }; |
| 230 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 231 | public CellLayout(Context context) { |
| 232 | this(context, null); |
| 233 | } |
| 234 | |
| 235 | public CellLayout(Context context, AttributeSet attrs) { |
| 236 | this(context, attrs, 0); |
| 237 | } |
| 238 | |
| 239 | public CellLayout(Context context, AttributeSet attrs, int defStyle) { |
| 240 | super(context, attrs, defStyle); |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 241 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0); |
| 242 | mContainerType = a.getInteger(R.styleable.CellLayout_containerType, WORKSPACE); |
| 243 | a.recycle(); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 244 | |
| 245 | // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show |
| 246 | // the user where a dragged item will land when dropped. |
| 247 | setWillNotDraw(false); |
Romain Guy | ce3cbd1 | 2013-02-25 15:00:36 -0800 | [diff] [blame] | 248 | setClipToPadding(false); |
Pat Manning | d0f729d | 2023-01-09 12:04:25 +0000 | [diff] [blame] | 249 | setClipChildren(false); |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 250 | mActivity = ActivityContext.lookupContext(context); |
Steven Ng | cc505b8 | 2021-03-18 23:04:35 +0000 | [diff] [blame] | 251 | DeviceProfile deviceProfile = mActivity.getDeviceProfile(); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 252 | |
Thales Lima | 8cd020b | 2022-03-15 20:15:14 +0000 | [diff] [blame] | 253 | resetCellSizeInternal(deviceProfile); |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 254 | |
Steven Ng | cc505b8 | 2021-03-18 23:04:35 +0000 | [diff] [blame] | 255 | mCountX = deviceProfile.inv.numColumns; |
| 256 | mCountY = deviceProfile.inv.numRows; |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 257 | mOccupied = new GridOccupancy(mCountX, mCountY); |
| 258 | mTmpOccupied = new GridOccupancy(mCountX, mCountY); |
| 259 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 260 | mFolderLeaveBehind.mDelegateCellX = -1; |
| 261 | mFolderLeaveBehind.mDelegateCellY = -1; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 262 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 263 | setAlwaysDrawnWithCacheEnabled(false); |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 264 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 265 | Resources res = getResources(); |
| 266 | |
| 267 | mBackground = getContext().getDrawable(R.drawable.bg_celllayout); |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 268 | mBackground.setCallback(this); |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 269 | mBackground.setAlpha(0); |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 270 | |
Yogisha Dixit | c0ac1dd | 2021-05-29 00:26:25 +0100 | [diff] [blame] | 271 | mGridColor = Themes.getAttrColor(getContext(), R.attr.workspaceAccentColor); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 272 | mGridVisualizationRoundingRadius = |
| 273 | res.getDimensionPixelSize(R.dimen.grid_visualization_rounding_radius); |
Steven Ng | cc505b8 | 2021-03-18 23:04:35 +0000 | [diff] [blame] | 274 | mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * deviceProfile.iconSizePx); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 275 | |
Patrick Dubroy | 046e7eb | 2010-10-06 12:14:43 -0700 | [diff] [blame] | 276 | // Initialize the data structures used for the drag visualization. |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 277 | mEaseOutInterpolator = Interpolators.DECELERATE_QUINT; // Quint ease out |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 278 | mDragCell[0] = mDragCell[1] = -1; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 279 | mDragCellSpan[0] = mDragCellSpan[1] = -1; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 280 | for (int i = 0; i < mDragOutlines.length; i++) { |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 281 | mDragOutlines[i] = new CellLayoutLayoutParams(0, 0, 0, 0); |
Patrick Dubroy | 046e7eb | 2010-10-06 12:14:43 -0700 | [diff] [blame] | 282 | } |
Mario Bertschler | 54ba601 | 2017-06-08 10:53:53 -0700 | [diff] [blame] | 283 | mDragOutlinePaint.setColor(Themes.getAttrColor(context, R.attr.workspaceTextColor)); |
Patrick Dubroy | 046e7eb | 2010-10-06 12:14:43 -0700 | [diff] [blame] | 284 | |
| 285 | // When dragging things around the home screens, we show a green outline of |
| 286 | // where the item will land. The outlines gradually fade out, leaving a trail |
| 287 | // behind the drag path. |
| 288 | // Set up all the animations that are used to implement this fading. |
| 289 | final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 290 | final float fromAlphaValue = 0; |
| 291 | final float toAlphaValue = (float)res.getInteger(R.integer.config_dragOutlineMaxAlpha); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 292 | |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 293 | Arrays.fill(mDragOutlineAlphas, fromAlphaValue); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 294 | |
| 295 | for (int i = 0; i < mDragOutlineAnims.length; i++) { |
Patrick Dubroy | 046e7eb | 2010-10-06 12:14:43 -0700 | [diff] [blame] | 296 | final InterruptibleInOutAnimator anim = |
Sebastian Franco | f153d91 | 2022-04-22 16:15:27 -0500 | [diff] [blame] | 297 | new InterruptibleInOutAnimator(duration, fromAlphaValue, toAlphaValue); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 298 | anim.getAnimator().setInterpolator(mEaseOutInterpolator); |
Patrick Dubroy | 046e7eb | 2010-10-06 12:14:43 -0700 | [diff] [blame] | 299 | final int thisIndex = i; |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 300 | anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 301 | public void onAnimationUpdate(ValueAnimator animation) { |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 302 | // If an animation is started and then stopped very quickly, we can still |
| 303 | // get spurious updates we've cleared the tag. Guard against this. |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 304 | mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); |
| 305 | CellLayout.this.invalidate(); |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 306 | } |
| 307 | }); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 308 | // The animation holds a reference to the drag outline bitmap as long is it's |
| 309 | // running. This way the bitmap can be GCed when the animations are complete. |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 310 | mDragOutlineAnims[i] = anim; |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 311 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 312 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 313 | mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context, mContainerType); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 314 | mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY, |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 315 | mBorderSpace); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 316 | addView(mShortcutsAndWidgets); |
Michael Jurka | 1801479 | 2010-10-14 09:01:34 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Sets or clears a delegate used for accessible drag and drop |
| 321 | */ |
| 322 | public void setDragAndDropAccessibilityDelegate(DragAndDropAccessibilityDelegate delegate) { |
| 323 | setOnClickListener(delegate); |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 324 | ViewCompat.setAccessibilityDelegate(this, delegate); |
| 325 | |
Adam Cohen | 6e7c37a | 2020-06-25 19:22:37 -0700 | [diff] [blame] | 326 | mTouchHelper = delegate; |
| 327 | int accessibilityFlag = mTouchHelper != null |
Sunny Goyal | 9b18010 | 2020-03-11 10:02:29 -0700 | [diff] [blame] | 328 | ? IMPORTANT_FOR_ACCESSIBILITY_YES : IMPORTANT_FOR_ACCESSIBILITY_NO; |
| 329 | setImportantForAccessibility(accessibilityFlag); |
| 330 | getShortcutsAndWidgets().setImportantForAccessibility(accessibilityFlag); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 331 | |
Sunny Goyal | 384b578 | 2021-02-09 22:50:02 -0800 | [diff] [blame] | 332 | // ExploreByTouchHelper sets focusability. Clear it when the delegate is cleared. |
| 333 | setFocusable(delegate != null); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 334 | // Invalidate the accessibility hierarchy |
| 335 | if (getParent() != null) { |
| 336 | getParent().notifySubtreeAccessibilityStateChanged( |
| 337 | this, this, AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE); |
| 338 | } |
| 339 | } |
| 340 | |
Sunny Goyal | a4647b6 | 2021-02-02 13:45:34 -0800 | [diff] [blame] | 341 | /** |
| 342 | * Returns the currently set accessibility delegate |
| 343 | */ |
| 344 | public DragAndDropAccessibilityDelegate getDragAndDropAccessibilityDelegate() { |
| 345 | return mTouchHelper; |
| 346 | } |
| 347 | |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 348 | @Override |
Adam Cohen | 6e7c37a | 2020-06-25 19:22:37 -0700 | [diff] [blame] | 349 | public boolean dispatchHoverEvent(MotionEvent event) { |
| 350 | // Always attempt to dispatch hover events to accessibility first. |
| 351 | if (mTouchHelper != null && mTouchHelper.dispatchHoverEvent(event)) { |
| 352 | return true; |
| 353 | } |
| 354 | return super.dispatchHoverEvent(event); |
| 355 | } |
| 356 | |
| 357 | @Override |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 358 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Winson Chung | f993518 | 2020-10-23 09:26:44 -0700 | [diff] [blame] | 359 | return mTouchHelper != null |
| 360 | || (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev)); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 361 | } |
| 362 | |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 363 | public void enableHardwareLayer(boolean hasLayer) { |
| 364 | mShortcutsAndWidgets.setLayerType(hasLayer ? LAYER_TYPE_HARDWARE : LAYER_TYPE_NONE, sPaint); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 365 | } |
| 366 | |
vadimt | 04f356f | 2019-02-14 18:46:36 -0800 | [diff] [blame] | 367 | public boolean isHardwareLayerEnabled() { |
| 368 | return mShortcutsAndWidgets.getLayerType() == LAYER_TYPE_HARDWARE; |
| 369 | } |
| 370 | |
Thales Lima | 8cd020b | 2022-03-15 20:15:14 +0000 | [diff] [blame] | 371 | /** |
| 372 | * Change sizes of cells |
| 373 | * |
| 374 | * @param width the new width of the cells |
| 375 | * @param height the new height of the cells |
| 376 | */ |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 377 | public void setCellDimensions(int width, int height) { |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 378 | mFixedCellWidth = mCellWidth = width; |
| 379 | mFixedCellHeight = mCellHeight = height; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 380 | mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY, |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 381 | mBorderSpace); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Thales Lima | 8cd020b | 2022-03-15 20:15:14 +0000 | [diff] [blame] | 384 | private void resetCellSizeInternal(DeviceProfile deviceProfile) { |
| 385 | switch (mContainerType) { |
| 386 | case FOLDER: |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 387 | mBorderSpace = new Point(deviceProfile.folderCellLayoutBorderSpacePx); |
Thales Lima | 8cd020b | 2022-03-15 20:15:14 +0000 | [diff] [blame] | 388 | break; |
| 389 | case HOTSEAT: |
| 390 | mBorderSpace = new Point(deviceProfile.hotseatBorderSpace, |
| 391 | deviceProfile.hotseatBorderSpace); |
| 392 | break; |
| 393 | case WORKSPACE: |
| 394 | default: |
| 395 | mBorderSpace = new Point(deviceProfile.cellLayoutBorderSpacePx); |
| 396 | break; |
| 397 | } |
| 398 | |
| 399 | mCellWidth = mCellHeight = -1; |
| 400 | mFixedCellWidth = mFixedCellHeight = -1; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Reset the cell sizes and border space |
| 405 | */ |
| 406 | public void resetCellSize(DeviceProfile deviceProfile) { |
| 407 | resetCellSizeInternal(deviceProfile); |
| 408 | requestLayout(); |
| 409 | } |
| 410 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 411 | public void setGridSize(int x, int y) { |
| 412 | mCountX = x; |
| 413 | mCountY = y; |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 414 | mOccupied = new GridOccupancy(mCountX, mCountY); |
| 415 | mTmpOccupied = new GridOccupancy(mCountX, mCountY); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 416 | mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY, |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 417 | mBorderSpace); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 418 | requestLayout(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Adam Cohen | 2374abf | 2013-04-16 14:56:57 -0700 | [diff] [blame] | 421 | // Set whether or not to invert the layout horizontally if the layout is in RTL mode. |
| 422 | public void setInvertIfRtl(boolean invert) { |
| 423 | mShortcutsAndWidgets.setInvertIfRtl(invert); |
| 424 | } |
| 425 | |
Adam Cohen | 917e388 | 2013-10-31 15:03:35 -0700 | [diff] [blame] | 426 | public void setDropPending(boolean pending) { |
| 427 | mDropPending = pending; |
| 428 | } |
| 429 | |
| 430 | public boolean isDropPending() { |
| 431 | return mDropPending; |
| 432 | } |
| 433 | |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 434 | void setIsDragOverlapping(boolean isDragOverlapping) { |
| 435 | if (mIsDragOverlapping != isDragOverlapping) { |
| 436 | mIsDragOverlapping = isDragOverlapping; |
Sunny Goyal | f5440cb | 2016-12-14 15:13:00 -0800 | [diff] [blame] | 437 | mBackground.setState(mIsDragOverlapping |
| 438 | ? BACKGROUND_STATE_ACTIVE : BACKGROUND_STATE_DEFAULT); |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 439 | invalidate(); |
| 440 | } |
| 441 | } |
| 442 | |
Sunny Goyal | e2fd14b | 2015-08-27 17:45:46 -0700 | [diff] [blame] | 443 | @Override |
| 444 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 445 | ParcelableSparseArray jail = getJailedArray(container); |
| 446 | super.dispatchSaveInstanceState(jail); |
| 447 | container.put(R.id.cell_layout_jail_id, jail); |
Sunny Goyal | e2fd14b | 2015-08-27 17:45:46 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | @Override |
| 451 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 452 | super.dispatchRestoreInstanceState(getJailedArray(container)); |
Sunny Goyal | e2fd14b | 2015-08-27 17:45:46 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 455 | /** |
| 456 | * Wrap the SparseArray in another Parcelable so that the item ids do not conflict with our |
| 457 | * our internal resource ids |
| 458 | */ |
Sunny Goyal | e2fd14b | 2015-08-27 17:45:46 -0700 | [diff] [blame] | 459 | private ParcelableSparseArray getJailedArray(SparseArray<Parcelable> container) { |
| 460 | final Parcelable parcelable = container.get(R.id.cell_layout_jail_id); |
| 461 | return parcelable instanceof ParcelableSparseArray ? |
| 462 | (ParcelableSparseArray) parcelable : new ParcelableSparseArray(); |
| 463 | } |
| 464 | |
Tony Wickham | 0f97b78 | 2015-12-02 17:55:07 -0800 | [diff] [blame] | 465 | public boolean getIsDragOverlapping() { |
| 466 | return mIsDragOverlapping; |
| 467 | } |
| 468 | |
Jeff Sharkey | 83f111d | 2009-04-20 21:03:13 -0700 | [diff] [blame] | 469 | @Override |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 470 | protected void onDraw(Canvas canvas) { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 471 | // When we're large, we are either drawn in a "hover" state (ie when dragging an item to |
| 472 | // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) |
| 473 | // When we're small, we are either drawn normally or in the "accepts drops" state (during |
| 474 | // a drag). However, we also drag the mini hover background *over* one of those two |
| 475 | // backgrounds |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 476 | if (mBackground.getAlpha() > 0) { |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 477 | mBackground.draw(canvas); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 478 | } |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 479 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 480 | if (DEBUG_VISUALIZE_OCCUPIED) { |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 481 | Rect cellBounds = new Rect(); |
| 482 | // Will contain the bounds of the cell including spacing between cells. |
| 483 | Rect cellBoundsWithSpacing = new Rect(); |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 484 | int[] targetCell = new int[2]; |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 485 | int[] cellCenter = new int[2]; |
| 486 | Paint debugPaint = new Paint(); |
| 487 | debugPaint.setStrokeWidth(Utilities.dpToPx(1)); |
| 488 | for (int x = 0; x < mCountX; x++) { |
| 489 | for (int y = 0; y < mCountY; y++) { |
| 490 | if (!mOccupied.cells[x][y]) { |
| 491 | continue; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 492 | } |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 493 | targetCell[0] = x; |
| 494 | targetCell[1] = y; |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 495 | |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 496 | boolean canCreateFolder = canCreateFolder(getChildAt(x, y)); |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 497 | cellToRect(x, y, 1, 1, cellBounds); |
| 498 | cellBoundsWithSpacing.set(cellBounds); |
| 499 | cellBoundsWithSpacing.inset(-mBorderSpace.x / 2, -mBorderSpace.y / 2); |
Tony Wickham | 3cfa5ed | 2021-11-03 13:20:43 -0700 | [diff] [blame] | 500 | getWorkspaceCellVisualCenter(x, y, cellCenter); |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 501 | |
| 502 | canvas.save(); |
| 503 | canvas.clipRect(cellBoundsWithSpacing); |
| 504 | |
| 505 | // Draw reorder drag target. |
| 506 | debugPaint.setColor(Color.RED); |
Sebastian Franco | 6e1024e | 2022-07-29 13:46:49 -0700 | [diff] [blame] | 507 | canvas.drawCircle(cellCenter[0], cellCenter[1], |
| 508 | getReorderRadius(targetCell, 1, 1), debugPaint); |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 509 | |
| 510 | // Draw folder creation drag target. |
| 511 | if (canCreateFolder) { |
| 512 | debugPaint.setColor(Color.GREEN); |
| 513 | canvas.drawCircle(cellCenter[0], cellCenter[1], |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 514 | getFolderCreationRadius(targetCell), debugPaint); |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | canvas.restore(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 522 | for (int i = 0; i < mDelegatedCellDrawings.size(); i++) { |
| 523 | DelegatedCellDrawing cellDrawing = mDelegatedCellDrawings.get(i); |
| 524 | cellToPoint(cellDrawing.mDelegateCellX, cellDrawing.mDelegateCellY, mTempLocation); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 525 | canvas.save(); |
| 526 | canvas.translate(mTempLocation[0], mTempLocation[1]); |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 527 | cellDrawing.drawUnderItem(canvas); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 528 | canvas.restore(); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 529 | } |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 530 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 531 | if (mFolderLeaveBehind.mDelegateCellX >= 0 && mFolderLeaveBehind.mDelegateCellY >= 0) { |
| 532 | cellToPoint(mFolderLeaveBehind.mDelegateCellX, |
| 533 | mFolderLeaveBehind.mDelegateCellY, mTempLocation); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 534 | canvas.save(); |
| 535 | canvas.translate(mTempLocation[0], mTempLocation[1]); |
Tony Wickham | ec6fd6f | 2023-03-11 02:08:57 +0000 | [diff] [blame] | 536 | mFolderLeaveBehind.drawLeaveBehind(canvas, FOLDER_LEAVE_BEHIND_COLOR); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 537 | canvas.restore(); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 538 | } |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 539 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 540 | if (mVisualizeCells || mVisualizeDropLocation) { |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 541 | visualizeGrid(canvas); |
| 542 | } |
| 543 | } |
| 544 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 545 | /** |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 546 | * Returns whether dropping an icon on the given View can create (or add to) a folder. |
| 547 | */ |
| 548 | private boolean canCreateFolder(View child) { |
| 549 | return child instanceof DraggableView |
| 550 | && ((DraggableView) child).getViewType() == DRAGGABLE_ICON; |
| 551 | } |
| 552 | |
| 553 | /** |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 554 | * Indicates the progress of the Workspace entering the SpringLoaded state; allows the |
| 555 | * CellLayout to update various visuals for this state. |
| 556 | * |
| 557 | * @param progress |
| 558 | */ |
| 559 | public void setSpringLoadedProgress(float progress) { |
| 560 | if (Float.compare(progress, mSpringLoadedProgress) != 0) { |
| 561 | mSpringLoadedProgress = progress; |
fbaron | e74256b | 2023-04-10 14:50:31 -0700 | [diff] [blame] | 562 | updateBgAlpha(); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 563 | setGridAlpha(progress); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * See setSpringLoadedProgress |
| 569 | * @return progress |
| 570 | */ |
| 571 | public float getSpringLoadedProgress() { |
| 572 | return mSpringLoadedProgress; |
| 573 | } |
| 574 | |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 575 | protected void updateBgAlpha() { |
Charlie Anderson | 438d405 | 2023-04-25 14:38:57 -0400 | [diff] [blame] | 576 | if (!getWorkspace().mLauncher.isInState(EDIT_MODE)) { |
| 577 | mBackground.setAlpha((int) (mSpringLoadedProgress * 255)); |
| 578 | } |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Set the progress of this page's scroll |
| 583 | * |
| 584 | * @param progress 0 if the screen is centered, +/-1 if it is to the right / left respectively |
| 585 | */ |
| 586 | public void setScrollProgress(float progress) { |
| 587 | if (Float.compare(Math.abs(progress), mScrollProgress) != 0) { |
| 588 | mScrollProgress = Math.abs(progress); |
fbaron | e74256b | 2023-04-10 14:50:31 -0700 | [diff] [blame] | 589 | updateBgAlpha(); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | private void setGridAlpha(float gridAlpha) { |
| 594 | if (Float.compare(gridAlpha, mGridAlpha) != 0) { |
| 595 | mGridAlpha = gridAlpha; |
| 596 | invalidate(); |
| 597 | } |
| 598 | } |
| 599 | |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 600 | protected void visualizeGrid(Canvas canvas) { |
Adam Cohen | 0c4d278 | 2021-04-29 15:56:13 -0700 | [diff] [blame] | 601 | DeviceProfile dp = mActivity.getDeviceProfile(); |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 602 | int paddingX = Math.min((mCellWidth - dp.iconSizePx) / 2, dp.gridVisualizationPaddingX); |
| 603 | int paddingY = Math.min((mCellHeight - dp.iconSizePx) / 2, dp.gridVisualizationPaddingY); |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 604 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 605 | mVisualizeGridPaint.setStrokeWidth(8); |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 606 | |
Sebastian Franco | 0dd5db8 | 2023-10-13 11:09:21 -0700 | [diff] [blame] | 607 | // This is used for debugging purposes only |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 608 | if (mVisualizeCells) { |
Sebastian Franco | 0dd5db8 | 2023-10-13 11:09:21 -0700 | [diff] [blame] | 609 | int paintAlpha = (int) (120 * mGridAlpha); |
| 610 | mVisualizeGridPaint.setColor(ColorUtils.setAlphaComponent(mGridColor, paintAlpha)); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 611 | for (int i = 0; i < mCountX; i++) { |
| 612 | for (int j = 0; j < mCountY; j++) { |
Sebastian Franco | 0dd5db8 | 2023-10-13 11:09:21 -0700 | [diff] [blame] | 613 | cellToRect(i, j, 1, 1, mTempOnDrawCellToRect); |
| 614 | mVisualizeGridRect.set(mTempOnDrawCellToRect); |
| 615 | mVisualizeGridRect.inset(paddingX, paddingY); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 616 | mVisualizeGridPaint.setStyle(Paint.Style.FILL); |
| 617 | canvas.drawRoundRect(mVisualizeGridRect, mGridVisualizationRoundingRadius, |
| 618 | mGridVisualizationRoundingRadius, mVisualizeGridPaint); |
| 619 | } |
| 620 | } |
| 621 | } |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 622 | |
fbaron | e74256b | 2023-04-10 14:50:31 -0700 | [diff] [blame] | 623 | if (mVisualizeDropLocation) { |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 624 | for (int i = 0; i < mDragOutlines.length; i++) { |
| 625 | final float alpha = mDragOutlineAlphas[i]; |
| 626 | if (alpha <= 0) continue; |
Sebastian Franco | 0dd5db8 | 2023-10-13 11:09:21 -0700 | [diff] [blame] | 627 | CellLayoutLayoutParams params = mDragOutlines[i]; |
| 628 | cellToRect(params.getCellX(), params.getCellY(), params.cellHSpan, params.cellVSpan, |
| 629 | mTempOnDrawCellToRect); |
| 630 | mVisualizeGridRect.set(mTempOnDrawCellToRect); |
| 631 | mVisualizeGridRect.inset(paddingX, paddingY); |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 632 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 633 | mVisualizeGridPaint.setAlpha(255); |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 634 | mVisualizeGridPaint.setStyle(Paint.Style.STROKE); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 635 | mVisualizeGridPaint.setColor(Color.argb((int) (alpha), |
| 636 | Color.red(mGridColor), Color.green(mGridColor), Color.blue(mGridColor))); |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 637 | |
Sebastian Franco | 9ea36d4 | 2023-09-21 13:56:42 -0700 | [diff] [blame] | 638 | canvas.save(); |
| 639 | canvas.translate(getMarginForGivenCellParams(params), 0); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 640 | canvas.drawRoundRect(mVisualizeGridRect, mGridVisualizationRoundingRadius, |
| 641 | mGridVisualizationRoundingRadius, mVisualizeGridPaint); |
Sebastian Franco | 9ea36d4 | 2023-09-21 13:56:42 -0700 | [diff] [blame] | 642 | canvas.restore(); |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 643 | } |
| 644 | } |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Sebastian Franco | 9ea36d4 | 2023-09-21 13:56:42 -0700 | [diff] [blame] | 647 | protected float getMarginForGivenCellParams(CellLayoutLayoutParams params) { |
| 648 | return 0; |
| 649 | } |
| 650 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 651 | @Override |
| 652 | protected void dispatchDraw(Canvas canvas) { |
| 653 | super.dispatchDraw(canvas); |
| 654 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 655 | for (int i = 0; i < mDelegatedCellDrawings.size(); i++) { |
| 656 | DelegatedCellDrawing bg = mDelegatedCellDrawings.get(i); |
| 657 | cellToPoint(bg.mDelegateCellX, bg.mDelegateCellY, mTempLocation); |
| 658 | canvas.save(); |
| 659 | canvas.translate(mTempLocation[0], mTempLocation[1]); |
| 660 | bg.drawOverItem(canvas); |
| 661 | canvas.restore(); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 662 | } |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 665 | /** |
| 666 | * Add Delegated cell drawing |
| 667 | */ |
| 668 | public void addDelegatedCellDrawing(DelegatedCellDrawing bg) { |
| 669 | mDelegatedCellDrawings.add(bg); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 670 | } |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 671 | |
| 672 | /** |
| 673 | * Remove item from DelegatedCellDrawings |
| 674 | */ |
| 675 | public void removeDelegatedCellDrawing(DelegatedCellDrawing bg) { |
| 676 | mDelegatedCellDrawings.remove(bg); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 679 | public void setFolderLeaveBehindCell(int x, int y) { |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 680 | View child = getChildAt(x, y); |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 681 | mFolderLeaveBehind.setup(getContext(), mActivity, null, |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 682 | child.getMeasuredWidth(), child.getPaddingTop()); |
| 683 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 684 | mFolderLeaveBehind.mDelegateCellX = x; |
| 685 | mFolderLeaveBehind.mDelegateCellY = y; |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 686 | invalidate(); |
| 687 | } |
| 688 | |
| 689 | public void clearFolderLeaveBehind() { |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 690 | mFolderLeaveBehind.mDelegateCellX = -1; |
| 691 | mFolderLeaveBehind.mDelegateCellY = -1; |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 692 | invalidate(); |
| 693 | } |
| 694 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 695 | @Override |
Michael Jurka | e6235dd | 2011-10-04 15:02:05 -0700 | [diff] [blame] | 696 | public boolean shouldDelayChildPressedState() { |
| 697 | return false; |
| 698 | } |
| 699 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 700 | public void restoreInstanceState(SparseArray<Parcelable> states) { |
Sunny Goyal | 33a152f | 2014-07-22 12:13:14 -0700 | [diff] [blame] | 701 | try { |
| 702 | dispatchRestoreInstanceState(states); |
| 703 | } catch (IllegalArgumentException ex) { |
Zak Cohen | 3eeb41d | 2020-02-14 14:15:13 -0800 | [diff] [blame] | 704 | if (FeatureFlags.IS_STUDIO_BUILD) { |
Sunny Goyal | 33a152f | 2014-07-22 12:13:14 -0700 | [diff] [blame] | 705 | throw ex; |
| 706 | } |
| 707 | // Mismatched viewId / viewType preventing restore. Skip restore on production builds. |
| 708 | Log.e(TAG, "Ignoring an error while restoring a view instance state", ex); |
| 709 | } |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Michael Jurka | e6235dd | 2011-10-04 15:02:05 -0700 | [diff] [blame] | 712 | @Override |
Jeff Sharkey | 83f111d | 2009-04-20 21:03:13 -0700 | [diff] [blame] | 713 | public void cancelLongPress() { |
| 714 | super.cancelLongPress(); |
| 715 | |
| 716 | // Cancel long press for all children |
| 717 | final int count = getChildCount(); |
| 718 | for (int i = 0; i < count; i++) { |
| 719 | final View child = getChildAt(i); |
| 720 | child.cancelLongPress(); |
| 721 | } |
| 722 | } |
| 723 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 724 | public void setOnInterceptTouchListener(View.OnTouchListener listener) { |
| 725 | mInterceptTouchListener = listener; |
| 726 | } |
| 727 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 728 | public int getCountX() { |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 729 | return mCountX; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 732 | public int getCountY() { |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 733 | return mCountY; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 736 | public boolean acceptsWidget() { |
| 737 | return mContainerType == WORKSPACE; |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 740 | /** |
| 741 | * Adds the given view to the CellLayout |
| 742 | * |
| 743 | * @param child view to add. |
| 744 | * @param index index of the CellLayout children where to add the view. |
| 745 | * @param childId id of the view. |
| 746 | * @param params represent the logic of the view on the CellLayout. |
| 747 | * @param markCells if the occupied cells should be marked or not |
| 748 | * @return if adding the view was successful |
| 749 | */ |
| 750 | public boolean addViewToCellLayout(View child, int index, int childId, |
| 751 | CellLayoutLayoutParams params, boolean markCells) { |
| 752 | final CellLayoutLayoutParams lp = params; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 753 | |
Andrew Flynn | de38e42 | 2012-05-08 11:22:15 -0700 | [diff] [blame] | 754 | // Hotseat icons - remove text |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 755 | if (child instanceof BubbleTextView) { |
| 756 | BubbleTextView bubbleChild = (BubbleTextView) child; |
Jon Miranda | f1eae80 | 2017-10-04 11:23:33 -0700 | [diff] [blame] | 757 | bubbleChild.setTextVisibility(mContainerType != HOTSEAT); |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Sebastian Franco | f765425 | 2024-01-18 11:50:50 -0800 | [diff] [blame^] | 760 | child.setScaleX(DEFAULT_SCALE); |
| 761 | child.setScaleY(DEFAULT_SCALE); |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 762 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 763 | // Generate an id for each view, this assumes we have at most 256x256 cells |
| 764 | // per workspace screen |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 765 | if (lp.getCellX() >= 0 && lp.getCellX() <= mCountX - 1 |
| 766 | && lp.getCellY() >= 0 && lp.getCellY() <= mCountY - 1) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 767 | // If the horizontal or vertical span is set to -1, it is taken to |
| 768 | // mean that it spans the extent of the CellLayout |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 769 | if (lp.cellHSpan < 0) lp.cellHSpan = mCountX; |
| 770 | if (lp.cellVSpan < 0) lp.cellVSpan = mCountY; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 771 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 772 | child.setId(childId); |
Tony Wickham | a0628cc | 2015-10-14 15:23:04 -0700 | [diff] [blame] | 773 | if (LOGD) { |
| 774 | Log.d(TAG, "Adding view to ShortcutsAndWidgetsContainer: " + child); |
| 775 | } |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 776 | mShortcutsAndWidgets.addView(child, index, lp); |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 777 | |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 778 | if (markCells) markCellsAsOccupiedForView(child); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 779 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 780 | return true; |
| 781 | } |
| 782 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 783 | } |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 784 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 785 | @Override |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 786 | public void removeAllViews() { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 787 | mOccupied.clear(); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 788 | mShortcutsAndWidgets.removeAllViews(); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public void removeAllViewsInLayout() { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 793 | if (mShortcutsAndWidgets.getChildCount() > 0) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 794 | mOccupied.clear(); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 795 | mShortcutsAndWidgets.removeAllViewsInLayout(); |
Michael Jurka | 7cfc282 | 2011-08-02 20:19:24 -0700 | [diff] [blame] | 796 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | @Override |
| 800 | public void removeView(View view) { |
| 801 | markCellsAsUnoccupiedForView(view); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 802 | mShortcutsAndWidgets.removeView(view); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | @Override |
| 806 | public void removeViewAt(int index) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 807 | markCellsAsUnoccupiedForView(mShortcutsAndWidgets.getChildAt(index)); |
| 808 | mShortcutsAndWidgets.removeViewAt(index); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | @Override |
| 812 | public void removeViewInLayout(View view) { |
| 813 | markCellsAsUnoccupiedForView(view); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 814 | mShortcutsAndWidgets.removeViewInLayout(view); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | @Override |
| 818 | public void removeViews(int start, int count) { |
| 819 | for (int i = start; i < start + count; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 820 | markCellsAsUnoccupiedForView(mShortcutsAndWidgets.getChildAt(i)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 821 | } |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 822 | mShortcutsAndWidgets.removeViews(start, count); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | @Override |
| 826 | public void removeViewsInLayout(int start, int count) { |
| 827 | for (int i = start; i < start + count; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 828 | markCellsAsUnoccupiedForView(mShortcutsAndWidgets.getChildAt(i)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 829 | } |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 830 | mShortcutsAndWidgets.removeViewsInLayout(start, count); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 833 | /** |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 834 | * Given a point, return the cell that strictly encloses that point |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 835 | * @param x X coordinate of the point |
| 836 | * @param y Y coordinate of the point |
| 837 | * @param result Array of 2 ints to hold the x and y coordinate of the cell |
| 838 | */ |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 839 | public void pointToCellExact(int x, int y, int[] result) { |
Winson Chung | 4b825dcd | 2011-06-19 12:41:22 -0700 | [diff] [blame] | 840 | final int hStartPadding = getPaddingLeft(); |
| 841 | final int vStartPadding = getPaddingTop(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 842 | |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 843 | result[0] = (x - hStartPadding) / (mCellWidth + mBorderSpace.x); |
| 844 | result[1] = (y - vStartPadding) / (mCellHeight + mBorderSpace.y); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 845 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 846 | final int xAxis = mCountX; |
| 847 | final int yAxis = mCountY; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 848 | |
| 849 | if (result[0] < 0) result[0] = 0; |
| 850 | if (result[0] >= xAxis) result[0] = xAxis - 1; |
| 851 | if (result[1] < 0) result[1] = 0; |
| 852 | if (result[1] >= yAxis) result[1] = yAxis - 1; |
| 853 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 854 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 855 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 856 | * Given a cell coordinate, return the point that represents the upper left corner of that cell |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 857 | * |
| 858 | * @param cellX X coordinate of the cell |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 859 | * @param cellY Y coordinate of the cell |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 860 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 861 | * @param result Array of 2 ints to hold the x and y coordinate of the point |
| 862 | */ |
| 863 | void cellToPoint(int cellX, int cellY, int[] result) { |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 864 | cellToRect(cellX, cellY, 1, 1, mTempRect); |
| 865 | result[0] = mTempRect.left; |
| 866 | result[1] = mTempRect.top; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 869 | /** |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 870 | * Given a cell coordinate, return the point that represents the center of the cell |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 871 | * |
| 872 | * @param cellX X coordinate of the cell |
| 873 | * @param cellY Y coordinate of the cell |
| 874 | * |
| 875 | * @param result Array of 2 ints to hold the x and y coordinate of the point |
| 876 | */ |
| 877 | void cellToCenterPoint(int cellX, int cellY, int[] result) { |
Adam Cohen | 47a876d | 2012-03-19 13:21:41 -0700 | [diff] [blame] | 878 | regionToCenterPoint(cellX, cellY, 1, 1, result); |
| 879 | } |
| 880 | |
| 881 | /** |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 882 | * Given a cell coordinate and span return the point that represents the center of the region |
Adam Cohen | 47a876d | 2012-03-19 13:21:41 -0700 | [diff] [blame] | 883 | * |
| 884 | * @param cellX X coordinate of the cell |
| 885 | * @param cellY Y coordinate of the cell |
| 886 | * |
| 887 | * @param result Array of 2 ints to hold the x and y coordinate of the point |
| 888 | */ |
Sebastian Franco | 45b39b5 | 2023-01-10 10:47:46 -0600 | [diff] [blame] | 889 | public void regionToCenterPoint(int cellX, int cellY, int spanX, int spanY, int[] result) { |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 890 | cellToRect(cellX, cellY, spanX, spanY, mTempRect); |
| 891 | result[0] = mTempRect.centerX(); |
| 892 | result[1] = mTempRect.centerY(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Tony Wickham | 3cfa5ed | 2021-11-03 13:20:43 -0700 | [diff] [blame] | 895 | /** |
| 896 | * Returns the distance between the given coordinate and the visual center of the given cell. |
| 897 | */ |
| 898 | public float getDistanceFromWorkspaceCellVisualCenter(float x, float y, int[] cell) { |
| 899 | getWorkspaceCellVisualCenter(cell[0], cell[1], mTmpPoint); |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 900 | return (float) Math.hypot(x - mTmpPoint[0], y - mTmpPoint[1]); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Tony Wickham | 3cfa5ed | 2021-11-03 13:20:43 -0700 | [diff] [blame] | 903 | private void getWorkspaceCellVisualCenter(int cellX, int cellY, int[] outPoint) { |
| 904 | View child = getChildAt(cellX, cellY); |
| 905 | if (child instanceof DraggableView) { |
| 906 | DraggableView draggableChild = (DraggableView) child; |
| 907 | if (draggableChild.getViewType() == DRAGGABLE_ICON) { |
| 908 | cellToPoint(cellX, cellY, outPoint); |
| 909 | draggableChild.getWorkspaceVisualDragBounds(mTempRect); |
| 910 | mTempRect.offset(outPoint[0], outPoint[1]); |
| 911 | outPoint[0] = mTempRect.centerX(); |
| 912 | outPoint[1] = mTempRect.centerY(); |
| 913 | return; |
| 914 | } |
| 915 | } |
| 916 | cellToCenterPoint(cellX, cellY, outPoint); |
| 917 | } |
| 918 | |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 919 | /** |
| 920 | * Returns the max distance from the center of a cell that can accept a drop to create a folder. |
| 921 | */ |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 922 | public float getFolderCreationRadius(int[] targetCell) { |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 923 | DeviceProfile grid = mActivity.getDeviceProfile(); |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 924 | float iconVisibleRadius = ICON_VISIBLE_AREA_FACTOR * grid.iconSizePx / 2; |
| 925 | // Halfway between reorder radius and icon. |
Sebastian Franco | 6e1024e | 2022-07-29 13:46:49 -0700 | [diff] [blame] | 926 | return (getReorderRadius(targetCell, 1, 1) + iconVisibleRadius) / 2; |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Returns the max distance from the center of a cell that will start to reorder on drag over. |
| 931 | */ |
Sebastian Franco | 6e1024e | 2022-07-29 13:46:49 -0700 | [diff] [blame] | 932 | public float getReorderRadius(int[] targetCell, int spanX, int spanY) { |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 933 | int[] centerPoint = mTmpPoint; |
| 934 | getWorkspaceCellVisualCenter(targetCell[0], targetCell[1], centerPoint); |
| 935 | |
| 936 | Rect cellBoundsWithSpacing = mTempRect; |
Sebastian Franco | 6e1024e | 2022-07-29 13:46:49 -0700 | [diff] [blame] | 937 | cellToRect(targetCell[0], targetCell[1], spanX, spanY, cellBoundsWithSpacing); |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 938 | cellBoundsWithSpacing.inset(-mBorderSpace.x / 2, -mBorderSpace.y / 2); |
| 939 | |
Sebastian Franco | c8392ea | 2022-10-28 16:38:37 -0700 | [diff] [blame] | 940 | if (canCreateFolder(getChildAt(targetCell[0], targetCell[1])) && spanX == 1 && spanY == 1) { |
Tony Wickham | 1278490 | 2021-11-03 14:02:10 -0700 | [diff] [blame] | 941 | // Take only the circle in the smaller dimension, to ensure we don't start reordering |
| 942 | // too soon before accepting a folder drop. |
| 943 | int minRadius = centerPoint[0] - cellBoundsWithSpacing.left; |
| 944 | minRadius = Math.min(minRadius, centerPoint[1] - cellBoundsWithSpacing.top); |
| 945 | minRadius = Math.min(minRadius, cellBoundsWithSpacing.right - centerPoint[0]); |
| 946 | minRadius = Math.min(minRadius, cellBoundsWithSpacing.bottom - centerPoint[1]); |
| 947 | return minRadius; |
| 948 | } |
| 949 | // Take up the entire cell, including space between this cell and the adjacent ones. |
Sebastian Franco | c8392ea | 2022-10-28 16:38:37 -0700 | [diff] [blame] | 950 | // Multiply by span to scale radius |
| 951 | return (float) Math.hypot(spanX * cellBoundsWithSpacing.width() / 2f, |
| 952 | spanY * cellBoundsWithSpacing.height() / 2f); |
Tony Wickham | 0ac045f | 2021-11-03 13:17:02 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 955 | public int getCellWidth() { |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 956 | return mCellWidth; |
| 957 | } |
| 958 | |
Sunny Goyal | 0b754e5 | 2017-08-07 07:42:45 -0700 | [diff] [blame] | 959 | public int getCellHeight() { |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 960 | return mCellHeight; |
| 961 | } |
| 962 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 963 | public void setFixedSize(int width, int height) { |
| 964 | mFixedWidth = width; |
| 965 | mFixedHeight = height; |
| 966 | } |
| 967 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 968 | @Override |
| 969 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 970 | int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 971 | int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 972 | int widthSize = MeasureSpec.getSize(widthMeasureSpec); |
| 973 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 974 | int childWidthSize = widthSize - (getPaddingLeft() + getPaddingRight()); |
| 975 | int childHeightSize = heightSize - (getPaddingTop() + getPaddingBottom()); |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 976 | |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 977 | if (mFixedCellWidth < 0 || mFixedCellHeight < 0) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 978 | int cw = DeviceProfile.calculateCellWidth(childWidthSize, mBorderSpace.x, |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 979 | mCountX); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 980 | int ch = DeviceProfile.calculateCellHeight(childHeightSize, mBorderSpace.y, |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 981 | mCountY); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 982 | if (cw != mCellWidth || ch != mCellHeight) { |
| 983 | mCellWidth = cw; |
| 984 | mCellHeight = ch; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 985 | mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY, |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 986 | mBorderSpace); |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 987 | } |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 988 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 989 | |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 990 | int newWidth = childWidthSize; |
| 991 | int newHeight = childHeightSize; |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 992 | if (mFixedWidth > 0 && mFixedHeight > 0) { |
| 993 | newWidth = mFixedWidth; |
| 994 | newHeight = mFixedHeight; |
| 995 | } else if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 996 | throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions"); |
| 997 | } |
| 998 | |
Sunny Goyal | 4fe5a37 | 2015-05-14 19:55:10 -0700 | [diff] [blame] | 999 | mShortcutsAndWidgets.measure( |
| 1000 | MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY), |
| 1001 | MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY)); |
| 1002 | |
| 1003 | int maxWidth = mShortcutsAndWidgets.getMeasuredWidth(); |
| 1004 | int maxHeight = mShortcutsAndWidgets.getMeasuredHeight(); |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 1005 | if (mFixedWidth > 0 && mFixedHeight > 0) { |
| 1006 | setMeasuredDimension(maxWidth, maxHeight); |
| 1007 | } else { |
| 1008 | setMeasuredDimension(widthSize, heightSize); |
| 1009 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | @Override |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 1013 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
Tony Wickham | 26b0142 | 2015-11-10 14:44:32 -0800 | [diff] [blame] | 1014 | int left = getPaddingLeft(); |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 1015 | left += (int) Math.ceil(getUnusedHorizontalSpace() / 2f); |
Sunny Goyal | 7c786f7 | 2016-06-01 14:08:21 -0700 | [diff] [blame] | 1016 | int right = r - l - getPaddingRight(); |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 1017 | right -= (int) Math.ceil(getUnusedHorizontalSpace() / 2f); |
Sunny Goyal | 7c786f7 | 2016-06-01 14:08:21 -0700 | [diff] [blame] | 1018 | |
Winson Chung | 38848ca | 2013-10-08 12:03:44 -0700 | [diff] [blame] | 1019 | int top = getPaddingTop(); |
Sunny Goyal | 7c786f7 | 2016-06-01 14:08:21 -0700 | [diff] [blame] | 1020 | int bottom = b - t - getPaddingBottom(); |
Sunny Goyal | 4fe5a37 | 2015-05-14 19:55:10 -0700 | [diff] [blame] | 1021 | |
Sunny Goyal | 7c786f7 | 2016-06-01 14:08:21 -0700 | [diff] [blame] | 1022 | // Expand the background drawing bounds by the padding baked into the background drawable |
| 1023 | mBackground.getPadding(mTempRect); |
| 1024 | mBackground.setBounds( |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 1025 | left - mTempRect.left - getPaddingLeft(), |
| 1026 | top - mTempRect.top - getPaddingTop(), |
| 1027 | right + mTempRect.right + getPaddingRight(), |
| 1028 | bottom + mTempRect.bottom + getPaddingBottom()); |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 1029 | |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 1030 | mShortcutsAndWidgets.layout(left, top, right, bottom); |
Sunny Goyal | 7c786f7 | 2016-06-01 14:08:21 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Tony Wickham | a501d49 | 2015-11-03 18:05:01 -0800 | [diff] [blame] | 1033 | /** |
| 1034 | * Returns the amount of space left over after subtracting padding and cells. This space will be |
| 1035 | * very small, a few pixels at most, and is a result of rounding down when calculating the cell |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1036 | * width in {@link DeviceProfile#calculateCellWidth(int, int, int)}. |
Tony Wickham | a501d49 | 2015-11-03 18:05:01 -0800 | [diff] [blame] | 1037 | */ |
| 1038 | public int getUnusedHorizontalSpace() { |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1039 | return getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth) |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1040 | - ((mCountX - 1) * mBorderSpace.x); |
Tony Wickham | a501d49 | 2015-11-03 18:05:01 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 1043 | @Override |
| 1044 | protected boolean verifyDrawable(Drawable who) { |
Sunny Goyal | 7ce471b | 2017-08-02 03:37:39 -0700 | [diff] [blame] | 1045 | return super.verifyDrawable(who) || (who == mBackground); |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1048 | public ShortcutAndWidgetContainer getShortcutsAndWidgets() { |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 1049 | return mShortcutsAndWidgets; |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1052 | public View getChildAt(int cellX, int cellY) { |
| 1053 | return mShortcutsAndWidgets.getChildAt(cellX, cellY); |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 1056 | public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1057 | int delay, boolean permanent, boolean adjustOccupied) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1058 | ShortcutAndWidgetContainer clc = getShortcutsAndWidgets(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1059 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1060 | if (clc.indexOfChild(child) != -1 && (child instanceof Reorderable)) { |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1061 | final CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1062 | final ItemInfo info = (ItemInfo) child.getTag(); |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1063 | final Reorderable item = (Reorderable) child; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1064 | |
| 1065 | // We cancel any existing animations |
| 1066 | if (mReorderAnimators.containsKey(lp)) { |
| 1067 | mReorderAnimators.get(lp).cancel(); |
| 1068 | mReorderAnimators.remove(lp); |
| 1069 | } |
| 1070 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1071 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1072 | if (adjustOccupied) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1073 | GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied; |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1074 | occupied.markCells(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan, false); |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1075 | occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, true); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1076 | } |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1077 | |
| 1078 | // Compute the new x and y position based on the new cellX and cellY |
| 1079 | // We leverage the actual layout logic in the layout params and hence need to modify |
| 1080 | // state and revert that state. |
| 1081 | final int oldX = lp.x; |
| 1082 | final int oldY = lp.y; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1083 | lp.isLockedToGrid = true; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1084 | if (permanent) { |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 1085 | lp.setCellX(cellX); |
| 1086 | lp.setCellY(cellY); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1087 | } else { |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1088 | lp.setTmpCellX(cellX); |
| 1089 | lp.setTmpCellY(cellY); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1090 | } |
Jon Miranda | e96798e | 2016-12-07 12:10:44 -0800 | [diff] [blame] | 1091 | clc.setupLp(child); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1092 | final int newX = lp.x; |
| 1093 | final int newY = lp.y; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 1094 | lp.x = oldX; |
| 1095 | lp.y = oldY; |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1096 | lp.isLockedToGrid = false; |
| 1097 | // End compute new x and y |
| 1098 | |
Sunny Goyal | 82dfc15 | 2023-02-24 16:50:09 -0800 | [diff] [blame] | 1099 | MultiTranslateDelegate mtd = item.getTranslateDelegate(); |
| 1100 | float initPreviewOffsetX = mtd.getTranslationX(INDEX_REORDER_PREVIEW_OFFSET).getValue(); |
| 1101 | float initPreviewOffsetY = mtd.getTranslationY(INDEX_REORDER_PREVIEW_OFFSET).getValue(); |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1102 | final float finalPreviewOffsetX = newX - oldX; |
| 1103 | final float finalPreviewOffsetY = newY - oldY; |
| 1104 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1105 | // Exit early if we're not actually moving the view |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1106 | if (finalPreviewOffsetX == 0 && finalPreviewOffsetY == 0 |
| 1107 | && initPreviewOffsetX == 0 && initPreviewOffsetY == 0) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1108 | lp.isLockedToGrid = true; |
| 1109 | return true; |
| 1110 | } |
| 1111 | |
Sunny Goyal | 849c6a2 | 2018-08-08 16:33:46 -0700 | [diff] [blame] | 1112 | ValueAnimator va = ValueAnimator.ofFloat(0f, 1f); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1113 | va.setDuration(duration); |
| 1114 | mReorderAnimators.put(lp, va); |
| 1115 | |
| 1116 | va.addUpdateListener(new AnimatorUpdateListener() { |
| 1117 | @Override |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1118 | public void onAnimationUpdate(ValueAnimator animation) { |
Jon Miranda | e96798e | 2016-12-07 12:10:44 -0800 | [diff] [blame] | 1119 | float r = (Float) animation.getAnimatedValue(); |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame] | 1120 | float x = (1 - r) * initPreviewOffsetX + r * finalPreviewOffsetX; |
| 1121 | float y = (1 - r) * initPreviewOffsetY + r * finalPreviewOffsetY; |
Sunny Goyal | 82dfc15 | 2023-02-24 16:50:09 -0800 | [diff] [blame] | 1122 | item.getTranslateDelegate().setTranslation(INDEX_REORDER_PREVIEW_OFFSET, x, y); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1123 | } |
| 1124 | }); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1125 | va.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1126 | boolean cancelled = false; |
| 1127 | public void onAnimationEnd(Animator animation) { |
| 1128 | // If the animation was cancelled, it means that another animation |
| 1129 | // has interrupted this one, and we don't want to lock the item into |
| 1130 | // place just yet. |
| 1131 | if (!cancelled) { |
| 1132 | lp.isLockedToGrid = true; |
Sunny Goyal | 82dfc15 | 2023-02-24 16:50:09 -0800 | [diff] [blame] | 1133 | item.getTranslateDelegate() |
| 1134 | .setTranslation(INDEX_REORDER_PREVIEW_OFFSET, 0, 0); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1135 | child.requestLayout(); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1136 | } |
| 1137 | if (mReorderAnimators.containsKey(lp)) { |
| 1138 | mReorderAnimators.remove(lp); |
| 1139 | } |
| 1140 | } |
| 1141 | public void onAnimationCancel(Animator animation) { |
| 1142 | cancelled = true; |
| 1143 | } |
| 1144 | }); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1145 | va.setStartDelay(delay); |
| 1146 | va.start(); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1147 | return true; |
| 1148 | } |
| 1149 | return false; |
| 1150 | } |
| 1151 | |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 1152 | void visualizeDropLocation(int cellX, int cellY, int spanX, int spanY, |
| 1153 | DropTarget.DragObject dragObject) { |
| 1154 | if (mDragCell[0] != cellX || mDragCell[1] != cellY || mDragCellSpan[0] != spanX |
| 1155 | || mDragCellSpan[1] != spanY) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1156 | mDragCell[0] = cellX; |
| 1157 | mDragCell[1] = cellY; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 1158 | mDragCellSpan[0] = spanX; |
| 1159 | mDragCellSpan[1] = spanY; |
Steven Ng | 30dd1d6 | 2021-03-15 21:45:49 +0000 | [diff] [blame] | 1160 | |
Steven Ng | a999e22 | 2021-04-19 18:17:15 +0100 | [diff] [blame] | 1161 | // Apply color extraction on a widget when dragging. |
| 1162 | applyColorExtractionOnWidget(dragObject, mDragCell, spanX, spanY); |
| 1163 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1164 | final int oldIndex = mDragOutlineCurrent; |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 1165 | mDragOutlineAnims[oldIndex].animateOut(); |
| 1166 | mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length; |
Sunny Goyal | 106bf64 | 2015-07-16 12:18:06 -0700 | [diff] [blame] | 1167 | |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1168 | CellLayoutLayoutParams cell = mDragOutlines[mDragOutlineCurrent]; |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1169 | cell.setCellX(cellX); |
| 1170 | cell.setCellY(cellY); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 1171 | cell.cellHSpan = spanX; |
| 1172 | cell.cellVSpan = spanY; |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 1173 | |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 1174 | mDragOutlineAnims[mDragOutlineCurrent].animateIn(); |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 1175 | invalidate(); |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 1176 | |
| 1177 | if (dragObject.stateAnnouncer != null) { |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1178 | dragObject.stateAnnouncer.announce(getItemMoveDescription(cellX, cellY)); |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 1179 | } |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 1180 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
Steven Ng | 30dd1d6 | 2021-03-15 21:45:49 +0000 | [diff] [blame] | 1184 | /** Applies the local color extraction to a dragging widget object. */ |
Steven Ng | a999e22 | 2021-04-19 18:17:15 +0100 | [diff] [blame] | 1185 | private void applyColorExtractionOnWidget(DropTarget.DragObject dragObject, int[] targetCell, |
| 1186 | int spanX, int spanY) { |
Steven Ng | 30dd1d6 | 2021-03-15 21:45:49 +0000 | [diff] [blame] | 1187 | // Apply local extracted color if the DragView is an AppWidgetHostViewDrawable. |
Steven Ng | 3242720 | 2021-04-19 18:12:12 +0100 | [diff] [blame] | 1188 | View view = dragObject.dragView.getContentView(); |
| 1189 | if (view instanceof LauncherAppWidgetHostView) { |
Andras Kloczl | 2dacbee | 2022-02-21 16:53:28 +0000 | [diff] [blame] | 1190 | int screenId = getWorkspace().getIdForScreen(this); |
Steven Ng | 30dd1d6 | 2021-03-15 21:45:49 +0000 | [diff] [blame] | 1191 | cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect); |
Jonathan Miranda | 21930da | 2021-05-03 18:44:13 +0000 | [diff] [blame] | 1192 | |
Sunny Goyal | 69a8eec | 2021-07-22 10:02:50 -0700 | [diff] [blame] | 1193 | ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, this, screenId); |
Steven Ng | 30dd1d6 | 2021-03-15 21:45:49 +0000 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 1197 | @SuppressLint("StringFormatMatches") |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1198 | public String getItemMoveDescription(int cellX, int cellY) { |
| 1199 | if (mContainerType == HOTSEAT) { |
| 1200 | return getContext().getString(R.string.move_to_hotseat_position, |
| 1201 | Math.max(cellX, cellY) + 1); |
| 1202 | } else { |
Shikha Malhotra | f78da1b | 2022-04-11 10:23:18 +0000 | [diff] [blame] | 1203 | Workspace<?> workspace = getWorkspace(); |
Andras Kloczl | 2dacbee | 2022-02-21 16:53:28 +0000 | [diff] [blame] | 1204 | int row = cellY + 1; |
| 1205 | int col = workspace.mIsRtl ? mCountX - cellX : cellX + 1; |
| 1206 | int panelCount = workspace.getPanelCount(); |
Sebastian Franco | 930531f | 2022-06-16 16:49:11 -0700 | [diff] [blame] | 1207 | int screenId = workspace.getIdForScreen(this); |
| 1208 | int pageIndex = workspace.getPageIndexForScreenId(screenId); |
Andras Kloczl | 2dacbee | 2022-02-21 16:53:28 +0000 | [diff] [blame] | 1209 | if (panelCount > 1) { |
| 1210 | // Increment the column if the target is on the right side of a two panel home |
Andras Kloczl | 2dacbee | 2022-02-21 16:53:28 +0000 | [diff] [blame] | 1211 | col += (pageIndex % panelCount) * mCountX; |
| 1212 | } |
Sebastian Franco | 930531f | 2022-06-16 16:49:11 -0700 | [diff] [blame] | 1213 | return getContext().getString(R.string.move_to_empty_cell_description, row, col, |
| 1214 | workspace.getPageDescription(pageIndex)); |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Shikha Malhotra | f78da1b | 2022-04-11 10:23:18 +0000 | [diff] [blame] | 1218 | private Workspace<?> getWorkspace() { |
Andras Kloczl | 2dacbee | 2022-02-21 16:53:28 +0000 | [diff] [blame] | 1219 | return Launcher.cast(mActivity).getWorkspace(); |
| 1220 | } |
| 1221 | |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 1222 | public void clearDragOutlines() { |
| 1223 | final int oldIndex = mDragOutlineCurrent; |
| 1224 | mDragOutlineAnims[oldIndex].animateOut(); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1225 | mDragCell[0] = mDragCell[1] = -1; |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1228 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 1229 | * Find a vacant area that will fit the given bounds nearest the requested |
| 1230 | * cell location. Uses Euclidean distance to score multiple vacant areas. |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1231 | * |
Romain Guy | 51afc02 | 2009-05-04 18:03:43 -0700 | [diff] [blame] | 1232 | * @param pixelX The X location at which you want to search for a vacant area. |
| 1233 | * @param pixelY The Y location at which you want to search for a vacant area. |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1234 | * @param minSpanX The minimum horizontal span required |
| 1235 | * @param minSpanY The minimum vertical span required |
| 1236 | * @param spanX Horizontal span of the object. |
| 1237 | * @param spanY Vertical span of the object. |
| 1238 | * @param result Array in which to place the result, or null (in which case a new array will |
| 1239 | * be allocated) |
| 1240 | * @return The X, Y cell of a vacant area that can contain this object, |
| 1241 | * nearest the requested location. |
| 1242 | */ |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 1243 | public int[] findNearestVacantArea(int pixelX, int pixelY, int minSpanX, int minSpanY, |
| 1244 | int spanX, int spanY, int[] result, int[] resultSpan) { |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1245 | return findNearestArea(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, false, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1246 | result, resultSpan); |
| 1247 | } |
| 1248 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1249 | /** |
| 1250 | * Find a vacant area that will fit the given bounds nearest the requested |
| 1251 | * cell location. Uses Euclidean distance to score multiple vacant areas. |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1252 | * @param relativeXPos The X location relative to the Cell layout at which you want to search |
| 1253 | * for a vacant area. |
| 1254 | * @param relativeYPos The Y location relative to the Cell layout at which you want to search |
| 1255 | * for a vacant area. |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1256 | * @param minSpanX The minimum horizontal span required |
| 1257 | * @param minSpanY The minimum vertical span required |
| 1258 | * @param spanX Horizontal span of the object. |
| 1259 | * @param spanY Vertical span of the object. |
| 1260 | * @param ignoreOccupied If true, the result can be an occupied cell |
| 1261 | * @param result Array in which to place the result, or null (in which case a new array will |
| 1262 | * be allocated) |
| 1263 | * @return The X, Y cell of a vacant area that can contain this object, |
| 1264 | * nearest the requested location. |
| 1265 | */ |
Sebastian Franco | 96c46e7 | 2023-05-08 10:04:44 -0600 | [diff] [blame] | 1266 | protected int[] findNearestArea(int relativeXPos, int relativeYPos, int minSpanX, int minSpanY, |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1267 | int spanX, int spanY, boolean ignoreOccupied, int[] result, int[] resultSpan) { |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1268 | // For items with a spanX / spanY > 1, the passed in point (relativeXPos, relativeYPos) |
| 1269 | // corresponds to the center of the item, but we are searching based on the top-left cell, |
| 1270 | // so we translate the point over to correspond to the top-left. |
| 1271 | relativeXPos = (int) (relativeXPos - (mCellWidth + mBorderSpace.x) * (spanX - 1) / 2f); |
| 1272 | relativeYPos = (int) (relativeYPos - (mCellHeight + mBorderSpace.y) * (spanY - 1) / 2f); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1273 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 1274 | // Keep track of best-scoring drop area |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 1275 | final int[] bestXY = result != null ? result : new int[2]; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 1276 | double bestDistance = Double.MAX_VALUE; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1277 | final Rect bestRect = new Rect(-1, -1, -1, -1); |
Rajeev Kumar | 9962dbe | 2017-06-12 12:16:20 -0700 | [diff] [blame] | 1278 | final Stack<Rect> validRegions = new Stack<>(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1279 | |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 1280 | final int countX = mCountX; |
| 1281 | final int countY = mCountY; |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 1282 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1283 | if (minSpanX <= 0 || minSpanY <= 0 || spanX <= 0 || spanY <= 0 || |
| 1284 | spanX < minSpanX || spanY < minSpanY) { |
| 1285 | return bestXY; |
| 1286 | } |
| 1287 | |
| 1288 | for (int y = 0; y < countY - (minSpanY - 1); y++) { |
Michael Jurka | c28de51 | 2010-08-13 11:27:44 -0700 | [diff] [blame] | 1289 | inner: |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1290 | for (int x = 0; x < countX - (minSpanX - 1); x++) { |
| 1291 | int ySize = -1; |
| 1292 | int xSize = -1; |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1293 | if (!ignoreOccupied) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1294 | // First, let's see if this thing fits anywhere |
| 1295 | for (int i = 0; i < minSpanX; i++) { |
| 1296 | for (int j = 0; j < minSpanY; j++) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1297 | if (mOccupied.cells[x + i][y + j]) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1298 | continue inner; |
| 1299 | } |
Michael Jurka | c28de51 | 2010-08-13 11:27:44 -0700 | [diff] [blame] | 1300 | } |
| 1301 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1302 | xSize = minSpanX; |
| 1303 | ySize = minSpanY; |
| 1304 | |
| 1305 | // We know that the item will fit at _some_ acceptable size, now let's see |
| 1306 | // how big we can make it. We'll alternate between incrementing x and y spans |
| 1307 | // until we hit a limit. |
| 1308 | boolean incX = true; |
| 1309 | boolean hitMaxX = xSize >= spanX; |
| 1310 | boolean hitMaxY = ySize >= spanY; |
| 1311 | while (!(hitMaxX && hitMaxY)) { |
| 1312 | if (incX && !hitMaxX) { |
| 1313 | for (int j = 0; j < ySize; j++) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1314 | if (x + xSize > countX -1 || mOccupied.cells[x + xSize][y + j]) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1315 | // We can't move out horizontally |
| 1316 | hitMaxX = true; |
| 1317 | } |
| 1318 | } |
| 1319 | if (!hitMaxX) { |
| 1320 | xSize++; |
| 1321 | } |
| 1322 | } else if (!hitMaxY) { |
| 1323 | for (int i = 0; i < xSize; i++) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1324 | if (y + ySize > countY - 1 || mOccupied.cells[x + i][y + ySize]) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1325 | // We can't move out vertically |
| 1326 | hitMaxY = true; |
| 1327 | } |
| 1328 | } |
| 1329 | if (!hitMaxY) { |
| 1330 | ySize++; |
| 1331 | } |
| 1332 | } |
| 1333 | hitMaxX |= xSize >= spanX; |
| 1334 | hitMaxY |= ySize >= spanY; |
| 1335 | incX = !incX; |
| 1336 | } |
Michael Jurka | c28de51 | 2010-08-13 11:27:44 -0700 | [diff] [blame] | 1337 | } |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 1338 | final int[] cellXY = mTmpPoint; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1339 | cellToCenterPoint(x, y, cellXY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1340 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1341 | // We verify that the current rect is not a sub-rect of any of our previous |
| 1342 | // candidates. In this case, the current rect is disqualified in favour of the |
| 1343 | // containing rect. |
Sebastian Franco | 4a92267 | 2022-10-27 16:42:24 -0700 | [diff] [blame] | 1344 | Rect currentRect = new Rect(x, y, x + xSize, y + ySize); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1345 | boolean contained = false; |
| 1346 | for (Rect r : validRegions) { |
| 1347 | if (r.contains(currentRect)) { |
| 1348 | contained = true; |
| 1349 | break; |
| 1350 | } |
| 1351 | } |
| 1352 | validRegions.push(currentRect); |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1353 | double distance = Math.hypot(cellXY[0] - relativeXPos, cellXY[1] - relativeYPos); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1354 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1355 | if ((distance <= bestDistance && !contained) || |
| 1356 | currentRect.contains(bestRect)) { |
Michael Jurka | c28de51 | 2010-08-13 11:27:44 -0700 | [diff] [blame] | 1357 | bestDistance = distance; |
| 1358 | bestXY[0] = x; |
| 1359 | bestXY[1] = y; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1360 | if (resultSpan != null) { |
| 1361 | resultSpan[0] = xSize; |
| 1362 | resultSpan[1] = ySize; |
| 1363 | } |
| 1364 | bestRect.set(currentRect); |
Michael Jurka | c28de51 | 2010-08-13 11:27:44 -0700 | [diff] [blame] | 1365 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 1369 | // Return -1, -1 if no suitable location found |
| 1370 | if (bestDistance == Double.MAX_VALUE) { |
| 1371 | bestXY[0] = -1; |
| 1372 | bestXY[1] = -1; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 1373 | } |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 1374 | return bestXY; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1375 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1376 | |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 1377 | public GridOccupancy getOccupied() { |
| 1378 | return mOccupied; |
| 1379 | } |
| 1380 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1381 | private void copySolutionToTempState(ItemConfiguration solution, View dragView) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1382 | mTmpOccupied.clear(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1383 | |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1384 | int childCount = mShortcutsAndWidgets.getChildCount(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1385 | for (int i = 0; i < childCount; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1386 | View child = mShortcutsAndWidgets.getChildAt(i); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1387 | if (child == dragView) continue; |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1388 | CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Adam Cohen | 8baab35 | 2012-03-20 17:39:21 -0700 | [diff] [blame] | 1389 | CellAndSpan c = solution.map.get(child); |
| 1390 | if (c != null) { |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1391 | lp.setTmpCellX(c.cellX); |
| 1392 | lp.setTmpCellY(c.cellY); |
Adam Cohen | 8baab35 | 2012-03-20 17:39:21 -0700 | [diff] [blame] | 1393 | lp.cellHSpan = c.spanX; |
| 1394 | lp.cellVSpan = c.spanY; |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1395 | mTmpOccupied.markCells(c, true); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1396 | } |
| 1397 | } |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1398 | mTmpOccupied.markCells(solution, true); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | private void animateItemsToSolution(ItemConfiguration solution, View dragView, boolean |
| 1402 | commitDragView) { |
| 1403 | |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1404 | GridOccupancy occupied = DESTRUCTIVE_REORDER ? mOccupied : mTmpOccupied; |
| 1405 | occupied.clear(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1406 | |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1407 | int childCount = mShortcutsAndWidgets.getChildCount(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1408 | for (int i = 0; i < childCount; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1409 | View child = mShortcutsAndWidgets.getChildAt(i); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1410 | if (child == dragView) continue; |
Adam Cohen | 8baab35 | 2012-03-20 17:39:21 -0700 | [diff] [blame] | 1411 | CellAndSpan c = solution.map.get(child); |
| 1412 | if (c != null) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1413 | animateChildToPosition(child, c.cellX, c.cellY, REORDER_ANIMATION_DURATION, 0, |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1414 | DESTRUCTIVE_REORDER, false); |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1415 | occupied.markCells(c, true); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | if (commitDragView) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1419 | occupied.markCells(solution, true); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1423 | |
| 1424 | // This method starts or changes the reorder preview animations |
| 1425 | private void beginOrAdjustReorderPreviewAnimations(ItemConfiguration solution, |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 1426 | View dragView, int mode) { |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1427 | int childCount = mShortcutsAndWidgets.getChildCount(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1428 | for (int i = 0; i < childCount; i++) { |
| 1429 | View child = mShortcutsAndWidgets.getChildAt(i); |
| 1430 | if (child == dragView) continue; |
| 1431 | CellAndSpan c = solution.map.get(child); |
Sebastian Franco | 5f0af4f | 2023-11-21 10:45:45 -0600 | [diff] [blame] | 1432 | boolean skip = mode == ReorderPreviewAnimation.MODE_HINT |
| 1433 | && !solution.intersectingViews.contains(child); |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 1434 | |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1435 | CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 1436 | if (c != null && !skip && (child instanceof Reorderable)) { |
Sebastian Franco | f765425 | 2024-01-18 11:50:50 -0800 | [diff] [blame^] | 1437 | ReorderPreviewAnimation rha = new ReorderPreviewAnimation(child, mode, |
| 1438 | lp.getCellX(), lp.getCellY(), c.cellX, c.cellY, c.spanX, c.spanY, |
| 1439 | mReorderPreviewAnimationMagnitude, this, mShakeAnimators); |
Adam Cohen | d024f98 | 2012-05-23 18:26:45 -0700 | [diff] [blame] | 1440 | rha.animate(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1441 | } |
| 1442 | } |
| 1443 | } |
| 1444 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1445 | private void completeAndClearReorderPreviewAnimations() { |
| 1446 | for (ReorderPreviewAnimation a: mShakeAnimators.values()) { |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 1447 | a.finishAnimation(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1448 | } |
| 1449 | mShakeAnimators.clear(); |
| 1450 | } |
| 1451 | |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 1452 | private void commitTempPlacement(View dragView) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1453 | mTmpOccupied.copyTo(mOccupied); |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 1454 | |
Andras Kloczl | 2dacbee | 2022-02-21 16:53:28 +0000 | [diff] [blame] | 1455 | int screenId = getWorkspace().getIdForScreen(this); |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 1456 | int container = Favorites.CONTAINER_DESKTOP; |
| 1457 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1458 | if (mContainerType == HOTSEAT) { |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 1459 | screenId = -1; |
| 1460 | container = Favorites.CONTAINER_HOTSEAT; |
| 1461 | } |
| 1462 | |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1463 | int childCount = mShortcutsAndWidgets.getChildCount(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1464 | for (int i = 0; i < childCount; i++) { |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 1465 | View child = mShortcutsAndWidgets.getChildAt(i); |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1466 | CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 1467 | ItemInfo info = (ItemInfo) child.getTag(); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 1468 | // We do a null check here because the item info can be null in the case of the |
| 1469 | // AllApps button in the hotseat. |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 1470 | if (info != null && child != dragView) { |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 1471 | CellPos presenterPos = mActivity.getCellPosMapper().mapModelToPresenter(info); |
| 1472 | final boolean requiresDbUpdate = (presenterPos.cellX != lp.getTmpCellX() |
| 1473 | || presenterPos.cellY != lp.getTmpCellY() || info.spanX != lp.cellHSpan |
| 1474 | || info.spanY != lp.cellVSpan || presenterPos.screenId != screenId); |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 1475 | |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1476 | lp.setCellX(lp.getTmpCellX()); |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1477 | lp.setCellY(lp.getTmpCellY()); |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 1478 | if (requiresDbUpdate) { |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 1479 | Launcher.cast(mActivity).getModelWriter().modifyItemInDatabase(info, container, |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 1480 | screenId, lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan); |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 1481 | } |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 1482 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 1486 | private void setUseTempCoords(boolean useTempCoords) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1487 | int childCount = mShortcutsAndWidgets.getChildCount(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1488 | for (int i = 0; i < childCount; i++) { |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1489 | CellLayoutLayoutParams lp = (CellLayoutLayoutParams) mShortcutsAndWidgets.getChildAt( |
| 1490 | i).getLayoutParams(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1491 | lp.useTmpCoords = useTempCoords; |
| 1492 | } |
| 1493 | } |
| 1494 | |
Sebastian Franco | 5c8f868 | 2023-11-14 09:52:41 -0600 | [diff] [blame] | 1495 | /** |
| 1496 | * For a given region, return the rectangle of the overlapping cell and span with the given |
| 1497 | * region including the region itself. If there is no overlap the rectangle will be |
| 1498 | * invalid i.e. -1, 0, -1, 0. |
| 1499 | */ |
| 1500 | @Nullable |
| 1501 | public Rect getIntersectingRectanglesInRegion(final Rect region, final View dragView) { |
| 1502 | Rect boundingRect = new Rect(region); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1503 | Rect r1 = new Rect(); |
Sebastian Franco | 5c8f868 | 2023-11-14 09:52:41 -0600 | [diff] [blame] | 1504 | boolean isOverlapping = false; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1505 | final int count = mShortcutsAndWidgets.getChildCount(); |
| 1506 | for (int i = 0; i < count; i++) { |
| 1507 | View child = mShortcutsAndWidgets.getChildAt(i); |
| 1508 | if (child == dragView) continue; |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1509 | CellLayoutLayoutParams |
| 1510 | lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1511 | r1.set(lp.getCellX(), lp.getCellY(), lp.getCellX() + lp.cellHSpan, |
| 1512 | lp.getCellY() + lp.cellVSpan); |
Sebastian Franco | 5c8f868 | 2023-11-14 09:52:41 -0600 | [diff] [blame] | 1513 | if (Rect.intersects(region, r1)) { |
| 1514 | isOverlapping = true; |
| 1515 | boundingRect.union(r1); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1516 | } |
| 1517 | } |
Sebastian Franco | 5c8f868 | 2023-11-14 09:52:41 -0600 | [diff] [blame] | 1518 | return isOverlapping ? boundingRect : null; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 1521 | public boolean isNearestDropLocationOccupied(int pixelX, int pixelY, int spanX, int spanY, |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1522 | View dragView, int[] result) { |
Sebastián Franco | f9a6ac2 | 2022-11-15 22:56:37 +0000 | [diff] [blame] | 1523 | result = findNearestAreaIgnoreOccupied(pixelX, pixelY, spanX, spanY, result); |
Sebastian Franco | 5c8f868 | 2023-11-14 09:52:41 -0600 | [diff] [blame] | 1524 | return getIntersectingRectanglesInRegion( |
| 1525 | new Rect(result[0], result[1], result[0] + spanX, result[1] + spanY), |
| 1526 | dragView |
| 1527 | ) != null; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | void revertTempState() { |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1531 | completeAndClearReorderPreviewAnimations(); |
| 1532 | if (isItemPlacementDirty() && !DESTRUCTIVE_REORDER) { |
| 1533 | final int count = mShortcutsAndWidgets.getChildCount(); |
| 1534 | for (int i = 0; i < count; i++) { |
| 1535 | View child = mShortcutsAndWidgets.getChildAt(i); |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1536 | CellLayoutLayoutParams |
| 1537 | lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1538 | if (lp.getTmpCellX() != lp.getCellX() || lp.getTmpCellY() != lp.getCellY()) { |
| 1539 | lp.setTmpCellX(lp.getCellX()); |
| 1540 | lp.setTmpCellY(lp.getCellY()); |
| 1541 | animateChildToPosition(child, lp.getCellX(), lp.getCellY(), |
| 1542 | REORDER_ANIMATION_DURATION, 0, false, false); |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1543 | } |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1544 | } |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1545 | setItemPlacementDirty(false); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1546 | } |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 1549 | boolean createAreaForResize(int cellX, int cellY, int spanX, int spanY, |
| 1550 | View dragView, int[] direction, boolean commit) { |
| 1551 | int[] pixelXY = new int[2]; |
| 1552 | regionToCenterPoint(cellX, cellY, spanX, spanY, pixelXY); |
| 1553 | |
| 1554 | // First we determine if things have moved enough to cause a different layout |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1555 | ItemConfiguration swapSolution = findReorderSolution(pixelXY[0], pixelXY[1], spanX, spanY, |
Charlie Anderson | 4612239 | 2024-01-18 17:23:46 -0500 | [diff] [blame] | 1556 | spanX, spanY, direction, dragView, true); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 1557 | |
| 1558 | setUseTempCoords(true); |
| 1559 | if (swapSolution != null && swapSolution.isSolution) { |
| 1560 | // If we're just testing for a possible location (MODE_ACCEPT_DROP), we don't bother |
| 1561 | // committing anything or animating anything as we just want to determine if a solution |
| 1562 | // exists |
| 1563 | copySolutionToTempState(swapSolution, dragView); |
| 1564 | setItemPlacementDirty(true); |
| 1565 | animateItemsToSolution(swapSolution, dragView, commit); |
| 1566 | |
| 1567 | if (commit) { |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 1568 | commitTempPlacement(null); |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1569 | completeAndClearReorderPreviewAnimations(); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 1570 | setItemPlacementDirty(false); |
| 1571 | } else { |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1572 | beginOrAdjustReorderPreviewAnimations(swapSolution, dragView, |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 1573 | ReorderPreviewAnimation.MODE_PREVIEW); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 1574 | } |
| 1575 | mShortcutsAndWidgets.requestLayout(); |
| 1576 | } |
| 1577 | return swapSolution.isSolution; |
| 1578 | } |
| 1579 | |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 1580 | public ReorderAlgorithm createReorderAlgorithm() { |
| 1581 | return new ReorderAlgorithm(this); |
| 1582 | } |
| 1583 | |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 1584 | protected ItemConfiguration findReorderSolution(int pixelX, int pixelY, int minSpanX, |
Charlie Anderson | 4612239 | 2024-01-18 17:23:46 -0500 | [diff] [blame] | 1585 | int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX) { |
Sebastian Franco | 25f8e40 | 2023-12-02 13:54:05 -0600 | [diff] [blame] | 1586 | ItemConfiguration configuration = new ItemConfiguration(); |
| 1587 | copyCurrentStateToSolution(configuration); |
| 1588 | ReorderParameters parameters = new ReorderParameters(pixelX, pixelY, spanX, spanY, minSpanX, |
| 1589 | minSpanY, dragView, configuration); |
Charlie Anderson | 4612239 | 2024-01-18 17:23:46 -0500 | [diff] [blame] | 1590 | int[] directionVector = direction != null ? direction : mDirectionVector; |
| 1591 | return createReorderAlgorithm().findReorderSolution(parameters, directionVector, decX); |
Sebastian Franco | 0958932 | 2022-11-02 15:25:58 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Sebastián Franco | 61fbd18 | 2023-11-29 21:30:43 +0000 | [diff] [blame] | 1594 | public void copyCurrentStateToSolution(ItemConfiguration solution) { |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1595 | int childCount = mShortcutsAndWidgets.getChildCount(); |
| 1596 | for (int i = 0; i < childCount; i++) { |
| 1597 | View child = mShortcutsAndWidgets.getChildAt(i); |
| 1598 | CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Sebastián Franco | 61fbd18 | 2023-11-29 21:30:43 +0000 | [diff] [blame] | 1599 | solution.add(child, |
| 1600 | new CellAndSpan(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan)); |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1601 | } |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | /** |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1605 | * When the user drags an Item in the workspace sometimes we need to move the items already in |
| 1606 | * the workspace to make space for the new item, this function return a solution for that |
| 1607 | * reorder. |
| 1608 | * |
| 1609 | * @param pixelX X coordinate in the screen of the dragView in pixels |
| 1610 | * @param pixelY Y coordinate in the screen of the dragView in pixels |
| 1611 | * @param minSpanX minimum horizontal span the item can be shrunk to |
| 1612 | * @param minSpanY minimum vertical span the item can be shrunk to |
| 1613 | * @param spanX occupied horizontal span |
| 1614 | * @param spanY occupied vertical span |
| 1615 | * @param dragView the view of the item being draged |
| 1616 | * @return returns a solution for the given parameters, the solution contains all the icons and |
| 1617 | * the locations they should be in the given solution. |
| 1618 | */ |
| 1619 | public ItemConfiguration calculateReorder(int pixelX, int pixelY, int minSpanX, int minSpanY, |
| 1620 | int spanX, int spanY, View dragView) { |
Sebastian Franco | 25f8e40 | 2023-12-02 13:54:05 -0600 | [diff] [blame] | 1621 | ItemConfiguration configuration = new ItemConfiguration(); |
| 1622 | copyCurrentStateToSolution(configuration); |
| 1623 | return createReorderAlgorithm().calculateReorder( |
| 1624 | new ReorderParameters(pixelX, pixelY, spanX, spanY, minSpanX, minSpanY, dragView, |
| 1625 | configuration) |
| 1626 | ); |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1627 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1628 | |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1629 | int[] performReorder(int pixelX, int pixelY, int minSpanX, int minSpanY, int spanX, int spanY, |
| 1630 | View dragView, int[] result, int[] resultSpan, int mode) { |
| 1631 | if (resultSpan == null) { |
| 1632 | resultSpan = new int[]{-1, -1}; |
| 1633 | } |
| 1634 | if (result == null) { |
| 1635 | result = new int[]{-1, -1}; |
| 1636 | } |
Sebastian Franco | 5d990ee | 2022-11-01 16:08:24 -0700 | [diff] [blame] | 1637 | |
| 1638 | ItemConfiguration finalSolution = null; |
| 1639 | // We want the solution to match the animation of the preview and to match the drop so we |
| 1640 | // only recalculate in mode MODE_SHOW_REORDER_HINT because that the first one to run in the |
| 1641 | // reorder cycle. |
| 1642 | if (mode == MODE_SHOW_REORDER_HINT || mPreviousSolution == null) { |
| 1643 | finalSolution = calculateReorder(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, |
| 1644 | dragView); |
| 1645 | mPreviousSolution = finalSolution; |
| 1646 | } else { |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1647 | finalSolution = mPreviousSolution; |
| 1648 | // We reset this vector after drop |
| 1649 | if (mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL) { |
| 1650 | mPreviousSolution = null; |
| 1651 | } |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | if (finalSolution == null || !finalSolution.isSolution) { |
| 1655 | result[0] = result[1] = resultSpan[0] = resultSpan[1] = -1; |
| 1656 | } else { |
| 1657 | result[0] = finalSolution.cellX; |
| 1658 | result[1] = finalSolution.cellY; |
| 1659 | resultSpan[0] = finalSolution.spanX; |
| 1660 | resultSpan[1] = finalSolution.spanY; |
Sebastian Franco | 9c74327 | 2022-11-15 15:03:25 -0800 | [diff] [blame] | 1661 | performReorder(finalSolution, dragView, mode); |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1662 | } |
Sebastian Franco | 9cab1c3 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1663 | return result; |
| 1664 | } |
| 1665 | |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1666 | /** |
| 1667 | * Animates and submits in the DB the given ItemConfiguration depending of the mode. |
| 1668 | * |
| 1669 | * @param solution represents widgets on the screen which the Workspace will animate to and |
| 1670 | * would be submitted to the database. |
| 1671 | * @param dragView view which is being dragged over the workspace that trigger the reorder |
| 1672 | * @param mode depending on the mode different animations would be played and depending on the |
| 1673 | * mode the solution would be submitted or not the database. |
| 1674 | * The possible modes are {@link MODE_SHOW_REORDER_HINT}, {@link MODE_DRAG_OVER}, |
| 1675 | * {@link MODE_ON_DROP}, {@link MODE_ON_DROP_EXTERNAL}, {@link MODE_ACCEPT_DROP} |
| 1676 | * defined in {@link CellLayout}. |
| 1677 | */ |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 1678 | public void performReorder(ItemConfiguration solution, View dragView, int mode) { |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1679 | if (mode == MODE_SHOW_REORDER_HINT) { |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1680 | beginOrAdjustReorderPreviewAnimations(solution, dragView, |
| 1681 | ReorderPreviewAnimation.MODE_HINT); |
| 1682 | return; |
| 1683 | } |
| 1684 | // If we're just testing for a possible location (MODE_ACCEPT_DROP), we don't bother |
| 1685 | // committing anything or animating anything as we just want to determine if a solution |
| 1686 | // exists |
| 1687 | if (mode == MODE_DRAG_OVER || mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL) { |
| 1688 | if (!DESTRUCTIVE_REORDER) { |
| 1689 | setUseTempCoords(true); |
| 1690 | } |
| 1691 | |
| 1692 | if (!DESTRUCTIVE_REORDER) { |
| 1693 | copySolutionToTempState(solution, dragView); |
| 1694 | } |
| 1695 | setItemPlacementDirty(true); |
| 1696 | animateItemsToSolution(solution, dragView, mode == MODE_ON_DROP); |
| 1697 | |
| 1698 | if (!DESTRUCTIVE_REORDER |
| 1699 | && (mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL)) { |
| 1700 | // Since the temp solution didn't update dragView, don't commit it either |
| 1701 | commitTempPlacement(dragView); |
| 1702 | completeAndClearReorderPreviewAnimations(); |
| 1703 | setItemPlacementDirty(false); |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1704 | } else { |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1705 | beginOrAdjustReorderPreviewAnimations(solution, dragView, |
| 1706 | ReorderPreviewAnimation.MODE_PREVIEW); |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1707 | } |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
Sebastian Franco | 53a15a4 | 2022-10-25 17:28:54 -0700 | [diff] [blame] | 1710 | if (mode == MODE_ON_DROP && !DESTRUCTIVE_REORDER) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1711 | setUseTempCoords(false); |
| 1712 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1713 | |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1714 | mShortcutsAndWidgets.requestLayout(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1715 | } |
| 1716 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1717 | void setItemPlacementDirty(boolean dirty) { |
| 1718 | mItemPlacementDirty = dirty; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1719 | } |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1720 | boolean isItemPlacementDirty() { |
| 1721 | return mItemPlacementDirty; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1722 | } |
| 1723 | |
Sebastian Franco | e4c0345 | 2022-12-27 14:50:02 -0600 | [diff] [blame] | 1724 | /** |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1725 | * Find a starting cell position that will fit the given bounds nearest the requested |
| 1726 | * cell location. Uses Euclidean distance to score multiple vacant areas. |
| 1727 | * |
| 1728 | * @param pixelX The X location at which you want to search for a vacant area. |
| 1729 | * @param pixelY The Y location at which you want to search for a vacant area. |
| 1730 | * @param spanX Horizontal span of the object. |
| 1731 | * @param spanY Vertical span of the object. |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1732 | * @param result Previously returned value to possibly recycle. |
| 1733 | * @return The X, Y cell of a vacant area that can contain this object, |
| 1734 | * nearest the requested location. |
| 1735 | */ |
Sebastián Franco | f9a6ac2 | 2022-11-15 22:56:37 +0000 | [diff] [blame] | 1736 | public int[] findNearestAreaIgnoreOccupied(int pixelX, int pixelY, int spanX, int spanY, |
| 1737 | int[] result) { |
Sebastian Franco | b57c0b2 | 2022-06-28 13:54:35 -0700 | [diff] [blame] | 1738 | return findNearestArea(pixelX, pixelY, spanX, spanY, spanX, spanY, true, result, null); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1741 | boolean existsEmptyCell() { |
| 1742 | return findCellForSpan(null, 1, 1); |
| 1743 | } |
| 1744 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1745 | /** |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1746 | * Finds the upper-left coordinate of the first rectangle in the grid that can |
| 1747 | * hold a cell of the specified dimensions. If intersectX and intersectY are not -1, |
| 1748 | * then this method will only return coordinates for rectangles that contain the cell |
| 1749 | * (intersectX, intersectY) |
| 1750 | * |
| 1751 | * @param cellXY The array that will contain the position of a vacant cell if such a cell |
| 1752 | * can be found. |
| 1753 | * @param spanX The horizontal span of the cell we want to find. |
| 1754 | * @param spanY The vertical span of the cell we want to find. |
| 1755 | * |
| 1756 | * @return True if a vacant cell of the specified dimension was found, false otherwise. |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1757 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 1758 | public boolean findCellForSpan(int[] cellXY, int spanX, int spanY) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1759 | if (cellXY == null) { |
| 1760 | cellXY = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1761 | } |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1762 | return mOccupied.findVacantCell(cellXY, spanX, spanY); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | /** |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 1766 | * A drag event has begun over this layout. |
| 1767 | * It may have begun over this layout (in which case onDragChild is called first), |
| 1768 | * or it may have begun on another layout. |
| 1769 | */ |
| 1770 | void onDragEnter() { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 1771 | mDragging = true; |
Sebastian Franco | 5aa71ce | 2022-12-14 12:13:19 -0600 | [diff] [blame] | 1772 | mPreviousSolution = null; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | /** |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1776 | * Called when drag has left this CellLayout or has been completed (successfully or not) |
| 1777 | */ |
| 1778 | void onDragExit() { |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1779 | // This can actually be called when we aren't in a drag, e.g. when adding a new |
| 1780 | // item to this layout via the customize drawer. |
| 1781 | // Guard against that case. |
| 1782 | if (mDragging) { |
| 1783 | mDragging = false; |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 1784 | } |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 1785 | |
| 1786 | // Invalidate the drag data |
Sebastian Franco | 5aa71ce | 2022-12-14 12:13:19 -0600 | [diff] [blame] | 1787 | mPreviousSolution = null; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1788 | mDragCell[0] = mDragCell[1] = -1; |
Adam Cohen | f7ca3b4 | 2021-02-22 11:03:58 -0800 | [diff] [blame] | 1789 | mDragCellSpan[0] = mDragCellSpan[1] = -1; |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 1790 | mDragOutlineAnims[mDragOutlineCurrent].animateOut(); |
| 1791 | mDragOutlineCurrent = (mDragOutlineCurrent + 1) % mDragOutlineAnims.length; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1792 | revertTempState(); |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 1793 | setIsDragOverlapping(false); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | /** |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1797 | * Mark a child as having been dropped. |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 1798 | * At the beginning of the drag operation, the child may have been on another |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 1799 | * screen, but it is re-parented before this method is called. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1800 | * |
| 1801 | * @param child The child that is being dropped |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1802 | */ |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 1803 | void onDropChild(View child) { |
Romain Guy | d94533d | 2009-08-17 10:01:15 -0700 | [diff] [blame] | 1804 | if (child != null) { |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1805 | CellLayoutLayoutParams |
| 1806 | lp = (CellLayoutLayoutParams) child.getLayoutParams(); |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 1807 | lp.dropped = true; |
Romain Guy | d94533d | 2009-08-17 10:01:15 -0700 | [diff] [blame] | 1808 | child.requestLayout(); |
Tony Wickham | 1cdb6d0 | 2015-09-17 11:08:27 -0700 | [diff] [blame] | 1809 | markCellsAsOccupiedForView(child); |
Romain Guy | d94533d | 2009-08-17 10:01:15 -0700 | [diff] [blame] | 1810 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1813 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1814 | * Computes a bounding rectangle for a range of cells |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1815 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1816 | * @param cellX X coordinate of upper left corner expressed as a cell position |
| 1817 | * @param cellY Y coordinate of upper left corner expressed as a cell position |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1818 | * @param cellHSpan Width in cells |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1819 | * @param cellVSpan Height in cells |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1820 | * @param resultRect Rect into which to put the results |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1821 | */ |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1822 | public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, Rect resultRect) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1823 | final int cellWidth = mCellWidth; |
| 1824 | final int cellHeight = mCellHeight; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1825 | |
Pierre Barbier de Reuille | 1b8bbb6 | 2021-05-19 22:45:16 +0100 | [diff] [blame] | 1826 | // We observe a shift of 1 pixel on the x coordinate compared to the actual cell coordinates |
| 1827 | final int hStartPadding = getPaddingLeft() |
| 1828 | + (int) Math.ceil(getUnusedHorizontalSpace() / 2f); |
Winson Chung | 4b825dcd | 2011-06-19 12:41:22 -0700 | [diff] [blame] | 1829 | final int vStartPadding = getPaddingTop(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1830 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1831 | int x = hStartPadding + (cellX * mBorderSpace.x) + (cellX * cellWidth); |
| 1832 | int y = vStartPadding + (cellY * mBorderSpace.y) + (cellY * cellHeight); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1833 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1834 | int width = cellHSpan * cellWidth + ((cellHSpan - 1) * mBorderSpace.x); |
| 1835 | int height = cellVSpan * cellHeight + ((cellVSpan - 1) * mBorderSpace.y); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1836 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1837 | resultRect.set(x, y, x + width, y + height); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1838 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1839 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 1840 | public void markCellsAsOccupiedForView(View view) { |
Sebastian Franco | f153d91 | 2022-04-22 16:15:27 -0500 | [diff] [blame] | 1841 | if (view instanceof LauncherAppWidgetHostView |
| 1842 | && view.getTag() instanceof LauncherAppWidgetInfo) { |
| 1843 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 1844 | CellPos pos = mActivity.getCellPosMapper().mapModelToPresenter(info); |
| 1845 | mOccupied.markCells(pos.cellX, pos.cellY, info.spanX, info.spanY, true); |
Sebastian Franco | f153d91 | 2022-04-22 16:15:27 -0500 | [diff] [blame] | 1846 | return; |
| 1847 | } |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1848 | if (view == null || view.getParent() != mShortcutsAndWidgets) return; |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1849 | CellLayoutLayoutParams |
| 1850 | lp = (CellLayoutLayoutParams) view.getLayoutParams(); |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1851 | mOccupied.markCells(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan, true); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 1854 | public void markCellsAsUnoccupiedForView(View view) { |
Sebastian Franco | f153d91 | 2022-04-22 16:15:27 -0500 | [diff] [blame] | 1855 | if (view instanceof LauncherAppWidgetHostView |
| 1856 | && view.getTag() instanceof LauncherAppWidgetInfo) { |
| 1857 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag(); |
Sunny Goyal | 669b71f | 2023-01-27 14:37:07 -0800 | [diff] [blame] | 1858 | CellPos pos = mActivity.getCellPosMapper().mapModelToPresenter(info); |
| 1859 | mOccupied.markCells(pos.cellX, pos.cellY, info.spanX, info.spanY, false); |
Sebastian Franco | f153d91 | 2022-04-22 16:15:27 -0500 | [diff] [blame] | 1860 | return; |
| 1861 | } |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1862 | if (view == null || view.getParent() != mShortcutsAndWidgets) return; |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1863 | CellLayoutLayoutParams |
| 1864 | lp = (CellLayoutLayoutParams) view.getLayoutParams(); |
Sebastian Franco | 877088e | 2023-01-03 15:16:22 -0700 | [diff] [blame] | 1865 | mOccupied.markCells(lp.getCellX(), lp.getCellY(), lp.cellHSpan, lp.cellVSpan, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1868 | public int getDesiredWidth() { |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1869 | return getPaddingLeft() + getPaddingRight() + (mCountX * mCellWidth) |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1870 | + ((mCountX - 1) * mBorderSpace.x); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | public int getDesiredHeight() { |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1874 | return getPaddingTop() + getPaddingBottom() + (mCountY * mCellHeight) |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1875 | + ((mCountY - 1) * mBorderSpace.y); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Michael Jurka | 66d7217 | 2011-04-12 16:29:25 -0700 | [diff] [blame] | 1878 | public boolean isOccupied(int x, int y) { |
Schneider Victor-tulias | 750c5af | 2023-07-26 10:16:04 -0700 | [diff] [blame] | 1879 | if (x >= 0 && x < mCountX && y >= 0 && y < mCountY) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1880 | return mOccupied.cells[x][y]; |
Schneider Victor-tulias | 750c5af | 2023-07-26 10:16:04 -0700 | [diff] [blame] | 1881 | } |
| 1882 | if (BuildConfig.IS_STUDIO_BUILD) { |
Michael Jurka | 66d7217 | 2011-04-12 16:29:25 -0700 | [diff] [blame] | 1883 | throw new RuntimeException("Position exceeds the bound of this CellLayout"); |
| 1884 | } |
Schneider Victor-tulias | 750c5af | 2023-07-26 10:16:04 -0700 | [diff] [blame] | 1885 | return true; |
Michael Jurka | 66d7217 | 2011-04-12 16:29:25 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1888 | @Override |
| 1889 | public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1890 | return new CellLayoutLayoutParams(getContext(), attrs); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | @Override |
| 1894 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1895 | return p instanceof CellLayoutLayoutParams; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | @Override |
| 1899 | protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { |
Sebastian Franco | d468299 | 2022-10-05 13:03:09 -0500 | [diff] [blame] | 1900 | return new CellLayoutLayoutParams(p); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1901 | } |
| 1902 | |
Samuel Fufa | 1e2d004 | 2019-11-18 17:12:46 -0800 | [diff] [blame] | 1903 | /** |
Tony Wickham | 8693061 | 2015-09-09 13:50:40 -0700 | [diff] [blame] | 1904 | * Returns whether an item can be placed in this CellLayout (after rearranging and/or resizing |
| 1905 | * if necessary). |
| 1906 | */ |
| 1907 | public boolean hasReorderSolution(ItemInfo itemInfo) { |
| 1908 | int[] cellPoint = new int[2]; |
| 1909 | // Check for a solution starting at every cell. |
| 1910 | for (int cellX = 0; cellX < getCountX(); cellX++) { |
| 1911 | for (int cellY = 0; cellY < getCountY(); cellY++) { |
| 1912 | cellToPoint(cellX, cellY, cellPoint); |
| 1913 | if (findReorderSolution(cellPoint[0], cellPoint[1], itemInfo.minSpanX, |
| 1914 | itemInfo.minSpanY, itemInfo.spanX, itemInfo.spanY, mDirectionVector, null, |
Charlie Anderson | 4612239 | 2024-01-18 17:23:46 -0500 | [diff] [blame] | 1915 | true).isSolution) { |
Tony Wickham | 8693061 | 2015-09-09 13:50:40 -0700 | [diff] [blame] | 1916 | return true; |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | return false; |
| 1921 | } |
| 1922 | |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 1923 | /** |
| 1924 | * Finds solution to accept hotseat migration to cell layout. commits solution if commitConfig |
| 1925 | */ |
| 1926 | public boolean makeSpaceForHotseatMigration(boolean commitConfig) { |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 1927 | int[] cellPoint = new int[2]; |
| 1928 | int[] directionVector = new int[]{0, -1}; |
| 1929 | cellToPoint(0, mCountY, cellPoint); |
Charlie Anderson | 4612239 | 2024-01-18 17:23:46 -0500 | [diff] [blame] | 1930 | ItemConfiguration configuration = findReorderSolution( |
| 1931 | cellPoint[0] /* pixelX */, |
| 1932 | cellPoint[1] /* pixelY */, |
| 1933 | mCountX /* minSpanX */, |
| 1934 | 1 /* minSpanY */, |
| 1935 | mCountX /* spanX */, |
| 1936 | 1 /* spanY */, |
| 1937 | directionVector /* direction */, |
| 1938 | null /* dragView */, |
| 1939 | false /* decX */ |
| 1940 | ); |
| 1941 | if (configuration.isSolution) { |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 1942 | if (commitConfig) { |
| 1943 | copySolutionToTempState(configuration, null); |
Sunny Goyal | 711c596 | 2021-06-23 12:36:18 -0700 | [diff] [blame] | 1944 | commitTempPlacement(null); |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 1945 | // undo marking cells occupied since there is actually nothing being placed yet. |
| 1946 | mOccupied.markCells(0, mCountY - 1, mCountX, 1, false); |
Samuel Fufa | a421143 | 2020-02-25 18:47:54 -0800 | [diff] [blame] | 1947 | } |
| 1948 | return true; |
| 1949 | } |
| 1950 | return false; |
| 1951 | } |
| 1952 | |
Samuel Fufa | 82bbdac | 2020-03-09 18:24:47 -0700 | [diff] [blame] | 1953 | /** |
| 1954 | * returns a copy of cell layout's grid occupancy |
| 1955 | */ |
| 1956 | public GridOccupancy cloneGridOccupancy() { |
| 1957 | GridOccupancy occupancy = new GridOccupancy(mCountX, mCountY); |
| 1958 | mOccupied.copyTo(occupancy); |
| 1959 | return occupancy; |
| 1960 | } |
| 1961 | |
Sunny Goyal | 9ca9c13 | 2015-04-29 14:57:22 -0700 | [diff] [blame] | 1962 | public boolean isRegionVacant(int x, int y, int spanX, int spanY) { |
Sunny Goyal | ff4ba2d | 2016-04-02 14:12:34 -0700 | [diff] [blame] | 1963 | return mOccupied.isRegionVacant(x, y, spanX, spanY); |
Sunny Goyal | 9ca9c13 | 2015-04-29 14:57:22 -0700 | [diff] [blame] | 1964 | } |
Sebastian Franco | 9ea36d4 | 2023-09-21 13:56:42 -0700 | [diff] [blame] | 1965 | |
| 1966 | public void setSpaceBetweenCellLayoutsPx(@Px int spaceBetweenCellLayoutsPx) { |
| 1967 | mSpaceBetweenCellLayoutsPx = spaceBetweenCellLayoutsPx; |
| 1968 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1969 | } |