android.app.SharedElementCallback Java Examples

The following examples show how to use android.app.SharedElementCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchActivity.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
private void setupTransitions() {
    // grab the position that the search icon transitions in *from*
    // & use it to configure the return transition
    setEnterSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onSharedElementStart(
                List<String> sharedElementNames,
                List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            if (sharedElements != null && !sharedElements.isEmpty()) {
                View searchIcon = sharedElements.get(0);
                if (searchIcon.getId() != R.id.searchback) return;
                int centerX = (searchIcon.getLeft() + searchIcon.getRight()) / 2;
                CircularReveal hideResults = (CircularReveal) TransitionUtils.findTransition(
                        (TransitionSet) getWindow().getReturnTransition(),
                        CircularReveal.class, R.id.results_container);
                if (hideResults != null) {
                    hideResults.setCenter(new Point(centerX, 0));
                }
            }
        }
    });
}
 
Example #2
Source File: VODAdapter.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
@Override
void handleElementOnClick(final View view) {
    final int itemPosition = getRecyclerView().getChildAdapterPosition(view);
    VideoOnDemand item = getElements().get(itemPosition);
    if (activity instanceof VODActivity) {
        ((VODActivity) activity).startNewVOD(item);
    } else {
        Intent intent = VODActivity.createVODIntent(item, getContext());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            intent.putExtra(getContext().getString(R.string.stream_preview_url), item.getMediumPreview());
            intent.putExtra(getContext().getString(R.string.stream_preview_alpha), hasVodBeenWatched(item.getVideoId()) ? VOD_WATCHED_IMAGE_ALPHA : 1.0f);

            final View sharedView = view.findViewById(R.id.image_stream_preview);
            sharedView.setTransitionName(getContext().getString(R.string.stream_preview_transition));
            final ActivityOptionsCompat options = ActivityOptionsCompat.
                    makeSceneTransitionAnimation(activity, sharedView, getContext().getString(R.string.stream_preview_transition));

            activity.setExitSharedElementCallback(new SharedElementCallback() {
                @SuppressLint("NewApi")
                @Override
                public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                    super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);

                    sharedView.animate().alpha(VOD_WATCHED_IMAGE_ALPHA).setDuration(300).start();
                    activity.setExitSharedElementCallback(null);
                }
            });

            activity.startActivity(intent, options.toBundle());
        } else {
            getContext().startActivity(intent);
            activity.overridePendingTransition(R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
        }
    }
}
 
Example #3
Source File: ImagePreViewActivity.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    bg.setBackgroundColor(Color.TRANSPARENT);
    dataList = getIntent().getStringArrayListExtra(Constant.DATA);
    position = getIntent().getIntExtra(Constant.POSITION, 0);
    flag = getIntent().getIntExtra(Constant.FLAG, 0);
    mViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    list = new ArrayList<>();
    for (String item :
            dataList) {
        list.add(ImagePreViewFragment.newInstance(item));
    }
    mViewPagerAdapter.setTitleAndFragments(null, list);
    display.setAdapter(mViewPagerAdapter);
    display.setCurrentItem(position);
    //这个可以看做个管道  每次进入和退出的时候都会进行调用  进入的时候获取到前面传来的共享元素的信息
    //退出的时候 把这些信息传递给前面的activity
    //同时向sharedElements里面put view,跟对view添加transitionname作用一样
    supportPostponeEnterTransition();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                sharedElements.clear();
                sharedElements.put(dataList.get(display.getCurrentItem()), ((ImagePreViewFragment) list.get(display.getCurrentItem())).getSharedElement());
            }
        });
    }

}
 
Example #4
Source File: CommentListActivity.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
private void initSharedElement() {
    supportPostponeEnterTransition();
    ViewCompat.setTransitionName(headerView, "header");
    headerAvatar.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            headerAvatar.getViewTreeObserver().removeOnPreDrawListener(this);
            supportStartPostponedEnterTransition();
            return true;
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setExitSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {

                View view = null;
                if (headerDisplay != null) {
                    view = headerDisplay.getLayoutManager().findViewByPosition(index);
                }
                if (view != null) {
                    sharedElements.clear();
                    sharedElements.put(((ImageShareInfoHolder.ImageShareAdapter) headerDisplay.getAdapter())
                            .getData(index), view);
                    index = -1;
                }
            }
        });
    }
    presenter.registerEvent(PhotoPreEvent.class, photoPreEvent -> {
        if (photoPreEvent.getFlag() == ConstantUtil.COMMENT_LIST_FLAG) {
            index = photoPreEvent.getIndex();
        }
    });
}
 
