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