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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.res.TypedArray; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 21 | import android.graphics.Paint; |
| 22 | import android.graphics.PorterDuff; |
| 23 | import android.graphics.PorterDuffColorFilter; |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.graphics.RectF; |
| 26 | import android.graphics.drawable.TransitionDrawable; |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.view.animation.AccelerateInterpolator; |
| 30 | import android.view.animation.AlphaAnimation; |
| 31 | import android.view.animation.Animation; |
| 32 | import android.view.animation.AnimationSet; |
| 33 | import android.view.animation.TranslateAnimation; |
| 34 | import android.widget.ImageView; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 35 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 36 | import com.android.launcher.R; |
| 37 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | public class DeleteZone extends ImageView implements DropTarget, DragController.DragListener { |
| 39 | private static final int ORIENTATION_HORIZONTAL = 1; |
| 40 | private static final int TRANSITION_DURATION = 250; |
| 41 | private static final int ANIMATION_DURATION = 200; |
| 42 | |
| 43 | private final int[] mLocation = new int[2]; |
| 44 | |
| 45 | private Launcher mLauncher; |
| 46 | private boolean mTrashMode; |
| 47 | |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 48 | /** |
| 49 | * If true, this View responsible for managing its own visibility, and that of its handle. |
| 50 | * This is generally the case, but it will be set to false when this is part of the |
| 51 | * Contextual Action Bar. |
| 52 | */ |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 53 | private boolean mDragAndDropEnabled = true; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 54 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | private AnimationSet mInAnimation; |
| 56 | private AnimationSet mOutAnimation; |
| 57 | private Animation mHandleInAnimation; |
| 58 | private Animation mHandleOutAnimation; |
| 59 | |
| 60 | private int mOrientation; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 61 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 62 | |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 63 | private final RectF mRegionF = new RectF(); |
| 64 | private final Rect mRegion = new Rect(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | private TransitionDrawable mTransition; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 66 | private final Paint mTrashPaint = new Paint(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 68 | /** The View that this view will replace. */ |
| 69 | private View mHandle = null; |
| 70 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 71 | public DeleteZone(Context context, AttributeSet attrs) { |
| 72 | this(context, attrs, 0); |
| 73 | } |
| 74 | |
| 75 | public DeleteZone(Context context, AttributeSet attrs, int defStyle) { |
| 76 | super(context, attrs, defStyle); |
| 77 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 78 | final int srcColor = context.getResources().getColor(R.color.delete_color_filter); |
| 79 | mTrashPaint.setColorFilter(new PorterDuffColorFilter(srcColor, PorterDuff.Mode.SRC_ATOP)); |
| 80 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 81 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeleteZone, defStyle, 0); |
| 82 | mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL); |
| 83 | a.recycle(); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | protected void onFinishInflate() { |
| 88 | super.onFinishInflate(); |
Joe Onorato | a9c28f6 | 2009-09-14 18:38:49 -0400 | [diff] [blame] | 89 | mTransition = (TransitionDrawable) getDrawable(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 93 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | return true; |
| 95 | } |
| 96 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 97 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 98 | DragView dragView, Object dragInfo) { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 99 | if (!mDragAndDropEnabled) return; |
| 100 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 101 | final ItemInfo item = (ItemInfo) dragInfo; |
| 102 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 103 | // On x-large screens, you can uninstall an app by dragging from all apps |
| 104 | if (item instanceof ApplicationInfo && LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 105 | mLauncher.startApplicationUninstallActivity((ApplicationInfo) item); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 106 | } |
| 107 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 108 | if (item.container == -1) return; |
| 109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 111 | if (item instanceof LauncherAppWidgetInfo) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 112 | mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 113 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 114 | } else if (source instanceof UserFolder) { |
| 115 | final UserFolder userFolder = (UserFolder) source; |
| 116 | final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo(); |
| 117 | // Item must be a ShortcutInfo otherwise it couldn't have been in the folder |
| 118 | // in the first place. |
| 119 | userFolderInfo.remove((ShortcutInfo)item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 120 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 121 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | if (item instanceof UserFolderInfo) { |
| 123 | final UserFolderInfo userFolderInfo = (UserFolderInfo)item; |
| 124 | LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 125 | mLauncher.removeFolder(userFolderInfo); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 126 | } else if (item instanceof LauncherAppWidgetInfo) { |
| 127 | final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; |
| 128 | final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); |
| 129 | if (appWidgetHost != null) { |
Brad Fitzpatrick | 73013bf | 2010-09-14 12:15:32 -0700 | [diff] [blame] | 130 | final int appWidgetId = launcherAppWidgetInfo.appWidgetId; |
| 131 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 132 | // to the caller... |
| 133 | new Thread("deleteAppWidgetId") { |
| 134 | public void run() { |
| 135 | appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); |
| 136 | } |
| 137 | }.start(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 138 | } |
| 139 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 140 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
| 142 | } |
| 143 | |
| 144 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 145 | DragView dragView, Object dragInfo) { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 146 | if (!mDragAndDropEnabled) return; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 147 | mTransition.reverseTransition(TRANSITION_DURATION); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 148 | dragView.setPaint(mTrashPaint); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 152 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 156 | DragView dragView, Object dragInfo) { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 157 | if (!mDragAndDropEnabled) return; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 158 | mTransition.reverseTransition(TRANSITION_DURATION); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 159 | dragView.setPaint(null); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 162 | public void onDragStart(DragSource source, Object info, int dragAction) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 163 | final ItemInfo item = (ItemInfo) info; |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 164 | if (item != null && mDragAndDropEnabled) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 165 | mTrashMode = true; |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 166 | getHitRect(mRegion); |
| 167 | mRegionF.set(mRegion); |
| 168 | |
| 169 | if (LauncherApplication.isScreenXLarge()) { |
| 170 | // This region will be a "dead zone" for scrolling; make it extend to the edge of |
| 171 | // the screen so users don't accidentally trigger a scroll while deleting items |
| 172 | mRegionF.top = mLauncher.getWorkspace().getTop(); |
| 173 | mRegionF.right = mLauncher.getWorkspace().getRight(); |
| 174 | } |
| 175 | |
| 176 | mDragController.setDeleteRegion(mRegionF); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 177 | |
| 178 | // Make sure the icon is set to the default drawable, not the hover drawable |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 179 | mTransition.resetTransition(); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 180 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 181 | createAnimations(); |
| 182 | startAnimation(mInAnimation); |
| 183 | if (mHandle != null) { |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 184 | mHandle.startAnimation(mHandleOutAnimation); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 185 | } |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 186 | setVisibility(VISIBLE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | public void onDragEnd() { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 191 | if (mTrashMode && mDragAndDropEnabled) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 192 | mTrashMode = false; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 193 | mDragController.setDeleteRegion(null); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 194 | |
| 195 | if (mOutAnimation != null) startAnimation(mOutAnimation); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 196 | if (mHandleInAnimation != null && mHandle != null) { |
| 197 | mHandle.startAnimation(mHandleInAnimation); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 198 | } |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 199 | setVisibility(GONE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 203 | public boolean isDropEnabled() { |
| 204 | return true; |
| 205 | } |
| 206 | |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public void getHitRect(Rect outRect) { |
| 209 | super.getHitRect(outRect); |
| 210 | if (LauncherApplication.isScreenXLarge()) { |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 211 | // TODO: This is a temporary hack. mManageVisiblity = false when you're in CAB mode. |
| 212 | // In that case, this icon is more tightly spaced next to the delete icon so we want |
| 213 | // it to have a smaller drag region. When the new drag&drop system comes in, we'll |
| 214 | // dispatch the drag/drop by calculating what target you're overlapping |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 215 | final int padding = R.dimen.delete_zone_padding; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 216 | final int outerDragPadding = |
| 217 | getResources().getDimensionPixelSize(R.dimen.delete_zone_size); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 218 | final int innerDragPadding = getResources().getDimensionPixelSize(padding); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 219 | outRect.top -= outerDragPadding; |
| 220 | outRect.left -= innerDragPadding; |
| 221 | outRect.bottom += outerDragPadding; |
| 222 | outRect.right += innerDragPadding; |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 226 | private void createAnimations() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 227 | if (mHandleInAnimation == null) { |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 228 | mHandleInAnimation = new AlphaAnimation(0.0f, 1.0f); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 229 | mHandleInAnimation.setDuration(ANIMATION_DURATION); |
| 230 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 231 | |
| 232 | if (mInAnimation == null) { |
| 233 | mInAnimation = new FastAnimationSet(); |
| 234 | if (!LauncherApplication.isScreenXLarge()) { |
| 235 | final AnimationSet animationSet = mInAnimation; |
| 236 | animationSet.setInterpolator(new AccelerateInterpolator()); |
| 237 | animationSet.addAnimation(new AlphaAnimation(0.0f, 1.0f)); |
| 238 | if (mOrientation == ORIENTATION_HORIZONTAL) { |
| 239 | animationSet.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, 0.0f, |
| 240 | Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, |
| 241 | Animation.RELATIVE_TO_SELF, 0.0f)); |
| 242 | } else { |
| 243 | animationSet.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, |
| 244 | 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.ABSOLUTE, 0.0f, |
| 245 | Animation.ABSOLUTE, 0.0f)); |
| 246 | } |
| 247 | animationSet.setDuration(ANIMATION_DURATION); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 248 | } else { |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 249 | mInAnimation.addAnimation(mHandleInAnimation); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 250 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 251 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 252 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 253 | if (mHandleOutAnimation == null) { |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 254 | mHandleOutAnimation = new AlphaAnimation(1.0f, 0.0f); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 255 | mHandleOutAnimation.setFillAfter(true); |
| 256 | mHandleOutAnimation.setDuration(ANIMATION_DURATION); |
| 257 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 258 | |
| 259 | if (mOutAnimation == null) { |
| 260 | mOutAnimation = new FastAnimationSet(); |
| 261 | if (!LauncherApplication.isScreenXLarge()) { |
| 262 | final AnimationSet animationSet = mOutAnimation; |
| 263 | animationSet.setInterpolator(new AccelerateInterpolator()); |
| 264 | animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f)); |
| 265 | if (mOrientation == ORIENTATION_HORIZONTAL) { |
| 266 | animationSet.addAnimation(new FastTranslateAnimation(Animation.ABSOLUTE, 0.0f, |
| 267 | Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, |
| 268 | Animation.RELATIVE_TO_SELF, 1.0f)); |
| 269 | } else { |
| 270 | animationSet.addAnimation(new FastTranslateAnimation(Animation.RELATIVE_TO_SELF, |
| 271 | 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.ABSOLUTE, 0.0f, |
| 272 | Animation.ABSOLUTE, 0.0f)); |
| 273 | } |
| 274 | animationSet.setDuration(ANIMATION_DURATION); |
| 275 | } else { |
| 276 | mOutAnimation.addAnimation(mHandleOutAnimation); |
| 277 | } |
| 278 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void setLauncher(Launcher launcher) { |
| 282 | mLauncher = launcher; |
| 283 | } |
| 284 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 285 | void setDragController(DragController dragController) { |
| 286 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void setHandle(View view) { |
| 290 | mHandle = view; |
| 291 | } |
| 292 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 293 | void setDragAndDropEnabled(boolean enabled) { |
| 294 | mDragAndDropEnabled = enabled; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 295 | } |
| 296 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 297 | private static class FastTranslateAnimation extends TranslateAnimation { |
| 298 | public FastTranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, |
| 299 | int fromYType, float fromYValue, int toYType, float toYValue) { |
| 300 | super(fromXType, fromXValue, toXType, toXValue, |
| 301 | fromYType, fromYValue, toYType, toYValue); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public boolean willChangeTransformationMatrix() { |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public boolean willChangeBounds() { |
| 311 | return false; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | private static class FastAnimationSet extends AnimationSet { |
| 316 | FastAnimationSet() { |
| 317 | super(false); |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public boolean willChangeTransformationMatrix() { |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public boolean willChangeBounds() { |
| 327 | return false; |
| 328 | } |
| 329 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 330 | |
| 331 | @Override |
| 332 | public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset, |
| 333 | DragView dragView, Object dragInfo) { |
| 334 | return null; |
| 335 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 336 | } |