Example usage for android.view View getTransitionName

List of usage examples for android.view View getTransitionName

Introduction

In this page you can find the example usage for android.view View getTransitionName.

Prototype

@ViewDebug.ExportedProperty
public String getTransitionName() 

Source Link

Document

Returns the name of the View to be used to identify Views in Transitions.

Usage

From source file:com.asburymotors.android.disneysocal.ui.DetailActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void launch(Activity activity, String attraction, View heroView) {
    Intent intent = getLaunchIntent(activity, attraction);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, heroView,
                heroView.getTransitionName());
        ActivityCompat.startActivity(activity, intent, options.toBundle());
    } else {//  www  . j  a va2s  .  c o m
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Launch the {@link UserContactActivity}.
 *
 * @param activity The context used to start this intent
 * @param user     that was selected/*w ww.jav  a2  s  .  c om*/
 */
public static void launchUserProfileActivity(Activity activity, User user, String loggedInUserId,
        View profileImage, View userName) {
    Intent intent = getUserProfileIntent(user, loggedInUserId);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        View statusbar = activity.findViewById(android.R.id.statusBarBackground);
        View actionbar = activity.findViewById(android.R.id.navigationBarBackground);

        Pair<View, String> pair1 = Pair.create(profileImage, profileImage.getTransitionName());
        Pair<View, String> pair2 = Pair.create(userName, userName.getTransitionName());
        Pair<View, String> pair3 = Pair.create(statusbar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME);
        Pair<View, String> pair4 = Pair.create(actionbar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME);

        ActivityOptionsCompat options = makeSceneTransitionAnimation(activity, pair1, pair2, pair3, pair4);
        activity.startActivity(intent, options.toBundle());
    } else {
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Launch the {@link SearchActivity}.// www . j a  v  a  2  s.  com
 *
 * @param activity The context used to start this intent
 * @param textView search textview to animate
 * @param menu     hamburger icon to animate
 */
public static void launchSearchActivity(Activity activity, @NonNull View container, @NonNull View textView,
        @NonNull View menu) {
    Intent intent = new Intent(Intents.ACTION_SEARCH_VIEW);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        View statusbar = activity.findViewById(android.R.id.statusBarBackground);
        View actionbar = activity.findViewById(android.R.id.navigationBarBackground);

        Pair<View, String> pair1 = Pair.create(textView, textView.getTransitionName());
        Pair<View, String> pair2 = Pair.create(menu, menu.getTransitionName());
        Pair<View, String> pair3 = Pair.create(container, container.getTransitionName());

        Pair<View, String> pair4 = Pair.create(statusbar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME);
        Pair<View, String> pair5 = Pair.create(actionbar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME);

        ActivityOptionsCompat options = makeSceneTransitionAnimation(activity, pair1, pair2, pair3, pair4,
                pair5);
        activity.startActivity(intent, options.toBundle());
    } else {
        activity.startActivity(intent);
    }

}

From source file:tomerbu.edu.transitionsdemo.MyRecyclerAdapter.java

@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
    final Cheese cheese = data.get(position);

    holder.tvTitle.setText(cheese.getDescription());
    holder.ivImage.setImageResource(cheese.getImageResID());

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w ww .jav a 2 s .  c  o m*/
        public void onClick(View view) {
            Intent intent = new Intent(context, DetailsActivity.class);
            intent.putExtra(EXTRA_CHEESE, cheese);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                holder.tvTitle.setTransitionName("description");
                holder.ivImage.setTransitionName("image");

                View tvTitle = holder.tvTitle;
                View ivImage = holder.ivImage;

                Pair<View, String> pair1 = Pair.create(tvTitle, tvTitle.getTransitionName());
                Pair<View, String> pair2 = Pair.create(ivImage, ivImage.getTransitionName());

                MainActivity act = (MainActivity) context;
                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(act, pair1,
                        pair2);

                Transition transition = TransitionInflater.from(act).inflateTransition(R.transition.arc_bounds);
                /*               Transition transition = new Slide();
                        
                               ArcMotion arc = new ArcMotion();
                               arc.setMinimumHorizontalAngle(90);
                               transition.setPathMotion(arc);*/

                act.getWindow().setSharedElementEnterTransition(transition);
                act.getWindow().setSharedElementExitTransition(transition);
                act.getWindow().setSharedElementReenterTransition(transition);
                act.getWindow().setSharedElementReturnTransition(transition);

                ActivityCompat.startActivity(act, intent, options.toBundle());
            } else {
                context.startActivity(intent);
            }

        }
    });
}

