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 | |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW; |
| 20 | import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION; |
| 21 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 22 | import android.animation.Animator; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 23 | import android.animation.AnimatorListenerAdapter; |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 24 | import android.animation.ObjectAnimator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 27 | import android.graphics.Rect; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
| 29 | import android.util.AttributeSet; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 30 | import android.util.Property; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 32 | import android.view.MotionEvent; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 33 | import android.view.View; |
Jason Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 34 | import android.view.ViewConfiguration; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 35 | import android.view.ViewDebug; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.view.ViewGroup; |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 37 | import android.widget.FrameLayout; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | |
Tony Wickham | e1cb93f | 2019-05-03 11:27:32 -0700 | [diff] [blame] | 39 | import androidx.annotation.NonNull; |
| 40 | |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 41 | import com.android.launcher3.Alarm; |
| 42 | import com.android.launcher3.AppInfo; |
| 43 | import com.android.launcher3.BubbleTextView; |
| 44 | import com.android.launcher3.CellLayout; |
| 45 | import com.android.launcher3.CheckLongPressHelper; |
| 46 | import com.android.launcher3.DeviceProfile; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 47 | import com.android.launcher3.DropTarget.DragObject; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 48 | import com.android.launcher3.FolderInfo; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 49 | import com.android.launcher3.FolderInfo.FolderListener; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 50 | import com.android.launcher3.ItemInfo; |
| 51 | import com.android.launcher3.Launcher; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 52 | import com.android.launcher3.LauncherSettings; |
| 53 | import com.android.launcher3.OnAlarmListener; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 54 | import com.android.launcher3.R; |
Sunny Goyal | 2611943 | 2016-02-18 22:09:23 +0000 | [diff] [blame] | 55 | import com.android.launcher3.SimpleOnStylusPressListener; |
| 56 | import com.android.launcher3.StylusEventHelper; |
| 57 | import com.android.launcher3.Utilities; |
| 58 | import com.android.launcher3.Workspace; |
Tony Wickham | e1cb93f | 2019-05-03 11:27:32 -0700 | [diff] [blame] | 59 | import com.android.launcher3.WorkspaceItemInfo; |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 60 | import com.android.launcher3.anim.Interpolators; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 61 | import com.android.launcher3.config.FeatureFlags; |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 62 | import com.android.launcher3.dot.FolderDotInfo; |
Jon Miranda | 4f59381 | 2017-08-30 11:59:30 -0700 | [diff] [blame] | 63 | import com.android.launcher3.dragndrop.BaseItemDragListener; |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 64 | import com.android.launcher3.dragndrop.DragLayer; |
| 65 | import com.android.launcher3.dragndrop.DragView; |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 66 | import com.android.launcher3.icons.DotRenderer; |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 67 | import com.android.launcher3.touch.ItemClickHandler; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 68 | import com.android.launcher3.util.Executors; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 69 | import com.android.launcher3.util.Thunk; |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 70 | import com.android.launcher3.views.ActivityContext; |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 71 | import com.android.launcher3.views.IconLabelDotView; |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 72 | import com.android.launcher3.widget.PendingAddShortcutInfo; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 73 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
Jon Miranda | 12b616c | 2017-02-06 15:45:53 -0800 | [diff] [blame] | 75 | import java.util.List; |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 76 | import java.util.function.Predicate; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 77 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | /** |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 79 | * 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] | 80 | */ |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 81 | public class FolderIcon extends FrameLayout implements FolderListener, IconLabelDotView { |
Sunny Goyal | d0ae492 | 2018-10-11 10:37:53 -0700 | [diff] [blame] | 82 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 83 | @Thunk ActivityContext mActivity; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 84 | @Thunk Folder mFolder; |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 85 | private FolderInfo mInfo; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 86 | |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 87 | private CheckLongPressHelper mLongPressHelper; |
Mady Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 88 | private StylusEventHelper mStylusEventHelper; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 89 | |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 90 | static final int DROP_IN_ANIMATION_DURATION = 400; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 91 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 92 | // 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 Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 95 | // Delay when drag enters until the folder opens, in miliseconds. |
| 96 | private static final int ON_OPEN_DELAY = 800; |
| 97 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 98 | @Thunk BubbleTextView mFolderName; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 99 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 100 | PreviewBackground mBackground = new PreviewBackground(); |
Jon Miranda | e4a252a | 2017-06-18 17:43:16 -0700 | [diff] [blame] | 101 | private boolean mBackgroundIsVisible = true; |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 102 | |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 103 | FolderGridOrganizer mPreviewVerifier; |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 104 | ClippedFolderIconLayoutRule mPreviewLayoutRule; |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 105 | private PreviewItemManager mPreviewItemManager; |
| 106 | private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0); |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 107 | private List<WorkspaceItemInfo> mCurrentPreviewItems = new ArrayList<>(); |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 108 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 109 | boolean mAnimating = false; |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 110 | |
Jason Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 111 | private float mSlop; |
| 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 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 124 | private static final Property<FolderIcon, Float> DOT_SCALE_PROPERTY |
| 125 | = new Property<FolderIcon, Float>(Float.TYPE, "dotScale") { |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 126 | @Override |
| 127 | public Float get(FolderIcon folderIcon) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 128 | return folderIcon.mDotScale; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public void set(FolderIcon folderIcon, Float value) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 133 | folderIcon.mDotScale = value; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 134 | folderIcon.invalidate(); |
| 135 | } |
| 136 | }; |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 137 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 138 | public FolderIcon(Context context, AttributeSet attrs) { |
| 139 | super(context, attrs); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 140 | init(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | public FolderIcon(Context context) { |
| 144 | super(context); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 145 | init(); |
| 146 | } |
| 147 | |
| 148 | private void init() { |
| 149 | mLongPressHelper = new CheckLongPressHelper(this); |
Mady Mellor | bb83520 | 2015-07-15 16:34:34 -0700 | [diff] [blame] | 150 | mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this); |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 151 | mPreviewLayoutRule = new ClippedFolderIconLayoutRule(); |
Sunny Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 152 | mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 153 | mPreviewItemManager = new PreviewItemManager(this); |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 154 | mDotParams = new DotRenderer.DrawParams(); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 157 | 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 Goyal | 1cd01b0 | 2016-11-09 10:43:58 -0800 | [diff] [blame] | 172 | FolderInfo folderInfo) { |
Michael Jurka | 3a9fced | 2012-04-13 14:44:29 -0700 | [diff] [blame] | 173 | @SuppressWarnings("all") // suppress dead code warning |
| 174 | final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION; |
| 175 | if (error) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 176 | 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 Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 180 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 181 | DeviceProfile grid = activity.getWallpaperDeviceProfile(); |
Sunny Goyal | 9b29ca5 | 2017-02-17 10:39:44 -0800 | [diff] [blame] | 182 | FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext()) |
| 183 | .inflate(resId, group, false); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 184 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 185 | icon.setClipToPadding(false); |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 186 | icon.mFolderName = icon.findViewById(R.id.folder_icon_name); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 187 | icon.mFolderName.setText(folderInfo.title); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 188 | 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 192 | icon.setTag(folderInfo); |
Sunny Goyal | 8a2a63b | 2018-03-06 22:15:18 -0800 | [diff] [blame] | 193 | icon.setOnClickListener(ItemClickHandler.INSTANCE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 194 | icon.mInfo = folderInfo; |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 195 | icon.mActivity = activity; |
Samuel Fufa | c96fa24 | 2019-09-26 23:06:32 -0700 | [diff] [blame] | 196 | icon.mDotRenderer = grid.mDotRendererWorkSpace; |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 197 | |
| 198 | icon.setContentDescription( |
| 199 | group.getContext().getString(R.string.folder_name_format, folderInfo.title)); |
Tony Wickham | a538d2b | 2020-01-06 18:08:05 -0800 | [diff] [blame] | 200 | |
| 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 Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 204 | folderDotInfo.addDotInfo(activity.getDotInfoForItem(si)); |
Tony Wickham | a538d2b | 2020-01-06 18:08:05 -0800 | [diff] [blame] | 205 | } |
| 206 | icon.setDotInfo(folderDotInfo); |
| 207 | |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 208 | icon.setAccessibilityDelegate(activity.getAccessibilityDelegate()); |
| 209 | |
| 210 | icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile().inv); |
| 211 | icon.mPreviewVerifier.setFolderInfo(folderInfo); |
| 212 | icon.updatePreviewItems(false); |
Sunny Goyal | e48644a | 2016-05-16 16:16:14 -0700 | [diff] [blame] | 213 | |
Sunny Goyal | 90cb3e5 | 2016-05-17 21:25:48 +0000 | [diff] [blame] | 214 | folderInfo.addListener(icon); |
| 215 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 216 | return icon; |
| 217 | } |
| 218 | |
Jon Miranda | 6f455b5 | 2019-03-27 08:27:16 -0700 | [diff] [blame] | 219 | public void animateBgShadowAndStroke() { |
| 220 | mBackground.fadeInBackgroundShadow(); |
| 221 | mBackground.animateBackgroundStroke(); |
| 222 | } |
| 223 | |
| 224 | public BubbleTextView getFolderName() { |
| 225 | return mFolderName; |
| 226 | } |
| 227 | |
Jon Miranda | 69b35e0 | 2019-03-04 20:16:18 -0800 | [diff] [blame] | 228 | public void getPreviewBounds(Rect outBounds) { |
Tony | 5cb5e40 | 2019-03-28 12:09:58 -0500 | [diff] [blame] | 229 | mPreviewItemManager.recomputePreviewDrawingParams(); |
Jon Miranda | 69b35e0 | 2019-03-04 20:16:18 -0800 | [diff] [blame] | 230 | mBackground.getBounds(outBounds); |
| 231 | } |
| 232 | |
Jon Miranda | ae975a6 | 2019-05-20 11:10:25 -0700 | [diff] [blame] | 233 | public float getBackgroundStrokeWidth() { |
| 234 | return mBackground.getStrokeWidth(); |
| 235 | } |
| 236 | |
Anjali Koppal | f05545f | 2014-03-10 19:18:43 -0700 | [diff] [blame] | 237 | public Folder getFolder() { |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 238 | return mFolder; |
| 239 | } |
| 240 | |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 241 | private void setFolder(Folder folder) { |
| 242 | mFolder = folder; |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 245 | private boolean willAcceptItem(ItemInfo item) { |
| 246 | final int itemType = item.itemType; |
| 247 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 248 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT || |
| 249 | itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) && |
Sunny Goyal | 6bb51f4 | 2018-01-04 10:54:48 -0800 | [diff] [blame] | 250 | item != mInfo && !mFolder.isOpen()); |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 253 | public boolean acceptDrop(ItemInfo dragInfo) { |
Jon Miranda | cb73920 | 2017-06-23 18:40:31 -0700 | [diff] [blame] | 254 | return !mFolder.isDestroyed() && willAcceptItem(dragInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 257 | public void addItem(WorkspaceItemInfo item) { |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 258 | mInfo.add(item, true); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 261 | public void removeItem(WorkspaceItemInfo item, boolean animate) { |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 262 | mInfo.remove(item, animate); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 265 | public void onDragEnter(ItemInfo dragInfo) { |
| 266 | if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return; |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 267 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 268 | CellLayout cl = (CellLayout) getParent().getParent(); |
| 269 | |
| 270 | mBackground.animateToAccept(cl, lp.cellX, lp.cellY); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 271 | mOpenAlarm.setOnAlarmListener(mOnOpenListener); |
Adam Cohen | dedfca2 | 2014-05-19 15:10:39 -0700 | [diff] [blame] | 272 | if (SPRING_LOADING_ENABLED && |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 273 | ((dragInfo instanceof AppInfo) |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 274 | || (dragInfo instanceof WorkspaceItemInfo) |
Jon Miranda | c476d6e | 2017-05-04 16:30:01 -0700 | [diff] [blame] | 275 | || (dragInfo instanceof PendingAddShortcutInfo))) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 276 | mOpenAlarm.setAlarm(ON_OPEN_DELAY); |
| 277 | } |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 280 | OnAlarmListener mOnOpenListener = new OnAlarmListener() { |
| 281 | public void onAlarm(Alarm alarm) { |
Sunny Goyal | e393d3a | 2016-09-09 12:42:10 -0700 | [diff] [blame] | 282 | mFolder.beginExternalDrag(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 283 | } |
| 284 | }; |
| 285 | |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 286 | public Drawable prepareCreateAnimation(final View destView) { |
| 287 | return mPreviewItemManager.prepareCreateAnimation(destView); |
Winson | 8f288aa | 2016-07-25 16:49:15 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 290 | public void performCreateAnimation(final WorkspaceItemInfo destInfo, final View destView, |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 291 | final WorkspaceItemInfo srcInfo, final DragObject d, Rect dstRect, |
Sunny Goyal | 1797af4 | 2017-10-06 13:29:57 -0700 | [diff] [blame] | 292 | float scaleRelativeToDragLayer) { |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 293 | final DragView srcView = d.dragView; |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 294 | prepareCreateAnimation(destView); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 295 | addItem(destInfo); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 296 | // 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 Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 298 | mPreviewItemManager.createFirstItemAnimation(false /* reverse */, null) |
| 299 | .start(); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 300 | |
| 301 | // This will animate the dragView (srcView) into the new folder |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 302 | onDrop(srcInfo, d, dstRect, scaleRelativeToDragLayer, 1, |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 303 | false /* itemReturnedOnFailedDrop */); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 306 | 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 Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 312 | public void onDragExit() { |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 313 | mBackground.animateToRest(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 314 | mOpenAlarm.cancelAlarm(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 315 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 316 | |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 317 | private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect, |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 318 | float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 319 | item.cellX = -1; |
| 320 | item.cellY = -1; |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 321 | DragView animateView = d.dragView; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 322 | // 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 Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 325 | if (animateView != null && mActivity instanceof Launcher) { |
| 326 | final Launcher launcher = (Launcher) mActivity; |
| 327 | DragLayer dragLayer = launcher.getDragLayer(); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 328 | Rect from = new Rect(); |
| 329 | dragLayer.getViewRectRelativeToSelf(animateView, from); |
| 330 | Rect to = finalRect; |
| 331 | if (to == null) { |
| 332 | to = new Rect(); |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 333 | Workspace workspace = launcher.getWorkspace(); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 334 | // 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] | 335 | workspace.setFinalTransitionTransform(); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 336 | 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 Goyal | aeb1643 | 2017-10-16 11:46:41 -0700 | [diff] [blame] | 344 | workspace.resetTransitionTransform(); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 345 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 346 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 347 | int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 348 | boolean itemAdded = false; |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 349 | if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) { |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 350 | List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems); |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 351 | mInfo.add(item, index, false); |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 352 | mCurrentPreviewItems.clear(); |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 353 | mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0)); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 354 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 355 | if (!oldPreviewItems.equals(mCurrentPreviewItems)) { |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 356 | 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 Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 361 | } |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 362 | |
| 363 | mPreviewItemManager.hidePreviewItem(index, true); |
| 364 | mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 365 | itemAdded = true; |
| 366 | } else { |
| 367 | removeItem(item, false); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (!itemAdded) { |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 372 | mInfo.add(item, index, true); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 375 | int[] center = new int[2]; |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 376 | float scale = getLocalCenterForIndex(index, numItemsInPreview, center); |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 377 | center[0] = Math.round(scaleRelativeToDragLayer * center[0]); |
| 378 | center[1] = Math.round(scaleRelativeToDragLayer * center[1]); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 379 | |
| 380 | to.offset(center[0] - animateView.getMeasuredWidth() / 2, |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 381 | center[1] - animateView.getMeasuredHeight() / 2); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 382 | |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 383 | float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 384 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 385 | float finalScale = scale * scaleRelativeToDragLayer; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 386 | dragLayer.animateView(animateView, from, to, finalAlpha, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 387 | 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, |
Sunny Goyal | 5bc6b6f | 2017-10-26 15:36:10 -0700 | [diff] [blame] | 388 | Interpolators.DEACCEL_2, Interpolators.ACCEL_2, |
Sunny Goyal | 1797af4 | 2017-10-06 13:29:57 -0700 | [diff] [blame] | 389 | null, DragLayer.ANIMATION_END_DISAPPEAR, null); |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 390 | |
Adam Cohen | 7a8b82b | 2013-05-29 18:41:50 -0700 | [diff] [blame] | 391 | mFolder.hideItem(item); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 392 | |
Jon Miranda | 4dd024b | 2017-07-13 17:54:54 -0700 | [diff] [blame] | 393 | if (!itemAdded) mPreviewItemManager.hidePreviewItem(index, true); |
| 394 | final int finalIndex = index; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 395 | |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 396 | String[] suggestedNameOut = new String[FolderNameProvider.SUGGEST_MAX]; |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 397 | if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) { |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 398 | Executors.UI_HELPER_EXECUTOR.post(() -> { |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 399 | d.folderNameProvider.getSuggestedFolderName( |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 400 | getContext(), mInfo.contents, suggestedNameOut); |
| 401 | showFinalView(finalIndex, item, suggestedNameOut); |
| 402 | }); |
| 403 | } else { |
| 404 | showFinalView(finalIndex, item, suggestedNameOut); |
Hyunyoung Song | 4c74620 | 2019-10-10 23:11:12 -0700 | [diff] [blame] | 405 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 406 | } else { |
| 407 | addItem(item); |
| 408 | } |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Hyunyoung Song | 5fcd8f9 | 2019-11-06 21:34:36 -0800 | [diff] [blame] | 411 | 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 Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 421 | public void onDrop(DragObject d, boolean itemReturnedOnFailedDrop) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 422 | WorkspaceItemInfo item; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 423 | if (d.dragInfo instanceof AppInfo) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 424 | // Came from all apps -- make a copy |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 425 | item = ((AppInfo) d.dragInfo).makeWorkspaceItem(); |
Jon Miranda | 4f59381 | 2017-08-30 11:59:30 -0700 | [diff] [blame] | 426 | } else if (d.dragSource instanceof BaseItemDragListener){ |
| 427 | // Came from a different window -- make a copy |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 428 | item = new WorkspaceItemInfo((WorkspaceItemInfo) d.dragInfo); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 429 | } else { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 430 | item = (WorkspaceItemInfo) d.dragInfo; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 431 | } |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 432 | mFolder.notifyDrop(); |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 433 | onDrop(item, d, null, 1.0f, |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 434 | itemReturnedOnFailedDrop ? item.rank : mInfo.contents.size(), |
Hyunyoung Song | 1ae4242 | 2020-01-26 23:25:14 -0800 | [diff] [blame^] | 435 | itemReturnedOnFailedDrop |
| 436 | ); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 439 | public void setDotInfo(FolderDotInfo dotInfo) { |
| 440 | updateDotScale(mDotInfo.hasDot(), dotInfo.hasDot()); |
| 441 | mDotInfo = dotInfo; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 442 | } |
| 443 | |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 444 | public ClippedFolderIconLayoutRule getLayoutRule() { |
Jon Miranda | 4717011 | 2017-03-03 14:57:14 -0800 | [diff] [blame] | 445 | return mPreviewLayoutRule; |
| 446 | } |
| 447 | |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 448 | @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 Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 462 | /** |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 463 | * Sets mDotScale to 1 or 0, animating if wasDotted or isDotted is false |
| 464 | * (the dot is being added or removed). |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 465 | */ |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 466 | 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 Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 471 | } else { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 472 | cancelDotScaleAnim(); |
| 473 | mDotScale = newDotScale; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 474 | invalidate(); |
| 475 | } |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 478 | private void cancelDotScaleAnim() { |
| 479 | if (mDotScaleAnim != null) { |
| 480 | mDotScaleAnim.cancel(); |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 484 | public void animateDotScale(float... dotScales) { |
| 485 | cancelDotScaleAnim(); |
| 486 | mDotScaleAnim = ObjectAnimator.ofFloat(this, DOT_SCALE_PROPERTY, dotScales); |
| 487 | mDotScaleAnim.addListener(new AnimatorListenerAdapter() { |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 488 | @Override |
| 489 | public void onAnimationEnd(Animator animation) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 490 | mDotScaleAnim = null; |
Tony | 4043b05 | 2018-08-17 13:47:39 -0700 | [diff] [blame] | 491 | } |
| 492 | }); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 493 | mDotScaleAnim.start(); |
Tony | 814dead | 2017-06-15 18:30:41 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 496 | public boolean hasDot() { |
| 497 | return mDotInfo != null && mDotInfo.hasDot(); |
Tony | 814dead | 2017-06-15 18:30:41 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Adam Cohen | 119e898 | 2016-02-05 14:47:50 -0800 | [diff] [blame] | 500 | private float getLocalCenterForIndex(int index, int curNumItems, int[] center) { |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 501 | mTmpParams = mPreviewItemManager.computePreviewItemDrawingParams( |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 502 | Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index), curNumItems, mTmpParams); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 503 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 504 | mTmpParams.transX += mBackground.basePreviewOffsetX; |
| 505 | mTmpParams.transY += mBackground.basePreviewOffsetY; |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 506 | |
| 507 | float intrinsicIconSize = mPreviewItemManager.getIntrinsicIconSize(); |
| 508 | float offsetX = mTmpParams.transX + (mTmpParams.scale * intrinsicIconSize) / 2; |
| 509 | float offsetY = mTmpParams.transY + (mTmpParams.scale * intrinsicIconSize) / 2; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 510 | |
Jon Miranda | cb73920 | 2017-06-23 18:40:31 -0700 | [diff] [blame] | 511 | center[0] = Math.round(offsetX); |
| 512 | center[1] = Math.round(offsetY); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 513 | return mTmpParams.scale; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 516 | public void setFolderBackground(PreviewBackground bg) { |
| 517 | mBackground = bg; |
Adam Cohen | f172b74 | 2016-03-30 19:28:34 -0700 | [diff] [blame] | 518 | mBackground.setInvalidateDelegate(this); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 521 | @Override |
| 522 | public void setIconVisible(boolean visible) { |
Jon Miranda | e4a252a | 2017-06-18 17:43:16 -0700 | [diff] [blame] | 523 | mBackgroundIsVisible = visible; |
| 524 | invalidate(); |
| 525 | } |
| 526 | |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 527 | public PreviewBackground getFolderBackground() { |
| 528 | return mBackground; |
| 529 | } |
| 530 | |
| 531 | public PreviewItemManager getPreviewItemManager() { |
| 532 | return mPreviewItemManager; |
| 533 | } |
| 534 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 535 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 536 | protected void dispatchDraw(Canvas canvas) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 537 | super.dispatchDraw(canvas); |
| 538 | |
Jon Miranda | e4a252a | 2017-06-18 17:43:16 -0700 | [diff] [blame] | 539 | if (!mBackgroundIsVisible) return; |
| 540 | |
Jon Miranda | 0c17215 | 2017-07-24 11:39:38 -0700 | [diff] [blame] | 541 | mPreviewItemManager.recomputePreviewDrawingParams(); |
| 542 | |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 543 | if (!mBackground.drawingDelegated()) { |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 544 | mBackground.drawBackground(canvas); |
Adam Cohen | 119e898 | 2016-02-05 14:47:50 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Sunny Goyal | 11a5074 | 2019-08-07 09:24:26 -0700 | [diff] [blame] | 547 | if (mCurrentPreviewItems.isEmpty() && !mAnimating) return; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 548 | |
Sunny Goyal | d0ae492 | 2018-10-11 10:37:53 -0700 | [diff] [blame] | 549 | final int saveCount = canvas.save(); |
| 550 | canvas.clipPath(mBackground.getClipPath()); |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 551 | mPreviewItemManager.draw(canvas); |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 552 | canvas.restoreToCount(saveCount); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 553 | |
Sunny Goyal | add3d83 | 2017-09-08 11:59:05 -0700 | [diff] [blame] | 554 | if (!mBackground.drawingDelegated()) { |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 555 | mBackground.drawBackgroundStroke(canvas); |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 556 | } |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 557 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 558 | drawDot(canvas); |
Sunny Goyal | e29897f | 2017-07-20 10:09:42 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 561 | public void drawDot(Canvas canvas) { |
Jon Miranda | 9b78e19 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 562 | if (!mForceHideDot && ((mDotInfo != null && mDotInfo.hasDot()) || mDotScale > 0)) { |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 563 | Rect iconBounds = mDotParams.iconBounds; |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 564 | BubbleTextView.getIconBounds(this, iconBounds, |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 565 | mActivity.getWallpaperDeviceProfile().iconSizePx); |
Tony Wickham | e1cb93f | 2019-05-03 11:27:32 -0700 | [diff] [blame] | 566 | float iconScale = (float) mBackground.previewSize / iconBounds.width(); |
| 567 | Utilities.scaleRectAboutCenter(iconBounds, iconScale); |
Sunny Goyal | 19b93b7 | 2017-02-19 20:21:37 -0800 | [diff] [blame] | 568 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 569 | // If we are animating to the accepting state, animate the dot out. |
| 570 | mDotParams.scale = Math.max(0, mDotScale - mBackground.getScaleProgress()); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 571 | mDotParams.color = mBackground.getDotColor(); |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 572 | mDotRenderer.draw(canvas, mDotParams); |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 573 | } |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 576 | 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 Miranda | 27bdbca | 2017-07-06 16:31:56 -0700 | [diff] [blame] | 588 | /** |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 589 | * Returns the list of items which should be visible in the preview |
Jon Miranda | 27bdbca | 2017-07-06 16:31:56 -0700 | [diff] [blame] | 590 | */ |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 591 | public List<WorkspaceItemInfo> getPreviewItemsOnPage(int page) { |
| 592 | return mPreviewVerifier.setFolderInfo(mInfo).previewItemsForPage(page, mInfo.contents); |
Jon Miranda | 655ec42 | 2017-02-07 11:40:22 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Sunny Goyal | 828b11e | 2017-06-22 09:53:59 -0700 | [diff] [blame] | 595 | @Override |
| 596 | protected boolean verifyDrawable(@NonNull Drawable who) { |
Jon Miranda | 6c5d102 | 2017-07-06 09:55:50 -0700 | [diff] [blame] | 597 | return mPreviewItemManager.verifyDrawable(who) || super.verifyDrawable(who); |
Adam Cohen | 4f8071b | 2016-02-13 16:06:05 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Sunny Goyal | c52ba71 | 2016-04-05 15:59:05 -0700 | [diff] [blame] | 600 | @Override |
| 601 | public void onItemsChanged(boolean animate) { |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 602 | updatePreviewItems(animate); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 603 | invalidate(); |
| 604 | requestLayout(); |
| 605 | } |
| 606 | |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 607 | private void updatePreviewItems(boolean animate) { |
| 608 | mPreviewItemManager.updatePreviewItems(animate); |
| 609 | mCurrentPreviewItems.clear(); |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 610 | mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0)); |
Jon Miranda | 6d3586c | 2017-09-08 12:39:10 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Sunny Goyal | ac6f69f | 2019-08-16 11:59:55 -0700 | [diff] [blame] | 613 | /** |
| 614 | * Updates the preview items which match the provided condition |
| 615 | */ |
| 616 | public void updatePreviewItems(Predicate<WorkspaceItemInfo> itemCheck) { |
| 617 | mPreviewItemManager.updatePreviewItems(itemCheck); |
Jon Miranda | 4406094 | 2017-02-22 10:17:49 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | @Override |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 621 | public void onAdd(WorkspaceItemInfo item, int rank) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 622 | boolean wasDotted = mDotInfo.hasDot(); |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 623 | mDotInfo.addDotInfo(mActivity.getDotInfoForItem(item)); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 624 | boolean isDotted = mDotInfo.hasDot(); |
| 625 | updateDotScale(wasDotted, isDotted); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 626 | invalidate(); |
| 627 | requestLayout(); |
| 628 | } |
| 629 | |
Tony Wickham | 11ba507 | 2017-02-02 12:42:50 -0800 | [diff] [blame] | 630 | @Override |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 631 | public void onRemove(WorkspaceItemInfo item) { |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 632 | boolean wasDotted = mDotInfo.hasDot(); |
Tracy Zhou | 4d7b244 | 2019-12-09 13:42:57 -0800 | [diff] [blame] | 633 | mDotInfo.subtractDotInfo(mActivity.getDotInfoForItem(item)); |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 634 | boolean isDotted = mDotInfo.hasDot(); |
| 635 | updateDotScale(wasDotted, isDotted); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 636 | invalidate(); |
| 637 | requestLayout(); |
| 638 | } |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 639 | |
| 640 | public void onTitleChanged(CharSequence title) { |
Winson Chung | 82b016c | 2015-05-08 17:00:10 -0700 | [diff] [blame] | 641 | mFolderName.setText(title); |
Sunny Goyal | f4f89ef | 2015-09-02 15:06:12 -0700 | [diff] [blame] | 642 | setContentDescription(getContext().getString(R.string.folder_name_format, title)); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 643 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 644 | |
| 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 Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 651 | // Check for a stylus button press, if it occurs cancel any long press checks. |
Mady Mellor | bb83520 | 2015-07-15 16:34:34 -0700 | [diff] [blame] | 652 | if (mStylusEventHelper.onMotionEvent(event)) { |
Mady Mellor | ef044dd | 2015-06-02 15:35:07 -0700 | [diff] [blame] | 653 | mLongPressHelper.cancelLongPress(); |
| 654 | return true; |
| 655 | } |
| 656 | |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 657 | 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 Monk | 02dd7ae | 2014-04-15 15:23:31 -0400 | [diff] [blame] | 665 | case MotionEvent.ACTION_MOVE: |
| 666 | if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) { |
| 667 | mLongPressHelper.cancelLongPress(); |
| 668 | } |
| 669 | break; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 670 | } |
| 671 | return result; |
| 672 | } |
| 673 | |
| 674 | @Override |
| 675 | public void cancelLongPress() { |
| 676 | super.cancelLongPress(); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 677 | mLongPressHelper.cancelLongPress(); |
| 678 | } |
Adam Cohen | f9c184a | 2016-01-15 16:47:43 -0800 | [diff] [blame] | 679 | |
Sunny Goyal | aaf7d1d | 2016-05-17 13:38:54 -0700 | [diff] [blame] | 680 | public void removeListeners() { |
| 681 | mInfo.removeListener(this); |
| 682 | mInfo.removeListener(mFolder); |
| 683 | } |
| 684 | |
Jon Miranda | f79e54b | 2017-03-31 13:48:39 -0700 | [diff] [blame] | 685 | 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 Goyal | 740ac7f | 2016-09-28 16:47:32 -0700 | [diff] [blame] | 694 | 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 Miranda | f79e54b | 2017-03-31 13:48:39 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Jon Miranda | 27bdbca | 2017-07-06 16:31:56 -0700 | [diff] [blame] | 703 | public void onFolderClose(int currentPage) { |
| 704 | mPreviewItemManager.onFolderClose(currentPage); |
| 705 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 706 | } |