android.transition.Transition Java Examples

The following examples show how to use android.transition.Transition. 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: FragmentSelect.java    From imageres_resolution with MIT License 6 votes vote down vote up
private void switchToPreview(Uri uri) {
    Fragment fragment = FragmentPreview.instance(uri);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

        Slide slideTransition = new Slide(Gravity.LEFT);
        slideTransition.setDuration(duration);
        setExitTransition(slideTransition);

        Slide slideTransition2 = new Slide(Gravity.RIGHT);
        slideTransition2.setDuration(duration);
        fragment.setEnterTransition(slideTransition2);

        TransitionInflater inflater = TransitionInflater.from(getContext());
        Transition transition = inflater.inflateTransition(R.transition.transition_default);
        fragment.setSharedElementEnterTransition(transition);
    }

    getFragmentManager()
            .beginTransaction()
            .replace(R.id.frg_docker, fragment)
            .addSharedElement(mBtnFindWrapper, ViewCompat.getTransitionName(mBtnFindWrapper))
            .addToBackStack("select")
            .commitAllowingStateLoss();
}
 
Example #2
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 #3
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used for fragment transitions for ordered transactions to change the
 * enter and exit transition targets after the call to
 * {@link TransitionManager#beginDelayedTransition(ViewGroup, Transition)}. The exit transition
 * must ensure that it does not target any Views and the enter transition must start targeting
 * the Views of the incoming Fragment.
 *
 * @param sceneRoot The fragment container View
 * @param inFragment The last fragment that is entering
 * @param nonExistentView A view that does not exist in the hierarchy that is used as a
 *                        transition target to ensure no View is targeted.
 * @param sharedElementsIn The shared element Views of the incoming fragment
 * @param enterTransition The enter transition of the incoming fragment
 * @param enteringViews The entering Views of the incoming fragment
 * @param exitTransition The exit transition of the outgoing fragment
 * @param exitingViews The exiting views of the outgoing fragment
 */
private static void scheduleTargetChange(final ViewGroup sceneRoot,
        final Fragment inFragment, final View nonExistentView,
        final ArrayList<View> sharedElementsIn,
        final Transition enterTransition, final ArrayList<View> enteringViews,
        final Transition exitTransition, final ArrayList<View> exitingViews) {

    OneShotPreDrawListener.add(sceneRoot, () -> {
        if (enterTransition != null) {
            enterTransition.removeTarget(nonExistentView);
            ArrayList<View> views = configureEnteringExitingViews(
                    enterTransition, inFragment, sharedElementsIn, nonExistentView);
            enteringViews.addAll(views);
        }

        if (exitingViews != null) {
            if (exitTransition != null) {
                ArrayList<View> tempExiting = new ArrayList<>();
                tempExiting.add(nonExistentView);
                replaceTargets(exitTransition, exitingViews, tempExiting);
            }
            exitingViews.clear();
            exitingViews.add(nonExistentView);
        }
    });
}
 
Example #4
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a TransitionSet containing the shared element transition. The wrapping TransitionSet
 * targets all shared elements to ensure that no other Views are targeted. The shared element
 * transition can then target any or all shared elements without worrying about accidentally
 * targeting entering or exiting Views.
 *
 * @param inFragment The incoming fragment
 * @param outFragment the outgoing fragment
 * @param isPop True if this is a pop transaction or false if it is a normal (add) transaction.
 * @return A TransitionSet wrapping the shared element transition or null if no such transition
 * exists.
 */
private static TransitionSet getSharedElementTransition(Fragment inFragment,
        Fragment outFragment, boolean isPop) {
    if (inFragment == null || outFragment == null) {
        return null;
    }
    Transition transition = cloneTransition(isPop
            ? outFragment.getSharedElementReturnTransition()
            : inFragment.getSharedElementEnterTransition());
    if (transition == null) {
        return null;
    }
    TransitionSet transitionSet = new TransitionSet();
    transitionSet.addTransition(transition);
    return transitionSet;
}
 
Example #5
Source File: EnterTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void viewsReady(ArrayMap<String, View> sharedElements) {
    super.viewsReady(sharedElements);
    mIsReadyForTransition = true;
    hideViews(mSharedElements);
    Transition viewsTransition = getViewsTransition();
    if (viewsTransition != null && mTransitioningViews != null) {
        removeExcludedViews(viewsTransition, mTransitioningViews);
        stripOffscreenViews();
        hideViews(mTransitioningViews);
    }
    if (mIsReturning) {
        sendSharedElementDestination();
    } else {
        moveSharedElementsToOverlay();
    }
    if (mSharedElementsBundle != null) {
        onTakeSharedElements();
    }
}
 
Example #6
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * After the transition has started, remove all targets that we added to the transitions
 * so that the transitions are left in a clean state.
 */
private static void scheduleRemoveTargets(final Transition overalTransition,
        final Transition enterTransition, final ArrayList<View> enteringViews,
        final Transition exitTransition, final ArrayList<View> exitingViews,
        final TransitionSet sharedElementTransition, final ArrayList<View> sharedElementsIn) {
    overalTransition.addListener(new TransitionListenerAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            if (enterTransition != null) {
                replaceTargets(enterTransition, enteringViews, null);
            }
            if (exitTransition != null) {
                replaceTargets(exitTransition, exitingViews, null);
            }
            if (sharedElementTransition != null) {
                replaceTargets(sharedElementTransition, sharedElementsIn, null);
            }
        }
    });
}
 
