@Override @Nullable public String getTransitionName(@NonNull View v) { return v.getTransitionName(); }
/** * Used to register an element that will take part in the shared element transition. Maps the name used in the * "from" view to the name used in the "to" view if they are not the same. * * @param sharedElement The view from the "from" view that will take part in the shared element transition * @param toName The transition name used in the "to" view */ protected final void addSharedElement(@NonNull View sharedElement, @NonNull String toName) { String transitionName = sharedElement.getTransitionName(); if (transitionName == null) { throw new IllegalArgumentException("Unique transitionNames are required for all sharedElements"); } sharedElementNames.put(transitionName, toName); }
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); } }
@Override public void run() { waitForTransitionNames.remove(view.getTransitionName()); removedViews.add(new ViewParentPair(view, (ViewGroup)view.getParent())); ((ViewGroup)view.getParent()).removeView(view); if (waitForTransitionNames.size() == 0) { to.getViewTreeObserver().removeOnPreDrawListener(parentPreDrawListener); to.setVisibility(View.INVISIBLE); onTransitionPreparedListener.onPrepared(); } } });
@Nullable public static View findNamedView(@NonNull View view, @NonNull String transitionName) { if (transitionName.equals(view.getTransitionName())) { return view; } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; int childCount = viewGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View viewWithTransitionName = findNamedView(viewGroup.getChildAt(i), transitionName); if (viewWithTransitionName != null) { return viewWithTransitionName; } } } return null; }
public static void findNamedViews(@NonNull Map<String, View> namedViews, View view) { if (view.getVisibility() == View.VISIBLE) { String transitionName = view.getTransitionName(); if (transitionName != null) { namedViews.put(transitionName, view); } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; int childCount = viewGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View child = viewGroup.getChildAt(i); findNamedViews(namedViews, child); } } } }
@Override public void run() { final int numSharedElements = toSharedElements.size(); for (int i = 0; i < numSharedElements; i++) { final View view = toSharedElements.get(i); final String name = view.getTransitionName(); final String inName = sharedElementNames.get(name); view.setTransitionName(inName); } } });
private final SharedElementCallback mCallback = new SharedElementCallback() { @Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { if (mCurrentImagePosition != mOriginalImagePosition) { View sharedView = getImageAtPosition(mCurrentImagePosition); names.clear(); sharedElements.clear(); names.add(sharedView.getTransitionName()); sharedElements.put(sharedView.getTransitionName(), sharedView); } } /** * Returns the image of interest to be used as the entering/returning * shared element during the activity transition. */ private View getImageAtPosition(int position) { // ... } };
@Override public void run() { final int numSharedElements = toSharedElements.size(); for (int i = 0; i < numSharedElements; i++) { View view = toSharedElements.get(i); String name = view.getTransitionName(); if (name != null) { String inName = findKeyForValue(sharedElementNames, name); view.setTransitionName(inName); } } } });
@Nullable private ArrayMap<String, View> captureFromSharedElements(@NonNull View from) { if (sharedElementNames.isEmpty() || sharedElementTransition == null) { sharedElementNames.clear(); return null; } final ArrayMap<String, View> fromSharedElements = new ArrayMap<>(); TransitionUtils.findNamedViews(fromSharedElements, from); final List<String> names = new ArrayList<>(sharedElementNames.keySet()); fromSharedElements.retainAll(names); if (exitTransitionCallback != null) { exitTransitionCallback.onMapSharedElements(names, fromSharedElements); for (int i = names.size() - 1; i >= 0; i--) { String name = names.get(i); View view = fromSharedElements.get(name); if (view == null) { sharedElementNames.remove(name); } else if (!name.equals(view.getTransitionName())) { String targetValue = sharedElementNames.remove(name); sharedElementNames.put(view.getTransitionName(), targetValue); } } } else { sharedElementNames.retainAll(fromSharedElements.keySet()); } return fromSharedElements; }
TransitionUtils.findNamedViews(toSharedElements, to); for (ViewParentPair removedView : removedViews) { toSharedElements.put(removedView.view.getTransitionName(), removedView.view); sharedElementNames.remove(key); } else if (!name.equals(view.getTransitionName())) { String key = findKeyForValue(sharedElementNames, name); if (key != null) { sharedElementNames.put(key, view.getTransitionName());
@Override public boolean onTransition(Context context, FragmentTransaction transaction, Fragment exit, Fragment enter) { if (mThumb == null || !(enter instanceof GalleryDetailScene)) { return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { exit.setSharedElementReturnTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_move)); exit.setExitTransition( TransitionInflater.from(context).inflateTransition(android.R.transition.fade)); enter.setSharedElementEnterTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_move)); enter.setEnterTransition( TransitionInflater.from(context).inflateTransition(android.R.transition.fade)); transaction.addSharedElement(mThumb, mThumb.getTransitionName()); } return true; } }
@Override public boolean onTransition(Context context, FragmentTransaction transaction, Fragment exit, Fragment enter) { if (!(enter instanceof GalleryListScene) && !(enter instanceof DownloadsScene) && !(enter instanceof FavoritesScene) && !(enter instanceof HistoryScene)) { return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { exit.setSharedElementReturnTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_move)); exit.setExitTransition( TransitionInflater.from(context).inflateTransition(android.R.transition.fade)); enter.setSharedElementEnterTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_move)); enter.setEnterTransition( TransitionInflater.from(context).inflateTransition(android.R.transition.fade)); transaction.addSharedElement(mThumb, mThumb.getTransitionName()); } return true; } }
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); }
attributes.add(new MutableStringViewAttribute("TransitionName", view.getTransitionName()) { @Override @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); }
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); }
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); }
private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void addNonNullViewToTransitionParticipants(View view, List<Pair> participants) { if (view == null) { return; } participants.add(new Pair<>(view, view.getTransitionName())); }