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

public static ActivityOptions makeSceneTransitionAnimation(Activity activity, View sharedElement,
        String sharedElementName) 

Source Link

Document

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

Usage

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

void bindShot(final boolean postponeEnterTransition) {
    final Resources res = getResources();

    // load the main image
    final int[] imageSize = shot.images.bestSize();
    Glide.with(this).load(shot.images.best()).listener(shotLoadListener)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE)
            .override(imageSize[0], imageSize[1]).into(imageView);
    imageView.setOnClickListener(shotClick);
    shotSpacer.setOnClickListener(shotClick);

    if (postponeEnterTransition)
        postponeEnterTransition();//from  ww w .ja  v a  2  s .  c  o  m
    imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            imageView.getViewTreeObserver().removeOnPreDrawListener(this);
            calculateFabPosition();
            if (postponeEnterTransition)
                startPostponedEnterTransition();
            return true;
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ((FabOverlapTextView) title).setText(shot.title);
    } else {
        ((TextView) title).setText(shot.title);
    }
    if (!TextUtils.isEmpty(shot.description)) {
        final Spanned descText = shot.getParsedDescription(
                ContextCompat.getColorStateList(this, R.color.dribbble_links),
                ContextCompat.getColor(this, R.color.dribbble_link_highlight));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            ((FabOverlapTextView) description).setText(descText);
        } else {
            HtmlUtils.setTextWithNiceLinks((TextView) description, descText);
        }
    } else {
        description.setVisibility(View.GONE);
    }
    NumberFormat nf = NumberFormat.getInstance();
    likeCount.setText(
            res.getQuantityString(R.plurals.likes, (int) shot.likes_count, nf.format(shot.likes_count)));
    likeCount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) likeCount.getCompoundDrawables()[1]).start();
            if (shot.likes_count > 0) {
                PlayerSheet.start(DribbbleShot.this, shot);
            }
        }
    });
    if (shot.likes_count == 0) {
        likeCount.setBackground(null); // clear touch ripple if doesn't do anything
    }
    viewCount.setText(
            res.getQuantityString(R.plurals.views, (int) shot.views_count, nf.format(shot.views_count)));
    viewCount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) viewCount.getCompoundDrawables()[1]).start();
        }
    });
    share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            new ShareDribbbleImageTask(DribbbleShot.this, shot).execute();
        }
    });
    if (shot.user != null) {
        playerName.setText(shot.user.name.toLowerCase());
        Glide.with(this).load(shot.user.getHighQualityAvatarUrl()).transform(circleTransform)
                .placeholder(R.drawable.avatar_placeholder).override(largeAvatarSize, largeAvatarSize)
                .into(playerAvatar);
        View.OnClickListener playerClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent player = new Intent(DribbbleShot.this, PlayerActivity.class);
                if (shot.user.shots_count > 0) { // legit user object
                    player.putExtra(PlayerActivity.EXTRA_PLAYER, shot.user);
                } else {
                    // search doesn't fully populate the user object,
                    // in this case send the ID not the full user
                    player.putExtra(PlayerActivity.EXTRA_PLAYER_NAME, shot.user.username);
                    player.putExtra(PlayerActivity.EXTRA_PLAYER_ID, shot.user.id);
                }
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this,
                        playerAvatar, getString(R.string.transition_player_avatar));
                startActivity(player, options.toBundle());
            }
        };
        playerAvatar.setOnClickListener(playerClick);
        playerName.setOnClickListener(playerClick);
        if (shot.created_at != null) {
            shotTimeAgo
                    .setText(
                            DateUtils
                                    .getRelativeTimeSpanString(shot.created_at.getTime(),
                                            System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)
                                    .toString().toLowerCase());
        }
    } else {
        playerName.setVisibility(View.GONE);
        playerAvatar.setVisibility(View.GONE);
        shotTimeAgo.setVisibility(View.GONE);
    }

    commentAnimator = new CommentAnimator();
    commentsList.setItemAnimator(commentAnimator);
    adapter = new CommentsAdapter(shotDescription, commentFooter, shot.comments_count,
            getResources().getInteger(R.integer.comment_expand_collapse_duration));
    commentsList.setAdapter(adapter);
    commentsList.addItemDecoration(new InsetDividerDecoration(CommentViewHolder.class,
            res.getDimensionPixelSize(R.dimen.divider_height), res.getDimensionPixelSize(R.dimen.keyline_1),
            ContextCompat.getColor(this, R.color.divider)));
    if (shot.comments_count != 0) {
        loadComments();
    }
    checkLiked();
}

From source file:org.y20k.transistor.CollectionAdapter.java

