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

Commit d3e2ba30 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix blink of final position in activity transitions."

parents 00f9a1a4 f9c4b57b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -457,7 +457,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator {
            public void onSharedElementsReady() {
            public void onSharedElementsReady() {
                final View decorView = getDecor();
                final View decorView = getDecor();
                if (decorView != null) {
                if (decorView != null) {
                    OneShotPreDrawListener.add(decorView, () -> {
                    OneShotPreDrawListener.add(decorView, false, () -> {
                        startTransition(() -> {
                        startTransition(() -> {
                                startSharedElementTransition(sharedElementState);
                                startSharedElementTransition(sharedElementState);
                        });
                        });
+21 −6
Original line number Original line Diff line number Diff line
@@ -25,8 +25,6 @@ import android.view.ViewTreeObserver;
 *     OneShotPreDrawListener.add(view, () -> { view.doSomething(); })
 *     OneShotPreDrawListener.add(view, () -> { view.doSomething(); })
 * </code></pre>
 * </code></pre>
 * <p>
 * <p>
 * The onPreDraw always returns true.
 * <p>
 * The listener will also remove itself from the ViewTreeObserver when the view
 * The listener will also remove itself from the ViewTreeObserver when the view
 * is detached from the view hierarchy. In that case, the Runnable will never be
 * is detached from the view hierarchy. In that case, the Runnable will never be
 * executed.
 * executed.
@@ -36,22 +34,39 @@ public class OneShotPreDrawListener implements ViewTreeObserver.OnPreDrawListene
    private final View mView;
    private final View mView;
    private ViewTreeObserver mViewTreeObserver;
    private ViewTreeObserver mViewTreeObserver;
    private final Runnable mRunnable;
    private final Runnable mRunnable;
    private final boolean mReturnValue;


    private OneShotPreDrawListener(View view, Runnable runnable) {
    private OneShotPreDrawListener(View view, boolean returnValue, Runnable runnable) {
        mView = view;
        mView = view;
        mViewTreeObserver = view.getViewTreeObserver();
        mViewTreeObserver = view.getViewTreeObserver();
        mRunnable = runnable;
        mRunnable = runnable;
        mReturnValue = returnValue;
    }
    }


    /**
    /**
     * Creates a OneShotPreDrawListener and adds it to view's ViewTreeObserver.
     * Creates a OneShotPreDrawListener and adds it to view's ViewTreeObserver. The
     * return value from the OnPreDrawListener is {@code true}.
     *
     * @param view The view whose ViewTreeObserver the OnPreDrawListener should listen.
     * @param view The view whose ViewTreeObserver the OnPreDrawListener should listen.
     * @param runnable The Runnable to execute in the OnPreDraw (once)
     * @param runnable The Runnable to execute in the OnPreDraw (once)
     * @return The added OneShotPreDrawListener. It can be removed prior to
     * @return The added OneShotPreDrawListener. It can be removed prior to
     * the onPreDraw by calling {@link #removeListener()}.
     * the onPreDraw by calling {@link #removeListener()}.
     */
     */
    public static OneShotPreDrawListener add(View view, Runnable runnable) {
    public static OneShotPreDrawListener add(View view, Runnable runnable) {
        OneShotPreDrawListener listener = new OneShotPreDrawListener(view, runnable);
        return add(view, true, runnable);
    }

    /**
     * Creates a OneShotPreDrawListener and adds it to view's ViewTreeObserver.
     *
     * @param view The view whose ViewTreeObserver the OnPreDrawListener should listen.
     * @param returnValue The value to be returned from the OnPreDrawListener.
     * @param runnable The Runnable to execute in the OnPreDraw (once)
     * @return The added OneShotPreDrawListener. It can be removed prior to
     * the onPreDraw by calling {@link #removeListener()}.
     */
    public static OneShotPreDrawListener add(View view, boolean returnValue, Runnable runnable) {
        OneShotPreDrawListener listener = new OneShotPreDrawListener(view, returnValue, runnable);
        view.getViewTreeObserver().addOnPreDrawListener(listener);
        view.getViewTreeObserver().addOnPreDrawListener(listener);
        view.addOnAttachStateChangeListener(listener);
        view.addOnAttachStateChangeListener(listener);
        return listener;
        return listener;
@@ -61,7 +76,7 @@ public class OneShotPreDrawListener implements ViewTreeObserver.OnPreDrawListene
    public boolean onPreDraw() {
    public boolean onPreDraw() {
        removeListener();
        removeListener();
        mRunnable.run();
        mRunnable.run();
        return true;
        return mReturnValue;
    }
    }


    /**
    /**