blob: c180d32275e8d4e9d68477f0549cad645da4a379 [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;
Winson Chung656d11c2010-11-29 17:15:47 -080020import android.content.res.Resources;
Michael Jurka67b2f6c2010-11-17 12:33:46 -080021import android.graphics.Bitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022import android.graphics.Canvas;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080023import android.graphics.Rect;
Michael Jurka137142e2011-01-05 20:57:04 -080024import android.graphics.Region;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080025import android.graphics.Region.Op;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026import android.graphics.drawable.Drawable;
Winson Chung656d11c2010-11-29 17:15:47 -080027import android.util.AttributeSet;
Chris Wrenaeff7ea2014-02-14 16:59:24 -050028import android.util.Log;
Winson Chung5f8afe62013-08-12 16:19:28 -070029import android.util.TypedValue;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080030import android.view.MotionEvent;
Michael Jurkabdb5c532011-02-01 15:05:06 -080031import android.widget.TextView;
Romain Guyedcce092010-03-04 13:03:17 -080032
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033/**
34 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
35 * because we want to make the bubble taller than the text and TextView's clip is
36 * too aggressive.
37 */
Michael Jurka08ee7702011-08-11 16:53:35 -070038public class BubbleTextView extends TextView {
Winson Chung88127032010-12-13 12:11:33 -080039 static final float SHADOW_LARGE_RADIUS = 4.0f;
40 static final float SHADOW_SMALL_RADIUS = 1.75f;
41 static final float SHADOW_Y_OFFSET = 2.0f;
Winson Chungc7aef8c2011-09-15 18:53:04 -070042 static final int SHADOW_LARGE_COLOUR = 0xDD000000;
43 static final int SHADOW_SMALL_COLOUR = 0xCC000000;
Winson Chung656d11c2010-11-29 17:15:47 -080044 static final float PADDING_H = 8.0f;
45 static final float PADDING_V = 3.0f;
46
Chris Wrenaeff7ea2014-02-14 16:59:24 -050047 private static final String TAG = "BubbleTextView";
48
49 private static final boolean DEBUG = false;
50
Winson Chunge22a8e92010-11-12 13:40:58 -080051 private int mPrevAlpha = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052
Daniel Sandlere4f98912013-06-25 15:13:26 -040053 private HolographicOutlineHelper mOutlineHelper;
Michael Jurka38b4f7c2010-12-14 16:46:39 -080054 private final Canvas mTempCanvas = new Canvas();
55 private final Rect mTempRect = new Rect();
Michael Jurka38b4f7c2010-12-14 16:46:39 -080056 private boolean mDidInvalidateForPressedState;
57 private Bitmap mPressedOrFocusedBackground;
58 private int mFocusedOutlineColor;
59 private int mFocusedGlowColor;
60 private int mPressedOutlineColor;
61 private int mPressedGlowColor;
62
Adam Cohen477828c2013-09-20 12:05:49 -070063 private int mTextColor;
64 private boolean mShadowsEnabled = true;
Winson Chung5f8afe62013-08-12 16:19:28 -070065 private boolean mIsTextVisible;
66
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067 private boolean mBackgroundSizeChanged;
68 private Drawable mBackground;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069
Michael Jurkaddd62e92011-02-16 17:49:14 -080070 private boolean mStayPressed;
Winson Chung88f33452012-02-23 15:23:44 -080071 private CheckLongPressHelper mLongPressHelper;
Chris Wrenaeff7ea2014-02-14 16:59:24 -050072 private int mInstallState;
73
74 private int mState;
75
76 private CharSequence mDefaultText = "";
Michael Jurkaddd62e92011-02-16 17:49:14 -080077
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078 public BubbleTextView(Context context) {
79 super(context);
80 init();
81 }
82
83 public BubbleTextView(Context context, AttributeSet attrs) {
84 super(context, attrs);
85 init();
86 }
87
88 public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
89 super(context, attrs, defStyle);
90 init();
91 }
92
Winson Chung5f8afe62013-08-12 16:19:28 -070093 public void onFinishInflate() {
94 super.onFinishInflate();
95
96 // Ensure we are using the right text size
97 LauncherAppState app = LauncherAppState.getInstance();
98 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
Winson Chung6e1c0d32013-10-25 15:24:24 -070099 setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
Adam Cohen477828c2013-09-20 12:05:49 -0700100 setTextColor(getResources().getColor(R.color.workspace_icon_text_color));
Winson Chung5f8afe62013-08-12 16:19:28 -0700101 }
102
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800103 private void init() {
Winson Chung88f33452012-02-23 15:23:44 -0800104 mLongPressHelper = new CheckLongPressHelper(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800105 mBackground = getBackground();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106
Daniel Sandlere4f98912013-06-25 15:13:26 -0400107 mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
108
Winson Chung656d11c2010-11-29 17:15:47 -0800109 final Resources res = getContext().getResources();
Winson Chung7d3810d2011-10-07 13:11:56 -0700110 mFocusedOutlineColor = mFocusedGlowColor = mPressedOutlineColor = mPressedGlowColor =
Adam Cohen410f3cd2013-09-22 12:09:32 -0700111 res.getColor(R.color.outline_color);
Michael Jurkae7e3f6c2011-02-01 21:08:29 -0800112
113 setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114 }
115
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800116 public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {
117 Bitmap b = info.getIcon(iconCache);
Winson Chungcdef0442013-09-19 17:32:58 -0700118 LauncherAppState app = LauncherAppState.getInstance();
119 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800120
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500121 Drawable iconDrawable = Utilities.createIconDrawable(b);
122 setCompoundDrawables(null, iconDrawable, null, null);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700123 setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800124 setText(info.title);
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800125 setTag(info);
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500126 if (info.isPromise()) {
127 setState(ShortcutInfo.PACKAGE_STATE_UNKNOWN); // TODO: persist this state somewhere
128 }
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800129 }
130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 @Override
132 protected boolean setFrame(int left, int top, int right, int bottom) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700133 if (getLeft() != left || getRight() != right || getTop() != top || getBottom() != bottom) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 mBackgroundSizeChanged = true;
135 }
136 return super.setFrame(left, top, right, bottom);
137 }
138
139 @Override
140 protected boolean verifyDrawable(Drawable who) {
141 return who == mBackground || super.verifyDrawable(who);
142 }
143
144 @Override
Michael Jurka816474f2012-06-25 14:49:02 -0700145 public void setTag(Object tag) {
146 if (tag != null) {
147 LauncherModel.checkItemInfo((ItemInfo) tag);
148 }
149 super.setTag(tag);
150 }
151
152 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 protected void drawableStateChanged() {
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800154 if (isPressed()) {
155 // In this case, we have already created the pressed outline on ACTION_DOWN,
156 // so we just need to do an invalidate to trigger draw
157 if (!mDidInvalidateForPressedState) {
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800158 setCellLayoutPressedOrFocusedIcon();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800159 }
160 } else {
161 // Otherwise, either clear the pressed/focused background, or create a background
162 // for the focused state
163 final boolean backgroundEmptyBefore = mPressedOrFocusedBackground == null;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800164 if (!mStayPressed) {
165 mPressedOrFocusedBackground = null;
166 }
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800167 if (isFocused()) {
Gilles Debunnec7869522011-11-28 18:03:56 -0800168 if (getLayout() == null) {
Patrick Dubroya017c032011-03-09 15:58:32 -0800169 // In some cases, we get focus before we have been layed out. Set the
170 // background to null so that it will get created when the view is drawn.
171 mPressedOrFocusedBackground = null;
172 } else {
173 mPressedOrFocusedBackground = createGlowingOutline(
174 mTempCanvas, mFocusedGlowColor, mFocusedOutlineColor);
175 }
Michael Jurkaddd62e92011-02-16 17:49:14 -0800176 mStayPressed = false;
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800177 setCellLayoutPressedOrFocusedIcon();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800178 }
179 final boolean backgroundEmptyNow = mPressedOrFocusedBackground == null;
180 if (!backgroundEmptyBefore && backgroundEmptyNow) {
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800181 setCellLayoutPressedOrFocusedIcon();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800182 }
183 }
184
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 Drawable d = mBackground;
186 if (d != null && d.isStateful()) {
187 d.setState(getDrawableState());
188 }
189 super.drawableStateChanged();
190 }
191
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800192 /**
Patrick Dubroycd953712011-02-28 15:16:42 -0800193 * Draw this BubbleTextView into the given Canvas.
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800194 *
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800195 * @param destCanvas the canvas to draw on
196 * @param padding the horizontal and vertical padding to use when drawing
197 */
198 private void drawWithPadding(Canvas destCanvas, int padding) {
199 final Rect clipRect = mTempRect;
200 getDrawingRect(clipRect);
201
202 // adjust the clip rect so that we don't include the text label
203 clipRect.bottom =
204 getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + getLayout().getLineTop(0);
205
206 // Draw the View into the bitmap.
207 // The translate of scrollX and scrollY is necessary when drawing TextViews, because
208 // they set scrollX and scrollY to large values to achieve centered text
209 destCanvas.save();
Winson Chungeecf02d2012-03-02 17:14:58 -0800210 destCanvas.scale(getScaleX(), getScaleY(),
211 (getWidth() + padding) / 2, (getHeight() + padding) / 2);
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800212 destCanvas.translate(-getScrollX() + padding / 2, -getScrollY() + padding / 2);
213 destCanvas.clipRect(clipRect, Op.REPLACE);
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800214 draw(destCanvas);
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800215 destCanvas.restore();
216 }
217
Adam Cohen7397e622013-10-24 12:11:34 -0700218 public void setGlowColor(int color) {
219 mFocusedOutlineColor = mFocusedGlowColor = mPressedOutlineColor = mPressedGlowColor = color;
220 }
221
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800222 /**
223 * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
224 * Responsibility for the bitmap is transferred to the caller.
225 */
226 private Bitmap createGlowingOutline(Canvas canvas, int outlineColor, int glowColor) {
Daniel Sandlere4f98912013-06-25 15:13:26 -0400227 final int padding = mOutlineHelper.mMaxOuterBlurRadius;
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800228 final Bitmap b = Bitmap.createBitmap(
229 getWidth() + padding, getHeight() + padding, Bitmap.Config.ARGB_8888);
230
231 canvas.setBitmap(b);
232 drawWithPadding(canvas, padding);
233 mOutlineHelper.applyExtraThickExpensiveOutlineWithBlur(b, canvas, glowColor, outlineColor);
Adam Cohenaaf473c2011-08-03 12:02:47 -0700234 canvas.setBitmap(null);
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800235
236 return b;
237 }
238
239 @Override
240 public boolean onTouchEvent(MotionEvent event) {
241 // Call the superclass onTouchEvent first, because sometimes it changes the state to
242 // isPressed() on an ACTION_UP
243 boolean result = super.onTouchEvent(event);
244
245 switch (event.getAction()) {
246 case MotionEvent.ACTION_DOWN:
247 // So that the pressed outline is visible immediately when isPressed() is true,
248 // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time
249 // to create it)
250 if (mPressedOrFocusedBackground == null) {
251 mPressedOrFocusedBackground = createGlowingOutline(
252 mTempCanvas, mPressedGlowColor, mPressedOutlineColor);
253 }
254 // Invalidate so the pressed state is visible, or set a flag so we know that we
255 // have to call invalidate as soon as the state is "pressed"
256 if (isPressed()) {
257 mDidInvalidateForPressedState = true;
Michael Jurkae6235dd2011-10-04 15:02:05 -0700258 setCellLayoutPressedOrFocusedIcon();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800259 } else {
260 mDidInvalidateForPressedState = false;
261 }
Winson Chung88f33452012-02-23 15:23:44 -0800262
263 mLongPressHelper.postCheckForLongPress();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800264 break;
265 case MotionEvent.ACTION_CANCEL:
266 case MotionEvent.ACTION_UP:
267 // If we've touched down and up on an item, and it's still not "pressed", then
268 // destroy the pressed outline
269 if (!isPressed()) {
270 mPressedOrFocusedBackground = null;
271 }
Winson Chung88f33452012-02-23 15:23:44 -0800272
273 mLongPressHelper.cancelLongPress();
Michael Jurka38b4f7c2010-12-14 16:46:39 -0800274 break;
275 }
276 return result;
277 }
278
Michael Jurkaddd62e92011-02-16 17:49:14 -0800279 void setStayPressed(boolean stayPressed) {
280 mStayPressed = stayPressed;
281 if (!stayPressed) {
282 mPressedOrFocusedBackground = null;
283 }
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800284 setCellLayoutPressedOrFocusedIcon();
285 }
286
287 void setCellLayoutPressedOrFocusedIcon() {
Michael Jurkaa52570f2012-03-20 03:18:20 -0700288 if (getParent() instanceof ShortcutAndWidgetContainer) {
289 ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) getParent();
Adam Cohen76fc0852011-06-17 13:26:23 -0700290 if (parent != null) {
291 CellLayout layout = (CellLayout) parent.getParent();
292 layout.setPressedOrFocusedIcon((mPressedOrFocusedBackground != null) ? this : null);
293 }
Patrick Dubroyd69e1132011-03-15 10:29:01 -0700294 }
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800295 }
296
Winson Chung1e9cbfe2011-09-30 16:52:26 -0700297 void clearPressedOrFocusedBackground() {
298 mPressedOrFocusedBackground = null;
299 setCellLayoutPressedOrFocusedIcon();
300 }
301
Patrick Dubroy3499d8c2011-03-10 17:17:23 -0800302 Bitmap getPressedOrFocusedBackground() {
303 return mPressedOrFocusedBackground;
304 }
305
306 int getPressedOrFocusedBackgroundPadding() {
Daniel Sandlere4f98912013-06-25 15:13:26 -0400307 return mOutlineHelper.mMaxOuterBlurRadius / 2;
Michael Jurkaddd62e92011-02-16 17:49:14 -0800308 }
Patrick Dubroya017c032011-03-09 15:58:32 -0800309
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800310 @Override
311 public void draw(Canvas canvas) {
Adam Cohen477828c2013-09-20 12:05:49 -0700312 if (!mShadowsEnabled) {
313 super.draw(canvas);
314 return;
315 }
316
Michael Jurkabdb5c532011-02-01 15:05:06 -0800317 final Drawable background = mBackground;
318 if (background != null) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700319 final int scrollX = getScrollX();
320 final int scrollY = getScrollY();
Winson Chung88127032010-12-13 12:11:33 -0800321
Michael Jurkabdb5c532011-02-01 15:05:06 -0800322 if (mBackgroundSizeChanged) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700323 background.setBounds(0, 0, getRight() - getLeft(), getBottom() - getTop());
Michael Jurkabdb5c532011-02-01 15:05:06 -0800324 mBackgroundSizeChanged = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800325 }
Michael Jurkabdb5c532011-02-01 15:05:06 -0800326
327 if ((scrollX | scrollY) == 0) {
328 background.draw(canvas);
329 } else {
330 canvas.translate(scrollX, scrollY);
331 background.draw(canvas);
332 canvas.translate(-scrollX, -scrollY);
333 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800334 }
Andrew Flynn0dca1ec2012-02-29 13:33:22 -0800335
336 // If text is transparent, don't draw any shadow
Andrew Flynnbc239a12012-03-06 11:39:49 -0800337 if (getCurrentTextColor() == getResources().getColor(android.R.color.transparent)) {
Andrew Flynn0dca1ec2012-02-29 13:33:22 -0800338 getPaint().clearShadowLayer();
339 super.draw(canvas);
340 return;
341 }
342
Michael Jurkabdb5c532011-02-01 15:05:06 -0800343 // We enhance the shadow by drawing the shadow twice
Michael Jurkae7e3f6c2011-02-01 21:08:29 -0800344 getPaint().setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR);
Michael Jurkabdb5c532011-02-01 15:05:06 -0800345 super.draw(canvas);
346 canvas.save(Canvas.CLIP_SAVE_FLAG);
Michael Jurka8b805b12012-04-18 14:23:14 -0700347 canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(),
348 getScrollX() + getWidth(),
349 getScrollY() + getHeight(), Region.Op.INTERSECT);
Michael Jurkae7e3f6c2011-02-01 21:08:29 -0800350 getPaint().setShadowLayer(SHADOW_SMALL_RADIUS, 0.0f, 0.0f, SHADOW_SMALL_COLOUR);
Michael Jurkabdb5c532011-02-01 15:05:06 -0800351 super.draw(canvas);
352 canvas.restore();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400354
355 @Override
356 protected void onAttachedToWindow() {
357 super.onAttachedToWindow();
Winson Chung656d11c2010-11-29 17:15:47 -0800358 if (mBackground != null) mBackground.setCallback(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400359 }
360
361 @Override
362 protected void onDetachedFromWindow() {
363 super.onDetachedFromWindow();
Winson Chung656d11c2010-11-29 17:15:47 -0800364 if (mBackground != null) mBackground.setCallback(null);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400365 }
Winson Chungaffd7b42010-08-20 15:11:56 -0700366
Adam Cohen477828c2013-09-20 12:05:49 -0700367 @Override
368 public void setTextColor(int color) {
369 mTextColor = color;
370 super.setTextColor(color);
371 }
372
373 public void setShadowsEnabled(boolean enabled) {
374 mShadowsEnabled = enabled;
375 getPaint().clearShadowLayer();
376 invalidate();
377 }
378
Winson Chung5f8afe62013-08-12 16:19:28 -0700379 public void setTextVisibility(boolean visible) {
380 Resources res = getResources();
381 if (visible) {
Adam Cohen477828c2013-09-20 12:05:49 -0700382 super.setTextColor(mTextColor);
Winson Chung5f8afe62013-08-12 16:19:28 -0700383 } else {
Adam Cohen477828c2013-09-20 12:05:49 -0700384 super.setTextColor(res.getColor(android.R.color.transparent));
Winson Chung5f8afe62013-08-12 16:19:28 -0700385 }
386 mIsTextVisible = visible;
387 }
388
389 public boolean isTextVisible() {
390 return mIsTextVisible;
391 }
392
Winson Chungaffd7b42010-08-20 15:11:56 -0700393 @Override
394 protected boolean onSetAlpha(int alpha) {
Winson Chunge22a8e92010-11-12 13:40:58 -0800395 if (mPrevAlpha != alpha) {
396 mPrevAlpha = alpha;
Winson Chunge22a8e92010-11-12 13:40:58 -0800397 super.onSetAlpha(alpha);
398 }
399 return true;
Winson Chungaffd7b42010-08-20 15:11:56 -0700400 }
Winson Chung88f33452012-02-23 15:23:44 -0800401
402 @Override
403 public void cancelLongPress() {
404 super.cancelLongPress();
405
406 mLongPressHelper.cancelLongPress();
407 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -0500408
409 public void setState(int state) {
410 if (mState == ShortcutInfo.PACKAGE_STATE_DEFAULT && mState != state) {
411 mDefaultText = getText();
412 }
413 mState = state;
414 applyState();
415 }
416
417 private void applyState() {
418 int alpha = getResources().getInteger(R.integer.promise_icon_alpha);
419 if (DEBUG) Log.d(TAG, "applying icon state: " + mState);
420
421 switch(mState) {
422 case ShortcutInfo.PACKAGE_STATE_DEFAULT:
423 super.setText(mDefaultText);
424 alpha = 255;
425 break;
426
427 case ShortcutInfo.PACKAGE_STATE_ENQUEUED:
428 setText(R.string.package_state_enqueued);
429 break;
430
431 case ShortcutInfo.PACKAGE_STATE_DOWNLOADING:
432 setText(R.string.package_state_downloading);
433 break;
434
435 case ShortcutInfo.PACKAGE_STATE_INSTALLING:
436 setText(R.string.package_state_installing);
437 break;
438
439 case ShortcutInfo.PACKAGE_STATE_ERROR:
440 setText(R.string.package_state_error);
441 break;
442
443 case ShortcutInfo.PACKAGE_STATE_UNKNOWN:
444 default:
445 setText(R.string.package_state_unknown);
446 break;
447 }
448 if (DEBUG) Log.d(TAG, "setting icon alpha to: " + alpha);
449 Drawable[] drawables = getCompoundDrawables();
450 for (int i = 0; i < drawables.length; i++) {
451 if (drawables[i] != null) {
452 drawables[i].setAlpha(alpha);
453 }
454 }
455 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456}