summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorTony <twickham@google.com>2018-08-17 13:47:39 -0700
committerTony <twickham@google.com>2018-08-17 13:47:39 -0700
commit4043b05cdef4e713b57f76e532539ead7e7c2ba6 (patch)
treed252d571c3e639365599553b6e32e36f7695fa14 /src/com/android
parent9e26e26f0057b5c19248238ff869aba2930b7f56 (diff)
downloadandroid_packages_apps_Trebuchet-4043b05cdef4e713b57f76e532539ead7e7c2ba6.tar.gz
android_packages_apps_Trebuchet-4043b05cdef4e713b57f76e532539ead7e7c2ba6.tar.bz2
android_packages_apps_Trebuchet-4043b05cdef4e713b57f76e532539ead7e7c2ba6.zip
Cancel badge scale anim when setting new badge scale
Otherwise it's possible the badge scale animation will override the non-animated set value, which could mean a badge continues to show even though it shouldn't: - Animate badge scale to 1 - Before animation finishes, set badge scale to 0 - Badge scale ends at 1, since animation wasn't cancelled, so we continue to show it indefinitely Also exported some properties in case a similar issue arises. Bug: 111791593 Change-Id: Ia1a417239b909886adf9351e9bdc06a3b22d8b73
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/launcher3/BubbleTextView.java29
-rw-r--r--src/com/android/launcher3/badge/FolderBadgeInfo.java3
-rw-r--r--src/com/android/launcher3/folder/Folder.java2
-rw-r--r--src/com/android/launcher3/folder/FolderIcon.java26
4 files changed, 54 insertions, 6 deletions
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 01e3a10b0..230ea4fea 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -16,6 +16,8 @@
package com.android.launcher3;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -112,10 +114,13 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
@ViewDebug.ExportedProperty(category = "launcher")
private float mTextAlpha = 1;
+ @ViewDebug.ExportedProperty(category = "launcher")
private BadgeInfo mBadgeInfo;
private BadgeRenderer mBadgeRenderer;
private int mBadgeColor;
+ @ViewDebug.ExportedProperty(category = "launcher")
private float mBadgeScale;
+ private Animator mBadgeScaleAnim;
private boolean mForceHideBadge;
private Point mTempSpaceForBadgeOffset = new Point();
private Rect mTempIconBounds = new Rect();
@@ -188,10 +193,29 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
public void reset() {
mBadgeInfo = null;
mBadgeColor = Color.TRANSPARENT;
+ cancelBadgeScaleAnim();
mBadgeScale = 0f;
mForceHideBadge = false;
}
+ private void cancelBadgeScaleAnim() {
+ if (mBadgeScaleAnim != null) {
+ mBadgeScaleAnim.cancel();
+ }
+ }
+
+ private void animateBadgeScale(float... badgeScales) {
+ cancelBadgeScaleAnim();
+ mBadgeScaleAnim = ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, badgeScales);
+ mBadgeScaleAnim.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mBadgeScaleAnim = null;
+ }
+ });
+ mBadgeScaleAnim.start();
+ }
+
public void applyFromShortcutInfo(ShortcutInfo info) {
applyFromShortcutInfo(info, false);
}
@@ -378,7 +402,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
if (forceHideBadge) {
invalidate();
} else if (hasBadge()) {
- ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, 0, 1).start();
+ animateBadgeScale(0, 1);
}
}
@@ -524,8 +548,9 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
if (wasBadged || isBadged) {
// Animate when a badge is first added or when it is removed.
if (animate && (wasBadged ^ isBadged) && isShown()) {
- ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, newBadgeScale).start();
+ animateBadgeScale(newBadgeScale);
} else {
+ cancelBadgeScaleAnim();
mBadgeScale = newBadgeScale;
invalidate();
}
diff --git a/src/com/android/launcher3/badge/FolderBadgeInfo.java b/src/com/android/launcher3/badge/FolderBadgeInfo.java
index 3a1bf60c4..fa5e8a43d 100644
--- a/src/com/android/launcher3/badge/FolderBadgeInfo.java
+++ b/src/com/android/launcher3/badge/FolderBadgeInfo.java
@@ -16,6 +16,8 @@
package com.android.launcher3.badge;
+import android.view.ViewDebug;
+
import com.android.launcher3.Utilities;
/**
@@ -56,6 +58,7 @@ public class FolderBadgeInfo extends BadgeInfo {
return 0;
}
+ @ViewDebug.ExportedProperty(category = "launcher")
public boolean hasBadge() {
return mNumNotifications > 0;
}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 6a3ebcfb0..a059627df 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -644,7 +644,7 @@ public class Folder extends AbstractFloatingView implements DragSource,
mFolderIcon.mBackground.animateBackgroundStroke();
mFolderIcon.onFolderClose(mContent.getCurrentPage());
if (mFolderIcon.hasBadge()) {
- mFolderIcon.createBadgeScaleAnimator(0f, 1f).start();
+ mFolderIcon.animateBadgeScale(0f, 1f);
}
mFolderIcon.requestFocus();
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index 87a079604..d09f03612 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -20,6 +20,7 @@ import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_I
import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMATION_DURATION;
import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
@@ -32,6 +33,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
+import android.view.ViewDebug;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -106,9 +108,12 @@ public class FolderIcon extends FrameLayout implements FolderListener {
private Alarm mOpenAlarm = new Alarm();
+ @ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
private FolderBadgeInfo mBadgeInfo = new FolderBadgeInfo();
private BadgeRenderer mBadgeRenderer;
+ @ViewDebug.ExportedProperty(category = "launcher")
private float mBadgeScale;
+ private Animator mBadgeScaleAnim;
private Point mTempSpaceForBadgeOffset = new Point();
private static final Property<FolderIcon, Float> BADGE_SCALE_PROPERTY
@@ -393,15 +398,30 @@ public class FolderIcon extends FrameLayout implements FolderListener {
float newBadgeScale = isBadged ? 1f : 0f;
// Animate when a badge is first added or when it is removed.
if ((wasBadged ^ isBadged) && isShown()) {
- createBadgeScaleAnimator(newBadgeScale).start();
+ animateBadgeScale(newBadgeScale);
} else {
+ cancelBadgeScaleAnim();
mBadgeScale = newBadgeScale;
invalidate();
}
}
- public Animator createBadgeScaleAnimator(float... badgeScales) {
- return ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, badgeScales);
+ private void cancelBadgeScaleAnim() {
+ if (mBadgeScaleAnim != null) {
+ mBadgeScaleAnim.cancel();
+ }
+ }
+
+ public void animateBadgeScale(float... badgeScales) {
+ cancelBadgeScaleAnim();
+ mBadgeScaleAnim = ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, badgeScales);
+ mBadgeScaleAnim.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mBadgeScaleAnim = null;
+ }
+ });
+ mBadgeScaleAnim.start();
}
public boolean hasBadge() {