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.core.ui.FeedAdapter.java

@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
    final DribbbleShotHolder holder = new DribbbleShotHolder(
            layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
    holder.image.setBadgeColor(initialGifBadgeColor);
    holder.image.setOnClickListener(view -> {
        Intent intent = ActivityHelper.intentTo(Activities.Dribbble.Shot.INSTANCE);
        intent.putExtra(Activities.Dribbble.Shot.EXTRA_SHOT_ID, getItem(holder.getAdapterPosition()).getId());
        setGridItemContentTransitions(holder.image);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                Pair.create(view, host.getString(R.string.transition_shot)),
                Pair.create(view, host.getString(R.string.transition_shot_background)));
        host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
    });//w w  w.java  2s. c  o m
    // play animated GIFs whilst touched
    holder.image.setOnTouchListener((v, event) -> {
        // check if it's an event we care about, else bail fast
        final int action = event.getAction();
        if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP
                || action == MotionEvent.ACTION_CANCEL)) {
            return false;
        }

        // get the image and check if it's an animated GIF
        final Drawable drawable = holder.image.getDrawable();
        if (drawable == null)
            return false;
        GifDrawable gif = null;
        if (drawable instanceof GifDrawable) {
            gif = (GifDrawable) drawable;
        } else if (drawable instanceof TransitionDrawable) {
            // we fade in images on load which uses a TransitionDrawable; check its layers
            TransitionDrawable fadingIn = (TransitionDrawable) drawable;
            for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
                if (fadingIn.getDrawable(i) instanceof GifDrawable) {
                    gif = (GifDrawable) fadingIn.getDrawable(i);
                    break;
                }
            }
        }
        if (gif == null)
            return false;
        // GIF found, start/stop it on press/lift
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            gif.start();
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            gif.stop();
            break;
        }
        return false;
    });
    return holder;
}

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

@Override
public void onClick(View v) {
    if (v.getId() == R.id.fab_add) {
        Intent intent = new Intent(this, AddReviewActivity.class);

        Bundle bundle = null;/*from  w w  w.  jav  a2 s  .  c  o m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // no really useful element name transition possible...
            BasePagerFragment fragment = getFragment(mViewPager.getCurrentItem());
            if (fragment != null) {
                bundle = ActivityOptions
                        .makeSceneTransitionAnimation(this, v, getString(fragment.getSharedTransitionId()))
                        .toBundle();
            }
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && bundle != null) {
            startActivityForResult(intent, ADD_REVIEW_REQUEST, bundle);
        } else {
            startActivityForResult(intent, ADD_REVIEW_REQUEST);
        }
    }
}

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);
        intent.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
                ContextCompat.getColor(this, R.color.accent));
        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  w  ww.  j  av  a2 s .  co  m*/
        Intent intent = new Intent(this, DesignerNewsLogin.class);
        intent.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
                ContextCompat.getColor(this, R.color.accent));
        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.FeedAdapter.java

@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
    final DribbbleShotHolder holder = new DribbbleShotHolder(
            layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
    holder.image.setBadgeColor(initialGifBadgeColor);
    holder.image.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w w.  j a v  a2s. c  o m*/
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, (Shot) getItem(holder.getAdapterPosition()));
            setGridItemContentTransitions(holder.image);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
        }
    });
    // play animated GIFs whilst touched
    holder.image.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // check if it's an event we care about, else bail fast
            final int action = event.getAction();
            if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP
                    || action == MotionEvent.ACTION_CANCEL))
                return false;

            // get the image and check if it's an animated GIF
            final Drawable drawable = holder.image.getDrawable();
            if (drawable == null)
                return false;
            GifDrawable gif = null;
            if (drawable instanceof GifDrawable) {
                gif = (GifDrawable) drawable;
            } else if (drawable instanceof TransitionDrawable) {
                // we fade in images on load which uses a TransitionDrawable; check its layers
                TransitionDrawable fadingIn = (TransitionDrawable) drawable;
                for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
                    if (fadingIn.getDrawable(i) instanceof GifDrawable) {
                        gif = (GifDrawable) fadingIn.getDrawable(i);
                        break;
                    }
                }
            }
            if (gif == null)
                return false;
            // GIF found, start/stop it on press/lift
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                gif.start();
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                gif.stop();
                break;
            }
            return false;
        }
    });
    return holder;
}

From source file:io.romain.passport.ui.MainActivity.java

