Fixed a bug with the notification appear animation

This happened since the switch animation was running
even when invisible. This is fixed now and only
runs when the view is actually shown.

Bug: 18168562
Change-Id: I7fa2254411d249c23cd623cdff64524729f0817c
This commit is contained in:
Selim Cinek
2014-10-31 00:12:56 +01:00
parent 1d59af45f6
commit bb3d1cf11d
2 changed files with 40 additions and 4 deletions

View File

@@ -23,10 +23,8 @@ import android.graphics.drawable.Drawable;
import android.service.notification.StatusBarNotification;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.accessibility.AccessibilityEvent;
import android.widget.ImageView;
import com.android.systemui.R;

View File

@@ -27,11 +27,11 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.android.systemui.R;
/**
@@ -60,6 +60,16 @@ public class NotificationContentView extends FrameLayout {
private boolean mDark;
private final Paint mFadePaint = new Paint();
private boolean mAnimate;
private ViewTreeObserver.OnPreDrawListener mEnableAnimationPredrawListener
= new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mAnimate = true;
getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
};
public NotificationContentView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -73,6 +83,12 @@ public class NotificationContentView extends FrameLayout {
updateClipping();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
updateVisibility();
}
public void reset() {
if (mContractedChild != null) {
mContractedChild.animate().cancel();
@@ -117,9 +133,31 @@ public class NotificationContentView extends FrameLayout {
selectLayout(false /* animate */, true /* force */);
}
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
updateVisibility();
}
private void updateVisibility() {
setVisible(isShown());
}
private void setVisible(final boolean isVisible) {
if (isVisible) {
// We only animate if we are drawn at least once, otherwise the view might animate when
// it's shown the first time
getViewTreeObserver().addOnPreDrawListener(mEnableAnimationPredrawListener);
} else {
getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener);
mAnimate = false;
}
}
public void setActualHeight(int actualHeight) {
mActualHeight = actualHeight;
selectLayout(true /* animate */, false /* force */);
selectLayout(mAnimate /* animate */, false /* force */);
updateClipping();
}