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 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ObjectAnimator; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 23 | import android.app.Notification; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Adrian Roos | a8e18ef | 2016-05-26 17:17:02 -0700 | [diff] [blame] | 25 | import android.content.pm.ApplicationInfo; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 26 | import android.content.res.ColorStateList; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 29 | import android.graphics.Canvas; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 30 | import android.graphics.Color; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 31 | import android.graphics.Paint; |
| 32 | import android.graphics.Rect; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 34 | import android.graphics.drawable.Icon; |
Adrian Roos | a8e18ef | 2016-05-26 17:17:02 -0700 | [diff] [blame] | 35 | import android.os.Parcelable; |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 36 | import android.os.UserHandle; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 37 | import android.text.TextUtils; |
Daniel Sandler | 05e2414 | 2011-11-10 11:56:49 -0500 | [diff] [blame] | 38 | import android.util.AttributeSet; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 39 | import android.util.FloatProperty; |
Joe Onorato | f9ec03c | 2010-09-23 15:09:18 -0700 | [diff] [blame] | 40 | import android.util.Log; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 41 | import android.util.Property; |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 42 | import android.util.TypedValue; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 43 | import android.view.ViewDebug; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 44 | import android.view.accessibility.AccessibilityEvent; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 45 | import android.view.animation.Interpolator; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 46 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 47 | import com.android.internal.statusbar.StatusBarIcon; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 48 | import com.android.systemui.Interpolators; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 49 | import com.android.systemui.R; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 50 | import com.android.systemui.statusbar.notification.NotificationIconDozeHelper; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 51 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 52 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 53 | import java.text.NumberFormat; |
| 54 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 55 | public class StatusBarIconView extends AnimatedImageView { |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 56 | public static final int NO_COLOR = 0; |
| 57 | private final int ANIMATION_DURATION_FAST = 100; |
| 58 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 59 | public static final int STATE_ICON = 0; |
| 60 | public static final int STATE_DOT = 1; |
| 61 | public static final int STATE_HIDDEN = 2; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 62 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 63 | private static final String TAG = "StatusBarIconView"; |
| 64 | private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT |
| 65 | = new FloatProperty<StatusBarIconView>("iconAppearAmount") { |
| 66 | |
| 67 | @Override |
| 68 | public void setValue(StatusBarIconView object, float value) { |
| 69 | object.setIconAppearAmount(value); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public Float get(StatusBarIconView object) { |
| 74 | return object.getIconAppearAmount(); |
| 75 | } |
| 76 | }; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 77 | private static final Property<StatusBarIconView, Float> DOT_APPEAR_AMOUNT |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 78 | = new FloatProperty<StatusBarIconView>("dot_appear_amount") { |
| 79 | |
| 80 | @Override |
| 81 | public void setValue(StatusBarIconView object, float value) { |
| 82 | object.setDotAppearAmount(value); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Float get(StatusBarIconView object) { |
| 87 | return object.getDotAppearAmount(); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | private boolean mAlwaysScaleIcon; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 92 | private StatusBarIcon mIcon; |
| 93 | @ViewDebug.ExportedProperty private String mSlot; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 94 | private Drawable mNumberBackground; |
| 95 | private Paint mNumberPain; |
| 96 | private int mNumberX; |
| 97 | private int mNumberY; |
| 98 | private String mNumberText; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 99 | private Notification mNotification; |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 100 | private final boolean mBlocked; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 101 | private int mDensity; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 102 | private float mIconScale = 1.0f; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 103 | private final Paint mDotPaint = new Paint(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 104 | private float mDotRadius; |
| 105 | private int mStaticDotRadius; |
| 106 | private int mVisibleState = STATE_ICON; |
| 107 | private float mIconAppearAmount = 1.0f; |
| 108 | private ObjectAnimator mIconAppearAnimator; |
| 109 | private ObjectAnimator mDotAnimator; |
| 110 | private float mDotAppearAmount; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 111 | private OnVisibilityChangedListener mOnVisibilityChangedListener; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 112 | private int mDrawableColor; |
| 113 | private int mIconColor; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 114 | private int mDecorColor; |
| 115 | private float mDarkAmount; |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 116 | private ValueAnimator mColorAnimator; |
| 117 | private int mCurrentSetColor = NO_COLOR; |
| 118 | private int mAnimationStartColor = NO_COLOR; |
| 119 | private final ValueAnimator.AnimatorUpdateListener mColorUpdater |
| 120 | = animation -> { |
| 121 | int newColor = NotificationUtils.interpolateColors(mAnimationStartColor, mIconColor, |
| 122 | animation.getAnimatedFraction()); |
| 123 | setColorInternal(newColor); |
| 124 | }; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 125 | private final NotificationIconDozeHelper mDozer; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 126 | |
John Spurlock | e6f0a71 | 2013-09-03 16:23:49 -0400 | [diff] [blame] | 127 | public StatusBarIconView(Context context, String slot, Notification notification) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 128 | this(context, slot, notification, false); |
| 129 | } |
| 130 | |
| 131 | public StatusBarIconView(Context context, String slot, Notification notification, |
| 132 | boolean blocked) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 133 | super(context); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 134 | mDozer = new NotificationIconDozeHelper(context); |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 135 | mBlocked = blocked; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 136 | mSlot = slot; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 137 | mNumberPain = new Paint(); |
| 138 | mNumberPain.setTextAlign(Paint.Align.CENTER); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 139 | mNumberPain.setColor(context.getColor(R.drawable.notification_number_text_color)); |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 140 | mNumberPain.setAntiAlias(true); |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 141 | setNotification(notification); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 142 | maybeUpdateIconScale(); |
| 143 | setScaleType(ScaleType.CENTER); |
| 144 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 145 | if (mNotification != null) { |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 146 | setDecorColor(getContext().getColor( |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 147 | com.android.internal.R.color.notification_icon_default_color)); |
| 148 | } |
| 149 | reloadDimens(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 150 | } |
Daniel Sandler | 26c84b1 | 2011-07-27 00:09:40 -0400 | [diff] [blame] | 151 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 152 | private void maybeUpdateIconScale() { |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 153 | // We do not resize and scale system icons (on the right), only notification icons (on the |
| 154 | // left). |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 155 | if (mNotification != null || mAlwaysScaleIcon) { |
| 156 | updateIconScale(); |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 157 | } |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 158 | } |
Daniel Sandler | abff032 | 2011-09-27 11:19:34 -0400 | [diff] [blame] | 159 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 160 | private void updateIconScale() { |
| 161 | Resources res = mContext.getResources(); |
| 162 | final int outerBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_size); |
| 163 | final int imageBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 164 | mIconScale = (float)imageBounds / (float)outerBounds; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | public float getIconScale() { |
| 168 | return mIconScale; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | @Override |
| 172 | protected void onConfigurationChanged(Configuration newConfig) { |
| 173 | super.onConfigurationChanged(newConfig); |
| 174 | int density = newConfig.densityDpi; |
| 175 | if (density != mDensity) { |
| 176 | mDensity = density; |
| 177 | maybeUpdateIconScale(); |
| 178 | updateDrawable(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 179 | reloadDimens(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | private void reloadDimens() { |
| 184 | boolean applyRadius = mDotRadius == mStaticDotRadius; |
| 185 | mStaticDotRadius = getResources().getDimensionPixelSize(R.dimen.overflow_dot_radius); |
| 186 | if (applyRadius) { |
| 187 | mDotRadius = mStaticDotRadius; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 188 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 191 | public void setNotification(Notification notification) { |
| 192 | mNotification = notification; |
| 193 | setContentDescription(notification); |
| 194 | } |
| 195 | |
Daniel Sandler | 05e2414 | 2011-11-10 11:56:49 -0500 | [diff] [blame] | 196 | public StatusBarIconView(Context context, AttributeSet attrs) { |
| 197 | super(context, attrs); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 198 | mDozer = new NotificationIconDozeHelper(context); |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 199 | mBlocked = false; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 200 | mAlwaysScaleIcon = true; |
| 201 | updateIconScale(); |
| 202 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Daniel Sandler | 05e2414 | 2011-11-10 11:56:49 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 205 | private static boolean streq(String a, String b) { |
Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 206 | if (a == b) { |
| 207 | return true; |
| 208 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 209 | if (a == null && b != null) { |
| 210 | return false; |
| 211 | } |
| 212 | if (a != null && b == null) { |
| 213 | return false; |
| 214 | } |
| 215 | return a.equals(b); |
| 216 | } |
| 217 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 218 | public boolean equalIcons(Icon a, Icon b) { |
| 219 | if (a == b) return true; |
| 220 | if (a.getType() != b.getType()) return false; |
| 221 | switch (a.getType()) { |
| 222 | case Icon.TYPE_RESOURCE: |
| 223 | return a.getResPackage().equals(b.getResPackage()) && a.getResId() == b.getResId(); |
| 224 | case Icon.TYPE_URI: |
| 225 | return a.getUriString().equals(b.getUriString()); |
| 226 | default: |
| 227 | return false; |
| 228 | } |
| 229 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 230 | /** |
| 231 | * Returns whether the set succeeded. |
| 232 | */ |
| 233 | public boolean set(StatusBarIcon icon) { |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 234 | final boolean iconEquals = mIcon != null && equalIcons(mIcon.icon, icon.icon); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 235 | final boolean levelEquals = iconEquals |
| 236 | && mIcon.iconLevel == icon.iconLevel; |
| 237 | final boolean visibilityEquals = mIcon != null |
| 238 | && mIcon.visible == icon.visible; |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 239 | final boolean numberEquals = mIcon != null |
| 240 | && mIcon.number == icon.number; |
| 241 | mIcon = icon.clone(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 242 | setContentDescription(icon.contentDescription); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 243 | if (!iconEquals) { |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 244 | if (!updateDrawable(false /* no clear */)) return false; |
Selim Cinek | 2b6eb803 | 2016-12-29 14:22:21 +0100 | [diff] [blame] | 245 | // we have to clear the grayscale tag since it may have changed |
| 246 | setTag(R.id.icon_is_grayscale, null); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 247 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 248 | if (!levelEquals) { |
| 249 | setImageLevel(icon.iconLevel); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 250 | } |
Daniel Sandler | 26c84b1 | 2011-07-27 00:09:40 -0400 | [diff] [blame] | 251 | |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 252 | if (!numberEquals) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 253 | if (icon.number > 0 && getContext().getResources().getBoolean( |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 254 | R.bool.config_statusBarShowNumber)) { |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 255 | if (mNumberBackground == null) { |
| 256 | mNumberBackground = getContext().getResources().getDrawable( |
| 257 | R.drawable.ic_notification_overlay); |
| 258 | } |
| 259 | placeNumber(); |
| 260 | } else { |
| 261 | mNumberBackground = null; |
| 262 | mNumberText = null; |
| 263 | } |
| 264 | invalidate(); |
| 265 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 266 | if (!visibilityEquals) { |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 267 | setVisibility(icon.visible && !mBlocked ? VISIBLE : GONE); |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 268 | } |
Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 269 | return true; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 272 | public void updateDrawable() { |
| 273 | updateDrawable(true /* with clear */); |
| 274 | } |
| 275 | |
| 276 | private boolean updateDrawable(boolean withClear) { |
Jorim Jaggi | 66ac133 | 2015-01-21 19:22:26 +0100 | [diff] [blame] | 277 | if (mIcon == null) { |
| 278 | return false; |
| 279 | } |
Adrian Roos | fb2d0cc | 2017-01-31 15:10:00 -0800 | [diff] [blame] | 280 | Drawable drawable; |
| 281 | try { |
| 282 | drawable = getIcon(mIcon); |
| 283 | } catch (OutOfMemoryError e) { |
| 284 | Log.w(TAG, "OOM while inflating " + mIcon.icon + " for slot " + mSlot); |
| 285 | return false; |
| 286 | } |
| 287 | |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 288 | if (drawable == null) { |
Adrian Roos | fb2d0cc | 2017-01-31 15:10:00 -0800 | [diff] [blame] | 289 | Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon); |
Fabrice Di Meglio | 82fca5d | 2013-01-09 15:42:31 -0800 | [diff] [blame] | 290 | return false; |
| 291 | } |
| 292 | if (withClear) { |
| 293 | setImageDrawable(null); |
| 294 | } |
| 295 | setImageDrawable(drawable); |
| 296 | return true; |
| 297 | } |
| 298 | |
Joe Onorato | f551054 | 2010-06-01 07:46:41 -0700 | [diff] [blame] | 299 | private Drawable getIcon(StatusBarIcon icon) { |
| 300 | return getIcon(getContext(), icon); |
| 301 | } |
| 302 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 303 | /** |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 304 | * Returns the right icon to use for this item |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 305 | * |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 306 | * @param context Context to use to get resources |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 307 | * @return Drawable for this item, or null if the package or item could not |
| 308 | * be found |
| 309 | */ |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 310 | public static Drawable getIcon(Context context, StatusBarIcon statusBarIcon) { |
| 311 | int userId = statusBarIcon.user.getIdentifier(); |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 312 | if (userId == UserHandle.USER_ALL) { |
Xiaohui Chen | 87d0e25 | 2015-07-30 15:38:16 -0700 | [diff] [blame] | 313 | userId = UserHandle.USER_SYSTEM; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 314 | } |
Anthony Chen | 55e8e1e | 2016-01-08 10:31:46 -0800 | [diff] [blame] | 315 | |
| 316 | Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId); |
| 317 | |
| 318 | TypedValue typedValue = new TypedValue(); |
| 319 | context.getResources().getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true); |
| 320 | float scaleFactor = typedValue.getFloat(); |
| 321 | |
| 322 | // No need to scale the icon, so return it as is. |
| 323 | if (scaleFactor == 1.f) { |
| 324 | return icon; |
| 325 | } |
| 326 | |
| 327 | return new ScalingDrawableWrapper(icon, scaleFactor); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 328 | } |
Joe Onorato | b77f53b | 2010-05-28 19:59:51 -0400 | [diff] [blame] | 329 | |
| 330 | public StatusBarIcon getStatusBarIcon() { |
| 331 | return mIcon; |
| 332 | } |
Joe Onorato | f9ec03c | 2010-09-23 15:09:18 -0700 | [diff] [blame] | 333 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 334 | @Override |
| 335 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 336 | super.onInitializeAccessibilityEvent(event); |
| 337 | if (mNotification != null) { |
| 338 | event.setParcelableData(mNotification); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | @Override |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 343 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 344 | super.onSizeChanged(w, h, oldw, oldh); |
| 345 | if (mNumberBackground != null) { |
| 346 | placeNumber(); |
| 347 | } |
| 348 | } |
| 349 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 350 | @Override |
Jorim Jaggi | 66ac133 | 2015-01-21 19:22:26 +0100 | [diff] [blame] | 351 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 352 | super.onRtlPropertiesChanged(layoutDirection); |
| 353 | updateDrawable(); |
| 354 | } |
| 355 | |
| 356 | @Override |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 357 | protected void onDraw(Canvas canvas) { |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 358 | if (mIconAppearAmount > 0.0f) { |
| 359 | canvas.save(); |
| 360 | canvas.scale(mIconScale * mIconAppearAmount, mIconScale * mIconAppearAmount, |
| 361 | getWidth() / 2, getHeight() / 2); |
| 362 | super.onDraw(canvas); |
| 363 | canvas.restore(); |
| 364 | } |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 365 | |
| 366 | if (mNumberBackground != null) { |
| 367 | mNumberBackground.draw(canvas); |
| 368 | canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain); |
| 369 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 370 | if (mDotAppearAmount != 0.0f) { |
| 371 | float radius; |
| 372 | float alpha; |
| 373 | if (mDotAppearAmount <= 1.0f) { |
| 374 | radius = mDotRadius * mDotAppearAmount; |
| 375 | alpha = 1.0f; |
| 376 | } else { |
| 377 | float fadeOutAmount = mDotAppearAmount - 1.0f; |
| 378 | alpha = 1.0f - fadeOutAmount; |
| 379 | radius = NotificationUtils.interpolate(mDotRadius, getWidth() / 4, fadeOutAmount); |
| 380 | } |
| 381 | mDotPaint.setAlpha((int) (alpha * 255)); |
| 382 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, mDotPaint); |
| 383 | } |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 384 | } |
| 385 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 386 | @Override |
Joe Onorato | f9ec03c | 2010-09-23 15:09:18 -0700 | [diff] [blame] | 387 | protected void debug(int depth) { |
| 388 | super.debug(depth); |
| 389 | Log.d("View", debugIndent(depth) + "slot=" + mSlot); |
| 390 | Log.d("View", debugIndent(depth) + "icon=" + mIcon); |
| 391 | } |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 392 | |
| 393 | void placeNumber() { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 394 | final String str; |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 395 | final int tooBig = getContext().getResources().getInteger( |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 396 | android.R.integer.status_bar_notification_info_maxnum); |
| 397 | if (mIcon.number > tooBig) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 398 | str = getContext().getResources().getString( |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 399 | android.R.string.status_bar_notification_info_overflow); |
| 400 | } else { |
| 401 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 402 | str = f.format(mIcon.number); |
| 403 | } |
| 404 | mNumberText = str; |
| 405 | |
Joe Onorato | 6c01a11 | 2010-10-04 17:38:47 -0400 | [diff] [blame] | 406 | final int w = getWidth(); |
| 407 | final int h = getHeight(); |
| 408 | final Rect r = new Rect(); |
| 409 | mNumberPain.getTextBounds(str, 0, str.length(), r); |
| 410 | final int tw = r.right - r.left; |
| 411 | final int th = r.bottom - r.top; |
| 412 | mNumberBackground.getPadding(r); |
| 413 | int dw = r.left + tw + r.right; |
| 414 | if (dw < mNumberBackground.getMinimumWidth()) { |
| 415 | dw = mNumberBackground.getMinimumWidth(); |
| 416 | } |
| 417 | mNumberX = w-r.right-((dw-r.right-r.left)/2); |
| 418 | int dh = r.top + th + r.bottom; |
| 419 | if (dh < mNumberBackground.getMinimumWidth()) { |
| 420 | dh = mNumberBackground.getMinimumWidth(); |
| 421 | } |
| 422 | mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2); |
| 423 | mNumberBackground.setBounds(w-dw, h-dh, w, h); |
| 424 | } |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 425 | |
| 426 | private void setContentDescription(Notification notification) { |
| 427 | if (notification != null) { |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 428 | String d = contentDescForNotification(mContext, notification); |
| 429 | if (!TextUtils.isEmpty(d)) { |
| 430 | setContentDescription(d); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | } |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 434 | |
| 435 | public String toString() { |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 436 | return "StatusBarIconView(slot=" + mSlot + " icon=" + mIcon |
Daniel Sandler | 7579bca | 2011-08-18 15:47:26 -0400 | [diff] [blame] | 437 | + " notification=" + mNotification + ")"; |
| 438 | } |
Jason Monk | 3b23007 | 2015-05-29 11:11:29 -0400 | [diff] [blame] | 439 | |
| 440 | public String getSlot() { |
| 441 | return mSlot; |
| 442 | } |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 443 | |
| 444 | |
| 445 | public static String contentDescForNotification(Context c, Notification n) { |
Adrian Roos | a8e18ef | 2016-05-26 17:17:02 -0700 | [diff] [blame] | 446 | String appName = ""; |
| 447 | try { |
| 448 | Notification.Builder builder = Notification.Builder.recoverBuilder(c, n); |
| 449 | appName = builder.loadHeaderAppName(); |
| 450 | } catch (RuntimeException e) { |
| 451 | Log.e(TAG, "Unable to recover builder", e); |
| 452 | // Trying to get the app name from the app info instead. |
| 453 | Parcelable appInfo = n.extras.getParcelable( |
| 454 | Notification.EXTRA_BUILDER_APPLICATION_INFO); |
| 455 | if (appInfo instanceof ApplicationInfo) { |
| 456 | appName = String.valueOf(((ApplicationInfo) appInfo).loadLabel( |
| 457 | c.getPackageManager())); |
| 458 | } |
| 459 | } |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 460 | |
Julia Reynolds | 7f9ce78 | 2016-05-17 15:34:34 -0400 | [diff] [blame] | 461 | CharSequence title = n.extras.getCharSequence(Notification.EXTRA_TITLE); |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 462 | CharSequence ticker = n.tickerText; |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 463 | |
Adrian Roos | 6e782a5 | 2017-03-30 18:34:10 -0700 | [diff] [blame] | 464 | CharSequence desc = !TextUtils.isEmpty(title) ? title |
| 465 | : !TextUtils.isEmpty(ticker) ? ticker : ""; |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 466 | |
| 467 | return c.getString(R.string.accessibility_desc_notification_icon, appName, desc); |
Adrian Roos | eba0582 | 2016-04-22 17:09:27 -0700 | [diff] [blame] | 468 | } |
Adrian Roos | 51548e6 | 2016-04-28 11:20:26 -0700 | [diff] [blame] | 469 | |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 470 | /** |
| 471 | * Set the color that is used to draw decoration like the overflow dot. This will not be applied |
| 472 | * to the drawable. |
| 473 | */ |
| 474 | public void setDecorColor(int iconTint) { |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 475 | mDecorColor = iconTint; |
| 476 | updateDecorColor(); |
| 477 | } |
| 478 | |
| 479 | private void updateDecorColor() { |
| 480 | int color = NotificationUtils.interpolateColors(mDecorColor, Color.WHITE, mDarkAmount); |
| 481 | if (mDotPaint.getColor() != color) { |
| 482 | mDotPaint.setColor(color); |
| 483 | |
| 484 | if (mDotAppearAmount != 0) { |
| 485 | invalidate(); |
| 486 | } |
| 487 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 490 | /** |
| 491 | * Set the static color that should be used for the drawable of this icon if it's not |
| 492 | * transitioning this also immediately sets the color. |
| 493 | */ |
| 494 | public void setStaticDrawableColor(int color) { |
| 495 | mDrawableColor = color; |
| 496 | setColorInternal(color); |
| 497 | mIconColor = color; |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 498 | mDozer.setColor(color); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | private void setColorInternal(int color) { |
Adrian Roos | f3eacd3 | 2017-04-14 16:35:58 -0700 | [diff] [blame^] | 502 | mCurrentSetColor = color; |
| 503 | updateIconColor(); |
| 504 | } |
| 505 | |
| 506 | private void updateIconColor() { |
| 507 | if (mCurrentSetColor != NO_COLOR) { |
| 508 | setImageTintList(ColorStateList.valueOf(NotificationUtils.interpolateColors( |
| 509 | mCurrentSetColor, Color.WHITE, mDarkAmount))); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 510 | } else { |
| 511 | setImageTintList(null); |
Adrian Roos | f3eacd3 | 2017-04-14 16:35:58 -0700 | [diff] [blame^] | 512 | mDozer.updateGrayscale(this, mDarkAmount); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 513 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | public void setIconColor(int iconColor, boolean animate) { |
| 517 | if (mIconColor != iconColor) { |
| 518 | mIconColor = iconColor; |
| 519 | if (mColorAnimator != null) { |
| 520 | mColorAnimator.cancel(); |
| 521 | } |
| 522 | if (mCurrentSetColor == iconColor) { |
| 523 | return; |
| 524 | } |
| 525 | if (animate && mCurrentSetColor != NO_COLOR) { |
| 526 | mAnimationStartColor = mCurrentSetColor; |
| 527 | mColorAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); |
| 528 | mColorAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 529 | mColorAnimator.setDuration(ANIMATION_DURATION_FAST); |
| 530 | mColorAnimator.addUpdateListener(mColorUpdater); |
| 531 | mColorAnimator.addListener(new AnimatorListenerAdapter() { |
| 532 | @Override |
| 533 | public void onAnimationEnd(Animator animation) { |
| 534 | mColorAnimator = null; |
| 535 | mAnimationStartColor = NO_COLOR; |
| 536 | } |
| 537 | }); |
| 538 | mColorAnimator.start(); |
| 539 | } else { |
| 540 | setColorInternal(iconColor); |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | public int getStaticDrawableColor() { |
| 546 | return mDrawableColor; |
| 547 | } |
| 548 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 549 | public void setVisibleState(int state) { |
| 550 | setVisibleState(state, true /* animate */, null /* endRunnable */); |
| 551 | } |
| 552 | |
| 553 | public void setVisibleState(int state, boolean animate) { |
| 554 | setVisibleState(state, animate, null); |
| 555 | } |
| 556 | |
| 557 | @Override |
| 558 | public boolean hasOverlappingRendering() { |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | public void setVisibleState(int visibleState, boolean animate, Runnable endRunnable) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 563 | boolean runnableAdded = false; |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 564 | if (visibleState != mVisibleState) { |
| 565 | mVisibleState = visibleState; |
Selim Cinek | 5ece5a7 | 2017-02-15 11:47:42 -0800 | [diff] [blame] | 566 | if (mIconAppearAnimator != null) { |
| 567 | mIconAppearAnimator.cancel(); |
| 568 | } |
| 569 | if (mDotAnimator != null) { |
| 570 | mDotAnimator.cancel(); |
| 571 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 572 | if (animate) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 573 | float targetAmount = 0.0f; |
| 574 | Interpolator interpolator = Interpolators.FAST_OUT_LINEAR_IN; |
| 575 | if (visibleState == STATE_ICON) { |
| 576 | targetAmount = 1.0f; |
| 577 | interpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
| 578 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 579 | float currentAmount = getIconAppearAmount(); |
| 580 | if (targetAmount != currentAmount) { |
| 581 | mIconAppearAnimator = ObjectAnimator.ofFloat(this, ICON_APPEAR_AMOUNT, |
| 582 | currentAmount, targetAmount); |
| 583 | mIconAppearAnimator.setInterpolator(interpolator); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 584 | mIconAppearAnimator.setDuration(ANIMATION_DURATION_FAST); |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 585 | mIconAppearAnimator.addListener(new AnimatorListenerAdapter() { |
| 586 | @Override |
| 587 | public void onAnimationEnd(Animator animation) { |
| 588 | mIconAppearAnimator = null; |
| 589 | runRunnable(endRunnable); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 590 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 591 | }); |
| 592 | mIconAppearAnimator.start(); |
| 593 | runnableAdded = true; |
| 594 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 595 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 596 | targetAmount = visibleState == STATE_ICON ? 2.0f : 0.0f; |
| 597 | interpolator = Interpolators.FAST_OUT_LINEAR_IN; |
| 598 | if (visibleState == STATE_DOT) { |
| 599 | targetAmount = 1.0f; |
| 600 | interpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
| 601 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 602 | currentAmount = getDotAppearAmount(); |
| 603 | if (targetAmount != currentAmount) { |
| 604 | mDotAnimator = ObjectAnimator.ofFloat(this, DOT_APPEAR_AMOUNT, |
| 605 | currentAmount, targetAmount); |
| 606 | mDotAnimator.setInterpolator(interpolator); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 607 | mDotAnimator.setDuration(ANIMATION_DURATION_FAST); |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 608 | final boolean runRunnable = !runnableAdded; |
| 609 | mDotAnimator.addListener(new AnimatorListenerAdapter() { |
| 610 | @Override |
| 611 | public void onAnimationEnd(Animator animation) { |
| 612 | mDotAnimator = null; |
| 613 | if (runRunnable) { |
| 614 | runRunnable(endRunnable); |
| 615 | } |
| 616 | } |
| 617 | }); |
| 618 | mDotAnimator.start(); |
| 619 | runnableAdded = true; |
| 620 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 621 | } else { |
| 622 | setIconAppearAmount(visibleState == STATE_ICON ? 1.0f : 0.0f); |
Selim Cinek | 01a73f9 | 2016-12-06 16:13:42 -0800 | [diff] [blame] | 623 | setDotAppearAmount(visibleState == STATE_DOT ? 1.0f |
| 624 | : visibleState == STATE_ICON ? 2.0f |
| 625 | : 0.0f); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 626 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 627 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 628 | if (!runnableAdded) { |
| 629 | runRunnable(endRunnable); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | private void runRunnable(Runnable runnable) { |
| 634 | if (runnable != null) { |
| 635 | runnable.run(); |
| 636 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 639 | public void setIconAppearAmount(float iconAppearAmount) { |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 640 | if (mIconAppearAmount != iconAppearAmount) { |
| 641 | mIconAppearAmount = iconAppearAmount; |
| 642 | invalidate(); |
| 643 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | public float getIconAppearAmount() { |
| 647 | return mIconAppearAmount; |
| 648 | } |
| 649 | |
| 650 | public int getVisibleState() { |
| 651 | return mVisibleState; |
| 652 | } |
| 653 | |
| 654 | public void setDotAppearAmount(float dotAppearAmount) { |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 655 | if (mDotAppearAmount != dotAppearAmount) { |
| 656 | mDotAppearAmount = dotAppearAmount; |
| 657 | invalidate(); |
| 658 | } |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 661 | @Override |
| 662 | public void setVisibility(int visibility) { |
| 663 | super.setVisibility(visibility); |
| 664 | if (mOnVisibilityChangedListener != null) { |
| 665 | mOnVisibilityChangedListener.onVisibilityChanged(visibility); |
| 666 | } |
| 667 | } |
| 668 | |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 669 | public float getDotAppearAmount() { |
| 670 | return mDotAppearAmount; |
| 671 | } |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 672 | |
| 673 | public void setOnVisibilityChangedListener(OnVisibilityChangedListener listener) { |
| 674 | mOnVisibilityChangedListener = listener; |
| 675 | } |
| 676 | |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 677 | public void setDark(boolean dark, boolean fade, long delay) { |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 678 | mDozer.setIntensityDark(f -> { |
| 679 | mDarkAmount = f; |
| 680 | updateDecorColor(); |
Adrian Roos | f3eacd3 | 2017-04-14 16:35:58 -0700 | [diff] [blame^] | 681 | updateIconColor(); |
Adrian Roos | 456e005 | 2017-04-04 16:44:29 -0700 | [diff] [blame] | 682 | }, dark, fade, delay); |
| 683 | } |
| 684 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 685 | public interface OnVisibilityChangedListener { |
| 686 | void onVisibilityChanged(int newVisibility); |
| 687 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 688 | } |