Example #5
Source File: VODAdapter.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
@Override
void handleElementOnClick(final View view) {
	final int itemPosition =  getRecyclerView().getChildAdapterPosition(view);
	VideoOnDemand item = getElements().get(itemPosition);
	if (activity instanceof VODActivity) {
		((VODActivity) activity).startNewVOD(item);
	} else {
		Intent intent = VODActivity.createVODIntent(item, getContext());

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
			intent.putExtra(getContext().getString(R.string.stream_preview_url), item.getMediumPreview());
			intent.putExtra(getContext().getString(R.string.stream_preview_alpha), hasVodBeenWatched(item.getVideoId()) ? VOD_WATCHED_IMAGE_ALPHA : 1.0f);

			final View sharedView = view.findViewById(R.id.image_stream_preview);
			sharedView.setTransitionName(getContext().getString(R.string.stream_preview_transition));
			final ActivityOptionsCompat options = ActivityOptionsCompat.
					makeSceneTransitionAnimation(activity, sharedView, getContext().getString(R.string.stream_preview_transition));

			activity.setExitSharedElementCallback(new SharedElementCallback() {
				@SuppressLint("NewApi")
				@Override
				public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
					super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);

					sharedView.animate().alpha(VOD_WATCHED_IMAGE_ALPHA).setDuration(300).start();
					activity.setExitSharedElementCallback(null);
				}
			});

			activity.startActivity(intent, options.toBundle());
		} else {
			getContext().startActivity(intent);
			activity.overridePendingTransition(R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
		}
	}
}
 
Example #6
Source File: FeedAdapter.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
public static SharedElementCallback createSharedElementReenterCallback(
        @NonNull Context context) {
    final String shotTransitionName = context.getString(R.string.transition_shot);
    final String shotBackgroundTransitionName =
            context.getString(R.string.transition_shot_background);
    return new SharedElementCallback() {

        /**
         * We're performing a slightly unusual shared element transition i.e. from one view
         * (image in the grid) to two views (the image & also the background of the details
         * view, to produce the expand effect). After changing orientation, the transition
         * system seems unable to map both shared elements (only seems to map the shot, not
         * the background) so in this situation we manually map the background to the
         * same view.
         */
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (sharedElements.size() != names.size()) {
                // couldn't map all shared elements
                final View sharedShot = sharedElements.get(shotTransitionName);
                if (sharedShot != null) {
                    // has shot so add shot background, mapped to same view
                    sharedElements.put(shotBackgroundTransitionName, sharedShot);
                }
            }
        }
    };
}
 
Example #7
Source File: TransitionUtils.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
static void clearSharedElementsOnReturn(@NonNull final BaseActivity activity) {
    activity.setEnterSharedElementCallback(new SharedElementCallback() {

        @Override
        public void onMapSharedElements(final List<String> names,
                final Map<String, View> sharedElements) {
            super.onMapSharedElements(names, sharedElements);
            if (activity.isFinishingAfterTransition()) {
                names.clear();
                sharedElements.clear();
            }
        }
    });
}
 
Example #8
Source File: ActivityCompat21.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private static SharedElementCallback createCallback(SharedElementCallback21 callback) {
    SharedElementCallback newListener = null;
    if (callback != null) {
        newListener = new SharedElementCallbackImpl(callback);
    }
    return newListener;
}
 
Example #9
Source File: ChannelsAdapter.java    From Twire with GNU General Public License v3.0 4 votes vote down vote up
@Override
void handleElementOnClick(final View view) {
    int itemPosition = getRecyclerView().getChildAdapterPosition(view);
    final ChannelInfo item = getElements().get(itemPosition);
    final StreamerInfoViewHolder vh = (StreamerInfoViewHolder) getRecyclerView().getChildViewHolder(view);
    final PreviewTarget previewTarget = getTargets().get(vh.getTargetsKey());

    // Create intent for opening StreamerInfo activity. Send the StreamerInfo object with
    // the intent, and flag it to make sure it creates a new task on the history stack
    final Intent intent = new Intent(getContext(), ChannelActivity.class);
    intent.putExtra(getContext().getResources().getString(R.string.channel_info_intent_object), item);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View sharedView = view.findViewById(R.id.profileLogoImageView);
        sharedView.setTransitionName(getContext().getString(R.string.streamerInfo_transition));
        final ActivityOptionsCompat options = ActivityOptionsCompat.
                makeSceneTransitionAnimation(activity, sharedView, getContext().getString(R.string.streamerInfo_transition));

        activity.setExitSharedElementCallback(new SharedElementCallback() {
            @SuppressLint("NewApi")
            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);

                if (!sharedElements.isEmpty() && sharedElements.get(0) != null && previewTarget != null) {
                    View element = sharedElements.get(0);
                    Animation anim = new RoundImageAnimation(element.getWidth() / 2, 0, (ImageView) element, previewTarget.getPreview());
                    anim.setDuration(200);
                    anim.setInterpolator(new DecelerateInterpolator());
                    view.startAnimation(anim);
                }
                activity.setExitSharedElementCallback(null);
            }
        });
        activity.startActivity(intent, options.toBundle());
    } else {
        getContext().startActivity(intent);
        if (activity != null) {
            activity.overridePendingTransition(R.anim.slide_in_right_anim, R.anim.fade_out_semi_anim);
        }
    }
}
 
