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

Commit 5be6f339 authored by Selim Cinek's avatar Selim Cinek
Browse files

Modified the interpolators when opening an ambient notification

Change-Id: Ie24468be028fd7c894840e3d1fbf42717ad387a4
Test: add low-priority notification and expand
Bug: 34469375
parent 3416cc28
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;

import com.android.systemui.Interpolators;
import com.android.systemui.R;
@@ -298,5 +299,14 @@ public class ViewTransformationHelper implements TransformableView {
                TransformState otherState) {
            return false;
        }

        /**
         * Get a custom interpolator for this animation
         * @param interpolationType the type of the interpolation, i.e TranslationX / TranslationY
         * @param isFrom true if this transformation from the other view
         */
        public Interpolator getCustomInterpolator(int interpolationType, boolean isFrom) {
            return null;
        }
    }
}
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.notification;

import android.view.View;
import android.view.animation.Interpolator;

import com.android.systemui.Interpolators;
import com.android.systemui.statusbar.CrossFadeHelper;
import com.android.systemui.statusbar.TransformableView;
import com.android.systemui.statusbar.ViewTransformationHelper;

import static com.android.systemui.statusbar.TransformableView.TRANSFORMING_VIEW_TITLE;
import static com.android.systemui.statusbar.notification.TransformState.TRANSFORM_Y;

/**
 * A custom transformation that modifies the interpolator
 */
public abstract class CustomInterpolatorTransformation
        extends ViewTransformationHelper.CustomTransformation {

    private final int mViewType;

    public CustomInterpolatorTransformation(int viewType) {
        mViewType = viewType;
    }

    @Override
    public boolean transformTo(TransformState ownState, TransformableView notification,
            float transformationAmount) {
        if (!hasCustomTransformation()) {
            return false;
        }
        TransformState otherState = notification.getCurrentState(mViewType);
        if (otherState == null) {
            return false;
        }
        View view = ownState.getTransformedView();
        CrossFadeHelper.fadeOut(view, transformationAmount);
        ownState.transformViewFullyTo(otherState, this, transformationAmount);
        otherState.recycle();
        return true;
    }

    protected boolean hasCustomTransformation() {
        return true;
    }

    @Override
    public boolean transformFrom(TransformState ownState,
            TransformableView notification, float transformationAmount) {
        if (!hasCustomTransformation()) {
            return false;
        }
        TransformState otherState = notification.getCurrentState(mViewType);
        if (otherState == null) {
            return false;
        }
        View view = ownState.getTransformedView();
        CrossFadeHelper.fadeIn(view, transformationAmount);
        ownState.transformViewFullyFrom(otherState, this, transformationAmount);
        otherState.recycle();
        return true;
    }
}
+34 −1
Original line number Diff line number Diff line
@@ -31,9 +31,12 @@ import android.util.ArraySet;
import android.view.NotificationHeaderView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.ViewInvertHelper;
import com.android.systemui.statusbar.ExpandableNotificationRow;
@@ -43,17 +46,21 @@ import com.android.systemui.statusbar.phone.NotificationPanelView;

import java.util.Stack;

import static com.android.systemui.statusbar.notification.TransformState.TRANSFORM_Y;

/**
 * Wraps a notification header view.
 */
public class NotificationHeaderViewWrapper extends NotificationViewWrapper {

    private static final Interpolator LOW_PRIORITY_HEADER_CLOSE
            = new PathInterpolator(0.4f, 0f, 0.7f, 1f);
    private final PorterDuffColorFilter mIconColorFilter = new PorterDuffColorFilter(
            0, PorterDuff.Mode.SRC_ATOP);
    private final int mIconDarkAlpha;
    private final int mIconDarkColor = 0xffffffff;
    protected final ViewInvertHelper mInvertHelper;

    protected final ViewInvertHelper mInvertHelper;
    protected final ViewTransformationHelper mTransformationHelper;