Example #7
Source File: ContentActivity.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_content);
    ButterKnife.bind(this);

    if (getIntent() != null) {
        int avatar = getIntent().getIntExtra(getString(R.string.transition_shared_avatar), 0);
        String title = getIntent().getStringExtra(getString(R.string.transition_shared_title));

        if (avatar > 0) {
            imageAvatar.setImageResource(avatar);
            colorize(((BitmapDrawable) imageAvatar.getDrawable()).getBitmap());
        }
        if (title != null) {
            textTitle.setText(title);
        }

        Transition transition =
                TransitionInflater.from(this).inflateTransition(R.transition.slide_bottom);
        getWindow().setEnterTransition(transition);
    }
}
 
Example #8
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 #9
Source File: Versatile.java    From Synapse with Apache License 2.0 5 votes vote down vote up
/**
 * Solve TransitionManager leak problem
 */
public static void removeActivityFromTransitionManager(Activity activity) {
    final Class transitionManagerClass = TransitionManager.class;

    try {
        final Field runningTransitionsField = transitionManagerClass.getDeclaredField("sRunningTransitions");

        if (runningTransitionsField == null) {
            return;
        }

        runningTransitionsField.setAccessible(true);

        //noinspection unchecked
        final ThreadLocal<WeakReference<ArrayMap<ViewGroup, ArrayList<Transition>>>> runningTransitions
                = (ThreadLocal<WeakReference<ArrayMap<ViewGroup, ArrayList<Transition>>>>)
                runningTransitionsField.get(transitionManagerClass);

        if (runningTransitions == null
                || runningTransitions.get() == null
                || runningTransitions.get().get() == null) {
            return;
        }

        final ArrayMap map = runningTransitions.get().get();
        final View decorView = activity.getWindow().getDecorView();

        if (map.containsKey(decorView)) {
            map.remove(decorView);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: FragmentTransitionCompat21.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static void cleanupTransitions(final View sceneRoot, final View nonExistentView,
        Object enterTransitionObject, final ArrayList<View> enteringViews,
        Object exitTransitionObject, final ArrayList<View> exitingViews,
        Object sharedElementTransitionObject, final ArrayList<View> sharedElementTargets,
        Object overallTransitionObject, final ArrayList<View> hiddenViews,
        final Map<String, View> renamedViews) {
    final Transition enterTransition = (Transition) enterTransitionObject;
    final Transition exitTransition = (Transition) exitTransitionObject;
    final Transition sharedElementTransition = (Transition) sharedElementTransitionObject;
    final Transition overallTransition = (Transition) overallTransitionObject;
    if (overallTransition != null) {
        sceneRoot.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                sceneRoot.getViewTreeObserver().removeOnPreDrawListener(this);
                if (enterTransition != null) {
                    enterTransition.removeTarget(nonExistentView);
                    removeTargets(enterTransition, enteringViews);
                }
                if (exitTransition != null) {
                    removeTargets(exitTransition, exitingViews);
                }
                if (sharedElementTransition != null) {
                    removeTargets(sharedElementTransition, sharedElementTargets);
                }
                for (Map.Entry<String, View> entry : renamedViews.entrySet()) {
                    View view = entry.getValue();
                    String name = entry.getKey();
                    view.setTransitionName(name);
                }
                int numViews = hiddenViews.size();
                for (int i = 0; i < numViews; i++) {
                    overallTransition.excludeTarget(hiddenViews.get(i), false);
                }
                overallTransition.excludeTarget(nonExistentView, false);
                return true;
            }
        });
    }
}
 
Example #11
Source File: BaseActivity.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
private void setupWindowAnimations() {
    Transition slideLeft = TransitionInflater.from(this).inflateTransition(android.R.transition.slide_left);
    Transition slideRight = TransitionInflater.from(this).inflateTransition(android.R.transition.slide_right);
    getWindow().setExitTransition(slideLeft);
    getWindow().setEnterTransition(slideRight);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY));
}
 
Example #12
Source File: TransitionAnimationBySlideActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void setupWindowAnimations() {
    Transition transition = null;

    switch (mSlideType) {
        case SLIDE_CODE:
            transition = buildEnterTransitionByCode();
            break;
        case SLIDE_XML:
            transition = buildEnterTransitionByXml();
            break;
        default:
            break;
    }
    getWindow().setEnterTransition(transition);
}
 
