Example usage for android.transition TransitionInflater from

List of usage examples for android.transition TransitionInflater from

Introduction

In this page you can find the example usage for android.transition TransitionInflater from.

Prototype

public static TransitionInflater from(Context context) 

Source Link

Document

Obtains the TransitionInflater from the given context.

Usage

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoListFragment.java

private void displayDetailsFragment(View v, String videoId, String videoName) {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment fragment = VideoDetailsFragment.newInstance(videoId, videoName);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setSharedElementReturnTransition(
                TransitionInflater.from(mContext).inflateTransition(R.transition.simple_image_transition));
        setExitTransition(TransitionInflater.from(mContext).inflateTransition(android.R.transition.fade));
        setReenterTransition(TransitionInflater.from(mContext).inflateTransition(android.R.transition.fade));
        setReturnTransition(TransitionInflater.from(mContext).inflateTransition(android.R.transition.fade));
        fragment.setSharedElementEnterTransition(
                TransitionInflater.from(mContext).inflateTransition(R.transition.simple_image_transition));
        fragment.setEnterTransition(/* w  w  w .  j av a 2  s  .c o  m*/
                TransitionInflater.from(mContext).inflateTransition(android.R.transition.fade));
    } else {
        ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out);
    }
    fragment.setAllowEnterTransitionOverlap(true);
    fragment.setAllowReturnTransitionOverlap(true);

    View containerView = getView() != null ? (View) getView().getParent() : null;
    if (containerView != null) {
        ft.replace(containerView.getId(), fragment);
        ft.addToBackStack(TAG_VIDEO_DETAILS);
        ft.addSharedElement(v.findViewById(R.id.playlist_row_image),
                VideoDetailsFragment.THMB_TRANSITION_NAME + videoId);
        ft.commit();
    }
}

From source file:com.hufeiya.SignIn.activity.CategorySelectionActivity.java

@SuppressLint("NewApi")
private void signOut() {
    AsyncHttpHelper.clearAllCookies();//from   w w w  . j  a v  a  2  s.  c  om

    PreferencesHelper.signOut(this);
    if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
        getWindow().setExitTransition(
                TransitionInflater.from(this).inflateTransition(R.transition.category_enter));
    }
    SignInActivity.start(this, false);
    ActivityCompat.finishAfterTransition(this);
}

From source file:com.google.samples.apps.topeka.activity.CategorySelectionActivity.java

@SuppressLint("NewApi")
private void signOut() {
    PreferencesHelper.signOut(this);
    TopekaDatabaseHelper.reset(this);
    if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
        getWindow().setExitTransition(//ww  w.ja v  a2 s . c om
                TransitionInflater.from(this).inflateTransition(R.transition.category_enter));
    }
    SignInActivity.start(this, false);
    finish();
}

From source file:org.goodev.material.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();// www  . ja  v a  2s .  c o m
    if (UI.isLollipop()) {
        auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);
    }

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<Hit> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    if (UI.isLollipop()) {
                        TransitionManager.beginDelayedTransition(container, auto);
                    }
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                }
                adapter.addAll(data);
                if (dataManager.getPage() == 0) {
                    results.scrollToPosition(0);
                }
            } else if (adapter.getItemCount() == 0) {
                if (UI.isLollipop()) {
                    TransitionManager.beginDelayedTransition(container, auto);
                }
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            } else {
                adapter.notifyDataSetChanged();
                Snackbar.make(results, R.string.no_more_posts, Snackbar.LENGTH_LONG).show();
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns);
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    //        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    //            @Override
    //            public int getSpanSize(int position) {
    //                return adapter.getItemColumnSpan(position);
    //            }
    //        });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    if (UI.isLollipop()) {
        results.addOnScrollListener(gridScroll);
    }

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    int interpolator = UI.isLollipop() ? android.R.interpolator.fast_out_slow_in
            : android.R.interpolator.accelerate_decelerate;
    int backInterpolator = UI.isLollipop() ? android.R.interpolator.linear_out_slow_in
            : android.R.interpolator.accelerate_decelerate;
    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, interpolator));
    if (UI.isLollipop()) {
        // transform from search icon to back icon
        AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
                R.drawable.avd_search_to_back);
        searchBack.setImageDrawable(searchToBack);
        searchToBack.start();
    } else {
        searchBack.setVisibility(View.INVISIBLE);
        searchBack.setImageResource(R.drawable.ic_arrow_back_padded);
    }
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    if (UI.isLollipop()) {
        // animate in a scrim over the content behind
        scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean onPreDraw() {
                scrim.getViewTreeObserver().removeOnPreDrawListener(this);
                AnimatorSet showScrim = new AnimatorSet();
                showScrim.playTogether(
                        ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                                searchBackground.getBottom(), 0,
                                (float) Math.hypot(searchBackDistanceX,
                                        scrim.getHeight() - searchBackground.getBottom())),
                        ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                                ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
                showScrim.setDuration(400L);
                showScrim.setInterpolator(
                        AnimationUtils.loadInterpolator(SearchActivity.this, backInterpolator));
                showScrim.start();
                return false;
            }
        });
    }

    onNewIntent(getIntent());
}

