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

Commit 9e76f682 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing wrapper around ViewPropertyAnimator, and using ObjectAnimator

instead

Bug: 35218222
Change-Id: Ic714cf7d20989cb45f07712e8a6f6659d0e3f30d
parent eb04b841
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate;
import com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate;
import com.android.launcher3.accessibility.FolderAccessibilityHelper;
import com.android.launcher3.accessibility.FolderAccessibilityHelper;
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.graphics.DragPreviewProvider;
@@ -2097,11 +2098,12 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
            }
            }


            setInitialAnimationValues(true);
            setInitialAnimationValues(true);
            a = new LauncherViewPropertyAnimator(child)
            a = LauncherAnimUtils.ofPropertyValuesHolder(child,
                .scaleX(initScale)
                    new PropertyListBuilder()
                .scaleY(initScale)
                            .scale(initScale)
                            .translationX(initDeltaX)
                            .translationX(initDeltaX)
                            .translationY(initDeltaY)
                            .translationY(initDeltaY)
                            .build())
                    .setDuration(REORDER_ANIMATION_DURATION);
                    .setDuration(REORDER_ANIMATION_DURATION);
            a.setInterpolator(new android.view.animation.DecelerateInterpolator(1.5f));
            a.setInterpolator(new android.view.animation.DecelerateInterpolator(1.5f));
            a.start();
            a.start();
+0 −275
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2012 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.launcher3;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.TimeInterpolator;
import android.view.View;
import android.view.ViewPropertyAnimator;

import java.util.ArrayList;
import java.util.EnumSet;

public class LauncherViewPropertyAnimator extends Animator implements AnimatorListener {

    enum Properties {
            TRANSLATION_X,
            TRANSLATION_Y,
            SCALE_X,
            SCALE_Y,
            ROTATION_Y,
            ALPHA,
            START_DELAY,
            DURATION,
            INTERPOLATOR,
            WITH_LAYER
    }
    EnumSet<Properties> mPropertiesToSet = EnumSet.noneOf(Properties.class);
    ViewPropertyAnimator mViewPropertyAnimator;
    View mTarget;

    float mTranslationX;
    float mTranslationY;
    float mScaleX;
    float mScaleY;
    float mRotationY;
    float mAlpha;
    long mStartDelay;
    long mDuration;
    TimeInterpolator mInterpolator;
    ArrayList<Animator.AnimatorListener> mListeners = new ArrayList<>();
    boolean mRunning = false;
    FirstFrameAnimatorHelper mFirstFrameHelper;

    public LauncherViewPropertyAnimator(View target) {
        mTarget = target;
    }

    @Override
    public void addListener(Animator.AnimatorListener listener) {
        mListeners.add(listener);
    }

    @Override
    public void cancel() {
        if (mViewPropertyAnimator != null) {
            mViewPropertyAnimator.cancel();
        }
    }

    @Override
    public Animator clone() {
        throw new RuntimeException("Not implemented");
    }

    @Override
    public void end() {
        throw new RuntimeException("Not implemented");
    }

    @Override
    public long getDuration() {
        return mDuration;
    }

    @Override
    public ArrayList<Animator.AnimatorListener> getListeners() {
        return mListeners;
    }

    @Override
    public long getStartDelay() {
        return mStartDelay;
    }

    @Override
    public void onAnimationCancel(Animator animation) {
        for (int i = 0; i < mListeners.size(); i++) {
            Animator.AnimatorListener listener = mListeners.get(i);
            listener.onAnimationCancel(this);
        }
        mRunning = false;
    }

    @Override
    public void onAnimationEnd(Animator animation) {
        for (int i = 0; i < mListeners.size(); i++) {
            Animator.AnimatorListener listener = mListeners.get(i);
            listener.onAnimationEnd(this);
        }
        mRunning = false;
    }

    @Override
    public void onAnimationRepeat(Animator animation) {
        for (int i = 0; i < mListeners.size(); i++) {
            Animator.AnimatorListener listener = mListeners.get(i);
            listener.onAnimationRepeat(this);
        }
    }

    @Override
    public void onAnimationStart(Animator animation) {
        // This is the first time we get a handle to the internal ValueAnimator
        // used by the ViewPropertyAnimator.
        mFirstFrameHelper.onAnimationStart(animation);

        for (int i = 0; i < mListeners.size(); i++) {
            Animator.AnimatorListener listener = mListeners.get(i);
            listener.onAnimationStart(this);
        }
        mRunning = true;
    }