From source file:com.afollestad.polar.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    final boolean useNavDrawer = Config.get().navDrawerModeEnabled();
    if (useNavDrawer)
        setContentView(R.layout.activity_main_drawer);
    else/* w w w  . ja  va  2s .c  o  m*/
        setContentView(R.layout.activity_main);

    ButterKnife.bind(this);
    setSupportActionBar(mToolbar);

    setupPages();
    setupPager();
    if (useNavDrawer)
        setupNavDrawer();
    else
        setupTabs();

    // Restore last selected page, tab/nav-drawer-item
    if (Config.get().persistSelectedPage()) {
        int lastPage = PreferenceManager.getDefaultSharedPreferences(MainActivity.this)
                .getInt("last_selected_page", 0);
        if (lastPage > mPager.getAdapter().getCount() - 1)
            lastPage = 0;
        mPager.setCurrentItem(lastPage);
        if (mNavView != null)
            invalidateNavViewSelection(lastPage);
    }
    dispatchFragmentUpdateTitle(!useNavDrawer);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setExitSharedElementCallback(new SharedElementCallback() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                if (isReentering) {
                    WallpapersFragment frag = (WallpapersFragment) getFragmentManager()
                            .findFragmentByTag("page:" + mPager.getCurrentItem());
                    final RecyclerView recyclerView = frag.getRecyclerView();
                    View item = recyclerView.findViewWithTag("view_" + reenterPos);
                    View image = item.findViewById(R.id.image);

                    names.clear();
                    names.add(image.getTransitionName());
                    sharedElements.clear();
                    sharedElements.put(image.getTransitionName(), image);

                    isReentering = false;
                }
            }
        });
    }

    processIntent(getIntent());
}

From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java

@Override
public void onCryptoOperationSuccess(EditKeyResult result) {

    setState(State.DONE);// w w w.  j  ava  2 s  .  c o m

    mButtonContainer.getInAnimation().setDuration(750);
    mButtonContainer.setDisplayedChild(2);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            FragmentActivity activity = getActivity();
            Intent intent = new Intent(activity, ViewKeyActivity.class);
            intent.setData(KeyRings.buildGenericKeyRingUri(mMasterKeyId));
            // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                intent.putExtra(ViewKeyActivity.EXTRA_LINKED_TRANSITION, true);
                View linkedItem = mButtonContainer.getChildAt(2);

                Bundle options = ActivityOptionsCompat
                        .makeSceneTransitionAnimation(activity, linkedItem, linkedItem.getTransitionName())
                        .toBundle();
                activity.startActivity(intent, options);
                mFinishOnStop = true;
            } else {
                activity.startActivity(intent);
                activity.finish();
            }
        }
    }, 1000);
}

From source file:app.jorge.mobile.com.transportalert.ScrollingActivity.java

private void addCard(LinearLayout item, CardFactory.TUBE_LINE line) {

    CardTube card = CardFactory.getCard(line);
    View child = getLayoutInflater().inflate(R.layout.tube_line, null);

    ImageView imageView = (ImageView) child.findViewById(R.id.iconTube);
    //imageView.setImageResource(card.getIcon());
    imageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), card.getIcon(), 100, 100));

    TextView lineName = (TextView) child.findViewById(R.id.tubeName);
    lineName.setText(card.getName());//from  w w  w .j  ava 2s. com
    lineName.setTextColor(Color.parseColor(card.getColour()));

    TextView text = (TextView) child.findViewById(R.id.tubeStatus);
    text.setText(card.getStatus());

    item.addView(child);

    child.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            View imageView = v.findViewById(R.id.iconTube);
            imageView.setTransitionName(getString(R.string.activity_image_trans));

            View textTubeNameView = v.findViewById(R.id.tubeName);
            textTubeNameView.setTransitionName(getString(R.string.activity_text_tube_name));

            View textStatusView = v.findViewById(R.id.tubeStatus);
            textStatusView.setTransitionName(getString(R.string.activity_text_tube_status));

            Intent intent = new Intent(ScrollingActivity.this, DetailActivity.class);
            Pair<View, String> pair1 = Pair.create(imageView, imageView.getTransitionName());
            Pair<View, String> pair2 = Pair.create(textTubeNameView, textTubeNameView.getTransitionName());
            Pair<View, String> pair3 = Pair.create(textStatusView, textStatusView.getTransitionName());

            ActivityOptionsCompat options = ActivityOptionsCompat
                    .makeSceneTransitionAnimation(ScrollingActivity.this, pair1, pair2, pair3);

            String line = ((TextView) textTubeNameView).getText().toString();
            String status = ((TextView) textStatusView).getText().toString();

            LineStatuses ls = tubeStatus.get(line);
            if ((ls != null) && (ls.getDisruption() != null)) {
                intent.putExtra(getString(R.string.activity_info_category), ls.getDisruption().getCategory());
                intent.putExtra(getString(R.string.activity_info_description),
                        ls.getDisruption().getDescription());
                intent.putExtra(getString(R.string.activity_info_additional),
                        ls.getDisruption().getAdditionalInfo());
                intent.putExtra(getString(R.string.activity_info_icon), line);
                intent.putExtra(getString(R.string.activity_info_status), status);

                startActivity(intent, options.toBundle());
            }

        }
    });

}

