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 | |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 17 | package com.android.launcher3.folder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
jayaprakashs | 8693272 | 2020-04-10 20:52:23 -0700 | [diff] [blame] | 19 | import static android.text.TextUtils.isEmpty; |
| 20 | |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW; |
| 22 | import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION; |
| 23 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 24 | import android.animation.Animator; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 25 | import android.animation.AnimatorListenerAdapter; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 26 | import android.animation.ObjectAnimator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 28 | import android.graphics.Canvas; |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 29 | import android.graphics.PointF; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 30 | import android.graphics.Rect; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
| 32 | import android.util.AttributeSet; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 33 | import android.util.Property; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | import android.view.LayoutInflater; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 35 | import android.view.MotionEvent; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 36 | import android.view.View; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 37 | import android.view.ViewDebug; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | import android.view.ViewGroup; |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 39 | import android.widget.FrameLayout; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | |
Tony Wickham | e1cb93f | 2019-05-03 11:27:32 -0700 | [diff] [blame] | 41 | import androidx.annotation.NonNull; |
| 42 | |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 43 | import com.android.launcher3.Alarm; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 44 | import com.android.launcher3.BubbleTextView; |
| 45 | import com.android.launcher3.CellLayout; |
| 46 | import com.android.launcher3.CheckLongPressHelper; |
| 47 | import com.android.launcher3.DeviceProfile; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 48 | import com.android.launcher3.DropTarget.DragObject; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 49 | import com.android.launcher3.Launcher; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 50 | import com.android.launcher3.LauncherSettings; |
| 51 | import com.android.launcher3.OnAlarmListener; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 52 | import com.android.launcher3.R; |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 53 | import com.android.launcher3.Reorderable; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 54 | import com.android.launcher3.Utilities; |
| 55 | import com.android.launcher3.Workspace; |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 56 | import com.android.launcher3.anim.Interpolators; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 57 | import com.android.launcher3.config.FeatureFlags; |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 58 | import com.android.launcher3.dot.FolderDotInfo; |
Jon Miranda | 4f59381 | 2017-08-30 11:59:30 -0700 | [diff] [blame] | 59 | import com.android.launcher3.dragndrop.BaseItemDragListener; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 60 | import com.android.launcher3.dragndrop.DragLayer; |
| 61 | import com.android.launcher3.dragndrop.DragView; |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 62 | import com.android.launcher3.dragndrop.DraggableView; |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 63 | import com.android.launcher3.icons.DotRenderer; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 64 | import com.android.launcher3.model.data.AppInfo; |
| 65 | import com.android.launcher3.model.data.FolderInfo; |
| 66 | import com.android.launcher3.model.data.FolderInfo.FolderListener; |
| 67 | import com.android.launcher3.model.data.ItemInfo; |
| 68 | import com.android.launcher3.model.data.WorkspaceItemInfo; |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 69 | import com.android.launcher3.touch.ItemClickHandler; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 70 | import com.android.launcher3.util.Executors; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 71 | import com.android.launcher3.util.Thunk; |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 72 | import com.android.launcher3.views.ActivityContext; |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 73 | import com.android.launcher3.views.IconLabelDotView; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 74 | import com.android.launcher3.widget.PendingAddShortcutInfo; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 75 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 76 | import java.util.ArrayList; |
Jon Miranda | 12b616c | 2017-02-06 15:45:53 -0800 | [diff] [blame] | 77 | import java.util.List; |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 78 | import java.util.function.Predicate; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 80 | /** |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 81 | * An icon that can appear on in the workspace representing an {@link Folder}. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 82 | */ |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 83 | public class FolderIcon extends FrameLayout implements FolderListener, IconLabelDotView, |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 84 | DraggableView, Reorderable { |
Sunny Goyal | d0ae492 | 2018-10-11 10:37:53 -0700 | [diff] [blame] | 85 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 86 | @Thunk ActivityContext mActivity; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 87 | @Thunk Folder mFolder; |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 88 | private FolderInfo mInfo; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 89 | |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 90 | private CheckLongPressHelper mLongPressHelper; |
| 91 | |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 92 | static final int DROP_IN_ANIMATION_DURATION = 400; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 93 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 94 | // Flag whether the folder should open itself when an item is dragged over is enabled. |
| 95 | public static final boolean SPRING_LOADING_ENABLED = true; |
| 96 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 97 | // Delay when drag enters until the folder opens, in miliseconds. |
| 98 | private static final int ON_OPEN_DELAY = 800; |
| 99 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 100 | @Thunk BubbleTextView mFolderName; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 101 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 102 | PreviewBackground mBackground = new PreviewBackground(); |
Jon Miranda | e4a252a | 2017-06-18 17:43:16 -0700 | [diff] [blame] | 103 | private boolean mBackgroundIsVisible = true; |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 104 | |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 105 | FolderGridOrganizer mPreviewVerifier; |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 106 | ClippedFolderIconLayoutRule mPreviewLayoutRule; |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 107 | private PreviewItemManager mPreviewItemManager; |
| 108 | private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0); |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 109 | private List<WorkspaceItemInfo> mCurrentPreviewItems = new ArrayList<>(); |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 110 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 111 | boolean mAnimating = false; |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 112 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 113 | private Alarm mOpenAlarm = new Alarm(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 114 | |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 115 | private boolean mForceHideDot; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 116 | @ViewDebug.ExportedProperty(category = "launcher", deepExport = true) |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 117 | private FolderDotInfo mDotInfo = new FolderDotInfo(); |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 118 | private DotRenderer mDotRenderer; |
| 119 | @ViewDebug.ExportedProperty(category = "launcher", deepExport = true) |
| 120 | private DotRenderer.DrawParams mDotParams; |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 121 | private float mDotScale; |
| 122 | private Animator mDotScaleAnim; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 123 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame^] | 124 | private final PointF mTranslationForReorderBounce = new PointF(0, 0); |
| 125 | private final PointF mTranslationForReorderPreview = new PointF(0, 0); |
| 126 | private float mScaleForReorderBounce = 1f; |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 127 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 128 | private static final Property<FolderIcon, Float> DOT_SCALE_PROPERTY |
| 129 | = new Property<FolderIcon, Float>(Float.TYPE, "dotScale") { |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 130 | @Override |
| 131 | public Float get(FolderIcon folderIcon) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 132 | return folderIcon.mDotScale; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void set(FolderIcon folderIcon, Float value) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 137 | folderIcon.mDotScale = value; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 138 | folderIcon.invalidate(); |
| 139 | } |
| 140 | }; |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 141 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 142 | public FolderIcon(Context context, AttributeSet attrs) { |
| 143 | super(context, attrs); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 144 | init(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | public FolderIcon(Context context) { |
| 148 | super(context); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 149 | init(); |
| 150 | } |
| 151 | |
| 152 | private void init() { |
| 153 | mLongPressHelper = new CheckLongPressHelper(this); |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 154 | mPreviewLayoutRule = new ClippedFolderIconLayoutRule(); |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 155 | mPreviewItemManager = new PreviewItemManager(this); |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 156 | mDotParams = new DotRenderer.DrawParams(); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 159 | public static FolderIcon inflateFolderAndIcon(int resId, Launcher launcher, ViewGroup group, |
| 160 | FolderInfo folderInfo) { |
| 161 | Folder folder = Folder.fromXml(launcher); |
| 162 | folder.setDragController(launcher.getDragController()); |
| 163 | |
| 164 | FolderIcon icon = inflateIcon(resId, launcher, group, folderInfo); |
| 165 | folder.setFolderIcon(icon); |
| 166 | folder.bind(folderInfo); |
| 167 | icon.setFolder(folder); |
| 168 | |
| 169 | icon.setOnFocusChangeListener(launcher.getFocusHandler()); |
| 170 | return icon; |
| 171 | } |
| 172 | |
| 173 | public static FolderIcon inflateIcon(int resId, ActivityContext activity, ViewGroup group, |
Sunny Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 174 | FolderInfo folderInfo) { |
Michael Jurka | 3a9fced | 2012-04-13 14:44:29 -0700 | [diff] [blame] | 175 | @SuppressWarnings("all") // suppress dead code warning |
| 176 | final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION; |
| 177 | if (error) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 178 | throw new IllegalStateException("DROP_IN_ANIMATION_DURATION must be greater than " + |
| 179 | "INITIAL_ITEM_ANIMATION_DURATION, as sequencing of adding first two items " + |
| 180 | "is dependent on this"); |
| 181 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 182 | |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 183 | DeviceProfile grid = activity.getDeviceProfile(); |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 184 | FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext()) |
| 185 | .inflate(resId, group, false); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 186 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 187 | icon.setClipToPadding(false); |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 188 | icon.mFolderName = icon.findViewById(R.id.folder_icon_name); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 189 | icon.mFolderName.setText(folderInfo.title); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 190 | icon.mFolderName.setCompoundDrawablePadding(0); |
| 191 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) icon.mFolderName.getLayoutParams(); |
| 192 | lp.topMargin = grid.iconSizePx + grid.iconDrawablePaddingPx; |
| 193 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 194 | icon.setTag(folderInfo); |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 195 | icon.setOnClickListener(ItemClickHandler.INSTANCE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 196 | icon.mInfo = folderInfo; |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 197 | icon.mActivity = activity; |
Samuel Fufa | c96fa24 | 2019-09-26 23:06:32 -0700 | [diff] [blame] | 198 | icon.mDotRenderer = grid.mDotRendererWorkSpace; |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 199 | |
| 200 | icon.setContentDescription( |
| 201 | group.getContext().getString(R.string.folder_name_format, folderInfo.title)); |
Tony Wickham | a538d2b | 2020-01-06 18:08:05 -0800 | [diff] [blame] | 202 | |
| 203 | // Keep the notification dot up to date with the sum of all the content's dots. |
| 204 | FolderDotInfo folderDotInfo = new FolderDotInfo(); |
| 205 | for (WorkspaceItemInfo si : folderInfo.contents) { |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 206 | folderDotInfo.addDotInfo(activity.getDotInfoForItem(si)); |
Tony Wickham | a538d2b | 2020-01-06 18:08:05 -0800 | [diff] [blame] | 207 | } |
| 208 | icon.setDotInfo(folderDotInfo); |
| 209 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 210 | icon.setAccessibilityDelegate(activity.getAccessibilityDelegate()); |
| 211 | |
| 212 | icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile().inv); |
| 213 | icon.mPreviewVerifier.setFolderInfo(folderInfo); |
| 214 | icon.updatePreviewItems(false); |
Sunny Goyal | e48644a | 2016-05-16 16:16:14 -0700 | [diff] [blame] | 215 | |
Sunny Goyal | 90cb3e5 | 2016-05-17 21:25:48 +0000 | [diff] [blame] | 216 | folderInfo.addListener(icon); |
| 217 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 218 | return icon; |
| 219 | } |
| 220 | |
Jon Miranda | 6f455b5 | 2019-03-27 08:27:16 -0700 | [diff] [blame] | 221 | public void animateBgShadowAndStroke() { |
| 222 | mBackground.fadeInBackgroundShadow(); |
| 223 | mBackground.animateBackgroundStroke(); |
| 224 | } |
| 225 | |
| 226 | public BubbleTextView getFolderName() { |
| 227 | return mFolderName; |
| 228 | } |
| 229 | |
Jon Miranda | 69b35e0 | 2019-03-04 20:16:18 -0800 | [diff] [blame] | 230 | public void getPreviewBounds(Rect outBounds) { |
Tony | 5cb5e40 | 2019-03-28 12:09:58 -0500 | [diff] [blame] | 231 | mPreviewItemManager.recomputePreviewDrawingParams(); |
Jon Miranda | 69b35e0 | 2019-03-04 20:16:18 -0800 | [diff] [blame] | 232 | mBackground.getBounds(outBounds); |
| 233 | } |
| 234 | |
Jon Miranda | ae975a6 | 2019-05-20 11:10:25 -0700 | [diff] [blame] | 235 | public float getBackgroundStrokeWidth() { |
| 236 | return mBackground.getStrokeWidth(); |
| 237 | } |
| 238 | |
Anjali Koppal | f05545f | 2014-03-10 19:18:43 -0700 | [diff] [blame] | 239 | public Folder getFolder() { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 240 | return mFolder; |
| 241 | } |
| 242 | |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 243 | private void setFolder(Folder folder) { |
| 244 | mFolder = folder; |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 247 | private boolean willAcceptItem(ItemInfo item) { |
| 248 | final int itemType = item.itemType; |
| 249 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 250 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT || |
| 251 | itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) && |
Sunny Goyal | 6bb51f4 | 2018-01-04 10:54:48 -0800 | [diff] [blame] | 252 | item != mInfo && !mFolder.isOpen()); |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 255 | public boolean acceptDrop(ItemInfo dragInfo) { |
Jon Miranda | cb73920 | 2017-06-23 18:40:31 -0700 | [diff] [blame] | 256 | return !mFolder.isDestroyed() && willAcceptItem(dragInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 259 | public void addItem(WorkspaceItemInfo item) { |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 260 | mInfo.add(item, true); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 263 | public void removeItem(WorkspaceItemInfo item, boolean animate) { |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 264 | mInfo.remove(item, animate); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 267 | public void onDragEnter(ItemInfo dragInfo) { |
| 268 | if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return; |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 269 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 270 | CellLayout cl = (CellLayout) getParent().getParent(); |
| 271 | |
| 272 | mBackground.animateToAccept(cl, lp.cellX, lp.cellY); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 273 | mOpenAlarm.setOnAlarmListener(mOnOpenListener); |
Adam Cohen | dedfca2 | 2014-05-19 15:10:39 -0700 | [diff] [blame] | 274 | if (SPRING_LOADING_ENABLED && |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 275 | ((dragInfo instanceof AppInfo) |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 276 | || (dragInfo instanceof WorkspaceItemInfo) |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 277 | || (dragInfo instanceof PendingAddShortcutInfo))) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 278 | mOpenAlarm.setAlarm(ON_OPEN_DELAY); |
| 279 | } |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 282 | OnAlarmListener mOnOpenListener = new OnAlarmListener() { |
| 283 | public void onAlarm(Alarm alarm) { |
Sunny Goyal | e393d3a | 2016-09-09 12:42:10 -0700 | [diff] [blame] | 284 | mFolder.beginExternalDrag(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 285 | } |
| 286 | }; |
| 287 | |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 288 | public Drawable prepareCreateAnimation(final View destView) { |
| 289 | return mPreviewItemManager.prepareCreateAnimation(destView); |
Winson | 8f288aa | 2016-07-25 16:49:15 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 292 | public void performCreateAnimation(final WorkspaceItemInfo destInfo, final View destView, |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 293 | final WorkspaceItemInfo srcInfo, final DragObject d, Rect dstRect, |
Sunny Goyal | 1797af4 | 2017-10-06 13:29:57 -0700 | [diff] [blame] | 294 | float scaleRelativeToDragLayer) { |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 295 | final DragView srcView = d.dragView; |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 296 | prepareCreateAnimation(destView); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 297 | addItem(destInfo); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 298 | // This will animate the first item from it's position as an icon into its |
| 299 | // position as the first item in the preview |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 300 | mPreviewItemManager.createFirstItemAnimation(false /* reverse */, null) |
| 301 | .start(); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 302 | |
| 303 | // This will animate the dragView (srcView) into the new folder |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 304 | onDrop(srcInfo, d, dstRect, scaleRelativeToDragLayer, 1, |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 305 | false /* itemReturnedOnFailedDrop */); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 308 | public void performDestroyAnimation(Runnable onCompleteRunnable) { |
| 309 | // This will animate the final item in the preview to be full size. |
| 310 | mPreviewItemManager.createFirstItemAnimation(true /* reverse */, onCompleteRunnable) |
| 311 | .start(); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 314 | public void onDragExit() { |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 315 | mBackground.animateToRest(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 316 | mOpenAlarm.cancelAlarm(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 317 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 318 | |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 319 | private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect, |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 320 | float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 321 | item.cellX = -1; |
| 322 | item.cellY = -1; |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 323 | DragView animateView = d.dragView; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 324 | // Typically, the animateView corresponds to the DragView; however, if this is being done |
| 325 | // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we |
| 326 | // will not have a view to animate |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 327 | if (animateView != null && mActivity instanceof Launcher) { |
| 328 | final Launcher launcher = (Launcher) mActivity; |
| 329 | DragLayer dragLayer = launcher.getDragLayer(); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 330 | Rect from = new Rect(); |
| 331 | dragLayer.getViewRectRelativeToSelf(animateView, from); |
| 332 | Rect to = finalRect; |
| 333 | if (to == null) { |
| 334 | to = new Rect(); |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 335 | Workspace workspace = launcher.getWorkspace(); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 336 | // Set cellLayout and this to it's final state to compute final animation locations |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 337 | workspace.setFinalTransitionTransform(); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 338 | float scaleX = getScaleX(); |
| 339 | float scaleY = getScaleY(); |
| 340 | setScaleX(1.0f); |
| 341 | setScaleY(1.0f); |
| 342 | scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to); |
| 343 | // Finished computing final animation locations, restore current state |
| 344 | setScaleX(scaleX); |
| 345 | setScaleY(scaleY); |
Sunny Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 346 | workspace.resetTransitionTransform(); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 347 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 348 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 349 | int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 350 | boolean itemAdded = false; |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 351 | if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) { |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 352 | List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems); |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 353 | mInfo.add(item, index, false); |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 354 | mCurrentPreviewItems.clear(); |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 355 | mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0)); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 356 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 357 | if (!oldPreviewItems.equals(mCurrentPreviewItems)) { |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 358 | int newIndex = mCurrentPreviewItems.indexOf(item); |
| 359 | if (newIndex >= 0) { |
| 360 | // If the item dropped is going to be in the preview, we update the |
| 361 | // index here to reflect its position in the preview. |
| 362 | index = newIndex; |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 363 | } |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 364 | |
| 365 | mPreviewItemManager.hidePreviewItem(index, true); |
| 366 | mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 367 | itemAdded = true; |
| 368 | } else { |
| 369 | removeItem(item, false); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if (!itemAdded) { |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 374 | mInfo.add(item, index, true); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 377 | int[] center = new int[2]; |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 378 | float scale = getLocalCenterForIndex(index, numItemsInPreview, center); |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 379 | center[0] = Math.round(scaleRelativeToDragLayer * center[0]); |
| 380 | center[1] = Math.round(scaleRelativeToDragLayer * center[1]); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 381 | |
| 382 | to.offset(center[0] - animateView.getMeasuredWidth() / 2, |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 383 | center[1] - animateView.getMeasuredHeight() / 2); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 384 | |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 385 | float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 386 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 387 | float finalScale = scale * scaleRelativeToDragLayer; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 388 | dragLayer.animateView(animateView, from, to, finalAlpha, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 389 | 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 390 | Interpolators.DEACCEL_2, Interpolators.ACCEL_2, |
Sunny Goyal | 1797af4 | 2017-10-06 13:29:57 -0700 | [diff] [blame] | 391 | null, DragLayer.ANIMATION_END_DISAPPEAR, null); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 392 | |
Adam Cohen | 7a8b82b | 2013-05-29 18:41:50 -0700 | [diff] [blame] | 393 | mFolder.hideItem(item); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 394 | |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 395 | if (!itemAdded) mPreviewItemManager.hidePreviewItem(index, true); |
| 396 | final int finalIndex = index; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 397 | |
jayaprakashs | e534d3b | 2020-02-07 20:06:34 -0800 | [diff] [blame] | 398 | FolderNameInfo[] nameInfos = |
| 399 | new FolderNameInfo[FolderNameProvider.SUGGEST_MAX]; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 400 | if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) { |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 401 | Executors.UI_HELPER_EXECUTOR.post(() -> { |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 402 | d.folderNameProvider.getSuggestedFolderName( |
jayaprakashs | e534d3b | 2020-02-07 20:06:34 -0800 | [diff] [blame] | 403 | getContext(), mInfo.contents, nameInfos); |
| 404 | showFinalView(finalIndex, item, nameInfos); |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 405 | }); |
| 406 | } else { |
jayaprakashs | e534d3b | 2020-02-07 20:06:34 -0800 | [diff] [blame] | 407 | showFinalView(finalIndex, item, nameInfos); |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 408 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 409 | } else { |
| 410 | addItem(item); |
| 411 | } |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 414 | private void showFinalView(int finalIndex, final WorkspaceItemInfo item, |
jayaprakashs | e534d3b | 2020-02-07 20:06:34 -0800 | [diff] [blame] | 415 | FolderNameInfo[] nameInfos) { |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 416 | postDelayed(() -> { |
| 417 | mPreviewItemManager.hidePreviewItem(finalIndex, false); |
| 418 | mFolder.showItem(item); |
jayaprakashs | 8693272 | 2020-04-10 20:52:23 -0700 | [diff] [blame] | 419 | setLabelSuggestion(nameInfos); |
thiruram | f065fdf | 2020-04-14 09:55:34 -0700 | [diff] [blame] | 420 | mFolder.logCurrentFolderLabelState(); |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 421 | invalidate(); |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 422 | }, DROP_IN_ANIMATION_DURATION); |
| 423 | } |
| 424 | |
jayaprakashs | 8693272 | 2020-04-10 20:52:23 -0700 | [diff] [blame] | 425 | /** |
| 426 | * Set the suggested folder name. |
| 427 | */ |
| 428 | public void setLabelSuggestion(FolderNameInfo[] nameInfos) { |
| 429 | if (!FeatureFlags.FOLDER_NAME_SUGGEST.get()) { |
| 430 | return; |
| 431 | } |
| 432 | if (!isEmpty(mFolderName.getText().toString()) |
| 433 | || mInfo.hasOption(FolderInfo.FLAG_MANUAL_FOLDER_NAME)) { |
| 434 | return; |
| 435 | } |
| 436 | if (nameInfos == null || nameInfos[0] == null || isEmpty(nameInfos[0].getLabel())) { |
| 437 | return; |
| 438 | } |
| 439 | mInfo.title = nameInfos[0].getLabel(); |
| 440 | onTitleChanged(mInfo.title); |
| 441 | mFolder.mFolderName.setText(mInfo.title); |
| 442 | mFolder.mLauncher.getModelWriter().updateItemInDatabase(mInfo); |
jayaprakashs | 8693272 | 2020-04-10 20:52:23 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 446 | public void onDrop(DragObject d, boolean itemReturnedOnFailedDrop) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 447 | WorkspaceItemInfo item; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 448 | if (d.dragInfo instanceof AppInfo) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 449 | // Came from all apps -- make a copy |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 450 | item = ((AppInfo) d.dragInfo).makeWorkspaceItem(); |
Jon Miranda | 4f59381 | 2017-08-30 11:59:30 -0700 | [diff] [blame] | 451 | } else if (d.dragSource instanceof BaseItemDragListener){ |
| 452 | // Came from a different window -- make a copy |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 453 | item = new WorkspaceItemInfo((WorkspaceItemInfo) d.dragInfo); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 454 | } else { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 455 | item = (WorkspaceItemInfo) d.dragInfo; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 456 | } |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 457 | mFolder.notifyDrop(); |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 458 | onDrop(item, d, null, 1.0f, |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 459 | itemReturnedOnFailedDrop ? item.rank : mInfo.contents.size(), |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame] | 460 | itemReturnedOnFailedDrop |
| 461 | ); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 464 | public void setDotInfo(FolderDotInfo dotInfo) { |
| 465 | updateDotScale(mDotInfo.hasDot(), dotInfo.hasDot()); |
| 466 | mDotInfo = dotInfo; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 469 | public ClippedFolderIconLayoutRule getLayoutRule() { |
Jon Miranda | 4717011 | 2017-03-03 14:57:14 -0800 | [diff] [blame] | 470 | return mPreviewLayoutRule; |
| 471 | } |
| 472 | |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 473 | @Override |
| 474 | public void setForceHideDot(boolean forceHideDot) { |
| 475 | if (mForceHideDot == forceHideDot) { |
| 476 | return; |
| 477 | } |
| 478 | mForceHideDot = forceHideDot; |
| 479 | |
| 480 | if (forceHideDot) { |
| 481 | invalidate(); |
| 482 | } else if (hasDot()) { |
| 483 | animateDotScale(0, 1); |
| 484 | } |
| 485 | } |
| 486 | |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 487 | /** |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 488 | * Sets mDotScale to 1 or 0, animating if wasDotted or isDotted is false |
| 489 | * (the dot is being added or removed). |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 490 | */ |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 491 | private void updateDotScale(boolean wasDotted, boolean isDotted) { |
| 492 | float newDotScale = isDotted ? 1f : 0f; |
| 493 | // Animate when a dot is first added or when it is removed. |
| 494 | if ((wasDotted ^ isDotted) && isShown()) { |
| 495 | animateDotScale(newDotScale); |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 496 | } else { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 497 | cancelDotScaleAnim(); |
| 498 | mDotScale = newDotScale; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 499 | invalidate(); |
| 500 | } |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 503 | private void cancelDotScaleAnim() { |
| 504 | if (mDotScaleAnim != null) { |
| 505 | mDotScaleAnim.cancel(); |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 509 | public void animateDotScale(float... dotScales) { |
| 510 | cancelDotScaleAnim(); |
| 511 | mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales); |
| 512 | mDotScaleAnim.addListener(new AnimatorListenerAdapter() { |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 513 | @Override |
| 514 | public void onAnimationEnd(Animator animation) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 515 | mDotScaleAnim = null; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 516 | } |
| 517 | }); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 518 | mDotScaleAnim.start(); |
Tony | 814dead | 2017-06-15 18:30:41 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 521 | public boolean hasDot() { |
| 522 | return mDotInfo != null && mDotInfo.hasDot(); |
Tony | 814dead | 2017-06-15 18:30:41 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Adam Cohen | 119e898 | 2016-02-05 14:47:50 -0800 | [diff] [blame] | 525 | private float getLocalCenterForIndex(int index, int curNumItems, int[] center) { |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 526 | mTmpParams = mPreviewItemManager.computePreviewItemDrawingParams( |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 527 | Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index), curNumItems, mTmpParams); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 528 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 529 | mTmpParams.transX += mBackground.basePreviewOffsetX; |
| 530 | mTmpParams.transY += mBackground.basePreviewOffsetY; |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 531 | |
| 532 | float intrinsicIconSize = mPreviewItemManager.getIntrinsicIconSize(); |
| 533 | float offsetX = mTmpParams.transX + (mTmpParams.scale * intrinsicIconSize) / 2; |
| 534 | float offsetY = mTmpParams.transY + (mTmpParams.scale * intrinsicIconSize) / 2; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 535 | |
Jon Miranda | cb73920 | 2017-06-23 18:40:31 -0700 | [diff] [blame] | 536 | center[0] = Math.round(offsetX); |
| 537 | center[1] = Math.round(offsetY); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 538 | return mTmpParams.scale; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 541 | public void setFolderBackground(PreviewBackground bg) { |
| 542 | mBackground = bg; |
Adam Cohen | f172b74 | 2016-03-30 19:28:34 -0700 | [diff] [blame] | 543 | mBackground.setInvalidateDelegate(this); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 546 | @Override |
| 547 | public void setIconVisible(boolean visible) { |
Jon Miranda | e4a252a | 2017-06-18 17:43:16 -0700 | [diff] [blame] | 548 | mBackgroundIsVisible = visible; |
| 549 | invalidate(); |
| 550 | } |
| 551 | |
Adam Cohen | 6508699 | 2020-02-19 08:40:49 -0800 | [diff] [blame] | 552 | public boolean getIconVisible() { |
| 553 | return mBackgroundIsVisible; |
| 554 | } |
| 555 | |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 556 | public PreviewBackground getFolderBackground() { |
| 557 | return mBackground; |
| 558 | } |
| 559 | |
| 560 | public PreviewItemManager getPreviewItemManager() { |
| 561 | return mPreviewItemManager; |
| 562 | } |
| 563 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 564 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 565 | protected void dispatchDraw(Canvas canvas) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 566 | super.dispatchDraw(canvas); |
| 567 | |
Jon Miranda | e4a252a | 2017-06-18 17:43:16 -0700 | [diff] [blame] | 568 | if (!mBackgroundIsVisible) return; |
| 569 | |
Jon Miranda | 0c17215 | 2017-07-24 11:39:38 -0700 | [diff] [blame] | 570 | mPreviewItemManager.recomputePreviewDrawingParams(); |
| 571 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 572 | if (!mBackground.drawingDelegated()) { |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 573 | mBackground.drawBackground(canvas); |
Adam Cohen | 119e898 | 2016-02-05 14:47:50 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 576 | if (mCurrentPreviewItems.isEmpty() && !mAnimating) return; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 577 | |
Sunny Goyal | d0ae492 | 2018-10-11 10:37:53 -0700 | [diff] [blame] | 578 | final int saveCount = canvas.save(); |
| 579 | canvas.clipPath(mBackground.getClipPath()); |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 580 | mPreviewItemManager.draw(canvas); |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 581 | canvas.restoreToCount(saveCount); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 582 | |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 583 | if (!mBackground.drawingDelegated()) { |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 584 | mBackground.drawBackgroundStroke(canvas); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 585 | } |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 586 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 587 | drawDot(canvas); |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 590 | public void drawDot(Canvas canvas) { |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 591 | if (!mForceHideDot && ((mDotInfo != null && mDotInfo.hasDot()) || mDotScale > 0)) { |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 592 | Rect iconBounds = mDotParams.iconBounds; |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 593 | BubbleTextView.getIconBounds(this, iconBounds, mActivity.getDeviceProfile().iconSizePx); |
Tony Wickham | e1cb93f | 2019-05-03 11:27:32 -0700 | [diff] [blame] | 594 | float iconScale = (float) mBackground.previewSize / iconBounds.width(); |
| 595 | Utilities.scaleRectAboutCenter(iconBounds, iconScale); |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 596 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 597 | // If we are animating to the accepting state, animate the dot out. |
| 598 | mDotParams.scale = Math.max(0, mDotScale - mBackground.getScaleProgress()); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 599 | mDotParams.color = mBackground.getDotColor(); |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 600 | mDotRenderer.draw(canvas, mDotParams); |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 601 | } |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 604 | public void setTextVisible(boolean visible) { |
| 605 | if (visible) { |
| 606 | mFolderName.setVisibility(VISIBLE); |
| 607 | } else { |
| 608 | mFolderName.setVisibility(INVISIBLE); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | public boolean getTextVisible() { |
| 613 | return mFolderName.getVisibility() == VISIBLE; |
| 614 | } |
| 615 | |
Jon Miranda | 27bdbca | 2017-07-06 16:31:56 -0700 | [diff] [blame] | 616 | /** |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 617 | * Returns the list of items which should be visible in the preview |
Jon Miranda | 27bdbca | 2017-07-06 16:31:56 -0700 | [diff] [blame] | 618 | */ |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 619 | public List<WorkspaceItemInfo> getPreviewItemsOnPage(int page) { |
| 620 | return mPreviewVerifier.setFolderInfo(mInfo).previewItemsForPage(page, mInfo.contents); |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 621 | } |
| 622 | |
Sunny Goyal | 828b11e | 2017-06-22 09:53:59 -0700 | [diff] [blame] | 623 | @Override |
| 624 | protected boolean verifyDrawable(@NonNull Drawable who) { |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 625 | return mPreviewItemManager.verifyDrawable(who) || super.verifyDrawable(who); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Sunny Goyal | c52ba71 | 2016-04-05 15:59:05 -0700 | [diff] [blame] | 628 | @Override |
| 629 | public void onItemsChanged(boolean animate) { |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 630 | updatePreviewItems(animate); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 631 | invalidate(); |
| 632 | requestLayout(); |
| 633 | } |
| 634 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 635 | private void updatePreviewItems(boolean animate) { |
| 636 | mPreviewItemManager.updatePreviewItems(animate); |
| 637 | mCurrentPreviewItems.clear(); |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 638 | mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0)); |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 641 | /** |
| 642 | * Updates the preview items which match the provided condition |
| 643 | */ |
| 644 | public void updatePreviewItems(Predicate<WorkspaceItemInfo> itemCheck) { |
| 645 | mPreviewItemManager.updatePreviewItems(itemCheck); |
Jon Miranda | 4406094 | 2017-02-22 10:17:49 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | @Override |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 649 | public void onAdd(WorkspaceItemInfo item, int rank) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 650 | boolean wasDotted = mDotInfo.hasDot(); |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 651 | mDotInfo.addDotInfo(mActivity.getDotInfoForItem(item)); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 652 | boolean isDotted = mDotInfo.hasDot(); |
| 653 | updateDotScale(wasDotted, isDotted); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 654 | invalidate(); |
| 655 | requestLayout(); |
| 656 | } |
| 657 | |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 658 | @Override |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 659 | public void onRemove(WorkspaceItemInfo item) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 660 | boolean wasDotted = mDotInfo.hasDot(); |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 661 | mDotInfo.subtractDotInfo(mActivity.getDotInfoForItem(item)); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 662 | boolean isDotted = mDotInfo.hasDot(); |
| 663 | updateDotScale(wasDotted, isDotted); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 664 | invalidate(); |
| 665 | requestLayout(); |
| 666 | } |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 667 | |
| 668 | public void onTitleChanged(CharSequence title) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 669 | mFolderName.setText(title); |
Sunny Goyal | f4f89ef | 2015-09-02 15:06:12 -0700 | [diff] [blame] | 670 | setContentDescription(getContext().getString(R.string.folder_name_format, title)); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 671 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 672 | |
| 673 | @Override |
| 674 | public boolean onTouchEvent(MotionEvent event) { |
| 675 | // Call the superclass onTouchEvent first, because sometimes it changes the state to |
| 676 | // isPressed() on an ACTION_UP |
Sunny Goyal | 17feee8 | 2020-03-24 13:55:15 -0700 | [diff] [blame] | 677 | super.onTouchEvent(event); |
| 678 | mLongPressHelper.onTouchEvent(event); |
| 679 | // Keep receiving the rest of the events |
| 680 | return true; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void cancelLongPress() { |
| 685 | super.cancelLongPress(); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 686 | mLongPressHelper.cancelLongPress(); |
| 687 | } |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 688 | |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 689 | public void removeListeners() { |
| 690 | mInfo.removeListener(this); |
| 691 | mInfo.removeListener(mFolder); |
| 692 | } |
| 693 | |
Jon Miranda | f79e54b | 2017-03-31 13:48:39 -0700 | [diff] [blame] | 694 | public void clearLeaveBehindIfExists() { |
| 695 | ((CellLayout.LayoutParams) getLayoutParams()).canReorder = true; |
| 696 | if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 697 | CellLayout cl = (CellLayout) getParent().getParent(); |
| 698 | cl.clearFolderLeaveBehind(); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | public void drawLeaveBehindIfExists() { |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 703 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); |
| 704 | // While the folder is open, the position of the icon cannot change. |
| 705 | lp.canReorder = false; |
| 706 | if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 707 | CellLayout cl = (CellLayout) getParent().getParent(); |
| 708 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
| 709 | } |
Jon Miranda | f79e54b | 2017-03-31 13:48:39 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Jon Miranda | 27bdbca | 2017-07-06 16:31:56 -0700 | [diff] [blame] | 712 | public void onFolderClose(int currentPage) { |
| 713 | mPreviewItemManager.onFolderClose(currentPage); |
| 714 | } |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 715 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame^] | 716 | private void updateTranslation() { |
| 717 | super.setTranslationX(mTranslationForReorderBounce.x + mTranslationForReorderPreview.x); |
| 718 | super.setTranslationY(mTranslationForReorderBounce.y + mTranslationForReorderPreview.y); |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame^] | 721 | public void setReorderBounceOffset(float x, float y) { |
| 722 | mTranslationForReorderBounce.set(x, y); |
| 723 | updateTranslation(); |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame^] | 726 | public void getReorderBounceOffset(PointF offset) { |
| 727 | offset.set(mTranslationForReorderBounce); |
| 728 | } |
| 729 | |
| 730 | @Override |
| 731 | public void setReorderPreviewOffset(float x, float y) { |
| 732 | mTranslationForReorderPreview.set(x, y); |
| 733 | updateTranslation(); |
| 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public void getReorderPreviewOffset(PointF offset) { |
| 738 | offset.set(mTranslationForReorderPreview); |
| 739 | } |
| 740 | |
| 741 | public void setReorderBounceScale(float scale) { |
| 742 | mScaleForReorderBounce = scale; |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 743 | super.setScaleX(scale); |
| 744 | super.setScaleY(scale); |
| 745 | } |
| 746 | |
Adam Cohen | 1d13c0b | 2020-04-21 16:29:12 -0700 | [diff] [blame^] | 747 | public float getReorderBounceScale() { |
| 748 | return mScaleForReorderBounce; |
Adam Cohen | d916206 | 2020-03-24 16:35:35 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | public View getView() { |
| 752 | return this; |
| 753 | } |
| 754 | |
| 755 | @Override |
| 756 | public int getViewType() { |
| 757 | return DRAGGABLE_ICON; |
| 758 | } |
| 759 | |
| 760 | @Override |
| 761 | public void getVisualDragBounds(Rect bounds) { |
| 762 | getPreviewBounds(bounds); |
| 763 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 764 | } |