Java Code Examples for android.support.v4.app.ActivityCompat.startActivity()

The following are Jave code examples for showing how to use startActivity() of the android.support.v4.app.ActivityCompat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: robird-reborn   File: HomeActivity.java   Source Code and License Vote up 6 votes
@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
    if (menuItem.getItemId() != R.id.navigation_item_settings) {
        if (mSelectedNavigationPosition != menuItem.getOrder() ||
                mSelectedAccountId != mAccounts.get(0).id()) {
            mPager.post(new Runnable() {
                @Override
                public void run() {
                    mPager.setCurrentItem(menuItem.getOrder(), false);
                }
            });
        }

        selectNavigation(menuItem);
    } else {
        ActivityCompat.startActivity(this, new Intent(this, SettingsActivity.class), null);
    }

    return true;
}
 
Example 2
Project: AndroidOpen   File: Navigator.java   Source Code and License Vote up 6 votes
public static void launchDetail(MainActivity fromActivity, View fromView, Thing item, View backgroundView) {
    ViewCompat.setTransitionName(fromView, "detail_element");
    ViewCompat.setTransitionName(fromActivity.findViewById(R.id.fab), "fab");
    ActivityOptionsCompat options =
            TransitionHelper.makeOptionsCompat(
                    fromActivity,
                    Pair.create(fromView, "detail_element"),
                    Pair.create(fromActivity.findViewById(R.id.fab), "fab")
            );
    Intent intent = new Intent(fromActivity, MainActivity.class);
    intent.putExtra("item_text", item.text);
    intent.putExtra("fragment_resource_id", R.layout.fragment_thing_detail);

    if (backgroundView != null) BitmapUtil.storeBitmapInIntent(BitmapUtil.createBitmap(backgroundView), intent);

    ActivityCompat.startActivity(fromActivity, intent, options.toBundle());

    fromActivity.overridePendingTransition(R.anim.slide_up, R.anim.scale_down);
}
 
Example 3
Project: EsperantoRadio   File: VideoBrowserFragment.java   Source Code and License Vote up 6 votes
@Override
public void itemClicked(View view, MediaInfo item, int position) {
    if (view instanceof ImageButton) {
        Utils.showQueuePopup(getActivity(), view, item);
    } else {
        String transitionName = getString(R.string.transition_image);
        VideoListAdapter.ViewHolder viewHolder =
                (VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForPosition(position);
        Pair<View, String> imagePair = Pair
                .create((View) viewHolder.getImageView(), transitionName);
        ActivityOptionsCompat options = ActivityOptionsCompat
                .makeSceneTransitionAnimation(getActivity(), imagePair);

        Intent intent = new Intent(getActivity(), LocalPlayerActivity.class);
        intent.putExtra("media", item);
        intent.putExtra("shouldStart", false);
        ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
    }
}
 
Example 4
Project: robird-reborn   File: SignInActivity.java   Source Code and License Vote up 5 votes
@Override
public void onBackPressed() {
    if (getContentResolver().query(AccountContract.CONTENT_URI, null, null, null, null).getCount() > 0) {
        NavigationUtils.changeDefaultActivityToSignIn(getApplicationContext(), false);
        ActivityCompat.startActivity(SignInActivity.this,
                new Intent(SignInActivity.this, HomeActivity.class), null);
    }

    super.onBackPressed();
}
 
Example 5
Project: ClouldReader   File: OneMovieDetailActivity.java   Source Code and License Vote up 5 votes
/**
 * @param context      activity
 * @param positionData bean
 * @param imageView    imageView
 */
public static void start(Activity context, SubjectsBean positionData, ImageView imageView) {
    Intent intent = new Intent(context, OneMovieDetailActivity.class);
    intent.putExtra("bean", positionData);
    ActivityOptionsCompat options =
            ActivityOptionsCompat.makeSceneTransitionAnimation(context,
                    imageView, CommonUtils.getString(R.string.transition_movie_img));//与xml文件对应
    ActivityCompat.startActivity(context, intent, options.toBundle());
}
 
Example 6
Project: Mire   File: ActivityTransitionLauncher.java   Source Code and License Vote up 5 votes
public void launch(Intent intent) {

        intent.putExtras(createBundle());
        if (Build.VERSION.SDK_INT >= 16) {
            ActivityCompat.startActivity(activity, intent, createOptions());
            return;
        }
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
    }
 
Example 7
Project: Android_ImagePicker   File: PicImageActivity.java   Source Code and License Vote up 5 votes
@OnClick({R.id.main_imgPicture, R.id.main_btnPicImage, R.id.main_btnCropImage})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.main_imgPicture:
            if (selectedFilePath != null && selectedFilePath.length() > 0) {
                // Construct an Intent as normal
                Intent intent = new Intent(this, PicImageDetailActivity.class);
                intent.putExtra(PicImageDetailActivity.EXTRA_PARAM_ID, selectedFilePath);

                // BEGIN_INCLUDE(start_activity)
                /**
                 * Now create an {@link android.app.ActivityOptions} instance using the
                 * {@link ActivityOptionsCompat#makeSceneTransitionAnimation(Activity, Pair[])} factory
                 * method.
                 */
                ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                        // Now we provide a list of Pair items which contain the view we can transitioning
                        // from, and the name of the view it is transitioning to, in the launched activity
                        new Pair<View, String>(view.findViewById(R.id.main_imgPicture), PicImageDetailActivity.VIEW_NAME_HEADER_IMAGE));
                // Now we can start the Activity, providing the activity options as a bundle
                ActivityCompat.startActivity(this, intent, activityOptions.toBundle());
            }
            break;
        case R.id.main_btnPicImage:
            openImagePickerDialog(this);
            break;
        case R.id.main_btnCropImage:
            if (selectedFilePath != null && selectedFilePath.length() > 0) {
                try {
                    cropImage(selectedFilePath, getString(R.string.app_name), 1, 1, 200, 200);
                } catch (IOException e) {
                    Toast.makeText(mContext, e.getMessage().toString().trim(), Toast.LENGTH_LONG).show();
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(mContext, "Please select image first.", Toast.LENGTH_LONG).show();
            }
            break;
    }
}
 
