blob: a368796bd5367fba588a8d135f5ea6bc53deee1b [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019import android.content.Context;
Adam Cohen96bb7982014-07-07 11:58:56 -070020import android.content.res.ColorStateList;
Winson Chung656d11c2010-11-29 17:15:47 -080021import android.content.res.Resources;
Sunny Goyal95abbb32014-08-04 10:53:22 -070022import android.content.res.Resources.Theme;
Adam Cohen96bb7982014-07-07 11:58:56 -070023import android.content.res.TypedArray;
Michael Jurka67b2f6c2010-11-17 12:33:46 -080024import android.graphics.Bitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.graphics.Canvas;
Michael Jurka137142e2011-01-05 20:57:04 -080026import android.graphics.Region;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027import android.graphics.drawable.Drawable;
Winson Chung656d11c2010-11-29 17:15:47 -080028import android.util.AttributeSet;
Sunny Goyal95abbb32014-08-04 10:53:22 -070029import android.util.SparseArray;
Winson Chung5f8afe62013-08-12 16:19:28 -070030import android.util.TypedValue;
Sunny Goyal508da152014-08-14 10:53:27 -070031import android.view.KeyEvent;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080032import android.view.MotionEvent;
Jason Monk02dd7ae2014-04-15 15:23:31 -040033import android.view.ViewConfiguration;
Michael Jurkabdb5c532011-02-01 15:05:06 -080034import android.widget.TextView;
Romain Guyedcce092010-03-04 13:03:17 -080035
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036/**
37 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
38 * because we want to make the bubble taller than the text and TextView's clip is
39 * too aggressive.
40 */
Michael Jurka08ee7702011-08-11 16:53:35 -070041public class BubbleTextView extends TextView {
Sunny Goyal95abbb32014-08-04 10:53:22 -070042
43 private static SparseArray<Theme> sPreloaderThemes = new SparseArray<>(2);
44
Sunny Goyal508da152014-08-14 10:53:27 -070045 private static final float SHADOW_LARGE_RADIUS = 4.0f;
46 private static final float SHADOW_SMALL_RADIUS = 1.75f;
47 private static final float SHADOW_Y_OFFSET = 2.0f;
48 private static final int SHADOW_LARGE_COLOUR = 0xDD000000;
49 private static final int SHADOW_SMALL_COLOUR = 0xCC000000;
Winson Chung656d11c2010-11-29 17:15:47 -080050 static final float PADDING_V = 3.0f;
51
Daniel Sandlere4f98912013-06-25 15:13:26 -040052 private HolographicOutlineHelper mOutlineHelper;
Sunny Goyal508da152014-08-14 10:53:27 -070053 private Bitmap mPressedBackground;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080054
Jason Monk02dd7ae2014-04-15 15:23:31 -040055 private float mSlop;
56
Adam Cohen477828c2013-09-20 12:05:49 -070057 private int mTextColor;
Sunny Goyal15872da2014-07-08 15:43:54 -070058 private final boolean mCustomShadowsEnabled;
Winson Chung5f8afe62013-08-12 16:19:28 -070059 private boolean mIsTextVisible;
60
Sunny Goyal508da152014-08-14 10:53:27 -070061 // TODO: Remove custom background handling code, as no instance of BubbleTextView use any
62 // background.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063 private boolean mBackgroundSizeChanged;
Sunny Goyal15872da2014-07-08 15:43:54 -070064 private final Drawable mBackground;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065
Michael Jurkaddd62e92011-02-16 17:49:14 -080066 private boolean mStayPressed;
Sunny Goyal508da152014-08-14 10:53:27 -070067 private boolean mIgnorePressedStateChange;
Winson Chung88f33452012-02-23 15:23:44 -080068 private CheckLongPressHelper mLongPressHelper;
Chris Wrenaeff7ea2014-02-14 16:59:24 -050069
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070 public BubbleTextView(Context context) {
Adam Cohen96bb7982014-07-07 11:58:56 -070071 this(context, null, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072 }
73
74 public BubbleTextView(Context context, AttributeSet attrs) {
Adam Cohen96bb7982014-07-07 11:58:56 -070075 this(context, attrs, 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076 }
77
78 public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
79 super(context, attrs, defStyle);
Adam Cohen96bb7982014-07-07 11:58:56 -070080
Adam Cohen96bb7982014-07-07 11:58:56 -070081 TypedArray a = context.obtainStyledAttributes(attrs,
82 R.styleable.BubbleTextView, defStyle, 0);
Adam Cohen96bb7982014-07-07 11:58:56 -070083 mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true);
84 a.recycle();
85
Sunny Goyal15872da2014-07-08 15:43:54 -070086 if (mCustomShadowsEnabled) {
87 // Draw the background itself as the parent is drawn twice.
88 mBackground = getBackground();
89 setBackground(null);
90 } else {
91 mBackground = null;
92 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093 init();
94 }
95
Winson Chung5f8afe62013-08-12 16:19:28 -070096 public void onFinishInflate() {
97 super.onFinishInflate();
98
99 // Ensure we are using the right text size
100 LauncherAppState app = LauncherAppState.getInstance();
101 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700102 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
Winson Chung5f8afe62013-08-12 16:19:28 -0700103 }
104
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800105 private void init() {
Winson Chung88f33452012-02-23 15:23:44 -0800106 mLongPressHelper = new CheckLongPressHelper(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107
Daniel Sandlere4f98912013-06-25 15:13:26 -0400108 mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
Adam Cohen96bb7982014-07-07 11:58:56 -0700109 if (mCustomShadowsEnabled) {
110 setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR);
111 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112 }
113
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700114 public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
115 boolean setDefaultPadding) {
Sunny Goyal34942622014-08-29 17:20:55 -0700116 applyFromShortcutInfo(info, iconCache, setDefaultPadding, false);
117 }
118
119 public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
120 boolean setDefaultPadding, boolean promiseStateChanged) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800121 Bitmap b = info.getIcon(iconCache);
Winson Chungcdef0442013-09-19 17:32:58 -0700122 LauncherAppState app = LauncherAppState.getInstance();
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800123
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700124 FastBitmapDrawable iconDrawable = Utilities.createIconDrawable(b);
Sunny Goyal95abbb32014-08-04 10:53:22 -0700125 iconDrawable.setGhostModeEnabled(info.isDisabled);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700126
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500127 setCompoundDrawables(null, iconDrawable, null, null);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700128 if (setDefaultPadding) {
129 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
130 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
131 }
Kenny Guyc2bd8102014-06-30 12:30:31 +0100132 if (info.contentDescription != null) {
133 setContentDescription(info.contentDescription);
134 }
Sunny Goyal508da152014-08-14 10:53:27 -0700135 setText(info.title);
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800136 setTag(info);
Sunny Goyal34846382014-07-09 00:09:28 -0700137
Sunny Goyal34942622014-08-29 17:20:55 -0700138 if (promiseStateChanged || info.isPromise()) {
139 applyState(promiseStateChanged);
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500140 }
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800141 }
142
Sunny Goyal508da152014-08-14 10:53:27 -0700143 public void applyFromApplicationInfo(AppInfo info) {
144 LauncherAppState app = LauncherAppState.getInstance();
145 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
146
147 Drawable topDrawable = Utilities.createIconDrawable(info.iconBitmap);
148 topDrawable.setBounds(0, 0, grid.allAppsIconSizePx, grid.allAppsIconSizePx);
149 setCompoundDrawables(null, topDrawable, null, null);
150 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
151 setText(info.title);
152 if (info.contentDescription != null) {
153 setContentDescription(info.contentDescription);
154 }
155 setTag(info);
156 }
157
158
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159 @Override
160 protected boolean setFrame(int left, int top, int right, int bottom) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700161 if (getLeft() != left || getRight() != right || getTop() != top || getBottom() != bottom) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 mBackgroundSizeChanged = true;
163 }
164 return super.setFrame(left, top, right, bottom);
165 }
166
167 @Override
168 protected boolean verifyDrawable(Drawable who) {
169 return who == mBackground || super.verifyDrawable(who);
170 }
171
172 @Override
Michael Jurka816474f2012-06-25 14:49:02 -0700173 public void setTag(Object tag) {
174 if (tag != null) {
175 LauncherModel.checkItemInfo((ItemInfo) tag);
176 }
177 super.setTag(tag);
178 }
179
180 @Override
Sunny Goyal508da152014-08-14 10:53:27 -0700181 public void setPressed(boolean pressed) {
182 super.setPressed(pressed);
183
184 if (!mIgnorePressedStateChange) {
185 updateIconState();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800186 }
Sunny Goyal508da152014-08-14 10:53:27 -0700187 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800188
Sunny Goyal508da152014-08-14 10:53:27 -0700189 private void updateIconState() {
190 Drawable top = getCompoundDrawables()[1];
191 if (top instanceof FastBitmapDrawable) {
192 ((FastBitmapDrawable) top).setPressed(isPressed() || mStayPressed);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800194 }
195
196 @Override
197 public boolean onTouchEvent(MotionEvent event) {
198 // Call the superclass onTouchEvent first, because sometimes it changes the state to
199 // isPressed() on an ACTION_UP
200 boolean result = super.onTouchEvent(event);
201
202 switch (event.getAction()) {
203 case MotionEvent.ACTION_DOWN:
Sunny Goyal508da152014-08-14 10:53:27 -0700204 // So that the pressed outline is visible immediately on setStayPressed(),
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800205 // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time
206 // to create it)
Sunny Goyal508da152014-08-14 10:53:27 -0700207 if (mPressedBackground == null) {
208 mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800209 }
Winson Chung88f33452012-02-23 15:23:44 -0800210
211 mLongPressHelper.postCheckForLongPress();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800212 break;
213 case MotionEvent.ACTION_CANCEL:
214 case MotionEvent.ACTION_UP:
215 // If we've touched down and up on an item, and it's still not "pressed", then
216 // destroy the pressed outline
217 if (!isPressed()) {
Sunny Goyal508da152014-08-14 10:53:27 -0700218 mPressedBackground = null;
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800219 }
Winson Chung88f33452012-02-23 15:23:44 -0800220
221 mLongPressHelper.cancelLongPress();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800222 break;
Jason Monk02dd7ae2014-04-15 15:23:31 -0400223 case MotionEvent.ACTION_MOVE:
224 if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) {
225 mLongPressHelper.cancelLongPress();
226 }
227 break;
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800228 }
229 return result;
230 }
231
Michael Jurkaddd62e92011-02-16 17:49:14 -0800232 void setStayPressed(boolean stayPressed) {
233 mStayPressed = stayPressed;
234 if (!stayPressed) {
Sunny Goyal508da152014-08-14 10:53:27 -0700235 mPressedBackground = null;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800236 }
Sunny Goyal508da152014-08-14 10:53:27 -0700237
238 // Only show the shadow effect when persistent pressed state is set.
239 if (getParent() instanceof ShortcutAndWidgetContainer) {
240 CellLayout layout = (CellLayout) getParent().getParent();
241 layout.setPressedIcon(this, mPressedBackground, mOutlineHelper.shadowBitmapPadding);
242 }
243
244 updateIconState();
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800245 }
246
Sunny Goyal508da152014-08-14 10:53:27 -0700247 void clearPressedBackground() {
248 setPressed(false);
249 setStayPressed(false);
250 }
251
252 @Override
253 public boolean onKeyDown(int keyCode, KeyEvent event) {
254 if (super.onKeyDown(keyCode, event)) {
255 // Pre-create shadow so show immediately on click.
256 if (mPressedBackground == null) {
257 mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700258 }
Sunny Goyal508da152014-08-14 10:53:27 -0700259 return true;
Patrick Dubroyd69e1132011-03-15 10:29:01 -0700260 }
Sunny Goyal508da152014-08-14 10:53:27 -0700261 return false;
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800262 }
263
Sunny Goyal508da152014-08-14 10:53:27 -0700264 @Override
265 public boolean onKeyUp(int keyCode, KeyEvent event) {
266 // Unlike touch events, keypress event propagate pressed state change immediately,
267 // without waiting for onClickHandler to execute. Disable pressed state changes here
268 // to avoid flickering.
269 mIgnorePressedStateChange = true;
270 boolean result = super.onKeyUp(keyCode, event);
Winson Chung1e9cbfe2011-09-30 16:52:26 -0700271
Sunny Goyal508da152014-08-14 10:53:27 -0700272 mPressedBackground = null;
273 mIgnorePressedStateChange = false;
274 updateIconState();
275 return result;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800276 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800277
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278 @Override
279 public void draw(Canvas canvas) {
Adam Cohen96bb7982014-07-07 11:58:56 -0700280 if (!mCustomShadowsEnabled) {
Adam Cohen477828c2013-09-20 12:05:49 -0700281 super.draw(canvas);
282 return;
283 }
284
Michael Jurkabdb5c532011-02-01 15:05:06 -0800285 final Drawable background = mBackground;
286 if (background != null) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700287 final int scrollX = getScrollX();
288 final int scrollY = getScrollY();
Winson Chung88127032010-12-13 12:11:33 -0800289
Michael Jurkabdb5c532011-02-01 15:05:06 -0800290 if (mBackgroundSizeChanged) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700291 background.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop());
Michael Jurkabdb5c532011-02-01 15:05:06 -0800292 mBackgroundSizeChanged = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 }
Michael Jurkabdb5c532011-02-01 15:05:06 -0800294
295 if ((scrollX | scrollY) == 0) {
296 background.draw(canvas);
297 } else {
298 canvas.translate(scrollX, scrollY);
299 background.draw(canvas);
300 canvas.translate(-scrollX, -scrollY);
301 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302 }
Andrew Flynn0dca1ec2012-02-29 13:33:22 -0800303
304 // If text is transparent, don't draw any shadow
Andrew Flynnbc239a12012-03-06 11:39:49 -0800305 if (getCurrentTextColor() == getResources().getColor(android.R.color.transparent)) {
Andrew Flynn0dca1ec2012-02-29 13:33:22 -0800306 getPaint().clearShadowLayer();
307 super.draw(canvas);
308 return;
309 }
310
Michael Jurkabdb5c532011-02-01 15:05:06 -0800311 // We enhance the shadow by drawing the shadow twice
Michael Jurkae7e3f6c2011-02-01 21:08:29 -0800312 getPaint().setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR);
Michael Jurkabdb5c532011-02-01 15:05:06 -0800313 super.draw(canvas);
314 canvas.save(Canvas.CLIP_SAVE_FLAG);
Michael Jurka8b805b12012-04-18 14:23:14 -0700315 canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(),
316 getScrollX() + getWidth(),
317 getScrollY() + getHeight(), Region.Op.INTERSECT);
Michael Jurkae7e3f6c2011-02-01 21:08:29 -0800318 getPaint().setShadowLayer(SHADOW_SMALL_RADIUS, 0.0f, 0.0f, SHADOW_SMALL_COLOUR);
Michael Jurkabdb5c532011-02-01 15:05:06 -0800319 super.draw(canvas);
320 canvas.restore();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400322
323 @Override
324 protected void onAttachedToWindow() {
325 super.onAttachedToWindow();
Sunny Goyal95abbb32014-08-04 10:53:22 -0700326
Winson Chung656d11c2010-11-29 17:15:47 -0800327 if (mBackground != null) mBackground.setCallback(this);
Sunny Goyal95abbb32014-08-04 10:53:22 -0700328 Drawable top = getCompoundDrawables()[1];
329
330 if (top instanceof PreloadIconDrawable) {
331 ((PreloadIconDrawable) top).applyTheme(getPreloaderTheme());
332 }
Jason Monk02dd7ae2014-04-15 15:23:31 -0400333 mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400334 }
335
336 @Override
337 protected void onDetachedFromWindow() {
338 super.onDetachedFromWindow();
Winson Chung656d11c2010-11-29 17:15:47 -0800339 if (mBackground != null) mBackground.setCallback(null);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400340 }
Winson Chungaffd7b42010-08-20 15:11:56 -0700341
Adam Cohen477828c2013-09-20 12:05:49 -0700342 @Override
343 public void setTextColor(int color) {
344 mTextColor = color;
345 super.setTextColor(color);
346 }
347
Adam Cohen96bb7982014-07-07 11:58:56 -0700348 @Override
349 public void setTextColor(ColorStateList colors) {
350 mTextColor = colors.getDefaultColor();
351 super.setTextColor(colors);
Adam Cohen477828c2013-09-20 12:05:49 -0700352 }
353
Winson Chung5f8afe62013-08-12 16:19:28 -0700354 public void setTextVisibility(boolean visible) {
355 Resources res = getResources();
356 if (visible) {
Adam Cohen477828c2013-09-20 12:05:49 -0700357 super.setTextColor(mTextColor);
Winson Chung5f8afe62013-08-12 16:19:28 -0700358 } else {
Adam Cohen477828c2013-09-20 12:05:49 -0700359 super.setTextColor(res.getColor(android.R.color.transparent));
Winson Chung5f8afe62013-08-12 16:19:28 -0700360 }
361 mIsTextVisible = visible;
362 }
363
364 public boolean isTextVisible() {
365 return mIsTextVisible;
366 }
367
Winson Chungaffd7b42010-08-20 15:11:56 -0700368 @Override
369 protected boolean onSetAlpha(int alpha) {
Winson Chunge22a8e92010-11-12 13:40:58 -0800370 return true;
Winson Chungaffd7b42010-08-20 15:11:56 -0700371 }
Winson Chung88f33452012-02-23 15:23:44 -0800372
373 @Override
374 public void cancelLongPress() {
375 super.cancelLongPress();
376
377 mLongPressHelper.cancelLongPress();
378 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500379
Sunny Goyal34942622014-08-29 17:20:55 -0700380 public void applyState(boolean promiseStateChanged) {
Sunny Goyale755d462014-07-22 13:48:29 -0700381 if (getTag() instanceof ShortcutInfo) {
Chris Wren40c5ed32014-06-24 18:24:23 -0400382 ShortcutInfo info = (ShortcutInfo) getTag();
Sunny Goyal34942622014-08-29 17:20:55 -0700383 final boolean isPromise = info.isPromise();
384 final int progressLevel = isPromise ?
385 ((info.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE) ?
386 info.getInstallProgress() : 0)) : 100;
Sunny Goyale755d462014-07-22 13:48:29 -0700387
388 Drawable[] drawables = getCompoundDrawables();
389 Drawable top = drawables[1];
390 if (top != null) {
391 final PreloadIconDrawable preloadDrawable;
392 if (top instanceof PreloadIconDrawable) {
393 preloadDrawable = (PreloadIconDrawable) top;
394 } else {
Sunny Goyal95abbb32014-08-04 10:53:22 -0700395 preloadDrawable = new PreloadIconDrawable(top, getPreloaderTheme());
Sunny Goyale755d462014-07-22 13:48:29 -0700396 setCompoundDrawables(drawables[0], preloadDrawable, drawables[2], drawables[3]);
397 }
398
399 preloadDrawable.setLevel(progressLevel);
Sunny Goyal34942622014-08-29 17:20:55 -0700400 if (promiseStateChanged) {
401 preloadDrawable.maybePerformFinishedAnimation();
Sunny Goyale755d462014-07-22 13:48:29 -0700402 }
Sunny Goyale755d462014-07-22 13:48:29 -0700403 }
Chris Wren40c5ed32014-06-24 18:24:23 -0400404 }
405 }
Sunny Goyal95abbb32014-08-04 10:53:22 -0700406
407 private Theme getPreloaderTheme() {
408 Object tag = getTag();
409 int style = ((tag != null) && (tag instanceof ShortcutInfo) &&
410 (((ShortcutInfo) tag).container >= 0)) ? R.style.PreloadIcon_Folder
411 : R.style.PreloadIcon;
412 Theme theme = sPreloaderThemes.get(style);
413 if (theme == null) {
414 theme = getResources().newTheme();
415 theme.applyStyle(style, true);
416 sPreloaderThemes.put(style, theme);
417 }
418 return theme;
419 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420}