Example #13
Source File: TransitionAnimationBySlideActivity.java    From Android-Animation-Set with Apache License 2.0 5 votes vote down vote up
private void setupWindowAnimations() {
    Transition transition = null;

    switch (mSlideType) {
        case SLIDE_CODE:
            transition = buildEnterTransitionByCode();
            break;
        case SLIDE_XML:
            transition = buildEnterTransitionByXml();
            break;
        default:
            break;
    }
    getWindow().setEnterTransition(transition);
}
 
Example #14
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a clone of a transition or null if it is null
 */
private static Transition cloneTransition(Transition transition) {
    if (transition != null) {
        transition = transition.clone();
    }
    return transition;
}
 
Example #15
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the View in the incoming Fragment that should be used as the epicenter.
 *
 * @param inSharedElements The mapping of shared element names to Views in the
 *                         incoming fragment.
 * @param fragments A structure holding the transitioning fragments in this container.
 * @param enterTransition The transition used for the incoming Fragment's views
 * @param inIsPop Is the incoming fragment being added as a pop transaction?
 */
private static View getInEpicenterView(ArrayMap<String, View> inSharedElements,
        FragmentContainerTransition fragments,
        Transition enterTransition, boolean inIsPop) {
    BackStackRecord inTransaction = fragments.lastInTransaction;
    if (enterTransition != null && inSharedElements != null
            && inTransaction.mSharedElementSourceNames != null
            && !inTransaction.mSharedElementSourceNames.isEmpty()) {
        final String targetName = inIsPop
                ? inTransaction.mSharedElementSourceNames.get(0)
                : inTransaction.mSharedElementTargetNames.get(0);
        return inSharedElements.get(targetName);
    }
    return null;
}
 
Example #16
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 5 votes vote down vote up
public void goAnimate(View view) {
        //Resource file solution
        ViewGroup root = findViewById(R.id.layout);
        Scene scene = Scene.getSceneForLayout(root, R.layout.activity_main_end, this);
        Transition transition = TransitionInflater.from(this)
                .inflateTransition(R.transition.transition_move);
        TransitionManager.go(scene, transition);

        //Code only solution
//        ViewGroup root = findViewById(R.id.layout);
//        Scene scene = new Scene(root);
//
//        Transition transition = new ChangeBounds();
//        TransitionManager.beginDelayedTransition(root,transition);
//
//        TextView textViewTop = findViewById(R.id.textViewTop);
//        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)textViewTop.getLayoutParams();
//        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,1);
//        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
//        textViewTop.setLayoutParams(params);
//
//        TextView textViewBottom = findViewById(R.id.textViewBottom);
//        params = (RelativeLayout.LayoutParams) textViewBottom.getLayoutParams();
//        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,0);
//        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1);
//        textViewBottom.setLayoutParams(params);
//
//        TransitionManager.go(scene);
    }
 
Example #17
Source File: ActivityTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public Rect onGetEpicenter(Transition transition) {
    return mEpicenter;
}
 
Example #18
Source File: ReflowText.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
@Override
public Transition setDuration(long duration) {
    /* don't call super as we want to handle duration ourselves */
    return this;
}
 
Example #19
Source File: TransitionListenerAdapter.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onTransitionResume(Transition transition) {}
 
Example #20
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 #21
Source File: ImageTransitionSet.java    From Anecdote with Apache License 2.0 4 votes vote down vote up
@Override
public void onTransitionCancel(Transition transition) {
    // Nothing special here
}
 
Example #22
Source File: BoardAdapter.java    From BoardView with Apache License 2.0 4 votes vote down vote up
public void SetColumnTransition(Transition t){
    boardViewTransition = t;
}
 
Example #23
Source File: PlaylistDetailActivity.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
public void onTransitionStart(Transition paramTransition) {
}
 
Example #24
Source File: SimplelTransitionListener.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
public void onTransitionPause(Transition paramTransition) {
}
 
Example #25
Source File: SimpleTransitionListener.java    From native-navigation with MIT License 4 votes vote down vote up
@Override public void onTransitionResume(Transition transition) {
}
 
Example #26
Source File: TransitionCallback.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public void onTransitionCancel(Transition transition) {
    // no-op
}
 
Example #27
Source File: LoggingTransitionListener.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public void onTransitionStart(Transition transition) {
	log("onTransitionStart", transition);
}
 
Example #28
Source File: SearchActivity.java    From Melophile with Apache License 2.0 4 votes vote down vote up
private Transition getTransition(@TransitionRes int transitionId) {
  TransitionInflater inflater = TransitionInflater.from(this);
  return inflater.inflateTransition(transitionId);
}
 
Example #29
Source File: AcceleratedTransitionListener.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@Override
public void onTransitionResume(Transition transition) {
    onTransitionStart(transition);
}
 
Example #30
Source File: TransitionHelperKitkat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
static void include(Object transition, View targetView) {
    ((Transition) transition).addTarget(targetView);
}