Skip to content

Instantly share code, notes, and snippets.

:octocat:
Set your status

André Mion andremion

:octocat:
Set your status
View GitHub Profile
@andremion
andremion / Collection.ofType.kt
Last active Aug 20, 2018
Extension function to filter and map items of a Collection
View Collection.ofType.kt
inline fun <reified T> Collection<*>.ofType(): Collection<T> = filter { it is T }.map { it as T }
View NullSharedElementExitTransition.java
getActivity().getWindow().getSharedElementExitTransition().addListener(new TransitionCallback() {
@Override
public void onTransitionEnd(Transition transition) {
removeCallback();
}
private void removeCallback() {
if (getActivity() != null) {
getActivity().getWindow().getSharedElementExitTransition().removeListener(this);
getActivity().setExitSharedElementCallback((SharedElementCallback) null);
}
View onActivityReenterMediaSharedElementCallback.java
final MediaSharedElementCallback sharedElementCallback = new MediaSharedElementCallback();
getActivity().setExitSharedElementCallback(sharedElementCallback);
getActivity().supportPostponeEnterTransition();
mRecyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mRecyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(position);
if (holder instanceof GalleryAdapter.MediaViewHolder) {
GalleryAdapter.MediaViewHolder mediaViewHolder = (GalleryAdapter.MediaViewHolder) holder;
View MediaSharedElementCallback.java
MediaSharedElementCallback sharedElementCallback = new MediaSharedElementCallback();
setEnterSharedElementCallback(sharedElementCallback);
View onMapSharedElementsBody.java
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
if (!mSharedElementViews.isEmpty()) {
removeObsoleteElements(names, sharedElements, mapObsoleteElements(names));
for (View sharedElementView : mSharedElementViews) {
String transitionName = ViewCompat.getTransitionName(sharedElementView);
names.add(transitionName);
sharedElements.put(transitionName, sharedElementView);
}
}
View setSharedElementViews.java
public void setSharedElementViews(@NonNull View… sharedElementViews) {
mSharedElementViews.clear();
mSharedElementViews.addAll(Arrays.asList(sharedElementViews));
}
View onMapSharedElements.java
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements)
View transition_setresult.java
@Override
public void finishAfterTransition() {
setResult();
super.finishAfterTransition();
}
private void setResult() {
int position = mViewPager.getCurrentItem();
Intent data = new Intent();
data.putExtra(EXTRA_POSITION, position);
View activity_reenter_position.java
public void onActivityReenter(int resultCode, Intent data) {
final int position = PreviewActivity.getPosition(resultCode, data);
if (position != RecyclerView.NO_POSITION) {
mRecyclerView.scrollToPosition(position);
}
}
View start_activity_transition.java
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements);
ActivityCompat.startActivityForResult(activity, intent, requestCode, options.toBundle());
You can’t perform that action at this time.