blob: 27cb077394b12a4f53af463e74bc104bd0825cc9 [file] [log] [blame]
Joe Onorato0cbda992010-05-02 16:28:15 -07001/*
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 Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
Joe Onorato0cbda992010-05-02 16:28:15 -070018
Evan Lairde1d13c92018-03-20 16:58:01 -040019import static com.android.systemui.statusbar.policy.DarkIconDispatcher.getTint;
20
Selim Cinek49014f82016-11-04 14:55:30 -070021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
23import android.animation.ObjectAnimator;
Selim Cinek875ba9b2017-02-13 16:20:17 -080024import android.animation.ValueAnimator;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070025import android.app.Notification;
Joe Onorato0cbda992010-05-02 16:28:15 -070026import android.content.Context;
Adrian Roosa8e18ef2016-05-26 17:17:02 -070027import android.content.pm.ApplicationInfo;
Evan Lairde1d13c92018-03-20 16:58:01 -040028import android.content.res.ColorStateList;
Selim Cinek3e7592d2016-04-11 09:35:54 +080029import android.content.res.Configuration;
Joe Onorato0cbda992010-05-02 16:28:15 -070030import android.content.res.Resources;
Joe Onorato0cbda992010-05-02 16:28:15 -070031import android.graphics.Canvas;
Adrian Roos456e0052017-04-04 16:44:29 -070032import android.graphics.Color;
Adrian Roosc3e8cfc2017-07-17 17:09:39 +020033import android.graphics.ColorMatrixColorFilter;
Joe Onorato6c01a112010-10-04 17:38:47 -040034import android.graphics.Paint;
35import android.graphics.Rect;
John Spurlockde84f0e2013-06-12 12:41:00 -040036import android.graphics.drawable.Drawable;
Dan Sandlerd63f9322015-05-06 15:18:49 -040037import android.graphics.drawable.Icon;
Adrian Roosa8e18ef2016-05-26 17:17:02 -070038import android.os.Parcelable;
Jeff Sharkeyded653b2012-09-27 19:09:24 -070039import android.os.UserHandle;
Selim Cinek72fc8db2017-06-06 18:07:47 -070040import android.service.notification.StatusBarNotification;
Lucas Dupin83519da2017-06-21 11:58:31 -070041import android.support.v4.graphics.ColorUtils;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070042import android.text.TextUtils;
Daniel Sandler05e24142011-11-10 11:56:49 -050043import android.util.AttributeSet;
Selim Cinek49014f82016-11-04 14:55:30 -070044import android.util.FloatProperty;
Joe Onoratof9ec03c2010-09-23 15:09:18 -070045import android.util.Log;
Selim Cinek49014f82016-11-04 14:55:30 -070046import android.util.Property;
Anthony Chen55e8e1e2016-01-08 10:31:46 -080047import android.util.TypedValue;
Joe Onorato0cbda992010-05-02 16:28:15 -070048import android.view.ViewDebug;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070049import android.view.accessibility.AccessibilityEvent;
Selim Cinek49014f82016-11-04 14:55:30 -070050import android.view.animation.Interpolator;
Winsonc0d70582016-01-29 10:24:39 -080051
Joe Onorato0cbda992010-05-02 16:28:15 -070052import com.android.internal.statusbar.StatusBarIcon;
Lucas Dupin83519da2017-06-21 11:58:31 -070053import com.android.internal.util.NotificationColorUtil;
Selim Cinek49014f82016-11-04 14:55:30 -070054import com.android.systemui.Interpolators;
Joe Onorato6c01a112010-10-04 17:38:47 -040055import com.android.systemui.R;
Adrian Roos456e0052017-04-04 16:44:29 -070056import com.android.systemui.statusbar.notification.NotificationIconDozeHelper;
Selim Cinek49014f82016-11-04 14:55:30 -070057import com.android.systemui.statusbar.notification.NotificationUtils;
Joe Onorato6c01a112010-10-04 17:38:47 -040058
John Spurlockde84f0e2013-06-12 12:41:00 -040059import java.text.NumberFormat;
Adrian Roosc3e8cfc2017-07-17 17:09:39 +020060import java.util.Arrays;
John Spurlockde84f0e2013-06-12 12:41:00 -040061
Evan Lairde1d13c92018-03-20 16:58:01 -040062public class StatusBarIconView extends AnimatedImageView implements StatusIconDisplayable {
Selim Cinek875ba9b2017-02-13 16:20:17 -080063 public static final int NO_COLOR = 0;
Adrian Roosc3e8cfc2017-07-17 17:09:39 +020064
65 /**
66 * Multiply alpha values with (1+DARK_ALPHA_BOOST) when dozing. The chosen value boosts
67 * everything above 30% to 50%, making it appear on 1bit color depths.
68 */
69 private static final float DARK_ALPHA_BOOST = 0.67f;
Evan Laird39ea8102018-05-18 19:49:07 -040070 /**
71 * Status icons are currently drawn with the intention of being 17dp tall, but we
72 * want to scale them (in a way that doesn't require an asset dump) down 2dp. So
73 * 17dp * (15 / 17) = 15dp, the new height.
74 */
75 private static final float SYSTEM_ICON_SCALE = 15.f / 17.f;
Selim Cinek875ba9b2017-02-13 16:20:17 -080076 private final int ANIMATION_DURATION_FAST = 100;
77
Selim Cinek49014f82016-11-04 14:55:30 -070078 public static final int STATE_ICON = 0;
79 public static final int STATE_DOT = 1;
80 public static final int STATE_HIDDEN = 2;
Joe Onorato0cbda992010-05-02 16:28:15 -070081
Selim Cinek49014f82016-11-04 14:55:30 -070082 private static final String TAG = "StatusBarIconView";
83 private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
84 = new FloatProperty<StatusBarIconView>("iconAppearAmount") {
85
86 @Override
87 public void setValue(StatusBarIconView object, float value) {
88 object.setIconAppearAmount(value);
89 }
90
91 @Override
92 public Float get(StatusBarIconView object) {
93 return object.getIconAppearAmount();
94 }
95 };
Selim Cinek5b5beb012016-11-08 18:11:58 -080096 private static final Property<StatusBarIconView, Float> DOT_APPEAR_AMOUNT
Selim Cinek49014f82016-11-04 14:55:30 -070097 = new FloatProperty<StatusBarIconView>("dot_appear_amount") {
98
99 @Override
100 public void setValue(StatusBarIconView object, float value) {
101 object.setDotAppearAmount(value);
102 }
103
104 @Override
105 public Float get(StatusBarIconView object) {
106 return object.getDotAppearAmount();
107 }
108 };
109
110 private boolean mAlwaysScaleIcon;
Adrian Roos138f0342017-04-28 09:11:28 -0700111 private int mStatusBarIconDrawingSizeDark = 1;
112 private int mStatusBarIconDrawingSize = 1;
113 private int mStatusBarIconSize = 1;
Joe Onorato0cbda992010-05-02 16:28:15 -0700114 private StatusBarIcon mIcon;
115 @ViewDebug.ExportedProperty private String mSlot;
Joe Onorato6c01a112010-10-04 17:38:47 -0400116 private Drawable mNumberBackground;
117 private Paint mNumberPain;
118 private int mNumberX;
119 private int mNumberY;
120 private String mNumberText;
Selim Cinek72fc8db2017-06-06 18:07:47 -0700121 private StatusBarNotification mNotification;
Jason Monk3b230072015-05-29 11:11:29 -0400122 private final boolean mBlocked;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800123 private int mDensity;
Selim Cinek281c2022016-10-13 19:14:43 -0700124 private float mIconScale = 1.0f;
Evan Lairdbaccb462018-06-01 16:29:02 -0400125 private final Paint mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Selim Cinek49014f82016-11-04 14:55:30 -0700126 private float mDotRadius;
127 private int mStaticDotRadius;
128 private int mVisibleState = STATE_ICON;
129 private float mIconAppearAmount = 1.0f;
130 private ObjectAnimator mIconAppearAnimator;
131 private ObjectAnimator mDotAnimator;
132 private float mDotAppearAmount;
Selim Cinek2b549f42016-11-22 16:38:51 -0800133 private OnVisibilityChangedListener mOnVisibilityChangedListener;
Selim Cinek875ba9b2017-02-13 16:20:17 -0800134 private int mDrawableColor;
135 private int mIconColor;
Adrian Roos456e0052017-04-04 16:44:29 -0700136 private int mDecorColor;
137 private float mDarkAmount;
Selim Cinek875ba9b2017-02-13 16:20:17 -0800138 private ValueAnimator mColorAnimator;
139 private int mCurrentSetColor = NO_COLOR;
140 private int mAnimationStartColor = NO_COLOR;
141 private final ValueAnimator.AnimatorUpdateListener mColorUpdater
142 = animation -> {
143 int newColor = NotificationUtils.interpolateColors(mAnimationStartColor, mIconColor,
144 animation.getAnimatedFraction());
145 setColorInternal(newColor);
146 };
Adrian Roos456e0052017-04-04 16:44:29 -0700147 private final NotificationIconDozeHelper mDozer;
Lucas Dupin83519da2017-06-21 11:58:31 -0700148 private int mContrastedDrawableColor;
149 private int mCachedContrastBackgroundColor = NO_COLOR;
Adrian Roosc3e8cfc2017-07-17 17:09:39 +0200150 private float[] mMatrix;
151 private ColorMatrixColorFilter mMatrixColorFilter;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700152 private boolean mIsInShelf;
Selim Cinek887da3c2017-10-06 13:37:32 -0700153 private Runnable mLayoutRunnable;
Selim Cinekd03518c2018-03-15 12:13:51 -0700154 private boolean mDismissed;
155 private Runnable mOnDismissListener;
Joe Onorato0cbda992010-05-02 16:28:15 -0700156
Selim Cinek72fc8db2017-06-06 18:07:47 -0700157 public StatusBarIconView(Context context, String slot, StatusBarNotification sbn) {
158 this(context, slot, sbn, false);
Jason Monk3b230072015-05-29 11:11:29 -0400159 }
160
Selim Cinek72fc8db2017-06-06 18:07:47 -0700161 public StatusBarIconView(Context context, String slot, StatusBarNotification sbn,
Jason Monk3b230072015-05-29 11:11:29 -0400162 boolean blocked) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700163 super(context);
Adrian Roos456e0052017-04-04 16:44:29 -0700164 mDozer = new NotificationIconDozeHelper(context);
Jason Monk3b230072015-05-29 11:11:29 -0400165 mBlocked = blocked;
Joe Onorato0cbda992010-05-02 16:28:15 -0700166 mSlot = slot;
Joe Onorato6c01a112010-10-04 17:38:47 -0400167 mNumberPain = new Paint();
168 mNumberPain.setTextAlign(Paint.Align.CENTER);
Alan Viverette4a357cd2015-03-18 18:37:18 -0700169 mNumberPain.setColor(context.getColor(R.drawable.notification_number_text_color));
Joe Onorato6c01a112010-10-04 17:38:47 -0400170 mNumberPain.setAntiAlias(true);
Selim Cinek72fc8db2017-06-06 18:07:47 -0700171 setNotification(sbn);
Selim Cinek3e7592d2016-04-11 09:35:54 +0800172 setScaleType(ScaleType.CENTER);
173 mDensity = context.getResources().getDisplayMetrics().densityDpi;
Selim Cinek49014f82016-11-04 14:55:30 -0700174 if (mNotification != null) {
Selim Cinek875ba9b2017-02-13 16:20:17 -0800175 setDecorColor(getContext().getColor(
Selim Cinekc7f5a822018-03-20 19:32:06 -0700176 com.android.internal.R.color.notification_default_color_light));
Selim Cinek49014f82016-11-04 14:55:30 -0700177 }
178 reloadDimens();
Evan Laird20b87bf2018-04-12 09:54:11 -0400179 maybeUpdateIconScaleDimens();
Selim Cinek3e7592d2016-04-11 09:35:54 +0800180 }
Daniel Sandler26c84b12011-07-27 00:09:40 -0400181
Evan Laird20b87bf2018-04-12 09:54:11 -0400182 /** Should always be preceded by {@link #reloadDimens()} */
Adrian Roos138f0342017-04-28 09:11:28 -0700183 private void maybeUpdateIconScaleDimens() {
Daniel Sandler7579bca2011-08-18 15:47:26 -0400184 // We do not resize and scale system icons (on the right), only notification icons (on the
185 // left).
Selim Cinek3e7592d2016-04-11 09:35:54 +0800186 if (mNotification != null || mAlwaysScaleIcon) {
Evan Laird39ea8102018-05-18 19:49:07 -0400187 updateIconScaleForNotifications();
188 } else {
189 updateIconScaleForSystemIcons();
Daniel Sandler7579bca2011-08-18 15:47:26 -0400190 }
Selim Cinek3e7592d2016-04-11 09:35:54 +0800191 }
Daniel Sandlerabff0322011-09-27 11:19:34 -0400192
Evan Laird39ea8102018-05-18 19:49:07 -0400193 private void updateIconScaleForNotifications() {
Adrian Roos138f0342017-04-28 09:11:28 -0700194 final float imageBounds = NotificationUtils.interpolate(
195 mStatusBarIconDrawingSize,
196 mStatusBarIconDrawingSizeDark,
197 mDarkAmount);
198 final int outerBounds = mStatusBarIconSize;
Selim Cinek281c2022016-10-13 19:14:43 -0700199 mIconScale = (float)imageBounds / (float)outerBounds;
Selim Cinek281c2022016-10-13 19:14:43 -0700200 }
201
Evan Laird39ea8102018-05-18 19:49:07 -0400202 private void updateIconScaleForSystemIcons() {
203 mIconScale = SYSTEM_ICON_SCALE;
204 }
205
Adrian Roosceac4a02017-05-30 20:25:52 -0700206 public float getIconScaleFullyDark() {
207 return (float) mStatusBarIconDrawingSizeDark / mStatusBarIconDrawingSize;
208 }
209
Selim Cinek281c2022016-10-13 19:14:43 -0700210 public float getIconScale() {
211 return mIconScale;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800212 }
213
214 @Override
215 protected void onConfigurationChanged(Configuration newConfig) {
216 super.onConfigurationChanged(newConfig);
217 int density = newConfig.densityDpi;
218 if (density != mDensity) {
219 mDensity = density;
Evan Laird20b87bf2018-04-12 09:54:11 -0400220 reloadDimens();
Adrian Roos138f0342017-04-28 09:11:28 -0700221 maybeUpdateIconScaleDimens();
Selim Cinek3e7592d2016-04-11 09:35:54 +0800222 updateDrawable();
Selim Cinek49014f82016-11-04 14:55:30 -0700223 }
224 }
225
226 private void reloadDimens() {
227 boolean applyRadius = mDotRadius == mStaticDotRadius;
Evan Laird20b87bf2018-04-12 09:54:11 -0400228 Resources res = getResources();
229 mStaticDotRadius = res.getDimensionPixelSize(R.dimen.overflow_dot_radius);
230 mStatusBarIconSize = res.getDimensionPixelSize(R.dimen.status_bar_icon_size);
231 mStatusBarIconDrawingSizeDark =
232 res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size_dark);
233 mStatusBarIconDrawingSize =
234 res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size);
Selim Cinek49014f82016-11-04 14:55:30 -0700235 if (applyRadius) {
236 mDotRadius = mStaticDotRadius;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800237 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700238 }
239
Selim Cinek72fc8db2017-06-06 18:07:47 -0700240 public void setNotification(StatusBarNotification notification) {
Christoph Studera0506e72014-07-31 20:27:39 +0200241 mNotification = notification;
Selim Cinek72fc8db2017-06-06 18:07:47 -0700242 if (notification != null) {
243 setContentDescription(notification.getNotification());
244 }
Christoph Studera0506e72014-07-31 20:27:39 +0200245 }
246
Daniel Sandler05e24142011-11-10 11:56:49 -0500247 public StatusBarIconView(Context context, AttributeSet attrs) {
248 super(context, attrs);
Adrian Roos456e0052017-04-04 16:44:29 -0700249 mDozer = new NotificationIconDozeHelper(context);
Jason Monk3b230072015-05-29 11:11:29 -0400250 mBlocked = false;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800251 mAlwaysScaleIcon = true;
Evan Laird20b87bf2018-04-12 09:54:11 -0400252 reloadDimens();
Evan Laird39ea8102018-05-18 19:49:07 -0400253 updateIconScaleForNotifications();
Selim Cinek3e7592d2016-04-11 09:35:54 +0800254 mDensity = context.getResources().getDisplayMetrics().densityDpi;
Daniel Sandler05e24142011-11-10 11:56:49 -0500255 }
256
Joe Onorato0cbda992010-05-02 16:28:15 -0700257 private static boolean streq(String a, String b) {
Joe Onorato66d7d012010-05-14 10:05:10 -0700258 if (a == b) {
259 return true;
260 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700261 if (a == null && b != null) {
262 return false;
263 }
264 if (a != null && b == null) {
265 return false;
266 }
267 return a.equals(b);
268 }
269
Dan Sandlerd63f9322015-05-06 15:18:49 -0400270 public boolean equalIcons(Icon a, Icon b) {
271 if (a == b) return true;
272 if (a.getType() != b.getType()) return false;
273 switch (a.getType()) {
274 case Icon.TYPE_RESOURCE:
275 return a.getResPackage().equals(b.getResPackage()) && a.getResId() == b.getResId();
276 case Icon.TYPE_URI:
277 return a.getUriString().equals(b.getUriString());
278 default:
279 return false;
280 }
281 }
Joe Onorato005847b2010-06-04 16:08:02 -0400282 /**
283 * Returns whether the set succeeded.
284 */
285 public boolean set(StatusBarIcon icon) {
Dan Sandlerd63f9322015-05-06 15:18:49 -0400286 final boolean iconEquals = mIcon != null && equalIcons(mIcon.icon, icon.icon);
Joe Onorato005847b2010-06-04 16:08:02 -0400287 final boolean levelEquals = iconEquals
288 && mIcon.iconLevel == icon.iconLevel;
289 final boolean visibilityEquals = mIcon != null
290 && mIcon.visible == icon.visible;
Joe Onorato6c01a112010-10-04 17:38:47 -0400291 final boolean numberEquals = mIcon != null
292 && mIcon.number == icon.number;
293 mIcon = icon.clone();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700294 setContentDescription(icon.contentDescription);
Joe Onorato005847b2010-06-04 16:08:02 -0400295 if (!iconEquals) {
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800296 if (!updateDrawable(false /* no clear */)) return false;
Selim Cinek2b6eb8032016-12-29 14:22:21 +0100297 // we have to clear the grayscale tag since it may have changed
298 setTag(R.id.icon_is_grayscale, null);
Joe Onorato0cbda992010-05-02 16:28:15 -0700299 }
Joe Onorato005847b2010-06-04 16:08:02 -0400300 if (!levelEquals) {
301 setImageLevel(icon.iconLevel);
Joe Onorato0cbda992010-05-02 16:28:15 -0700302 }
Daniel Sandler26c84b12011-07-27 00:09:40 -0400303
Joe Onorato6c01a112010-10-04 17:38:47 -0400304 if (!numberEquals) {
John Spurlock01534782014-01-13 11:59:22 -0500305 if (icon.number > 0 && getContext().getResources().getBoolean(
Joe Onorato8595a3d2010-11-19 18:12:07 -0800306 R.bool.config_statusBarShowNumber)) {
Joe Onorato6c01a112010-10-04 17:38:47 -0400307 if (mNumberBackground == null) {
308 mNumberBackground = getContext().getResources().getDrawable(
309 R.drawable.ic_notification_overlay);
310 }
311 placeNumber();
312 } else {
313 mNumberBackground = null;
314 mNumberText = null;
315 }
316 invalidate();
317 }
Joe Onorato005847b2010-06-04 16:08:02 -0400318 if (!visibilityEquals) {
Jason Monk3b230072015-05-29 11:11:29 -0400319 setVisibility(icon.visible && !mBlocked ? VISIBLE : GONE);
Joe Onorato005847b2010-06-04 16:08:02 -0400320 }
Joe Onorato005847b2010-06-04 16:08:02 -0400321 return true;
Joe Onorato0cbda992010-05-02 16:28:15 -0700322 }
323
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800324 public void updateDrawable() {
325 updateDrawable(true /* with clear */);
326 }
327
328 private boolean updateDrawable(boolean withClear) {
Jorim Jaggi66ac1332015-01-21 19:22:26 +0100329 if (mIcon == null) {
330 return false;
331 }
Adrian Roosfb2d0cc2017-01-31 15:10:00 -0800332 Drawable drawable;
333 try {
334 drawable = getIcon(mIcon);
335 } catch (OutOfMemoryError e) {
336 Log.w(TAG, "OOM while inflating " + mIcon.icon + " for slot " + mSlot);
337 return false;
338 }
339
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800340 if (drawable == null) {
Adrian Roosfb2d0cc2017-01-31 15:10:00 -0800341 Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon);
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800342 return false;
343 }
344 if (withClear) {
345 setImageDrawable(null);
346 }
347 setImageDrawable(drawable);
348 return true;
349 }
350
Selim Cinek72fc8db2017-06-06 18:07:47 -0700351 public Icon getSourceIcon() {
352 return mIcon.icon;
353 }
354
Joe Onoratof5510542010-06-01 07:46:41 -0700355 private Drawable getIcon(StatusBarIcon icon) {
356 return getIcon(getContext(), icon);
357 }
358
Joe Onorato0cbda992010-05-02 16:28:15 -0700359 /**
Dan Sandlerd63f9322015-05-06 15:18:49 -0400360 * Returns the right icon to use for this item
John Spurlock209bede2013-07-17 12:23:27 -0400361 *
Dan Sandlerd63f9322015-05-06 15:18:49 -0400362 * @param context Context to use to get resources
Joe Onorato0cbda992010-05-02 16:28:15 -0700363 * @return Drawable for this item, or null if the package or item could not
364 * be found
365 */
Anthony Chen55e8e1e2016-01-08 10:31:46 -0800366 public static Drawable getIcon(Context context, StatusBarIcon statusBarIcon) {
367 int userId = statusBarIcon.user.getIdentifier();
Dan Sandlerd63f9322015-05-06 15:18:49 -0400368 if (userId == UserHandle.USER_ALL) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700369 userId = UserHandle.USER_SYSTEM;
Joe Onorato0cbda992010-05-02 16:28:15 -0700370 }
Anthony Chen55e8e1e2016-01-08 10:31:46 -0800371
372 Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
373
374 TypedValue typedValue = new TypedValue();
375 context.getResources().getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true);
376 float scaleFactor = typedValue.getFloat();
377
378 // No need to scale the icon, so return it as is.
379 if (scaleFactor == 1.f) {
380 return icon;
381 }
382
383 return new ScalingDrawableWrapper(icon, scaleFactor);
Joe Onorato0cbda992010-05-02 16:28:15 -0700384 }
Joe Onoratob77f53b2010-05-28 19:59:51 -0400385
386 public StatusBarIcon getStatusBarIcon() {
387 return mIcon;
388 }
Joe Onoratof9ec03c2010-09-23 15:09:18 -0700389
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700390 @Override
391 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
392 super.onInitializeAccessibilityEvent(event);
393 if (mNotification != null) {
Selim Cinek72fc8db2017-06-06 18:07:47 -0700394 event.setParcelableData(mNotification.getNotification());
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700395 }
396 }
397
398 @Override
Joe Onorato6c01a112010-10-04 17:38:47 -0400399 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
400 super.onSizeChanged(w, h, oldw, oldh);
401 if (mNumberBackground != null) {
402 placeNumber();
403 }
404 }
405
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700406 @Override
Jorim Jaggi66ac1332015-01-21 19:22:26 +0100407 public void onRtlPropertiesChanged(int layoutDirection) {
408 super.onRtlPropertiesChanged(layoutDirection);
409 updateDrawable();
410 }
411
412 @Override
Joe Onorato6c01a112010-10-04 17:38:47 -0400413 protected void onDraw(Canvas canvas) {
Selim Cinek49014f82016-11-04 14:55:30 -0700414 if (mIconAppearAmount > 0.0f) {
415 canvas.save();
416 canvas.scale(mIconScale * mIconAppearAmount, mIconScale * mIconAppearAmount,
417 getWidth() / 2, getHeight() / 2);
418 super.onDraw(canvas);
419 canvas.restore();
420 }
Joe Onorato6c01a112010-10-04 17:38:47 -0400421
422 if (mNumberBackground != null) {
423 mNumberBackground.draw(canvas);
424 canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain);
425 }
Selim Cinek49014f82016-11-04 14:55:30 -0700426 if (mDotAppearAmount != 0.0f) {
427 float radius;
Evan Lairdbaccb462018-06-01 16:29:02 -0400428 float alpha = Color.alpha(mDecorColor) / 255.f;
Selim Cinek49014f82016-11-04 14:55:30 -0700429 if (mDotAppearAmount <= 1.0f) {
430 radius = mDotRadius * mDotAppearAmount;
Selim Cinek49014f82016-11-04 14:55:30 -0700431 } else {
432 float fadeOutAmount = mDotAppearAmount - 1.0f;
Evan Lairdbaccb462018-06-01 16:29:02 -0400433 alpha = alpha * (1.0f - fadeOutAmount);
Selim Cinek49014f82016-11-04 14:55:30 -0700434 radius = NotificationUtils.interpolate(mDotRadius, getWidth() / 4, fadeOutAmount);
435 }
436 mDotPaint.setAlpha((int) (alpha * 255));
Evan Laird20b87bf2018-04-12 09:54:11 -0400437 canvas.drawCircle(mStatusBarIconSize / 2, getHeight() / 2, radius, mDotPaint);
Selim Cinek49014f82016-11-04 14:55:30 -0700438 }
Joe Onorato6c01a112010-10-04 17:38:47 -0400439 }
440
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700441 @Override
Joe Onoratof9ec03c2010-09-23 15:09:18 -0700442 protected void debug(int depth) {
443 super.debug(depth);
444 Log.d("View", debugIndent(depth) + "slot=" + mSlot);
445 Log.d("View", debugIndent(depth) + "icon=" + mIcon);
446 }
Joe Onorato6c01a112010-10-04 17:38:47 -0400447
448 void placeNumber() {
Daniel Sandlerebce0112011-06-16 16:44:51 -0400449 final String str;
John Spurlock01534782014-01-13 11:59:22 -0500450 final int tooBig = getContext().getResources().getInteger(
Daniel Sandlerebce0112011-06-16 16:44:51 -0400451 android.R.integer.status_bar_notification_info_maxnum);
452 if (mIcon.number > tooBig) {
John Spurlock01534782014-01-13 11:59:22 -0500453 str = getContext().getResources().getString(
Daniel Sandlerebce0112011-06-16 16:44:51 -0400454 android.R.string.status_bar_notification_info_overflow);
455 } else {
456 NumberFormat f = NumberFormat.getIntegerInstance();
457 str = f.format(mIcon.number);
458 }
459 mNumberText = str;
460
Joe Onorato6c01a112010-10-04 17:38:47 -0400461 final int w = getWidth();
462 final int h = getHeight();
463 final Rect r = new Rect();
464 mNumberPain.getTextBounds(str, 0, str.length(), r);
465 final int tw = r.right - r.left;
466 final int th = r.bottom - r.top;
467 mNumberBackground.getPadding(r);
468 int dw = r.left + tw + r.right;
469 if (dw < mNumberBackground.getMinimumWidth()) {
470 dw = mNumberBackground.getMinimumWidth();
471 }
472 mNumberX = w-r.right-((dw-r.right-r.left)/2);
473 int dh = r.top + th + r.bottom;
474 if (dh < mNumberBackground.getMinimumWidth()) {
475 dh = mNumberBackground.getMinimumWidth();
476 }
477 mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2);
478 mNumberBackground.setBounds(w-dw, h-dh, w, h);
479 }
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700480
481 private void setContentDescription(Notification notification) {
482 if (notification != null) {
Adrian Rooseba05822016-04-22 17:09:27 -0700483 String d = contentDescForNotification(mContext, notification);
484 if (!TextUtils.isEmpty(d)) {
485 setContentDescription(d);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700486 }
487 }
488 }
Daniel Sandler7579bca2011-08-18 15:47:26 -0400489
490 public String toString() {
John Spurlock209bede2013-07-17 12:23:27 -0400491 return "StatusBarIconView(slot=" + mSlot + " icon=" + mIcon
Daniel Sandler7579bca2011-08-18 15:47:26 -0400492 + " notification=" + mNotification + ")";
493 }
Jason Monk3b230072015-05-29 11:11:29 -0400494
Selim Cinek72fc8db2017-06-06 18:07:47 -0700495 public StatusBarNotification getNotification() {
496 return mNotification;
497 }
498
Jason Monk3b230072015-05-29 11:11:29 -0400499 public String getSlot() {
500 return mSlot;
501 }
Adrian Rooseba05822016-04-22 17:09:27 -0700502
503
504 public static String contentDescForNotification(Context c, Notification n) {
Adrian Roosa8e18ef2016-05-26 17:17:02 -0700505 String appName = "";
506 try {
507 Notification.Builder builder = Notification.Builder.recoverBuilder(c, n);
508 appName = builder.loadHeaderAppName();
509 } catch (RuntimeException e) {
510 Log.e(TAG, "Unable to recover builder", e);
511 // Trying to get the app name from the app info instead.
512 Parcelable appInfo = n.extras.getParcelable(
513 Notification.EXTRA_BUILDER_APPLICATION_INFO);
514 if (appInfo instanceof ApplicationInfo) {
515 appName = String.valueOf(((ApplicationInfo) appInfo).loadLabel(
516 c.getPackageManager()));
517 }
518 }
Adrian Roos51548e62016-04-28 11:20:26 -0700519
Julia Reynolds7f9ce782016-05-17 15:34:34 -0400520 CharSequence title = n.extras.getCharSequence(Notification.EXTRA_TITLE);
Adrian Roosf76600e2017-04-19 15:32:43 -0700521 CharSequence text = n.extras.getCharSequence(Notification.EXTRA_TEXT);
Adrian Rooseba05822016-04-22 17:09:27 -0700522 CharSequence ticker = n.tickerText;
Adrian Roos51548e62016-04-28 11:20:26 -0700523
Adrian Roosf76600e2017-04-19 15:32:43 -0700524 // Some apps just put the app name into the title
525 CharSequence titleOrText = TextUtils.equals(title, appName) ? text : title;
526
527 CharSequence desc = !TextUtils.isEmpty(titleOrText) ? titleOrText
Adrian Roos6e782a52017-03-30 18:34:10 -0700528 : !TextUtils.isEmpty(ticker) ? ticker : "";
Adrian Roos51548e62016-04-28 11:20:26 -0700529
530 return c.getString(R.string.accessibility_desc_notification_icon, appName, desc);
Adrian Rooseba05822016-04-22 17:09:27 -0700531 }
Adrian Roos51548e62016-04-28 11:20:26 -0700532
Selim Cinek875ba9b2017-02-13 16:20:17 -0800533 /**
534 * Set the color that is used to draw decoration like the overflow dot. This will not be applied
535 * to the drawable.
536 */
537 public void setDecorColor(int iconTint) {
Adrian Roos456e0052017-04-04 16:44:29 -0700538 mDecorColor = iconTint;
539 updateDecorColor();
540 }
541
542 private void updateDecorColor() {
543 int color = NotificationUtils.interpolateColors(mDecorColor, Color.WHITE, mDarkAmount);
544 if (mDotPaint.getColor() != color) {
545 mDotPaint.setColor(color);
546
547 if (mDotAppearAmount != 0) {
548 invalidate();
549 }
550 }
Selim Cinek49014f82016-11-04 14:55:30 -0700551 }
552
Selim Cinek875ba9b2017-02-13 16:20:17 -0800553 /**
554 * Set the static color that should be used for the drawable of this icon if it's not
555 * transitioning this also immediately sets the color.
556 */
557 public void setStaticDrawableColor(int color) {
558 mDrawableColor = color;
559 setColorInternal(color);
Lucas Dupin83519da2017-06-21 11:58:31 -0700560 updateContrastedStaticColor();
Selim Cinek875ba9b2017-02-13 16:20:17 -0800561 mIconColor = color;
Adrian Roos456e0052017-04-04 16:44:29 -0700562 mDozer.setColor(color);
Selim Cinek875ba9b2017-02-13 16:20:17 -0800563 }
564
565 private void setColorInternal(int color) {
Adrian Roosf3eacd32017-04-14 16:35:58 -0700566 mCurrentSetColor = color;
567 updateIconColor();
568 }
569
570 private void updateIconColor() {
571 if (mCurrentSetColor != NO_COLOR) {
Adrian Roosc3e8cfc2017-07-17 17:09:39 +0200572 if (mMatrixColorFilter == null) {
573 mMatrix = new float[4 * 5];
574 mMatrixColorFilter = new ColorMatrixColorFilter(mMatrix);
575 }
576 int color = NotificationUtils.interpolateColors(
577 mCurrentSetColor, Color.WHITE, mDarkAmount);
578 updateTintMatrix(mMatrix, color, DARK_ALPHA_BOOST * mDarkAmount);
579 mMatrixColorFilter.setColorMatrixArray(mMatrix);
580 setColorFilter(mMatrixColorFilter);
581 invalidate(); // setColorFilter only invalidates if the filter instance changed.
Selim Cinek875ba9b2017-02-13 16:20:17 -0800582 } else {
Adrian Roosf3eacd32017-04-14 16:35:58 -0700583 mDozer.updateGrayscale(this, mDarkAmount);
Selim Cinek875ba9b2017-02-13 16:20:17 -0800584 }
Selim Cinek875ba9b2017-02-13 16:20:17 -0800585 }
586
Adrian Roosc3e8cfc2017-07-17 17:09:39 +0200587 /**
588 * Updates {@param array} such that it represents a matrix that changes RGB to {@param color}
Adrian Roos24dbff32017-08-02 16:57:11 +0200589 * and multiplies the alpha channel with the color's alpha+{@param alphaBoost}.
Adrian Roosc3e8cfc2017-07-17 17:09:39 +0200590 */
591 private static void updateTintMatrix(float[] array, int color, float alphaBoost) {
592 Arrays.fill(array, 0);
593 array[4] = Color.red(color);
594 array[9] = Color.green(color);
595 array[14] = Color.blue(color);
Adrian Roos24dbff32017-08-02 16:57:11 +0200596 array[18] = Color.alpha(color) / 255f + alphaBoost;
Adrian Roosc3e8cfc2017-07-17 17:09:39 +0200597 }
598
Selim Cinek875ba9b2017-02-13 16:20:17 -0800599 public void setIconColor(int iconColor, boolean animate) {
600 if (mIconColor != iconColor) {
601 mIconColor = iconColor;
602 if (mColorAnimator != null) {
603 mColorAnimator.cancel();
604 }
605 if (mCurrentSetColor == iconColor) {
606 return;
607 }
608 if (animate && mCurrentSetColor != NO_COLOR) {
609 mAnimationStartColor = mCurrentSetColor;
610 mColorAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
611 mColorAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
612 mColorAnimator.setDuration(ANIMATION_DURATION_FAST);
613 mColorAnimator.addUpdateListener(mColorUpdater);
614 mColorAnimator.addListener(new AnimatorListenerAdapter() {
615 @Override
616 public void onAnimationEnd(Animator animation) {
617 mColorAnimator = null;
618 mAnimationStartColor = NO_COLOR;
619 }
620 });
621 mColorAnimator.start();
622 } else {
623 setColorInternal(iconColor);
624 }
625 }
626 }
627
628 public int getStaticDrawableColor() {
629 return mDrawableColor;
630 }
631
Lucas Dupin83519da2017-06-21 11:58:31 -0700632 /**
633 * A drawable color that passes GAR on a specific background.
634 * This value is cached.
635 *
636 * @param backgroundColor Background to test against.
637 * @return GAR safe version of {@link StatusBarIconView#getStaticDrawableColor()}.
638 */
639 int getContrastedStaticDrawableColor(int backgroundColor) {
640 if (mCachedContrastBackgroundColor != backgroundColor) {
641 mCachedContrastBackgroundColor = backgroundColor;
642 updateContrastedStaticColor();
643 }
644 return mContrastedDrawableColor;
645 }
646
647 private void updateContrastedStaticColor() {
Lucas Dupinddbaf842017-06-23 09:30:49 -0700648 if (Color.alpha(mCachedContrastBackgroundColor) != 255) {
649 mContrastedDrawableColor = mDrawableColor;
Lucas Dupin83519da2017-06-21 11:58:31 -0700650 return;
651 }
652 // We'll modify the color if it doesn't pass GAR
653 int contrastedColor = mDrawableColor;
654 if (!NotificationColorUtil.satisfiesTextContrast(mCachedContrastBackgroundColor,
655 contrastedColor)) {
656 float[] hsl = new float[3];
657 ColorUtils.colorToHSL(mDrawableColor, hsl);
658 // This is basically a light grey, pushing the color will only distort it.
659 // Best thing to do in here is to fallback to the default color.
660 if (hsl[1] < 0.2f) {
661 contrastedColor = Notification.COLOR_DEFAULT;
662 }
663 contrastedColor = NotificationColorUtil.resolveContrastColor(mContext,
664 contrastedColor, mCachedContrastBackgroundColor);
665 }
666 mContrastedDrawableColor = contrastedColor;
667 }
668
Evan Laird20b87bf2018-04-12 09:54:11 -0400669 @Override
Selim Cinek5b5beb012016-11-08 18:11:58 -0800670 public void setVisibleState(int state) {
671 setVisibleState(state, true /* animate */, null /* endRunnable */);
672 }
673
674 public void setVisibleState(int state, boolean animate) {
675 setVisibleState(state, animate, null);
676 }
677
678 @Override
679 public boolean hasOverlappingRendering() {
680 return false;
681 }
682
683 public void setVisibleState(int visibleState, boolean animate, Runnable endRunnable) {
Selim Cinekd03518c2018-03-15 12:13:51 -0700684 setVisibleState(visibleState, animate, endRunnable, 0);
685 }
686
687 /**
688 * Set the visibleState of this view.
689 *
690 * @param visibleState The new state.
691 * @param animate Should we animate?
692 * @param endRunnable The runnable to run at the end.
693 * @param duration The duration of an animation or 0 if the default should be taken.
694 */
695 public void setVisibleState(int visibleState, boolean animate, Runnable endRunnable,
696 long duration) {
Selim Cinek65d418e2016-11-29 15:42:34 -0800697 boolean runnableAdded = false;
Selim Cinek49014f82016-11-04 14:55:30 -0700698 if (visibleState != mVisibleState) {
699 mVisibleState = visibleState;
Selim Cinek5ece5a72017-02-15 11:47:42 -0800700 if (mIconAppearAnimator != null) {
701 mIconAppearAnimator.cancel();
702 }
703 if (mDotAnimator != null) {
704 mDotAnimator.cancel();
705 }
Selim Cinek5b5beb012016-11-08 18:11:58 -0800706 if (animate) {
Selim Cinek5b5beb012016-11-08 18:11:58 -0800707 float targetAmount = 0.0f;
708 Interpolator interpolator = Interpolators.FAST_OUT_LINEAR_IN;
709 if (visibleState == STATE_ICON) {
710 targetAmount = 1.0f;
711 interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
712 }
Selim Cinek65d418e2016-11-29 15:42:34 -0800713 float currentAmount = getIconAppearAmount();
714 if (targetAmount != currentAmount) {
715 mIconAppearAnimator = ObjectAnimator.ofFloat(this, ICON_APPEAR_AMOUNT,
716 currentAmount, targetAmount);
717 mIconAppearAnimator.setInterpolator(interpolator);
Selim Cinekd03518c2018-03-15 12:13:51 -0700718 mIconAppearAnimator.setDuration(duration == 0 ? ANIMATION_DURATION_FAST
719 : duration);
Selim Cinek65d418e2016-11-29 15:42:34 -0800720 mIconAppearAnimator.addListener(new AnimatorListenerAdapter() {
721 @Override
722 public void onAnimationEnd(Animator animation) {
723 mIconAppearAnimator = null;
724 runRunnable(endRunnable);
Selim Cinek5b5beb012016-11-08 18:11:58 -0800725 }
Selim Cinek65d418e2016-11-29 15:42:34 -0800726 });
727 mIconAppearAnimator.start();
728 runnableAdded = true;
729 }
Selim Cinek49014f82016-11-04 14:55:30 -0700730
Selim Cinek5b5beb012016-11-08 18:11:58 -0800731 targetAmount = visibleState == STATE_ICON ? 2.0f : 0.0f;
732 interpolator = Interpolators.FAST_OUT_LINEAR_IN;
733 if (visibleState == STATE_DOT) {
734 targetAmount = 1.0f;
735 interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
736 }
Selim Cinek65d418e2016-11-29 15:42:34 -0800737 currentAmount = getDotAppearAmount();
738 if (targetAmount != currentAmount) {
739 mDotAnimator = ObjectAnimator.ofFloat(this, DOT_APPEAR_AMOUNT,
740 currentAmount, targetAmount);
Selim Cinekd03518c2018-03-15 12:13:51 -0700741 mDotAnimator.setInterpolator(interpolator);;
742 mDotAnimator.setDuration(duration == 0 ? ANIMATION_DURATION_FAST
743 : duration);
Selim Cinek65d418e2016-11-29 15:42:34 -0800744 final boolean runRunnable = !runnableAdded;
745 mDotAnimator.addListener(new AnimatorListenerAdapter() {
746 @Override
747 public void onAnimationEnd(Animator animation) {
748 mDotAnimator = null;
749 if (runRunnable) {
750 runRunnable(endRunnable);
751 }
752 }
753 });
754 mDotAnimator.start();
755 runnableAdded = true;
756 }
Selim Cinek5b5beb012016-11-08 18:11:58 -0800757 } else {
758 setIconAppearAmount(visibleState == STATE_ICON ? 1.0f : 0.0f);
Selim Cinek01a73f92016-12-06 16:13:42 -0800759 setDotAppearAmount(visibleState == STATE_DOT ? 1.0f
760 : visibleState == STATE_ICON ? 2.0f
761 : 0.0f);
Selim Cinek5b5beb012016-11-08 18:11:58 -0800762 }
Selim Cinek49014f82016-11-04 14:55:30 -0700763 }
Selim Cinek65d418e2016-11-29 15:42:34 -0800764 if (!runnableAdded) {
765 runRunnable(endRunnable);
766 }
767 }
768
769 private void runRunnable(Runnable runnable) {
770 if (runnable != null) {
771 runnable.run();
772 }
Selim Cinek49014f82016-11-04 14:55:30 -0700773 }
774
Selim Cinek5b5beb012016-11-08 18:11:58 -0800775 public void setIconAppearAmount(float iconAppearAmount) {
Selim Cinek9ef119c2017-03-01 15:13:36 -0800776 if (mIconAppearAmount != iconAppearAmount) {
777 mIconAppearAmount = iconAppearAmount;
778 invalidate();
779 }
Selim Cinek49014f82016-11-04 14:55:30 -0700780 }
781
782 public float getIconAppearAmount() {
783 return mIconAppearAmount;
784 }
785
786 public int getVisibleState() {
787 return mVisibleState;
788 }
789
790 public void setDotAppearAmount(float dotAppearAmount) {
Selim Cinek9ef119c2017-03-01 15:13:36 -0800791 if (mDotAppearAmount != dotAppearAmount) {
792 mDotAppearAmount = dotAppearAmount;
793 invalidate();
794 }
Selim Cinek49014f82016-11-04 14:55:30 -0700795 }
796
Selim Cinek2b549f42016-11-22 16:38:51 -0800797 @Override
798 public void setVisibility(int visibility) {
799 super.setVisibility(visibility);
800 if (mOnVisibilityChangedListener != null) {
801 mOnVisibilityChangedListener.onVisibilityChanged(visibility);
802 }
803 }
804
Selim Cinek49014f82016-11-04 14:55:30 -0700805 public float getDotAppearAmount() {
806 return mDotAppearAmount;
807 }
Selim Cinek2b549f42016-11-22 16:38:51 -0800808
809 public void setOnVisibilityChangedListener(OnVisibilityChangedListener listener) {
810 mOnVisibilityChangedListener = listener;
811 }
812
Adrian Roos456e0052017-04-04 16:44:29 -0700813 public void setDark(boolean dark, boolean fade, long delay) {
Adrian Roos456e0052017-04-04 16:44:29 -0700814 mDozer.setIntensityDark(f -> {
815 mDarkAmount = f;
Evan Laird39ea8102018-05-18 19:49:07 -0400816 updateIconScaleForNotifications();
Adrian Roos456e0052017-04-04 16:44:29 -0700817 updateDecorColor();
Adrian Roosf3eacd32017-04-14 16:35:58 -0700818 updateIconColor();
Adrian Roosfe0071f2017-07-06 18:45:10 +0200819 updateAllowAnimation();
Selim Cinek653c1392018-05-15 13:02:42 -0700820 }, dark, fade, delay, this);
Adrian Roos456e0052017-04-04 16:44:29 -0700821 }
822
Adrian Roosfe0071f2017-07-06 18:45:10 +0200823 private void updateAllowAnimation() {
824 if (mDarkAmount == 0 || mDarkAmount == 1) {
825 setAllowAnimation(mDarkAmount == 0);
826 }
827 }
828
Selim Cinek13859052017-10-05 17:12:18 -0700829 /**
830 * This method returns the drawing rect for the view which is different from the regular
831 * drawing rect, since we layout all children at position 0 and usually the translation is
832 * neglected. The standard implementation doesn't account for translation.
833 *
834 * @param outRect The (scrolled) drawing bounds of the view.
835 */
836 @Override
837 public void getDrawingRect(Rect outRect) {
838 super.getDrawingRect(outRect);
839 float translationX = getTranslationX();
840 float translationY = getTranslationY();
841 outRect.left += translationX;
842 outRect.right += translationX;
843 outRect.top += translationY;
844 outRect.bottom += translationY;
845 }
846
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700847 public void setIsInShelf(boolean isInShelf) {
848 mIsInShelf = isInShelf;
849 }
850
851 public boolean isInShelf() {
852 return mIsInShelf;
853 }
854
Selim Cinek887da3c2017-10-06 13:37:32 -0700855 @Override
856 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
857 super.onLayout(changed, left, top, right, bottom);
858 if (mLayoutRunnable != null) {
859 mLayoutRunnable.run();
860 mLayoutRunnable = null;
861 }
862 }
863
864 public void executeOnLayout(Runnable runnable) {
865 mLayoutRunnable = runnable;
866 }
867
Selim Cinekd03518c2018-03-15 12:13:51 -0700868 public void setDismissed() {
869 mDismissed = true;
870 if (mOnDismissListener != null) {
871 mOnDismissListener.run();
872 }
873 }
874
875 public boolean isDismissed() {
876 return mDismissed;
877 }
878
879 public void setOnDismissListener(Runnable onDismissListener) {
880 mOnDismissListener = onDismissListener;
881 }
882
Evan Lairde1d13c92018-03-20 16:58:01 -0400883 @Override
884 public void onDarkChanged(Rect area, float darkIntensity, int tint) {
Evan Laird20b87bf2018-04-12 09:54:11 -0400885 int areaTint = getTint(area, this, tint);
886 ColorStateList color = ColorStateList.valueOf(areaTint);
887 setImageTintList(color);
888 setDecorColor(areaTint);
Evan Lairde1d13c92018-03-20 16:58:01 -0400889 }
890
891 @Override
892 public boolean isIconVisible() {
893 return mIcon != null && mIcon.visible;
894 }
895
896 @Override
897 public boolean isIconBlocked() {
898 return mBlocked;
899 }
900
Selim Cinek2b549f42016-11-22 16:38:51 -0800901 public interface OnVisibilityChangedListener {
902 void onVisibilityChanged(int newVisibility);
903 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700904}