public abstract class

VisibilityPropagation

extends TransitionPropagation

 java.lang.Object

androidx.transition.TransitionPropagation

↳androidx.transition.VisibilityPropagation

Subclasses:

CircularPropagation, SidePropagation

Gradle dependencies

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

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

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

Androidx artifact mapping:

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

Androidx class mapping:

androidx.transition.VisibilityPropagation android.support.transition.VisibilityPropagation

Overview

Base class for TransitionPropagations that care about View Visibility and the center position of the View.

Summary

Constructors
publicVisibilityPropagation()

Methods
public abstract voidcaptureValues(TransitionValues transitionValues)

Captures the values in the start or end scene for the properties that this transition propagation monitors.

public abstract java.lang.StringgetPropagationProperties()

Returns the set of property names stored in the TransitionValues object passed into TransitionPropagation.captureValues(TransitionValues) that this transition propagation cares about for the purposes of preventing duplicate capturing of property values.

public intgetViewVisibility(TransitionValues values)

Returns android.view.View for the View at the time the values were captured.

public intgetViewX(TransitionValues values)

Returns the View's center x coordinate, relative to the screen, at the time the values were captured.

public intgetViewY(TransitionValues values)

Returns the View's center y coordinate, relative to the screen, at the time the values were captured.

from TransitionPropagationgetStartDelay
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public VisibilityPropagation()

Methods

public abstract void captureValues(TransitionValues transitionValues)

Captures the values in the start or end scene for the properties that this transition propagation monitors. These values are then passed as the startValues or endValues structure in a later call to TransitionPropagation.getStartDelay(ViewGroup, Transition, TransitionValues, TransitionValues). The main concern for an implementation is what the properties are that the transition cares about and what the values are for all of those properties. The start and end values will be compared later during the TransitionPropagation.getStartDelay(ViewGroup, Transition, TransitionValues, TransitionValues). method to determine the start delay.

Subclasses must implement this method. The method should only be called by the transition system; it is not intended to be called from external classes.

Parameters:

transitionValues: The holder for any values that the Transition wishes to store. Values are stored in the values field of this TransitionValues object and are keyed from a String value. For example, to store a view's rotation value, a transition might call transitionValues.values.put("appname:transitionname:rotation", view.getRotation()). The target view will already be stored in the transitionValues structure when this method is called.

public abstract java.lang.String getPropagationProperties()

Returns the set of property names stored in the TransitionValues object passed into TransitionPropagation.captureValues(TransitionValues) that this transition propagation cares about for the purposes of preventing duplicate capturing of property values.

A TransitionPropagation must override this method to prevent duplicate capturing of values and must contain at least one

Returns:

An array of property names as described in the class documentation for TransitionValues.

public int getViewVisibility(TransitionValues values)

Returns android.view.View for the View at the time the values were captured.

Parameters:

values: The TransitionValues captured at the start or end of the Transition.

Returns:

android.view.View for the View at the time the values were captured.

public int getViewX(TransitionValues values)

Returns the View's center x coordinate, relative to the screen, at the time the values were captured.

Parameters:

values: The TransitionValues captured at the start or end of the Transition.

Returns:

the View's center x coordinate, relative to the screen, at the time the values were captured.

public int getViewY(TransitionValues values)

Returns the View's center y coordinate, relative to the screen, at the time the values were captured.

Parameters:

values: The TransitionValues captured at the start or end of the Transition.

Returns:

the View's center y coordinate, relative to the screen, at the time the values were captured.

Source

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

import android.view.View;

/**
 * Base class for <code>TransitionPropagation</code>s that care about
 * View Visibility and the center position of the View.
 */
public abstract class VisibilityPropagation extends TransitionPropagation {

    /**
     * The property key used for {@link android.view.View#getVisibility()}.
     */
    private static final String PROPNAME_VISIBILITY = "android:visibilityPropagation:visibility";

    /**
     * The property key used for the center of the View in screen coordinates. This is an
     * int[2] with the index 0 taking the x coordinate and index 1 taking the y coordinate.
     */
    private static final String PROPNAME_VIEW_CENTER = "android:visibilityPropagation:center";

    private static final String[] VISIBILITY_PROPAGATION_VALUES = {
            PROPNAME_VISIBILITY,
            PROPNAME_VIEW_CENTER,
    };

    @Override
    public void captureValues(TransitionValues values) {
        View view = values.view;
        Integer visibility = (Integer) values.values.get(Visibility.PROPNAME_VISIBILITY);
        if (visibility == null) {
            visibility = view.getVisibility();
        }
        values.values.put(PROPNAME_VISIBILITY, visibility);
        int[] loc = new int[2];
        view.getLocationOnScreen(loc);
        loc[0] += Math.round(view.getTranslationX());
        loc[0] += view.getWidth() / 2;
        loc[1] += Math.round(view.getTranslationY());
        loc[1] += view.getHeight() / 2;
        values.values.put(PROPNAME_VIEW_CENTER, loc);
    }

    @Override
    public String[] getPropagationProperties() {
        return VISIBILITY_PROPAGATION_VALUES;
    }

    /**
     * Returns {@link android.view.View#getVisibility()} for the View at the time the values
     * were captured.
     * @param values The TransitionValues captured at the start or end of the Transition.
     * @return {@link android.view.View#getVisibility()} for the View at the time the values
     * were captured.
     */
    public int getViewVisibility(TransitionValues values) {
        if (values == null) {
            return View.GONE;
        }
        Integer visibility = (Integer) values.values.get(PROPNAME_VISIBILITY);
        if (visibility == null) {
            return View.GONE;
        }
        return visibility;
    }

    /**
     * Returns the View's center x coordinate, relative to the screen, at the time the values
     * were captured.
     * @param values The TransitionValues captured at the start or end of the Transition.
     * @return the View's center x coordinate, relative to the screen, at the time the values
     * were captured.
     */
    public int getViewX(TransitionValues values) {
        return getViewCoordinate(values, 0);
    }

    /**
     * Returns the View's center y coordinate, relative to the screen, at the time the values
     * were captured.
     * @param values The TransitionValues captured at the start or end of the Transition.
     * @return the View's center y coordinate, relative to the screen, at the time the values
     * were captured.
     */
    public int getViewY(TransitionValues values) {
        return getViewCoordinate(values, 1);
    }

    private static int getViewCoordinate(TransitionValues values, int coordinateIndex) {
        if (values == null) {
            return -1;
        }

        int[] coordinates = (int[]) values.values.get(PROPNAME_VIEW_CENTER);
        if (coordinates == null) {
            return -1;
        }

        return coordinates[coordinateIndex];
    }

}