Java Code Examples for android.transition.Transition#addTarget()

The following examples show how to use android.transition.Transition#addTarget() . 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: StreamActivity.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private TransitionSet constructTransitions() {
    int[] slideTargets = {R.id.ChatRecyclerView, R.id.chat_input, R.id.chat_input_divider};

    Transition slideTransition = new Slide(Gravity.BOTTOM);
    Transition fadeTransition = new Fade();

    for (int slideTarget : slideTargets) {
        slideTransition.addTarget(slideTarget);
        fadeTransition.excludeTarget(slideTarget, true);
    }

    TransitionSet set = new TransitionSet();
    set.addTransition(slideTransition);
    set.addTransition(fadeTransition);
    return set;
}
 
Example 4
Source File: LiveStreamActivity.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private TransitionSet constructTransitions() {
	int[] slideTargets = {R.id.ChatRecyclerView, R.id.chat_input, R.id.chat_input_divider};

	Transition slideTransition = new Slide(Gravity.BOTTOM);
	Transition fadeTransition = new Fade();

	for (int slideTarget : slideTargets) {
		slideTransition.addTarget(slideTarget);
		fadeTransition.excludeTarget(slideTarget, true);
	}

	TransitionSet set = new TransitionSet();
	set.addTransition(slideTransition);
	set.addTransition(fadeTransition);
	return set;
}
 
Example 5
Source File: AlbumDetailActivity.java    From android-animations-transitions with MIT License 6 votes vote down vote up
private Transition createTransition() {
    TransitionSet set = new TransitionSet();
    set.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);

    Transition tFab = new Scale();
    tFab.setDuration(150);
    tFab.addTarget(fab);

    Transition tTitle = new Fold();
    tTitle.setDuration(150);
    tTitle.addTarget(titlePanel);

    Transition tTrack = new Fold();
    tTrack.setDuration(150);
    tTrack.addTarget(trackPanel);

    set.addTransition(tTrack);
    set.addTransition(tTitle);
    set.addTransition(tFab);

    return set;
}
 
Example 6
Source File: ViewActivity.java    From recurrence with GNU General Public License v3.0 5 votes vote down vote up
public void setupTransitions() {
    // Add shared element transition animation if on Lollipop or later
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Enter transitions
        TransitionSet setEnter = new TransitionSet();

        Transition slideDown = new Explode();
        slideDown.addTarget(headerView);
        slideDown.excludeTarget(scrollView, true);
        slideDown.setDuration(500);
        setEnter.addTransition(slideDown);

        Transition fadeOut = new Slide(Gravity.BOTTOM);
        fadeOut.addTarget(scrollView);
        fadeOut.setDuration(500);
        setEnter.addTransition(fadeOut);

        // Exit transitions
        TransitionSet setExit = new TransitionSet();

        Transition slideDown2 = new Explode();
        slideDown2.addTarget(headerView);
        slideDown2.setDuration(570);
        setExit.addTransition(slideDown2);

        Transition fadeOut2 = new Slide(Gravity.BOTTOM);
        fadeOut2.addTarget(scrollView);
        fadeOut2.setDuration(280);
        setExit.addTransition(fadeOut2);

        getWindow().setEnterTransition(setEnter);
        getWindow().setReturnTransition(setExit);
    }
}
 
Example 7
Source File: TransitionUtils.java    From Material-Movies with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Transition makeSharedElementEnterTransition(Context context) {

    Transition changeBounds = new ChangeBounds();
    changeBounds.addTarget(R.id.item_movie_cover);
    return changeBounds;
}
 
Example 8
Source File: FragmentTransitionCompat21.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static void addTargets(Object transitionObject, ArrayList<View> views) {
    Transition transition = (Transition) transitionObject;
    int numViews = views.size();
    for (int i = 0; i < numViews; i++) {
        transition.addTarget(views.get(i));
    }
}
 
