10cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato/* 20cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * Copyright (C) 2008 The Android Open Source Project 30cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * 40cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * Licensed under the Apache License, Version 2.0 (the "License"); 50cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * you may not use this file except in compliance with the License. 60cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * You may obtain a copy of the License at 70cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * 80cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * http://www.apache.org/licenses/LICENSE-2.0 90cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * 100cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * Unless required by applicable law or agreed to in writing, software 110cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * distributed under the License is distributed on an "AS IS" BASIS, 120cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * See the License for the specific language governing permissions and 140cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * limitations under the License. 150cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato */ 160cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 1779de0c550037a5328bbc7f4fddaf02f192a5c283Joe Onoratopackage com.android.systemui.statusbar; 180cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 196179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganovimport android.app.Notification; 200cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.content.Context; 210cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.content.pm.PackageManager; 220cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.content.res.Resources; 230cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.graphics.drawable.Drawable; 240cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.graphics.Canvas; 256c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onoratoimport android.graphics.Paint; 266c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onoratoimport android.graphics.Rect; 27ded653b168b19f6061889907d4f562d764c5559bJeff Sharkeyimport android.os.UserHandle; 286179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganovimport android.text.TextUtils; 2905e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandlerimport android.util.AttributeSet; 300cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.util.Slog; 31f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onoratoimport android.util.Log; 320cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport android.view.ViewDebug; 336179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganovimport android.view.accessibility.AccessibilityEvent; 34abff032e783398be7a1c6b7e1e25a73a8467adcfDaniel Sandlerimport android.widget.ImageView; 350cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 36ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandlerimport java.text.NumberFormat; 37ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler 380cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratoimport com.android.internal.statusbar.StatusBarIcon; 390cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 406c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onoratoimport com.android.systemui.R; 416c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato 420cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onoratopublic class StatusBarIconView extends AnimatedImageView { 430cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato private static final String TAG = "StatusBarIconView"; 440cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 450cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato private StatusBarIcon mIcon; 460cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato @ViewDebug.ExportedProperty private String mSlot; 476c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato private Drawable mNumberBackground; 486c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato private Paint mNumberPain; 496c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato private int mNumberX; 506c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato private int mNumberY; 516c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato private String mNumberText; 526179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov private Notification mNotification; 530cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 546179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov public StatusBarIconView(Context context, String slot, Notification notification) { 550cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato super(context); 566c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final Resources res = context.getResources(); 570cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato mSlot = slot; 586c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberPain = new Paint(); 596c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberPain.setTextAlign(Paint.Align.CENTER); 606c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberPain.setColor(res.getColor(R.drawable.notification_number_text_color)); 616c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberPain.setAntiAlias(true); 626179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov mNotification = notification; 636179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov setContentDescription(notification); 6426c84b139f0bfd2d3906f2ac163df8f1f15155d8Daniel Sandler 657579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler // We do not resize and scale system icons (on the right), only notification icons (on the 667579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler // left). 677579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler if (notification != null) { 687579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler final int outerBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_size); 697579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler final int imageBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size); 707579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler final float scale = (float)imageBounds / (float)outerBounds; 717579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler setScaleX(scale); 727579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler setScaleY(scale); 737579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler final float alpha = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1); 747579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler setAlpha(alpha); 757579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler } 76abff032e783398be7a1c6b7e1e25a73a8467adcfDaniel Sandler 77abff032e783398be7a1c6b7e1e25a73a8467adcfDaniel Sandler setScaleType(ImageView.ScaleType.CENTER); 780cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 790cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 8005e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler public StatusBarIconView(Context context, AttributeSet attrs) { 8105e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler super(context, attrs); 8205e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler final Resources res = context.getResources(); 8305e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler final int outerBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_size); 8405e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler final int imageBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size); 8505e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler final float scale = (float)imageBounds / (float)outerBounds; 8605e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler setScaleX(scale); 8705e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler setScaleY(scale); 8805e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler final float alpha = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1); 8905e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler setAlpha(alpha); 9005e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler } 9105e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler 920cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato private static boolean streq(String a, String b) { 9366d7d01ed91968f4ed2e2669fd306aa2af61cd16Joe Onorato if (a == b) { 9466d7d01ed91968f4ed2e2669fd306aa2af61cd16Joe Onorato return true; 9566d7d01ed91968f4ed2e2669fd306aa2af61cd16Joe Onorato } 960cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato if (a == null && b != null) { 970cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return false; 980cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 990cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato if (a != null && b == null) { 1000cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return false; 1010cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1020cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return a.equals(b); 1030cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1040cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 105005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato /** 106005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato * Returns whether the set succeeded. 107005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato */ 108005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato public boolean set(StatusBarIcon icon) { 109005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato final boolean iconEquals = mIcon != null 110005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato && streq(mIcon.iconPackage, icon.iconPackage) 111005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato && mIcon.iconId == icon.iconId; 112005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato final boolean levelEquals = iconEquals 113005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato && mIcon.iconLevel == icon.iconLevel; 114005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato final boolean visibilityEquals = mIcon != null 115005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato && mIcon.visible == icon.visible; 1166c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final boolean numberEquals = mIcon != null 1176c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato && mIcon.number == icon.number; 1186c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mIcon = icon.clone(); 1196179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov setContentDescription(icon.contentDescription); 120005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato if (!iconEquals) { 121005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato Drawable drawable = getIcon(icon); 122005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato if (drawable == null) { 123c6d29fc0f552db7cfee6491530cf89f59c242bd4Daniel Sandler Slog.w(TAG, "No icon for slot " + mSlot); 124005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato return false; 125871bdb9867f6630d8bb28e5607263e8bf4eac3baJoe Onorato } 126005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato setImageDrawable(drawable); 127005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato } 128005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato if (!levelEquals) { 129005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato setImageLevel(icon.iconLevel); 1300cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 13126c84b139f0bfd2d3906f2ac163df8f1f15155d8Daniel Sandler 1326c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato if (!numberEquals) { 1338595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato if (icon.number > 0 && mContext.getResources().getBoolean( 1348595a3dd9a6feff70f8ddbad924d79b591d611e4Joe Onorato R.bool.config_statusBarShowNumber)) { 1356c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato if (mNumberBackground == null) { 1366c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberBackground = getContext().getResources().getDrawable( 1376c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato R.drawable.ic_notification_overlay); 1386c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 1396c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato placeNumber(); 1406c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } else { 1416c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberBackground = null; 1426c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberText = null; 1436c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 1446c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato invalidate(); 1456c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 146005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato if (!visibilityEquals) { 147005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato setVisibility(icon.visible ? VISIBLE : GONE); 1480cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 149005847b03b2ebe3eb1a974a8a04ad51bca6636cdJoe Onorato return true; 1500cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1510cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 152f55105405578bfd8315584e69faa655800edef77Joe Onorato private Drawable getIcon(StatusBarIcon icon) { 153f55105405578bfd8315584e69faa655800edef77Joe Onorato return getIcon(getContext(), icon); 154f55105405578bfd8315584e69faa655800edef77Joe Onorato } 155f55105405578bfd8315584e69faa655800edef77Joe Onorato 1560cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato /** 1570cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * Returns the right icon to use for this item, respecting the iconId and 1580cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * iconPackage (if set) 1590cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * 1600cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * @param context Context to use to get resources if iconPackage is not set 1610cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * @return Drawable for this item, or null if the package or item could not 1620cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato * be found 1630cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato */ 164f55105405578bfd8315584e69faa655800edef77Joe Onorato public static Drawable getIcon(Context context, StatusBarIcon icon) { 1650cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato Resources r = null; 1660cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 1670cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato if (icon.iconPackage != null) { 1680cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato try { 169ded653b168b19f6061889907d4f562d764c5559bJeff Sharkey int userId = icon.user.getIdentifier(); 170ded653b168b19f6061889907d4f562d764c5559bJeff Sharkey if (userId == UserHandle.USER_ALL) { 171ded653b168b19f6061889907d4f562d764c5559bJeff Sharkey userId = UserHandle.USER_OWNER; 172ded653b168b19f6061889907d4f562d764c5559bJeff Sharkey } 173ded653b168b19f6061889907d4f562d764c5559bJeff Sharkey r = context.getPackageManager() 174ded653b168b19f6061889907d4f562d764c5559bJeff Sharkey .getResourcesForApplicationAsUser(icon.iconPackage, userId); 1750cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } catch (PackageManager.NameNotFoundException ex) { 176c6d29fc0f552db7cfee6491530cf89f59c242bd4Daniel Sandler Slog.e(TAG, "Icon package not found: " + icon.iconPackage); 1770cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return null; 1780cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1790cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } else { 1800cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato r = context.getResources(); 1810cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1820cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 1830cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato if (icon.iconId == 0) { 1840cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return null; 1850cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1860cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 1870cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato try { 1880cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return r.getDrawable(icon.iconId); 1890cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } catch (RuntimeException e) { 190c6d29fc0f552db7cfee6491530cf89f59c242bd4Daniel Sandler Slog.w(TAG, "Icon not found in " 1910cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato + (icon.iconPackage != null ? icon.iconId : "<system>") 1920cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato + ": " + Integer.toHexString(icon.iconId)); 1930cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 1940cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato 1950cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato return null; 1960cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato } 197b77f53b21c2185ae3ff7c219c384a6db73f8f4e4Joe Onorato 198b77f53b21c2185ae3ff7c219c384a6db73f8f4e4Joe Onorato public StatusBarIcon getStatusBarIcon() { 199b77f53b21c2185ae3ff7c219c384a6db73f8f4e4Joe Onorato return mIcon; 200b77f53b21c2185ae3ff7c219c384a6db73f8f4e4Joe Onorato } 201f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onorato 2026179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov @Override 2036179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 2046179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov super.onInitializeAccessibilityEvent(event); 2056179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov if (mNotification != null) { 2066179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov event.setParcelableData(mNotification); 2076179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov } 2086179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov } 2096179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov 2106179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov @Override 2116c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato protected void onSizeChanged(int w, int h, int oldw, int oldh) { 2126c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato super.onSizeChanged(w, h, oldw, oldh); 2136c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato if (mNumberBackground != null) { 2146c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato placeNumber(); 2156c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2166c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2176c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato 2186179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov @Override 2196c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato protected void onDraw(Canvas canvas) { 2206c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato super.onDraw(canvas); 2216c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato 2226c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato if (mNumberBackground != null) { 2236c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberBackground.draw(canvas); 2246c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain); 2256c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2266c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2276c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato 2286179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov @Override 229f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onorato protected void debug(int depth) { 230f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onorato super.debug(depth); 231f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onorato Log.d("View", debugIndent(depth) + "slot=" + mSlot); 232f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onorato Log.d("View", debugIndent(depth) + "icon=" + mIcon); 233f9ec03c0f5fc2c6eba5bbead24c4eb314c0205beJoe Onorato } 2346c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato 2356c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato void placeNumber() { 236ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler final String str; 237ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler final int tooBig = mContext.getResources().getInteger( 238ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler android.R.integer.status_bar_notification_info_maxnum); 239ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler if (mIcon.number > tooBig) { 240ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler str = mContext.getResources().getString( 241ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler android.R.string.status_bar_notification_info_overflow); 242ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler } else { 243ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler NumberFormat f = NumberFormat.getIntegerInstance(); 244ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler str = f.format(mIcon.number); 245ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler } 246ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler mNumberText = str; 247ebce0115e239919680fc5574ae4ca79e617fcce8Daniel Sandler 2486c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final int w = getWidth(); 2496c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final int h = getHeight(); 2506c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final Rect r = new Rect(); 2516c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberPain.getTextBounds(str, 0, str.length(), r); 2526c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final int tw = r.right - r.left; 2536c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato final int th = r.bottom - r.top; 2546c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberBackground.getPadding(r); 2556c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato int dw = r.left + tw + r.right; 2566c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato if (dw < mNumberBackground.getMinimumWidth()) { 2576c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato dw = mNumberBackground.getMinimumWidth(); 2586c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2596c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberX = w-r.right-((dw-r.right-r.left)/2); 2606c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato int dh = r.top + th + r.bottom; 2616c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato if (dh < mNumberBackground.getMinimumWidth()) { 2626c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato dh = mNumberBackground.getMinimumWidth(); 2636c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2646c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2); 2656c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato mNumberBackground.setBounds(w-dw, h-dh, w, h); 2666c01a11a20d5fc796360e5e97998401a6cc84f27Joe Onorato } 2676179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov 2686179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov private void setContentDescription(Notification notification) { 2696179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov if (notification != null) { 2706179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov CharSequence tickerText = notification.tickerText; 2716179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov if (!TextUtils.isEmpty(tickerText)) { 2726179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov setContentDescription(tickerText); 2736179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov } 2746179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov } 2756179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov } 2767579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler 2777579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler public String toString() { 2787579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler return "StatusBarIconView(slot=" + mSlot + " icon=" + mIcon 2797579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler + " notification=" + mNotification + ")"; 2807579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler } 2810cbda99f8721ad9b03ada04d2637fb75a2a0fecaJoe Onorato} 282