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; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 36 | import com.android.launcher2.DropTarget.DragObject; |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 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 | |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 72 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 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]; |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 85 | if (LauncherApplication.isScreenLarge()) { |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 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 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 94 | public boolean acceptDrop(DragObject d) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 95 | return true; |
| 96 | } |
| 97 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 98 | public void onDrop(DragObject d) { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 99 | if (!mDragAndDropEnabled) return; |
| 100 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 101 | final ItemInfo item = (ItemInfo) d.dragInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 104 | if (item instanceof ApplicationInfo && LauncherApplication.isScreenLarge()) { |
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 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 114 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 115 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 116 | if (item instanceof FolderInfo) { |
| 117 | final FolderInfo folderInfo = (FolderInfo)item; |
| 118 | LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo); |
| 119 | mLauncher.removeFolder(folderInfo); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 120 | } else if (item instanceof LauncherAppWidgetInfo) { |
| 121 | final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; |
| 122 | final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); |
| 123 | if (appWidgetHost != null) { |
Brad Fitzpatrick | 73013bf | 2010-09-14 12:15:32 -0700 | [diff] [blame] | 124 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 125 | // to the caller... |
| 126 | new Thread("deleteAppWidgetId") { |
| 127 | public void run() { |
| 128 | appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); |
| 129 | } |
| 130 | }.start(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 131 | } |
| 132 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 133 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 134 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
| 135 | } |
| 136 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 137 | public void onDragEnter(DragObject d) { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 138 | if (mDragAndDropEnabled) { |
| 139 | mTransition.reverseTransition(getTransitionAnimationDuration()); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 140 | setTextColor(mDragTextColor); |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 141 | super.onDragEnter(d); |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 142 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 145 | public void onDragExit(DragObject d) { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 146 | if (mDragAndDropEnabled) { |
| 147 | mTransition.reverseTransition(getTransitionAnimationDuration()); |
Michael Jurka | 577d017 | 2010-12-17 20:04:50 -0800 | [diff] [blame] | 148 | setTextColor(mTextColor); |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame^] | 149 | super.onDragExit(d); |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 150 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 153 | public void onDragStart(DragSource source, Object info, int dragAction) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 154 | final ItemInfo item = (ItemInfo) info; |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 155 | if (item != null && mDragAndDropEnabled) { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 156 | mActive = true; |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 157 | getHitRect(mRegion); |
| 158 | mRegionF.set(mRegion); |
| 159 | |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 160 | if (LauncherApplication.isScreenLarge()) { |
Michael Jurka | 3adcb0c | 2010-10-15 18:07:21 -0700 | [diff] [blame] | 161 | // This region will be a "dead zone" for scrolling; make it extend to the edge of |
| 162 | // the screen so users don't accidentally trigger a scroll while deleting items |
| 163 | mRegionF.top = mLauncher.getWorkspace().getTop(); |
| 164 | mRegionF.right = mLauncher.getWorkspace().getRight(); |
| 165 | } |
| 166 | |
| 167 | mDragController.setDeleteRegion(mRegionF); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 168 | |
| 169 | // 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] | 170 | mTransition.resetTransition(); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 171 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 172 | createAnimations(); |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 173 | mInAnimation.start(); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 174 | if (mOverlappingViews != null) { |
| 175 | for (View view : mOverlappingViews) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 176 | createOutAlphaAnim(view).start(); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 177 | } |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 178 | } |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 179 | setVisibility(VISIBLE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | public void onDragEnd() { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 184 | if (mActive && mDragAndDropEnabled) { |
| 185 | mActive = false; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 186 | mDragController.setDeleteRegion(null); |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 187 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 188 | mOutAnimation.start(); |
| 189 | if (mOverlappingViews != null) { |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 190 | for (View view : mOverlappingViews) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 191 | createInAlphaAnim(view).start(); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 192 | } |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 193 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 197 | private Animator createAlphaAnim(View v, float start, float end) { |
| 198 | Animator anim = ObjectAnimator.ofFloat(v, "alpha", start, end); |
| 199 | anim.setDuration(getAnimationDuration()); |
| 200 | return anim; |
| 201 | } |
| 202 | private Animator createInAlphaAnim(View v) { |
| 203 | return createAlphaAnim(v, 0f, 1f); |
| 204 | } |
| 205 | private Animator createOutAlphaAnim(View v) { |
| 206 | return createAlphaAnim(v, 1f, 0f); |
| 207 | } |
| 208 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 209 | private void createAnimations() { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 210 | int duration = getAnimationDuration(); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 211 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 212 | Animator inAlphaAnim = createInAlphaAnim(this); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 213 | if (mInAnimation == null) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 214 | mInAnimation = new AnimatorSet(); |
| 215 | mInAnimation.setInterpolator(new AccelerateInterpolator()); |
| 216 | mInAnimation.setDuration(duration); |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 217 | if (!LauncherApplication.isScreenLarge()) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 218 | Animator translateAnim; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 219 | if (mOrientation == ORIENTATION_HORIZONTAL) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 220 | translateAnim = ObjectAnimator.ofFloat(this, "translationY", |
| 221 | getMeasuredWidth(), 0f); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 222 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 223 | translateAnim = ObjectAnimator.ofFloat(this, "translationX", |
| 224 | getMeasuredHeight(), 0f); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 225 | } |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 226 | mInAnimation.playTogether(translateAnim, inAlphaAnim); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 227 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 228 | mInAnimation.play(inAlphaAnim); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 229 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 230 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 231 | |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 232 | Animator outAlphaAnim = createOutAlphaAnim(this); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 233 | if (mOutAnimation == null) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 234 | mOutAnimation = new AnimatorSet(); |
| 235 | mOutAnimation.setInterpolator(new AccelerateInterpolator()); |
| 236 | mOutAnimation.setDuration(duration); |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 237 | if (!LauncherApplication.isScreenLarge()) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 238 | Animator translateAnim; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 239 | if (mOrientation == ORIENTATION_HORIZONTAL) { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 240 | translateAnim = ObjectAnimator.ofFloat(this, "translationY", 0f, |
| 241 | getMeasuredWidth()); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 242 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 243 | translateAnim = ObjectAnimator.ofFloat(this, "translationX", 0f, |
| 244 | getMeasuredHeight()); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 245 | } |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 246 | mOutAnimation.playTogether(translateAnim, outAlphaAnim); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 247 | } else { |
Winson Chung | c5536bf | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 248 | mOutAnimation.addListener(new AnimatorListenerAdapter() { |
| 249 | public void onAnimationEnd(Animator animation) { |
| 250 | setVisibility(GONE); |
| 251 | } |
| 252 | }); |
| 253 | mOutAnimation.play(outAlphaAnim); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 258 | void setDragController(DragController dragController) { |
| 259 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 262 | private int getTransitionAnimationDuration() { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 263 | return LauncherApplication.isScreenLarge() ? |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 264 | XLARGE_TRANSITION_DURATION : TRANSITION_DURATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 267 | private int getAnimationDuration() { |
Michael Jurka | a2eb170 | 2011-05-12 14:57:05 -0700 | [diff] [blame] | 268 | return LauncherApplication.isScreenLarge() ? |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 269 | XLARGE_ANIMATION_DURATION : ANIMATION_DURATION; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 270 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 271 | } |