Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cfbef45 authored by Selim Cinek's avatar Selim Cinek
Browse files

Refactored the stack animation logic

Animations are now also applicable to normal views
and are more modularly applied to specific stack
view states.

Test: Add notifications, observe animations
Bug: 32437839
Change-Id: I75ebf98657749b50d43c88c4c39c5d4c302b1280
parent c383fd05
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.systemui.R;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.statusbar.notification.FakeShadowView;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.stack.ExpandableViewState;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.stack.StackStateAnimator;

+22 −7
Original line number Diff line number Diff line
@@ -51,11 +51,11 @@ import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.statusbar.notification.HybridNotificationView;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.stack.AnimationProperties;
import com.android.systemui.statusbar.stack.ExpandableViewState;
import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.stack.StackScrollState;
import com.android.systemui.statusbar.stack.StackStateAnimator;
import com.android.systemui.statusbar.stack.ExpandableViewState;

import java.util.ArrayList;
import java.util.List;
@@ -485,11 +485,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        }
    }

    public void startChildAnimation(StackScrollState finalState,
            StackStateAnimator stateAnimator, long delay, long duration) {
    public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
        if (mIsSummaryWithChildren) {
            mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay,
                    duration);
            mChildrenContainer.startAnimationToState(finalState, properties);
        }
    }

@@ -1762,7 +1760,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        return new NotificationViewState(stackScrollState);
    }

    public static class NotificationViewState extends ExpandableViewState {
    public class NotificationViewState extends ExpandableViewState {

        private final StackScrollState mOverallState;

@@ -1782,5 +1780,22 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
                row.applyChildrenState(mOverallState);
            }
        }

        @Override
        protected void onYTranslationAnimationFinished() {
            super.onYTranslationAnimationFinished();
            if (mHeadsupDisappearRunning) {
                setHeadsupDisappearRunning(false);
            }
        }

        @Override
        public void animateTo(View child, AnimationProperties properties) {
            super.animateTo(child, properties);
            if (child instanceof ExpandableNotificationRow) {
                ExpandableNotificationRow row = (ExpandableNotificationRow) child;
                row.startChildAnimation(mOverallState, properties);
            }
        }
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.phone.NotificationIconContainer;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.stack.AmbientState;
import com.android.systemui.statusbar.stack.AnimationProperties;
import com.android.systemui.statusbar.stack.ExpandableViewState;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.stack.StackScrollAlgorithm;
@@ -300,5 +301,12 @@ public class NotificationShelf extends ActivatableNotificationView {
            updateAppearance();
            setIconContainerTranslation(iconContainerTranslation);
        }

        @Override
        public void animateTo(View child, AnimationProperties properties) {
            super.animateTo(child, properties);
            updateAppearance();
            setIconContainerTranslation(iconContainerTranslation);
        }
    }
}
+5 −8
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.support.v4.graphics.ColorUtils;
import android.view.View;
@@ -37,7 +36,7 @@ import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationData;
import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.stack.StackStateAnimator;
import com.android.systemui.statusbar.stack.ViewState;

/**
 * Controls both the scrim behind the notifications and in front of the notifications (when a
@@ -478,14 +477,14 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
            return;
        }

        ValueAnimator previousAnimator = StackStateAnimator.getChildTag(scrim,
        ValueAnimator previousAnimator = ViewState.getChildTag(scrim,
                TAG_KEY_ANIM);
        float animEndValue = -1;
        if (previousAnimator != null) {
            if (animate || alpha == currentAlpha) {
                previousAnimator.cancel();
            } else {
                animEndValue = StackStateAnimator.getChildTag(scrim, TAG_END_ALPHA);
                animEndValue = ViewState.getChildTag(scrim, TAG_END_ALPHA);
            }
        }
        if (alpha != currentAlpha && alpha != animEndValue) {
@@ -495,10 +494,8 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
                scrim.setTag(TAG_END_ALPHA, alpha);
            } else {
                if (previousAnimator != null) {
                    float previousStartValue = StackStateAnimator.getChildTag(scrim,
                            TAG_START_ALPHA);
                    float previousEndValue = StackStateAnimator.getChildTag(scrim,
                            TAG_END_ALPHA);
                    float previousStartValue = ViewState.getChildTag(scrim, TAG_START_ALPHA);
                    float previousEndValue = ViewState.getChildTag(scrim, TAG_END_ALPHA);
                    // we need to increase all animation keyframes of the previous animator by the
                    // relative change to the end value
                    PropertyValuesHolder[] values = previousAnimator.getValues();
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.statusbar.stack;

import android.animation.AnimatorListenerAdapter;
import android.util.Property;
import android.view.View;
import android.view.animation.Interpolator;

/**
 * Properties for a View animation
 */
public class AnimationProperties {
    public long duration;
    public long delay;

    /**
     * @return an animation filter for this animation.
     */
    public AnimationFilter getAnimationFilter() {
        return null;
    }

    /**
     * @return a listener that should be run whenever any property finished its animation
     */
    public AnimatorListenerAdapter getAnimationFinishListener() {
        return null;
    }

    public boolean wasAdded(View view) {
        return false;
    }

    /**
     * Get a custom interpolator for a property instead of the normal one.
     */
    public Interpolator getCustomInterpolator(View child, Property translationY) {
        return null;
    }
}
Loading