blob: 6a47b98af932c91eecde0f35b97ba7df1a2c5a1a [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
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -070019import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW;
20import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION;
21
Adam Cohen2801caf2011-05-13 20:57:39 -070022import android.animation.Animator;
Tony4043b052018-08-17 13:47:39 -070023import android.animation.AnimatorListenerAdapter;
Sunny Goyal740ac7f2016-09-28 16:47:32 -070024import android.animation.ObjectAnimator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.content.Context;
Adam Cohena9cf38f2011-05-02 15:36:58 -070026import android.graphics.Canvas;
Adam Cohen3e8f8112011-07-02 18:03:00 -070027import android.graphics.Rect;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.graphics.drawable.Drawable;
29import android.util.AttributeSet;
Tony Wickham1e618492017-02-02 12:57:18 -080030import android.util.Property;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.view.LayoutInflater;
Winson Chung88f33452012-02-23 15:23:44 -080032import android.view.MotionEvent;
Adam Cohen7c693212011-05-18 15:26:57 -070033import android.view.View;
Jason Monk02dd7ae2014-04-15 15:23:31 -040034import android.view.ViewConfiguration;
Tony4043b052018-08-17 13:47:39 -070035import android.view.ViewDebug;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.view.ViewGroup;
Winson Chung6e1c0d32013-10-25 15:24:24 -070037import android.widget.FrameLayout;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038
Tony Wickhame1cb93f2019-05-03 11:27:32 -070039import androidx.annotation.NonNull;
40
Sunny Goyal26119432016-02-18 22:09:23 +000041import com.android.launcher3.Alarm;
42import com.android.launcher3.AppInfo;
43import com.android.launcher3.BubbleTextView;
44import com.android.launcher3.CellLayout;
45import com.android.launcher3.CheckLongPressHelper;
46import com.android.launcher3.DeviceProfile;
Daniel Sandler325dc232013-06-05 22:57:57 -040047import com.android.launcher3.DropTarget.DragObject;
Sunny Goyal26119432016-02-18 22:09:23 +000048import com.android.launcher3.FolderInfo;
Daniel Sandler325dc232013-06-05 22:57:57 -040049import com.android.launcher3.FolderInfo.FolderListener;
Sunny Goyal26119432016-02-18 22:09:23 +000050import com.android.launcher3.ItemInfo;
51import com.android.launcher3.Launcher;
Sunny Goyal26119432016-02-18 22:09:23 +000052import com.android.launcher3.LauncherSettings;
53import com.android.launcher3.OnAlarmListener;
Sunny Goyal26119432016-02-18 22:09:23 +000054import com.android.launcher3.R;
Sunny Goyal26119432016-02-18 22:09:23 +000055import com.android.launcher3.SimpleOnStylusPressListener;
56import com.android.launcher3.StylusEventHelper;
57import com.android.launcher3.Utilities;
58import com.android.launcher3.Workspace;
Tony Wickhame1cb93f2019-05-03 11:27:32 -070059import com.android.launcher3.WorkspaceItemInfo;
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -070060import com.android.launcher3.anim.Interpolators;
Hyunyoung Song4c746202019-10-10 23:11:12 -070061import com.android.launcher3.config.FeatureFlags;
Tony Wickhamf34bee82018-12-03 18:11:39 -080062import com.android.launcher3.dot.FolderDotInfo;
Jon Miranda4f593812017-08-30 11:59:30 -070063import com.android.launcher3.dragndrop.BaseItemDragListener;
Vadim Tryshevfedca432015-08-19 17:55:02 -070064import com.android.launcher3.dragndrop.DragLayer;
65import com.android.launcher3.dragndrop.DragView;
Tony Wickham8912b042018-11-29 15:28:53 -080066import com.android.launcher3.icons.DotRenderer;
Sunny Goyal8a2a63b2018-03-06 22:15:18 -080067import com.android.launcher3.touch.ItemClickHandler;
Hyunyoung Song4c746202019-10-10 23:11:12 -070068import com.android.launcher3.util.Executors;
Adam Cohen091440a2015-03-18 14:16:05 -070069import com.android.launcher3.util.Thunk;
Tracy Zhou4d7b2442019-12-09 13:42:57 -080070import com.android.launcher3.views.ActivityContext;
Jon Miranda9b78e192019-08-30 18:42:01 -070071import com.android.launcher3.views.IconLabelDotView;
Jon Mirandac476d6e2017-05-04 16:30:01 -070072import com.android.launcher3.widget.PendingAddShortcutInfo;
Romain Guyedcce092010-03-04 13:03:17 -080073
Adam Cohenc0dcf592011-06-01 15:30:43 -070074import java.util.ArrayList;
Jon Miranda12b616c2017-02-06 15:45:53 -080075import java.util.List;
Sunny Goyalac6f69f2019-08-16 11:59:55 -070076import java.util.function.Predicate;
Adam Cohenc0dcf592011-06-01 15:30:43 -070077
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078/**
Adam Cohenf9c184a2016-01-15 16:47:43 -080079 * An icon that can appear on in the workspace representing an {@link Folder}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080 */
Jon Miranda9b78e192019-08-30 18:42:01 -070081public class FolderIcon extends FrameLayout implements FolderListener, IconLabelDotView {
Sunny Goyald0ae4922018-10-11 10:37:53 -070082
Tracy Zhou4d7b2442019-12-09 13:42:57 -080083 @Thunk ActivityContext mActivity;
Adam Cohen091440a2015-03-18 14:16:05 -070084 @Thunk Folder mFolder;
Adam Cohenfb91f302012-06-11 15:45:18 -070085 private FolderInfo mInfo;
Adam Cohena9cf38f2011-05-02 15:36:58 -070086
Winson Chung88f33452012-02-23 15:23:44 -080087 private CheckLongPressHelper mLongPressHelper;
Mady Melloref044dd2015-06-02 15:35:07 -070088 private StylusEventHelper mStylusEventHelper;
Winson Chung88f33452012-02-23 15:23:44 -080089
Jon Miranda6c5d1022017-07-06 09:55:50 -070090 static final int DROP_IN_ANIMATION_DURATION = 400;
Adam Cohenbadf71e2011-05-26 19:08:29 -070091
Jorim Jaggi55bd9722014-01-16 15:30:42 -080092 // Flag whether the folder should open itself when an item is dragged over is enabled.
93 public static final boolean SPRING_LOADING_ENABLED = true;
94
Jorim Jaggi55bd9722014-01-16 15:30:42 -080095 // Delay when drag enters until the folder opens, in miliseconds.
96 private static final int ON_OPEN_DELAY = 800;
97
Adam Cohenefca0272016-02-24 19:19:06 -080098 @Thunk BubbleTextView mFolderName;
Adam Cohen2801caf2011-05-13 20:57:39 -070099
Adam Cohenefca0272016-02-24 19:19:06 -0800100 PreviewBackground mBackground = new PreviewBackground();
Jon Mirandae4a252a2017-06-18 17:43:16 -0700101 private boolean mBackgroundIsVisible = true;
Adam Cohenf9c184a2016-01-15 16:47:43 -0800102
Sunny Goyal11a50742019-08-07 09:24:26 -0700103 FolderGridOrganizer mPreviewVerifier;
Sunny Goyaladd3d832017-09-08 11:59:05 -0700104 ClippedFolderIconLayoutRule mPreviewLayoutRule;
Jon Miranda6c5d1022017-07-06 09:55:50 -0700105 private PreviewItemManager mPreviewItemManager;
106 private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0);
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700107 private List<WorkspaceItemInfo> mCurrentPreviewItems = new ArrayList<>();
Adam Cohenf9c184a2016-01-15 16:47:43 -0800108
Adam Cohend0445262011-07-04 23:53:22 -0700109 boolean mAnimating = false;
Adam Cohenfb91f302012-06-11 15:45:18 -0700110
Jason Monk02dd7ae2014-04-15 15:23:31 -0400111 private float mSlop;
112
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
Tony Wickhamf34bee82018-12-03 18:11:39 -0800124 private static final Property<FolderIcon, Float> DOT_SCALE_PROPERTY
125 = new Property<FolderIcon, Float>(Float.TYPE, "dotScale") {
Tony Wickham1e618492017-02-02 12:57:18 -0800126 @Override
127 public Float get(FolderIcon folderIcon) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800128 return folderIcon.mDotScale;
Tony Wickham1e618492017-02-02 12:57:18 -0800129 }
130
131 @Override
132 public void set(FolderIcon folderIcon, Float value) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800133 folderIcon.mDotScale = value;
Tony Wickham1e618492017-02-02 12:57:18 -0800134 folderIcon.invalidate();
135 }
136 };
Tony Wickham11ba5072017-02-02 12:42:50 -0800137
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138 public FolderIcon(Context context, AttributeSet attrs) {
139 super(context, attrs);
Winson Chung88f33452012-02-23 15:23:44 -0800140 init();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 }
142
143 public FolderIcon(Context context) {
144 super(context);
Winson Chung88f33452012-02-23 15:23:44 -0800145 init();
146 }
147
148 private void init() {
149 mLongPressHelper = new CheckLongPressHelper(this);
Mady Mellorbb835202015-07-15 16:34:34 -0700150 mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
Sunny Goyaladd3d832017-09-08 11:59:05 -0700151 mPreviewLayoutRule = new ClippedFolderIconLayoutRule();
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700152 mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
Jon Miranda6c5d1022017-07-06 09:55:50 -0700153 mPreviewItemManager = new PreviewItemManager(this);
Tony Wickham8912b042018-11-29 15:28:53 -0800154 mDotParams = new DotRenderer.DrawParams();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700155 }
156
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800157 public static FolderIcon inflateFolderAndIcon(int resId, Launcher launcher, ViewGroup group,
158 FolderInfo folderInfo) {
159 Folder folder = Folder.fromXml(launcher);
160 folder.setDragController(launcher.getDragController());
161
162 FolderIcon icon = inflateIcon(resId, launcher, group, folderInfo);
163 folder.setFolderIcon(icon);
164 folder.bind(folderInfo);
165 icon.setFolder(folder);
166
167 icon.setOnFocusChangeListener(launcher.getFocusHandler());
168 return icon;
169 }
170
171 public static FolderIcon inflateIcon(int resId, ActivityContext activity, ViewGroup group,
Sunny Goyal1cd01b02016-11-09 10:43:58 -0800172 FolderInfo folderInfo) {
Michael Jurka3a9fced2012-04-13 14:44:29 -0700173 @SuppressWarnings("all") // suppress dead code warning
174 final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION;
175 if (error) {
Adam Cohend0445262011-07-04 23:53:22 -0700176 throw new IllegalStateException("DROP_IN_ANIMATION_DURATION must be greater than " +
177 "INITIAL_ITEM_ANIMATION_DURATION, as sequencing of adding first two items " +
178 "is dependent on this");
179 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700180
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800181 DeviceProfile grid = activity.getWallpaperDeviceProfile();
Sunny Goyal9b29ca52017-02-17 10:39:44 -0800182 FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext())
183 .inflate(resId, group, false);
Adam Cohenefca0272016-02-24 19:19:06 -0800184
Winson Chung5f8afe62013-08-12 16:19:28 -0700185 icon.setClipToPadding(false);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800186 icon.mFolderName = icon.findViewById(R.id.folder_icon_name);
Adam Cohen76fc0852011-06-17 13:26:23 -0700187 icon.mFolderName.setText(folderInfo.title);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700188 icon.mFolderName.setCompoundDrawablePadding(0);
189 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) icon.mFolderName.getLayoutParams();
190 lp.topMargin = grid.iconSizePx + grid.iconDrawablePaddingPx;
191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 icon.setTag(folderInfo);
Sunny Goyal8a2a63b2018-03-06 22:15:18 -0800193 icon.setOnClickListener(ItemClickHandler.INSTANCE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194 icon.mInfo = folderInfo;
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800195 icon.mActivity = activity;
Samuel Fufac96fa242019-09-26 23:06:32 -0700196 icon.mDotRenderer = grid.mDotRendererWorkSpace;
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800197
198 icon.setContentDescription(
199 group.getContext().getString(R.string.folder_name_format, folderInfo.title));
Tony Wickhama538d2b2020-01-06 18:08:05 -0800200
201 // Keep the notification dot up to date with the sum of all the content's dots.
202 FolderDotInfo folderDotInfo = new FolderDotInfo();
203 for (WorkspaceItemInfo si : folderInfo.contents) {
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800204 folderDotInfo.addDotInfo(activity.getDotInfoForItem(si));
Tony Wickhama538d2b2020-01-06 18:08:05 -0800205 }
206 icon.setDotInfo(folderDotInfo);
207
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800208 icon.setAccessibilityDelegate(activity.getAccessibilityDelegate());
209
210 icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile().inv);
211 icon.mPreviewVerifier.setFolderInfo(folderInfo);
212 icon.updatePreviewItems(false);
Sunny Goyale48644a2016-05-16 16:16:14 -0700213
Sunny Goyal90cb3e52016-05-17 21:25:48 +0000214 folderInfo.addListener(icon);
215
Adam Cohen19072da2011-05-31 14:30:45 -0700216 return icon;
217 }
218
Jon Miranda6f455b52019-03-27 08:27:16 -0700219 public void animateBgShadowAndStroke() {
220 mBackground.fadeInBackgroundShadow();
221 mBackground.animateBackgroundStroke();
222 }
223
224 public BubbleTextView getFolderName() {
225 return mFolderName;
226 }
227
Jon Miranda69b35e02019-03-04 20:16:18 -0800228 public void getPreviewBounds(Rect outBounds) {
Tony5cb5e402019-03-28 12:09:58 -0500229 mPreviewItemManager.recomputePreviewDrawingParams();
Jon Miranda69b35e02019-03-04 20:16:18 -0800230 mBackground.getBounds(outBounds);
231 }
232
Jon Mirandaae975a62019-05-20 11:10:25 -0700233 public float getBackgroundStrokeWidth() {
234 return mBackground.getStrokeWidth();
235 }
236
Anjali Koppalf05545f2014-03-10 19:18:43 -0700237 public Folder getFolder() {
Adam Cohenfb91f302012-06-11 15:45:18 -0700238 return mFolder;
239 }
240
Adam Cohen4f8071b2016-02-13 16:06:05 -0800241 private void setFolder(Folder folder) {
242 mFolder = folder;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800243 }
244
Adam Cohen073a46f2011-05-17 16:28:09 -0700245 private boolean willAcceptItem(ItemInfo item) {
246 final int itemType = item.itemType;
247 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700248 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT ||
249 itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) &&
Sunny Goyal6bb51f42018-01-04 10:54:48 -0800250 item != mInfo && !mFolder.isOpen());
Adam Cohen073a46f2011-05-17 16:28:09 -0700251 }
252
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700253 public boolean acceptDrop(ItemInfo dragInfo) {
Jon Mirandacb739202017-06-23 18:40:31 -0700254 return !mFolder.isDestroyed() && willAcceptItem(dragInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 }
256
Sunny Goyal95899162019-03-27 16:03:06 -0700257 public void addItem(WorkspaceItemInfo item) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700258 mInfo.add(item, true);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700259 }
260
Sunny Goyal95899162019-03-27 16:03:06 -0700261 public void removeItem(WorkspaceItemInfo item, boolean animate) {
Jon Miranda4dd024b2017-07-13 17:54:54 -0700262 mInfo.remove(item, animate);
Adam Cohendf035382011-04-11 17:22:04 -0700263 }
264
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700265 public void onDragEnter(ItemInfo dragInfo) {
266 if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return;
Adam Cohen69ce2e52011-07-03 19:25:21 -0700267 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
Adam Cohenefca0272016-02-24 19:19:06 -0800268 CellLayout cl = (CellLayout) getParent().getParent();
269
270 mBackground.animateToAccept(cl, lp.cellX, lp.cellY);
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800271 mOpenAlarm.setOnAlarmListener(mOnOpenListener);
Adam Cohendedfca22014-05-19 15:10:39 -0700272 if (SPRING_LOADING_ENABLED &&
Jon Mirandac476d6e2017-05-04 16:30:01 -0700273 ((dragInfo instanceof AppInfo)
Sunny Goyal95899162019-03-27 16:03:06 -0700274 || (dragInfo instanceof WorkspaceItemInfo)
Jon Mirandac476d6e2017-05-04 16:30:01 -0700275 || (dragInfo instanceof PendingAddShortcutInfo))) {
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800276 mOpenAlarm.setAlarm(ON_OPEN_DELAY);
277 }
Adam Cohen073a46f2011-05-17 16:28:09 -0700278 }
279
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800280 OnAlarmListener mOnOpenListener = new OnAlarmListener() {
281 public void onAlarm(Alarm alarm) {
Sunny Goyale393d3a2016-09-09 12:42:10 -0700282 mFolder.beginExternalDrag();
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800283 }
284 };
285
Jon Miranda6c5d1022017-07-06 09:55:50 -0700286 public Drawable prepareCreateAnimation(final View destView) {
287 return mPreviewItemManager.prepareCreateAnimation(destView);
Winson8f288aa2016-07-25 16:49:15 -0700288 }
289
Sunny Goyal95899162019-03-27 16:03:06 -0700290 public void performCreateAnimation(final WorkspaceItemInfo destInfo, final View destView,
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800291 final WorkspaceItemInfo srcInfo, final DragObject d, Rect dstRect,
Sunny Goyal1797af42017-10-06 13:29:57 -0700292 float scaleRelativeToDragLayer) {
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800293 final DragView srcView = d.dragView;
Jon Miranda6c5d1022017-07-06 09:55:50 -0700294 prepareCreateAnimation(destView);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800295 addItem(destInfo);
Adam Cohend0445262011-07-04 23:53:22 -0700296 // This will animate the first item from it's position as an icon into its
297 // position as the first item in the preview
Jon Miranda6c5d1022017-07-06 09:55:50 -0700298 mPreviewItemManager.createFirstItemAnimation(false /* reverse */, null)
299 .start();
Adam Cohenfb91f302012-06-11 15:45:18 -0700300
301 // This will animate the dragView (srcView) into the new folder
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800302 onDrop(srcInfo, d, dstRect, scaleRelativeToDragLayer, 1,
Jon Miranda6d3586c2017-09-08 12:39:10 -0700303 false /* itemReturnedOnFailedDrop */);
Adam Cohenfb91f302012-06-11 15:45:18 -0700304 }
305
Jon Miranda6c5d1022017-07-06 09:55:50 -0700306 public void performDestroyAnimation(Runnable onCompleteRunnable) {
307 // This will animate the final item in the preview to be full size.
308 mPreviewItemManager.createFirstItemAnimation(true /* reverse */, onCompleteRunnable)
309 .start();
Adam Cohend0445262011-07-04 23:53:22 -0700310 }
311
Adam Cohenc6cc61d2012-04-04 12:47:08 -0700312 public void onDragExit() {
Adam Cohenefca0272016-02-24 19:19:06 -0800313 mBackground.animateToRest();
Jorim Jaggi55bd9722014-01-16 15:30:42 -0800314 mOpenAlarm.cancelAlarm();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800315 }
Patrick Dubroy440c3602010-07-13 17:50:32 -0700316
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800317 private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect,
Sunny Goyal11a50742019-08-07 09:24:26 -0700318 float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) {
Adam Cohend0445262011-07-04 23:53:22 -0700319 item.cellX = -1;
320 item.cellY = -1;
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800321 DragView animateView = d.dragView;
Adam Cohen558baaf2011-08-15 15:22:57 -0700322 // Typically, the animateView corresponds to the DragView; however, if this is being done
323 // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we
324 // will not have a view to animate
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800325 if (animateView != null && mActivity instanceof Launcher) {
326 final Launcher launcher = (Launcher) mActivity;
327 DragLayer dragLayer = launcher.getDragLayer();
Adam Cohen558baaf2011-08-15 15:22:57 -0700328 Rect from = new Rect();
329 dragLayer.getViewRectRelativeToSelf(animateView, from);
330 Rect to = finalRect;
331 if (to == null) {
332 to = new Rect();
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800333 Workspace workspace = launcher.getWorkspace();
Adam Cohen558baaf2011-08-15 15:22:57 -0700334 // Set cellLayout and this to it's final state to compute final animation locations
Sunny Goyalaeb16432017-10-16 11:46:41 -0700335 workspace.setFinalTransitionTransform();
Adam Cohen558baaf2011-08-15 15:22:57 -0700336 float scaleX = getScaleX();
337 float scaleY = getScaleY();
338 setScaleX(1.0f);
339 setScaleY(1.0f);
340 scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
341 // Finished computing final animation locations, restore current state
342 setScaleX(scaleX);
343 setScaleY(scaleY);
Sunny Goyalaeb16432017-10-16 11:46:41 -0700344 workspace.resetTransitionTransform();
Adam Cohend0445262011-07-04 23:53:22 -0700345 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700346
Jon Miranda6d3586c2017-09-08 12:39:10 -0700347 int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700348 boolean itemAdded = false;
Jon Miranda6d3586c2017-09-08 12:39:10 -0700349 if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) {
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700350 List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems);
Sunny Goyal11a50742019-08-07 09:24:26 -0700351 mInfo.add(item, index, false);
Jon Miranda6d3586c2017-09-08 12:39:10 -0700352 mCurrentPreviewItems.clear();
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700353 mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
Jon Miranda4dd024b2017-07-13 17:54:54 -0700354
Jon Miranda6d3586c2017-09-08 12:39:10 -0700355 if (!oldPreviewItems.equals(mCurrentPreviewItems)) {
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700356 int newIndex = mCurrentPreviewItems.indexOf(item);
357 if (newIndex >= 0) {
358 // If the item dropped is going to be in the preview, we update the
359 // index here to reflect its position in the preview.
360 index = newIndex;
Jon Miranda4dd024b2017-07-13 17:54:54 -0700361 }
Jon Miranda6d3586c2017-09-08 12:39:10 -0700362
363 mPreviewItemManager.hidePreviewItem(index, true);
364 mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700365 itemAdded = true;
366 } else {
367 removeItem(item, false);
368 }
369 }
370
371 if (!itemAdded) {
Sunny Goyal11a50742019-08-07 09:24:26 -0700372 mInfo.add(item, index, true);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700373 }
374
Adam Cohen558baaf2011-08-15 15:22:57 -0700375 int[] center = new int[2];
Jon Miranda6d3586c2017-09-08 12:39:10 -0700376 float scale = getLocalCenterForIndex(index, numItemsInPreview, center);
Sunny Goyal11a50742019-08-07 09:24:26 -0700377 center[0] = Math.round(scaleRelativeToDragLayer * center[0]);
378 center[1] = Math.round(scaleRelativeToDragLayer * center[1]);
Adam Cohen558baaf2011-08-15 15:22:57 -0700379
380 to.offset(center[0] - animateView.getMeasuredWidth() / 2,
Jon Miranda4dd024b2017-07-13 17:54:54 -0700381 center[1] - animateView.getMeasuredHeight() / 2);
Adam Cohen558baaf2011-08-15 15:22:57 -0700382
Sunny Goyaladd3d832017-09-08 11:59:05 -0700383 float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;
Adam Cohen558baaf2011-08-15 15:22:57 -0700384
Adam Cohened66b2b2012-01-23 17:28:51 -0800385 float finalScale = scale * scaleRelativeToDragLayer;
Adam Cohen558baaf2011-08-15 15:22:57 -0700386 dragLayer.animateView(animateView, from, to, finalAlpha,
Adam Cohened66b2b2012-01-23 17:28:51 -0800387 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION,
Sunny Goyal5bc6b6f2017-10-26 15:36:10 -0700388 Interpolators.DEACCEL_2, Interpolators.ACCEL_2,
Sunny Goyal1797af42017-10-06 13:29:57 -0700389 null, DragLayer.ANIMATION_END_DISAPPEAR, null);
Jon Miranda4dd024b2017-07-13 17:54:54 -0700390
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700391 mFolder.hideItem(item);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800392
Jon Miranda4dd024b2017-07-13 17:54:54 -0700393 if (!itemAdded) mPreviewItemManager.hidePreviewItem(index, true);
394 final int finalIndex = index;
Hyunyoung Song4c746202019-10-10 23:11:12 -0700395
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800396 String[] suggestedNameOut = new String[FolderNameProvider.SUGGEST_MAX];
Hyunyoung Song4c746202019-10-10 23:11:12 -0700397 if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800398 Executors.UI_HELPER_EXECUTOR.post(() -> {
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800399 d.folderNameProvider.getSuggestedFolderName(
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800400 getContext(), mInfo.contents, suggestedNameOut);
401 showFinalView(finalIndex, item, suggestedNameOut);
402 });
403 } else {
404 showFinalView(finalIndex, item, suggestedNameOut);
Hyunyoung Song4c746202019-10-10 23:11:12 -0700405 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700406 } else {
407 addItem(item);
408 }
Adam Cohend0445262011-07-04 23:53:22 -0700409 }
410
Hyunyoung Song5fcd8f92019-11-06 21:34:36 -0800411 private void showFinalView(int finalIndex, final WorkspaceItemInfo item,
412 String[] suggestedNameOut) {
413 postDelayed(() -> {
414 mPreviewItemManager.hidePreviewItem(finalIndex, false);
415 mFolder.showItem(item);
416 invalidate();
417 mFolder.showSuggestedTitle(suggestedNameOut);
418 }, DROP_IN_ANIMATION_DURATION);
419 }
420
Jon Miranda6d3586c2017-09-08 12:39:10 -0700421 public void onDrop(DragObject d, boolean itemReturnedOnFailedDrop) {
Sunny Goyal95899162019-03-27 16:03:06 -0700422 WorkspaceItemInfo item;
Michael Jurkaeadbfc52013-09-04 00:45:37 +0200423 if (d.dragInfo instanceof AppInfo) {
Adam Cohenc0dcf592011-06-01 15:30:43 -0700424 // Came from all apps -- make a copy
Sunny Goyal95899162019-03-27 16:03:06 -0700425 item = ((AppInfo) d.dragInfo).makeWorkspaceItem();
Jon Miranda4f593812017-08-30 11:59:30 -0700426 } else if (d.dragSource instanceof BaseItemDragListener){
427 // Came from a different window -- make a copy
Sunny Goyal95899162019-03-27 16:03:06 -0700428 item = new WorkspaceItemInfo((WorkspaceItemInfo) d.dragInfo);
Adam Cohenc0dcf592011-06-01 15:30:43 -0700429 } else {
Sunny Goyal95899162019-03-27 16:03:06 -0700430 item = (WorkspaceItemInfo) d.dragInfo;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700431 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700432 mFolder.notifyDrop();
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800433 onDrop(item, d, null, 1.0f,
Sunny Goyal11a50742019-08-07 09:24:26 -0700434 itemReturnedOnFailedDrop ? item.rank : mInfo.contents.size(),
Hyunyoung Song1ae42422020-01-26 23:25:14 -0800435 itemReturnedOnFailedDrop
436 );
Adam Cohenc0dcf592011-06-01 15:30:43 -0700437 }
438
Tony Wickhamf34bee82018-12-03 18:11:39 -0800439 public void setDotInfo(FolderDotInfo dotInfo) {
440 updateDotScale(mDotInfo.hasDot(), dotInfo.hasDot());
441 mDotInfo = dotInfo;
Tony Wickham1e618492017-02-02 12:57:18 -0800442 }
443
Sunny Goyaladd3d832017-09-08 11:59:05 -0700444 public ClippedFolderIconLayoutRule getLayoutRule() {
Jon Miranda47170112017-03-03 14:57:14 -0800445 return mPreviewLayoutRule;
446 }
447
Jon Miranda9b78e192019-08-30 18:42:01 -0700448 @Override
449 public void setForceHideDot(boolean forceHideDot) {
450 if (mForceHideDot == forceHideDot) {
451 return;
452 }
453 mForceHideDot = forceHideDot;
454
455 if (forceHideDot) {
456 invalidate();
457 } else if (hasDot()) {
458 animateDotScale(0, 1);
459 }
460 }
461
Tony Wickham1e618492017-02-02 12:57:18 -0800462 /**
Tony Wickhamf34bee82018-12-03 18:11:39 -0800463 * Sets mDotScale to 1 or 0, animating if wasDotted or isDotted is false
464 * (the dot is being added or removed).
Tony Wickham1e618492017-02-02 12:57:18 -0800465 */
Tony Wickhamf34bee82018-12-03 18:11:39 -0800466 private void updateDotScale(boolean wasDotted, boolean isDotted) {
467 float newDotScale = isDotted ? 1f : 0f;
468 // Animate when a dot is first added or when it is removed.
469 if ((wasDotted ^ isDotted) && isShown()) {
470 animateDotScale(newDotScale);
Tony Wickham1e618492017-02-02 12:57:18 -0800471 } else {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800472 cancelDotScaleAnim();
473 mDotScale = newDotScale;
Tony Wickham1e618492017-02-02 12:57:18 -0800474 invalidate();
475 }
Tony Wickham11ba5072017-02-02 12:42:50 -0800476 }
477
Tony Wickhamf34bee82018-12-03 18:11:39 -0800478 private void cancelDotScaleAnim() {
479 if (mDotScaleAnim != null) {
480 mDotScaleAnim.cancel();
Tony4043b052018-08-17 13:47:39 -0700481 }
482 }
483
Tony Wickhamf34bee82018-12-03 18:11:39 -0800484 public void animateDotScale(float... dotScales) {
485 cancelDotScaleAnim();
486 mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales);
487 mDotScaleAnim.addListener(new AnimatorListenerAdapter() {
Tony4043b052018-08-17 13:47:39 -0700488 @Override
489 public void onAnimationEnd(Animator animation) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800490 mDotScaleAnim = null;
Tony4043b052018-08-17 13:47:39 -0700491 }
492 });
Tony Wickhamf34bee82018-12-03 18:11:39 -0800493 mDotScaleAnim.start();
Tony814dead2017-06-15 18:30:41 -0700494 }
495
Tony Wickhamf34bee82018-12-03 18:11:39 -0800496 public boolean hasDot() {
497 return mDotInfo != null && mDotInfo.hasDot();
Tony814dead2017-06-15 18:30:41 -0700498 }
499
Adam Cohen119e8982016-02-05 14:47:50 -0800500 private float getLocalCenterForIndex(int index, int curNumItems, int[] center) {
Jon Miranda6c5d1022017-07-06 09:55:50 -0700501 mTmpParams = mPreviewItemManager.computePreviewItemDrawingParams(
Sunny Goyaladd3d832017-09-08 11:59:05 -0700502 Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index), curNumItems, mTmpParams);
Adam Cohend0445262011-07-04 23:53:22 -0700503
Adam Cohenefca0272016-02-24 19:19:06 -0800504 mTmpParams.transX += mBackground.basePreviewOffsetX;
505 mTmpParams.transY += mBackground.basePreviewOffsetY;
Jon Miranda6c5d1022017-07-06 09:55:50 -0700506
507 float intrinsicIconSize = mPreviewItemManager.getIntrinsicIconSize();
508 float offsetX = mTmpParams.transX + (mTmpParams.scale * intrinsicIconSize) / 2;
509 float offsetY = mTmpParams.transY + (mTmpParams.scale * intrinsicIconSize) / 2;
Adam Cohend0445262011-07-04 23:53:22 -0700510
Jon Mirandacb739202017-06-23 18:40:31 -0700511 center[0] = Math.round(offsetX);
512 center[1] = Math.round(offsetY);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800513 return mTmpParams.scale;
Adam Cohend0445262011-07-04 23:53:22 -0700514 }
515
Adam Cohenefca0272016-02-24 19:19:06 -0800516 public void setFolderBackground(PreviewBackground bg) {
517 mBackground = bg;
Adam Cohenf172b742016-03-30 19:28:34 -0700518 mBackground.setInvalidateDelegate(this);
Adam Cohenefca0272016-02-24 19:19:06 -0800519 }
520
Jon Miranda9b78e192019-08-30 18:42:01 -0700521 @Override
522 public void setIconVisible(boolean visible) {
Jon Mirandae4a252a2017-06-18 17:43:16 -0700523 mBackgroundIsVisible = visible;
524 invalidate();
525 }
526
Sunny Goyale29897f2017-07-20 10:09:42 -0700527 public PreviewBackground getFolderBackground() {
528 return mBackground;
529 }
530
531 public PreviewItemManager getPreviewItemManager() {
532 return mPreviewItemManager;
533 }
534
Adam Cohena9cf38f2011-05-02 15:36:58 -0700535 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700536 protected void dispatchDraw(Canvas canvas) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700537 super.dispatchDraw(canvas);
538
Jon Mirandae4a252a2017-06-18 17:43:16 -0700539 if (!mBackgroundIsVisible) return;
540
Jon Miranda0c172152017-07-24 11:39:38 -0700541 mPreviewItemManager.recomputePreviewDrawingParams();
542
Adam Cohenefca0272016-02-24 19:19:06 -0800543 if (!mBackground.drawingDelegated()) {
Sunny Goyal19b93b72017-02-19 20:21:37 -0800544 mBackground.drawBackground(canvas);
Adam Cohen119e8982016-02-05 14:47:50 -0800545 }
546
Sunny Goyal11a50742019-08-07 09:24:26 -0700547 if (mCurrentPreviewItems.isEmpty() && !mAnimating) return;
Adam Cohenefca0272016-02-24 19:19:06 -0800548
Sunny Goyald0ae4922018-10-11 10:37:53 -0700549 final int saveCount = canvas.save();
550 canvas.clipPath(mBackground.getClipPath());
Jon Miranda6c5d1022017-07-06 09:55:50 -0700551 mPreviewItemManager.draw(canvas);
Sunny Goyal19b93b72017-02-19 20:21:37 -0800552 canvas.restoreToCount(saveCount);
Adam Cohenefca0272016-02-24 19:19:06 -0800553
Sunny Goyaladd3d832017-09-08 11:59:05 -0700554 if (!mBackground.drawingDelegated()) {
Sunny Goyal19b93b72017-02-19 20:21:37 -0800555 mBackground.drawBackgroundStroke(canvas);
Adam Cohenefca0272016-02-24 19:19:06 -0800556 }
Tony Wickham11ba5072017-02-02 12:42:50 -0800557
Tony Wickhamf34bee82018-12-03 18:11:39 -0800558 drawDot(canvas);
Sunny Goyale29897f2017-07-20 10:09:42 -0700559 }
560
Tony Wickhamf34bee82018-12-03 18:11:39 -0800561 public void drawDot(Canvas canvas) {
Jon Miranda9b78e192019-08-30 18:42:01 -0700562 if (!mForceHideDot && ((mDotInfo != null && mDotInfo.hasDot()) || mDotScale > 0)) {
Tony Wickham8912b042018-11-29 15:28:53 -0800563 Rect iconBounds = mDotParams.iconBounds;
Sunny Goyalae6e3182019-04-30 12:04:37 -0700564 BubbleTextView.getIconBounds(this, iconBounds,
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800565 mActivity.getWallpaperDeviceProfile().iconSizePx);
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700566 float iconScale = (float) mBackground.previewSize / iconBounds.width();
567 Utilities.scaleRectAboutCenter(iconBounds, iconScale);
Sunny Goyal19b93b72017-02-19 20:21:37 -0800568
Tony Wickhamf34bee82018-12-03 18:11:39 -0800569 // If we are animating to the accepting state, animate the dot out.
570 mDotParams.scale = Math.max(0, mDotScale - mBackground.getScaleProgress());
Tony Wickhamf34bee82018-12-03 18:11:39 -0800571 mDotParams.color = mBackground.getDotColor();
Tony Wickham8912b042018-11-29 15:28:53 -0800572 mDotRenderer.draw(canvas, mDotParams);
Tony Wickham11ba5072017-02-02 12:42:50 -0800573 }
Adam Cohend0445262011-07-04 23:53:22 -0700574 }
575
Adam Cohen099f60d2011-08-23 21:07:26 -0700576 public void setTextVisible(boolean visible) {
577 if (visible) {
578 mFolderName.setVisibility(VISIBLE);
579 } else {
580 mFolderName.setVisibility(INVISIBLE);
581 }
582 }
583
584 public boolean getTextVisible() {
585 return mFolderName.getVisibility() == VISIBLE;
586 }
587
Jon Miranda27bdbca2017-07-06 16:31:56 -0700588 /**
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700589 * Returns the list of items which should be visible in the preview
Jon Miranda27bdbca2017-07-06 16:31:56 -0700590 */
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700591 public List<WorkspaceItemInfo> getPreviewItemsOnPage(int page) {
592 return mPreviewVerifier.setFolderInfo(mInfo).previewItemsForPage(page, mInfo.contents);
Jon Miranda655ec422017-02-07 11:40:22 -0800593 }
594
Sunny Goyal828b11e2017-06-22 09:53:59 -0700595 @Override
596 protected boolean verifyDrawable(@NonNull Drawable who) {
Jon Miranda6c5d1022017-07-06 09:55:50 -0700597 return mPreviewItemManager.verifyDrawable(who) || super.verifyDrawable(who);
Adam Cohen4f8071b2016-02-13 16:06:05 -0800598 }
599
Sunny Goyalc52ba712016-04-05 15:59:05 -0700600 @Override
601 public void onItemsChanged(boolean animate) {
Jon Miranda6d3586c2017-09-08 12:39:10 -0700602 updatePreviewItems(animate);
Adam Cohen76078c42011-06-09 15:06:52 -0700603 invalidate();
604 requestLayout();
605 }
606
Jon Miranda6d3586c2017-09-08 12:39:10 -0700607 private void updatePreviewItems(boolean animate) {
608 mPreviewItemManager.updatePreviewItems(animate);
609 mCurrentPreviewItems.clear();
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700610 mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
Jon Miranda6d3586c2017-09-08 12:39:10 -0700611 }
612
Sunny Goyalac6f69f2019-08-16 11:59:55 -0700613 /**
614 * Updates the preview items which match the provided condition
615 */
616 public void updatePreviewItems(Predicate<WorkspaceItemInfo> itemCheck) {
617 mPreviewItemManager.updatePreviewItems(itemCheck);
Jon Miranda44060942017-02-22 10:17:49 -0800618 }
619
620 @Override
Sunny Goyal95899162019-03-27 16:03:06 -0700621 public void onAdd(WorkspaceItemInfo item, int rank) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800622 boolean wasDotted = mDotInfo.hasDot();
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800623 mDotInfo.addDotInfo(mActivity.getDotInfoForItem(item));
Tony Wickhamf34bee82018-12-03 18:11:39 -0800624 boolean isDotted = mDotInfo.hasDot();
625 updateDotScale(wasDotted, isDotted);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700626 invalidate();
627 requestLayout();
628 }
629
Tony Wickham11ba5072017-02-02 12:42:50 -0800630 @Override
Sunny Goyal95899162019-03-27 16:03:06 -0700631 public void onRemove(WorkspaceItemInfo item) {
Tony Wickhamf34bee82018-12-03 18:11:39 -0800632 boolean wasDotted = mDotInfo.hasDot();
Tracy Zhou4d7b2442019-12-09 13:42:57 -0800633 mDotInfo.subtractDotInfo(mActivity.getDotInfoForItem(item));
Tony Wickhamf34bee82018-12-03 18:11:39 -0800634 boolean isDotted = mDotInfo.hasDot();
635 updateDotScale(wasDotted, isDotted);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700636 invalidate();
637 requestLayout();
638 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700639
640 public void onTitleChanged(CharSequence title) {
Winson Chung82b016c2015-05-08 17:00:10 -0700641 mFolderName.setText(title);
Sunny Goyalf4f89ef2015-09-02 15:06:12 -0700642 setContentDescription(getContext().getString(R.string.folder_name_format, title));
Adam Cohen76fc0852011-06-17 13:26:23 -0700643 }
Winson Chung88f33452012-02-23 15:23:44 -0800644
645 @Override
646 public boolean onTouchEvent(MotionEvent event) {
647 // Call the superclass onTouchEvent first, because sometimes it changes the state to
648 // isPressed() on an ACTION_UP
649 boolean result = super.onTouchEvent(event);
650
Mady Melloref044dd2015-06-02 15:35:07 -0700651 // Check for a stylus button press, if it occurs cancel any long press checks.
Mady Mellorbb835202015-07-15 16:34:34 -0700652 if (mStylusEventHelper.onMotionEvent(event)) {
Mady Melloref044dd2015-06-02 15:35:07 -0700653 mLongPressHelper.cancelLongPress();
654 return true;
655 }
656
Winson Chung88f33452012-02-23 15:23:44 -0800657 switch (event.getAction()) {
658 case MotionEvent.ACTION_DOWN:
659 mLongPressHelper.postCheckForLongPress();
660 break;
661 case MotionEvent.ACTION_CANCEL:
662 case MotionEvent.ACTION_UP:
663 mLongPressHelper.cancelLongPress();
664 break;
Jason Monk02dd7ae2014-04-15 15:23:31 -0400665 case MotionEvent.ACTION_MOVE:
666 if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) {
667 mLongPressHelper.cancelLongPress();
668 }
669 break;
Winson Chung88f33452012-02-23 15:23:44 -0800670 }
671 return result;
672 }
673
674 @Override
675 public void cancelLongPress() {
676 super.cancelLongPress();
Winson Chung88f33452012-02-23 15:23:44 -0800677 mLongPressHelper.cancelLongPress();
678 }
Adam Cohenf9c184a2016-01-15 16:47:43 -0800679
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -0700680 public void removeListeners() {
681 mInfo.removeListener(this);
682 mInfo.removeListener(mFolder);
683 }
684
Jon Mirandaf79e54b2017-03-31 13:48:39 -0700685 public void clearLeaveBehindIfExists() {
686 ((CellLayout.LayoutParams) getLayoutParams()).canReorder = true;
687 if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
688 CellLayout cl = (CellLayout) getParent().getParent();
689 cl.clearFolderLeaveBehind();
690 }
691 }
692
693 public void drawLeaveBehindIfExists() {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700694 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
695 // While the folder is open, the position of the icon cannot change.
696 lp.canReorder = false;
697 if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
698 CellLayout cl = (CellLayout) getParent().getParent();
699 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
700 }
Jon Mirandaf79e54b2017-03-31 13:48:39 -0700701 }
702
Jon Miranda27bdbca2017-07-06 16:31:56 -0700703 public void onFolderClose(int currentPage) {
704 mPreviewItemManager.onFolderClose(currentPage);
705 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706}