Example 9
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Configures a transition for a single fragment container for which the transaction was
 * ordered. That means that the transaction has not been executed yet, so incoming
 * Views are not yet known.
 *
 * @param fragmentManager The executing FragmentManagerImpl
 * @param containerId The container ID that is executing the transition.
 * @param fragments A structure holding the transitioning fragments in this container.
 * @param nonExistentView A View that does not exist in the hierarchy. This is used to
 *                        prevent transitions from acting on other Views when there is no
 *                        other target.
 * @param nameOverrides A map of the shared element names from the starting fragment to
 *                      the final fragment's Views as given in
 *                      {@link FragmentTransaction#addSharedElement(View, String)}.
 */
private static void configureTransitionsOrdered(FragmentManagerImpl fragmentManager,
        int containerId, FragmentContainerTransition fragments,
        View nonExistentView, ArrayMap<String, String> nameOverrides) {
    ViewGroup sceneRoot = null;
    if (fragmentManager.mContainer.onHasView()) {
        sceneRoot = fragmentManager.mContainer.onFindViewById(containerId);
    }
    if (sceneRoot == null) {
        return;
    }
    final Fragment inFragment = fragments.lastIn;
    final Fragment outFragment = fragments.firstOut;
    final boolean inIsPop = fragments.lastInIsPop;
    final boolean outIsPop = fragments.firstOutIsPop;

    Transition enterTransition = getEnterTransition(inFragment, inIsPop);
    Transition exitTransition = getExitTransition(outFragment, outIsPop);

    ArrayList<View> sharedElementsOut = new ArrayList<>();
    ArrayList<View> sharedElementsIn = new ArrayList<>();

    TransitionSet sharedElementTransition = configureSharedElementsOrdered(sceneRoot,
            nonExistentView, nameOverrides, fragments, sharedElementsOut, sharedElementsIn,
            enterTransition, exitTransition);

    if (enterTransition == null && sharedElementTransition == null &&
            exitTransition == null) {
        return; // no transitions!
    }

    ArrayList<View> exitingViews = configureEnteringExitingViews(exitTransition,
            outFragment, sharedElementsOut, nonExistentView);

    if (exitingViews == null || exitingViews.isEmpty()) {
        exitTransition = null;
    }

    if (enterTransition != null) {
        // Ensure the entering transition doesn't target anything until the views are made
        // visible
        enterTransition.addTarget(nonExistentView);
    }

    Transition transition = mergeTransitions(enterTransition, exitTransition,
            sharedElementTransition, inFragment, fragments.lastInIsPop);

    if (transition != null) {
        transition.setNameOverrides(nameOverrides);
        final ArrayList<View> enteringViews = new ArrayList<>();
        scheduleRemoveTargets(transition,
                enterTransition, enteringViews, exitTransition, exitingViews,
                sharedElementTransition, sharedElementsIn);
        scheduleTargetChange(sceneRoot, inFragment, nonExistentView, sharedElementsIn,
                enterTransition, enteringViews, exitTransition, exitingViews);

        TransitionManager.beginDelayedTransition(sceneRoot, transition);
    }
}
 
Example 10
Source File: FragmentTransitionCompat21.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares the enter transition by adding a non-existent view to the transition's target list
 * and setting it epicenter callback. By adding a non-existent view to the target list,
 * we can prevent any view from being targeted at the beginning of the transition.
 * We will add to the views before the end state of the transition is captured so that the
 * views will appear. At the start of the transition, we clear the list of targets so that
 * we can restore the state of the transition and use it again.
 *
 * <p>The shared element transition maps its shared elements immediately prior to
 *  capturing the final state of the Transition.</p>
 */
public static void addTransitionTargets(Object enterTransitionObject,
        Object sharedElementTransitionObject, final View container,
        final ViewRetriever inFragment, final View nonExistentView,
        EpicenterView epicenterView, final Map<String, String> nameOverrides,
        final ArrayList<View> enteringViews, final Map<String, View> renamedViews,
        final ArrayList<View> sharedElementTargets) {
    if (enterTransitionObject != null || sharedElementTransitionObject != null) {
        final Transition enterTransition = (Transition) enterTransitionObject;
        if (enterTransition != null) {
            enterTransition.addTarget(nonExistentView);
        }
        if (sharedElementTransitionObject != null) {
            Transition sharedElementTransition = (Transition) sharedElementTransitionObject;
            addTargets(sharedElementTransition, sharedElementTargets);
        }

        if (inFragment != null) {
            container.getViewTreeObserver().addOnPreDrawListener(
                    new ViewTreeObserver.OnPreDrawListener() {
                        public boolean onPreDraw() {
                            container.getViewTreeObserver().removeOnPreDrawListener(this);
                            View fragmentView = inFragment.getView();
                            if (fragmentView != null) {
                                if (!nameOverrides.isEmpty()) {
                                    findNamedViews(renamedViews, fragmentView);
                                    renamedViews.keySet().retainAll(nameOverrides.values());
                                    for (Map.Entry<String, String> entry : nameOverrides.entrySet()) {
                                        String to = entry.getValue();
                                        View view = renamedViews.get(to);
                                        if (view != null) {
                                            String from = entry.getKey();
                                            view.setTransitionName(from);
                                        }
                                    }
                                }
                                if (enterTransition != null) {
                                    captureTransitioningViews(enteringViews, fragmentView);
                                    enteringViews.removeAll(renamedViews.values());
                                    addTargets(enterTransition, enteringViews);
                                }
                            }
                            return true;
                        }
                    });
        }
        setSharedElementEpicenter(enterTransition, epicenterView);
    }
}