blob: b875a0b4cc79a4ef003d9b40ef0727409b6e2ee5 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Goyal26119432016-02-18 22:09:23 +000017package com.android.launcher3.folder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
jayaprakashs86932722020-04-10 20:52:23 -070019import static android.text.TextUtils.isEmpty;
20
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -070021import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
22import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION;
23
Adam Cohen2801caf2011-05-13 20:57:39 -070024import android.animation.Animator;
Tony4043b052018-08-17 13:47:39 -070025import android.animation.AnimatorListenerAdapter;
Sunny Goyal740ac7f2016-09-28 16:47:32 -070026import android.animation.ObjectAnimator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.content.Context;
Adam Cohena9cf38f2011-05-02 15:36:58 -070028import android.graphics.Canvas;
Adam Cohend9162062020-03-24 16:35:35 -070029import android.graphics.PointF;
Adam Cohen3e8f8112011-07-02 18:03:00 -070030import android.graphics.Rect;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.graphics.drawable.Drawable;
32import android.util.AttributeSet;
Tony Wickham1e618492017-02-02 12:57:18 -080033import android.util.Property;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.view.LayoutInflater;
Winson Chung88f33452012-02-23 15:23:44 -080035import android.view.MotionEvent;
Adam Cohen7c693212011-05-18 15:26:57 -070036import android.view.View;
Tony4043b052018-08-17 13:47:39 -070037import android.view.ViewDebug;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038import android.view.ViewGroup;
Winson Chung6e1c0d32013-10-25 15:24:24 -070039import android.widget.FrameLayout;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040
Tony Wickhame1cb93f2019-05-03 11:27:32 -070041import androidx.annotation.NonNull;
42
Sunny Goyal26119432016-02-18 22:09:23 +000043import com.android.launcher3.Alarm;
Sunny Goyal26119432016-02-18 22:09:23 +000044import com.android.launcher3.BubbleTextView;
45import com.android.launcher3.CellLayout;
46import com.android.launcher3.CheckLongPressHelper;
47import com.android.launcher3.DeviceProfile;
Daniel Sandler325dc232013-06-05 22:57:57 -040048import com.android.launcher3.DropTarget.DragObject;
Sunny Goyal26119432016-02-18 22:09:23 +000049import com.android.launcher3.Launcher;
Sunny Goyal26119432016-02-18 22:09:23 +000050import com.android.launcher3.LauncherSettings;
51import com.android.launcher3.OnAlarmListener;
Sunny Goyal26119432016-02-18 22:09:23 +000052import com.android.launcher3.R;
Adam Cohend9162062020-03-24 16:35:35 -070053import com.android.launcher3.Reorderable;
Sunny Goyal26119432016-02-18 22:09:23 +000054import com.android.launcher3.Utilities;
55import com.android.launcher3.Workspace;
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -070056import com.android.launcher3.anim.Interpolators;
Hyunyoung Song4c746202019-10-10 23:11:12 -070057import com.android.launcher3.config.FeatureFlags;
Tony Wickhamf34bee82018-12-03 18:11:39 -080058import com.android.launcher3.dot.FolderDotInfo;
Jon Miranda4f593812017-08-30 11:59:30 -070059import com.android.launcher3.dragndrop.BaseItemDragListener;
Vadim Tryshevfedca432015-08-19 17:55:02 -070060import com.android.launcher3.dragndrop.DragLayer;
61import com.android.launcher3.dragndrop.DragView;
Adam Cohen65086992020-02-19 08:40:49 -080062import com.android.launcher3.dragndrop.DraggableView;
Tony Wickham8912b042018-11-29 15:28:53 -080063import com.android.launcher3.icons.DotRenderer;
Sunny Goyale396abf2020-04-06 15:11:17 -070064import com.android.launcher3.model.data.AppInfo;
65import com.android.launcher3.model.data.FolderInfo;
66import com.android.launcher3.model.data.FolderInfo.FolderListener;
67import com.android.launcher3.model.data.ItemInfo;
68import com.android.launcher3.model.data.WorkspaceItemInfo;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -080069import com.android.launcher3.touch.ItemClickHandler;
Hyunyoung Song4c746202019-10-10 23:11:12 -070070import com.android.launcher3.util.Executors;
Adam Cohen091440a2015-03-18 14:16:05 -070071import com.android.launcher3.util.Thunk;
Tracy Zhou4d7b2442019-12-09 13:42:57 -080072import com.android.launcher3.views.ActivityContext;
Jon Miranda9b78e192019-08-30 18:42:01 -070073import com.android.launcher3.views.IconLabelDotView;
Jon Mirandac476d6e2017-05-04 16:30:01 -070074import com.android.launcher3.widget.PendingAddShortcutInfo;
Romain Guyedcce092010-03-04 13:03:17 -080075
Adam Cohenc0dcf592011-06-01 15:30:43 -070076import java.util.ArrayList;
Jon Miranda12b616c2017-02-06 15:45:53 -080077import java.util.List;
Sunny Goyalac6f69f2019-08-16 11:59:55 -070078import java.util.function.Predicate;
Adam Cohenc0dcf592011-06-01 15:30:43 -070079
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080/**
Adam Cohenf9c184a2016-01-15 16:47:43 -080081 * An icon that can appear on in the workspace representing an {@link Folder}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082 */
Adam Cohen65086992020-02-19 08:40:49 -080083public class FolderIcon extends FrameLayout implements FolderListener, IconLabelDotView,
Adam Cohend9162062020-03-24 16:35:35 -070084 DraggableView, Reorderable {
Sunny Goyald0ae4922018-10-11 10:37:53 -070085
Tracy Zhou4d7b2442019-12-09 13:42:57 -080086 @Thunk ActivityContext mActivity;
Adam Cohen091440a2015-03-18 14:16:05 -070087 @Thunk Folder mFolder;
Adam Cohenfb91f302012-06-11 15:45:18 -070088 private FolderInfo mInfo;
Adam Cohena9cf38f2011-05-02 15:36:58 -070089
Winson Chung88f33452012-02-23 15:23:44 -080090 private CheckLongPressHelper mLongPressHelper;
91
Jon Miranda6c5d1022017-07-06 09:55:50 -070092 static final int DROP_IN_ANIMATION_DURATION = 400;
Adam Cohenbadf71e2011-05-26 19:08:29 -070093
Jorim Jaggi55bd9722014-01-16 15:30:42 -080094 // 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 Jaggi55bd9722014-01-16 15:30:42 -080097 // Delay when drag enters until the folder opens, in miliseconds.
98 private static final int ON_OPEN_DELAY = 800;
99
Adam Cohenefca0272016-02-24 19:19:06 -0800100 @Thunk BubbleTextView mFolderName;
Adam Cohen2801caf2011-05-13 20:57:39 -0700101
Adam Cohenefca0272016-02-24 19:19:06 -0800102 PreviewBackground mBackground = new PreviewBackground();
Jon Mirandae4a252a2017-06-18 17:43:16 -0700103 private boolean mBackgroundIsVisible = true;
Adam Cohenf9c184a2016-01-15 16:47:43 -0800104
Sunny Goyal11a50742019-08-07 09:24:26 -0700105 FolderGridOrganizer mPreviewVerifier;
Sunny Goyaladd3d832017-09-08 11:59:05 -0700106 ClippedFolderIconLayoutRule mPreviewLayoutRule;
Jon Miranda6c5d1022017-07-06 09:55:50 -0700107 private PreviewItemManager mPreviewItemManager;
108 private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0);
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700109 private List<WorkspaceItemInfo> mCurrentPreviewItems = new ArrayList<>();
Adam Cohenf9c184a2016-01-15 16:47:43 -0800110
Adam Cohend0445262011-07-04 23:53:22 -0700111 boolean mAnimating = false;
Adam Cohenfb91f302012-06-11 15:45:18 -0700112
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800113 private Alarm mOpenAlarm = new Alarm();
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800114
Jon Miranda9b78e192019-08-30 18:42:01 -0700115 private boolean mForceHideDot;
Tony4043b052018-08-17 13:47:39 -0700116 @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
Tony Wickhamf34bee82018-12-03 18:11:39 -0800117 private FolderDotInfo mDotInfo = new FolderDotInfo();
Tony Wickham8912b042018-11-29 15:28:53 -0800118 private DotRenderer mDotRenderer;
119 @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
120 private DotRenderer.DrawParams mDotParams;
Tony Wickhamf34bee82018-12-03 18:11:39 -0800121 private float mDotScale;
122 private Animator mDotScaleAnim;
Tony Wickham1e618492017-02-02 12:57:18 -0800123
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700124 private final PointF mTranslationForReorderBounce = new PointF(0, 0);
125 private final PointF mTranslationForReorderPreview = new PointF(0, 0);
126 private float mScaleForReorderBounce = 1f;
Adam Cohend9162062020-03-24 16:35:35 -0700127
Tony Wickhamf34bee82018-12-03 18:11:39 -0800128 private static final Property<FolderIcon, Float> DOT_SCALE_PROPERTY
129 = new Property<FolderIcon, Float>(Float.TYPE, "dotScale") {
Tony Wickham1e618492017-02-02 12:57:18 -0800130 @Override
131 public Float get(FolderIcon folderIcon) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800132 return folderIcon.mDotScale;
Tony Wickham1e618492017-02-02 12:57:18 -0800133 }
134
135 @Override
136 public void set(FolderIcon folderIcon, Float value) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800137 folderIcon.mDotScale = value;
Tony Wickham1e618492017-02-02 12:57:18 -0800138 folderIcon.invalidate();
139 }
140 };
Tony Wickham11ba5072017-02-02 12:42:50 -0800141
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142 public FolderIcon(Context context, AttributeSet attrs) {
143 super(context, attrs);
Winson Chung88f33452012-02-23 15:23:44 -0800144 init();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145 }
146
147 public FolderIcon(Context context) {
148 super(context);
Winson Chung88f33452012-02-23 15:23:44 -0800149 init();
150 }
151
152 private void init() {
153 mLongPressHelper = new CheckLongPressHelper(this);
Sunny Goyaladd3d832017-09-08 11:59:05 -0700154 mPreviewLayoutRule = new ClippedFolderIconLayoutRule();
Jon Miranda6c5d1022017-07-06 09:55:50 -0700155 mPreviewItemManager = new PreviewItemManager(this);
Tony Wickham8912b042018-11-29 15:28:53 -0800156 mDotParams = new DotRenderer.DrawParams();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700157 }
158
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800159 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 Goyal1cd01b02016-11-09 10:43:58 -0800174 FolderInfo folderInfo) {
Michael Jurka3a9fced2012-04-13 14:44:29 -0700175 @SuppressWarnings("all") // suppress dead code warning
176 final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION;
177 if (error) {
Adam Cohend0445262011-07-04 23:53:22 -0700178 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 Cohen2e6da152015-05-06 11:42:25 -0700182
Sunny Goyalc4d32012020-04-03 17:10:11 -0700183 DeviceProfile grid = activity.getDeviceProfile();
Sunny Goyal9b29ca52017-02-17 10:39:44 -0800184 FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext())
185 .inflate(resId, group, false);
Adam Cohenefca0272016-02-24 19:19:06 -0800186
Winson Chung5f8afe62013-08-12 16:19:28 -0700187 icon.setClipToPadding(false);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800188 icon.mFolderName = icon.findViewById(R.id.folder_icon_name);
Adam Cohen76fc0852011-06-17 13:26:23 -0700189 icon.mFolderName.setText(folderInfo.title);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700190 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 Project31dd5032009-03-03 19:32:27 -0800194 icon.setTag(folderInfo);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800195 icon.setOnClickListener(ItemClickHandler.INSTANCE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 icon.mInfo = folderInfo;
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800197 icon.mActivity = activity;
Samuel Fufac96fa242019-09-26 23:06:32 -0700198 icon.mDotRenderer = grid.mDotRendererWorkSpace;
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800199
200 icon.setContentDescription(
201 group.getContext().getString(R.string.folder_name_format, folderInfo.title));
Tony Wickhama538d2b2020-01-06 18:08:05 -0800202
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 Zhou4d7b2442019-12-09 13:42:57 -0800206 folderDotInfo.addDotInfo(activity.getDotInfoForItem(si));
Tony Wickhama538d2b2020-01-06 18:08:05 -0800207 }
208 icon.setDotInfo(folderDotInfo);
209
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800210 icon.setAccessibilityDelegate(activity.getAccessibilityDelegate());
211
212 icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile().inv);
213 icon.mPreviewVerifier.setFolderInfo(folderInfo);
214 icon.updatePreviewItems(false);
Sunny Goyale48644a2016-05-16 16:16:14 -0700215
Sunny Goyal90cb3e52016-05-17 21:25:48 +0000216 folderInfo.addListener(icon);
217
Adam Cohen19072da2011-05-31 14:30:45 -0700218 return icon;
219 }
220
Jon Miranda6f455b52019-03-27 08:27:16 -0700221 public void animateBgShadowAndStroke() {
222 mBackground.fadeInBackgroundShadow();
223 mBackground.animateBackgroundStroke();
224 }
225
226 public BubbleTextView getFolderName() {
227 return mFolderName;
228 }
229
Jon Miranda69b35e02019-03-04 20:16:18 -0800230 public void getPreviewBounds(Rect outBounds) {
Tony5cb5e402019-03-28 12:09:58 -0500231 mPreviewItemManager.recomputePreviewDrawingParams();
Jon Miranda69b35e02019-03-04 20:16:18 -0800232 mBackground.getBounds(outBounds);
233 }
234
Jon Mirandaae975a62019-05-20 11:10:25 -0700235 public float getBackgroundStrokeWidth() {
236 return mBackground.getStrokeWidth();
237 }
238
Anjali Koppalf05545f2014-03-10 19:18:43 -0700239 public Folder getFolder() {
Adam Cohenfb91f302012-06-11 15:45:18 -0700240 return mFolder;
241 }
242
Adam Cohen4f8071b2016-02-13 16:06:05 -0800243 private void setFolder(Folder folder) {
244 mFolder = folder;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800245 }
246
Adam Cohen073a46f2011-05-17 16:28:09 -0700247 private boolean willAcceptItem(ItemInfo item) {
248 final int itemType = item.itemType;
249 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700250 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT ||
251 itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) &&
Sunny Goyal6bb51f42018-01-04 10:54:48 -0800252 item != mInfo && !mFolder.isOpen());
Adam Cohen073a46f2011-05-17 16:28:09 -0700253 }
254
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700255 public boolean acceptDrop(ItemInfo dragInfo) {
Jon Mirandacb739202017-06-23 18:40:31 -0700256 return !mFolder.isDestroyed() && willAcceptItem(dragInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 }
258
Sunny Goyal95899162019-03-27 16:03:06 -0700259 public void addItem(WorkspaceItemInfo item) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700260 mInfo.add(item, true);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700261 }
262
Sunny Goyal95899162019-03-27 16:03:06 -0700263 public void removeItem(WorkspaceItemInfo item, boolean animate) {
Jon Miranda4dd024b2017-07-13 17:54:54 -0700264 mInfo.remove(item, animate);
Adam Cohendf035382011-04-11 17:22:04 -0700265 }
266
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700267 public void onDragEnter(ItemInfo dragInfo) {
268 if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return;
Adam Cohen69ce2e52011-07-03 19:25:21 -0700269 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
Adam Cohenefca0272016-02-24 19:19:06 -0800270 CellLayout cl = (CellLayout) getParent().getParent();
271
272 mBackground.animateToAccept(cl, lp.cellX, lp.cellY);
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800273 mOpenAlarm.setOnAlarmListener(mOnOpenListener);
Adam Cohendedfca22014-05-19 15:10:39 -0700274 if (SPRING_LOADING_ENABLED &&
Jon Mirandac476d6e2017-05-04 16:30:01 -0700275 ((dragInfo instanceof AppInfo)
Sunny Goyal95899162019-03-27 16:03:06 -0700276 || (dragInfo instanceof WorkspaceItemInfo)
Jon Mirandac476d6e2017-05-04 16:30:01 -0700277 || (dragInfo instanceof PendingAddShortcutInfo))) {
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800278 mOpenAlarm.setAlarm(ON_OPEN_DELAY);
279 }
Adam Cohen073a46f2011-05-17 16:28:09 -0700280 }
281
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800282 OnAlarmListener mOnOpenListener = new OnAlarmListener() {
283 public void onAlarm(Alarm alarm) {
Sunny Goyale393d3a2016-09-09 12:42:10 -0700284 mFolder.beginExternalDrag();
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800285 }
286 };
287
Jon Miranda6c5d1022017-07-06 09:55:50 -0700288 public Drawable prepareCreateAnimation(final View destView) {
289 return mPreviewItemManager.prepareCreateAnimation(destView);
Winson8f288aa2016-07-25 16:49:15 -0700290 }
291
Sunny Goyal95899162019-03-27 16:03:06 -0700292 public void performCreateAnimation(final WorkspaceItemInfo destInfo, final View destView,
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800293 final WorkspaceItemInfo srcInfo, final DragObject d, Rect dstRect,
Sunny Goyal1797af42017-10-06 13:29:57 -0700294 float scaleRelativeToDragLayer) {
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800295 final DragView srcView = d.dragView;
Jon Miranda6c5d1022017-07-06 09:55:50 -0700296 prepareCreateAnimation(destView);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800297 addItem(destInfo);
Adam Cohend0445262011-07-04 23:53:22 -0700298 // 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 Miranda6c5d1022017-07-06 09:55:50 -0700300 mPreviewItemManager.createFirstItemAnimation(false /* reverse */, null)
301 .start();
Adam Cohenfb91f302012-06-11 15:45:18 -0700302
303 // This will animate the dragView (srcView) into the new folder
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800304 onDrop(srcInfo, d, dstRect, scaleRelativeToDragLayer, 1,
Jon Miranda6d3586c2017-09-08 12:39:10 -0700305 false /* itemReturnedOnFailedDrop */);
Adam Cohenfb91f302012-06-11 15:45:18 -0700306 }
307
Jon Miranda6c5d1022017-07-06 09:55:50 -0700308 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 Cohend0445262011-07-04 23:53:22 -0700312 }
313
Adam Cohenc6cc61d2012-04-04 12:47:08 -0700314 public void onDragExit() {
Adam Cohenefca0272016-02-24 19:19:06 -0800315 mBackground.animateToRest();
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800316 mOpenAlarm.cancelAlarm();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800317 }
Patrick Dubroy440c3602010-07-13 17:50:32 -0700318
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800319 private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect,
Sunny Goyal11a50742019-08-07 09:24:26 -0700320 float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) {
Adam Cohend0445262011-07-04 23:53:22 -0700321 item.cellX = -1;
322 item.cellY = -1;
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800323 DragView animateView = d.dragView;
Adam Cohen558baaf2011-08-15 15:22:57 -0700324 // 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 Zhou4d7b2442019-12-09 13:42:57 -0800327 if (animateView != null && mActivity instanceof Launcher) {
328 final Launcher launcher = (Launcher) mActivity;
329 DragLayer dragLayer = launcher.getDragLayer();
Adam Cohen558baaf2011-08-15 15:22:57 -0700330 Rect from = new Rect();
331 dragLayer.getViewRectRelativeToSelf(animateView, from);
332 Rect to = finalRect;
333 if (to == null) {
334 to = new Rect();
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800335 Workspace workspace = launcher.getWorkspace();
Adam Cohen558baaf2011-08-15 15:22:57 -0700336 // Set cellLayout and this to it's final state to compute final animation locations
Sunny Goyalaeb16432017-10-16 11:46:41 -0700337 workspace.setFinalTransitionTransform();
Adam Cohen558baaf2011-08-15 15:22:57 -0700338 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 Goyalaeb16432017-10-16 11:46:41 -0700346 workspace.resetTransitionTransform();
Adam Cohend0445262011-07-04 23:53:22 -0700347 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700348
Jon Miranda6d3586c2017-09-08 12:39:10 -0700349 int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700350 boolean itemAdded = false;
Jon Miranda6d3586c2017-09-08 12:39:10 -0700351 if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) {
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700352 List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems);
Sunny Goyal11a50742019-08-07 09:24:26 -0700353 mInfo.add(item, index, false);
Jon Miranda6d3586c2017-09-08 12:39:10 -0700354 mCurrentPreviewItems.clear();
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700355 mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
Jon Miranda4dd024b2017-07-13 17:54:54 -0700356
Jon Miranda6d3586c2017-09-08 12:39:10 -0700357 if (!oldPreviewItems.equals(mCurrentPreviewItems)) {
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700358 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 Miranda4dd024b2017-07-13 17:54:54 -0700363 }
Jon Miranda6d3586c2017-09-08 12:39:10 -0700364
365 mPreviewItemManager.hidePreviewItem(index, true);
366 mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700367 itemAdded = true;
368 } else {
369 removeItem(item, false);
370 }
371 }
372
373 if (!itemAdded) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700374 mInfo.add(item, index, true);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700375 }
376
Adam Cohen558baaf2011-08-15 15:22:57 -0700377 int[] center = new int[2];
Jon Miranda6d3586c2017-09-08 12:39:10 -0700378 float scale = getLocalCenterForIndex(index, numItemsInPreview, center);
Sunny Goyal11a50742019-08-07 09:24:26 -0700379 center[0] = Math.round(scaleRelativeToDragLayer * center[0]);
380 center[1] = Math.round(scaleRelativeToDragLayer * center[1]);
Adam Cohen558baaf2011-08-15 15:22:57 -0700381
382 to.offset(center[0] - animateView.getMeasuredWidth() / 2,
Jon Miranda4dd024b2017-07-13 17:54:54 -0700383 center[1] - animateView.getMeasuredHeight() / 2);
Adam Cohen558baaf2011-08-15 15:22:57 -0700384
Sunny Goyaladd3d832017-09-08 11:59:05 -0700385 float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;
Adam Cohen558baaf2011-08-15 15:22:57 -0700386
Adam Cohened66b2b2012-01-23 17:28:51 -0800387 float finalScale = scale * scaleRelativeToDragLayer;
Adam Cohen558baaf2011-08-15 15:22:57 -0700388 dragLayer.animateView(animateView, from, to, finalAlpha,
Adam Cohened66b2b2012-01-23 17:28:51 -0800389 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION,
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -0700390 Interpolators.DEACCEL_2, Interpolators.ACCEL_2,
Sunny Goyal1797af42017-10-06 13:29:57 -0700391 null, DragLayer.ANIMATION_END_DISAPPEAR, null);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700392
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700393 mFolder.hideItem(item);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800394
Jon Miranda4dd024b2017-07-13 17:54:54 -0700395 if (!itemAdded) mPreviewItemManager.hidePreviewItem(index, true);
396 final int finalIndex = index;
Hyunyoung Song4c746202019-10-10 23:11:12 -0700397
jayaprakashse534d3b2020-02-07 20:06:34 -0800398 FolderNameInfo[] nameInfos =
399 new FolderNameInfo[FolderNameProvider.SUGGEST_MAX];
Hyunyoung Song4c746202019-10-10 23:11:12 -0700400 if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800401 Executors.UI_HELPER_EXECUTOR.post(() -> {
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800402 d.folderNameProvider.getSuggestedFolderName(
jayaprakashse534d3b2020-02-07 20:06:34 -0800403 getContext(), mInfo.contents, nameInfos);
404 showFinalView(finalIndex, item, nameInfos);
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800405 });
406 } else {
jayaprakashse534d3b2020-02-07 20:06:34 -0800407 showFinalView(finalIndex, item, nameInfos);
Hyunyoung Song4c746202019-10-10 23:11:12 -0700408 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700409 } else {
410 addItem(item);
411 }
Adam Cohend0445262011-07-04 23:53:22 -0700412 }
413
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800414 private void showFinalView(int finalIndex, final WorkspaceItemInfo item,
jayaprakashse534d3b2020-02-07 20:06:34 -0800415 FolderNameInfo[] nameInfos) {
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800416 postDelayed(() -> {
417 mPreviewItemManager.hidePreviewItem(finalIndex, false);
418 mFolder.showItem(item);
jayaprakashs86932722020-04-10 20:52:23 -0700419 setLabelSuggestion(nameInfos);
thiruramf065fdf2020-04-14 09:55:34 -0700420 mFolder.logCurrentFolderLabelState();
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800421 invalidate();
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800422 }, DROP_IN_ANIMATION_DURATION);
423 }
424
jayaprakashs86932722020-04-10 20:52:23 -0700425 /**
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);
jayaprakashs86932722020-04-10 20:52:23 -0700443 }
444
445
Jon Miranda6d3586c2017-09-08 12:39:10 -0700446 public void onDrop(DragObject d, boolean itemReturnedOnFailedDrop) {
Sunny Goyal95899162019-03-27 16:03:06 -0700447 WorkspaceItemInfo item;
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200448 if (d.dragInfo instanceof AppInfo) {
Adam Cohenc0dcf592011-06-01 15:30:43 -0700449 // Came from all apps -- make a copy
Sunny Goyal95899162019-03-27 16:03:06 -0700450 item = ((AppInfo) d.dragInfo).makeWorkspaceItem();
Jon Miranda4f593812017-08-30 11:59:30 -0700451 } else if (d.dragSource instanceof BaseItemDragListener){
452 // Came from a different window -- make a copy
Sunny Goyal95899162019-03-27 16:03:06 -0700453 item = new WorkspaceItemInfo((WorkspaceItemInfo) d.dragInfo);
Adam Cohenc0dcf592011-06-01 15:30:43 -0700454 } else {
Sunny Goyal95899162019-03-27 16:03:06 -0700455 item = (WorkspaceItemInfo) d.dragInfo;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700456 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700457 mFolder.notifyDrop();
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800458 onDrop(item, d, null, 1.0f,
Sunny Goyal11a50742019-08-07 09:24:26 -0700459 itemReturnedOnFailedDrop ? item.rank : mInfo.contents.size(),
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800460 itemReturnedOnFailedDrop
461 );
Adam Cohenc0dcf592011-06-01 15:30:43 -0700462 }
463
Tony Wickhamf34bee82018-12-03 18:11:39 -0800464 public void setDotInfo(FolderDotInfo dotInfo) {
465 updateDotScale(mDotInfo.hasDot(), dotInfo.hasDot());
466 mDotInfo = dotInfo;
Tony Wickham1e618492017-02-02 12:57:18 -0800467 }
468
Sunny Goyaladd3d832017-09-08 11:59:05 -0700469 public ClippedFolderIconLayoutRule getLayoutRule() {
Jon Miranda47170112017-03-03 14:57:14 -0800470 return mPreviewLayoutRule;
471 }
472
Jon Miranda9b78e192019-08-30 18:42:01 -0700473 @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 Wickham1e618492017-02-02 12:57:18 -0800487 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800488 * Sets mDotScale to 1 or 0, animating if wasDotted or isDotted is false
489 * (the dot is being added or removed).
Tony Wickham1e618492017-02-02 12:57:18 -0800490 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800491 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 Wickham1e618492017-02-02 12:57:18 -0800496 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800497 cancelDotScaleAnim();
498 mDotScale = newDotScale;
Tony Wickham1e618492017-02-02 12:57:18 -0800499 invalidate();
500 }
Tony Wickham11ba5072017-02-02 12:42:50 -0800501 }
502
Tony Wickhamf34bee82018-12-03 18:11:39 -0800503 private void cancelDotScaleAnim() {
504 if (mDotScaleAnim != null) {
505 mDotScaleAnim.cancel();
Tony4043b052018-08-17 13:47:39 -0700506 }
507 }
508
Tony Wickhamf34bee82018-12-03 18:11:39 -0800509 public void animateDotScale(float... dotScales) {
510 cancelDotScaleAnim();
511 mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales);
512 mDotScaleAnim.addListener(new AnimatorListenerAdapter() {
Tony4043b052018-08-17 13:47:39 -0700513 @Override
514 public void onAnimationEnd(Animator animation) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800515 mDotScaleAnim = null;
Tony4043b052018-08-17 13:47:39 -0700516 }
517 });
Tony Wickhamf34bee82018-12-03 18:11:39 -0800518 mDotScaleAnim.start();
Tony814dead2017-06-15 18:30:41 -0700519 }
520
Tony Wickhamf34bee82018-12-03 18:11:39 -0800521 public boolean hasDot() {
522 return mDotInfo != null && mDotInfo.hasDot();
Tony814dead2017-06-15 18:30:41 -0700523 }
524
Adam Cohen119e8982016-02-05 14:47:50 -0800525 private float getLocalCenterForIndex(int index, int curNumItems, int[] center) {
Jon Miranda6c5d1022017-07-06 09:55:50 -0700526 mTmpParams = mPreviewItemManager.computePreviewItemDrawingParams(
Sunny Goyaladd3d832017-09-08 11:59:05 -0700527 Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index), curNumItems, mTmpParams);
Adam Cohend0445262011-07-04 23:53:22 -0700528
Adam Cohenefca0272016-02-24 19:19:06 -0800529 mTmpParams.transX += mBackground.basePreviewOffsetX;
530 mTmpParams.transY += mBackground.basePreviewOffsetY;
Jon Miranda6c5d1022017-07-06 09:55:50 -0700531
532 float intrinsicIconSize = mPreviewItemManager.getIntrinsicIconSize();
533 float offsetX = mTmpParams.transX + (mTmpParams.scale * intrinsicIconSize) / 2;
534 float offsetY = mTmpParams.transY + (mTmpParams.scale * intrinsicIconSize) / 2;
Adam Cohend0445262011-07-04 23:53:22 -0700535
Jon Mirandacb739202017-06-23 18:40:31 -0700536 center[0] = Math.round(offsetX);
537 center[1] = Math.round(offsetY);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800538 return mTmpParams.scale;
Adam Cohend0445262011-07-04 23:53:22 -0700539 }
540
Adam Cohenefca0272016-02-24 19:19:06 -0800541 public void setFolderBackground(PreviewBackground bg) {
542 mBackground = bg;
Adam Cohenf172b742016-03-30 19:28:34 -0700543 mBackground.setInvalidateDelegate(this);
Adam Cohenefca0272016-02-24 19:19:06 -0800544 }
545
Jon Miranda9b78e192019-08-30 18:42:01 -0700546 @Override
547 public void setIconVisible(boolean visible) {
Jon Mirandae4a252a2017-06-18 17:43:16 -0700548 mBackgroundIsVisible = visible;
549 invalidate();
550 }
551
Adam Cohen65086992020-02-19 08:40:49 -0800552 public boolean getIconVisible() {
553 return mBackgroundIsVisible;
554 }
555
Sunny Goyale29897f2017-07-20 10:09:42 -0700556 public PreviewBackground getFolderBackground() {
557 return mBackground;
558 }
559
560 public PreviewItemManager getPreviewItemManager() {
561 return mPreviewItemManager;
562 }
563
Adam Cohena9cf38f2011-05-02 15:36:58 -0700564 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700565 protected void dispatchDraw(Canvas canvas) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700566 super.dispatchDraw(canvas);
567
Jon Mirandae4a252a2017-06-18 17:43:16 -0700568 if (!mBackgroundIsVisible) return;
569
Jon Miranda0c172152017-07-24 11:39:38 -0700570 mPreviewItemManager.recomputePreviewDrawingParams();
571
Adam Cohenefca0272016-02-24 19:19:06 -0800572 if (!mBackground.drawingDelegated()) {
Sunny Goyal19b93b72017-02-19 20:21:37 -0800573 mBackground.drawBackground(canvas);
Adam Cohen119e8982016-02-05 14:47:50 -0800574 }
575
Sunny Goyal11a50742019-08-07 09:24:26 -0700576 if (mCurrentPreviewItems.isEmpty() && !mAnimating) return;
Adam Cohenefca0272016-02-24 19:19:06 -0800577
Sunny Goyald0ae4922018-10-11 10:37:53 -0700578 final int saveCount = canvas.save();
579 canvas.clipPath(mBackground.getClipPath());
Jon Miranda6c5d1022017-07-06 09:55:50 -0700580 mPreviewItemManager.draw(canvas);
Sunny Goyal19b93b72017-02-19 20:21:37 -0800581 canvas.restoreToCount(saveCount);
Adam Cohenefca0272016-02-24 19:19:06 -0800582
Sunny Goyaladd3d832017-09-08 11:59:05 -0700583 if (!mBackground.drawingDelegated()) {
Sunny Goyal19b93b72017-02-19 20:21:37 -0800584 mBackground.drawBackgroundStroke(canvas);
Adam Cohenefca0272016-02-24 19:19:06 -0800585 }
Tony Wickham11ba5072017-02-02 12:42:50 -0800586
Tony Wickhamf34bee82018-12-03 18:11:39 -0800587 drawDot(canvas);
Sunny Goyale29897f2017-07-20 10:09:42 -0700588 }
589
Tony Wickhamf34bee82018-12-03 18:11:39 -0800590 public void drawDot(Canvas canvas) {
Jon Miranda9b78e192019-08-30 18:42:01 -0700591 if (!mForceHideDot && ((mDotInfo != null && mDotInfo.hasDot()) || mDotScale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800592 Rect iconBounds = mDotParams.iconBounds;
Sunny Goyalc4d32012020-04-03 17:10:11 -0700593 BubbleTextView.getIconBounds(this, iconBounds, mActivity.getDeviceProfile().iconSizePx);
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700594 float iconScale = (float) mBackground.previewSize / iconBounds.width();
595 Utilities.scaleRectAboutCenter(iconBounds, iconScale);
Sunny Goyal19b93b72017-02-19 20:21:37 -0800596
Tony Wickhamf34bee82018-12-03 18:11:39 -0800597 // If we are animating to the accepting state, animate the dot out.
598 mDotParams.scale = Math.max(0, mDotScale - mBackground.getScaleProgress());
Tony Wickhamf34bee82018-12-03 18:11:39 -0800599 mDotParams.color = mBackground.getDotColor();
Tony Wickham8912b042018-11-29 15:28:53 -0800600 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham11ba5072017-02-02 12:42:50 -0800601 }
Adam Cohend0445262011-07-04 23:53:22 -0700602 }
603
Adam Cohen099f60d2011-08-23 21:07:26 -0700604 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 Miranda27bdbca2017-07-06 16:31:56 -0700616 /**
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700617 * Returns the list of items which should be visible in the preview
Jon Miranda27bdbca2017-07-06 16:31:56 -0700618 */
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700619 public List<WorkspaceItemInfo> getPreviewItemsOnPage(int page) {
620 return mPreviewVerifier.setFolderInfo(mInfo).previewItemsForPage(page, mInfo.contents);
Jon Miranda655ec422017-02-07 11:40:22 -0800621 }
622
Sunny Goyal828b11e2017-06-22 09:53:59 -0700623 @Override
624 protected boolean verifyDrawable(@NonNull Drawable who) {
Jon Miranda6c5d1022017-07-06 09:55:50 -0700625 return mPreviewItemManager.verifyDrawable(who) || super.verifyDrawable(who);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800626 }
627
Sunny Goyalc52ba712016-04-05 15:59:05 -0700628 @Override
629 public void onItemsChanged(boolean animate) {
Jon Miranda6d3586c2017-09-08 12:39:10 -0700630 updatePreviewItems(animate);
Adam Cohen76078c42011-06-09 15:06:52 -0700631 invalidate();
632 requestLayout();
633 }
634
Jon Miranda6d3586c2017-09-08 12:39:10 -0700635 private void updatePreviewItems(boolean animate) {
636 mPreviewItemManager.updatePreviewItems(animate);
637 mCurrentPreviewItems.clear();
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700638 mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
Jon Miranda6d3586c2017-09-08 12:39:10 -0700639 }
640
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700641 /**
642 * Updates the preview items which match the provided condition
643 */
644 public void updatePreviewItems(Predicate<WorkspaceItemInfo> itemCheck) {
645 mPreviewItemManager.updatePreviewItems(itemCheck);
Jon Miranda44060942017-02-22 10:17:49 -0800646 }
647
648 @Override
Sunny Goyal95899162019-03-27 16:03:06 -0700649 public void onAdd(WorkspaceItemInfo item, int rank) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800650 boolean wasDotted = mDotInfo.hasDot();
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800651 mDotInfo.addDotInfo(mActivity.getDotInfoForItem(item));
Tony Wickhamf34bee82018-12-03 18:11:39 -0800652 boolean isDotted = mDotInfo.hasDot();
653 updateDotScale(wasDotted, isDotted);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700654 invalidate();
655 requestLayout();
656 }
657
Tony Wickham11ba5072017-02-02 12:42:50 -0800658 @Override
Sunny Goyal95899162019-03-27 16:03:06 -0700659 public void onRemove(WorkspaceItemInfo item) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800660 boolean wasDotted = mDotInfo.hasDot();
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800661 mDotInfo.subtractDotInfo(mActivity.getDotInfoForItem(item));
Tony Wickhamf34bee82018-12-03 18:11:39 -0800662 boolean isDotted = mDotInfo.hasDot();
663 updateDotScale(wasDotted, isDotted);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700664 invalidate();
665 requestLayout();
666 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700667
668 public void onTitleChanged(CharSequence title) {
Winson Chung82b016c2015-05-08 17:00:10 -0700669 mFolderName.setText(title);
Sunny Goyalf4f89ef2015-09-02 15:06:12 -0700670 setContentDescription(getContext().getString(R.string.folder_name_format, title));
Adam Cohen76fc0852011-06-17 13:26:23 -0700671 }
Winson Chung88f33452012-02-23 15:23:44 -0800672
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 Goyal17feee82020-03-24 13:55:15 -0700677 super.onTouchEvent(event);
678 mLongPressHelper.onTouchEvent(event);
679 // Keep receiving the rest of the events
680 return true;
Winson Chung88f33452012-02-23 15:23:44 -0800681 }
682
683 @Override
684 public void cancelLongPress() {
685 super.cancelLongPress();
Winson Chung88f33452012-02-23 15:23:44 -0800686 mLongPressHelper.cancelLongPress();
687 }
Adam Cohenf9c184a2016-01-15 16:47:43 -0800688
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -0700689 public void removeListeners() {
690 mInfo.removeListener(this);
691 mInfo.removeListener(mFolder);
692 }
693
Jon Mirandaf79e54b2017-03-31 13:48:39 -0700694 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 Goyal740ac7f2016-09-28 16:47:32 -0700703 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 Mirandaf79e54b2017-03-31 13:48:39 -0700710 }
711
Jon Miranda27bdbca2017-07-06 16:31:56 -0700712 public void onFolderClose(int currentPage) {
713 mPreviewItemManager.onFolderClose(currentPage);
714 }
Adam Cohend9162062020-03-24 16:35:35 -0700715
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700716 private void updateTranslation() {
717 super.setTranslationX(mTranslationForReorderBounce.x + mTranslationForReorderPreview.x);
718 super.setTranslationY(mTranslationForReorderBounce.y + mTranslationForReorderPreview.y);
Adam Cohend9162062020-03-24 16:35:35 -0700719 }
720
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700721 public void setReorderBounceOffset(float x, float y) {
722 mTranslationForReorderBounce.set(x, y);
723 updateTranslation();
Adam Cohend9162062020-03-24 16:35:35 -0700724 }
725
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700726 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 Cohend9162062020-03-24 16:35:35 -0700743 super.setScaleX(scale);
744 super.setScaleY(scale);
745 }
746
Adam Cohen1d13c0b2020-04-21 16:29:12 -0700747 public float getReorderBounceScale() {
748 return mScaleForReorderBounce;
Adam Cohend9162062020-03-24 16:35:35 -0700749 }
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 Project31dd5032009-03-03 19:32:27 -0800764}