@OnClick(R.id.floating_action_button)
protected void onFloatingActionButtonClicked() {
    Intent intent = new Intent(this, AddCityActivity.class);
    intent.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
            ContextCompat.getColor(this, R.color.accent));
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, mFloatingActionButton,
            getString(R.string.transition_add_city));
    startActivityForResult(intent, REQUEST_CODE_ADD_CITY, options.toBundle());
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvShareFragment.java

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

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

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

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

@OnClick(R.id.follow)
void follow() {//from  ww  w .j ava2  s. c  om
    if (DribbblePrefs.get(this).isLoggedIn()) {
        if (following != null && following) {
            final Call<Void> unfollowCall = dataManager.getDribbbleApi().unfollow(player.id);
            unfollowCall.enqueue(new Callback<Void>() {
                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                }
            });
            following = false;
            TransitionManager.beginDelayedTransition(container);
            follow.setText(R.string.follow);
            follow.setActivated(false);
            setFollowerCount(followerCount - 1);
        } else {
            final Call<Void> followCall = dataManager.getDribbbleApi().follow(player.id);
            followCall.enqueue(new Callback<Void>() {
                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                }
            });
            following = true;
            TransitionManager.beginDelayedTransition(container);
            follow.setText(R.string.following);
            follow.setActivated(true);
            setFollowerCount(followerCount + 1);
        }
    } else {
        Intent login = new Intent(this, DribbbleLogin.class);
        MorphTransform.addExtras(login, ContextCompat.getColor(this, R.color.dribbble),
                getResources().getDimensionPixelSize(R.dimen.dialog_corners));
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, follow,
                getString(R.string.transition_dribbble_login));
        startActivity(login, options.toBundle());
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_filter:
        drawer.openDrawer(GravityCompat.END);
        return true;
    case R.id.menu_search:
        View searchMenuView = toolbar.findViewById(R.id.menu_search);
        Bundle options = ActivityOptions
                .makeSceneTransitionAnimation(this, searchMenuView, getString(R.string.transition_search_back))
                .toBundle();//from   w w  w.j  a  va2 s . com
        startActivityForResult(new Intent(this, SearchActivity.class), RC_SEARCH, options);
        return true;
    case R.id.menu_dribbble_login:
        if (!dribbblePrefs.isLoggedIn()) {
            dribbblePrefs.login(HomeActivity.this);
        } else {
            dribbblePrefs.logout();
            // TODO something better than a toast!!
            Toast.makeText(getApplicationContext(), R.string.dribbble_logged_out, Toast.LENGTH_SHORT).show();
        }
        return true;
    case R.id.menu_designer_news_login:
        if (!designerNewsPrefs.isLoggedIn()) {
            startActivity(new Intent(this, DesignerNewsLogin.class));
        } else {
            designerNewsPrefs.logout(HomeActivity.this);
            // TODO something better than a toast!!
            Toast.makeText(getApplicationContext(), R.string.designer_news_logged_out, Toast.LENGTH_SHORT)
                    .show();
        }
        return true;
    case R.id.menu_about:
        startActivity(new Intent(HomeActivity.this, AboutActivity.class),
                ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) {
    final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView;
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override/*www  .j  av  a 2 s  . c o  m*/
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                iv.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f,
                        1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        if (iv.getDrawable() != null) {
                            iv.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
                        }
                    }
                });
                saturation.setDuration(2000);
                saturation.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        iv.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.ALL).into(new DribbbleTarget(iv, false));

    iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            iv.setTransitionName(iv.getResources().getString(R.string.transition_shot));
            iv.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light));
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, shot);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
}

From source file:com.fastbootmobile.encore.app.fragments.PlaybackQueueFragment.java

