blob: 543f899283d4b476cbe643a5036bff09f59b997e [file] [log] [blame]
Joe Onorato0cbda992010-05-02 16:28:15 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joe Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
Joe Onorato0cbda992010-05-02 16:28:15 -070018
Selim Cinek49014f82016-11-04 14:55:30 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
21import android.animation.ObjectAnimator;
22import android.animation.ValueAnimator;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070023import android.app.Notification;
Joe Onorato0cbda992010-05-02 16:28:15 -070024import android.content.Context;
Adrian Roosa8e18ef2016-05-26 17:17:02 -070025import android.content.pm.ApplicationInfo;
Selim Cinek3e7592d2016-04-11 09:35:54 +080026import android.content.res.Configuration;
Joe Onorato0cbda992010-05-02 16:28:15 -070027import android.content.res.Resources;
Joe Onorato0cbda992010-05-02 16:28:15 -070028import android.graphics.Canvas;
Joe Onorato6c01a112010-10-04 17:38:47 -040029import android.graphics.Paint;
30import android.graphics.Rect;
John Spurlockde84f0e2013-06-12 12:41:00 -040031import android.graphics.drawable.Drawable;
Dan Sandlerd63f9322015-05-06 15:18:49 -040032import android.graphics.drawable.Icon;
Adrian Roosa8e18ef2016-05-26 17:17:02 -070033import android.os.Parcelable;
Jeff Sharkeyded653b2012-09-27 19:09:24 -070034import android.os.UserHandle;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070035import android.text.TextUtils;
Daniel Sandler05e24142011-11-10 11:56:49 -050036import android.util.AttributeSet;
Selim Cinek49014f82016-11-04 14:55:30 -070037import android.util.FloatProperty;
Joe Onoratof9ec03c2010-09-23 15:09:18 -070038import android.util.Log;
Selim Cinek49014f82016-11-04 14:55:30 -070039import android.util.Property;
Anthony Chen55e8e1e2016-01-08 10:31:46 -080040import android.util.TypedValue;
Joe Onorato0cbda992010-05-02 16:28:15 -070041import android.view.ViewDebug;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070042import android.view.accessibility.AccessibilityEvent;
Selim Cinek49014f82016-11-04 14:55:30 -070043import android.view.animation.Interpolator;
Winsonc0d70582016-01-29 10:24:39 -080044
Joe Onorato0cbda992010-05-02 16:28:15 -070045import com.android.internal.statusbar.StatusBarIcon;
Selim Cinek49014f82016-11-04 14:55:30 -070046import com.android.systemui.Interpolators;
Joe Onorato6c01a112010-10-04 17:38:47 -040047import com.android.systemui.R;
Selim Cinek49014f82016-11-04 14:55:30 -070048import com.android.systemui.statusbar.notification.NotificationUtils;
Joe Onorato6c01a112010-10-04 17:38:47 -040049
John Spurlockde84f0e2013-06-12 12:41:00 -040050import java.text.NumberFormat;
51
Joe Onorato0cbda992010-05-02 16:28:15 -070052public class StatusBarIconView extends AnimatedImageView {
Selim Cinek49014f82016-11-04 14:55:30 -070053 public static final int STATE_ICON = 0;
54 public static final int STATE_DOT = 1;
55 public static final int STATE_HIDDEN = 2;
Joe Onorato0cbda992010-05-02 16:28:15 -070056
Selim Cinek49014f82016-11-04 14:55:30 -070057 private static final String TAG = "StatusBarIconView";
58 private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
59 = new FloatProperty<StatusBarIconView>("iconAppearAmount") {
60
61 @Override
62 public void setValue(StatusBarIconView object, float value) {
63 object.setIconAppearAmount(value);
64 }
65
66 @Override
67 public Float get(StatusBarIconView object) {
68 return object.getIconAppearAmount();
69 }
70 };
71 private static final Property<StatusBarIconView, Float> DOT_APPEAR_AMOUNG
72 = new FloatProperty<StatusBarIconView>("dot_appear_amount") {
73
74 @Override
75 public void setValue(StatusBarIconView object, float value) {
76 object.setDotAppearAmount(value);
77 }
78
79 @Override
80 public Float get(StatusBarIconView object) {
81 return object.getDotAppearAmount();
82 }
83 };
84
85 private boolean mAlwaysScaleIcon;
Joe Onorato0cbda992010-05-02 16:28:15 -070086 private StatusBarIcon mIcon;
87 @ViewDebug.ExportedProperty private String mSlot;
Joe Onorato6c01a112010-10-04 17:38:47 -040088 private Drawable mNumberBackground;
89 private Paint mNumberPain;
90 private int mNumberX;
91 private int mNumberY;
92 private String mNumberText;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070093 private Notification mNotification;
Jason Monk3b230072015-05-29 11:11:29 -040094 private final boolean mBlocked;
Selim Cinek3e7592d2016-04-11 09:35:54 +080095 private int mDensity;
Selim Cinek281c2022016-10-13 19:14:43 -070096 private float mIconScale = 1.0f;
Selim Cinek49014f82016-11-04 14:55:30 -070097 private final Paint mDotPaint = new Paint();
98 private boolean mDotVisible;
99 private float mDotRadius;
100 private int mStaticDotRadius;
101 private int mVisibleState = STATE_ICON;
102 private float mIconAppearAmount = 1.0f;
103 private ObjectAnimator mIconAppearAnimator;
104 private ObjectAnimator mDotAnimator;
105 private float mDotAppearAmount;
Joe Onorato0cbda992010-05-02 16:28:15 -0700106
John Spurlocke6f0a712013-09-03 16:23:49 -0400107 public StatusBarIconView(Context context, String slot, Notification notification) {
Jason Monk3b230072015-05-29 11:11:29 -0400108 this(context, slot, notification, false);
109 }
110
111 public StatusBarIconView(Context context, String slot, Notification notification,
112 boolean blocked) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700113 super(context);
Jason Monk3b230072015-05-29 11:11:29 -0400114 mBlocked = blocked;
Joe Onorato0cbda992010-05-02 16:28:15 -0700115 mSlot = slot;
Joe Onorato6c01a112010-10-04 17:38:47 -0400116 mNumberPain = new Paint();
117 mNumberPain.setTextAlign(Paint.Align.CENTER);
Alan Viverette4a357cd2015-03-18 18:37:18 -0700118 mNumberPain.setColor(context.getColor(R.drawable.notification_number_text_color));
Joe Onorato6c01a112010-10-04 17:38:47 -0400119 mNumberPain.setAntiAlias(true);
Christoph Studera0506e72014-07-31 20:27:39 +0200120 setNotification(notification);
Selim Cinek3e7592d2016-04-11 09:35:54 +0800121 maybeUpdateIconScale();
122 setScaleType(ScaleType.CENTER);
123 mDensity = context.getResources().getDisplayMetrics().densityDpi;
Selim Cinek49014f82016-11-04 14:55:30 -0700124 if (mNotification != null) {
125 setIconTint(getContext().getColor(
126 com.android.internal.R.color.notification_icon_default_color));
127 }
128 reloadDimens();
Selim Cinek3e7592d2016-04-11 09:35:54 +0800129 }
Daniel Sandler26c84b12011-07-27 00:09:40 -0400130
Selim Cinek3e7592d2016-04-11 09:35:54 +0800131 private void maybeUpdateIconScale() {
Daniel Sandler7579bca2011-08-18 15:47:26 -0400132 // We do not resize and scale system icons (on the right), only notification icons (on the
133 // left).
Selim Cinek3e7592d2016-04-11 09:35:54 +0800134 if (mNotification != null || mAlwaysScaleIcon) {
135 updateIconScale();
Daniel Sandler7579bca2011-08-18 15:47:26 -0400136 }
Selim Cinek3e7592d2016-04-11 09:35:54 +0800137 }
Daniel Sandlerabff0322011-09-27 11:19:34 -0400138
Selim Cinek3e7592d2016-04-11 09:35:54 +0800139 private void updateIconScale() {
140 Resources res = mContext.getResources();
141 final int outerBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_size);
142 final int imageBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size);
Selim Cinek281c2022016-10-13 19:14:43 -0700143 mIconScale = (float)imageBounds / (float)outerBounds;
Selim Cinek281c2022016-10-13 19:14:43 -0700144 }
145
146 public float getIconScale() {
147 return mIconScale;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800148 }
149
150 @Override
151 protected void onConfigurationChanged(Configuration newConfig) {
152 super.onConfigurationChanged(newConfig);
153 int density = newConfig.densityDpi;
154 if (density != mDensity) {
155 mDensity = density;
156 maybeUpdateIconScale();
157 updateDrawable();
Selim Cinek49014f82016-11-04 14:55:30 -0700158 reloadDimens();
159 }
160 }
161
162 private void reloadDimens() {
163 boolean applyRadius = mDotRadius == mStaticDotRadius;
164 mStaticDotRadius = getResources().getDimensionPixelSize(R.dimen.overflow_dot_radius);
165 if (applyRadius) {
166 mDotRadius = mStaticDotRadius;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800167 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700168 }
169
Christoph Studera0506e72014-07-31 20:27:39 +0200170 public void setNotification(Notification notification) {
171 mNotification = notification;
172 setContentDescription(notification);
173 }
174
Daniel Sandler05e24142011-11-10 11:56:49 -0500175 public StatusBarIconView(Context context, AttributeSet attrs) {
176 super(context, attrs);
Jason Monk3b230072015-05-29 11:11:29 -0400177 mBlocked = false;
Selim Cinek3e7592d2016-04-11 09:35:54 +0800178 mAlwaysScaleIcon = true;
179 updateIconScale();
180 mDensity = context.getResources().getDisplayMetrics().densityDpi;
Daniel Sandler05e24142011-11-10 11:56:49 -0500181 }
182
Joe Onorato0cbda992010-05-02 16:28:15 -0700183 private static boolean streq(String a, String b) {
Joe Onorato66d7d012010-05-14 10:05:10 -0700184 if (a == b) {
185 return true;
186 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700187 if (a == null && b != null) {
188 return false;
189 }
190 if (a != null && b == null) {
191 return false;
192 }
193 return a.equals(b);
194 }
195
Dan Sandlerd63f9322015-05-06 15:18:49 -0400196 public boolean equalIcons(Icon a, Icon b) {
197 if (a == b) return true;
198 if (a.getType() != b.getType()) return false;
199 switch (a.getType()) {
200 case Icon.TYPE_RESOURCE:
201 return a.getResPackage().equals(b.getResPackage()) && a.getResId() == b.getResId();
202 case Icon.TYPE_URI:
203 return a.getUriString().equals(b.getUriString());
204 default:
205 return false;
206 }
207 }
Joe Onorato005847b2010-06-04 16:08:02 -0400208 /**
209 * Returns whether the set succeeded.
210 */
211 public boolean set(StatusBarIcon icon) {
Dan Sandlerd63f9322015-05-06 15:18:49 -0400212 final boolean iconEquals = mIcon != null && equalIcons(mIcon.icon, icon.icon);
Joe Onorato005847b2010-06-04 16:08:02 -0400213 final boolean levelEquals = iconEquals
214 && mIcon.iconLevel == icon.iconLevel;
215 final boolean visibilityEquals = mIcon != null
216 && mIcon.visible == icon.visible;
Joe Onorato6c01a112010-10-04 17:38:47 -0400217 final boolean numberEquals = mIcon != null
218 && mIcon.number == icon.number;
219 mIcon = icon.clone();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700220 setContentDescription(icon.contentDescription);
Joe Onorato005847b2010-06-04 16:08:02 -0400221 if (!iconEquals) {
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800222 if (!updateDrawable(false /* no clear */)) return false;
Joe Onorato0cbda992010-05-02 16:28:15 -0700223 }
Joe Onorato005847b2010-06-04 16:08:02 -0400224 if (!levelEquals) {
225 setImageLevel(icon.iconLevel);
Joe Onorato0cbda992010-05-02 16:28:15 -0700226 }
Daniel Sandler26c84b12011-07-27 00:09:40 -0400227
Joe Onorato6c01a112010-10-04 17:38:47 -0400228 if (!numberEquals) {
John Spurlock01534782014-01-13 11:59:22 -0500229 if (icon.number > 0 && getContext().getResources().getBoolean(
Joe Onorato8595a3d2010-11-19 18:12:07 -0800230 R.bool.config_statusBarShowNumber)) {
Joe Onorato6c01a112010-10-04 17:38:47 -0400231 if (mNumberBackground == null) {
232 mNumberBackground = getContext().getResources().getDrawable(
233 R.drawable.ic_notification_overlay);
234 }
235 placeNumber();
236 } else {
237 mNumberBackground = null;
238 mNumberText = null;
239 }
240 invalidate();
241 }
Joe Onorato005847b2010-06-04 16:08:02 -0400242 if (!visibilityEquals) {
Jason Monk3b230072015-05-29 11:11:29 -0400243 setVisibility(icon.visible && !mBlocked ? VISIBLE : GONE);
Joe Onorato005847b2010-06-04 16:08:02 -0400244 }
Joe Onorato005847b2010-06-04 16:08:02 -0400245 return true;
Joe Onorato0cbda992010-05-02 16:28:15 -0700246 }
247
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800248 public void updateDrawable() {
249 updateDrawable(true /* with clear */);
250 }
251
252 private boolean updateDrawable(boolean withClear) {
Jorim Jaggi66ac1332015-01-21 19:22:26 +0100253 if (mIcon == null) {
254 return false;
255 }
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800256 Drawable drawable = getIcon(mIcon);
257 if (drawable == null) {
John Spurlockcd686b52013-06-05 10:13:46 -0400258 Log.w(TAG, "No icon for slot " + mSlot);
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800259 return false;
260 }
261 if (withClear) {
262 setImageDrawable(null);
263 }
264 setImageDrawable(drawable);
265 return true;
266 }
267
Joe Onoratof5510542010-06-01 07:46:41 -0700268 private Drawable getIcon(StatusBarIcon icon) {
269 return getIcon(getContext(), icon);
270 }
271
Joe Onorato0cbda992010-05-02 16:28:15 -0700272 /**
Dan Sandlerd63f9322015-05-06 15:18:49 -0400273 * Returns the right icon to use for this item
John Spurlock209bede2013-07-17 12:23:27 -0400274 *
Dan Sandlerd63f9322015-05-06 15:18:49 -0400275 * @param context Context to use to get resources
Joe Onorato0cbda992010-05-02 16:28:15 -0700276 * @return Drawable for this item, or null if the package or item could not
277 * be found
278 */
Anthony Chen55e8e1e2016-01-08 10:31:46 -0800279 public static Drawable getIcon(Context context, StatusBarIcon statusBarIcon) {
280 int userId = statusBarIcon.user.getIdentifier();
Dan Sandlerd63f9322015-05-06 15:18:49 -0400281 if (userId == UserHandle.USER_ALL) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700282 userId = UserHandle.USER_SYSTEM;
Joe Onorato0cbda992010-05-02 16:28:15 -0700283 }
Anthony Chen55e8e1e2016-01-08 10:31:46 -0800284
285 Drawable icon = statusBarIcon.icon.loadDrawableAsUser(context, userId);
286
287 TypedValue typedValue = new TypedValue();
288 context.getResources().getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true);
289 float scaleFactor = typedValue.getFloat();
290
291 // No need to scale the icon, so return it as is.
292 if (scaleFactor == 1.f) {
293 return icon;
294 }
295
296 return new ScalingDrawableWrapper(icon, scaleFactor);
Joe Onorato0cbda992010-05-02 16:28:15 -0700297 }
Joe Onoratob77f53b2010-05-28 19:59:51 -0400298
299 public StatusBarIcon getStatusBarIcon() {
300 return mIcon;
301 }
Joe Onoratof9ec03c2010-09-23 15:09:18 -0700302
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700303 @Override
304 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
305 super.onInitializeAccessibilityEvent(event);
306 if (mNotification != null) {
307 event.setParcelableData(mNotification);
308 }
309 }
310
311 @Override
Joe Onorato6c01a112010-10-04 17:38:47 -0400312 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
313 super.onSizeChanged(w, h, oldw, oldh);
314 if (mNumberBackground != null) {
315 placeNumber();
316 }
317 }
318
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700319 @Override
Jorim Jaggi66ac1332015-01-21 19:22:26 +0100320 public void onRtlPropertiesChanged(int layoutDirection) {
321 super.onRtlPropertiesChanged(layoutDirection);
322 updateDrawable();
323 }
324
325 @Override
Joe Onorato6c01a112010-10-04 17:38:47 -0400326 protected void onDraw(Canvas canvas) {
Selim Cinek49014f82016-11-04 14:55:30 -0700327 if (mIconAppearAmount > 0.0f) {
328 canvas.save();
329 canvas.scale(mIconScale * mIconAppearAmount, mIconScale * mIconAppearAmount,
330 getWidth() / 2, getHeight() / 2);
331 super.onDraw(canvas);
332 canvas.restore();
333 }
Joe Onorato6c01a112010-10-04 17:38:47 -0400334
335 if (mNumberBackground != null) {
336 mNumberBackground.draw(canvas);
337 canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain);
338 }
Selim Cinek49014f82016-11-04 14:55:30 -0700339 if (mDotAppearAmount != 0.0f) {
340 float radius;
341 float alpha;
342 if (mDotAppearAmount <= 1.0f) {
343 radius = mDotRadius * mDotAppearAmount;
344 alpha = 1.0f;
345 } else {
346 float fadeOutAmount = mDotAppearAmount - 1.0f;
347 alpha = 1.0f - fadeOutAmount;
348 radius = NotificationUtils.interpolate(mDotRadius, getWidth() / 4, fadeOutAmount);
349 }
350 mDotPaint.setAlpha((int) (alpha * 255));
351 canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, mDotPaint);
352 }
Joe Onorato6c01a112010-10-04 17:38:47 -0400353 }
354
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700355 @Override
Joe Onoratof9ec03c2010-09-23 15:09:18 -0700356 protected void debug(int depth) {
357 super.debug(depth);
358 Log.d("View", debugIndent(depth) + "slot=" + mSlot);
359 Log.d("View", debugIndent(depth) + "icon=" + mIcon);
360 }
Joe Onorato6c01a112010-10-04 17:38:47 -0400361
362 void placeNumber() {
Daniel Sandlerebce0112011-06-16 16:44:51 -0400363 final String str;
John Spurlock01534782014-01-13 11:59:22 -0500364 final int tooBig = getContext().getResources().getInteger(
Daniel Sandlerebce0112011-06-16 16:44:51 -0400365 android.R.integer.status_bar_notification_info_maxnum);
366 if (mIcon.number > tooBig) {
John Spurlock01534782014-01-13 11:59:22 -0500367 str = getContext().getResources().getString(
Daniel Sandlerebce0112011-06-16 16:44:51 -0400368 android.R.string.status_bar_notification_info_overflow);
369 } else {
370 NumberFormat f = NumberFormat.getIntegerInstance();
371 str = f.format(mIcon.number);
372 }
373 mNumberText = str;
374
Joe Onorato6c01a112010-10-04 17:38:47 -0400375 final int w = getWidth();
376 final int h = getHeight();
377 final Rect r = new Rect();
378 mNumberPain.getTextBounds(str, 0, str.length(), r);
379 final int tw = r.right - r.left;
380 final int th = r.bottom - r.top;
381 mNumberBackground.getPadding(r);
382 int dw = r.left + tw + r.right;
383 if (dw < mNumberBackground.getMinimumWidth()) {
384 dw = mNumberBackground.getMinimumWidth();
385 }
386 mNumberX = w-r.right-((dw-r.right-r.left)/2);
387 int dh = r.top + th + r.bottom;
388 if (dh < mNumberBackground.getMinimumWidth()) {
389 dh = mNumberBackground.getMinimumWidth();
390 }
391 mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2);
392 mNumberBackground.setBounds(w-dw, h-dh, w, h);
393 }
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700394
395 private void setContentDescription(Notification notification) {
396 if (notification != null) {
Adrian Rooseba05822016-04-22 17:09:27 -0700397 String d = contentDescForNotification(mContext, notification);
398 if (!TextUtils.isEmpty(d)) {
399 setContentDescription(d);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700400 }
401 }
402 }
Daniel Sandler7579bca2011-08-18 15:47:26 -0400403
404 public String toString() {
John Spurlock209bede2013-07-17 12:23:27 -0400405 return "StatusBarIconView(slot=" + mSlot + " icon=" + mIcon
Daniel Sandler7579bca2011-08-18 15:47:26 -0400406 + " notification=" + mNotification + ")";
407 }
Jason Monk3b230072015-05-29 11:11:29 -0400408
409 public String getSlot() {
410 return mSlot;
411 }
Adrian Rooseba05822016-04-22 17:09:27 -0700412
413
414 public static String contentDescForNotification(Context c, Notification n) {
Adrian Roosa8e18ef2016-05-26 17:17:02 -0700415 String appName = "";
416 try {
417 Notification.Builder builder = Notification.Builder.recoverBuilder(c, n);
418 appName = builder.loadHeaderAppName();
419 } catch (RuntimeException e) {
420 Log.e(TAG, "Unable to recover builder", e);
421 // Trying to get the app name from the app info instead.
422 Parcelable appInfo = n.extras.getParcelable(
423 Notification.EXTRA_BUILDER_APPLICATION_INFO);
424 if (appInfo instanceof ApplicationInfo) {
425 appName = String.valueOf(((ApplicationInfo) appInfo).loadLabel(
426 c.getPackageManager()));
427 }
428 }
Adrian Roos51548e62016-04-28 11:20:26 -0700429
Julia Reynolds7f9ce782016-05-17 15:34:34 -0400430 CharSequence title = n.extras.getCharSequence(Notification.EXTRA_TITLE);
Adrian Rooseba05822016-04-22 17:09:27 -0700431 CharSequence ticker = n.tickerText;
Adrian Roos51548e62016-04-28 11:20:26 -0700432
433 CharSequence desc = !TextUtils.isEmpty(ticker) ? ticker
434 : !TextUtils.isEmpty(title) ? title : "";
435
436 return c.getString(R.string.accessibility_desc_notification_icon, appName, desc);
Adrian Rooseba05822016-04-22 17:09:27 -0700437 }
Adrian Roos51548e62016-04-28 11:20:26 -0700438
Selim Cinek49014f82016-11-04 14:55:30 -0700439 public void setIconTint(int iconTint) {
440 mDotPaint.setColor(iconTint);
441 }
442
443 public void setVisibleState(int visibleState) {
444 if (visibleState != mVisibleState) {
445 mVisibleState = visibleState;
446 if (mIconAppearAnimator != null) {
447 mIconAppearAnimator.cancel();
448 }
449 float targetAmount = 0.0f;
450 Interpolator interpolator = Interpolators.FAST_OUT_LINEAR_IN;
451 if (visibleState == STATE_ICON) {
452 targetAmount = 1.0f;
453 interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
454 }
455 mIconAppearAnimator = ObjectAnimator.ofFloat(this, ICON_APPEAR_AMOUNT,
456 targetAmount);
457 mIconAppearAnimator.setInterpolator(interpolator);
458 mIconAppearAnimator.setDuration(100);
459 mIconAppearAnimator.addListener(new AnimatorListenerAdapter() {
460 @Override
461 public void onAnimationEnd(Animator animation) {
462 mIconAppearAnimator = null;
463 }
464 });
465 mIconAppearAnimator.start();
466
467 if (mDotAnimator != null) {
468 mDotAnimator.cancel();
469 }
470 targetAmount = visibleState == STATE_ICON ? 2.0f : 0.0f;
471 interpolator = Interpolators.FAST_OUT_LINEAR_IN;
472 if (visibleState == STATE_DOT) {
473 targetAmount = 1.0f;
474 interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
475 }
476 mDotAnimator = ObjectAnimator.ofFloat(this, DOT_APPEAR_AMOUNG,
477 targetAmount);
478 mDotAnimator.setInterpolator(interpolator);
479 mDotAnimator.setDuration(100);
480 mDotAnimator.addListener(new AnimatorListenerAdapter() {
481 @Override
482 public void onAnimationEnd(Animator animation) {
483 mDotAnimator = null;
484 }
485 });
486 mDotAnimator.start();
487 }
488 }
489
490 public void setIconAppearAmount(Float iconAppearAmount) {
491 mIconAppearAmount = iconAppearAmount;
492 invalidate();
493 }
494
495 public float getIconAppearAmount() {
496 return mIconAppearAmount;
497 }
498
499 public int getVisibleState() {
500 return mVisibleState;
501 }
502
503 public void setDotAppearAmount(float dotAppearAmount) {
504 mDotAppearAmount = dotAppearAmount;
505 invalidate();
506 }
507
508 public float getDotAppearAmount() {
509 return mDotAppearAmount;
510 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700511}