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; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -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.drawable.Drawable; |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 30 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.util.AttributeSet; |
| 32 | import android.view.LayoutInflater; |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 33 | import android.view.MotionEvent; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 34 | import android.view.View; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | import android.view.ViewGroup; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 36 | import android.view.animation.AccelerateInterpolator; |
| 37 | import android.view.animation.DecelerateInterpolator; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 38 | import android.widget.ImageView; |
| 39 | import android.widget.LinearLayout; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 40 | import android.widget.TextView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 42 | import com.android.launcher.R; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 43 | import com.android.launcher2.DropTarget.DragObject; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 44 | import com.android.launcher2.FolderInfo.FolderListener; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 45 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 46 | import java.util.ArrayList; |
| 47 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | /** |
| 49 | * An icon that can appear on in the workspace representing an {@link UserFolder}. |
| 50 | */ |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 51 | public class FolderIcon extends LinearLayout implements FolderListener { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | private Launcher mLauncher; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 53 | Folder mFolder; |
| 54 | FolderInfo mInfo; |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 55 | private static boolean sStaticValuesDirty = true; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 56 | |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 57 | private CheckLongPressHelper mLongPressHelper; |
| 58 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 59 | // The number of icons to display in the |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 60 | private static final int NUM_ITEMS_IN_PREVIEW = 3; |
Adam Cohen | f4b0891 | 2011-05-17 18:45:47 -0700 | [diff] [blame] | 61 | private static final int CONSUMPTION_ANIMATION_DURATION = 100; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 62 | private static final int DROP_IN_ANIMATION_DURATION = 400; |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 63 | private static final int INITIAL_ITEM_ANIMATION_DURATION = 350; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 64 | |
| 65 | // The degree to which the inner ring grows when accepting drop |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 66 | private static final float INNER_RING_GROWTH_FACTOR = 0.15f; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 67 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 68 | // The degree to which the outer ring is scaled in its natural state |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 69 | private static final float OUTER_RING_GROWTH_FACTOR = 0.3f; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 70 | |
| 71 | // The amount of vertical spread between items in the stack [0...1] |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 72 | private static final float PERSPECTIVE_SHIFT_FACTOR = 0.24f; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 73 | |
| 74 | // The degree to which the item in the back of the stack is scaled [0...1] |
| 75 | // (0 means it's not scaled at all, 1 means it's scaled to nothing) |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 76 | private static final float PERSPECTIVE_SCALE_FACTOR = 0.35f; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 77 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 78 | public static Drawable sSharedFolderLeaveBehind = null; |
| 79 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 80 | private ImageView mPreviewBackground; |
| 81 | private BubbleTextView mFolderName; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 82 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 83 | FolderRingAnimator mFolderRingAnimator = null; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 84 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 85 | // These variables are all associated with the drawing of the preview; they are stored |
| 86 | // as member variables for shared usage and to avoid computation on each frame |
| 87 | private int mIntrinsicIconSize; |
| 88 | private float mBaselineIconScale; |
| 89 | private int mBaselineIconSize; |
| 90 | private int mAvailableSpaceInPreview; |
| 91 | private int mTotalWidth = -1; |
| 92 | private int mPreviewOffsetX; |
| 93 | private int mPreviewOffsetY; |
| 94 | private float mMaxPerspectiveShift; |
| 95 | boolean mAnimating = false; |
| 96 | private PreviewItemDrawingParams mParams = new PreviewItemDrawingParams(0, 0, 0, 0); |
| 97 | private PreviewItemDrawingParams mAnimParams = new PreviewItemDrawingParams(0, 0, 0, 0); |
| 98 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 99 | public FolderIcon(Context context, AttributeSet attrs) { |
| 100 | super(context, attrs); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 101 | init(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | public FolderIcon(Context context) { |
| 105 | super(context); |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 106 | init(); |
| 107 | } |
| 108 | |
| 109 | private void init() { |
| 110 | mLongPressHelper = new CheckLongPressHelper(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 113 | public boolean isDropEnabled() { |
Winson Chung | 7a1d165 | 2011-03-18 15:56:01 -0700 | [diff] [blame] | 114 | final ViewGroup cellLayoutChildren = (ViewGroup) getParent(); |
| 115 | final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent(); |
| 116 | final Workspace workspace = (Workspace) cellLayout.getParent(); |
| 117 | return !workspace.isSmall(); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 118 | } |
| 119 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 120 | static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group, |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 121 | FolderInfo folderInfo, IconCache iconCache) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 123 | if (INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION) { |
| 124 | throw new IllegalStateException("DROP_IN_ANIMATION_DURATION must be greater than " + |
| 125 | "INITIAL_ITEM_ANIMATION_DURATION, as sequencing of adding first two items " + |
| 126 | "is dependent on this"); |
| 127 | } |
| 128 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 129 | FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false); |
| 130 | |
Adam Cohen | d2eca6b | 2011-07-26 22:49:13 -0700 | [diff] [blame] | 131 | icon.mFolderName = (BubbleTextView) icon.findViewById(R.id.folder_icon_name); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 132 | icon.mFolderName.setText(folderInfo.title); |
| 133 | icon.mPreviewBackground = (ImageView) icon.findViewById(R.id.preview_background); |
| 134 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | icon.setTag(folderInfo); |
| 136 | icon.setOnClickListener(launcher); |
| 137 | icon.mInfo = folderInfo; |
| 138 | icon.mLauncher = launcher; |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 139 | icon.setContentDescription(String.format(launcher.getString(R.string.folder_name_format), |
| 140 | folderInfo.title)); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 141 | Folder folder = Folder.fromXml(launcher); |
| 142 | folder.setDragController(launcher.getDragController()); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 143 | folder.setFolderIcon(icon); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 144 | folder.bind(folderInfo); |
| 145 | icon.mFolder = folder; |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 146 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 147 | icon.mFolderRingAnimator = new FolderRingAnimator(launcher, icon); |
| 148 | folderInfo.addListener(icon); |
| 149 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 150 | return icon; |
| 151 | } |
| 152 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 153 | @Override |
| 154 | protected Parcelable onSaveInstanceState() { |
| 155 | sStaticValuesDirty = true; |
| 156 | return super.onSaveInstanceState(); |
| 157 | } |
| 158 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 159 | public static class FolderRingAnimator { |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 160 | public int mCellX; |
| 161 | public int mCellY; |
| 162 | private CellLayout mCellLayout; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 163 | public float mOuterRingSize; |
| 164 | public float mInnerRingSize; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 165 | public FolderIcon mFolderIcon = null; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 166 | public Drawable mOuterRingDrawable = null; |
| 167 | public Drawable mInnerRingDrawable = null; |
| 168 | public static Drawable sSharedOuterRingDrawable = null; |
| 169 | public static Drawable sSharedInnerRingDrawable = null; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 170 | public static int sPreviewSize = -1; |
| 171 | public static int sPreviewPadding = -1; |
| 172 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 173 | private ValueAnimator mAcceptAnimator; |
| 174 | private ValueAnimator mNeutralAnimator; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 175 | |
| 176 | public FolderRingAnimator(Launcher launcher, FolderIcon folderIcon) { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 177 | mFolderIcon = folderIcon; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 178 | Resources res = launcher.getResources(); |
| 179 | mOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo); |
| 180 | mInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo); |
| 181 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 182 | // We need to reload the static values when configuration changes in case they are |
| 183 | // different in another configuration |
| 184 | if (sStaticValuesDirty) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 185 | sPreviewSize = res.getDimensionPixelSize(R.dimen.folder_preview_size); |
| 186 | sPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 187 | sSharedOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 188 | sSharedInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo); |
Adam Cohen | df6af57 | 2011-10-19 14:38:16 -0700 | [diff] [blame] | 189 | sSharedFolderLeaveBehind = res.getDrawable(R.drawable.portal_ring_rest); |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 190 | sStaticValuesDirty = false; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 191 | } |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 192 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 193 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 194 | public void animateToAcceptState() { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 195 | if (mNeutralAnimator != null) { |
| 196 | mNeutralAnimator.cancel(); |
| 197 | } |
| 198 | mAcceptAnimator = ValueAnimator.ofFloat(0f, 1f); |
| 199 | mAcceptAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION); |
| 200 | mAcceptAnimator.addUpdateListener(new AnimatorUpdateListener() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 201 | public void onAnimationUpdate(ValueAnimator animation) { |
| 202 | final float percent = (Float) animation.getAnimatedValue(); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 203 | mOuterRingSize = (1 + percent * OUTER_RING_GROWTH_FACTOR) * sPreviewSize; |
| 204 | mInnerRingSize = (1 + percent * INNER_RING_GROWTH_FACTOR) * sPreviewSize; |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 205 | if (mCellLayout != null) { |
| 206 | mCellLayout.invalidate(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 210 | mAcceptAnimator.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 211 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 212 | public void onAnimationStart(Animator animation) { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 213 | if (mFolderIcon != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 214 | mFolderIcon.mPreviewBackground.setVisibility(INVISIBLE); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 218 | mAcceptAnimator.start(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | public void animateToNaturalState() { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 222 | if (mAcceptAnimator != null) { |
| 223 | mAcceptAnimator.cancel(); |
| 224 | } |
| 225 | mNeutralAnimator = ValueAnimator.ofFloat(0f, 1f); |
| 226 | mNeutralAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION); |
| 227 | mNeutralAnimator.addUpdateListener(new AnimatorUpdateListener() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 228 | public void onAnimationUpdate(ValueAnimator animation) { |
| 229 | final float percent = (Float) animation.getAnimatedValue(); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 230 | mOuterRingSize = (1 + (1 - percent) * OUTER_RING_GROWTH_FACTOR) * sPreviewSize; |
| 231 | mInnerRingSize = (1 + (1 - percent) * INNER_RING_GROWTH_FACTOR) * sPreviewSize; |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 232 | if (mCellLayout != null) { |
| 233 | mCellLayout.invalidate(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 237 | mNeutralAnimator.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 238 | @Override |
| 239 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 240 | if (mCellLayout != null) { |
| 241 | mCellLayout.hideFolderAccept(FolderRingAnimator.this); |
| 242 | } |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 243 | if (mFolderIcon != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 244 | mFolderIcon.mPreviewBackground.setVisibility(VISIBLE); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 245 | } |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 246 | } |
| 247 | }); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 248 | mNeutralAnimator.start(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 251 | // Location is expressed in window coordinates |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 252 | public void getCell(int[] loc) { |
| 253 | loc[0] = mCellX; |
| 254 | loc[1] = mCellY; |
| 255 | } |
| 256 | |
| 257 | // Location is expressed in window coordinates |
| 258 | public void setCell(int x, int y) { |
| 259 | mCellX = x; |
| 260 | mCellY = y; |
| 261 | } |
| 262 | |
| 263 | public void setCellLayout(CellLayout layout) { |
| 264 | mCellLayout = layout; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 267 | public float getOuterRingSize() { |
| 268 | return mOuterRingSize; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 271 | public float getInnerRingSize() { |
| 272 | return mInnerRingSize; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 273 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 276 | private boolean willAcceptItem(ItemInfo item) { |
| 277 | final int itemType = item.itemType; |
| 278 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 279 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 280 | !mFolder.isFull() && item != mInfo && !mInfo.opened); |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 283 | public boolean acceptDrop(Object dragInfo) { |
| 284 | final ItemInfo item = (ItemInfo) dragInfo; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 285 | return willAcceptItem(item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 288 | public void addItem(ShortcutInfo item) { |
| 289 | mInfo.add(item); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 290 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 293 | public void onDragEnter(Object dragInfo) { |
| 294 | if (!willAcceptItem((ItemInfo) dragInfo)) return; |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 295 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); |
| 296 | CellLayout layout = (CellLayout) getParent().getParent(); |
| 297 | mFolderRingAnimator.setCell(lp.cellX, lp.cellY); |
| 298 | mFolderRingAnimator.setCellLayout(layout); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 299 | mFolderRingAnimator.animateToAcceptState(); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 300 | layout.showFolderAccept(mFolderRingAnimator); |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 303 | public void onDragOver(Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 306 | public void performCreateAnimation(final ShortcutInfo destInfo, final View destView, |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 307 | final ShortcutInfo srcInfo, final DragView srcView, Rect dstRect, |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 308 | float scaleRelativeToDragLayer, Runnable postAnimationRunnable) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 309 | |
| 310 | Drawable animateDrawable = ((TextView) destView).getCompoundDrawables()[1]; |
| 311 | computePreviewDrawingParams(animateDrawable.getIntrinsicWidth(), destView.getMeasuredWidth()); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 312 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 313 | // This will animate the dragView (srcView) into the new folder |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 314 | onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, postAnimationRunnable, null); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 315 | |
| 316 | // This will animate the first item from it's position as an icon into its |
| 317 | // position as the first item in the preview |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 318 | animateFirstItem(animateDrawable, INITIAL_ITEM_ANIMATION_DURATION); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 319 | |
| 320 | postDelayed(new Runnable() { |
| 321 | public void run() { |
| 322 | addItem(destInfo); |
| 323 | } |
| 324 | }, INITIAL_ITEM_ANIMATION_DURATION); |
| 325 | } |
| 326 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 327 | public void onDragExit(Object dragInfo) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame^] | 328 | onDragExit(); |
| 329 | } |
| 330 | |
| 331 | public void onDragExit() { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 332 | mFolderRingAnimator.animateToNaturalState(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 333 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 334 | |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 335 | private void onDrop(final ShortcutInfo item, DragView animateView, Rect finalRect, |
| 336 | float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable, |
| 337 | DragObject d) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 338 | item.cellX = -1; |
| 339 | item.cellY = -1; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 340 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 341 | // Typically, the animateView corresponds to the DragView; however, if this is being done |
| 342 | // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we |
| 343 | // will not have a view to animate |
| 344 | if (animateView != null) { |
| 345 | DragLayer dragLayer = mLauncher.getDragLayer(); |
| 346 | Rect from = new Rect(); |
| 347 | dragLayer.getViewRectRelativeToSelf(animateView, from); |
| 348 | Rect to = finalRect; |
| 349 | if (to == null) { |
| 350 | to = new Rect(); |
| 351 | Workspace workspace = mLauncher.getWorkspace(); |
| 352 | // Set cellLayout and this to it's final state to compute final animation locations |
| 353 | workspace.setFinalTransitionTransform((CellLayout) getParent().getParent()); |
| 354 | float scaleX = getScaleX(); |
| 355 | float scaleY = getScaleY(); |
| 356 | setScaleX(1.0f); |
| 357 | setScaleY(1.0f); |
| 358 | scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to); |
| 359 | // Finished computing final animation locations, restore current state |
| 360 | setScaleX(scaleX); |
| 361 | setScaleY(scaleY); |
| 362 | workspace.resetTransitionTransform((CellLayout) getParent().getParent()); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 363 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 364 | |
| 365 | int[] center = new int[2]; |
| 366 | float scale = getLocalCenterForIndex(index, center); |
| 367 | center[0] = (int) Math.round(scaleRelativeToDragLayer * center[0]); |
| 368 | center[1] = (int) Math.round(scaleRelativeToDragLayer * center[1]); |
| 369 | |
| 370 | to.offset(center[0] - animateView.getMeasuredWidth() / 2, |
| 371 | center[1] - animateView.getMeasuredHeight() / 2); |
| 372 | |
| 373 | float finalAlpha = index < NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f; |
| 374 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 375 | float finalScale = scale * scaleRelativeToDragLayer; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 376 | dragLayer.animateView(animateView, from, to, finalAlpha, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 377 | 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 378 | new DecelerateInterpolator(2), new AccelerateInterpolator(2), |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 379 | postAnimationRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null); |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 380 | postDelayed(new Runnable() { |
| 381 | public void run() { |
| 382 | addItem(item); |
| 383 | } |
| 384 | }, DROP_IN_ANIMATION_DURATION); |
| 385 | } else { |
| 386 | addItem(item); |
| 387 | } |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 390 | public void onDrop(DragObject d) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 391 | ShortcutInfo item; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 392 | if (d.dragInfo instanceof ApplicationInfo) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 393 | // Came from all apps -- make a copy |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 394 | item = ((ApplicationInfo) d.dragInfo).makeShortcut(); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 395 | } else { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 396 | item = (ShortcutInfo) d.dragInfo; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 397 | } |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 398 | mFolder.notifyDrop(); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 399 | onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable, d); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 402 | public DropTarget getDropTargetDelegate(DragObject d) { |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 403 | return null; |
| 404 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 405 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 406 | private void computePreviewDrawingParams(int drawableSize, int totalSize) { |
| 407 | if (mIntrinsicIconSize != drawableSize || mTotalWidth != totalSize) { |
| 408 | mIntrinsicIconSize = drawableSize; |
| 409 | mTotalWidth = totalSize; |
| 410 | |
| 411 | final int previewSize = FolderRingAnimator.sPreviewSize; |
| 412 | final int previewPadding = FolderRingAnimator.sPreviewPadding; |
| 413 | |
| 414 | mAvailableSpaceInPreview = (previewSize - 2 * previewPadding); |
| 415 | // cos(45) = 0.707 + ~= 0.1) = 0.8f |
| 416 | int adjustedAvailableSpace = (int) ((mAvailableSpaceInPreview / 2) * (1 + 0.8f)); |
| 417 | |
| 418 | int unscaledHeight = (int) (mIntrinsicIconSize * (1 + PERSPECTIVE_SHIFT_FACTOR)); |
| 419 | mBaselineIconScale = (1.0f * adjustedAvailableSpace / unscaledHeight); |
| 420 | |
| 421 | mBaselineIconSize = (int) (mIntrinsicIconSize * mBaselineIconScale); |
| 422 | mMaxPerspectiveShift = mBaselineIconSize * PERSPECTIVE_SHIFT_FACTOR; |
| 423 | |
| 424 | mPreviewOffsetX = (mTotalWidth - mAvailableSpaceInPreview) / 2; |
| 425 | mPreviewOffsetY = previewPadding; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | private void computePreviewDrawingParams(Drawable d) { |
| 430 | computePreviewDrawingParams(d.getIntrinsicWidth(), getMeasuredWidth()); |
| 431 | } |
| 432 | |
| 433 | class PreviewItemDrawingParams { |
| 434 | PreviewItemDrawingParams(float transX, float transY, float scale, int overlayAlpha) { |
| 435 | this.transX = transX; |
| 436 | this.transY = transY; |
| 437 | this.scale = scale; |
| 438 | this.overlayAlpha = overlayAlpha; |
| 439 | } |
| 440 | float transX; |
| 441 | float transY; |
| 442 | float scale; |
| 443 | int overlayAlpha; |
| 444 | Drawable drawable; |
| 445 | } |
| 446 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 447 | private float getLocalCenterForIndex(int index, int[] center) { |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 448 | mParams = computePreviewItemDrawingParams(Math.min(NUM_ITEMS_IN_PREVIEW, index), mParams); |
| 449 | |
| 450 | mParams.transX += mPreviewOffsetX; |
| 451 | mParams.transY += mPreviewOffsetY; |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 452 | float offsetX = mParams.transX + (mParams.scale * mIntrinsicIconSize) / 2; |
| 453 | float offsetY = mParams.transY + (mParams.scale * mIntrinsicIconSize) / 2; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 454 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 455 | center[0] = (int) Math.round(offsetX); |
| 456 | center[1] = (int) Math.round(offsetY); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 457 | return mParams.scale; |
| 458 | } |
| 459 | |
| 460 | private PreviewItemDrawingParams computePreviewItemDrawingParams(int index, |
| 461 | PreviewItemDrawingParams params) { |
| 462 | index = NUM_ITEMS_IN_PREVIEW - index - 1; |
| 463 | float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1); |
| 464 | float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r)); |
| 465 | |
| 466 | float offset = (1 - r) * mMaxPerspectiveShift; |
| 467 | float scaledSize = scale * mBaselineIconSize; |
| 468 | float scaleOffsetCorrection = (1 - scale) * mBaselineIconSize; |
| 469 | |
| 470 | // We want to imagine our coordinates from the bottom left, growing up and to the |
| 471 | // right. This is natural for the x-axis, but for the y-axis, we have to invert things. |
| 472 | float transY = mAvailableSpaceInPreview - (offset + scaledSize + scaleOffsetCorrection); |
| 473 | float transX = offset + scaleOffsetCorrection; |
| 474 | float totalScale = mBaselineIconScale * scale; |
| 475 | final int overlayAlpha = (int) (80 * (1 - r)); |
| 476 | |
| 477 | if (params == null) { |
| 478 | params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha); |
| 479 | } else { |
| 480 | params.transX = transX; |
| 481 | params.transY = transY; |
| 482 | params.scale = totalScale; |
| 483 | params.overlayAlpha = overlayAlpha; |
| 484 | } |
| 485 | return params; |
| 486 | } |
| 487 | |
| 488 | private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) { |
| 489 | canvas.save(); |
| 490 | canvas.translate(params.transX + mPreviewOffsetX, params.transY + mPreviewOffsetY); |
| 491 | canvas.scale(params.scale, params.scale); |
| 492 | Drawable d = params.drawable; |
| 493 | |
| 494 | if (d != null) { |
| 495 | d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); |
| 496 | d.setFilterBitmap(true); |
| 497 | d.setColorFilter(Color.argb(params.overlayAlpha, 0, 0, 0), PorterDuff.Mode.SRC_ATOP); |
| 498 | d.draw(canvas); |
| 499 | d.clearColorFilter(); |
| 500 | d.setFilterBitmap(false); |
| 501 | } |
| 502 | canvas.restore(); |
| 503 | } |
| 504 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 505 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 506 | protected void dispatchDraw(Canvas canvas) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 507 | super.dispatchDraw(canvas); |
| 508 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 509 | if (mFolder == null) return; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 510 | if (mFolder.getItemCount() == 0 && !mAnimating) return; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 511 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 512 | ArrayList<View> items = mFolder.getItemsInReadingOrder(false); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 513 | Drawable d; |
| 514 | TextView v; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 515 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 516 | // Update our drawing parameters if necessary |
| 517 | if (mAnimating) { |
| 518 | computePreviewDrawingParams(mAnimParams.drawable); |
| 519 | } else { |
| 520 | v = (TextView) items.get(0); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 521 | d = v.getCompoundDrawables()[1]; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 522 | computePreviewDrawingParams(d); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 523 | } |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 524 | |
| 525 | int nItemsInPreview = Math.min(items.size(), NUM_ITEMS_IN_PREVIEW); |
| 526 | if (!mAnimating) { |
| 527 | for (int i = nItemsInPreview - 1; i >= 0; i--) { |
| 528 | v = (TextView) items.get(i); |
| 529 | d = v.getCompoundDrawables()[1]; |
| 530 | |
| 531 | mParams = computePreviewItemDrawingParams(i, mParams); |
| 532 | mParams.drawable = d; |
| 533 | drawPreviewItem(canvas, mParams); |
| 534 | } |
| 535 | } else { |
| 536 | drawPreviewItem(canvas, mAnimParams); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | private void animateFirstItem(final Drawable d, int duration) { |
| 541 | computePreviewDrawingParams(d); |
| 542 | final PreviewItemDrawingParams finalParams = computePreviewItemDrawingParams(0, null); |
| 543 | |
| 544 | final float scale0 = 1.0f; |
Adam Cohen | 1d4ee4e | 2011-08-12 15:51:59 -0700 | [diff] [blame] | 545 | final float transX0 = (mAvailableSpaceInPreview - d.getIntrinsicWidth()) / 2; |
| 546 | final float transY0 = (mAvailableSpaceInPreview - d.getIntrinsicHeight()) / 2; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 547 | mAnimParams.drawable = d; |
| 548 | |
| 549 | ValueAnimator va = ValueAnimator.ofFloat(0f, 1.0f); |
| 550 | va.addUpdateListener(new AnimatorUpdateListener(){ |
| 551 | public void onAnimationUpdate(ValueAnimator animation) { |
| 552 | float progress = (Float) animation.getAnimatedValue(); |
| 553 | |
| 554 | mAnimParams.transX = transX0 + progress * (finalParams.transX - transX0); |
| 555 | mAnimParams.transY = transY0 + progress * (finalParams.transY - transY0); |
| 556 | mAnimParams.scale = scale0 + progress * (finalParams.scale - scale0); |
| 557 | invalidate(); |
| 558 | } |
| 559 | }); |
| 560 | va.addListener(new AnimatorListenerAdapter() { |
| 561 | @Override |
| 562 | public void onAnimationStart(Animator animation) { |
| 563 | mAnimating = true; |
| 564 | } |
| 565 | @Override |
| 566 | public void onAnimationEnd(Animator animation) { |
| 567 | mAnimating = false; |
| 568 | } |
| 569 | }); |
| 570 | va.setDuration(duration); |
| 571 | va.start(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 574 | public void setTextVisible(boolean visible) { |
| 575 | if (visible) { |
| 576 | mFolderName.setVisibility(VISIBLE); |
| 577 | } else { |
| 578 | mFolderName.setVisibility(INVISIBLE); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | public boolean getTextVisible() { |
| 583 | return mFolderName.getVisibility() == VISIBLE; |
| 584 | } |
| 585 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 586 | public void onItemsChanged() { |
| 587 | invalidate(); |
| 588 | requestLayout(); |
| 589 | } |
| 590 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 591 | public void onAdd(ShortcutInfo item) { |
| 592 | invalidate(); |
| 593 | requestLayout(); |
| 594 | } |
| 595 | |
| 596 | public void onRemove(ShortcutInfo item) { |
| 597 | invalidate(); |
| 598 | requestLayout(); |
| 599 | } |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 600 | |
| 601 | public void onTitleChanged(CharSequence title) { |
Adam Cohen | d63cfa9 | 2011-06-24 14:17:17 -0700 | [diff] [blame] | 602 | mFolderName.setText(title.toString()); |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 603 | setContentDescription(String.format(mContext.getString(R.string.folder_name_format), |
| 604 | title)); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 605 | } |
Winson Chung | 88f3345 | 2012-02-23 15:23:44 -0800 | [diff] [blame] | 606 | |
| 607 | @Override |
| 608 | public boolean onTouchEvent(MotionEvent event) { |
| 609 | // Call the superclass onTouchEvent first, because sometimes it changes the state to |
| 610 | // isPressed() on an ACTION_UP |
| 611 | boolean result = super.onTouchEvent(event); |
| 612 | |
| 613 | switch (event.getAction()) { |
| 614 | case MotionEvent.ACTION_DOWN: |
| 615 | mLongPressHelper.postCheckForLongPress(); |
| 616 | break; |
| 617 | case MotionEvent.ACTION_CANCEL: |
| 618 | case MotionEvent.ACTION_UP: |
| 619 | mLongPressHelper.cancelLongPress(); |
| 620 | break; |
| 621 | } |
| 622 | return result; |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public void cancelLongPress() { |
| 627 | super.cancelLongPress(); |
| 628 | |
| 629 | mLongPressHelper.cancelLongPress(); |
| 630 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 631 | } |