Example usage for android.app ActivityOptions toBundle

List of usage examples for android.app ActivityOptions toBundle

Introduction

In this page you can find the example usage for android.app ActivityOptions toBundle.

Prototype

public Bundle toBundle() 

Source Link

Document

Returns the created options as a Bundle, which can be passed to android.content.Context#startActivity(android.content.Intent,android.os.Bundle) Context.startActivity(Intent, Bundle) and related methods.

Usage

From source file:io.plaidapp.ui.DribbbleShot.java

public void postComment(View view) {
    if (dribbblePrefs.isLoggedIn()) {
        if (TextUtils.isEmpty(enterComment.getText()))
            return;
        enterComment.setEnabled(false);//  w w  w  .j a  v  a  2 s.  c o  m
        dribbbleApi.postComment(shot.id, enterComment.getText().toString().trim(),
                new retrofit.Callback<Comment>() {
                    @Override
                    public void success(Comment comment, Response response) {
                        loadComments();
                        enterComment.getText().clear();
                        enterComment.setEnabled(true);
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        enterComment.setEnabled(true);
                    }
                });
    } else {
        Intent login = new Intent(DribbbleShot.this, DribbbleLogin.class);
        login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
                ContextCompat.getColor(this, R.color.background_light));
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this, postComment,
                getString(R.string.transition_dribbble_login));
        startActivityForResult(login, RC_LOGIN_COMMENT, options.toBundle());
    }
}

From source file:io.plaidapp.ui.FeedAdapter.java

@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/*from w  w w  .  j a v a  2 s .  co  m*/
        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) {
        holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble...
        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;
}

From source file:uk.org.downiesoft.slideshow.GridViewFragment.java

/**
 * Start the slideshow activity./*w w  w  .  j  a  va 2s  .c om*/
 * @param aFile The location of the images to be shown.
 * @param aPosition The position of the starting slide.
 * @param aAutoStart Flag indicating if the slideshow should start running immediately (true).
 * @param aOptions Activity transition options (e.g. scale-up transition option).
 */
public void startSlideshow(ZFile aFile, int aPosition, boolean aAutoStart, ActivityOptions aOptions) {
    Intent intent = new Intent(getActivity(), SlidesActivity.class);
    intent.putExtra(SlidesActivity.ARG_ZFILE, aFile.toArgs());
    intent.putExtra(SlidesActivity.ARG_START_SLIDE, aPosition);
    intent.putExtra(SlidesActivity.ARG_AUTOSTART, aAutoStart);
    if (aOptions != null) {
        startActivityForResult(intent, SlideShowActivity.REQUEST_SLIDESHOW, aOptions.toBundle());
    } else {
        startActivity(intent);
    }
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void needsLogin(View triggeringView, int requestCode) {
    Intent login = new Intent(DesignerNewsStory.this, DesignerNewsLogin.class);
    login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR,
            ContextCompat.getColor(DesignerNewsStory.this, R.color.background_light));
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DesignerNewsStory.this,
            triggeringView, getString(R.string.transition_designer_news_login));
    startActivityForResult(login, requestCode, options.toBundle());
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void needsLogin(View triggeringView, int requestCode) {
    Intent login = new Intent(DesignerNewsStory.this, DesignerNewsLogin.class);
    MorphTransform.addExtras(login, ContextCompat.getColor(this, R.color.background_light),
            triggeringView.getHeight() / 2);
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DesignerNewsStory.this,
            triggeringView, getString(R.string.transition_designer_news_login));
    startActivityForResult(login, requestCode, options.toBundle());
}

From source file:io.plaidapp.ui.DribbbleShot.java

public void postComment(View view) {
    if (dribbblePrefs.isLoggedIn()) {
        if (TextUtils.isEmpty(enterComment.getText()))
            return;
        enterComment.setEnabled(false);//from  w  w w .  j a v  a2 s.c om
        final Call<Comment> postCommentCall = dribbblePrefs.getApi().postComment(shot.id,
                enterComment.getText().toString().trim());
        postCommentCall.enqueue(new Callback<Comment>() {
            @Override
            public void onResponse(Call<Comment> call, Response<Comment> response) {
                loadComments();
                enterComment.getText().clear();
                enterComment.setEnabled(true);
            }

            @Override
            public void onFailure(Call<Comment> call, Throwable t) {
                enterComment.setEnabled(true);
            }
        });
    } else {
        Intent login = new Intent(DribbbleShot.this, DribbbleLogin.class);
        FabTransform.addExtras(login, ContextCompat.getColor(DribbbleShot.this, R.color.background_light),
                R.drawable.ic_comment_add);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this, postComment,
                getString(R.string.transition_dribbble_login));
        startActivityForResult(login, RC_LOGIN_COMMENT, options.toBundle());
    }
}

