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 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 19 | import android.animation.AnimatorSet; |
| 20 | import android.animation.Animator; |
| 21 | import android.animation.AnimatorListenerAdapter; |
| 22 | import android.animation.ObjectAnimator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 24 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.content.res.TypedArray; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 26 | import android.graphics.PorterDuff; |
| 27 | import android.graphics.PorterDuffColorFilter; |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 28 | import android.graphics.Rect; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | import android.graphics.RectF; |
| 30 | import android.graphics.drawable.TransitionDrawable; |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 31 | import android.util.AttributeSet; |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 32 | import android.view.View; |
| 33 | import android.view.animation.AccelerateInterpolator; |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 34 | import android.view.animation.TranslateAnimation; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 35 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 36 | import com.android.launcher.R; |
| 37 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 38 | public class DeleteZone extends IconDropTarget { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | private static final int ORIENTATION_HORIZONTAL = 1; |
| 40 | private static final int TRANSITION_DURATION = 250; |
| 41 | private static final int ANIMATION_DURATION = 200; |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 42 | private static final int XLARGE_TRANSITION_DURATION = 150; |
| 43 | private static final int XLARGE_ANIMATION_DURATION = 200; |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 44 | private static final int LEFT_DRAWABLE = 0; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 45 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 46 | private AnimatorSet mInAnimation; |
| 47 | private AnimatorSet mOutAnimation; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | |
| 49 | private int mOrientation; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 50 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 52 | private final RectF mRegionF = new RectF(); |
| 53 | private final Rect mRegion = new Rect(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | private TransitionDrawable mTransition; |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 55 | private int mTextColor; |
| 56 | private int mDragTextColor; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 57 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 58 | public DeleteZone(Context context, AttributeSet attrs) { |
| 59 | this(context, attrs, 0); |
| 60 | } |
| 61 | |
| 62 | public DeleteZone(Context context, AttributeSet attrs, int defStyle) { |
| 63 | super(context, attrs, defStyle); |
| 64 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 65 | final int srcColor = context.getResources().getColor(R.color.delete_color_filter); |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 66 | mHoverPaint.setColorFilter(new PorterDuffColorFilter(srcColor, PorterDuff.Mode.SRC_ATOP)); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 67 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 68 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeleteZone, defStyle, 0); |
| 69 | mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL); |
| 70 | a.recycle(); |
Winson Chung | be5212b | 2010-12-20 11:36:33 -0800 | [diff] [blame] | 71 | |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 72 | if (LauncherApplication.isScreenXLarge()) { |
| 73 | int tb = getResources().getDimensionPixelSize( |
| 74 | R.dimen.delete_zone_vertical_drag_padding); |
| 75 | int lr = getResources().getDimensionPixelSize( |
| 76 | R.dimen.delete_zone_horizontal_drag_padding); |
| 77 | setDragPadding(tb, lr, tb, lr); |
| 78 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
| 82 | protected void onFinishInflate() { |
| 83 | super.onFinishInflate(); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 84 | mTransition = (TransitionDrawable) getCompoundDrawables()[LEFT_DRAWABLE]; |
| 85 | if (LauncherApplication.isScreenXLarge()) { |
| 86 | mTransition.setCrossFadeEnabled(false); |
| 87 | } |
| 88 | |
| 89 | Resources r = getResources(); |
| 90 | mTextColor = r.getColor(R.color.workspace_all_apps_and_delete_zone_text_color); |
| 91 | mDragTextColor = r.getColor(R.color.workspace_delete_zone_drag_text_color); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | 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] | 95 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 96 | return true; |
| 97 | } |
| 98 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 99 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 100 | DragView dragView, Object dragInfo) { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 101 | if (!mDragAndDropEnabled) return; |
| 102 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 103 | final ItemInfo item = (ItemInfo) dragInfo; |
| 104 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 105 | // On x-large screens, you can uninstall an app by dragging from all apps |
| 106 | if (item instanceof ApplicationInfo && LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 107 | mLauncher.startApplicationUninstallActivity((ApplicationInfo) item); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 108 | } |
| 109 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | if (item.container == -1) return; |
| 111 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 112 | if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 113 | if (item instanceof LauncherAppWidgetInfo) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 114 | mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 115 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 116 | } else if (source instanceof UserFolder) { |
| 117 | final UserFolder userFolder = (UserFolder) source; |
| 118 | final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo(); |
| 119 | // Item must be a ShortcutInfo otherwise it couldn't have been in the folder |
| 120 | // in the first place. |
| 121 | userFolderInfo.remove((ShortcutInfo)item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 123 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | if (item instanceof UserFolderInfo) { |
| 125 | final UserFolderInfo userFolderInfo = (UserFolderInfo)item; |
| 126 | LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 127 | mLauncher.removeFolder(userFolderInfo); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 128 | } else if (item instanceof LauncherAppWidgetInfo) { |
| 129 | final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; |
| 130 | final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); |
| 131 | if (appWidgetHost != null) { |
Brad Fitzpatrick | 73013bf | 2010-09-14 12:15:32 -0700 | [diff] [blame] | 132 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 133 | // to the caller... |
| 134 | new Thread("deleteAppWidgetId") { |
| 135 | public void run() { |
| 136 | appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); |
| 137 | } |
| 138 | }.start(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | } |
| 140 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 141 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 142 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
| 143 | } |
| 144 | |
| 145 | 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] | 146 | DragView dragView, Object dragInfo) { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 147 | if (mDragAndDropEnabled) { |
| 148 | mTransition.reverseTransition(getTransitionAnimationDuration()); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 149 | setTextColor(mDragTextColor); |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 150 | super.onDragEnter(source, x, y, xOffset, yOffset, dragView, dragInfo); |
| 151 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | 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] | 155 | DragView dragView, Object dragInfo) { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 156 | if (mDragAndDropEnabled) { |
| 157 | mTransition.reverseTransition(getTransitionAnimationDuration()); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 158 | setTextColor(mTextColor); |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 159 | super.onDragExit(source, x, y, xOffset, yOffset, dragView, dragInfo); |
| 160 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 163 | public void onDragStart(DragSource source, Object info, int dragAction) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 164 | final ItemInfo item = (ItemInfo) info; |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 165 | if (item != null && mDragAndDropEnabled) { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 166 | mActive = true; |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 167 | getHitRect(mRegion); |
| 168 | mRegionF.set(mRegion); |
| 169 | |
| 170 | if (LauncherApplication.isScreenXLarge()) { |
| 171 | // This region will be a "dead zone" for scrolling; make it extend to the edge of |
| 172 | // the screen so users don't accidentally trigger a scroll while deleting items |
| 173 | mRegionF.top = mLauncher.getWorkspace().getTop(); |
| 174 | mRegionF.right = mLauncher.getWorkspace().getRight(); |
| 175 | } |
| 176 | |
| 177 | mDragController.setDeleteRegion(mRegionF); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 178 | |
| 179 | // 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] | 180 | mTransition.resetTransition(); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 181 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 182 | createAnimations(); |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 183 | mInAnimation.start(); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 184 | if (mOverlappingViews != null) { |
| 185 | for (View view : mOverlappingViews) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 186 | createOutAlphaAnim(view).start(); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 187 | } |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 188 | } |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 189 | setVisibility(VISIBLE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | public void onDragEnd() { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 194 | if (mActive && mDragAndDropEnabled) { |
| 195 | mActive = false; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 196 | mDragController.setDeleteRegion(null); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 197 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 198 | mOutAnimation.start(); |
| 199 | if (mOverlappingViews != null) { |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 200 | for (View view : mOverlappingViews) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 201 | createInAlphaAnim(view).start(); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 202 | } |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 203 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 207 | private Animator createAlphaAnim(View v, float start, float end) { |
| 208 | Animator anim = ObjectAnimator.ofFloat(v, "alpha", start, end); |
| 209 | anim.setDuration(getAnimationDuration()); |
| 210 | return anim; |
| 211 | } |
| 212 | private Animator createInAlphaAnim(View v) { |
| 213 | return createAlphaAnim(v, 0f, 1f); |
| 214 | } |
| 215 | private Animator createOutAlphaAnim(View v) { |
| 216 | return createAlphaAnim(v, 1f, 0f); |
| 217 | } |
| 218 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 219 | private void createAnimations() { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 220 | int duration = getAnimationDuration(); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 221 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 222 | Animator inAlphaAnim = createInAlphaAnim(this); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 223 | if (mInAnimation == null) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 224 | mInAnimation = new AnimatorSet(); |
| 225 | mInAnimation.setInterpolator(new AccelerateInterpolator()); |
| 226 | mInAnimation.setDuration(duration); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 227 | if (!LauncherApplication.isScreenXLarge()) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 228 | Animator translateAnim; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 229 | if (mOrientation == ORIENTATION_HORIZONTAL) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 230 | translateAnim = ObjectAnimator.ofFloat(this, "translationY", |
| 231 | getMeasuredWidth(), 0f); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 232 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 233 | translateAnim = ObjectAnimator.ofFloat(this, "translationX", |
| 234 | getMeasuredHeight(), 0f); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 235 | } |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 236 | mInAnimation.playTogether(translateAnim, inAlphaAnim); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 237 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 238 | mInAnimation.play(inAlphaAnim); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 239 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 240 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 241 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 242 | Animator outAlphaAnim = createOutAlphaAnim(this); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 243 | if (mOutAnimation == null) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 244 | mOutAnimation = new AnimatorSet(); |
| 245 | mOutAnimation.setInterpolator(new AccelerateInterpolator()); |
| 246 | mOutAnimation.setDuration(duration); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 247 | if (!LauncherApplication.isScreenXLarge()) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 248 | Animator translateAnim; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 249 | if (mOrientation == ORIENTATION_HORIZONTAL) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 250 | translateAnim = ObjectAnimator.ofFloat(this, "translationY", 0f, |
| 251 | getMeasuredWidth()); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 252 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 253 | translateAnim = ObjectAnimator.ofFloat(this, "translationX", 0f, |
| 254 | getMeasuredHeight()); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 255 | } |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 256 | mOutAnimation.playTogether(translateAnim, outAlphaAnim); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 257 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 258 | mOutAnimation.addListener(new AnimatorListenerAdapter() { |
| 259 | public void onAnimationEnd(Animator animation) { |
| 260 | setVisibility(GONE); |
| 261 | } |
| 262 | }); |
| 263 | mOutAnimation.play(outAlphaAnim); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 268 | void setDragController(DragController dragController) { |
| 269 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 272 | private int getTransitionAnimationDuration() { |
| 273 | return LauncherApplication.isScreenXLarge() ? |
| 274 | XLARGE_TRANSITION_DURATION : TRANSITION_DURATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 277 | private int getAnimationDuration() { |
| 278 | return LauncherApplication.isScreenXLarge() ? |
| 279 | XLARGE_ANIMATION_DURATION : ANIMATION_DURATION; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 280 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 281 | } |