    protected int mColor;
@@ -70,6 +77,32 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper {
        mIconDarkAlpha = ctx.getResources().getInteger(R.integer.doze_small_icon_alpha);
        mInvertHelper = new ViewInvertHelper(ctx, NotificationPanelView.DOZE_ANIMATION_DURATION);
        mTransformationHelper = new ViewTransformationHelper();

        // we want to avoid that the header clashes with the other text when transforming
        // low-priority
        mTransformationHelper.setCustomTransformation(
                new CustomInterpolatorTransformation(TRANSFORMING_VIEW_TITLE) {

                    @Override
                    public Interpolator getCustomInterpolator(int interpolationType,
                            boolean isFrom) {
                        boolean isLowPriority = mView instanceof NotificationHeaderView;
                        if (interpolationType == TRANSFORM_Y) {
                            if (isLowPriority && !isFrom
                                    || !isLowPriority && isFrom) {
                                return Interpolators.LINEAR_OUT_SLOW_IN;
                            } else {
                                return LOW_PRIORITY_HEADER_CLOSE;
                            }
                        }
                        return null;
                    }

                    @Override
                    protected boolean hasCustomTransformation() {
                        return mIsLowPriority;
                    }
                }, TRANSFORMING_VIEW_TITLE);
        resolveHeaderViews();
        updateInvertHelper();
    }
+67 −24
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@ package com.android.systemui.statusbar.notification;

import android.util.ArraySet;
import android.util.Pools;
import android.view.NotificationHeaderView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -38,10 +38,11 @@ import com.android.systemui.statusbar.ViewTransformationHelper;
*/
public class TransformState {

    public static final int TRANSFORM_X = 0x1;
    public static final int TRANSFORM_Y = 0x10;
    public static final int TRANSFORM_ALL = TRANSFORM_X | TRANSFORM_Y;

    private static final float UNDEFINED = -1f;
    private static final int TRANSOFORM_X = 0x1;
    private static final int TRANSOFORM_Y = 0x10;
    private static final int TRANSOFORM_ALL = TRANSOFORM_X | TRANSOFORM_Y;
    private static final int CLIP_CLIPPING_SET = R.id.clip_children_set_tag;
    private static final int CLIP_CHILDREN_TAG = R.id.clip_children_tag;
    private static final int CLIP_TO_PADDING = R.id.clip_to_padding_tag;
@@ -80,25 +81,31 @@ public class TransformState {
    }

    public void transformViewFullyFrom(TransformState otherState, float transformationAmount) {
        transformViewFrom(otherState, TRANSOFORM_ALL, null, transformationAmount);
        transformViewFrom(otherState, TRANSFORM_ALL, null, transformationAmount);
    }

    public void transformViewFullyFrom(TransformState otherState,
            ViewTransformationHelper.CustomTransformation customTransformation,
            float transformationAmount) {
        transformViewFrom(otherState, TRANSFORM_ALL, customTransformation, transformationAmount);
    }

    public void transformViewVerticalFrom(TransformState otherState,
            ViewTransformationHelper.CustomTransformation customTransformation,
            float transformationAmount) {
        transformViewFrom(otherState, TRANSOFORM_Y, customTransformation, transformationAmount);
        transformViewFrom(otherState, TRANSFORM_Y, customTransformation, transformationAmount);
    }

    public void transformViewVerticalFrom(TransformState otherState, float transformationAmount) {
        transformViewFrom(otherState, TRANSOFORM_Y, null, transformationAmount);
        transformViewFrom(otherState, TRANSFORM_Y, null, transformationAmount);
    }