From source file:io.plaidapp.ui.DribbbleShot.java

void bindShot(final boolean postponeEnterTransition) {
    final Resources res = getResources();

    // load the main image
    final int[] imageSize = shot.images.bestSize();
    Glide.with(this).load(shot.images.best()).listener(shotLoadListener)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE)
            .override(imageSize[0], imageSize[1]).into(imageView);
    imageView.setOnClickListener(shotClick);
    shotSpacer.setOnClickListener(shotClick);

    if (postponeEnterTransition)
        postponeEnterTransition();/*  w w  w  . java  2s .c o  m*/
    imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            imageView.getViewTreeObserver().removeOnPreDrawListener(this);
            calculateFabPosition();
            if (postponeEnterTransition)
                startPostponedEnterTransition();
            return true;
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ((FabOverlapTextView) title).setText(shot.title);
    } else {
        ((TextView) title).setText(shot.title);
    }
    if (!TextUtils.isEmpty(shot.description)) {
        final Spanned descText = shot.getParsedDescription(
                ContextCompat.getColorStateList(this, R.color.dribbble_links),
                ContextCompat.getColor(this, R.color.dribbble_link_highlight));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            ((FabOverlapTextView) description).setText(descText);
        } else {
            HtmlUtils.setTextWithNiceLinks((TextView) description, descText);
        }
    } else {
        description.setVisibility(View.GONE);
    }
    NumberFormat nf = NumberFormat.getInstance();
    likeCount.setText(
            res.getQuantityString(R.plurals.likes, (int) shot.likes_count, nf.format(shot.likes_count)));
    likeCount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) likeCount.getCompoundDrawables()[1]).start();
            if (shot.likes_count > 0) {
                PlayerSheet.start(DribbbleShot.this, shot);
            }
        }
    });
    if (shot.likes_count == 0) {
        likeCount.setBackground(null); // clear touch ripple if doesn't do anything
    }
    viewCount.setText(
            res.getQuantityString(R.plurals.views, (int) shot.views_count, nf.format(shot.views_count)));
    viewCount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) viewCount.getCompoundDrawables()[1]).start();
        }
    });
    share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            new ShareDribbbleImageTask(DribbbleShot.this, shot).execute();
        }
    });
    if (shot.user != null) {
        playerName.setText(shot.user.name.toLowerCase());
        Glide.with(this).load(shot.user.getHighQualityAvatarUrl()).transform(circleTransform)
                .placeholder(R.drawable.avatar_placeholder).override(largeAvatarSize, largeAvatarSize)
                .into(playerAvatar);
        View.OnClickListener playerClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent player = new Intent(DribbbleShot.this, PlayerActivity.class);
                if (shot.user.shots_count > 0) { // legit user object
                    player.putExtra(PlayerActivity.EXTRA_PLAYER, shot.user);
                } else {
                    // search doesn't fully populate the user object,
                    // in this case send the ID not the full user
                    player.putExtra(PlayerActivity.EXTRA_PLAYER_NAME, shot.user.username);
                    player.putExtra(PlayerActivity.EXTRA_PLAYER_ID, shot.user.id);
                }
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this,
                        playerAvatar, getString(R.string.transition_player_avatar));
                startActivity(player, options.toBundle());
            }
        };
        playerAvatar.setOnClickListener(playerClick);
        playerName.setOnClickListener(playerClick);
        if (shot.created_at != null) {
            shotTimeAgo
                    .setText(
                            DateUtils
                                    .getRelativeTimeSpanString(shot.created_at.getTime(),
                                            System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)
                                    .toString().toLowerCase());
        }
    } else {
        playerName.setVisibility(View.GONE);
        playerAvatar.setVisibility(View.GONE);
        shotTimeAgo.setVisibility(View.GONE);
    }

    commentAnimator = new CommentAnimator();
    commentsList.setItemAnimator(commentAnimator);
    adapter = new CommentsAdapter(shotDescription, commentFooter, shot.comments_count,
            getResources().getInteger(R.integer.comment_expand_collapse_duration));
    commentsList.setAdapter(adapter);
    commentsList.addItemDecoration(new InsetDividerDecoration(CommentViewHolder.class,
            res.getDimensionPixelSize(R.dimen.divider_height), res.getDimensionPixelSize(R.dimen.keyline_1),
            ContextCompat.getColor(this, R.color.divider)));
    if (shot.comments_count != 0) {
        loadComments();
    }
    checkLiked();
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

