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 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 21 | import android.animation.ValueAnimator; |
| 22 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.res.Resources; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 25 | import android.graphics.Canvas; |
Adam Cohen | f4b0891 | 2011-05-17 18:45:47 -0700 | [diff] [blame] | 26 | import android.graphics.Color; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 27 | import android.graphics.PorterDuff; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
| 29 | import android.util.AttributeSet; |
| 30 | import android.view.LayoutInflater; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 31 | import android.view.View; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | import android.view.ViewGroup; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
| 34 | import android.widget.TextView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 36 | import com.android.launcher.R; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 37 | import com.android.launcher2.DropTarget.DragObject; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 38 | import com.android.launcher2.FolderInfo.FolderListener; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 39 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 40 | import java.util.ArrayList; |
| 41 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | /** |
| 43 | * An icon that can appear on in the workspace representing an {@link UserFolder}. |
| 44 | */ |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 45 | public class FolderIcon extends FrameLayout implements FolderListener { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 46 | private Launcher mLauncher; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 47 | Folder mFolder; |
| 48 | FolderInfo mInfo; |
| 49 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 50 | // The number of icons to display in the |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 51 | private static final int NUM_ITEMS_IN_PREVIEW = 4; |
Adam Cohen | f4b0891 | 2011-05-17 18:45:47 -0700 | [diff] [blame] | 52 | private static final int CONSUMPTION_ANIMATION_DURATION = 100; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 53 | |
| 54 | // The degree to which the inner ring grows when accepting drop |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 55 | private static final float INNER_RING_GROWTH_FACTOR = 0.1f; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 56 | |
| 57 | // The degree to which the inner ring is scaled in its natural state |
Adam Cohen | f4b0891 | 2011-05-17 18:45:47 -0700 | [diff] [blame] | 58 | private static final float INNER_RING_BASELINE_SCALE = 1.0f; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 59 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 60 | // The degree to which the outer ring grows when accepting drop |
| 61 | private static final float OUTER_RING_BASELINE_SCALE = 0.7f; |
| 62 | |
| 63 | // The degree to which the outer ring is scaled in its natural state |
| 64 | private static final float OUTER_RING_GROWTH_FACTOR = 0.3f; |
| 65 | |
| 66 | // The amount of vertical spread between items in the stack [0...1] |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 67 | private static final float PERSPECTIVE_SHIFT_FACTOR = 0.3f; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 68 | |
| 69 | // The degree to which the item in the back of the stack is scaled [0...1] |
| 70 | // (0 means it's not scaled at all, 1 means it's scaled to nothing) |
| 71 | private static final float PERSPECTIVE_SCALE_FACTOR = 0.3f; |
| 72 | |
| 73 | // The percentage of the FolderIcons view that will be dedicated to the items preview |
| 74 | private static final float SPACE_PERCENTAGE_FOR_ICONS = 0.8f; |
| 75 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 76 | private int mOriginalWidth = -1; |
| 77 | private int mOriginalHeight = -1; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 78 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 79 | FolderRingAnimator mFolderRingAnimator = null; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 80 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 81 | public FolderIcon(Context context, AttributeSet attrs) { |
| 82 | super(context, attrs); |
| 83 | } |
| 84 | |
| 85 | public FolderIcon(Context context) { |
| 86 | super(context); |
| 87 | } |
| 88 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 89 | public boolean isDropEnabled() { |
Winson Chung | 7a1d165 | 2011-03-18 15:56:01 -0700 | [diff] [blame] | 90 | final ViewGroup cellLayoutChildren = (ViewGroup) getParent(); |
| 91 | final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent(); |
| 92 | final Workspace workspace = (Workspace) cellLayout.getParent(); |
| 93 | return !workspace.isSmall(); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 94 | } |
| 95 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 96 | static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group, |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 97 | FolderInfo folderInfo, IconCache iconCache) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 98 | |
| 99 | FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false); |
| 100 | |
| 101 | final Resources resources = launcher.getResources(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 102 | Drawable d = iconCache.getFullResIcon(resources, R.drawable.portal_ring_inner_holo); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 103 | icon.setBackgroundDrawable(d); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 104 | icon.setTag(folderInfo); |
| 105 | icon.setOnClickListener(launcher); |
| 106 | icon.mInfo = folderInfo; |
| 107 | icon.mLauncher = launcher; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 108 | |
| 109 | Folder folder = Folder.fromXml(launcher); |
| 110 | folder.setDragController(launcher.getDragController()); |
| 111 | folder.setLauncher(launcher); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 112 | folder.setFolderIcon(icon); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 113 | folder.bind(folderInfo); |
| 114 | icon.mFolder = folder; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 115 | icon.mFolderRingAnimator = new FolderRingAnimator(launcher, icon); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 116 | folderInfo.addListener(icon); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 117 | |
| 118 | return icon; |
| 119 | } |
| 120 | |
| 121 | public static class FolderRingAnimator { |
| 122 | public int mFolderLocX; |
| 123 | public int mFolderLocY; |
| 124 | public float mOuterRingScale; |
| 125 | public float mInnerRingScale; |
| 126 | public FolderIcon mFolderIcon = null; |
| 127 | private Launcher mLauncher; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 128 | public Drawable mOuterRingDrawable = null; |
| 129 | public Drawable mInnerRingDrawable = null; |
| 130 | public static Drawable sSharedOuterRingDrawable = null; |
| 131 | public static Drawable sSharedInnerRingDrawable = null; |
| 132 | private ValueAnimator mAcceptAnimator; |
| 133 | private ValueAnimator mNeutralAnimator; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 134 | |
| 135 | public FolderRingAnimator(Launcher launcher, FolderIcon folderIcon) { |
| 136 | mLauncher = launcher; |
| 137 | mFolderIcon = folderIcon; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 138 | mOuterRingDrawable = |
| 139 | launcher.getResources().getDrawable(R.drawable.portal_ring_outer_holo); |
| 140 | mInnerRingDrawable = |
| 141 | launcher.getResources().getDrawable(R.drawable.portal_ring_inner_holo); |
| 142 | if (sSharedOuterRingDrawable == null) { |
| 143 | sSharedOuterRingDrawable = |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 144 | launcher.getResources().getDrawable(R.drawable.portal_ring_outer_holo); |
| 145 | } |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 146 | if (sSharedInnerRingDrawable == null) { |
| 147 | sSharedInnerRingDrawable = |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 148 | launcher.getResources().getDrawable(R.drawable.portal_ring_inner_holo); |
| 149 | } |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 150 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 151 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 152 | // Location is expressed in window coordinates |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 153 | public void setLocation(int x, int y) { |
| 154 | mFolderLocX = x; |
| 155 | mFolderLocY = y; |
Adam Cohen | f4b0891 | 2011-05-17 18:45:47 -0700 | [diff] [blame] | 156 | } |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 157 | |
| 158 | public void animateToAcceptState() { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 159 | if (mNeutralAnimator != null) { |
| 160 | mNeutralAnimator.cancel(); |
| 161 | } |
| 162 | mAcceptAnimator = ValueAnimator.ofFloat(0f, 1f); |
| 163 | mAcceptAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION); |
| 164 | mAcceptAnimator.addUpdateListener(new AnimatorUpdateListener() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 165 | public void onAnimationUpdate(ValueAnimator animation) { |
| 166 | final float percent = (Float) animation.getAnimatedValue(); |
| 167 | mOuterRingScale = OUTER_RING_BASELINE_SCALE + percent * OUTER_RING_GROWTH_FACTOR; |
| 168 | mInnerRingScale = INNER_RING_BASELINE_SCALE + percent * INNER_RING_GROWTH_FACTOR; |
| 169 | mLauncher.getWorkspace().invalidate(); |
| 170 | if (mFolderIcon != null) { |
| 171 | mFolderIcon.invalidate(); |
| 172 | } |
| 173 | } |
| 174 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 175 | mAcceptAnimator.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 176 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 177 | public void onAnimationStart(Animator animation) { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 178 | if (mFolderIcon != null) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 179 | mFolderIcon.setBackgroundDrawable(null); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 183 | mAcceptAnimator.start(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | public void animateToNaturalState() { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 187 | if (mAcceptAnimator != null) { |
| 188 | mAcceptAnimator.cancel(); |
| 189 | } |
| 190 | mNeutralAnimator = ValueAnimator.ofFloat(0f, 1f); |
| 191 | mNeutralAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION); |
| 192 | mNeutralAnimator.addUpdateListener(new AnimatorUpdateListener() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 193 | public void onAnimationUpdate(ValueAnimator animation) { |
| 194 | final float percent = (Float) animation.getAnimatedValue(); |
| 195 | mOuterRingScale = OUTER_RING_BASELINE_SCALE + OUTER_RING_GROWTH_FACTOR |
| 196 | - percent * OUTER_RING_GROWTH_FACTOR; |
| 197 | mInnerRingScale = INNER_RING_BASELINE_SCALE + INNER_RING_GROWTH_FACTOR |
| 198 | - percent * INNER_RING_GROWTH_FACTOR; |
| 199 | mLauncher.getWorkspace().invalidate(); |
| 200 | if (mFolderIcon != null) { |
| 201 | mFolderIcon.invalidate(); |
| 202 | } |
| 203 | } |
| 204 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 205 | mNeutralAnimator.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 206 | @Override |
| 207 | public void onAnimationEnd(Animator animation) { |
| 208 | if (mFolderIcon != null) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 209 | mFolderIcon.setBackgroundDrawable(mInnerRingDrawable); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 210 | } |
| 211 | mLauncher.getWorkspace().hideFolderAccept(FolderRingAnimator.this); |
| 212 | } |
| 213 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 214 | mNeutralAnimator.start(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 217 | // Location is expressed in window coordinates |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 218 | public void getLocation(int[] loc) { |
| 219 | loc[0] = mFolderLocX; |
| 220 | loc[1] = mFolderLocY; |
| 221 | } |
| 222 | |
| 223 | public float getOuterRingScale() { |
| 224 | return mOuterRingScale; |
| 225 | } |
| 226 | |
| 227 | public float getInnerRingScale() { |
| 228 | return mInnerRingScale; |
| 229 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 232 | private boolean willAcceptItem(ItemInfo item) { |
| 233 | final int itemType = item.itemType; |
| 234 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 235 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && |
| 236 | !mFolder.isFull() && item != mInfo); |
| 237 | } |
| 238 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 239 | public boolean acceptDrop(Object dragInfo) { |
| 240 | final ItemInfo item = (ItemInfo) dragInfo; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 241 | return willAcceptItem(item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 244 | public void addItem(ShortcutInfo item) { |
| 245 | mInfo.add(item); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 246 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 249 | void saveState(CellLayout.LayoutParams lp) { |
| 250 | mOriginalWidth = lp.width; |
| 251 | mOriginalHeight = lp.height; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 254 | private void determineFolderLocationInWorkspace() { |
| 255 | int tvLocation[] = new int[2]; |
| 256 | int wsLocation[] = new int[2]; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 257 | getLocationInWindow(tvLocation); |
| 258 | mLauncher.getWorkspace().getLocationInWindow(wsLocation); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 259 | |
| 260 | int x = tvLocation[0] - wsLocation[0] + getMeasuredWidth() / 2; |
| 261 | int y = tvLocation[1] - wsLocation[1] + getMeasuredHeight() / 2; |
| 262 | mFolderRingAnimator.setLocation(x, y); |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 265 | public void onDragEnter(Object dragInfo) { |
| 266 | if (!willAcceptItem((ItemInfo) dragInfo)) return; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 267 | determineFolderLocationInWorkspace(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 268 | mLauncher.getWorkspace().showFolderAccept(mFolderRingAnimator); |
| 269 | mFolderRingAnimator.animateToAcceptState(); |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 272 | public void onDragOver(Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 275 | public void onDragExit(Object dragInfo) { |
| 276 | if (!willAcceptItem((ItemInfo) dragInfo)) return; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 277 | mFolderRingAnimator.animateToNaturalState(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 278 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 279 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 280 | public void onDrop(Object dragInfo) { |
| 281 | ShortcutInfo item; |
| 282 | if (dragInfo instanceof ApplicationInfo) { |
| 283 | // Came from all apps -- make a copy |
| 284 | item = ((ApplicationInfo) dragInfo).makeShortcut(); |
| 285 | } else { |
| 286 | item = (ShortcutInfo) dragInfo; |
| 287 | } |
| 288 | item.cellX = -1; |
| 289 | item.cellY = -1; |
| 290 | addItem(item); |
| 291 | } |
| 292 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 293 | public DropTarget getDropTargetDelegate(DragObject d) { |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 294 | return null; |
| 295 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 296 | |
| 297 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 298 | protected void dispatchDraw(Canvas canvas) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 299 | if (mFolder == null) return; |
| 300 | if (mFolder.getItemCount() == 0) return; |
| 301 | |
| 302 | canvas.save(); |
| 303 | TextView v = (TextView) mFolder.getItemAt(0); |
| 304 | Drawable d = v.getCompoundDrawables()[1]; |
| 305 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 306 | if (mOriginalWidth < 0 || mOriginalHeight < 0) { |
| 307 | mOriginalWidth = getMeasuredWidth(); |
| 308 | mOriginalHeight = getMeasuredHeight(); |
| 309 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 310 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 311 | int unscaledHeight = (int) (d.getIntrinsicHeight() * (1 + PERSPECTIVE_SHIFT_FACTOR)); |
| 312 | float baselineIconScale = SPACE_PERCENTAGE_FOR_ICONS / (unscaledHeight / (mOriginalHeight * 1.0f)); |
| 313 | |
| 314 | int baselineHeight = (int) (d.getIntrinsicHeight() * baselineIconScale); |
| 315 | int totalStackHeight = (int) (baselineHeight * (1 + PERSPECTIVE_SHIFT_FACTOR)); |
| 316 | int baselineWidth = (int) (d.getIntrinsicWidth() * baselineIconScale); |
| 317 | float maxPerpectiveShift = baselineHeight * PERSPECTIVE_SHIFT_FACTOR; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 318 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 319 | ArrayList<View> items = mFolder.getItemsInReadingOrder(false); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 320 | int firstItemIndex = Math.max(0, items.size() - NUM_ITEMS_IN_PREVIEW); |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 321 | |
| 322 | int xShift = (int) (mOriginalWidth - baselineWidth) / 2; |
| 323 | int yShift = (int) (mOriginalHeight - totalStackHeight) / 2; |
| 324 | canvas.translate(xShift, yShift); |
Adam Cohen | 4dbe6d9 | 2011-05-18 17:14:15 -0700 | [diff] [blame] | 325 | for (int i = firstItemIndex; i < items.size(); i++) { |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 326 | int index = i - firstItemIndex; |
| 327 | index += Math.max(0, NUM_ITEMS_IN_PREVIEW - items.size()); |
| 328 | |
| 329 | float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1); |
| 330 | float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r)); |
| 331 | r = (float) Math.pow(r, 2); |
| 332 | |
| 333 | float transY = r * maxPerpectiveShift; |
| 334 | float transX = (1 - scale) * baselineWidth / 2.0f; |
| 335 | |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 336 | v = (TextView) items.get(i); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 337 | d = v.getCompoundDrawables()[1]; |
| 338 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 339 | canvas.save(); |
| 340 | canvas.translate(transX, transY); |
| 341 | canvas.scale(baselineIconScale * scale, baselineIconScale * scale); |
Adam Cohen | f4b0891 | 2011-05-17 18:45:47 -0700 | [diff] [blame] | 342 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 343 | int overlayAlpha = (int) (80 * (1 - r)); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 344 | if (d != null) { |
| 345 | d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 346 | d.setColorFilter(Color.argb(overlayAlpha, 0, 0, 0), PorterDuff.Mode.SRC_ATOP); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 347 | d.draw(canvas); |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 348 | d.clearColorFilter(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 349 | } |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 350 | canvas.restore(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 351 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 352 | canvas.restore(); |
| 353 | } |
| 354 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 355 | public void onItemsChanged() { |
| 356 | invalidate(); |
| 357 | requestLayout(); |
| 358 | } |
| 359 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 360 | public void onAdd(ShortcutInfo item) { |
| 361 | invalidate(); |
| 362 | requestLayout(); |
| 363 | } |
| 364 | |
| 365 | public void onRemove(ShortcutInfo item) { |
| 366 | invalidate(); |
| 367 | requestLayout(); |
| 368 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 369 | } |