use of androidx.core.app.SharedElementCallback in project Douya by DreaminginCodeZH.
the class BroadcastFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
CustomTabsHelperFragment.attachTo(this);
mResource = BroadcastAndCommentListResource.attachTo(mBroadcastId, mBroadcast, this);
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setTitle(getTitle());
activity.setSupportActionBar(mToolbar);
mContainerLayout.setOnClickListener(view -> onFinish());
ViewCompat.setTransitionName(mSharedView, Broadcast.makeTransitionName(mBroadcastId));
// This magically gives better visual effect when the broadcast is partially visible. Using
// setEnterSharedElementCallback() disables this hack when no transition is used to start
// this Activity.
ActivityCompat.setEnterSharedElementCallback(activity, new SharedElementCallback() {
@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
mBroadcastCommentList.scrollToPosition(0);
}
});
mToolbar.setOnDoubleClickListener(view -> {
mBroadcastCommentList.smoothScrollToPosition(0);
return true;
});
mSwipeRefreshLayout.setOnRefreshListener(() -> {
mResource.loadBroadcast();
mResource.loadCommentList(false);
});
mBroadcastCommentList.setHasFixedSize(true);
mBroadcastCommentList.setItemAnimator(new NoChangeAnimationItemAnimator());
mBroadcastCommentList.setLayoutManager(new LinearLayoutManager(activity));
mBroadcastAdapter = new SingleBroadcastAdapter(null, this);
// BroadcastLayout will take care of showing the effective broadcast.
// noinspection deprecation
setBroadcast(mResource.getBroadcast());
mCommentAdapter = new CommentAdapter(mResource.getCommentList(), (parent, itemView, item, position) -> onShowCommentAction(item));
mAdapter = new LoadMoreAdapter(mBroadcastAdapter, mCommentAdapter);
mBroadcastCommentList.setAdapter(mAdapter);
mBroadcastCommentList.addOnScrollListener(new OnVerticalScrollListener() {
public void onScrolledToBottom() {
mResource.loadCommentList(true);
}
});
mSendButton.setOnClickListener(view -> onSendComment());
TooltipUtils.setup(mSendButton);
View.OnLongClickListener sendTooltipListener = mSendButton.getOnLongClickListener();
mSendButton.setOnLongClickListener(view -> {
if (!Settings.LONG_CLICK_TO_SHOW_SEND_COMMENT_ACTIVITY.getValue()) {
return sendTooltipListener.onLongClick(view);
}
onShowSendCommentActivity();
return true;
});
updateSendCommentStatus();
if (savedInstanceState == null) {
if (mShowSendComment) {
TransitionUtils.postAfterTransition(this, this::onShowCommentIme);
}
}
TransitionUtils.setEnterReturnExplode(this);
TransitionUtils.setupTransitionOnActivityCreated(this);
}
use of androidx.core.app.SharedElementCallback in project CloudReader by youlookwhat.
the class BigImagePagerActivity method startThis.
public static void startThis(final AppCompatActivity activity, List<View> imageViews, List<String> imageUrls, int enterIndex) {
Intent intent = new Intent(activity, BigImagePagerActivity.class);
intent.putStringArrayListExtra(KEY_IMAGE_URLS, (ArrayList<String>) imageUrls);
intent.putExtra(KEY_ENTER_INDEX, enterIndex);
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, imageViews.get(enterIndex), imageUrls.get(enterIndex));
try {
ActivityCompat.startActivity(activity, intent, optionsCompat.toBundle());
} catch (IllegalArgumentException e) {
e.printStackTrace();
activity.startActivity(intent);
}
ActivityCompat.setExitSharedElementCallback(activity, new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
super.onMapSharedElements(names, sharedElements);
/* 这个方法会调用两次,一次进入前,一次回来前。 */
if (sExitIndex == null) {
return;
}
int exitIndex = sExitIndex;
sExitIndex = null;
if (exitIndex != enterIndex && imageViews.size() > exitIndex && imageUrls.size() > exitIndex) {
names.clear();
sharedElements.clear();
View view = imageViews.get(exitIndex);
String transitName = imageUrls.get(exitIndex);
if (view == null) {
activity.setExitSharedElementCallback((SharedElementCallback) null);
return;
}
names.add(transitName);
sharedElements.put(transitName, view);
}
activity.setExitSharedElementCallback((SharedElementCallback) null);
}
});
}
Aggregations