public PlaybackQueueFragment() {
    mHandler = new PlaybackQueueHandler(new WeakReference<>(this));

    mPlayFabClickListener = new View.OnClickListener() {
        @Override// w  ww.j  a v  a  2s  . c  o m
        public void onClick(View v) {
            switch (PlaybackProxy.getState()) {
            case PlaybackService.STATE_PAUSED:
            case PlaybackService.STATE_STOPPED:
            case PlaybackService.STATE_PAUSING:
                PlaybackProxy.play();
                break;

            case PlaybackService.STATE_BUFFERING:
            case PlaybackService.STATE_PLAYING:
                PlaybackProxy.pause();
                break;

            }
        }
    };

    mNextClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackProxy.next();
        }
    };

    mPreviousClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackProxy.previous();
        }
    };

    mSeekListener = new SeekBar.OnSeekBarChangeListener() {
        private int mStartProgress;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mLockSeekBarUpdate = true;
            mStartProgress = seekBar.getProgress();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            mLockSeekBarUpdate = false;
            int endProgress = seekBar.getProgress();

            if (endProgress != mStartProgress) {
                PlaybackProxy.seek(endProgress);
            }
        }
    };

    mRepeatClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean currentMode = PlaybackProxy.isRepeatMode();
            boolean newMode = !currentMode;

            PlaybackProxy.setRepeatMode(newMode);
            v.animate().rotationBy(-360).setDuration(600).start();

            if (newMode) {
                ((ImageView) v).setImageResource(R.drawable.ic_replay);
            } else {
                ((ImageView) v).setImageResource(R.drawable.ic_replay_gray);
            }
        }
    };

    mShuffleClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean currentMode = PlaybackProxy.isShuffleMode();
            boolean newMode = !currentMode;

            PlaybackProxy.setShuffleMode(newMode);

            if (newMode) {
                ((ImageView) v).setImageResource(R.drawable.ic_shuffle);
            } else {
                ((ImageView) v).setImageResource(R.drawable.ic_shuffle_gray);
            }
        }
    };

    mLikeClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ListenLogger logger = new ListenLogger(getActivity());
            PlaybackQueueAdapter.ViewHolder tag = (PlaybackQueueAdapter.ViewHolder) v.getTag();
            boolean isLiked = logger.isLiked(tag.song.getRef());

            if (isLiked) {
                logger.removeLike(tag.song);
                ((ImageView) v).setImageResource(R.drawable.ic_thumbs_up_gray);
            } else {
                logger.addLike(tag.song);

                final AutoMixBucket bucket = AutoMixManager.getDefault().getCurrentPlayingBucket();
                if (bucket != null) {
                    new Thread() {
                        public void run() {
                            try {
                                bucket.notifyLike();
                            } catch (EchoNestException e) {
                                Log.e(TAG, "Unable to notify like event to EchoNest");
                            }
                        }
                    }.start();
                }

                ((ImageView) v).setImageResource(R.drawable.ic_thumbs_up);
            }
        }
    };

    mDislikeClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ListenLogger logger = new ListenLogger(getActivity());
            PlaybackQueueAdapter.ViewHolder tag = (PlaybackQueueAdapter.ViewHolder) v.getTag();
            boolean isDisliked = logger.isDisliked(tag.song.getRef());

            if (isDisliked) {
                logger.removeDislike(tag.song);
                ((ImageView) v).setImageResource(R.drawable.ic_thumb_down_gray);
            } else {
                logger.addDislike(tag.song);

                final AutoMixBucket bucket = AutoMixManager.getDefault().getCurrentPlayingBucket();
                if (bucket != null) {
                    new Thread() {
                        public void run() {
                            try {
                                bucket.notifyDislike();
                            } catch (EchoNestException e) {
                                Log.e(TAG, "Unable to notify dislike event to EchoNest");
                            }
                        }
                    }.start();
                }

                ((ImageView) v).setImageResource(R.drawable.ic_thumb_down);
            }
        }
    };

    mAlbumArtClickListener = new View.OnClickListener() {
        @Override
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        public void onClick(View v) {
            PlaybackQueueAdapter.ViewHolder tag = (PlaybackQueueAdapter.ViewHolder) v.getTag();
            if (tag.song.getAlbum() != null) {
                Bitmap hero = ((MaterialTransitionDrawable) tag.ivAlbumArt.getDrawable()).getFinalDrawable()
                        .getBitmap();
                Intent intent = AlbumActivity.craftIntent(getActivity(), hero, tag.song.getAlbum(),
                        tag.song.getProvider(), 0xFF333333);

                if (Utils.hasLollipop()) {
                    ActivityOptions opts = ActivityOptions.makeSceneTransitionAnimation(getActivity(), v,
                            "itemImage");
                    getActivity().startActivity(intent, opts.toBundle());
                } else {
                    startActivity(intent);
                }
            } else {
                Toast.makeText(getActivity(), R.string.toast_song_no_album, Toast.LENGTH_SHORT).show();
            }
        }
    };
}