Example 8
Project: Android-Gank-Share   File: MainActivity.java   Source Code and License Vote up 5 votes
private void startPhotoActivity(){
    Intent intent = PhotoActivity.getIntent(MainActivity.this, word.fenxiang_img, word.caption + word.dateline);
    ActivityOptionsCompat optionsCompat =  ActivityOptionsCompat
            .makeSceneTransitionAnimation(MainActivity.this, bgImg, PhotoActivity.KEY_PHOTO);
    try {
        ActivityCompat.startActivity(MainActivity.this, intent, optionsCompat.toBundle());
    }catch (IllegalArgumentException e){
        e.printStackTrace();
        startActivity(intent);
    }
}
 
Example 9
Project: GitHub   File: Router.java   Source Code and License Vote up 5 votes
public void launch() {
    try {
        if (intent != null && from != null && to != null) {

            if (callback != null) {
                callback.onBefore(from, to);
            }

            intent.setClass(from, to);

            intent.putExtras(getBundleData());

            if (options == null) {
                if (requestCode < 0) {
                    from.startActivity(intent);
                } else {
                    from.startActivityForResult(intent, requestCode);
                }

                if (enterAnim > 0 && exitAnim > 0) {
                    from.overridePendingTransition(enterAnim, exitAnim);
                }
            } else {
                if (requestCode < 0) {
                    ActivityCompat.startActivity(from, intent, options.toBundle());
                } else {
                    ActivityCompat.startActivityForResult(from, intent, requestCode, options.toBundle());
                }
            }

            if (callback != null) {
                callback.onNext(from, to);
            }
        }
    } catch (Throwable throwable) {
        if (callback != null) {
            callback.onError(from, to, throwable);
        }
    }
}
 
Example 10
Project: robird-reborn   File: TweetAdapter.java   Source Code and License Vote up 5 votes
@Override
public void onClick(View v) {
    final String url = String.format("https://twitter.com/%s/status/%d",
            tweet.quotedScreenName(), tweet.quotedId());
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    ActivityCompat.startActivity(mActivity, intent, null);
}
 
Example 11
Project: GitHub   File: SplashActivity.java   Source Code and License Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
	if (Utils.hasLollipop()) requestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS);
	super.onCreate(savedInstanceState);

	if (Utils.hasLollipop()) {
		getWindow().setExitTransition(new Fade());
	}

	Intent intent = new Intent(this, MainActivity.class);
	ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this);
	ActivityCompat.startActivity(this, intent, options.toBundle());
	ActivityCompat.finishAfterTransition(this);
}
 
Example 12
Project: whatanime-android   File: Navigator.java   Source Code and License Vote up 5 votes
public static void goToPreviewVideo(AppCompatActivity activity, String url, SearchDetail.Doc doc) {
    ActivityOptionsCompat aoc;
    aoc = ActivityOptionsCompat.makeBasic();
    Intent intent = new Intent(activity, VideoPreviewActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString(C.Extras.VIDEO_URL, url);
    bundle.putParcelable(C.Extras.DOC, doc);
    intent.putExtras(bundle);
    ActivityCompat.startActivity(activity, intent, aoc.toBundle());
}
 
Example 13
Project: pokequest   File: PokeQuizActivity.java   Source Code and License Vote up 5 votes
@OnClick(R.id.imPoke)
void onPokeClicked() {
    Pokemon pokemon = mCurPokeQuiz.getAnswer();
    Intent intent = PokeDetailActivity.createIntent(this, pokemon, mImAnswerPoke.getDrawable());
    Pair<View, String> pairIm = Pair.create((View) mImAnswerPoke, getString(R.string
            .transition_name_im_poke));
    Pair<View, String> pairTv = Pair.create((View) mTvAnswerName, getString(R
            .string.transition_name_tv_poke_name));
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this,
            pairIm, pairTv);
    ActivityCompat.startActivity(this, intent, options.toBundle());
}
 
