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

Commit 92fd7754 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge "Use separate thread if app doesn't listen to animations" into rvc-dev

parents aa22f3e0 6d5c801c
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.animation;

import android.annotation.CallSuper;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
@@ -268,6 +269,11 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
     */
    private float mDurationScale = -1f;

    /**
     * Animation handler used to schedule updates for this animation.
     */
    private AnimationHandler mAnimationHandler;

    /**
     * Public constants
     */
@@ -1684,6 +1690,15 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio
     * @hide
     */
    public AnimationHandler getAnimationHandler() {
        return AnimationHandler.getInstance();
        return mAnimationHandler != null ? mAnimationHandler : AnimationHandler.getInstance();
    }

    /**
     * Sets the animation handler used to schedule updates for this animator or {@code null} to use
     * the default handler.
     * @hide
     */
    public void setAnimationHandler(@Nullable AnimationHandler animationHandler) {
        mAnimationHandler = animationHandler;
    }
}
+3 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.view;

import android.view.InsetsController.LayoutInsetsDuringAnimation;
import android.view.WindowInsetsAnimation.Bounds;

/**
@@ -37,7 +36,7 @@ public interface InsetsAnimationControlCallbacks {
    void startAnimation(InsetsAnimationControlImpl controller,
            WindowInsetsAnimationControlListener listener, int types,
            WindowInsetsAnimation animation,
            Bounds bounds, @LayoutInsetsDuringAnimation int layoutDuringAnimation);
            Bounds bounds);

    /**
     * Schedule the apply by posting the animation callback.
@@ -46,10 +45,10 @@ public interface InsetsAnimationControlCallbacks {

    /**
     * Finish the final steps after the animation.
     * @param controller The controller used to control the animation.
     * @param runner The runner used to run the animation.
     * @param shown {@code true} if the insets are shown.
     */
    void notifyFinished(InsetsAnimationControlImpl controller, boolean shown);
    void notifyFinished(InsetsAnimationControlRunner runner, boolean shown);

    /**
     * Apply the new params to the surface.
+14 −13
Original line number Diff line number Diff line
@@ -31,9 +31,7 @@ import android.util.ArraySet;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.SparseSetArray;
import android.view.InsetsController.LayoutInsetsDuringAnimation;
import android.view.InsetsState.InternalInsetsSide;
import android.view.InsetsState.InternalInsetsType;
import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsAnimation.Bounds;
@@ -49,7 +47,8 @@ import java.util.ArrayList;
 * @hide
 */
@VisibleForTesting
public class InsetsAnimationControlImpl implements WindowInsetsAnimationController  {
public class InsetsAnimationControlImpl implements WindowInsetsAnimationController,
        InsetsAnimationControlRunner {

    private final Rect mTmpFrame = new Rect();

@@ -84,8 +83,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
            InsetsState state, WindowInsetsAnimationControlListener listener,
            @InsetsType int types,
            InsetsAnimationControlCallbacks controller, long durationMs, Interpolator interpolator,
            boolean fade, @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation,
            @AnimationType int animationType) {
            boolean fade, @AnimationType int animationType) {
        mControls = controls;
        mListener = listener;
        mTypes = types;
@@ -105,7 +103,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        mAnimation.setAlpha(getCurrentAlpha());
        mAnimationType = animationType;
        mController.startAnimation(this, listener, types, mAnimation,
                new Bounds(mHiddenInsets, mShownInsets), layoutInsetsDuringAnimation);
                new Bounds(mHiddenInsets, mShownInsets));
    }

    @Override
@@ -133,11 +131,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        return mTypes;
    }

    boolean controlsInternalType(@InternalInsetsType int type) {
        return InsetsState.toInternalType(mTypes).contains(type);
    }

    @AnimationType int getAnimationType() {
    @Override
    public @AnimationType int getAnimationType() {
        return mAnimationType;
    }

@@ -205,7 +200,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        return mAnimation.getFraction();
    }

    public void onCancelled() {
    @Override
    public void cancel() {
        if (mFinished) {
            return;
        }
@@ -217,7 +213,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        return mCancelled;
    }

    WindowInsetsAnimation getAnimation() {
    @Override
    public WindowInsetsAnimation getAnimation() {
        return mAnimation;
    }

@@ -225,6 +222,10 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        return mListener;
    }

    SparseArray<InsetsSourceControl> getControls() {
        return mControls;
    }

    private Insets calculateInsets(InsetsState state, Rect frame,
            SparseArray<InsetsSourceControl> controls, boolean shown,
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 android.view;

import android.view.InsetsController.AnimationType;
import android.view.InsetsState.InternalInsetsType;
import android.view.WindowInsets.Type.InsetsType;

/**
 * Interface representing a runner for an insets animation.
 *
 * @hide
 */
public interface InsetsAnimationControlRunner {

    /**
     * @return The {@link InsetsType} the animation of this runner is controlling.
     */
    @InsetsType int getTypes();

    /**
     * Cancels the animation.
     */
    void cancel();

    /**
     * @return The animation this runner is running.
     */
    WindowInsetsAnimation getAnimation();

    /**
     * @return Whether {@link #getTypes()} maps to a specific {@link InternalInsetsType}.
     */
    default boolean controlsInternalType(@InternalInsetsType int type) {
        return InsetsState.toInternalType(getTypes()).contains(type);
    }

    /**
     * @return The animation type this runner is running.
     */
    @AnimationType int getAnimationType();
}
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 android.view;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Trace;

/**
 * Thread to be used for inset animations to be running off the main thread.
 * @hide
 */
public class InsetsAnimationThread extends HandlerThread {

    private static InsetsAnimationThread sInstance;
    private static Handler sHandler;

    private InsetsAnimationThread() {
        // TODO: Should this use higher priority?
        super("InsetsAnimations");
    }

    private static void ensureThreadLocked() {
        if (sInstance == null) {
            sInstance = new InsetsAnimationThread();
            sInstance.start();
            sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_VIEW);
            sHandler = new Handler(sInstance.getLooper());
        }
    }

    public static void release() {
        synchronized (InsetsAnimationThread.class) {
            if (sInstance == null) {
                return;
            }
            sInstance.getLooper().quitSafely();
            sInstance = null;
            sHandler = null;
        }
    }

    public static InsetsAnimationThread get() {
        synchronized (InsetsAnimationThread.class) {
            ensureThreadLocked();
            return sInstance;
        }
    }

    public static Handler getHandler() {
        synchronized (InsetsAnimationThread.class) {
            ensureThreadLocked();
            return sHandler;
        }
    }
}
Loading