    private void transformViewFrom(TransformState otherState, int transformationFlags,
            ViewTransformationHelper.CustomTransformation customTransformation,
            float transformationAmount) {
        final View transformedView = mTransformedView;
        boolean transformX = (transformationFlags & TRANSOFORM_X) != 0;
        boolean transformY = (transformationFlags & TRANSOFORM_Y) != 0;
        boolean transformX = (transformationFlags & TRANSFORM_X) != 0;
        boolean transformY = (transformationFlags & TRANSFORM_Y) != 0;
        boolean transformScale = transformScale();
        // lets animate the positions correctly
        if (transformationAmount == 0.0f
@@ -153,14 +160,30 @@ public class TransformState {
        float interpolatedValue = Interpolators.FAST_OUT_SLOW_IN.getInterpolation(
                transformationAmount);
        if (transformX) {
            float interpolation = interpolatedValue;
            if (customTransformation != null) {
                Interpolator customInterpolator =
                        customTransformation.getCustomInterpolator(TRANSFORM_X, true /* isFrom */);
                if (customInterpolator != null) {
                    interpolation = customInterpolator.getInterpolation(transformationAmount);
                }
            }
            transformedView.setTranslationX(NotificationUtils.interpolate(getTransformationStartX(),
                    0.0f,
                    interpolatedValue));
                    interpolation));
        }
        if (transformY) {
            float interpolation = interpolatedValue;
            if (customTransformation != null) {
                Interpolator customInterpolator =
                        customTransformation.getCustomInterpolator(TRANSFORM_Y, true /* isFrom */);
                if (customInterpolator != null) {
                    interpolation = customInterpolator.getInterpolation(transformationAmount);
                }
            }
            transformedView.setTranslationY(NotificationUtils.interpolate(getTransformationStartY(),
                    0.0f,
                    interpolatedValue));
                    interpolation));
        }
        if (transformScale) {
            float transformationStartScaleX = getTransformationStartScaleX();
@@ -207,17 +230,23 @@ public class TransformState {
    }

    public void transformViewFullyTo(TransformState otherState, float transformationAmount) {
        transformViewTo(otherState, TRANSOFORM_ALL, null, transformationAmount);
        transformViewTo(otherState, TRANSFORM_ALL, null, transformationAmount);
    }

    public void transformViewFullyTo(TransformState otherState,
            ViewTransformationHelper.CustomTransformation customTransformation,
            float transformationAmount) {
        transformViewTo(otherState, TRANSFORM_ALL, customTransformation, transformationAmount);
    }

    public void transformViewVerticalTo(TransformState otherState,
            ViewTransformationHelper.CustomTransformation customTransformation,
            float transformationAmount) {
        transformViewTo(otherState, TRANSOFORM_Y, customTransformation, transformationAmount);
        transformViewTo(otherState, TRANSFORM_Y, customTransformation, transformationAmount);
    }

    public void transformViewVerticalTo(TransformState otherState, float transformationAmount) {
        transformViewTo(otherState, TRANSOFORM_Y, null, transformationAmount);
        transformViewTo(otherState, TRANSFORM_Y, null, transformationAmount);
    }

    private void transformViewTo(TransformState otherState, int transformationFlags,
@@ -226,8 +255,8 @@ public class TransformState {
        // lets animate the positions correctly

        final View transformedView = mTransformedView;
        boolean transformX = (transformationFlags & TRANSOFORM_X) != 0;
        boolean transformY = (transformationFlags & TRANSOFORM_Y) != 0;
        boolean transformX = (transformationFlags & TRANSFORM_X) != 0;
        boolean transformY = (transformationFlags & TRANSFORM_Y) != 0;
        boolean transformScale = transformScale();
        // lets animate the positions correctly
        if (transformationAmount == 0.0f) {
@@ -264,23 +293,37 @@ public class TransformState {
        int[] ownPosition = getLaidOutLocationOnScreen();
        if (transformX) {
            float endX = otherStablePosition[0] - ownPosition[0];
            if (customTransformation != null
                    && customTransformation.customTransformTarget(this, otherState)) {
            float interpolation = interpolatedValue;
            if (customTransformation != null) {
                if (customTransformation.customTransformTarget(this, otherState)) {
                    endX = mTransformationEndX;
                }
                Interpolator customInterpolator =
                        customTransformation.getCustomInterpolator(TRANSFORM_X, false /* isFrom */);
                if (customInterpolator != null) {
                    interpolation = customInterpolator.getInterpolation(transformationAmount);
                }
            }
            transformedView.setTranslationX(NotificationUtils.interpolate(getTransformationStartX(),
                    endX,
                    interpolatedValue));
                    interpolation));
        }
        if (transformY) {
            float endY = otherStablePosition[1] - ownPosition[1];
            if (customTransformation != null
                    && customTransformation.customTransformTarget(this, otherState)) {
            float interpolation = interpolatedValue;
            if (customTransformation != null) {
                if (customTransformation.customTransformTarget(this, otherState)) {
                    endY = mTransformationEndY;
                }
                Interpolator customInterpolator =
                        customTransformation.getCustomInterpolator(TRANSFORM_Y, false /* isFrom */);
                if (customInterpolator != null) {
                    interpolation = customInterpolator.getInterpolation(transformationAmount);
                }
            }
            transformedView.setTranslationY(NotificationUtils.interpolate(getTransformationStartY(),
                    endY,
                    interpolatedValue));
                    interpolation));
        }
        if (transformScale) {
            View otherView = otherState.getTransformedView();