Example #10
Source File: ActivityCompat21.java    From letv with Apache License 2.0 4 votes vote down vote up
private static SharedElementCallback createCallback(SharedElementCallback21 callback) {
    if (callback != null) {
        return new SharedElementCallbackImpl(callback);
    }
    return null;
}
 
Example #11
Source File: ChannelsAdapter.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
@Override
void handleElementOnClick(final View view) {
	int itemPosition = getRecyclerView().getChildAdapterPosition(view);
	final ChannelInfo item = getElements().get(itemPosition);
	final StreamerInfoViewHolder vh = (StreamerInfoViewHolder) getRecyclerView().getChildViewHolder(view);
	final PreviewTarget previewTarget = getTargets().get(vh.getTargetsKey());

	// Create intent for opening StreamerInfo activity. Send the StreamerInfo object with
	// the intent, and flag it to make sure it creates a new task on the history stack
	final Intent intent = new Intent(getContext(), ChannelActivity.class);
	intent.putExtra(getContext().getResources().getString(R.string.channel_info_intent_object), item);
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		View sharedView = view.findViewById(R.id.profileLogoImageView);
		sharedView.setTransitionName(getContext().getString(R.string.streamerInfo_transition));
		final ActivityOptionsCompat options = ActivityOptionsCompat.
				makeSceneTransitionAnimation(activity, sharedView, getContext().getString(R.string.streamerInfo_transition));

		activity.setExitSharedElementCallback(new SharedElementCallback() {
			@SuppressLint("NewApi")
			@Override
			public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
				super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);

				if (!sharedElements.isEmpty() && sharedElements.get(0) != null && previewTarget != null) {
					View element = sharedElements.get(0);
					Animation anim = new RoundImageAnimation(element.getWidth()/2, 0, (ImageView) element, previewTarget.getPreview());
					anim.setDuration(200);
					anim.setInterpolator(new DecelerateInterpolator());
					view.startAnimation(anim);
				}
				activity.setExitSharedElementCallback(null);
			}
		});
		activity.startActivity(intent, options.toBundle());
	} else {
		getContext().startActivity(intent);
		if(activity != null) {
			activity.overridePendingTransition(R.anim.slide_in_right_anim, R.anim.fade_out_semi_anim);
		}
	}
}
 
Example #12
Source File: FeedAdapter.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
@NonNull
private DesignerNewsStoryHolder createDesignerNewsStoryHolder(ViewGroup parent) {
    final DesignerNewsStoryHolder holder = new DesignerNewsStoryHolder(layoutInflater.inflate(
            R.layout.designer_news_story_item, parent, false), pocketIsInstalled);
    holder.itemView.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final Story story = (Story) getItem(holder.getAdapterPosition());
                    CustomTabActivityHelper.openCustomTab(host,
                            DesignerNewsStory.getCustomTabIntent(host, story, null).build(),
                            Uri.parse(story.url));
                }
            }
        );
    holder.comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View commentsView) {
            final Intent intent = new Intent();
            intent.setClass(host, DesignerNewsStory.class);
            intent.putExtra(DesignerNewsStory.EXTRA_STORY,
                    (Story) getItem(holder.getAdapterPosition()));
            ReflowText.addExtras(intent, new ReflowText.ReflowableTextView(holder.title));
            setGridItemContentTransitions(holder.itemView);

            // on return, fade the pocket & comments buttons in
            host.setExitSharedElementCallback(new SharedElementCallback() {
                @Override
                public void onSharedElementStart(List<String> sharedElementNames, List<View>
                        sharedElements, List<View> sharedElementSnapshots) {
                    host.setExitSharedElementCallback(null);
                    notifyItemChanged(holder.getAdapterPosition(),
                            HomeGridItemAnimator.STORY_COMMENTS_RETURN);
                }
            });

            final ActivityOptions options =
                    ActivityOptions.makeSceneTransitionAnimation(host,
                            Pair.create((View) holder.title,
                                    host.getString(R.string.transition_story_title)),
                            Pair.create(holder.itemView,
                                    host.getString(R.string.transition_story_title_background)),
                            Pair.create(holder.itemView,
                                    host.getString(R.string.transition_story_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
    if (pocketIsInstalled) {
        holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble...
        holder.pocket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                PocketUtils.addToPocket(host,
                        ((Story) getItem(holder.getAdapterPosition())).url);
                // notify changed with a payload asking RV to run the anim
                notifyItemChanged(holder.getAdapterPosition(),
                        HomeGridItemAnimator.ADD_TO_POCKET);
            }
        });
    }
    return holder;
}
 
Example #13
Source File: DynamicSystemActivity.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the callback for the shared element transition.
 *
 * @return The callback for the shared element transition.
 */
public @Nullable SharedElementCallback getSharedElementCallback() {
    return mSharedElementCallback;
}
 
Example #14
Source File: DynamicSystemActivity.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the callback for the shared element transition.
 *
 * @param sharedElementCallback The callback for the shared element transition.
 */
public void setSharedElementCallback(@Nullable SharedElementCallback sharedElementCallback) {
    this.mSharedElementCallback = sharedElementCallback;
}