From cab4a60c485872848fc0fa3e65baaeb06d21a7d8 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Wed, 3 Sep 2014 14:47:57 +0200 Subject: [PATCH] Fixed a bug where notification icons where not animating Bug: 16043845 Change-Id: I23217d90803fd247f6d1b4d2aea056deb5749c15 --- .../systemui/statusbar/BaseStatusBar.java | 4 +- .../statusbar/ExpandableNotificationRow.java | 50 +++++++++++++++++++ .../statusbar/NotificationContentView.java | 8 +++ .../stack/NotificationStackScrollLayout.java | 23 +++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index c3eb94c3162b4..f5d660584b7f8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -1263,7 +1263,9 @@ public abstract class BaseStatusBar extends SystemUI implements // Add a basic notification template publicViewLocal = LayoutInflater.from(mContext).inflate( com.android.internal.R.layout.notification_template_material_base, - expandedPublic, true); + expandedPublic, false); + publicViewLocal.setIsRootNamespace(true); + expandedPublic.setContractedChild(publicViewLocal); final TextView title = (TextView) publicViewLocal.findViewById(com.android.internal.R.id.title); try { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index dfcc40847ec7d..e3a0b1855f0dc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -17,10 +17,15 @@ package com.android.systemui.statusbar; import android.content.Context; +import android.graphics.drawable.AnimatedVectorDrawable; +import android.graphics.drawable.AnimationDrawable; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; +import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; +import android.widget.ImageView; import com.android.systemui.R; public class ExpandableNotificationRow extends ActivatableNotificationView { @@ -62,6 +67,51 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { private boolean mWasReset; private NotificationGuts mGuts; + public void setIconAnimationRunning(boolean running) { + setIconAnimationRunning(running, mPublicLayout); + setIconAnimationRunning(running, mPrivateLayout); + } + + private void setIconAnimationRunning(boolean running, NotificationContentView layout) { + if (layout != null) { + View contractedChild = layout.getContractedChild(); + View expandedChild = layout.getExpandedChild(); + setIconAnimationRunningForChild(running, contractedChild); + setIconAnimationRunningForChild(running, expandedChild); + } + } + + private void setIconAnimationRunningForChild(boolean running, View child) { + if (child != null) { + ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); + setIconRunning(icon, running); + ImageView rightIcon = (ImageView) child.findViewById( + com.android.internal.R.id.right_icon); + setIconRunning(rightIcon, running); + } + } + + private void setIconRunning(ImageView imageView, boolean running) { + if (imageView != null) { + Drawable drawable = imageView.getDrawable(); + if (drawable instanceof AnimationDrawable) { + AnimationDrawable animationDrawable = (AnimationDrawable) drawable; + if (running) { + animationDrawable.start(); + } else { + animationDrawable.stop(); + } + } else if (drawable instanceof AnimatedVectorDrawable) { + AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; + if (running) { + animationDrawable.start(); + } else { + animationDrawable.stop(); + } + } + } + } + public interface ExpansionLogger { public void logNotificationExpansion(String key, boolean userAction, boolean expanded); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index 8b4c2c4e44ce8..e31eb7c9bd081 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -88,6 +88,14 @@ public class NotificationContentView extends FrameLayout { mContractedVisible = true; } + public View getContractedChild() { + return mContractedChild; + } + + public View getExpandedChild() { + return mExpandedChild; + } + public void setContractedChild(View child) { if (mContractedChild != null) { mContractedChild.animate().cancel(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java index 148b00cfa3f10..fed579cb39ee3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -1467,6 +1467,7 @@ public class NotificationStackScrollLayout extends ViewGroup // drawn when removed getOverlay().add(child); } + updateAnimationState(false, child); // Make sure the clipRect we might have set is removed child.setClipBounds(null); @@ -1545,10 +1546,28 @@ public class NotificationStackScrollLayout extends ViewGroup mStackScrollAlgorithm.notifyChildrenChanged(this); ((ExpandableView) child).setOnHeightChangedListener(this); generateAddAnimation(child, false /* fromMoreCard */); + updateAnimationState(mAnimationsEnabled && mIsExpanded, child); } public void setAnimationsEnabled(boolean animationsEnabled) { mAnimationsEnabled = animationsEnabled; + updateNotificationAnimationStates(); + } + + private void updateNotificationAnimationStates() { + boolean running = mIsExpanded && mAnimationsEnabled; + int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + updateAnimationState(running, child); + } + } + + private void updateAnimationState(boolean running, View child) { + if (child instanceof ExpandableNotificationRow) { + ExpandableNotificationRow row = (ExpandableNotificationRow) child; + row.setIconAnimationRunning(running); + } } public boolean isAddOrRemoveAnimationPending() { @@ -1918,8 +1937,12 @@ public class NotificationStackScrollLayout extends ViewGroup } private void setIsExpanded(boolean isExpanded) { + boolean changed = isExpanded != mIsExpanded; mIsExpanded = isExpanded; mStackScrollAlgorithm.setIsExpanded(isExpanded); + if (changed) { + updateNotificationAnimationStates(); + } } @Override