public interface

TransitionSeekController

 androidx.transition.TransitionSeekController

Gradle dependencies

compile group: 'androidx.transition', name: 'transition', version: '1.5.1'

  • groupId: androidx.transition
  • artifactId: transition
  • version: 1.5.1

Artifact androidx.transition:transition:1.5.1 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.transition:transition com.android.support:transition

Overview

Returned from TransitionManager.controlDelayedTransition(ViewGroup, Transition) to allow manually controlling the animations within a Transition using TransitionSeekController.setCurrentPlayTimeMillis(long). The transition will be ready to seek when TransitionSeekController.isReady() is true.

Summary

Methods
public voidaddOnProgressChangedListener(Consumer<TransitionSeekController> consumer)

Add a listener for whenever the progress of the transition is changed.

public voidaddOnReadyListener(Consumer<TransitionSeekController> onReadyListener)

Adds a listener to know when TransitionSeekController.isReady() is true.

public voidanimateToEnd()

Runs the animation forwards toward the end.

public voidanimateToStart(java.lang.Runnable resetToStartState)

Runs the animation backwards toward the start.

public floatgetCurrentFraction()

public longgetCurrentPlayTimeMillis()

public longgetDurationMillis()

public booleanisReady()

Returns true when the Transition is ready to seek or false when the Transition's animations have yet to be built.

public voidremoveOnProgressChangedListener(Consumer<TransitionSeekController> consumer)

Remove a listener previously added in TransitionSeekController.addOnProgressChangedListener(Consumer)

public voidremoveOnReadyListener(Consumer<TransitionSeekController> onReadyListener)

Removes onReadyListener that was previously added in TransitionSeekController.addOnReadyListener(Consumer) so that it won't be called.

public voidsetCurrentFraction(float fraction)

Sets the position of the Transition's animation.

public voidsetCurrentPlayTimeMillis(long playTimeMillis)

Sets the position of the Transition's animation.

Methods

public long getDurationMillis()

Returns:

The total duration, in milliseconds, of the Transition's animations.

public long getCurrentPlayTimeMillis()

Returns:

The time, in milliseconds, of the animation. This will be between 0 and TransitionSeekController.getDurationMillis().

public float getCurrentFraction()

Returns:

The fraction, between 0 and 1, inclusive, of the progress of the transition.

See also: TransitionSeekController.getCurrentPlayTimeMillis()

public boolean isReady()

Returns true when the Transition is ready to seek or false when the Transition's animations have yet to be built.

public void animateToStart(java.lang.Runnable resetToStartState)

Runs the animation backwards toward the start. TransitionSeekController.setCurrentPlayTimeMillis(long) will not be allowed after executing this. When the animation completes, resetToStart will be executed to set the state back to the starting state and Transition.TransitionListener.onTransitionEnd(Transition) will be called with the isReverse parameter true. If resetToStartState does not properly set the state back to starting state, Transition.TransitionListener.onTransitionEnd(Transition) will still be called, but the UI will jump to the end state instead of the start state.

public void animateToEnd()

Runs the animation forwards toward the end. TransitionSeekController.setCurrentPlayTimeMillis(long) will not be allowed after executing this. When the animation completes, Transition.TransitionListener.onTransitionEnd(Transition) will be called with the isReverse parameter false. After the Transition ends, the state will reach the final state set after TransitionManager.controlDelayedTransition(ViewGroup, Transition). After calling this, TransitionSeekController.setCurrentPlayTimeMillis(long) may not be called.

public void setCurrentFraction(float fraction)

Sets the position of the Transition's animation. fraction should be between 0 and 1, inclusive, where 0 indicates that the transition hasn't progressed and 1 indicates that the transition is completed. Calling this before TransitionSeekController.isReady() is true will do nothing.

Parameters:

fraction: The fraction, between 0 and 1, inclusive, of the progress of the transition.

See also: TransitionSeekController.setCurrentPlayTimeMillis(long)

public void setCurrentPlayTimeMillis(long playTimeMillis)

Sets the position of the Transition's animation. playTimeMillis should be between 0 and TransitionSeekController.getDurationMillis(). Calling this before TransitionSeekController.isReady() is true will do nothing.

Parameters:

playTimeMillis: The time, between 0 and TransitionSeekController.getDurationMillis() that the animation should play.

See also: TransitionSeekController.setCurrentFraction(float)

public void addOnReadyListener(Consumer<TransitionSeekController> onReadyListener)

Adds a listener to know when TransitionSeekController.isReady() is true. The listener will be removed once notified as TransitionSeekController.isReady() can only be made true once. If TransitionSeekController.isReady() is already true, then it will be notified immediately.

Parameters:

onReadyListener: The listener to be notified when the Transition is ready.

public void removeOnReadyListener(Consumer<TransitionSeekController> onReadyListener)

Removes onReadyListener that was previously added in TransitionSeekController.addOnReadyListener(Consumer) so that it won't be called.

Parameters:

onReadyListener: The listener to be removed so that it won't be notified when ready.

public void addOnProgressChangedListener(Consumer<TransitionSeekController> consumer)

Add a listener for whenever the progress of the transition is changed. This will be called when TransitionSeekController.setCurrentPlayTimeMillis(long) or TransitionSeekController.setCurrentFraction(float) are called as well as when the animation from TransitionSeekController.animateToEnd() or TransitionSeekController.animateToStart(Runnable) changes the progress.

