Example usage for android.app ActivityOptions makeSceneTransitionAnimation

List of usage examples for android.app ActivityOptions makeSceneTransitionAnimation

Introduction

In this page you can find the example usage for android.app ActivityOptions makeSceneTransitionAnimation.

Prototype

@SafeVarargs
public static ActivityOptions makeSceneTransitionAnimation(Activity activity,
        Pair<View, String>... sharedElements) 

Source Link

Document

Create an ActivityOptions to transition between Activities using cross-Activity scene animations.

Usage

From source file:pl.ipebk.tabi.presentation.ui.search.SearchActivity.java

public void goToPlaceDetails(View view, AggregateId placeId, String searchedPlate, SearchType searchType,
        PlaceListItemType itemType, int position) {

    indicator.setVisibility(View.GONE);

    Intent intent = new Intent(this, DetailsSearchActivity.class);
    intent.putExtra(DetailsSearchActivity.PARAM_PLACE_ID, placeId.getValue());
    intent.putExtra(DetailsSearchActivity.PARAM_SEARCHED_PLATE, searchedPlate);
    intent.putExtra(DetailsSearchActivity.PARAM_SEARCHED_TYPE, searchType);
    intent.putExtra(DetailsSearchActivity.PARAM_ITEM_TYPE, itemType);
    intent.putExtra(DetailsSearchActivity.PARAM_ADAPTER_POSITION, position);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        List<Pair<View, String>> transitions = new ArrayList<>();
        // shared elements
        transitions.add(Pair.create(indicator, getString(R.string.trans_tab_indicator)));
        transitions.add(Pair.create(searchInputWrap, getString(R.string.trans_search_input)));
        transitions.add(Pair.create(view,
                SharedTransitionNaming.getName(getString(R.string.trans_row_background), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_voivodeship),
                SharedTransitionNaming.getName(getString(R.string.trans_voivodeship_name), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_powiat),
                SharedTransitionNaming.getName(getString(R.string.trans_powiat_name), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_place_name),
                SharedTransitionNaming.getName(getString(R.string.trans_place_name), position)));
        transitions.add(Pair.create(view.findViewById(R.id.ic_row),
                SharedTransitionNaming.getName(getString(R.string.trans_place_icon), position)));
        transitions.add(Pair.create(view.findViewById(R.id.txt_plate),
                SharedTransitionNaming.getName(getString(R.string.trans_place_plate), position)));
        // status and nav bar
        View statusBar = findViewById(android.R.id.statusBarBackground);
        if (statusBar != null) {
            transitions.add(Pair.create(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME));
        }/*from  w w w . j av a  2s . c o m*/
        View navigationBar = findViewById(android.R.id.navigationBarBackground);
        if (navigationBar != null) {
            transitions.add(Pair.create(navigationBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
        }

        Pair<View, String>[] transitionsArray = transitions.toArray(new Pair[transitions.size()]);

        ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(this,
                transitionsArray);
        startActivity(intent, transitionActivityOptions.toBundle());
    } else {
        startActivity(intent);
    }
}