Search in sources :

Example 1 with SharedElementCallback

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);
}
Also used : ToastUtils(me.zhanghai.android.douya.util.ToastUtils) Bundle(android.os.Bundle) DoubleClickToolbar(me.zhanghai.android.douya.ui.DoubleClickToolbar) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) ProgressBar(android.widget.ProgressBar) FrameLayout(android.widget.FrameLayout) Comment(me.zhanghai.android.douya.network.api.info.frodo.Comment) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) GetOnLongClickListenerImageButton(me.zhanghai.android.douya.ui.GetOnLongClickListenerImageButton) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) BindView(butterknife.BindView) FragmentUtils(me.zhanghai.android.douya.util.FragmentUtils) ShareUtils(me.zhanghai.android.douya.util.ShareUtils) Fragment(androidx.fragment.app.Fragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator) ViewCompat(androidx.core.view.ViewCompat) WebViewActivity(me.zhanghai.android.douya.ui.WebViewActivity) DeleteBroadcastManager(me.zhanghai.android.douya.broadcast.content.DeleteBroadcastManager) LikeBroadcastManager(me.zhanghai.android.douya.broadcast.content.LikeBroadcastManager) ConfirmDiscardContentDialogFragment(me.zhanghai.android.douya.ui.ConfirmDiscardContentDialogFragment) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) DoubanUtils(me.zhanghai.android.douya.util.DoubanUtils) List(java.util.List) Nullable(androidx.annotation.Nullable) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CustomTabsHelperFragment(me.zhanghai.android.customtabshelper.CustomTabsHelperFragment) EventBusUtils(me.zhanghai.android.douya.eventbus.EventBusUtils) ButterKnife(butterknife.ButterKnife) BroadcastCommentSentEvent(me.zhanghai.android.douya.eventbus.BroadcastCommentSentEvent) ApiError(me.zhanghai.android.douya.network.api.ApiError) FragmentFinishable(me.zhanghai.android.douya.ui.FragmentFinishable) MenuItem(android.view.MenuItem) Settings(me.zhanghai.android.douya.settings.info.Settings) ImeUtils(me.zhanghai.android.douya.util.ImeUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ClipboardUtils(me.zhanghai.android.douya.util.ClipboardUtils) LogUtils(me.zhanghai.android.douya.util.LogUtils) Broadcast(me.zhanghai.android.douya.network.api.info.frodo.Broadcast) TooltipUtils(me.zhanghai.android.douya.util.TooltipUtils) BroadcastCommentSendErrorEvent(me.zhanghai.android.douya.eventbus.BroadcastCommentSendErrorEvent) ActivityCompat(androidx.core.app.ActivityCompat) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) LayoutInflater(android.view.LayoutInflater) ViewUtils(me.zhanghai.android.douya.util.ViewUtils) DeleteBroadcastCommentManager(me.zhanghai.android.douya.broadcast.content.DeleteBroadcastCommentManager) TransitionUtils(me.zhanghai.android.douya.util.TransitionUtils) TextUtils(android.text.TextUtils) R(me.zhanghai.android.douya.R) BroadcastCommentCountFixer(me.zhanghai.android.douya.broadcast.content.BroadcastCommentCountFixer) RebroadcastBroadcastManager(me.zhanghai.android.douya.broadcast.content.RebroadcastBroadcastManager) Subscribe(org.greenrobot.eventbus.Subscribe) SendBroadcastCommentManager(me.zhanghai.android.douya.broadcast.content.SendBroadcastCommentManager) BroadcastAndCommentListResource(me.zhanghai.android.douya.broadcast.content.BroadcastAndCommentListResource) SharedElementCallback(androidx.core.app.SharedElementCallback) Activity(android.app.Activity) EditText(android.widget.EditText) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) OnVerticalScrollListener(me.zhanghai.android.douya.ui.OnVerticalScrollListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SharedElementCallback(androidx.core.app.SharedElementCallback) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)

Example 2 with SharedElementCallback

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);
        }
    });
}
Also used : Intent(android.content.Intent) SharedElementCallback(androidx.core.app.SharedElementCallback) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View)

Aggregations

View (android.view.View)2 SharedElementCallback (androidx.core.app.SharedElementCallback)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ProgressBar (android.widget.ProgressBar)1 Nullable (androidx.annotation.Nullable)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 ActivityCompat (androidx.core.app.ActivityCompat)1 ActivityOptionsCompat (androidx.core.app.ActivityOptionsCompat)1 ViewCompat (androidx.core.view.ViewCompat)1 Fragment (androidx.fragment.app.Fragment)1