Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 18 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 19 | import android.animation.TimeInterpolator; |
| 20 | import android.animation.ValueAnimator; |
| 21 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 22 | import android.annotation.TargetApi; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 23 | import android.content.ComponentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 25 | import android.content.res.ColorStateList; |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 26 | import android.content.res.Configuration; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 27 | import android.content.res.Resources; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 28 | import android.graphics.PointF; |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 29 | import android.graphics.Rect; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.TransitionDrawable; |
Michael Jurka | 4346746 | 2013-11-14 12:03:58 +0100 | [diff] [blame] | 31 | import android.os.AsyncTask; |
Jason Monk | 6a2c778 | 2014-09-02 13:13:24 -0400 | [diff] [blame] | 32 | import android.os.Build; |
| 33 | import android.os.Bundle; |
Jason Monk | 950a467 | 2014-07-15 09:22:36 -0400 | [diff] [blame] | 34 | import android.os.UserManager; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 35 | import android.util.AttributeSet; |
| 36 | import android.view.View; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 37 | import android.view.ViewConfiguration; |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 38 | import android.view.ViewGroup; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 39 | import android.view.animation.AnimationUtils; |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 40 | import android.view.animation.DecelerateInterpolator; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 41 | import android.view.animation.LinearInterpolator; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 42 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 43 | import com.android.launcher3.compat.UserHandleCompat; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 44 | import com.android.launcher3.util.Thunk; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame^] | 45 | import com.android.launcher3.widget.WidgetsContainerView; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 46 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 47 | public class DeleteDropTarget extends ButtonDropTarget { |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 48 | private static int DELETE_ANIMATION_DURATION = 285; |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 49 | private static int FLING_DELETE_ANIMATION_DURATION = 350; |
| 50 | private static float FLING_TO_DELETE_FRICTION = 0.035f; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 51 | private static int MODE_FLING_DELETE_TO_TRASH = 0; |
| 52 | private static int MODE_FLING_DELETE_ALONG_VECTOR = 1; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 53 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 54 | private final int mFlingDeleteMode = MODE_FLING_DELETE_ALONG_VECTOR; |
| 55 | |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 56 | private ColorStateList mOriginalTextColor; |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 57 | private TransitionDrawable mUninstallDrawable; |
| 58 | private TransitionDrawable mRemoveDrawable; |
| 59 | private TransitionDrawable mCurrentDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 60 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 61 | @Thunk boolean mWaitingForUninstall = false; |
Michael Jurka | 24715c7 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 62 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 63 | public DeleteDropTarget(Context context, AttributeSet attrs) { |
| 64 | this(context, attrs, 0); |
| 65 | } |
| 66 | |
| 67 | public DeleteDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 68 | super(context, attrs, defStyle); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected void onFinishInflate() { |
| 73 | super.onFinishInflate(); |
| 74 | |
| 75 | // Get the drawable |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 76 | mOriginalTextColor = getTextColors(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 77 | |
| 78 | // Get the hover color |
| 79 | Resources r = getResources(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 80 | mHoverColor = r.getColor(R.color.delete_target_hover_tint); |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 81 | mUninstallDrawable = (TransitionDrawable) |
| 82 | r.getDrawable(R.drawable.uninstall_target_selector); |
| 83 | mRemoveDrawable = (TransitionDrawable) r.getDrawable(R.drawable.remove_target_selector); |
| 84 | |
| 85 | mRemoveDrawable.setCrossFadeEnabled(true); |
| 86 | mUninstallDrawable.setCrossFadeEnabled(true); |
| 87 | |
| 88 | // The current drawable is set to either the remove drawable or the uninstall drawable |
| 89 | // and is initially set to the remove drawable, as set in the layout xml. |
Winson Chung | 947245b | 2012-05-15 16:34:19 -0700 | [diff] [blame] | 90 | mCurrentDrawable = (TransitionDrawable) getCurrentDrawable(); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 91 | |
| 92 | // Remove the text in the Phone UI in landscape |
| 93 | int orientation = getResources().getConfiguration().orientation; |
| 94 | if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 95 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 96 | setText(""); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | private boolean isAllAppsApplication(DragSource source, Object info) { |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 102 | return source.supportsAppInfoDropTarget() && (info instanceof AppInfo); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 103 | } |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame^] | 104 | |
| 105 | private boolean isWidget(DragSource source, Object info) { |
| 106 | if (source instanceof WidgetsContainerView) { |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 107 | if (info instanceof PendingAddItemInfo) { |
| 108 | PendingAddItemInfo addInfo = (PendingAddItemInfo) info; |
| 109 | switch (addInfo.itemType) { |
| 110 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 111 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 112 | case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET: |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 113 | return true; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | return false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 118 | } |
Michael Jurka | 0b4870d | 2011-07-10 13:39:08 -0700 | [diff] [blame] | 119 | private boolean isDragSourceWorkspaceOrFolder(DragObject d) { |
| 120 | return (d.dragSource instanceof Workspace) || (d.dragSource instanceof Folder); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 121 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 122 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 123 | private void setHoverColor() { |
Adam Cohen | fe9da81 | 2014-08-04 17:08:01 -0700 | [diff] [blame] | 124 | if (mCurrentDrawable != null) { |
| 125 | mCurrentDrawable.startTransition(mTransitionDuration); |
| 126 | } |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 127 | setTextColor(mHoverColor); |
| 128 | } |
| 129 | private void resetHoverColor() { |
Adam Cohen | fe9da81 | 2014-08-04 17:08:01 -0700 | [diff] [blame] | 130 | if (mCurrentDrawable != null) { |
| 131 | mCurrentDrawable.resetTransition(); |
| 132 | } |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 133 | setTextColor(mOriginalTextColor); |
| 134 | } |
| 135 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 136 | @Override |
| 137 | public boolean acceptDrop(DragObject d) { |
Adam Cohen | 7c4c510 | 2013-06-14 17:42:35 -0700 | [diff] [blame] | 138 | return willAcceptDrop(d.dragInfo); |
| 139 | } |
| 140 | |
| 141 | public static boolean willAcceptDrop(Object info) { |
| 142 | if (info instanceof ItemInfo) { |
| 143 | ItemInfo item = (ItemInfo) info; |
| 144 | if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 145 | item.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET || |
Adam Cohen | 7c4c510 | 2013-06-14 17:42:35 -0700 | [diff] [blame] | 146 | item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { |
| 147 | return true; |
| 148 | } |
Michael Jurka | ed3d4df | 2013-09-12 18:09:24 +0200 | [diff] [blame] | 149 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 150 | if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) { |
Michael Jurka | ed3d4df | 2013-09-12 18:09:24 +0200 | [diff] [blame] | 151 | return true; |
| 152 | } |
| 153 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 154 | if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && |
Michael Jurka | 5e7af5d | 2013-09-14 18:35:38 +0200 | [diff] [blame] | 155 | item instanceof AppInfo) { |
| 156 | AppInfo appInfo = (AppInfo) info; |
| 157 | return (appInfo.flags & AppInfo.DOWNLOADED_FLAG) != 0; |
| 158 | } |
| 159 | |
Michael Jurka | 9bd4d28 | 2013-09-05 19:21:31 +0200 | [diff] [blame] | 160 | if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 161 | item instanceof ShortcutInfo) { |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 162 | return true; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 163 | } |
Adam Cohen | 947dc54 | 2013-06-06 22:43:33 -0700 | [diff] [blame] | 164 | } |
Adam Cohen | 7c4c510 | 2013-06-14 17:42:35 -0700 | [diff] [blame] | 165 | return false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 168 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 169 | @Override |
| 170 | public void onDragStart(DragSource source, Object info, int dragAction) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 171 | boolean isVisible = true; |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 172 | boolean useUninstallLabel = isAllAppsApplication(source, info); |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 173 | boolean useDeleteLabel = !useUninstallLabel && source.supportsDeleteDropTarget(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 174 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 175 | // If we are dragging an application from AppsCustomize, only show the control if we can |
Winson Chung | e01af63 | 2013-09-26 10:43:20 -0700 | [diff] [blame] | 176 | // delete the app (it was downloaded), and rename the string to "uninstall" in such a case. |
| 177 | // Hide the delete target if it is a widget from AppsCustomize. |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame^] | 178 | if (!willAcceptDrop(info) || isWidget(source, info)) { |
Adam Cohen | 947dc54 | 2013-06-06 22:43:33 -0700 | [diff] [blame] | 179 | isVisible = false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 180 | } |
Jason Monk | 950a467 | 2014-07-15 09:22:36 -0400 | [diff] [blame] | 181 | if (useUninstallLabel) { |
Jason Monk | 6a2c778 | 2014-09-02 13:13:24 -0400 | [diff] [blame] | 182 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { |
| 183 | UserManager userManager = (UserManager) |
| 184 | getContext().getSystemService(Context.USER_SERVICE); |
| 185 | Bundle restrictions = userManager.getUserRestrictions(); |
| 186 | if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false) |
| 187 | || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) { |
| 188 | isVisible = false; |
| 189 | } |
Jason Monk | 950a467 | 2014-07-15 09:22:36 -0400 | [diff] [blame] | 190 | } |
| 191 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 192 | |
Michael Jurka | addcba6 | 2013-10-09 19:04:13 -0700 | [diff] [blame] | 193 | if (useUninstallLabel) { |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 194 | setCompoundDrawablesRelativeWithIntrinsicBounds(mUninstallDrawable, null, null, null); |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 195 | } else if (useDeleteLabel) { |
Fabrice Di Meglio | d6a33c6 | 2013-02-06 15:40:46 -0800 | [diff] [blame] | 196 | setCompoundDrawablesRelativeWithIntrinsicBounds(mRemoveDrawable, null, null, null); |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 197 | } else { |
| 198 | isVisible = false; |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 199 | } |
Winson Chung | 947245b | 2012-05-15 16:34:19 -0700 | [diff] [blame] | 200 | mCurrentDrawable = (TransitionDrawable) getCurrentDrawable(); |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 201 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 202 | mActive = isVisible; |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 203 | resetHoverColor(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 204 | ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 205 | if (isVisible && getText().length() > 0) { |
Michael Jurka | addcba6 | 2013-10-09 19:04:13 -0700 | [diff] [blame] | 206 | setText(useUninstallLabel ? R.string.delete_target_uninstall_label |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 207 | : R.string.delete_target_label); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public void onDragEnd() { |
| 213 | super.onDragEnd(); |
| 214 | mActive = false; |
| 215 | } |
| 216 | |
| 217 | public void onDragEnter(DragObject d) { |
| 218 | super.onDragEnter(d); |
| 219 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 220 | setHoverColor(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | public void onDragExit(DragObject d) { |
| 224 | super.onDragExit(d); |
| 225 | |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 226 | if (!d.dragComplete) { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 227 | resetHoverColor(); |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 228 | } else { |
| 229 | // Restore the hover color if we are deleting |
| 230 | d.dragView.setColor(mHoverColor); |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 231 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 234 | private void animateToTrashAndCompleteDrop(final DragObject d) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 235 | final DragLayer dragLayer = mLauncher.getDragLayer(); |
| 236 | final Rect from = new Rect(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 237 | dragLayer.getViewRectRelativeToSelf(d.dragView, from); |
Adam Cohen | fe9da81 | 2014-08-04 17:08:01 -0700 | [diff] [blame] | 238 | |
| 239 | int width = mCurrentDrawable == null ? 0 : mCurrentDrawable.getIntrinsicWidth(); |
| 240 | int height = mCurrentDrawable == null ? 0 : mCurrentDrawable.getIntrinsicHeight(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 241 | final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), |
Adam Cohen | fe9da81 | 2014-08-04 17:08:01 -0700 | [diff] [blame] | 242 | width, height); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 243 | final float scale = (float) to.width() / from.width(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 244 | |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 245 | mSearchDropTargetBar.deferOnDragEnd(); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 246 | deferCompleteDropIfUninstalling(d); |
| 247 | |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 248 | Runnable onAnimationEndRunnable = new Runnable() { |
| 249 | @Override |
| 250 | public void run() { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 251 | completeDrop(d); |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 252 | mSearchDropTargetBar.onDragEnd(); |
Sunny Goyal | 8498eb4 | 2014-10-16 12:08:41 -0700 | [diff] [blame] | 253 | mLauncher.exitSpringLoadedDragModeDelayed(true, 0, null); |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 254 | } |
| 255 | }; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 256 | dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 257 | DELETE_ANIMATION_DURATION, new DecelerateInterpolator(2), |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 258 | new LinearInterpolator(), onAnimationEndRunnable, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 259 | DragLayer.ANIMATION_END_DISAPPEAR, null); |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 262 | private void deferCompleteDropIfUninstalling(DragObject d) { |
| 263 | mWaitingForUninstall = false; |
Michael Jurka | 5e7af5d | 2013-09-14 18:35:38 +0200 | [diff] [blame] | 264 | if (isUninstallFromWorkspace(d)) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 265 | if (d.dragSource instanceof Folder) { |
| 266 | ((Folder) d.dragSource).deferCompleteDropAfterUninstallActivity(); |
| 267 | } else if (d.dragSource instanceof Workspace) { |
| 268 | ((Workspace) d.dragSource).deferCompleteDropAfterUninstallActivity(); |
| 269 | } |
| 270 | mWaitingForUninstall = true; |
| 271 | } |
| 272 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 273 | |
Michael Jurka | 5e7af5d | 2013-09-14 18:35:38 +0200 | [diff] [blame] | 274 | private boolean isUninstallFromWorkspace(DragObject d) { |
Michael Jurka | 5e7af5d | 2013-09-14 18:35:38 +0200 | [diff] [blame] | 275 | return false; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 278 | @Thunk void completeDrop(DragObject d) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 279 | ItemInfo item = (ItemInfo) d.dragInfo; |
| 280 | boolean wasWaitingForUninstall = mWaitingForUninstall; |
| 281 | mWaitingForUninstall = false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 282 | if (isAllAppsApplication(d.dragSource, item)) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 283 | uninstallApp(mLauncher, (AppInfo) item); |
Michael Jurka | 5e7af5d | 2013-09-14 18:35:38 +0200 | [diff] [blame] | 284 | } else if (isUninstallFromWorkspace(d)) { |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 285 | ShortcutInfo shortcut = (ShortcutInfo) item; |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 286 | if (shortcut.intent != null && shortcut.intent.getComponent() != null) { |
Michael Jurka | f300758 | 2013-08-21 14:33:57 +0200 | [diff] [blame] | 287 | final ComponentName componentName = shortcut.intent.getComponent(); |
| 288 | final DragSource dragSource = d.dragSource; |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 289 | final UserHandleCompat user = shortcut.user; |
| 290 | mWaitingForUninstall = mLauncher.startApplicationUninstallActivity( |
| 291 | componentName, shortcut.flags, user); |
Michael Jurka | f300758 | 2013-08-21 14:33:57 +0200 | [diff] [blame] | 292 | if (mWaitingForUninstall) { |
| 293 | final Runnable checkIfUninstallWasSuccess = new Runnable() { |
| 294 | @Override |
| 295 | public void run() { |
| 296 | mWaitingForUninstall = false; |
| 297 | String packageName = componentName.getPackageName(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 298 | boolean uninstallSuccessful = !AllAppsList.packageHasActivities( |
Kenny Guy | d31df54 | 2014-06-30 15:12:11 +0100 | [diff] [blame] | 299 | getContext(), packageName, user); |
Michael Jurka | f300758 | 2013-08-21 14:33:57 +0200 | [diff] [blame] | 300 | if (dragSource instanceof Folder) { |
| 301 | ((Folder) dragSource). |
| 302 | onUninstallActivityReturned(uninstallSuccessful); |
| 303 | } else if (dragSource instanceof Workspace) { |
| 304 | ((Workspace) dragSource). |
| 305 | onUninstallActivityReturned(uninstallSuccessful); |
| 306 | } |
| 307 | } |
| 308 | }; |
| 309 | mLauncher.addOnResumeCallback(checkIfUninstallWasSuccess); |
| 310 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 311 | } |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 312 | } else if (isDragSourceWorkspaceOrFolder(d)) { |
| 313 | removeWorkspaceOrFolderItem(mLauncher, item, null); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 314 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 315 | if (wasWaitingForUninstall && !mWaitingForUninstall) { |
| 316 | if (d.dragSource instanceof Folder) { |
| 317 | ((Folder) d.dragSource).onUninstallActivityReturned(false); |
| 318 | } else if (d.dragSource instanceof Workspace) { |
| 319 | ((Workspace) d.dragSource).onUninstallActivityReturned(false); |
| 320 | } |
| 321 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 322 | } |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 323 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 324 | public static void uninstallApp(Launcher launcher, AppInfo info) { |
| 325 | launcher.startApplicationUninstallActivity(info.componentName, info.flags, info.user); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Removes the item from the workspace. If the view is not null, it also removes the view. |
| 330 | * @return true if the item was removed. |
| 331 | */ |
| 332 | public static boolean removeWorkspaceOrFolderItem(Launcher launcher, ItemInfo item, View view) { |
| 333 | if (item instanceof ShortcutInfo) { |
| 334 | LauncherModel.deleteItemFromDatabase(launcher, item); |
| 335 | } else if (item instanceof FolderInfo) { |
| 336 | FolderInfo folder = (FolderInfo) item; |
| 337 | launcher.removeFolder(folder); |
| 338 | LauncherModel.deleteFolderContentsFromDatabase(launcher, folder); |
| 339 | } else if (item instanceof LauncherAppWidgetInfo) { |
| 340 | final LauncherAppWidgetInfo widget = (LauncherAppWidgetInfo) item; |
| 341 | |
| 342 | // Remove the widget from the workspace |
| 343 | launcher.removeAppWidget(widget); |
| 344 | LauncherModel.deleteItemFromDatabase(launcher, widget); |
| 345 | |
| 346 | final LauncherAppWidgetHost appWidgetHost = launcher.getAppWidgetHost(); |
| 347 | |
| 348 | if (appWidgetHost != null && !widget.isCustomWidget() |
| 349 | && widget.isWidgetIdValid()) { |
| 350 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 351 | // to the caller... |
| 352 | new AsyncTask<Void, Void, Void>() { |
| 353 | public Void doInBackground(Void ... args) { |
| 354 | appWidgetHost.deleteAppWidgetId(widget.appWidgetId); |
| 355 | return null; |
| 356 | } |
| 357 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
| 358 | } |
| 359 | } else { |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | if (view != null) { |
| 364 | launcher.getWorkspace().removeWorkspaceItem(view); |
| 365 | launcher.getWorkspace().stripEmptyScreens(); |
| 366 | } |
| 367 | return true; |
| 368 | } |
| 369 | |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 370 | public void onDrop(DragObject d) { |
| 371 | animateToTrashAndCompleteDrop(d); |
| 372 | } |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 373 | |
| 374 | /** |
| 375 | * Creates an animation from the current drag view to the delete trash icon. |
| 376 | */ |
| 377 | private AnimatorUpdateListener createFlingToTrashAnimatorListener(final DragLayer dragLayer, |
| 378 | DragObject d, PointF vel, ViewConfiguration config) { |
Adam Cohen | fe9da81 | 2014-08-04 17:08:01 -0700 | [diff] [blame] | 379 | |
| 380 | int width = mCurrentDrawable == null ? 0 : mCurrentDrawable.getIntrinsicWidth(); |
| 381 | int height = mCurrentDrawable == null ? 0 : mCurrentDrawable.getIntrinsicHeight(); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 382 | final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), |
Adam Cohen | fe9da81 | 2014-08-04 17:08:01 -0700 | [diff] [blame] | 383 | width, height); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 384 | final Rect from = new Rect(); |
| 385 | dragLayer.getViewRectRelativeToSelf(d.dragView, from); |
| 386 | |
| 387 | // Calculate how far along the velocity vector we should put the intermediate point on |
| 388 | // the bezier curve |
| 389 | float velocity = Math.abs(vel.length()); |
| 390 | float vp = Math.min(1f, velocity / (config.getScaledMaximumFlingVelocity() / 2f)); |
| 391 | int offsetY = (int) (-from.top * vp); |
| 392 | int offsetX = (int) (offsetY / (vel.y / vel.x)); |
| 393 | final float y2 = from.top + offsetY; // intermediate t/l |
| 394 | final float x2 = from.left + offsetX; |
| 395 | final float x1 = from.left; // drag view t/l |
| 396 | final float y1 = from.top; |
| 397 | final float x3 = to.left; // delete target t/l |
| 398 | final float y3 = to.top; |
| 399 | |
| 400 | final TimeInterpolator scaleAlphaInterpolator = new TimeInterpolator() { |
| 401 | @Override |
| 402 | public float getInterpolation(float t) { |
| 403 | return t * t * t * t * t * t * t * t; |
| 404 | } |
| 405 | }; |
| 406 | return new AnimatorUpdateListener() { |
| 407 | @Override |
| 408 | public void onAnimationUpdate(ValueAnimator animation) { |
| 409 | final DragView dragView = (DragView) dragLayer.getAnimatedView(); |
| 410 | float t = ((Float) animation.getAnimatedValue()).floatValue(); |
| 411 | float tp = scaleAlphaInterpolator.getInterpolation(t); |
| 412 | float initialScale = dragView.getInitialScale(); |
| 413 | float finalAlpha = 0.5f; |
| 414 | float scale = dragView.getScaleX(); |
| 415 | float x1o = ((1f - scale) * dragView.getMeasuredWidth()) / 2f; |
| 416 | float y1o = ((1f - scale) * dragView.getMeasuredHeight()) / 2f; |
| 417 | float x = (1f - t) * (1f - t) * (x1 - x1o) + 2 * (1f - t) * t * (x2 - x1o) + |
| 418 | (t * t) * x3; |
| 419 | float y = (1f - t) * (1f - t) * (y1 - y1o) + 2 * (1f - t) * t * (y2 - x1o) + |
| 420 | (t * t) * y3; |
| 421 | |
| 422 | dragView.setTranslationX(x); |
| 423 | dragView.setTranslationY(y); |
| 424 | dragView.setScaleX(initialScale * (1f - tp)); |
| 425 | dragView.setScaleY(initialScale * (1f - tp)); |
| 426 | dragView.setAlpha(finalAlpha + (1f - finalAlpha) * (1f - tp)); |
| 427 | } |
| 428 | }; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Creates an animation from the current drag view along its current velocity vector. |
| 433 | * For this animation, the alpha runs for a fixed duration and we update the position |
| 434 | * progressively. |
| 435 | */ |
| 436 | private static class FlingAlongVectorAnimatorUpdateListener implements AnimatorUpdateListener { |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 437 | private DragLayer mDragLayer; |
| 438 | private PointF mVelocity; |
| 439 | private Rect mFrom; |
| 440 | private long mPrevTime; |
| 441 | private boolean mHasOffsetForScale; |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 442 | private float mFriction; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 443 | |
Winson Chung | 9658b1e | 2012-04-09 18:30:07 -0700 | [diff] [blame] | 444 | private final TimeInterpolator mAlphaInterpolator = new DecelerateInterpolator(0.75f); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 445 | |
| 446 | public FlingAlongVectorAnimatorUpdateListener(DragLayer dragLayer, PointF vel, Rect from, |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 447 | long startTime, float friction) { |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 448 | mDragLayer = dragLayer; |
| 449 | mVelocity = vel; |
| 450 | mFrom = from; |
| 451 | mPrevTime = startTime; |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 452 | mFriction = 1f - (dragLayer.getResources().getDisplayMetrics().density * friction); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public void onAnimationUpdate(ValueAnimator animation) { |
| 457 | final DragView dragView = (DragView) mDragLayer.getAnimatedView(); |
| 458 | float t = ((Float) animation.getAnimatedValue()).floatValue(); |
| 459 | long curTime = AnimationUtils.currentAnimationTimeMillis(); |
| 460 | |
| 461 | if (!mHasOffsetForScale) { |
| 462 | mHasOffsetForScale = true; |
| 463 | float scale = dragView.getScaleX(); |
| 464 | float xOffset = ((scale - 1f) * dragView.getMeasuredWidth()) / 2f; |
| 465 | float yOffset = ((scale - 1f) * dragView.getMeasuredHeight()) / 2f; |
| 466 | |
| 467 | mFrom.left += xOffset; |
| 468 | mFrom.top += yOffset; |
| 469 | } |
| 470 | |
| 471 | mFrom.left += (mVelocity.x * (curTime - mPrevTime) / 1000f); |
| 472 | mFrom.top += (mVelocity.y * (curTime - mPrevTime) / 1000f); |
| 473 | |
| 474 | dragView.setTranslationX(mFrom.left); |
| 475 | dragView.setTranslationY(mFrom.top); |
| 476 | dragView.setAlpha(1f - mAlphaInterpolator.getInterpolation(t)); |
| 477 | |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 478 | mVelocity.x *= mFriction; |
| 479 | mVelocity.y *= mFriction; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 480 | mPrevTime = curTime; |
| 481 | } |
| 482 | }; |
| 483 | private AnimatorUpdateListener createFlingAlongVectorAnimatorListener(final DragLayer dragLayer, |
| 484 | DragObject d, PointF vel, final long startTime, final int duration, |
| 485 | ViewConfiguration config) { |
| 486 | final Rect from = new Rect(); |
| 487 | dragLayer.getViewRectRelativeToSelf(d.dragView, from); |
| 488 | |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 489 | return new FlingAlongVectorAnimatorUpdateListener(dragLayer, vel, from, startTime, |
| 490 | FLING_TO_DELETE_FRICTION); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | public void onFlingToDelete(final DragObject d, int x, int y, PointF vel) { |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame^] | 494 | final boolean isWidgets = d.dragSource instanceof WidgetsContainerView; |
| 495 | final boolean isAllapps = d.dragSource instanceof AppsContainerView; |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 496 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 497 | // Don't highlight the icon as it's animating |
| 498 | d.dragView.setColor(0); |
| 499 | d.dragView.updateInitialScaleToCurrentScale(); |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 500 | // Don't highlight the target if we are flinging from AllApps |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame^] | 501 | if (isWidgets || isAllapps) { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 502 | resetHoverColor(); |
| 503 | } |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 504 | |
| 505 | if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) { |
| 506 | // Defer animating out the drop target if we are animating to it |
| 507 | mSearchDropTargetBar.deferOnDragEnd(); |
| 508 | mSearchDropTargetBar.finishAnimations(); |
| 509 | } |
| 510 | |
| 511 | final ViewConfiguration config = ViewConfiguration.get(mLauncher); |
| 512 | final DragLayer dragLayer = mLauncher.getDragLayer(); |
Winson Chung | 6e1bdaf | 2012-05-29 17:03:45 -0700 | [diff] [blame] | 513 | final int duration = FLING_DELETE_ANIMATION_DURATION; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 514 | final long startTime = AnimationUtils.currentAnimationTimeMillis(); |
| 515 | |
| 516 | // NOTE: Because it takes time for the first frame of animation to actually be |
| 517 | // called and we expect the animation to be a continuation of the fling, we have |
| 518 | // to account for the time that has elapsed since the fling finished. And since |
| 519 | // we don't have a startDelay, we will always get call to update when we call |
| 520 | // start() (which we want to ignore). |
| 521 | final TimeInterpolator tInterpolator = new TimeInterpolator() { |
| 522 | private int mCount = -1; |
| 523 | private float mOffset = 0f; |
| 524 | |
| 525 | @Override |
| 526 | public float getInterpolation(float t) { |
| 527 | if (mCount < 0) { |
| 528 | mCount++; |
| 529 | } else if (mCount == 0) { |
| 530 | mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - |
| 531 | startTime) / duration); |
| 532 | mCount++; |
| 533 | } |
| 534 | return Math.min(1f, mOffset + t); |
| 535 | } |
| 536 | }; |
| 537 | AnimatorUpdateListener updateCb = null; |
| 538 | if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) { |
| 539 | updateCb = createFlingToTrashAnimatorListener(dragLayer, d, vel, config); |
| 540 | } else if (mFlingDeleteMode == MODE_FLING_DELETE_ALONG_VECTOR) { |
| 541 | updateCb = createFlingAlongVectorAnimatorListener(dragLayer, d, vel, startTime, |
| 542 | duration, config); |
| 543 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 544 | deferCompleteDropIfUninstalling(d); |
| 545 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 546 | Runnable onAnimationEndRunnable = new Runnable() { |
| 547 | @Override |
| 548 | public void run() { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 549 | // If we are dragging from AllApps, then we allow AppsCustomizePagedView to clean up |
| 550 | // itself, otherwise, complete the drop to initiate the deletion process |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame^] | 551 | if (!isWidgets || !isAllapps) { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 552 | mLauncher.exitSpringLoadedDragMode(); |
| 553 | completeDrop(d); |
| 554 | } |
| 555 | mLauncher.getDragController().onDeferredEndFling(d); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 556 | } |
| 557 | }; |
| 558 | dragLayer.animateView(d.dragView, updateCb, duration, tInterpolator, onAnimationEndRunnable, |
| 559 | DragLayer.ANIMATION_END_DISAPPEAR, null); |
| 560 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 561 | } |