From source file:com.jlt.unsplashd.MainActivity.java

/**
 * Overrides//from  w  w  w  .j  ava  2  s.co  m
 */

@Override
// begin onCreate
protected void onCreate(Bundle savedInstanceState) {

    // 0. super things
    // 1. use the main activity layout
    // 2. bind items
    // 3. create a grid layout manager
    // 3a. should have the number of columns found in the resources
    // 3b. configure the space, or span, each item will occupy in the grid on a base of 6
    // 3b1. 1st, 2nd, 3rd, 5th items should cover 1 space
    // 3b2. 4th items should cover 2 spaces
    // 3b3. other, that is 6th, items should cover 3 spaces
    // 4. use this grid layout manager in the photo grid
    // 5. decorate the photo grid using the grid margin decoration
    // 6. the photo grid should have a fixed size for efficiency
    // 7. initialize the base url for the photos
    // 8. when a photo is tapped,
    // 8a. get the tapped photo
    // 8b. plan to start the details activity
    // 8b1. use the view action
    // 8b2. put the url of the photo as data
    // 8b3. send an extra with the author
    // 8b4. start details using the appropriate transition
    // 9. initialize a REST fetcher for the photos
    // 9a. use the unsplash endpoint
    // 9b. build the fetcher
    // 9c. use the unsplash service class to service this
    // 10. when the feed comes back
    // 10a. successfully
    // 10a1. initialize the photo adapter with the gotten photos
    // 10a2. use the photo adapter to populate the photo grid
    // 10a3. hide the progress bar
    // 10b. unsuccessfully
    // 10b2. log this

    // 0. super things

    super.onCreate(savedInstanceState);

    // 1. use the main activity layout

    setContentView(R.layout.activity_main);

    // 2. bind items

    ButterKnife.bind(this);

    // 3. create a grid layout manager

    // 3a. should have the number of columns found in the resources

    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, photoGridColumns);

    // 3b. configure the space, or span, each item will occupy in the grid on a base of 6
    // 3b1. 1st, 2nd, 3rd, 5th items should cover 1 space
    // 3b2. 4th items should cover 2 spaces
    // 3b3. other, that is 6th, items should cover 3 spaces

    // begin gridLayoutManager.setSpanSizeLookup
    // setSpanSizeLookup - set source to get the number of spans occupied by each item
    //  in the adapter.
    gridLayoutManager.setSpanSizeLookup(

            // begin new GridLayoutManager.SpanSizeLookup
            new GridLayoutManager.SpanSizeLookup() {

                @Override
                // begin getSpanSize
                // getSpanSize - returns the number of span occupied by the item at position.
                public int getSpanSize(int position) {

                    // 3b. configure the space, or span, each item will occupy
                    // in the grid on a base of 6

                    // begin switching the position
                    switch (position % 6) {

                    // 3b1. 1st, 2nd, 3rd, 5th items should cover 1 space

                    case 0:
                    case 1:
                    case 2:
                    case 4:

                        return 1;

                    // 3b2. 4th items should cover 2 spaces

                    case 5:

                        return 2;

                    // 3b3. other, that is 6th, items should cover 3 spaces

                    default:

                        return 3;

                    } // end switching the position

                } // end getSpanSize

            } // end new GridLayoutManager.SpanSizeLookup

    ); // end gridLayoutManager.setSpanSizeLookup

    // 4. use this grid layout manager in the photo grid

    photoGridRecyclerView.setLayoutManager(gridLayoutManager);

    // 5. decorate the photo grid using the grid margin decoration

    photoGridRecyclerView.addItemDecoration(new GridMarginDecoration(gridSpacing));

    // 6. the photo grid should have a fixed size for efficiency

    photoGridRecyclerView.setHasFixedSize(true);

    // 7. initialize the base url for the photos

    photoUrlBase = "https://unsplash.it/" + getResources().getDisplayMetrics().widthPixels + "?image=";

    // 8. when a photo is tapped,

    // begin ItemClickSupport.addTo( photoGridRecyclerView ).setOnItemClickListener
    ItemClickSupport.addTo(photoGridRecyclerView).setOnItemClickListener(

            // begin new ItemClickSupport.OnItemClickListener
            new OnItemClickListener() {

                @Override
                // begin onItemClicked
                public void onItemClicked(RecyclerView recyclerView, int position, View view) {

                    // 8a. get the tapped photo

                    Photo photo = mPhotoAdapter.getItem(position);

                    // 8b. plan to start the details activity

                    Intent detailsActivityIntent = new Intent(MainActivity.this, DetailActivity.class);

                    // 8b1. use the view action

                    detailsActivityIntent.setAction(Intent.ACTION_VIEW);

                    // 8b2. put the url of the photo as data

                    detailsActivityIntent.setData(Uri.parse(photoUrlBase + photo.id));

                    // 8b3. send an extra with the author

                    detailsActivityIntent.putExtra(DetailActivity.EXTRA_AUTHOR_NAME, photo.author);

                    // 8b4. start details using the appropriate transition

                    Bundle transitionBundle = ActivityOptionsCompat
                            .makeSceneTransitionAnimation(MainActivity.this, view, view.getTransitionName())
                            .toBundle();

                    MainActivity.this.startActivity(detailsActivityIntent, transitionBundle);

                } // end onItemClicked

            } // end new ItemClickSupport.OnItemClickListener

    ); // end ItemClickSupport.addTo( photoGridRecyclerView ).setOnItemClickListener

    // 9. initialize a REST fetcher for the photos

    // RestAdapter - Adapts a Java interface to a REST API.
    UnsplashService unsplashApi = new RestAdapter.Builder()

            // 9a. use the unsplash endpoint

            // setEndpoint - set API endpoint
            .setEndpoint(UnsplashService.ENDPOINT)

            // 9b. build the fetcher

            // build - create the RestAdapter instances.
            .build()

            // 9c. use the unsplash service class to service this

            // create - Create an implementation of the API defined by the specified service interface.
            .create(UnsplashService.class);

    // 10. when the feed comes back

    // begin unsplashApi.getFeed
    unsplashApi.getFeed(

            // begin new Callback< List< Photo > >()
            // Callback - Communicates responses from a server or offline requests.
            new Callback<List<Photo>>() {

                // 10a. successfully

                @Override
                // begin success
                // success - Successful HTTP response.
                public void success(List<Photo> photos, Response response) {

                    // 10a1. initialize the photo adapter with the gotten photos

                    mPhotoAdapter = new PhotoAdapter(MainActivity.this, photos, photoUrlBase);

                    // 10a2. use the photo adapter to populate the photo grid

                    photoGridRecyclerView.setAdapter(mPhotoAdapter);

                    // 10a3. hide the progress bar

                    emptyProgressBar.setVisibility(View.GONE);

                } // end success

                // 10b. unsuccessfully

                @Override
                // begin failure
                // failure -  due to network failure, non-2XX status code, or unexpected exception.
                public void failure(RetrofitError error) {

                    // 10b2. log this

                    Log.e("failure: ", "RetrofitError " + error);

                } // end failure

            } // end new Callback< List< Photo > >()

    ); // end unsplashApi.getFeed

}

