Search in sources :

Example 1 with SharedElementCallback

use of android.app.SharedElementCallback in project plaid by nickbutcher.

the class DesignerNewsStory method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);
    ButterKnife.bind(this);
    story = getIntent().getParcelableExtra(EXTRA_STORY);
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
    markdown = new Bypass(this, new Bypass.Options().setBlockQuoteLineColor(ContextCompat.getColor(this, R.color.designer_news_quote_line)).setBlockQuoteLineWidth(// dps
    2).setBlockQuoteLineIndent(// dps
    8).setPreImageLinebreakHeight(//dps
    4).setBlockQuoteIndentSize(TypedValue.COMPLEX_UNIT_DIP, 2f).setBlockQuoteTextColor(ContextCompat.getColor(this, R.color.designer_news_quote)));
    circleTransform = new CircleTransform(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(new CommentAnimator(getResources().getInteger(R.integer.comment_expand_collapse_duration)));
    header = getLayoutInflater().inflate(R.layout.designer_news_story_description, commentsList, false);
    bindDescription();
    // setup title/toolbar
    if (collapsingToolbar != null) {
        // narrow device: collapsing toolbar
        collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
        collapsingToolbar.setTitle(story.title);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.story_toolbar);
        toolbar.setNavigationOnClickListener(backClick);
        commentsList.addOnScrollListener(headerScrollListener);
        setEnterSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(getIntent(), collapsingToolbar);
            }

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(collapsingToolbar);
            }
        });
    } else {
        // w600dp configuration: content card scrolls over title bar
        final TextView title = (TextView) findViewById(R.id.story_title);
        title.setText(story.title);
        findViewById(R.id.back).setOnClickListener(backClick);
    }
    final View enterCommentView = setupCommentField();
    if (story.comment_count > 0) {
        // flatten the comments from a nested structure {@see Comment#comments} to a
        // list appropriate for our adapter (using the depth attribute).
        List<Comment> flattened = new ArrayList<>(story.comment_count);
        unnestComments(story.comments, flattened);
        commentsAdapter = new DesignerNewsCommentsAdapter(header, flattened, enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    } else {
        commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<Comment>(0), enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    }
    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}
Also used : ActivityOptions(android.app.ActivityOptions) Comment(io.plaidapp.data.api.designernews.model.Comment) ArrayList(java.util.ArrayList) CircleTransform(io.plaidapp.util.glide.CircleTransform) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) ElasticDragDismissFrameLayout(io.plaidapp.ui.widget.ElasticDragDismissFrameLayout) CustomTabActivityHelper(io.plaidapp.util.customtabs.CustomTabActivityHelper) Bypass(in.uncod.android.bypass.Bypass) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) SharedElementCallback(android.app.SharedElementCallback) Toolbar(android.widget.Toolbar)

Example 2 with SharedElementCallback

use of android.app.SharedElementCallback in project plaid by nickbutcher.

the class FeedAdapter method createSharedElementReenterCallback.

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);
                }
            }
        }
    };
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) SharedElementCallback(android.app.SharedElementCallback) Map(java.util.Map) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) BadgedFourThreeImageView(io.plaidapp.ui.widget.BadgedFourThreeImageView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with SharedElementCallback

use of android.app.SharedElementCallback in project plaid by nickbutcher.

the class FeedAdapter method createDesignerNewsStoryHolder.

@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) {
        // grumble... no xml setter, grumble...
        holder.pocket.setImageAlpha(178);
        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;
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) List(java.util.List) ArrayList(java.util.ArrayList) SharedElementCallback(android.app.SharedElementCallback) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) BadgedFourThreeImageView(io.plaidapp.ui.widget.BadgedFourThreeImageView) RecyclerView(android.support.v7.widget.RecyclerView) Story(io.plaidapp.data.api.designernews.model.Story) ActivityOptions(android.app.ActivityOptions) NonNull(android.support.annotation.NonNull)

Example 4 with SharedElementCallback

use of android.app.SharedElementCallback in project android_frameworks_base by ResurrectionRemix.

the class ActivityTransition method setupHero.

private void setupHero() {
    String name = getIntent().getStringExtra(KEY_ID);
    mHero = null;
    if (name != null) {
        mHero = (ImageView) findViewById(getIdForKey(name));
        setEnterSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                sharedElements.put("hero", mHero);
            }
        });
    }
}
Also used : SharedElementCallback(android.app.SharedElementCallback) ImageView(android.widget.ImageView) View(android.view.View)

Example 5 with SharedElementCallback

use of android.app.SharedElementCallback in project android_frameworks_base by DirtyUnicorns.

the class ActivityTransition method setupHero.

private void setupHero() {
    String name = getIntent().getStringExtra(KEY_ID);
    mHero = null;
    if (name != null) {
        mHero = (ImageView) findViewById(getIdForKey(name));
        setEnterSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                sharedElements.put("hero", mHero);
            }
        });
    }
}
Also used : SharedElementCallback(android.app.SharedElementCallback) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

SharedElementCallback (android.app.SharedElementCallback)7 View (android.view.View)7 ImageView (android.widget.ImageView)5 RecyclerView (android.support.v7.widget.RecyclerView)3 TextView (android.widget.TextView)3 BindView (butterknife.BindView)3 ArrayList (java.util.ArrayList)3 ActivityOptions (android.app.ActivityOptions)2 BadgedFourThreeImageView (io.plaidapp.ui.widget.BadgedFourThreeImageView)2 List (java.util.List)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 SpannableString (android.text.SpannableString)1 Toolbar (android.widget.Toolbar)1 Bypass (in.uncod.android.bypass.Bypass)1 Comment (io.plaidapp.data.api.designernews.model.Comment)1 Story (io.plaidapp.data.api.designernews.model.Story)1 AuthorTextView (io.plaidapp.ui.widget.AuthorTextView)1