public void handleSingleClick(int position, CollectionAdapterViewHolder theHolder) {

    Station station = mStationList.get(position);

    if (mTwoPane) {
        Bundle args = new Bundle();
        args.putParcelable(TransistorKeys.ARG_STATION, station);
        args.putInt(TransistorKeys.ARG_STATION_ID, position);
        args.putBoolean(TransistorKeys.ARG_TWO_PANE, mTwoPane);

        PlayerActivityFragment playerActivityFragment = new PlayerActivityFragment();
        playerActivityFragment.setArguments(args);
        mActivity.getFragmentManager().beginTransaction()
                .replace(R.id.player_container, playerActivityFragment, TransistorKeys.PLAYER_FRAGMENT_TAG)
                .commit();//  w  ww. j  a v  a  2  s  . com
    } else {
        // add ID of station to intent and start activity
        Intent intent = new Intent(mActivity, PlayerActivity.class);
        intent.setAction(TransistorKeys.ACTION_SHOW_PLAYER);
        intent.putExtra(TransistorKeys.EXTRA_STATION, station);
        intent.putExtra(TransistorKeys.EXTRA_STATION_Position_ID, position);

        if (theHolder != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            //for Motion (transaction) between activities
            View sharedView = theHolder.getStationImageView();
            String transitionName = mActivity.getString(R.string.mainImageForSation);
            ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(mActivity,
                    sharedView, transitionName);
            mActivity.startActivity(intent, transitionActivityOptions.toBundle());
        } else {
            mActivity.startActivity(intent);
        }
    }
}

From source file:org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity.java

private void showQrCodeDialog() {
    Intent qrCodeIntent = new Intent(this, QrCodeViewActivity.class);

    // create the transition animation - the images in the layouts
    // of both activities are defined with android:transitionName="qr_code"
    Bundle opts = null;//from  w  ww.  j a v  a2  s. c o  m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, mQrCodeLayout, "qr_code");
        opts = options.toBundle();
    }

    qrCodeIntent.setData(mDataUri);
    ActivityCompat.startActivity(this, qrCodeIntent, opts);
}

From source file:com.fbartnitzek.tasteemall.MainActivity.java

private void startShowMap2() {
    BasePagerFragment baseFragment = getFragment(mViewPager.getCurrentItem());

    Intent intent = new Intent(this, ShowMapActivity.class);
    intent.putExtra(ShowMapActivity.BASE_URI, baseFragment.getJsonUri());
    intent.putExtra(ShowMapActivity.BASE_ENTITY, baseFragment.getEntity());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View rootView = findViewById(R.id.pager);

        // no useful element name transition possible
        //            menuView.setTransitionName(getString(R.string.shared_transition_show_map));

        // workaround: start usual activity with wrong element transition ...
        Bundle bundle = ActivityOptions
                .makeSceneTransitionAnimation(this, rootView, getString(R.string.no_shared_element_transition))
                .toBundle();/* ww w.jav a2s  .  c o  m*/

        startActivity(intent, bundle);
    } else {
        startActivity(intent);
    }

}

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

@OnClick(R.id.fab)
protected void fabClick() {
    if (designerNewsPrefs.isLoggedIn()) {
        Intent intent = new Intent(this, PostNewDesignerNewsStory.class);
        FabTransform.addExtras(intent, ContextCompat.getColor(this, R.color.accent), R.drawable.ic_add_dark);
        intent.putExtra(PostStoryService.EXTRA_BROADCAST_RESULT, true);
        registerPostStoryResultListener();
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, fab,
                getString(R.string.transition_new_designer_news_post));
        startActivityForResult(intent, RC_NEW_DESIGNER_NEWS_STORY, options.toBundle());
    } else {//from ww  w  . j  ava 2s  .  c  o  m
        Intent intent = new Intent(this, DesignerNewsLogin.class);
        FabTransform.addExtras(intent, ContextCompat.getColor(this, R.color.accent), R.drawable.ic_add_dark);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, fab,
                getString(R.string.transition_designer_news_login));
        startActivityForResult(intent, RC_NEW_DESIGNER_NEWS_LOGIN, options.toBundle());
    }
}

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

private void needsLogin(View triggeringView, int requestCode) {
    Intent login = new Intent(DesignerNewsStory.this, DesignerNewsLogin.class);
    login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
            ContextCompat.getColor(DesignerNewsStory.this, R.color.background_light));
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DesignerNewsStory.this,
            triggeringView, getString(R.string.transition_designer_news_login));
    startActivityForResult(login, requestCode, options.toBundle());
}

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

private void needsLogin(View triggeringView, int requestCode) {
    Intent login = new Intent(DesignerNewsStory.this, DesignerNewsLogin.class);
    MorphTransform.addExtras(login, ContextCompat.getColor(this, R.color.background_light),
            triggeringView.getHeight() / 2);
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DesignerNewsStory.this,
            triggeringView, getString(R.string.transition_designer_news_login));
    startActivityForResult(login, requestCode, options.toBundle());
}

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

public void postComment(View view) {
    if (dribbblePrefs.isLoggedIn()) {
        if (TextUtils.isEmpty(enterComment.getText()))
            return;
        enterComment.setEnabled(false);/*ww w  .  j  a v a  2 s  . c o m*/
        dribbbleApi.postComment(shot.id, enterComment.getText().toString().trim(),
                new retrofit.Callback<Comment>() {
                    @Override
                    public void success(Comment comment, Response response) {
                        loadComments();
                        enterComment.getText().clear();
                        enterComment.setEnabled(true);
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        enterComment.setEnabled(true);
                    }
                });
    } else {
        Intent login = new Intent(DribbbleShot.this, DribbbleLogin.class);
        login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
                ContextCompat.getColor(this, R.color.background_light));
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this, postComment,
                getString(R.string.transition_dribbble_login));
        startActivityForResult(login, RC_LOGIN_COMMENT, options.toBundle());
    }
}