    @Override
    public boolean isRunning() {
        return mRunning;
    }

    @Override
    public boolean isStarted() {
        return mViewPropertyAnimator != null;
    }

    @Override
    public void removeAllListeners() {
        mListeners.clear();
    }

    @Override
    public void removeListener(Animator.AnimatorListener listener) {
        mListeners.remove(listener);
    }

    @Override
    public Animator setDuration(long duration) {
        mPropertiesToSet.add(Properties.DURATION);
        mDuration = duration;
        return this;
    }

    @Override
    public void setInterpolator(TimeInterpolator value) {
        mPropertiesToSet.add(Properties.INTERPOLATOR);
        mInterpolator = value;
    }

    @Override
    public void setStartDelay(long startDelay) {
        mPropertiesToSet.add(Properties.START_DELAY);
        mStartDelay = startDelay;
    }

    @Override
    public void setTarget(Object target) {
        throw new RuntimeException("Not implemented");
    }

    @Override
    public void setupEndValues() {

    }

    @Override
    public void setupStartValues() {
    }

    @Override
    public void start() {
        mViewPropertyAnimator = mTarget.animate();

        // FirstFrameAnimatorHelper hooks itself up to the updates on the animator,
        // and then adjusts the play time to keep the first two frames jank-free
        mFirstFrameHelper = new FirstFrameAnimatorHelper(mViewPropertyAnimator, mTarget);

        if (mPropertiesToSet.contains(Properties.TRANSLATION_X)) {
            mViewPropertyAnimator.translationX(mTranslationX);
        }
        if (mPropertiesToSet.contains(Properties.TRANSLATION_Y)) {
            mViewPropertyAnimator.translationY(mTranslationY);
        }
        if (mPropertiesToSet.contains(Properties.SCALE_X)) {
            mViewPropertyAnimator.scaleX(mScaleX);
        }
        if (mPropertiesToSet.contains(Properties.ROTATION_Y)) {
            mViewPropertyAnimator.rotationY(mRotationY);
        }
        if (mPropertiesToSet.contains(Properties.SCALE_Y)) {
            mViewPropertyAnimator.scaleY(mScaleY);
        }
        if (mPropertiesToSet.contains(Properties.ALPHA)) {
            mViewPropertyAnimator.alpha(mAlpha);
        }
        if (mPropertiesToSet.contains(Properties.START_DELAY)) {
            mViewPropertyAnimator.setStartDelay(mStartDelay);
        }
        if (mPropertiesToSet.contains(Properties.DURATION)) {
            mViewPropertyAnimator.setDuration(mDuration);
        }
        if (mPropertiesToSet.contains(Properties.INTERPOLATOR)) {
            mViewPropertyAnimator.setInterpolator(mInterpolator);
        }
        if (mPropertiesToSet.contains(Properties.WITH_LAYER)) {
            mViewPropertyAnimator.withLayer();
        }
        mViewPropertyAnimator.setListener(this);
        mViewPropertyAnimator.start();
        LauncherAnimUtils.cancelOnDestroyActivity(this);
    }

    public LauncherViewPropertyAnimator translationX(float value) {
        mPropertiesToSet.add(Properties.TRANSLATION_X);
        mTranslationX = value;
        return this;
    }

    public LauncherViewPropertyAnimator translationY(float value) {
        mPropertiesToSet.add(Properties.TRANSLATION_Y);
        mTranslationY = value;
        return this;
    }

    public LauncherViewPropertyAnimator scaleX(float value) {
        mPropertiesToSet.add(Properties.SCALE_X);
        mScaleX = value;
        return this;
    }

    public LauncherViewPropertyAnimator scaleY(float value) {
        mPropertiesToSet.add(Properties.SCALE_Y);
        mScaleY = value;
        return this;
    }

    public LauncherViewPropertyAnimator rotationY(float value) {
        mPropertiesToSet.add(Properties.ROTATION_Y);
        mRotationY = value;
        return this;
    }

    public LauncherViewPropertyAnimator alpha(float value) {
        mPropertiesToSet.add(Properties.ALPHA);
        mAlpha = value;
        return this;
    }

    public LauncherViewPropertyAnimator withLayer() {
        mPropertiesToSet.add(Properties.WITH_LAYER);
        return this;
    }
}
+7 −5
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.Interpolator;
import android.view.animation.Interpolator;