Example 14
Project: robird-reborn   File: SearchActivity.java   Source Code and License Vote up 4 votes
public static void start(Activity activity, Account account, String query) {
    Intent intent = new Intent(activity, SearchActivity.class);
    intent.putExtra("account", account);
    intent.putExtra("query", query);
    ActivityCompat.startActivity(activity, intent, null);
}
 
Example 15
Project: RetroMusicPlayer   File: NavigationUtil.java   Source Code and License Vote up 4 votes
public static void goToAlbum(@NonNull Activity activity, int i, @Nullable Pair... pairArr) {
    Intent intent = new Intent(activity, AlbumDetailsActivity.class);
    intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, i);
    ActivityCompat.startActivity(activity, intent, ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairArr).toBundle());
}
 
Example 16
Project: GracefulMovies   File: CheckPermissionsActivity.java   Source Code and License Vote up 4 votes
/**
 * 带水波动画的Activity跳转
 */
@SuppressLint("NewApi")
protected void navigateWithRippleCompat(final Activity activity, final Intent intent,
                                        final View triggerView, @ColorRes int color) {

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ActivityOptionsCompat option = ActivityOptionsCompat.makeClipRevealAnimation(triggerView, 0, 0,
                triggerView.getMeasuredWidth(), triggerView.getMeasuredHeight());
        ActivityCompat.startActivity(activity, intent, option.toBundle());

        return;
    }

    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth() / 2;
    final int cy = location[1] + triggerView.getHeight() / 2;
    final ImageView view = new ImageView(activity);
    view.setImageResource(color);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);
    int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(500);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            activity.startActivity(intent);
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            decorView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    decorView.removeView(view);
                }
            }, 500);
        }
    });
    anim.start();
}
 
Example 17
Project: starwarsshop   File: PaymentActivity.java   Source Code and License Vote up 4 votes
public static void navigate(Activity activity) {
    Intent intent = new Intent(activity, PaymentActivity.class);
    ActivityCompat.startActivity(activity,intent, ActivityOptionsCompat.makeSceneTransitionAnimation(activity).toBundle());
}
 
Example 18
Project: robird-reborn   File: VideoActivity.java   Source Code and License Vote up 4 votes
public static void start(Activity activity, String video) {
    Intent intent = new Intent(activity, VideoActivity.class);
    intent.putExtra("video", video);
    ActivityCompat.startActivity(activity, intent, null);
}
 
Example 19
Project: Nird2   File: ContactListFragment.java   Source Code and License Vote up 4 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
		@Nullable ViewGroup container,
		@Nullable Bundle savedInstanceState) {

	getActivity().setTitle(R.string.contact_list_button);

	View contentView = inflater.inflate(R.layout.list, container, false);

	OnContactClickListener<ContactListItem> onContactClickListener =
			new OnContactClickListener<ContactListItem>() {
				@Override
				public void onItemClick(View view, ContactListItem item) {
					Intent i = new Intent(getActivity(),
							ConversationActivity.class);
					ContactId contactId = item.getContact().getId();
					i.putExtra(CONTACT_ID, contactId.getInt());

					if (Build.VERSION.SDK_INT >= 23) {
						ContactListItemViewHolder holder =
								(ContactListItemViewHolder) list
										.getRecyclerView()
										.findViewHolderForAdapterPosition(
												adapter.findItemPosition(
														item));
						Pair<View, String> avatar =
								Pair.create((View) holder.avatar,
										getTransitionName(holder.avatar));
						Pair<View, String> bulb =
								Pair.create((View) holder.bulb,
										getTransitionName(holder.bulb));
						ActivityOptionsCompat options =
								makeSceneTransitionAnimation(getActivity(),
										avatar, bulb);
						ActivityCompat.startActivity(getActivity(), i,
								options.toBundle());
					} else {
						// work-around for android bug #224270
						startActivity(i);
					}
				}
			};
	adapter = new ContactListAdapter(getContext(), onContactClickListener);
	list = (BriarRecyclerView) contentView.findViewById(R.id.list);
	list.setLayoutManager(new LinearLayoutManager(getContext()));
	list.setAdapter(adapter);
	list.setEmptyText(getString(R.string.no_contacts));

	return contentView;
}
 
Example 20
Project: quickblox-android   File: PermissionsActivity.java   Source Code and License Vote up 4 votes
public static void startActivity(Activity activity, boolean checkOnlyAudio, String... permissions) {
    Intent intent = new Intent(activity, PermissionsActivity.class);
    intent.putExtra(EXTRA_PERMISSIONS, permissions);
    intent.putExtra(CHECK_ONLY_AUDIO, checkOnlyAudio);
    ActivityCompat.startActivity(activity, intent, null);
}