Java Code Examples for android.transition.TransitionSet#getTransitionCount()

The following examples show how to use android.transition.TransitionSet#getTransitionCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * This method removes the views from transitions that target ONLY those views and
 * replaces them with the new targets list.
 * The views list should match those added in addTargets and should contain
 * one view that is not in the view hierarchy (state.nonExistentView).
 */
public static void replaceTargets(Transition transition, ArrayList<View> oldTargets,
        ArrayList<View> newTargets) {
    if (transition instanceof TransitionSet) {
        TransitionSet set = (TransitionSet) transition;
        int numTransitions = set.getTransitionCount();
        for (int i = 0; i < numTransitions; i++) {
            Transition child = set.getTransitionAt(i);
            replaceTargets(child, oldTargets, newTargets);
        }
    } else if (!hasSimpleTarget(transition)) {
        List<View> targets = transition.getTargets();
        if (targets != null && targets.size() == oldTargets.size() &&
                targets.containsAll(oldTargets)) {
            // We have an exact match. We must have added these earlier in addTargets
            final int targetCount = newTargets == null ? 0 : newTargets.size();
            for (int i = 0; i < targetCount; i++) {
                transition.addTarget(newTargets.get(i));
            }
            for (int i = oldTargets.size() - 1; i >= 0; i--) {
                transition.removeTarget(oldTargets.get(i));
            }
        }
    }
}
 
Example 2
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * This method adds views as targets to the transition, but only if the transition
 * doesn't already have a target. It is best for views to contain one View object
 * that does not exist in the view hierarchy (state.nonExistentView) so that
 * when they are removed later, a list match will suffice to remove the targets.
 * Otherwise, if you happened to have targeted the exact views for the transition,
 * the replaceTargets call will remove them unexpectedly.
 */
public static void addTargets(Transition transition, ArrayList<View> views) {
    if (transition == null) {
        return;
    }
    if (transition instanceof TransitionSet) {
        TransitionSet set = (TransitionSet) transition;
        int numTransitions = set.getTransitionCount();
        for (int i = 0; i < numTransitions; i++) {
            Transition child = set.getTransitionAt(i);
            addTargets(child, views);
        }
    } else if (!hasSimpleTarget(transition)) {
        List<View> targets = transition.getTargets();
        if (isNullOrEmpty(targets)) {
            // We can just add the target views
            int numViews = views.size();
            for (int i = 0; i < numViews; i++) {
                transition.addTarget(views.get(i));
            }
        }
    }
}
 
Example 3
Source File: TransitionUtils.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
public static @Nullable Transition findTransition(
        @NonNull TransitionSet set,
        @NonNull Class<? extends Transition> clazz,
        @IdRes int targetId) {
    for (int i = 0; i < set.getTransitionCount(); i++) {
        Transition transition = set.getTransitionAt(i);
        if (transition.getClass() == clazz) {
            if (transition.getTargetIds().contains(targetId)) {
                return transition;
            }
        }
        if (transition instanceof TransitionSet) {
            Transition child = findTransition((TransitionSet) transition, clazz, targetId);
            if (child != null) return child;
        }
    }
    return null;
}
 
Example 4
Source File: ActivityTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Blocks suppressLayout from Visibility transitions. It is ok to suppress the layout,
 * but we don't want to force the layout when suppressLayout becomes false. This leads
 * to visual glitches.
 */
private static void noLayoutSuppressionForVisibilityTransitions(Transition transition) {
    if (transition instanceof Visibility) {
        final Visibility visibility = (Visibility) transition;
        visibility.setSuppressLayout(false);
    } else if (transition instanceof TransitionSet) {
        final TransitionSet set = (TransitionSet) transition;
        final int count = set.getTransitionCount();
        for (int i = 0; i < count; i++) {
            noLayoutSuppressionForVisibilityTransitions(set.getTransitionAt(i));
        }
    }
}
 
Example 5
Source File: TransitionUtils.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
public static @Nullable Transition findTransition(
        @NonNull TransitionSet set, @NonNull Class<? extends Transition> clazz) {
    for (int i = 0; i < set.getTransitionCount(); i++) {
        Transition transition = set.getTransitionAt(i);
        if (transition.getClass() == clazz) {
            return transition;
        }
        if (transition instanceof TransitionSet) {
            Transition child = findTransition((TransitionSet) transition, clazz);
            if (child != null) return child;
        }
    }
    return null;
}