import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.util.LauncherEdgeEffect;
import com.android.launcher3.util.LauncherEdgeEffect;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.Thunk;
@@ -1998,11 +1999,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
    // Animate the drag view back to the original position
    // Animate the drag view back to the original position
    private void animateDragViewToOriginalPosition() {
    private void animateDragViewToOriginalPosition() {
        if (mDragView != null) {
        if (mDragView != null) {
            Animator anim = new LauncherViewPropertyAnimator(mDragView)
            Animator anim = LauncherAnimUtils.ofPropertyValuesHolder(mDragView,
                    new PropertyListBuilder()
                            .scale(1)
                            .translationX(0)
                            .translationX(0)
                            .translationY(0)
                            .translationY(0)
                    .scaleX(1)
                            .build())
                    .scaleY(1)
                    .setDuration(REORDERING_DROP_REPOSITION_DURATION);
                    .setDuration(REORDERING_DROP_REPOSITION_DURATION);
            anim.addListener(new AnimatorListenerAdapter() {
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                @Override
+3 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.view.animation.LinearInterpolator;


import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;


@@ -211,7 +212,8 @@ public class PinchAnimationManager {
    }
    }


    private void animateShowHideView(int index, final View view, boolean show) {
    private void animateShowHideView(int index, final View view, boolean show) {
        Animator animator = new LauncherViewPropertyAnimator(view).alpha(show ? 1 : 0).withLayer();
        Animator animator = ObjectAnimator.ofFloat(view, View.ALPHA, show ? 1 : 0);
        animator.addListener(new AnimationLayerSet(view));
        if (show) {
        if (show) {
            view.setVisibility(View.VISIBLE);
            view.setVisibility(View.VISIBLE);
        } else {
        } else {
+11 −12
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;


import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.Thunk;
@@ -337,10 +338,9 @@ public class WorkspaceStateTransitionAnimation {
            if (animated) {
            if (animated) {
                float oldBackgroundAlpha = cl.getBackgroundAlpha();
                float oldBackgroundAlpha = cl.getBackgroundAlpha();
                if (initialAlpha != finalAlpha) {
                if (initialAlpha != finalAlpha) {
                    LauncherViewPropertyAnimator alphaAnim =
                    Animator alphaAnim = ObjectAnimator.ofFloat(
                            new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets());
                            cl.getShortcutsAndWidgets(), View.ALPHA, finalAlpha);
                    alphaAnim.alpha(finalAlpha)
                    alphaAnim.setDuration(duration)
                            .setDuration(duration)
                            .setInterpolator(mZoomInInterpolator);
                            .setInterpolator(mZoomInInterpolator);
                    mStateAnimator.play(alphaAnim);
                    mStateAnimator.play(alphaAnim);
                }
                }
@@ -377,17 +377,16 @@ public class WorkspaceStateTransitionAnimation {
                .animateAlphaAtIndex(finalQsbAlpha, Workspace.QSB_ALPHA_INDEX_STATE_CHANGE);
                .animateAlphaAtIndex(finalQsbAlpha, Workspace.QSB_ALPHA_INDEX_STATE_CHANGE);


        if (animated) {
        if (animated) {
            LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(mWorkspace);
            Animator scale = LauncherAnimUtils.ofPropertyValuesHolder(mWorkspace,
            scale.scaleX(mNewScale)
                    new PropertyListBuilder().scale(mNewScale)
                    .scaleY(mNewScale)
                            .translationY(finalWorkspaceTranslationY).build())
                    .translationY(finalWorkspaceTranslationY)
                    .setDuration(duration);
                    .setDuration(duration)
            scale.setInterpolator(mZoomInInterpolator);
                    .setInterpolator(mZoomInInterpolator);
            mStateAnimator.play(scale);
            mStateAnimator.play(scale);
            Animator hotseatAlpha = mWorkspace.createHotseatAlphaAnimator(finalHotseatAlpha);
            Animator hotseatAlpha = mWorkspace.createHotseatAlphaAnimator(finalHotseatAlpha);


            LauncherViewPropertyAnimator overviewPanelAlpha =
            Animator overviewPanelAlpha = ObjectAnimator.ofFloat(
                    new LauncherViewPropertyAnimator(overviewPanel).alpha(finalOverviewPanelAlpha);
                    overviewPanel, View.ALPHA, finalOverviewPanelAlpha);
            overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel,
            overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel,
                    accessibilityEnabled));
                    accessibilityEnabled));


Loading