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