boolean startActivity(View v, Intent intent, Object tag) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {/*  w  w  w. jav a 2  s  .c  o  m*/
        // Only launch using the new animation if the shortcut has not opted out (this is a
        // private contract between launcher and may be ignored in the future).
        boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
        UserManagerCompat userManager = UserManagerCompat.getInstance(this);

        UserHandleCompat user = null;
        if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
            long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
            user = userManager.getUserForSerialNumber(serialNumber);
        }

        Bundle optsBundle = null;
        if (useLaunchAnimation) {
            ActivityOptions opts = Utilities.isLmpOrAbove()
                    ? ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim)
                    : ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(),
                            v.getMeasuredHeight());
            optsBundle = opts.toBundle();
        }

        if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
            // Could be launching some bookkeeping activity
            startActivity(intent, optsBundle);
        } else {
            // TODO Component can be null when shortcuts are supported for secondary user
            launcherApps.startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(),
                    optsBundle);
        }
        return true;
    } catch (SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Launcher does not have the permission to launch " + intent
                + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e);
    }
    return false;
}

From source file:com.android.soma.Launcher.java

boolean startActivity(View v, Intent intent, Object tag) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    try {/*from  w ww  .ja  v  a 2s . c  om*/
        // Only launch using the new animation if the shortcut has not opted out (this is a
        // private contract between launcher and may be ignored in the future).
        boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
        if (useLaunchAnimation) {
            ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(),
                    v.getMeasuredHeight());

            startActivity(intent, opts.toBundle());
        } else {
            startActivity(intent);
        }
        return true;
    } catch (SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Launcher does not have the permission to launch " + intent
                + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e);
    }
    return false;
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

private boolean startActivity(View v, Intent intent, Object tag) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {/*from ww  w . j ava2 s . c  om*/
        // Only launch using the new animation if the shortcut has not opted out (this is a
        // private contract between launcher and may be ignored in the future).
        boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
        UserManagerCompat userManager = UserManagerCompat.getInstance(this);

        UserHandleCompat user = null;
        if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
            long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
            user = userManager.getUserForSerialNumber(serialNumber);
        }

        Bundle optsBundle = null;
        if (useLaunchAnimation) {
            ActivityOptions opts = null;
            if (Utilities.ATLEAST_MARSHMALLOW) {
                int left = 0, top = 0;
                int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
                if (v instanceof TextView) {
                    // Launch from center of icon, not entire view
                    Drawable icon = Workspace.getTextViewIcon((TextView) v);
                    if (icon != null) {
                        Rect bounds = icon.getBounds();
                        left = (width - bounds.width()) / 2;
                        top = v.getPaddingTop();
                        width = bounds.width();
                        height = bounds.height();
                    }
                }
                opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
            } else if (!Utilities.ATLEAST_LOLLIPOP) {
                // Below L, we use a scale up animation
                opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(),
                        v.getMeasuredHeight());
            } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
                // On L devices, we use the device default slide-up transition.
                // On L MR1 devices, we a custom version of the slide-up transition which
                // doesn't have the delay present in the device default.
                opts = ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim);
            }
            optsBundle = opts != null ? opts.toBundle() : null;
        }

        if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
            StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
            try {
                // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
                // containing file Uris would cause a crash as penaltyDeathOnFileUriExposure
                // is enabled by default on NYC.
                StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
                // Could be launching some bookkeeping activity
                startActivity(intent, optsBundle);
            } finally {
                StrictMode.setVmPolicy(oldPolicy);
            }
        } else {
            // TODO Component can be null when shortcuts are supported for secondary user
            launcherApps.startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(),
                    optsBundle);
        }
        return true;
    } catch (SecurityException e) {
        if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
            // Due to legacy reasons, direct call shortcuts require Launchers to have the
            // corresponding permission. Show the appropriate permission prompt if that
            // is the case.
            if (intent.getComponent() == null && Intent.ACTION_CALL.equals(intent.getAction())
                    && checkSelfPermission(
                            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Rename sPendingAddItem to a generic name.
                sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent, 0,
                        (ItemInfo) tag);
                requestPermissions(new String[] { Manifest.permission.CALL_PHONE },
                        REQUEST_PERMISSION_CALL_PHONE);
                return false;
            }
        }
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Launcher does not have the permission to launch " + intent
                + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e);
    }
    return false;
}