Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1 | /* |
| 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 Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 18 | |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 19 | import static com.android.systemui.plugins.DarkIconDispatcher.getTint; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 20 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
| 23 | import android.animation.ObjectAnimator; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 25 | import android.app.Notification; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Adrian Roos | a8e18ef | 2016-05-26 17:17:02 -0700 | [diff] [blame] | 27 | import android.content.pm.ApplicationInfo; |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 28 | import android.content.res.ColorStateList; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 31 | import android.graphics.Canvas; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 32 | import android.graphics.Color; |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 33 | import android.graphics.ColorMatrixColorFilter; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 34 | import android.graphics.Paint; |
| 35 | import android.graphics.Rect; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 36 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 37 | import android.graphics.drawable.Icon; |
Adrian Roos | a8e18ef | 2016-05-26 17:17:02 -0700 | [diff] [blame] | 38 | import android.os.Parcelable; |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 39 | import android.os.UserHandle; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 40 | import android.service.notification.StatusBarNotification; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 41 | import android.text.TextUtils; |
Daniel Sandler | 05e2414 | 2011-11-10 11:56:49 -0500 | [diff] [blame] | 42 | import android.util.AttributeSet; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 43 | import android.util.FloatProperty; |
Joe Onorato | f9ec03c | 2010-09-23 15:09:18 -0700 | [diff] [blame] | 44 | import android.util.Log; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 45 | import android.util.Property; |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 46 | import android.util.TypedValue; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 47 | import android.view.ViewDebug; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 48 | import android.view.accessibility.AccessibilityEvent; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 49 | import android.view.animation.Interpolator; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 50 | |
Lucas Dupin | de07d21 | 2018-10-23 17:47:03 -0700 | [diff] [blame] | 51 | import androidx.core.graphics.ColorUtils; |
| 52 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 53 | import com.android.internal.statusbar.StatusBarIcon; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 54 | import com.android.internal.util.ContrastColorUtil; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 55 | import com.android.systemui.Interpolators; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 56 | import com.android.systemui.R; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 57 | import com.android.systemui.statusbar.notification.NotificationIconDozeHelper; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 58 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 59 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 60 | import java.text.NumberFormat; |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 61 | import java.util.Arrays; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 62 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 63 | public class StatusBarIconView extends AnimatedImageView implements StatusIconDisplayable { |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 64 | public static final int NO_COLOR = 0; |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Multiply alpha values with (1+DARK_ALPHA_BOOST) when dozing. The chosen value boosts |
| 68 | * everything above 30% to 50%, making it appear on 1bit color depths. |
| 69 | */ |
| 70 | private static final float DARK_ALPHA_BOOST = 0.67f; |
Evan Laird | 39ea810 | 2018-05-18 19:49:07 -0400 | [diff] [blame] | 71 | /** |
| 72 | * Status icons are currently drawn with the intention of being 17dp tall, but we |
| 73 | * want to scale them (in a way that doesn't require an asset dump) down 2dp. So |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 74 | * 17dp * (15 / 17) = 15dp, the new height. After the first call to {@link #reloadDimens} all |
| 75 | * values will be in px. |
Evan Laird | 39ea810 | 2018-05-18 19:49:07 -0400 | [diff] [blame] | 76 | */ |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 77 | private float mSystemIconDesiredHeight = 15f; |
| 78 | private float mSystemIconIntrinsicHeight = 17f; |
| 79 | private float mSystemIconDefaultScale = mSystemIconDesiredHeight / mSystemIconIntrinsicHeight; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 80 | private final int ANIMATION_DURATION_FAST = 100; |
| 81 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 82 | public static final int STATE_ICON = 0; |
| 83 | public static final int STATE_DOT = 1; |
| 84 | public static final int STATE_HIDDEN = 2; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 85 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 86 | private static final String TAG = "StatusBarIconView"; |
| 87 | private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT |
| 88 | = new FloatProperty<StatusBarIconView>("iconAppearAmount") { |
| 89 | |
| 90 | @Override |
| 91 | public void setValue(StatusBarIconView object, float value) { |
| 92 | object.setIconAppearAmount(value); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Float get(StatusBarIconView object) { |
| 97 | return object.getIconAppearAmount(); |
| 98 | } |
| 99 | }; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 100 | private static final Property<StatusBarIconView, Float> DOT_APPEAR_AMOUNT |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 101 | = new FloatProperty<StatusBarIconView>("dot_appear_amount") { |
| 102 | |
| 103 | @Override |
| 104 | public void setValue(StatusBarIconView object, float value) { |
| 105 | object.setDotAppearAmount(value); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public Float get(StatusBarIconView object) { |
| 110 | return object.getDotAppearAmount(); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | private boolean mAlwaysScaleIcon; |
Adrian Roos | 138f034 | 2017-04-28 09:11:28 -0700 | [diff] [blame] | 115 | private int mStatusBarIconDrawingSizeDark = 1; |
| 116 | private int mStatusBarIconDrawingSize = 1; |
| 117 | private int mStatusBarIconSize = 1; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 118 | private StatusBarIcon mIcon; |
| 119 | @ViewDebug.ExportedProperty private String mSlot; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 120 | private Drawable mNumberBackground; |
| 121 | private Paint mNumberPain; |
| 122 | private int mNumberX; |
| 123 | private int mNumberY; |
| 124 | private String mNumberText; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 125 | private StatusBarNotification mNotification; |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 126 | private final boolean mBlocked; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 127 | private int mDensity; |
Lucas Dupin | de07d21 | 2018-10-23 17:47:03 -0700 | [diff] [blame] | 128 | private boolean mNightMode; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 129 | private float mIconScale = 1.0f; |
Evan Laird | baccb46 | 2018-06-01 16:29:02 -0400 | [diff] [blame] | 130 | private final Paint mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 131 | private float mDotRadius; |
| 132 | private int mStaticDotRadius; |
| 133 | private int mVisibleState = STATE_ICON; |
| 134 | private float mIconAppearAmount = 1.0f; |
| 135 | private ObjectAnimator mIconAppearAnimator; |
| 136 | private ObjectAnimator mDotAnimator; |
| 137 | private float mDotAppearAmount; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 138 | private OnVisibilityChangedListener mOnVisibilityChangedListener; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 139 | private int mDrawableColor; |
| 140 | private int mIconColor; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 141 | private int mDecorColor; |
| 142 | private float mDarkAmount; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 143 | private ValueAnimator mColorAnimator; |
| 144 | private int mCurrentSetColor = NO_COLOR; |
| 145 | private int mAnimationStartColor = NO_COLOR; |
| 146 | private final ValueAnimator.AnimatorUpdateListener mColorUpdater |
| 147 | = animation -> { |
| 148 | int newColor = NotificationUtils.interpolateColors(mAnimationStartColor, mIconColor, |
| 149 | animation.getAnimatedFraction()); |
| 150 | setColorInternal(newColor); |
| 151 | }; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 152 | private final NotificationIconDozeHelper mDozer; |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 153 | private int mContrastedDrawableColor; |
| 154 | private int mCachedContrastBackgroundColor = NO_COLOR; |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 155 | private float[] mMatrix; |
| 156 | private ColorMatrixColorFilter mMatrixColorFilter; |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 157 | private boolean mIsInShelf; |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 158 | private Runnable mLayoutRunnable; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 159 | private boolean mDismissed; |
| 160 | private Runnable mOnDismissListener; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 161 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 162 | public StatusBarIconView(Context context, String slot, StatusBarNotification sbn) { |
| 163 | this(context, slot, sbn, false); |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 166 | public StatusBarIconView(Context context, String slot, StatusBarNotification sbn, |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 167 | boolean blocked) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 168 | super(context); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 169 | mDozer = new NotificationIconDozeHelper(context); |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 170 | mBlocked = blocked; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 171 | mSlot = slot; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 172 | mNumberPain = new Paint(); |
| 173 | mNumberPain.setTextAlign(Paint.Align.CENTER); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 174 | mNumberPain.setColor(context.getColor(R.drawable.notification_number_text_color)); |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 175 | mNumberPain.setAntiAlias(true); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 176 | setNotification(sbn); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 177 | setScaleType(ScaleType.CENTER); |
| 178 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Lucas Dupin | de07d21 | 2018-10-23 17:47:03 -0700 | [diff] [blame] | 179 | Configuration configuration = context.getResources().getConfiguration(); |
| 180 | mNightMode = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 181 | == Configuration.UI_MODE_NIGHT_YES; |
| 182 | initializeDecorColor(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 183 | reloadDimens(); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 184 | maybeUpdateIconScaleDimens(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 185 | } |
Daniel Sandler | 26c84b1 | 2011-07-27 00:09:40 -0400 | [diff] [blame] | 186 | |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 187 | /** Should always be preceded by {@link #reloadDimens()} */ |
Adrian Roos | 138f034 | 2017-04-28 09:11:28 -0700 | [diff] [blame] | 188 | private void maybeUpdateIconScaleDimens() { |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 189 | // We do not resize and scale system icons (on the right), only notification icons (on the |
| 190 | // left). |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 191 | if (mNotification != null || mAlwaysScaleIcon) { |
Evan Laird | 39ea810 | 2018-05-18 19:49:07 -0400 | [diff] [blame] | 192 | updateIconScaleForNotifications(); |
| 193 | } else { |
| 194 | updateIconScaleForSystemIcons(); |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 195 | } |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 196 | } |
Daniel Sandler | abff032 | 2011-09-27 11:19:34 -0400 | [diff] [blame] | 197 | |
Evan Laird | 39ea810 | 2018-05-18 19:49:07 -0400 | [diff] [blame] | 198 | private void updateIconScaleForNotifications() { |
Adrian Roos | 138f034 | 2017-04-28 09:11:28 -0700 | [diff] [blame] | 199 | final float imageBounds = NotificationUtils.interpolate( |
| 200 | mStatusBarIconDrawingSize, |
| 201 | mStatusBarIconDrawingSizeDark, |
| 202 | mDarkAmount); |
| 203 | final int outerBounds = mStatusBarIconSize; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 204 | mIconScale = (float)imageBounds / (float)outerBounds; |
Selim Cinek | 3ddda6d | 2018-06-08 00:26:48 -0700 | [diff] [blame] | 205 | updatePivot(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 208 | // Makes sure that all icons are scaled to the same height (15dp). If we cannot get a height |
| 209 | // for the icon, it uses the default SCALE (15f / 17f) which is the old behavior |
Evan Laird | 39ea810 | 2018-05-18 19:49:07 -0400 | [diff] [blame] | 210 | private void updateIconScaleForSystemIcons() { |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 211 | float iconHeight = getIconHeight(); |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 212 | if (iconHeight != 0) { |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 213 | mIconScale = mSystemIconDesiredHeight / iconHeight; |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 214 | } else { |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 215 | mIconScale = mSystemIconDefaultScale; |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 219 | private float getIconHeight() { |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 220 | Drawable d = getDrawable(); |
| 221 | if (d != null) { |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 222 | return (float) getDrawable().getIntrinsicHeight(); |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 223 | } else { |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 224 | return mSystemIconIntrinsicHeight; |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 225 | } |
Evan Laird | 39ea810 | 2018-05-18 19:49:07 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 228 | public float getIconScaleFullyDark() { |
| 229 | return (float) mStatusBarIconDrawingSizeDark / mStatusBarIconDrawingSize; |
| 230 | } |
| 231 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 232 | public float getIconScale() { |
| 233 | return mIconScale; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
| 237 | protected void onConfigurationChanged(Configuration newConfig) { |
| 238 | super.onConfigurationChanged(newConfig); |
| 239 | int density = newConfig.densityDpi; |
| 240 | if (density != mDensity) { |
| 241 | mDensity = density; |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 242 | reloadDimens(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 243 | updateDrawable(); |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 244 | maybeUpdateIconScaleDimens(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 245 | } |
Lucas Dupin | de07d21 | 2018-10-23 17:47:03 -0700 | [diff] [blame] | 246 | boolean nightMode = (newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 247 | == Configuration.UI_MODE_NIGHT_YES; |
| 248 | if (nightMode != mNightMode) { |
| 249 | mNightMode = nightMode; |
| 250 | initializeDecorColor(); |
| 251 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | private void reloadDimens() { |
| 255 | boolean applyRadius = mDotRadius == mStaticDotRadius; |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 256 | Resources res = getResources(); |
| 257 | mStaticDotRadius = res.getDimensionPixelSize(R.dimen.overflow_dot_radius); |
| 258 | mStatusBarIconSize = res.getDimensionPixelSize(R.dimen.status_bar_icon_size); |
| 259 | mStatusBarIconDrawingSizeDark = |
| 260 | res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size_dark); |
| 261 | mStatusBarIconDrawingSize = |
| 262 | res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 263 | if (applyRadius) { |
| 264 | mDotRadius = mStaticDotRadius; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 265 | } |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 266 | mSystemIconDesiredHeight = res.getDimension( |
| 267 | com.android.internal.R.dimen.status_bar_system_icon_size); |
| 268 | mSystemIconIntrinsicHeight = res.getDimension( |
| 269 | com.android.internal.R.dimen.status_bar_system_icon_intrinsic_size); |
| 270 | mSystemIconDefaultScale = mSystemIconDesiredHeight / mSystemIconIntrinsicHeight; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 273 | public void setNotification(StatusBarNotification notification) { |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 274 | mNotification = notification; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 275 | if (notification != null) { |
| 276 | setContentDescription(notification.getNotification()); |
| 277 | } |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 278 | maybeUpdateIconScaleDimens(); |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Daniel Sandler | 05e2414 | 2011-11-10 11:56:49 -0500 | [diff] [blame] | 281 | public StatusBarIconView(Context context, AttributeSet attrs) { |
| 282 | super(context, attrs); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 283 | mDozer = new NotificationIconDozeHelper(context); |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 284 | mBlocked = false; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 285 | mAlwaysScaleIcon = true; |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 286 | reloadDimens(); |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 287 | maybeUpdateIconScaleDimens(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 288 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Daniel Sandler | 05e2414 | 2011-11-10 11:56:49 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 291 | private static boolean streq(String a, String b) { |
Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 292 | if (a == b) { |
| 293 | return true; |
| 294 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 295 | if (a == null && b != null) { |
| 296 | return false; |
| 297 | } |
| 298 | if (a != null && b == null) { |
| 299 | return false; |
| 300 | } |
| 301 | return a.equals(b); |
| 302 | } |
| 303 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 304 | public boolean equalIcons(Icon a, Icon b) { |
| 305 | if (a == b) return true; |
| 306 | if (a.getType() != b.getType()) return false; |
| 307 | switch (a.getType()) { |
| 308 | case Icon.TYPE_RESOURCE: |
| 309 | return a.getResPackage().equals(b.getResPackage()) && a.getResId() == b.getResId(); |
| 310 | case Icon.TYPE_URI: |
| 311 | return a.getUriString().equals(b.getUriString()); |
| 312 | default: |
| 313 | return false; |
| 314 | } |
| 315 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 316 | /** |
| 317 | * Returns whether the set succeeded. |
| 318 | */ |
| 319 | public boolean set(StatusBarIcon icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 320 | final boolean iconEquals = mIcon != null && equalIcons(mIcon.icon, icon.icon); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 321 | final boolean levelEquals = iconEquals |
| 322 | && mIcon.iconLevel == icon.iconLevel; |
| 323 | final boolean visibilityEquals = mIcon != null |
| 324 | && mIcon.visible == icon.visible; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 325 | final boolean numberEquals = mIcon != null |
| 326 | && mIcon.number == icon.number; |
| 327 | mIcon = icon.clone(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 328 | setContentDescription(icon.contentDescription); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 329 | if (!iconEquals) { |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 330 | if (!updateDrawable(false /* no clear */)) return false; |
Selim Cinek | 2b6eb803 | 2016-12-29 14:22:21 +0100 | [diff] [blame] | 331 | // we have to clear the grayscale tag since it may have changed |
| 332 | setTag(R.id.icon_is_grayscale, null); |
Fabian Kozynski | 718dab9 | 2019-05-02 17:28:02 -0400 | [diff] [blame] | 333 | // Maybe set scale based on icon height |
| 334 | maybeUpdateIconScaleDimens(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 335 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 336 | if (!levelEquals) { |
| 337 | setImageLevel(icon.iconLevel); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 338 | } |
Daniel Sandler | 26c84b1 | 2011-07-27 00:09:40 -0400 | [diff] [blame] | 339 | |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 340 | if (!numberEquals) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 341 | if (icon.number > 0 && getContext().getResources().getBoolean( |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 342 | R.bool.config_statusBarShowNumber)) { |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 343 | if (mNumberBackground == null) { |
| 344 | mNumberBackground = getContext().getResources().getDrawable( |
| 345 | R.drawable.ic_notification_overlay); |
| 346 | } |
| 347 | placeNumber(); |
| 348 | } else { |
| 349 | mNumberBackground = null; |
| 350 | mNumberText = null; |
| 351 | } |
| 352 | invalidate(); |
| 353 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 354 | if (!visibilityEquals) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 355 | setVisibility(icon.visible && !mBlocked ? VISIBLE : GONE); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 356 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 357 | return true; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 360 | public void updateDrawable() { |
| 361 | updateDrawable(true /* with clear */); |
| 362 | } |
| 363 | |
| 364 | private boolean updateDrawable(boolean withClear) { |
Jorim Jaggi | 66ac133 | 2015-01-21 19:22:26 +0100 | [diff] [blame] | 365 | if (mIcon == null) { |
| 366 | return false; |
| 367 | } |
Adrian Roos | fb2d0cc | 2017-01-31 15:10:00 -0800 | [diff] [blame] | 368 | Drawable drawable; |
| 369 | try { |
| 370 | drawable = getIcon(mIcon); |
| 371 | } catch (OutOfMemoryError e) { |
| 372 | Log.w(TAG, "OOM while inflating " + mIcon.icon + " for slot " + mSlot); |
| 373 | return false; |
| 374 | } |
| 375 | |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 376 | if (drawable == null) { |
Adrian Roos | fb2d0cc | 2017-01-31 15:10:00 -0800 | [diff] [blame] | 377 | Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon); |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 378 | return false; |
| 379 | } |
| 380 | if (withClear) { |
| 381 | setImageDrawable(null); |
| 382 | } |
| 383 | setImageDrawable(drawable); |
| 384 | return true; |
| 385 | } |
| 386 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 387 | public Icon getSourceIcon() { |
| 388 | return mIcon.icon; |
| 389 | } |
| 390 | |
Joe Onorato | f551054 | 2010-06-01 07:46:41 -0700 | [diff] [blame] | 391 | private Drawable getIcon(StatusBarIcon icon) { |
| 392 | return getIcon(getContext(), icon); |
| 393 | } |
| 394 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 395 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 396 | * Returns the right icon to use for this item |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 397 | * |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 398 | * @param context Context to use to get resources |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 399 | * @return Drawable for this item, or null if the package or item could not |
| 400 | * be found |
| 401 | */ |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 402 | public static Drawable getIcon(Context context, StatusBarIcon statusBarIcon) { |
| 403 | int userId = statusBarIcon.user.getIdentifier(); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 404 | if (userId == UserHandle.USER_ALL) { |
Xiaohui Chen | 87d0e25 | 2015-07-30 15:38:16 -0700 | [diff] [blame] | 405 | userId = UserHandle.USER_SYSTEM; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 406 | } |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 407 | |
| 408 | Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId); |
| 409 | |
| 410 | TypedValue typedValue = new TypedValue(); |
| 411 | context.getResources().getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true); |
| 412 | float scaleFactor = typedValue.getFloat(); |
| 413 | |
| 414 | // No need to scale the icon, so return it as is. |
| 415 | if (scaleFactor == 1.f) { |
| 416 | return icon; |
| 417 | } |
| 418 | |
| 419 | return new ScalingDrawableWrapper(icon, scaleFactor); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 420 | } |
Joe Onorato | b77f53b | 2010-05-28 19:59:51 -0400 | [diff] [blame] | 421 | |
| 422 | public StatusBarIcon getStatusBarIcon() { |
| 423 | return mIcon; |
| 424 | } |
Joe Onorato | f9ec03c | 2010-09-23 15:09:18 -0700 | [diff] [blame] | 425 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 426 | @Override |
| 427 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 428 | super.onInitializeAccessibilityEvent(event); |
| 429 | if (mNotification != null) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 430 | event.setParcelableData(mNotification.getNotification()); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
| 434 | @Override |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 435 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 436 | super.onSizeChanged(w, h, oldw, oldh); |
| 437 | if (mNumberBackground != null) { |
| 438 | placeNumber(); |
| 439 | } |
| 440 | } |
| 441 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 442 | @Override |
Jorim Jaggi | 66ac133 | 2015-01-21 19:22:26 +0100 | [diff] [blame] | 443 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 444 | super.onRtlPropertiesChanged(layoutDirection); |
| 445 | updateDrawable(); |
| 446 | } |
| 447 | |
| 448 | @Override |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 449 | protected void onDraw(Canvas canvas) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 450 | if (mIconAppearAmount > 0.0f) { |
| 451 | canvas.save(); |
| 452 | canvas.scale(mIconScale * mIconAppearAmount, mIconScale * mIconAppearAmount, |
| 453 | getWidth() / 2, getHeight() / 2); |
| 454 | super.onDraw(canvas); |
| 455 | canvas.restore(); |
| 456 | } |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 457 | |
| 458 | if (mNumberBackground != null) { |
| 459 | mNumberBackground.draw(canvas); |
| 460 | canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain); |
| 461 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 462 | if (mDotAppearAmount != 0.0f) { |
| 463 | float radius; |
Evan Laird | baccb46 | 2018-06-01 16:29:02 -0400 | [diff] [blame] | 464 | float alpha = Color.alpha(mDecorColor) / 255.f; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 465 | if (mDotAppearAmount <= 1.0f) { |
| 466 | radius = mDotRadius * mDotAppearAmount; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 467 | } else { |
| 468 | float fadeOutAmount = mDotAppearAmount - 1.0f; |
Evan Laird | baccb46 | 2018-06-01 16:29:02 -0400 | [diff] [blame] | 469 | alpha = alpha * (1.0f - fadeOutAmount); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 470 | radius = NotificationUtils.interpolate(mDotRadius, getWidth() / 4, fadeOutAmount); |
| 471 | } |
| 472 | mDotPaint.setAlpha((int) (alpha * 255)); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 473 | canvas.drawCircle(mStatusBarIconSize / 2, getHeight() / 2, radius, mDotPaint); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 474 | } |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 475 | } |
| 476 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 477 | @Override |
Joe Onorato | f9ec03c | 2010-09-23 15:09:18 -0700 | [diff] [blame] | 478 | protected void debug(int depth) { |
| 479 | super.debug(depth); |
| 480 | Log.d("View", debugIndent(depth) + "slot=" + mSlot); |
| 481 | Log.d("View", debugIndent(depth) + "icon=" + mIcon); |
| 482 | } |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 483 | |
| 484 | void placeNumber() { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 485 | final String str; |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 486 | final int tooBig = getContext().getResources().getInteger( |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 487 | android.R.integer.status_bar_notification_info_maxnum); |
| 488 | if (mIcon.number > tooBig) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 489 | str = getContext().getResources().getString( |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 490 | android.R.string.status_bar_notification_info_overflow); |
| 491 | } else { |
| 492 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 493 | str = f.format(mIcon.number); |
| 494 | } |
| 495 | mNumberText = str; |
| 496 | |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 497 | final int w = getWidth(); |
| 498 | final int h = getHeight(); |
| 499 | final Rect r = new Rect(); |
| 500 | mNumberPain.getTextBounds(str, 0, str.length(), r); |
| 501 | final int tw = r.right - r.left; |
| 502 | final int th = r.bottom - r.top; |
| 503 | mNumberBackground.getPadding(r); |
| 504 | int dw = r.left + tw + r.right; |
| 505 | if (dw < mNumberBackground.getMinimumWidth()) { |
| 506 | dw = mNumberBackground.getMinimumWidth(); |
| 507 | } |
| 508 | mNumberX = w-r.right-((dw-r.right-r.left)/2); |
| 509 | int dh = r.top + th + r.bottom; |
| 510 | if (dh < mNumberBackground.getMinimumWidth()) { |
| 511 | dh = mNumberBackground.getMinimumWidth(); |
| 512 | } |
| 513 | mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2); |
| 514 | mNumberBackground.setBounds(w-dw, h-dh, w, h); |
| 515 | } |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 516 | |
| 517 | private void setContentDescription(Notification notification) { |
| 518 | if (notification != null) { |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 519 | String d = contentDescForNotification(mContext, notification); |
| 520 | if (!TextUtils.isEmpty(d)) { |
| 521 | setContentDescription(d); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | } |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 525 | |
| 526 | public String toString() { |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 527 | return "StatusBarIconView(slot=" + mSlot + " icon=" + mIcon |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 528 | + " notification=" + mNotification + ")"; |
| 529 | } |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 530 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 531 | public StatusBarNotification getNotification() { |
| 532 | return mNotification; |
| 533 | } |
| 534 | |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 535 | public String getSlot() { |
| 536 | return mSlot; |
| 537 | } |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 538 | |
| 539 | |
| 540 | public static String contentDescForNotification(Context c, Notification n) { |
Adrian Roos | a8e18ef | 2016-05-26 17:17:02 -0700 | [diff] [blame] | 541 | String appName = ""; |
| 542 | try { |
| 543 | Notification.Builder builder = Notification.Builder.recoverBuilder(c, n); |
| 544 | appName = builder.loadHeaderAppName(); |
| 545 | } catch (RuntimeException e) { |
| 546 | Log.e(TAG, "Unable to recover builder", e); |
| 547 | // Trying to get the app name from the app info instead. |
| 548 | Parcelable appInfo = n.extras.getParcelable( |
| 549 | Notification.EXTRA_BUILDER_APPLICATION_INFO); |
| 550 | if (appInfo instanceof ApplicationInfo) { |
| 551 | appName = String.valueOf(((ApplicationInfo) appInfo).loadLabel( |
| 552 | c.getPackageManager())); |
| 553 | } |
| 554 | } |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 555 | |
Julia Reynolds | 7f9ce78 | 2016-05-17 15:34:34 -0400 | [diff] [blame] | 556 | CharSequence title = n.extras.getCharSequence(Notification.EXTRA_TITLE); |
Adrian Roos | f76600e | 2017-04-19 15:32:43 -0700 | [diff] [blame] | 557 | CharSequence text = n.extras.getCharSequence(Notification.EXTRA_TEXT); |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 558 | CharSequence ticker = n.tickerText; |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 559 | |
Adrian Roos | f76600e | 2017-04-19 15:32:43 -0700 | [diff] [blame] | 560 | // Some apps just put the app name into the title |
| 561 | CharSequence titleOrText = TextUtils.equals(title, appName) ? text : title; |
| 562 | |
| 563 | CharSequence desc = !TextUtils.isEmpty(titleOrText) ? titleOrText |
Adrian Roos | 6e782a5 | 2017-03-30 18:34:10 -0700 | [diff] [blame] | 564 | : !TextUtils.isEmpty(ticker) ? ticker : ""; |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 565 | |
| 566 | return c.getString(R.string.accessibility_desc_notification_icon, appName, desc); |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 567 | } |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 568 | |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 569 | /** |
| 570 | * Set the color that is used to draw decoration like the overflow dot. This will not be applied |
| 571 | * to the drawable. |
| 572 | */ |
| 573 | public void setDecorColor(int iconTint) { |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 574 | mDecorColor = iconTint; |
| 575 | updateDecorColor(); |
| 576 | } |
| 577 | |
Lucas Dupin | de07d21 | 2018-10-23 17:47:03 -0700 | [diff] [blame] | 578 | private void initializeDecorColor() { |
| 579 | if (mNotification != null) { |
| 580 | setDecorColor(getContext().getColor(mNightMode |
| 581 | ? com.android.internal.R.color.notification_default_color_dark |
| 582 | : com.android.internal.R.color.notification_default_color_light)); |
| 583 | } |
| 584 | } |
| 585 | |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 586 | private void updateDecorColor() { |
| 587 | int color = NotificationUtils.interpolateColors(mDecorColor, Color.WHITE, mDarkAmount); |
| 588 | if (mDotPaint.getColor() != color) { |
| 589 | mDotPaint.setColor(color); |
| 590 | |
| 591 | if (mDotAppearAmount != 0) { |
| 592 | invalidate(); |
| 593 | } |
| 594 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 597 | /** |
| 598 | * Set the static color that should be used for the drawable of this icon if it's not |
| 599 | * transitioning this also immediately sets the color. |
| 600 | */ |
| 601 | public void setStaticDrawableColor(int color) { |
| 602 | mDrawableColor = color; |
| 603 | setColorInternal(color); |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 604 | updateContrastedStaticColor(); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 605 | mIconColor = color; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 606 | mDozer.setColor(color); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | private void setColorInternal(int color) { |
Adrian Roos | f3eacd3 | 2017-04-14 16:35:58 -0700 | [diff] [blame] | 610 | mCurrentSetColor = color; |
| 611 | updateIconColor(); |
| 612 | } |
| 613 | |
| 614 | private void updateIconColor() { |
| 615 | if (mCurrentSetColor != NO_COLOR) { |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 616 | if (mMatrixColorFilter == null) { |
| 617 | mMatrix = new float[4 * 5]; |
| 618 | mMatrixColorFilter = new ColorMatrixColorFilter(mMatrix); |
| 619 | } |
| 620 | int color = NotificationUtils.interpolateColors( |
| 621 | mCurrentSetColor, Color.WHITE, mDarkAmount); |
| 622 | updateTintMatrix(mMatrix, color, DARK_ALPHA_BOOST * mDarkAmount); |
| 623 | mMatrixColorFilter.setColorMatrixArray(mMatrix); |
Selim Cinek | 1280a72 | 2019-01-29 13:08:23 -0800 | [diff] [blame] | 624 | setColorFilter(null); // setColorFilter only invalidates if the instance changed. |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 625 | setColorFilter(mMatrixColorFilter); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 626 | } else { |
Adrian Roos | f3eacd3 | 2017-04-14 16:35:58 -0700 | [diff] [blame] | 627 | mDozer.updateGrayscale(this, mDarkAmount); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 628 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 631 | /** |
| 632 | * Updates {@param array} such that it represents a matrix that changes RGB to {@param color} |
Adrian Roos | 24dbff3 | 2017-08-02 16:57:11 +0200 | [diff] [blame] | 633 | * and multiplies the alpha channel with the color's alpha+{@param alphaBoost}. |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 634 | */ |
| 635 | private static void updateTintMatrix(float[] array, int color, float alphaBoost) { |
| 636 | Arrays.fill(array, 0); |
| 637 | array[4] = Color.red(color); |
| 638 | array[9] = Color.green(color); |
| 639 | array[14] = Color.blue(color); |
Adrian Roos | 24dbff3 | 2017-08-02 16:57:11 +0200 | [diff] [blame] | 640 | array[18] = Color.alpha(color) / 255f + alphaBoost; |
Adrian Roos | c3e8cfc | 2017-07-17 17:09:39 +0200 | [diff] [blame] | 641 | } |
| 642 | |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 643 | public void setIconColor(int iconColor, boolean animate) { |
| 644 | if (mIconColor != iconColor) { |
| 645 | mIconColor = iconColor; |
| 646 | if (mColorAnimator != null) { |
| 647 | mColorAnimator.cancel(); |
| 648 | } |
| 649 | if (mCurrentSetColor == iconColor) { |
| 650 | return; |
| 651 | } |
| 652 | if (animate && mCurrentSetColor != NO_COLOR) { |
| 653 | mAnimationStartColor = mCurrentSetColor; |
| 654 | mColorAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); |
| 655 | mColorAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 656 | mColorAnimator.setDuration(ANIMATION_DURATION_FAST); |
| 657 | mColorAnimator.addUpdateListener(mColorUpdater); |
| 658 | mColorAnimator.addListener(new AnimatorListenerAdapter() { |
| 659 | @Override |
| 660 | public void onAnimationEnd(Animator animation) { |
| 661 | mColorAnimator = null; |
| 662 | mAnimationStartColor = NO_COLOR; |
| 663 | } |
| 664 | }); |
| 665 | mColorAnimator.start(); |
| 666 | } else { |
| 667 | setColorInternal(iconColor); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | public int getStaticDrawableColor() { |
| 673 | return mDrawableColor; |
| 674 | } |
| 675 | |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 676 | /** |
| 677 | * A drawable color that passes GAR on a specific background. |
| 678 | * This value is cached. |
| 679 | * |
| 680 | * @param backgroundColor Background to test against. |
| 681 | * @return GAR safe version of {@link StatusBarIconView#getStaticDrawableColor()}. |
| 682 | */ |
| 683 | int getContrastedStaticDrawableColor(int backgroundColor) { |
| 684 | if (mCachedContrastBackgroundColor != backgroundColor) { |
| 685 | mCachedContrastBackgroundColor = backgroundColor; |
| 686 | updateContrastedStaticColor(); |
| 687 | } |
| 688 | return mContrastedDrawableColor; |
| 689 | } |
| 690 | |
| 691 | private void updateContrastedStaticColor() { |
Lucas Dupin | ddbaf84 | 2017-06-23 09:30:49 -0700 | [diff] [blame] | 692 | if (Color.alpha(mCachedContrastBackgroundColor) != 255) { |
| 693 | mContrastedDrawableColor = mDrawableColor; |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 694 | return; |
| 695 | } |
| 696 | // We'll modify the color if it doesn't pass GAR |
| 697 | int contrastedColor = mDrawableColor; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 698 | if (!ContrastColorUtil.satisfiesTextContrast(mCachedContrastBackgroundColor, |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 699 | contrastedColor)) { |
| 700 | float[] hsl = new float[3]; |
| 701 | ColorUtils.colorToHSL(mDrawableColor, hsl); |
| 702 | // This is basically a light grey, pushing the color will only distort it. |
| 703 | // Best thing to do in here is to fallback to the default color. |
| 704 | if (hsl[1] < 0.2f) { |
| 705 | contrastedColor = Notification.COLOR_DEFAULT; |
| 706 | } |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 707 | boolean isDark = !ContrastColorUtil.isColorLight(mCachedContrastBackgroundColor); |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 708 | contrastedColor = ContrastColorUtil.resolveContrastColor(mContext, |
Lucas Dupin | f03e752 | 2018-06-25 16:21:13 -0700 | [diff] [blame] | 709 | contrastedColor, mCachedContrastBackgroundColor, isDark); |
Lucas Dupin | 83519da | 2017-06-21 11:58:31 -0700 | [diff] [blame] | 710 | } |
| 711 | mContrastedDrawableColor = contrastedColor; |
| 712 | } |
| 713 | |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 714 | @Override |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 715 | public void setVisibleState(int state) { |
| 716 | setVisibleState(state, true /* animate */, null /* endRunnable */); |
| 717 | } |
| 718 | |
| 719 | public void setVisibleState(int state, boolean animate) { |
| 720 | setVisibleState(state, animate, null); |
| 721 | } |
| 722 | |
| 723 | @Override |
| 724 | public boolean hasOverlappingRendering() { |
| 725 | return false; |
| 726 | } |
| 727 | |
| 728 | public void setVisibleState(int visibleState, boolean animate, Runnable endRunnable) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 729 | setVisibleState(visibleState, animate, endRunnable, 0); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Set the visibleState of this view. |
| 734 | * |
| 735 | * @param visibleState The new state. |
| 736 | * @param animate Should we animate? |
| 737 | * @param endRunnable The runnable to run at the end. |
| 738 | * @param duration The duration of an animation or 0 if the default should be taken. |
| 739 | */ |
| 740 | public void setVisibleState(int visibleState, boolean animate, Runnable endRunnable, |
| 741 | long duration) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 742 | boolean runnableAdded = false; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 743 | if (visibleState != mVisibleState) { |
| 744 | mVisibleState = visibleState; |
Selim Cinek | 5ece5a7 | 2017-02-15 11:47:42 -0800 | [diff] [blame] | 745 | if (mIconAppearAnimator != null) { |
| 746 | mIconAppearAnimator.cancel(); |
| 747 | } |
| 748 | if (mDotAnimator != null) { |
| 749 | mDotAnimator.cancel(); |
| 750 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 751 | if (animate) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 752 | float targetAmount = 0.0f; |
| 753 | Interpolator interpolator = Interpolators.FAST_OUT_LINEAR_IN; |
| 754 | if (visibleState == STATE_ICON) { |
| 755 | targetAmount = 1.0f; |
| 756 | interpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
| 757 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 758 | float currentAmount = getIconAppearAmount(); |
| 759 | if (targetAmount != currentAmount) { |
| 760 | mIconAppearAnimator = ObjectAnimator.ofFloat(this, ICON_APPEAR_AMOUNT, |
| 761 | currentAmount, targetAmount); |
| 762 | mIconAppearAnimator.setInterpolator(interpolator); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 763 | mIconAppearAnimator.setDuration(duration == 0 ? ANIMATION_DURATION_FAST |
| 764 | : duration); |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 765 | mIconAppearAnimator.addListener(new AnimatorListenerAdapter() { |
| 766 | @Override |
| 767 | public void onAnimationEnd(Animator animation) { |
| 768 | mIconAppearAnimator = null; |
| 769 | runRunnable(endRunnable); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 770 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 771 | }); |
| 772 | mIconAppearAnimator.start(); |
| 773 | runnableAdded = true; |
| 774 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 775 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 776 | targetAmount = visibleState == STATE_ICON ? 2.0f : 0.0f; |
| 777 | interpolator = Interpolators.FAST_OUT_LINEAR_IN; |
| 778 | if (visibleState == STATE_DOT) { |
| 779 | targetAmount = 1.0f; |
| 780 | interpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
| 781 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 782 | currentAmount = getDotAppearAmount(); |
| 783 | if (targetAmount != currentAmount) { |
| 784 | mDotAnimator = ObjectAnimator.ofFloat(this, DOT_APPEAR_AMOUNT, |
| 785 | currentAmount, targetAmount); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 786 | mDotAnimator.setInterpolator(interpolator);; |
| 787 | mDotAnimator.setDuration(duration == 0 ? ANIMATION_DURATION_FAST |
| 788 | : duration); |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 789 | final boolean runRunnable = !runnableAdded; |
| 790 | mDotAnimator.addListener(new AnimatorListenerAdapter() { |
| 791 | @Override |
| 792 | public void onAnimationEnd(Animator animation) { |
| 793 | mDotAnimator = null; |
| 794 | if (runRunnable) { |
| 795 | runRunnable(endRunnable); |
| 796 | } |
| 797 | } |
| 798 | }); |
| 799 | mDotAnimator.start(); |
| 800 | runnableAdded = true; |
| 801 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 802 | } else { |
| 803 | setIconAppearAmount(visibleState == STATE_ICON ? 1.0f : 0.0f); |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 804 | setDotAppearAmount(visibleState == STATE_DOT ? 1.0f |
| 805 | : visibleState == STATE_ICON ? 2.0f |
| 806 | : 0.0f); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 807 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 808 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 809 | if (!runnableAdded) { |
| 810 | runRunnable(endRunnable); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | private void runRunnable(Runnable runnable) { |
| 815 | if (runnable != null) { |
| 816 | runnable.run(); |
| 817 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 820 | public void setIconAppearAmount(float iconAppearAmount) { |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 821 | if (mIconAppearAmount != iconAppearAmount) { |
| 822 | mIconAppearAmount = iconAppearAmount; |
| 823 | invalidate(); |
| 824 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | public float getIconAppearAmount() { |
| 828 | return mIconAppearAmount; |
| 829 | } |
| 830 | |
| 831 | public int getVisibleState() { |
| 832 | return mVisibleState; |
| 833 | } |
| 834 | |
| 835 | public void setDotAppearAmount(float dotAppearAmount) { |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 836 | if (mDotAppearAmount != dotAppearAmount) { |
| 837 | mDotAppearAmount = dotAppearAmount; |
| 838 | invalidate(); |
| 839 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 842 | @Override |
| 843 | public void setVisibility(int visibility) { |
| 844 | super.setVisibility(visibility); |
| 845 | if (mOnVisibilityChangedListener != null) { |
| 846 | mOnVisibilityChangedListener.onVisibilityChanged(visibility); |
| 847 | } |
| 848 | } |
| 849 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 850 | public float getDotAppearAmount() { |
| 851 | return mDotAppearAmount; |
| 852 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 853 | |
| 854 | public void setOnVisibilityChangedListener(OnVisibilityChangedListener listener) { |
| 855 | mOnVisibilityChangedListener = listener; |
| 856 | } |
| 857 | |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 858 | public void setDark(boolean dark, boolean fade, long delay) { |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 859 | mDozer.setIntensityDark(f -> { |
| 860 | mDarkAmount = f; |
Fabian Kozynski | 61e1ba6 | 2019-05-15 10:04:39 -0400 | [diff] [blame] | 861 | maybeUpdateIconScaleDimens(); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 862 | updateDecorColor(); |
Adrian Roos | f3eacd3 | 2017-04-14 16:35:58 -0700 | [diff] [blame] | 863 | updateIconColor(); |
Adrian Roos | fe0071f | 2017-07-06 18:45:10 +0200 | [diff] [blame] | 864 | updateAllowAnimation(); |
Selim Cinek | 653c139 | 2018-05-15 13:02:42 -0700 | [diff] [blame] | 865 | }, dark, fade, delay, this); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Adrian Roos | fe0071f | 2017-07-06 18:45:10 +0200 | [diff] [blame] | 868 | private void updateAllowAnimation() { |
| 869 | if (mDarkAmount == 0 || mDarkAmount == 1) { |
| 870 | setAllowAnimation(mDarkAmount == 0); |
| 871 | } |
| 872 | } |
| 873 | |
Selim Cinek | 1385905 | 2017-10-05 17:12:18 -0700 | [diff] [blame] | 874 | /** |
| 875 | * This method returns the drawing rect for the view which is different from the regular |
| 876 | * drawing rect, since we layout all children at position 0 and usually the translation is |
| 877 | * neglected. The standard implementation doesn't account for translation. |
| 878 | * |
| 879 | * @param outRect The (scrolled) drawing bounds of the view. |
| 880 | */ |
| 881 | @Override |
| 882 | public void getDrawingRect(Rect outRect) { |
| 883 | super.getDrawingRect(outRect); |
| 884 | float translationX = getTranslationX(); |
| 885 | float translationY = getTranslationY(); |
| 886 | outRect.left += translationX; |
| 887 | outRect.right += translationX; |
| 888 | outRect.top += translationY; |
| 889 | outRect.bottom += translationY; |
| 890 | } |
| 891 | |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 892 | public void setIsInShelf(boolean isInShelf) { |
| 893 | mIsInShelf = isInShelf; |
| 894 | } |
| 895 | |
| 896 | public boolean isInShelf() { |
| 897 | return mIsInShelf; |
| 898 | } |
| 899 | |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 900 | @Override |
| 901 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 902 | super.onLayout(changed, left, top, right, bottom); |
| 903 | if (mLayoutRunnable != null) { |
| 904 | mLayoutRunnable.run(); |
| 905 | mLayoutRunnable = null; |
| 906 | } |
Selim Cinek | 3ddda6d | 2018-06-08 00:26:48 -0700 | [diff] [blame] | 907 | updatePivot(); |
| 908 | } |
| 909 | |
| 910 | private void updatePivot() { |
| 911 | setPivotX((1 - mIconScale) / 2.0f * getWidth()); |
| 912 | setPivotY((getHeight() - mIconScale * getWidth()) / 2.0f); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | public void executeOnLayout(Runnable runnable) { |
| 916 | mLayoutRunnable = runnable; |
| 917 | } |
| 918 | |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 919 | public void setDismissed() { |
| 920 | mDismissed = true; |
| 921 | if (mOnDismissListener != null) { |
| 922 | mOnDismissListener.run(); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | public boolean isDismissed() { |
| 927 | return mDismissed; |
| 928 | } |
| 929 | |
| 930 | public void setOnDismissListener(Runnable onDismissListener) { |
| 931 | mOnDismissListener = onDismissListener; |
| 932 | } |
| 933 | |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 934 | @Override |
| 935 | public void onDarkChanged(Rect area, float darkIntensity, int tint) { |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 936 | int areaTint = getTint(area, this, tint); |
| 937 | ColorStateList color = ColorStateList.valueOf(areaTint); |
| 938 | setImageTintList(color); |
| 939 | setDecorColor(areaTint); |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | @Override |
| 943 | public boolean isIconVisible() { |
| 944 | return mIcon != null && mIcon.visible; |
| 945 | } |
| 946 | |
| 947 | @Override |
| 948 | public boolean isIconBlocked() { |
| 949 | return mBlocked; |
| 950 | } |
| 951 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 952 | public interface OnVisibilityChangedListener { |
| 953 | void onVisibilityChanged(int newVisibility); |
| 954 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 955 | } |