From source file:com.andremion.louvre.home.GalleryActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTransition() {
    TransitionInflater inflater = TransitionInflater.from(this);
    getWindow().setExitTransition(inflater.inflateTransition(R.transition.gallery_exit));
    getWindow().setReenterTransition(inflater.inflateTransition(R.transition.gallery_reenter));
    Transition sharedElementExitTransition = inflater.inflateTransition(R.transition.shared_element);
    // Listener to reset shared element exit transition callbacks.
    sharedElementExitTransition.addListener(mSharedElementExitListener);
    getWindow().setSharedElementExitTransition(sharedElementExitTransition);
}

From source file:com.fallahpoor.tehranbrt.MainActivity.java

private void setupWindowAnimation() {

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        Transition explodeTransition = TransitionInflater.from(this).inflateTransition(R.transition.explode);
        Window window = getWindow();

        window.setReenterTransition(explodeTransition);
        window.setExitTransition(explodeTransition);
        window.setAllowReturnTransitionOverlap(false);

    }/*from   w  ww . j a v  a2 s .  c o m*/

}

From source file:io.plaidapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();/*w  ww. j  a  v a2s .  c o  m*/
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L)
                            .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                                    android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return position == adapter.getDataItemCount() ? columns : 1;
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}

From source file:io.plaidapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();//w  ww  .  ja v  a2  s . c o  m
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L)
                            .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                                    android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600L);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}

From source file:ir.isilearning.lmsapp.activity.CategorySelectionActivity.java

@SuppressLint("NewApi")
private void signOut() throws InterruptedException {
    PreferencesHelper.signOut(this);
    LMSAppDatabaseHelper.reset(this);
    if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
        getWindow().setExitTransition(/*from  w  ww .  j av  a  2  s.  co  m*/
                TransitionInflater.from(this).inflateTransition(R.transition.category_enter));
    }
    SignInActivity.start(this, false);
    ActivityCompat.finishAfterTransition(this);
}

From source file:com.erevacation.challenge.ui.screens.main.productlist.ProductListViewModel.java

@Override
public void addObservables() {
    super.addObservables();
    compositeDisposable.add(rxEventBus.observable(ProductClickEvent.class).subscribe(productClickEvent -> {

        ProductFragment productFragment = ProductFragment.newInstance(productClickEvent.getProduct());

        // From some reason animation flickering, I would have to spend more time on this to make it to work proper
        if (false && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getView().setSharedElementReturnTransitionCustom(TransitionInflater.from(activityContext)
                    .inflateTransition(R.transition.change_image_transform));
            getView().setExitTransitionCustom(
                    TransitionInflater.from(activityContext).inflateTransition(android.R.transition.fade));

            productFragment.setSharedElementEnterTransition(TransitionInflater.from(activityContext)
                    .inflateTransition(R.transition.change_image_transform));
            productFragment.setEnterTransition(
                    TransitionInflater.from(activityContext).inflateTransition(android.R.transition.fade));
            navigator.replaceFragmentAndAddToBackStack(R.id.container, productFragment,
                    ProductFragment.class.getSimpleName(), null, productClickEvent.getView(),
                    productClickEvent.getProduct().getSku());
        } else {//from ww w. ja v  a 2 s  . co  m
            navigator.replaceFragmentAndAddToBackStack(R.id.container, productFragment,
                    ProductFragment.class.getSimpleName(), null);
        }
    }, error -> {
        Timber.e(error, "Something went wrong");
        Snackbar.make(getView().getRootView(), error.getMessage(), Snackbar.LENGTH_LONG).show();
    }));
}