Parameters:

consumer: A method that accepts this TransitionSeekController.

public void removeOnProgressChangedListener(Consumer<TransitionSeekController> consumer)

Remove a listener previously added in TransitionSeekController.addOnProgressChangedListener(Consumer)

Parameters:

consumer: The listener to be removed.

Source

/*
 * Copyright 2023 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 androidx.transition;

import android.view.ViewGroup;

import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.core.util.Consumer;

/**
 * Returned from {@link TransitionManager#controlDelayedTransition(ViewGroup, Transition)}
 * to allow manually controlling the animations within a Transition using
 * {@link #setCurrentPlayTimeMillis(long)}. The transition will be ready to seek when
 * {@link #isReady()} is {@code true}.
 */
public interface TransitionSeekController {
    /**
     * @return The total duration, in milliseconds, of the Transition's animations.
     */
    @IntRange(from = 0)
    long getDurationMillis();

    /**
     * @return The time, in milliseconds, of the animation. This will be between 0
     * and {@link #getDurationMillis()}.
     */
    @IntRange(from = 0)
    long getCurrentPlayTimeMillis();

    /**
     * @return The fraction, between 0 and 1, inclusive, of the progress of the transition.
     * @see #getCurrentPlayTimeMillis()
     */
    @FloatRange(from = 0.0, to = 1.0)
    float getCurrentFraction();

    /**
     * Returns {@code true} when the Transition is ready to seek or {@code false}
     * when the Transition's animations have yet to be built.
     */
    boolean isReady();

    /**
     * Runs the animation backwards toward the start. {@link #setCurrentPlayTimeMillis(long)}
     * will not be allowed after executing this. When the animation completes,
     * {@code resetToStart} will be executed to set the state back to the starting state and
     * {@link androidx.transition.Transition.TransitionListener#onTransitionEnd(Transition)}
     * will be called with the {@code isReverse} parameter {@code true}.
     *
     * If {@code resetToStartState} does not properly set the state back to starting state,
     * {@link androidx.transition.Transition.TransitionListener#onTransitionEnd(Transition)}
     * will still be called, but the UI will jump to the end state instead of the start state.
     */
    void animateToStart(@NonNull Runnable resetToStartState);

    /**
     * Runs the animation forwards toward the end. {@link #setCurrentPlayTimeMillis(long)}
     * will not be allowed after executing this. When the animation completes,
     * {@link androidx.transition.Transition.TransitionListener#onTransitionEnd(Transition)}
     * will be called with the {@code isReverse} parameter {@code false}.
     *
     * After the Transition ends, the state will reach the final state set after
     * {@link TransitionManager#controlDelayedTransition(ViewGroup, Transition)}.
     *
     * After calling this, {@link #setCurrentPlayTimeMillis(long)} may not be called.
     */
    void animateToEnd();

    /**
     * Sets the position of the Transition's animation. {@code fraction} should be
     * between 0 and 1, inclusive, where 0 indicates that the transition hasn't progressed and 1
     * indicates that the transition is completed. Calling this before {@link #isReady()} is
     * {@code true} will do nothing.
     *
     * @param fraction The fraction, between 0 and 1, inclusive, of the progress of the transition.
     * @see #setCurrentPlayTimeMillis(long)
     */
    void setCurrentFraction(@FloatRange(from = 0.0, to = 1.0) float fraction);

    /**
     * Sets the position of the Transition's animation. {@code playTimeMillis} should be
     * between 0 and {@link #getDurationMillis()}. Calling this before {@link #isReady()} is
     * {@code true} will do nothing.
     *
     * @param playTimeMillis The time, between 0 and {@link #getDurationMillis()} that the
     *                       animation should play.
     * @see #setCurrentFraction(float)
     */
    void setCurrentPlayTimeMillis(@IntRange(from = 0) long playTimeMillis);

    /**
     * Adds a listener to know when {@link #isReady()} is {@code true}. The listener will
     * be removed once notified as {@link #isReady()} can only be made true once. If
     * {@link #isReady()} is already {@code true}, then it will be notified immediately.
     *
     * @param onReadyListener The listener to be notified when the Transition is ready.
     */
    void addOnReadyListener(@NonNull Consumer<TransitionSeekController> onReadyListener);

    /**
     * Removes {@code onReadyListener} that was previously added in
     * {@link #addOnReadyListener(Consumer)} so that it won't be called.
     *
     * @param onReadyListener The listener to be removed so that it won't be notified when ready.
     */
    void removeOnReadyListener(@NonNull Consumer<TransitionSeekController> onReadyListener);

    /**
     * Add a listener for whenever the progress of the transition is changed. This will be called
     * when {@link #setCurrentPlayTimeMillis(long)} or {@link #setCurrentFraction(float)} are
     * called as well as when the animation from {@link #animateToEnd()} or
     * {@link #animateToStart(Runnable)} changes the progress.
     * @param consumer A method that accepts this TransitionSeekController.
     */
    void addOnProgressChangedListener(@NonNull Consumer<TransitionSeekController> consumer);

    /**
     * Remove a listener previously added in {@link #addOnProgressChangedListener(Consumer)}
     * @param consumer The listener to be removed.
     */
    void removeOnProgressChangedListener(@NonNull Consumer<TransitionSeekController> consumer);
}