blob: 0597110516373df1f7573be1d160caff30326f40 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Adam Cohen2801caf2011-05-13 20:57:39 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Adam Cohen2801caf2011-05-13 20:57:39 -070021import android.animation.ValueAnimator;
22import android.animation.ValueAnimator.AnimatorUpdateListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.Context;
24import android.content.res.Resources;
Adam Cohena9cf38f2011-05-02 15:36:58 -070025import android.graphics.Canvas;
Adam Cohenf4b08912011-05-17 18:45:47 -070026import android.graphics.Color;
Adam Cohenbadf71e2011-05-26 19:08:29 -070027import android.graphics.PorterDuff;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.graphics.drawable.Drawable;
29import android.util.AttributeSet;
30import android.view.LayoutInflater;
Adam Cohen7c693212011-05-18 15:26:57 -070031import android.view.View;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.view.ViewGroup;
Adam Cohen76fc0852011-06-17 13:26:23 -070033import android.widget.ImageView;
34import android.widget.LinearLayout;
Adam Cohena9cf38f2011-05-02 15:36:58 -070035import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036
Romain Guyedcce092010-03-04 13:03:17 -080037import com.android.launcher.R;
Adam Cohenc0dcf592011-06-01 15:30:43 -070038import com.android.launcher2.DropTarget.DragObject;
Adam Cohena9cf38f2011-05-02 15:36:58 -070039import com.android.launcher2.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080040
Adam Cohenc0dcf592011-06-01 15:30:43 -070041import java.util.ArrayList;
42
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043/**
44 * An icon that can appear on in the workspace representing an {@link UserFolder}.
45 */
Adam Cohen76fc0852011-06-17 13:26:23 -070046public class FolderIcon extends LinearLayout implements FolderListener {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047 private Launcher mLauncher;
Adam Cohena9cf38f2011-05-02 15:36:58 -070048 Folder mFolder;
49 FolderInfo mInfo;
50
Adam Cohenbadf71e2011-05-26 19:08:29 -070051 // The number of icons to display in the
Adam Cohen76fc0852011-06-17 13:26:23 -070052 private static final int NUM_ITEMS_IN_PREVIEW = 3;
Adam Cohenf4b08912011-05-17 18:45:47 -070053 private static final int CONSUMPTION_ANIMATION_DURATION = 100;
Adam Cohenbadf71e2011-05-26 19:08:29 -070054
55 // The degree to which the inner ring grows when accepting drop
Adam Cohen073a46f2011-05-17 16:28:09 -070056 private static final float INNER_RING_GROWTH_FACTOR = 0.1f;
Adam Cohenbadf71e2011-05-26 19:08:29 -070057
Adam Cohenbadf71e2011-05-26 19:08:29 -070058 // The degree to which the outer ring is scaled in its natural state
Adam Cohen76fc0852011-06-17 13:26:23 -070059 private static final float OUTER_RING_GROWTH_FACTOR = 0.4f;
Adam Cohenbadf71e2011-05-26 19:08:29 -070060
61 // The amount of vertical spread between items in the stack [0...1]
Adam Cohen76fc0852011-06-17 13:26:23 -070062 private static final float PERSPECTIVE_SHIFT_FACTOR = 0.24f;
Adam Cohenbadf71e2011-05-26 19:08:29 -070063
64 // The degree to which the item in the back of the stack is scaled [0...1]
65 // (0 means it's not scaled at all, 1 means it's scaled to nothing)
Adam Cohen76fc0852011-06-17 13:26:23 -070066 private static final float PERSPECTIVE_SCALE_FACTOR = 0.35f;
Adam Cohenbadf71e2011-05-26 19:08:29 -070067
Adam Cohen073a46f2011-05-17 16:28:09 -070068 private int mOriginalWidth = -1;
69 private int mOriginalHeight = -1;
Adam Cohen76fc0852011-06-17 13:26:23 -070070 private ImageView mPreviewBackground;
71 private BubbleTextView mFolderName;
Adam Cohen073a46f2011-05-17 16:28:09 -070072
Adam Cohen19072da2011-05-31 14:30:45 -070073 FolderRingAnimator mFolderRingAnimator = null;
Adam Cohen2801caf2011-05-13 20:57:39 -070074
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075 public FolderIcon(Context context, AttributeSet attrs) {
76 super(context, attrs);
77 }
78
79 public FolderIcon(Context context) {
80 super(context);
81 }
82
Michael Jurka0280c3b2010-09-17 15:00:07 -070083 public boolean isDropEnabled() {
Winson Chung7a1d1652011-03-18 15:56:01 -070084 final ViewGroup cellLayoutChildren = (ViewGroup) getParent();
85 final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent();
86 final Workspace workspace = (Workspace) cellLayout.getParent();
87 return !workspace.isSmall();
Michael Jurka0280c3b2010-09-17 15:00:07 -070088 }
89
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090 static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
Adam Cohendf2cc412011-04-27 16:56:57 -070091 FolderInfo folderInfo, IconCache iconCache) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092
93 FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
94
Adam Cohen76fc0852011-06-17 13:26:23 -070095 icon.mFolderName = (BubbleTextView) icon.findViewById(R.id.folder_name);
96 icon.mFolderName.setText(folderInfo.title);
97 icon.mPreviewBackground = (ImageView) icon.findViewById(R.id.preview_background);
98
The Android Open Source Project31dd5032009-03-03 19:32:27 -080099 icon.setTag(folderInfo);
100 icon.setOnClickListener(launcher);
101 icon.mInfo = folderInfo;
102 icon.mLauncher = launcher;
Adam Cohena9cf38f2011-05-02 15:36:58 -0700103
104 Folder folder = Folder.fromXml(launcher);
105 folder.setDragController(launcher.getDragController());
106 folder.setLauncher(launcher);
Adam Cohen2801caf2011-05-13 20:57:39 -0700107 folder.setFolderIcon(icon);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700108 folder.bind(folderInfo);
109 icon.mFolder = folder;
Adam Cohen19072da2011-05-31 14:30:45 -0700110 icon.mFolderRingAnimator = new FolderRingAnimator(launcher, icon);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700111 folderInfo.addListener(icon);
Adam Cohen19072da2011-05-31 14:30:45 -0700112
113 return icon;
114 }
115
116 public static class FolderRingAnimator {
117 public int mFolderLocX;
118 public int mFolderLocY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700119 public float mOuterRingSize;
120 public float mInnerRingSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700121 public FolderIcon mFolderIcon = null;
122 private Launcher mLauncher;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123 public Drawable mOuterRingDrawable = null;
124 public Drawable mInnerRingDrawable = null;
125 public static Drawable sSharedOuterRingDrawable = null;
126 public static Drawable sSharedInnerRingDrawable = null;
Adam Cohen76fc0852011-06-17 13:26:23 -0700127 public static int sPreviewSize = -1;
128 public static int sPreviewPadding = -1;
129
Adam Cohenc0dcf592011-06-01 15:30:43 -0700130 private ValueAnimator mAcceptAnimator;
131 private ValueAnimator mNeutralAnimator;
Adam Cohen19072da2011-05-31 14:30:45 -0700132
133 public FolderRingAnimator(Launcher launcher, FolderIcon folderIcon) {
134 mLauncher = launcher;
135 mFolderIcon = folderIcon;
Adam Cohen76fc0852011-06-17 13:26:23 -0700136 Resources res = launcher.getResources();
137 mOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo);
138 mInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo);
139
140 if (sPreviewSize < 0 || sPreviewPadding < 0) {
141 sPreviewSize = res.getDimensionPixelSize(R.dimen.folder_preview_size);
142 sPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
143 }
Adam Cohenc0dcf592011-06-01 15:30:43 -0700144 if (sSharedOuterRingDrawable == null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700145 sSharedOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo);
Adam Cohen19072da2011-05-31 14:30:45 -0700146 }
Adam Cohenc0dcf592011-06-01 15:30:43 -0700147 if (sSharedInnerRingDrawable == null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700148 sSharedInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo);
Adam Cohen19072da2011-05-31 14:30:45 -0700149 }
Adam Cohen073a46f2011-05-17 16:28:09 -0700150 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700151
Adam Cohenc0dcf592011-06-01 15:30:43 -0700152 // Location is expressed in window coordinates
Adam Cohen19072da2011-05-31 14:30:45 -0700153 public void setLocation(int x, int y) {
154 mFolderLocX = x;
155 mFolderLocY = y;
Adam Cohenf4b08912011-05-17 18:45:47 -0700156 }
Adam Cohen19072da2011-05-31 14:30:45 -0700157
158 public void animateToAcceptState() {
Adam Cohenc0dcf592011-06-01 15:30:43 -0700159 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 Cohen19072da2011-05-31 14:30:45 -0700165 public void onAnimationUpdate(ValueAnimator animation) {
166 final float percent = (Float) animation.getAnimatedValue();
Adam Cohen76fc0852011-06-17 13:26:23 -0700167 mOuterRingSize = (1 + percent * OUTER_RING_GROWTH_FACTOR) * sPreviewSize;
168 mInnerRingSize = (1 + percent * INNER_RING_GROWTH_FACTOR) * sPreviewSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700169 mLauncher.getWorkspace().invalidate();
170 if (mFolderIcon != null) {
171 mFolderIcon.invalidate();
172 }
173 }
174 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700175 mAcceptAnimator.addListener(new AnimatorListenerAdapter() {
Adam Cohen19072da2011-05-31 14:30:45 -0700176 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700177 public void onAnimationStart(Animator animation) {
Adam Cohen19072da2011-05-31 14:30:45 -0700178 if (mFolderIcon != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700179 mFolderIcon.mPreviewBackground.setVisibility(INVISIBLE);
Adam Cohen19072da2011-05-31 14:30:45 -0700180 }
181 }
182 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700183 mAcceptAnimator.start();
Adam Cohen19072da2011-05-31 14:30:45 -0700184 }
185
186 public void animateToNaturalState() {
Adam Cohenc0dcf592011-06-01 15:30:43 -0700187 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 Cohen19072da2011-05-31 14:30:45 -0700193 public void onAnimationUpdate(ValueAnimator animation) {
194 final float percent = (Float) animation.getAnimatedValue();
Adam Cohen76fc0852011-06-17 13:26:23 -0700195 mOuterRingSize = (1 + (1 - percent) * OUTER_RING_GROWTH_FACTOR) * sPreviewSize;
196 mInnerRingSize = (1 + (1 - percent) * INNER_RING_GROWTH_FACTOR) * sPreviewSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700197 mLauncher.getWorkspace().invalidate();
198 if (mFolderIcon != null) {
199 mFolderIcon.invalidate();
200 }
201 }
202 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700203 mNeutralAnimator.addListener(new AnimatorListenerAdapter() {
Adam Cohen19072da2011-05-31 14:30:45 -0700204 @Override
205 public void onAnimationEnd(Animator animation) {
206 if (mFolderIcon != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700207 mFolderIcon.mPreviewBackground.setVisibility(VISIBLE);
Adam Cohen19072da2011-05-31 14:30:45 -0700208 }
209 mLauncher.getWorkspace().hideFolderAccept(FolderRingAnimator.this);
210 }
211 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700212 mNeutralAnimator.start();
Adam Cohen19072da2011-05-31 14:30:45 -0700213 }
214
Adam Cohenc0dcf592011-06-01 15:30:43 -0700215 // Location is expressed in window coordinates
Adam Cohen19072da2011-05-31 14:30:45 -0700216 public void getLocation(int[] loc) {
217 loc[0] = mFolderLocX;
218 loc[1] = mFolderLocY;
219 }
220
Adam Cohen76fc0852011-06-17 13:26:23 -0700221 public float getOuterRingSize() {
222 return mOuterRingSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700223 }
224
Adam Cohen76fc0852011-06-17 13:26:23 -0700225 public float getInnerRingSize() {
226 return mInnerRingSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700227 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 }
229
Adam Cohen073a46f2011-05-17 16:28:09 -0700230 private boolean willAcceptItem(ItemInfo item) {
231 final int itemType = item.itemType;
232 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
233 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
234 !mFolder.isFull() && item != mInfo);
235 }
236
Adam Cohenc0dcf592011-06-01 15:30:43 -0700237 public boolean acceptDrop(Object dragInfo) {
238 final ItemInfo item = (ItemInfo) dragInfo;
Adam Cohen073a46f2011-05-17 16:28:09 -0700239 return willAcceptItem(item);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800240 }
241
Adam Cohendf035382011-04-11 17:22:04 -0700242 public void addItem(ShortcutInfo item) {
243 mInfo.add(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700244 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
Adam Cohendf035382011-04-11 17:22:04 -0700245 }
246
Adam Cohen2801caf2011-05-13 20:57:39 -0700247 void saveState(CellLayout.LayoutParams lp) {
248 mOriginalWidth = lp.width;
249 mOriginalHeight = lp.height;
Adam Cohen2801caf2011-05-13 20:57:39 -0700250 }
251
Adam Cohen073a46f2011-05-17 16:28:09 -0700252 private void determineFolderLocationInWorkspace() {
253 int tvLocation[] = new int[2];
254 int wsLocation[] = new int[2];
Adam Cohenc0dcf592011-06-01 15:30:43 -0700255 getLocationInWindow(tvLocation);
256 mLauncher.getWorkspace().getLocationInWindow(wsLocation);
Adam Cohen19072da2011-05-31 14:30:45 -0700257
258 int x = tvLocation[0] - wsLocation[0] + getMeasuredWidth() / 2;
Adam Cohen76fc0852011-06-17 13:26:23 -0700259 int y = tvLocation[1] - wsLocation[1] + FolderRingAnimator.sPreviewSize / 2;
Adam Cohen19072da2011-05-31 14:30:45 -0700260 mFolderRingAnimator.setLocation(x, y);
Adam Cohen073a46f2011-05-17 16:28:09 -0700261 }
262
Adam Cohenc0dcf592011-06-01 15:30:43 -0700263 public void onDragEnter(Object dragInfo) {
264 if (!willAcceptItem((ItemInfo) dragInfo)) return;
Adam Cohen073a46f2011-05-17 16:28:09 -0700265 determineFolderLocationInWorkspace();
Adam Cohen19072da2011-05-31 14:30:45 -0700266 mLauncher.getWorkspace().showFolderAccept(mFolderRingAnimator);
267 mFolderRingAnimator.animateToAcceptState();
Adam Cohen073a46f2011-05-17 16:28:09 -0700268 }
269
Adam Cohenc0dcf592011-06-01 15:30:43 -0700270 public void onDragOver(Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 }
272
Adam Cohenc0dcf592011-06-01 15:30:43 -0700273 public void onDragExit(Object dragInfo) {
274 if (!willAcceptItem((ItemInfo) dragInfo)) return;
Adam Cohen19072da2011-05-31 14:30:45 -0700275 mFolderRingAnimator.animateToNaturalState();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 }
Patrick Dubroy440c3602010-07-13 17:50:32 -0700277
Adam Cohenc0dcf592011-06-01 15:30:43 -0700278 public void onDrop(Object dragInfo) {
279 ShortcutInfo item;
280 if (dragInfo instanceof ApplicationInfo) {
281 // Came from all apps -- make a copy
282 item = ((ApplicationInfo) dragInfo).makeShortcut();
283 } else {
284 item = (ShortcutInfo) dragInfo;
285 }
286 item.cellX = -1;
287 item.cellY = -1;
288 addItem(item);
289 }
290
Adam Cohencb3382b2011-05-24 14:07:08 -0700291 public DropTarget getDropTargetDelegate(DragObject d) {
Patrick Dubroy440c3602010-07-13 17:50:32 -0700292 return null;
293 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700294
295 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700296 protected void dispatchDraw(Canvas canvas) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700297 super.dispatchDraw(canvas);
298
Adam Cohena9cf38f2011-05-02 15:36:58 -0700299 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];
Adam Cohen76fc0852011-06-17 13:26:23 -0700305 int intrinsicIconSize = d.getIntrinsicHeight();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700306
Adam Cohen073a46f2011-05-17 16:28:09 -0700307 if (mOriginalWidth < 0 || mOriginalHeight < 0) {
308 mOriginalWidth = getMeasuredWidth();
309 mOriginalHeight = getMeasuredHeight();
310 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700311 final int previewSize = FolderRingAnimator.sPreviewSize;
312 final int previewPadding = FolderRingAnimator.sPreviewPadding;
Adam Cohena9cf38f2011-05-02 15:36:58 -0700313
Adam Cohen76fc0852011-06-17 13:26:23 -0700314 int halfAvailableSpace = (previewSize - 2 * previewPadding) / 2;
315 // cos(45) = 0.707 + ~= 0.1)
316 int availableSpace = (int) (halfAvailableSpace * (1 + 0.8f));
Adam Cohenbadf71e2011-05-26 19:08:29 -0700317
Adam Cohen76fc0852011-06-17 13:26:23 -0700318 int unscaledHeight = (int) (intrinsicIconSize * (1 + PERSPECTIVE_SHIFT_FACTOR));
319 float baselineIconScale = (1.0f * availableSpace / unscaledHeight);
320
321 int baselineSize = (int) (intrinsicIconSize * baselineIconScale);
322 float maxPerspectiveShift = baselineSize * PERSPECTIVE_SHIFT_FACTOR;
Adam Cohena9cf38f2011-05-02 15:36:58 -0700323
Adam Cohen76078c42011-06-09 15:06:52 -0700324 ArrayList<View> items = mFolder.getItemsInReadingOrder(false);
Adam Cohen7c693212011-05-18 15:26:57 -0700325 int firstItemIndex = Math.max(0, items.size() - NUM_ITEMS_IN_PREVIEW);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700326
Adam Cohen76fc0852011-06-17 13:26:23 -0700327 int xShift = (mOriginalWidth - 2 * halfAvailableSpace) / 2;
328 int yShift = previewPadding;
Adam Cohenbadf71e2011-05-26 19:08:29 -0700329 canvas.translate(xShift, yShift);
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700330 for (int i = firstItemIndex; i < items.size(); i++) {
Adam Cohenbadf71e2011-05-26 19:08:29 -0700331 int index = i - firstItemIndex;
332 index += Math.max(0, NUM_ITEMS_IN_PREVIEW - items.size());
333
334 float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1);
335 float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));
Adam Cohenbadf71e2011-05-26 19:08:29 -0700336
Adam Cohen76fc0852011-06-17 13:26:23 -0700337 //r = (float) Math.pow(r, 2);
338
339 float offset = (1 - r) * maxPerspectiveShift;
340 float scaledSize = scale * baselineSize;
341 float scaleOffsetCorrection = (1 - scale) * baselineSize;
342
343 // We want to imagine our coordinates from the bottom left, growing up and to the
344 // right. This is natural for the x-axis, but for the y-axis, we have to invert things.
345 float transY = 2 * halfAvailableSpace - (offset + scaledSize + scaleOffsetCorrection);
346 float transX = offset + scaleOffsetCorrection;
Adam Cohenbadf71e2011-05-26 19:08:29 -0700347
Adam Cohen7c693212011-05-18 15:26:57 -0700348 v = (TextView) items.get(i);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700349 d = v.getCompoundDrawables()[1];
350
Adam Cohenbadf71e2011-05-26 19:08:29 -0700351 canvas.save();
352 canvas.translate(transX, transY);
353 canvas.scale(baselineIconScale * scale, baselineIconScale * scale);
Adam Cohenf4b08912011-05-17 18:45:47 -0700354
Adam Cohenbadf71e2011-05-26 19:08:29 -0700355 int overlayAlpha = (int) (80 * (1 - r));
Adam Cohena9cf38f2011-05-02 15:36:58 -0700356 if (d != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700357 d.setBounds(0, 0, intrinsicIconSize, intrinsicIconSize);
358 d.setFilterBitmap(true);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700359 d.setColorFilter(Color.argb(overlayAlpha, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700360 d.draw(canvas);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700361 d.clearColorFilter();
Adam Cohen76fc0852011-06-17 13:26:23 -0700362 d.setFilterBitmap(false);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700363 }
Adam Cohenbadf71e2011-05-26 19:08:29 -0700364 canvas.restore();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700365 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700366 canvas.restore();
367 }
368
Adam Cohen76078c42011-06-09 15:06:52 -0700369 public void onItemsChanged() {
370 invalidate();
371 requestLayout();
372 }
373
Adam Cohena9cf38f2011-05-02 15:36:58 -0700374 public void onAdd(ShortcutInfo item) {
375 invalidate();
376 requestLayout();
377 }
378
379 public void onRemove(ShortcutInfo item) {
380 invalidate();
381 requestLayout();
382 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700383
384 public void onTitleChanged(CharSequence title) {
Adam Cohend63cfa92011-06-24 14:17:17 -0700385 mFolderName.setText(title.toString());
Adam Cohen76fc0852011-06-17 13:26:23 -0700386 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800387}