blob: bae2fd77cc95368e0c06a8fce7358304b75c726a [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);
Winson Chung6a0f57d2011-06-29 20:10:49 -070098 icon.mPreviewBackground.setContentDescription(folderInfo.title);
Adam Cohen76fc0852011-06-17 13:26:23 -070099
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800100 icon.setTag(folderInfo);
101 icon.setOnClickListener(launcher);
102 icon.mInfo = folderInfo;
103 icon.mLauncher = launcher;
Adam Cohena9cf38f2011-05-02 15:36:58 -0700104
105 Folder folder = Folder.fromXml(launcher);
106 folder.setDragController(launcher.getDragController());
107 folder.setLauncher(launcher);
Adam Cohen2801caf2011-05-13 20:57:39 -0700108 folder.setFolderIcon(icon);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700109 folder.bind(folderInfo);
110 icon.mFolder = folder;
Adam Cohen19072da2011-05-31 14:30:45 -0700111 icon.mFolderRingAnimator = new FolderRingAnimator(launcher, icon);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700112 folderInfo.addListener(icon);
Adam Cohen19072da2011-05-31 14:30:45 -0700113
114 return icon;
115 }
116
117 public static class FolderRingAnimator {
118 public int mFolderLocX;
119 public int mFolderLocY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700120 public float mOuterRingSize;
121 public float mInnerRingSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700122 public FolderIcon mFolderIcon = null;
123 private Launcher mLauncher;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700124 public Drawable mOuterRingDrawable = null;
125 public Drawable mInnerRingDrawable = null;
126 public static Drawable sSharedOuterRingDrawable = null;
127 public static Drawable sSharedInnerRingDrawable = null;
Adam Cohen76fc0852011-06-17 13:26:23 -0700128 public static int sPreviewSize = -1;
129 public static int sPreviewPadding = -1;
130
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131 private ValueAnimator mAcceptAnimator;
132 private ValueAnimator mNeutralAnimator;
Adam Cohen19072da2011-05-31 14:30:45 -0700133
134 public FolderRingAnimator(Launcher launcher, FolderIcon folderIcon) {
135 mLauncher = launcher;
136 mFolderIcon = folderIcon;
Adam Cohen76fc0852011-06-17 13:26:23 -0700137 Resources res = launcher.getResources();
138 mOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo);
139 mInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo);
140
141 if (sPreviewSize < 0 || sPreviewPadding < 0) {
142 sPreviewSize = res.getDimensionPixelSize(R.dimen.folder_preview_size);
143 sPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
144 }
Adam Cohenc0dcf592011-06-01 15:30:43 -0700145 if (sSharedOuterRingDrawable == null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700146 sSharedOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo);
Adam Cohen19072da2011-05-31 14:30:45 -0700147 }
Adam Cohenc0dcf592011-06-01 15:30:43 -0700148 if (sSharedInnerRingDrawable == null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700149 sSharedInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo);
Adam Cohen19072da2011-05-31 14:30:45 -0700150 }
Adam Cohen073a46f2011-05-17 16:28:09 -0700151 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700152
Adam Cohenc0dcf592011-06-01 15:30:43 -0700153 // Location is expressed in window coordinates
Adam Cohen19072da2011-05-31 14:30:45 -0700154 public void setLocation(int x, int y) {
155 mFolderLocX = x;
156 mFolderLocY = y;
Adam Cohenf4b08912011-05-17 18:45:47 -0700157 }
Adam Cohen19072da2011-05-31 14:30:45 -0700158
159 public void animateToAcceptState() {
Adam Cohenc0dcf592011-06-01 15:30:43 -0700160 if (mNeutralAnimator != null) {
161 mNeutralAnimator.cancel();
162 }
163 mAcceptAnimator = ValueAnimator.ofFloat(0f, 1f);
164 mAcceptAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION);
165 mAcceptAnimator.addUpdateListener(new AnimatorUpdateListener() {
Adam Cohen19072da2011-05-31 14:30:45 -0700166 public void onAnimationUpdate(ValueAnimator animation) {
167 final float percent = (Float) animation.getAnimatedValue();
Adam Cohen76fc0852011-06-17 13:26:23 -0700168 mOuterRingSize = (1 + percent * OUTER_RING_GROWTH_FACTOR) * sPreviewSize;
169 mInnerRingSize = (1 + percent * INNER_RING_GROWTH_FACTOR) * sPreviewSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700170 mLauncher.getWorkspace().invalidate();
171 if (mFolderIcon != null) {
172 mFolderIcon.invalidate();
173 }
174 }
175 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700176 mAcceptAnimator.addListener(new AnimatorListenerAdapter() {
Adam Cohen19072da2011-05-31 14:30:45 -0700177 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700178 public void onAnimationStart(Animator animation) {
Adam Cohen19072da2011-05-31 14:30:45 -0700179 if (mFolderIcon != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700180 mFolderIcon.mPreviewBackground.setVisibility(INVISIBLE);
Adam Cohen19072da2011-05-31 14:30:45 -0700181 }
182 }
183 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700184 mAcceptAnimator.start();
Adam Cohen19072da2011-05-31 14:30:45 -0700185 }
186
187 public void animateToNaturalState() {
Adam Cohenc0dcf592011-06-01 15:30:43 -0700188 if (mAcceptAnimator != null) {
189 mAcceptAnimator.cancel();
190 }
191 mNeutralAnimator = ValueAnimator.ofFloat(0f, 1f);
192 mNeutralAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION);
193 mNeutralAnimator.addUpdateListener(new AnimatorUpdateListener() {
Adam Cohen19072da2011-05-31 14:30:45 -0700194 public void onAnimationUpdate(ValueAnimator animation) {
195 final float percent = (Float) animation.getAnimatedValue();
Adam Cohen76fc0852011-06-17 13:26:23 -0700196 mOuterRingSize = (1 + (1 - percent) * OUTER_RING_GROWTH_FACTOR) * sPreviewSize;
197 mInnerRingSize = (1 + (1 - percent) * INNER_RING_GROWTH_FACTOR) * sPreviewSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700198 mLauncher.getWorkspace().invalidate();
199 if (mFolderIcon != null) {
200 mFolderIcon.invalidate();
201 }
202 }
203 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700204 mNeutralAnimator.addListener(new AnimatorListenerAdapter() {
Adam Cohen19072da2011-05-31 14:30:45 -0700205 @Override
206 public void onAnimationEnd(Animator animation) {
207 if (mFolderIcon != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700208 mFolderIcon.mPreviewBackground.setVisibility(VISIBLE);
Adam Cohen19072da2011-05-31 14:30:45 -0700209 }
210 mLauncher.getWorkspace().hideFolderAccept(FolderRingAnimator.this);
211 }
212 });
Adam Cohenc0dcf592011-06-01 15:30:43 -0700213 mNeutralAnimator.start();
Adam Cohen19072da2011-05-31 14:30:45 -0700214 }
215
Adam Cohenc0dcf592011-06-01 15:30:43 -0700216 // Location is expressed in window coordinates
Adam Cohen19072da2011-05-31 14:30:45 -0700217 public void getLocation(int[] loc) {
218 loc[0] = mFolderLocX;
219 loc[1] = mFolderLocY;
220 }
221
Adam Cohen76fc0852011-06-17 13:26:23 -0700222 public float getOuterRingSize() {
223 return mOuterRingSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700224 }
225
Adam Cohen76fc0852011-06-17 13:26:23 -0700226 public float getInnerRingSize() {
227 return mInnerRingSize;
Adam Cohen19072da2011-05-31 14:30:45 -0700228 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 }
230
Adam Cohen073a46f2011-05-17 16:28:09 -0700231 private boolean willAcceptItem(ItemInfo item) {
232 final int itemType = item.itemType;
233 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
234 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
235 !mFolder.isFull() && item != mInfo);
236 }
237
Adam Cohenc0dcf592011-06-01 15:30:43 -0700238 public boolean acceptDrop(Object dragInfo) {
239 final ItemInfo item = (ItemInfo) dragInfo;
Adam Cohen073a46f2011-05-17 16:28:09 -0700240 return willAcceptItem(item);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241 }
242
Adam Cohendf035382011-04-11 17:22:04 -0700243 public void addItem(ShortcutInfo item) {
244 mInfo.add(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700245 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
Adam Cohendf035382011-04-11 17:22:04 -0700246 }
247
Adam Cohen2801caf2011-05-13 20:57:39 -0700248 void saveState(CellLayout.LayoutParams lp) {
249 mOriginalWidth = lp.width;
250 mOriginalHeight = lp.height;
Adam Cohen2801caf2011-05-13 20:57:39 -0700251 }
252
Adam Cohen073a46f2011-05-17 16:28:09 -0700253 private void determineFolderLocationInWorkspace() {
254 int tvLocation[] = new int[2];
255 int wsLocation[] = new int[2];
Adam Cohenc0dcf592011-06-01 15:30:43 -0700256 getLocationInWindow(tvLocation);
257 mLauncher.getWorkspace().getLocationInWindow(wsLocation);
Adam Cohen19072da2011-05-31 14:30:45 -0700258
259 int x = tvLocation[0] - wsLocation[0] + getMeasuredWidth() / 2;
Adam Cohen76fc0852011-06-17 13:26:23 -0700260 int y = tvLocation[1] - wsLocation[1] + FolderRingAnimator.sPreviewSize / 2;
Adam Cohen19072da2011-05-31 14:30:45 -0700261 mFolderRingAnimator.setLocation(x, y);
Adam Cohen073a46f2011-05-17 16:28:09 -0700262 }
263
Adam Cohenc0dcf592011-06-01 15:30:43 -0700264 public void onDragEnter(Object dragInfo) {
265 if (!willAcceptItem((ItemInfo) dragInfo)) return;
Adam Cohen073a46f2011-05-17 16:28:09 -0700266 determineFolderLocationInWorkspace();
Adam Cohen19072da2011-05-31 14:30:45 -0700267 mLauncher.getWorkspace().showFolderAccept(mFolderRingAnimator);
268 mFolderRingAnimator.animateToAcceptState();
Adam Cohen073a46f2011-05-17 16:28:09 -0700269 }
270
Adam Cohenc0dcf592011-06-01 15:30:43 -0700271 public void onDragOver(Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 }
273
Adam Cohenc0dcf592011-06-01 15:30:43 -0700274 public void onDragExit(Object dragInfo) {
275 if (!willAcceptItem((ItemInfo) dragInfo)) return;
Adam Cohen19072da2011-05-31 14:30:45 -0700276 mFolderRingAnimator.animateToNaturalState();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 }
Patrick Dubroy440c3602010-07-13 17:50:32 -0700278
Adam Cohenc0dcf592011-06-01 15:30:43 -0700279 public void onDrop(Object dragInfo) {
280 ShortcutInfo item;
281 if (dragInfo instanceof ApplicationInfo) {
282 // Came from all apps -- make a copy
283 item = ((ApplicationInfo) dragInfo).makeShortcut();
284 } else {
285 item = (ShortcutInfo) dragInfo;
286 }
287 item.cellX = -1;
288 item.cellY = -1;
289 addItem(item);
290 }
291
Adam Cohencb3382b2011-05-24 14:07:08 -0700292 public DropTarget getDropTargetDelegate(DragObject d) {
Patrick Dubroy440c3602010-07-13 17:50:32 -0700293 return null;
294 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700295
296 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700297 protected void dispatchDraw(Canvas canvas) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700298 super.dispatchDraw(canvas);
299
Adam Cohena9cf38f2011-05-02 15:36:58 -0700300 if (mFolder == null) return;
301 if (mFolder.getItemCount() == 0) return;
302
303 canvas.save();
304 TextView v = (TextView) mFolder.getItemAt(0);
305 Drawable d = v.getCompoundDrawables()[1];
Adam Cohen76fc0852011-06-17 13:26:23 -0700306 int intrinsicIconSize = d.getIntrinsicHeight();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700307
Adam Cohen073a46f2011-05-17 16:28:09 -0700308 if (mOriginalWidth < 0 || mOriginalHeight < 0) {
309 mOriginalWidth = getMeasuredWidth();
310 mOriginalHeight = getMeasuredHeight();
311 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700312 final int previewSize = FolderRingAnimator.sPreviewSize;
313 final int previewPadding = FolderRingAnimator.sPreviewPadding;
Adam Cohena9cf38f2011-05-02 15:36:58 -0700314
Adam Cohen76fc0852011-06-17 13:26:23 -0700315 int halfAvailableSpace = (previewSize - 2 * previewPadding) / 2;
316 // cos(45) = 0.707 + ~= 0.1)
317 int availableSpace = (int) (halfAvailableSpace * (1 + 0.8f));
Adam Cohenbadf71e2011-05-26 19:08:29 -0700318
Adam Cohen76fc0852011-06-17 13:26:23 -0700319 int unscaledHeight = (int) (intrinsicIconSize * (1 + PERSPECTIVE_SHIFT_FACTOR));
320 float baselineIconScale = (1.0f * availableSpace / unscaledHeight);
321
322 int baselineSize = (int) (intrinsicIconSize * baselineIconScale);
323 float maxPerspectiveShift = baselineSize * PERSPECTIVE_SHIFT_FACTOR;
Adam Cohena9cf38f2011-05-02 15:36:58 -0700324
Adam Cohen76078c42011-06-09 15:06:52 -0700325 ArrayList<View> items = mFolder.getItemsInReadingOrder(false);
Adam Cohen7c693212011-05-18 15:26:57 -0700326 int firstItemIndex = Math.max(0, items.size() - NUM_ITEMS_IN_PREVIEW);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700327
Adam Cohen76fc0852011-06-17 13:26:23 -0700328 int xShift = (mOriginalWidth - 2 * halfAvailableSpace) / 2;
329 int yShift = previewPadding;
Adam Cohenbadf71e2011-05-26 19:08:29 -0700330 canvas.translate(xShift, yShift);
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700331 for (int i = firstItemIndex; i < items.size(); i++) {
Adam Cohenbadf71e2011-05-26 19:08:29 -0700332 int index = i - firstItemIndex;
333 index += Math.max(0, NUM_ITEMS_IN_PREVIEW - items.size());
334
335 float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1);
336 float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));
Adam Cohenbadf71e2011-05-26 19:08:29 -0700337
Adam Cohen76fc0852011-06-17 13:26:23 -0700338 //r = (float) Math.pow(r, 2);
339
340 float offset = (1 - r) * maxPerspectiveShift;
341 float scaledSize = scale * baselineSize;
342 float scaleOffsetCorrection = (1 - scale) * baselineSize;
343
344 // We want to imagine our coordinates from the bottom left, growing up and to the
345 // right. This is natural for the x-axis, but for the y-axis, we have to invert things.
346 float transY = 2 * halfAvailableSpace - (offset + scaledSize + scaleOffsetCorrection);
347 float transX = offset + scaleOffsetCorrection;
Adam Cohenbadf71e2011-05-26 19:08:29 -0700348
Adam Cohen7c693212011-05-18 15:26:57 -0700349 v = (TextView) items.get(i);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700350 d = v.getCompoundDrawables()[1];
351
Adam Cohenbadf71e2011-05-26 19:08:29 -0700352 canvas.save();
353 canvas.translate(transX, transY);
354 canvas.scale(baselineIconScale * scale, baselineIconScale * scale);
Adam Cohenf4b08912011-05-17 18:45:47 -0700355
Adam Cohenbadf71e2011-05-26 19:08:29 -0700356 int overlayAlpha = (int) (80 * (1 - r));
Adam Cohena9cf38f2011-05-02 15:36:58 -0700357 if (d != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -0700358 d.setBounds(0, 0, intrinsicIconSize, intrinsicIconSize);
359 d.setFilterBitmap(true);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700360 d.setColorFilter(Color.argb(overlayAlpha, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700361 d.draw(canvas);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700362 d.clearColorFilter();
Adam Cohen76fc0852011-06-17 13:26:23 -0700363 d.setFilterBitmap(false);
Adam Cohena9cf38f2011-05-02 15:36:58 -0700364 }
Adam Cohenbadf71e2011-05-26 19:08:29 -0700365 canvas.restore();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700366 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700367 canvas.restore();
368 }
369
Adam Cohen76078c42011-06-09 15:06:52 -0700370 public void onItemsChanged() {
371 invalidate();
372 requestLayout();
373 }
374
Adam Cohena9cf38f2011-05-02 15:36:58 -0700375 public void onAdd(ShortcutInfo item) {
376 invalidate();
377 requestLayout();
378 }
379
380 public void onRemove(ShortcutInfo item) {
381 invalidate();
382 requestLayout();
383 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700384
385 public void onTitleChanged(CharSequence title) {
Adam Cohend63cfa92011-06-24 14:17:17 -0700386 mFolderName.setText(title.toString());
Winson Chung6a0f57d2011-06-29 20:10:49 -0700387 mPreviewBackground.setContentDescription(title.toString());
Adam Cohen76fc0852011-06-17 13:26:23 -0700388 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389}