From source file:org.xbmc.kore.utils.SharedElementTransition.java

/**
 * Sets up the transition for the entering fragment
 * @param fragmentTransaction/* w  w  w.j av a2 s . co m*/
 * @param fragment entering fragment
 * @param sharedElement must have the transition name set
 */
@TargetApi(21)
public void setupEnterTransition(Context context, FragmentTransaction fragmentTransaction,
        final Fragment fragment, View sharedElement) {
    if (!(fragment instanceof SharedElement)) {
        LogUtils.LOGD(TAG, "Enter transition fragment must implement SharedElement interface");
        return;
    }

    android.support.v4.app.SharedElementCallback seCallback = new android.support.v4.app.SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            // On returning, onMapSharedElements for the exiting fragment is called before the onMapSharedElements
            // for the reentering fragment. We use this to determine if we are returning and if
            // we should clear the shared element lists. Note that, clearing must be done in the reentering fragment
            // as this is called last. Otherwise, the app will crash during transition setup. Not sure, but might
            // be a v4 support package bug.
            if (fragment.isVisible() && (!((SharedElement) fragment).isSharedElementVisible())) {
                // shared element not visible
                clearSharedElements = true;
            }
        }
    };
    fragment.setEnterSharedElementCallback(seCallback);

    fragment.setEnterTransition(TransitionInflater.from(context).inflateTransition(R.transition.media_details));
    fragment.setReturnTransition(null);

    Transition changeImageTransition = TransitionInflater.from(context)
            .inflateTransition(R.transition.change_image);
    fragment.setSharedElementReturnTransition(changeImageTransition);
    fragment.setSharedElementEnterTransition(changeImageTransition);

    fragmentTransaction.addSharedElement(sharedElement, sharedElement.getTransitionName());
}