Java Code Examples for androidx.appcompat.app.AppCompatActivity#startActivity()

The following examples show how to use androidx.appcompat.app.AppCompatActivity#startActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkHandler.java    From RedReader with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(18)
public static void openCustomTab(AppCompatActivity activity, Uri uri) {
	Intent intent = new Intent();
	intent.setAction(Intent.ACTION_VIEW);
	intent.setData(uri);
	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

	Bundle bundle = new Bundle();
	bundle.putBinder("android.support.customtabs.extra.SESSION", null);
	intent.putExtras(bundle);

	intent.putExtra("android.support.customtabs.extra.SHARE_MENU_ITEM", true);

	TypedValue typedValue = new TypedValue();
	activity.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);

	intent.putExtra("android.support.customtabs.extra.TOOLBAR_COLOR", typedValue.data);

	intent.putExtra("android.support.customtabs.extra.ENABLE_URLBAR_HIDING", true);

	activity.startActivity(intent);
}
 
Example 2
Source File: LinkHandler.java    From RedReader with GNU General Public License v3.0 6 votes vote down vote up
public static void shareText(
		@NonNull final AppCompatActivity activity,
		@Nullable final String subject,
		@NonNull final String text) {

	final Intent mailer = new Intent(Intent.ACTION_SEND);
	mailer.setType("text/plain");
	mailer.putExtra(Intent.EXTRA_TEXT, text);

	if(subject != null) {
		mailer.putExtra(Intent.EXTRA_SUBJECT, subject);
	}

	if(PrefsUtility.pref_behaviour_sharing_dialog(
			activity,
			PreferenceManager.getDefaultSharedPreferences(activity))) {
		ShareOrderDialog.newInstance(mailer).show(
				activity.getSupportFragmentManager(),
				null);

	} else {
		activity.startActivity(Intent.createChooser(
				mailer,
				activity.getString(R.string.action_share)));
	}
}
 
Example 3
Source File: RedditPreparedMessage.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
private void openReplyActivity(final AppCompatActivity activity) {

		final Intent intent = new Intent(activity, CommentReplyActivity.class);
		intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, idAndType);
		intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, src.getUnescapedBodyMarkdown());
		intent.putExtra(CommentReplyActivity.PARENT_TYPE, CommentReplyActivity.PARENT_TYPE_MESSAGE);
		activity.startActivity(intent);
	}
 
Example 4
Source File: General.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
public static void recreateActivityNoAnimation(final AppCompatActivity activity) {

		// http://stackoverflow.com/a/3419987/1526861
		final Intent intent = activity.getIntent();
		activity.overridePendingTransition(0, 0);
		intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
		activity.finish();
		activity.overridePendingTransition(0, 0);
		activity.startActivity(intent);
	}
 
Example 5
Source File: LinkHandler.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
public static void onActionMenuItemSelected(String uri, AppCompatActivity activity, LinkAction action){
	switch (action){
		case SHARE:
			shareText(activity, null, uri);
			break;
		case COPY_URL:
			ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
			manager.setText(uri);
			break;

		case EXTERNAL:
			try {
				final Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri.parse(uri));
				activity.startActivity(intent);
			} catch(final ActivityNotFoundException e) {
				General.quickToast(activity, R.string.error_no_suitable_apps_available);
			}
			break;
		case SHARE_IMAGE:
			((BaseActivity)activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new ShareImageCallback(activity, uri));
			break;
		case SAVE_IMAGE:
			((BaseActivity)activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new SaveImageCallback(activity, uri));
			break;
	}
}
 
Example 6
Source File: BigImageActivity.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public static void startThis(AppCompatActivity activity, String url, View shareView) {
    Intent intent = new Intent(activity, BigImageActivity.class);
    intent.putExtra("image", url);
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(activity, shareView, "big_image");
    activity.startActivity(intent, options.toBundle());
}
 
Example 7
Source File: SongMenuHelper.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean handleMenuClick(@NonNull AppCompatActivity activity, @NonNull Song song, int string_res_option) {
    switch (string_res_option) {
        case R.string.play_preview:
            if(activity instanceof MainActivity) {
                ((MainActivity)activity).getSongPreviewController().previewSongs(song);
            }
            break;
        case R.string.play_preview_all:
            if(activity instanceof BaseActivity) {
                SongPreviewController preview = ((MainActivity) activity).getSongPreviewController();
                if (preview != null) {
                    if (preview.isPlayingPreview())
                        preview.cancelPreview();
                    else {
                        ArrayList<Song> list = SongLoader.getAllSongs(activity);
                        Collections.shuffle(list);
                        int index = 0;
                        for (int i = 0; i < list.size(); i++) {
                            if(song.id==list.get(i).id) index = i;
                        }

                        if(index!=0)
                        list.add(0,list.remove(index));
                        preview.previewSongs(list);
                    }
                }
            }
            break;
        case R.string.set_as_ringtone:
            if (RingtoneManager.requiresDialog(activity)) {
                RingtoneManager.showDialog(activity);
            } else {
                RingtoneManager ringtoneManager = new RingtoneManager();
                ringtoneManager.setRingtone(activity, song.id);
            }
            return true;
        case R.string.share:
            activity.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, activity), null));
            return true;
        case R.string.delete_from_device:
            DeleteSongsDialog.create(song).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
            return true;
        case R.string.add_to_playlist:
            AddToPlaylistDialog.create(song).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
            return true;
        case R.string.repeat_it_again:
        case R.string.play_next:
            MusicPlayerRemote.playNext(song);
            return true;
        case R.string.add_to_queue:
            MusicPlayerRemote.enqueue(song);
            return true;
        case R.string.show_lyric:
            LyricBottomSheet.newInstance(song).show(activity.getSupportFragmentManager(),LyricBottomSheet.TAG);
            break;
        case R.string.edit_tag:
            return true;
        case R.string.detail:
            //  SongDetailDialog.create(song).show(activity.getSupportFragmentManager(), "SONG_DETAILS");
            return true;
        case R.string.go_to_album:
            // NavigationUtil.goToAlbum(activity, song.albumId);
            return true;
        case R.string.go_to_artist:
            NavigationUtil.navigateToArtist(activity, song.artistId);
            return true;
    }
    return false;
}
 
Example 8
Source File: Utils.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handles gesture actions based on the direction of the gesture.
 *
 * @param activity  The activity where the gesture is performed.
 * @param direction The direction of the gesture.
 *
 * @see Gesture Valid directions for the gestures.
 */
public static void handleGestureActions(AppCompatActivity activity, int direction) {
    UserUtils userUtils = new UserUtils(activity);

    switch (PreferenceHelper.getGestureForDirection(direction)) {
        case "handler":
            if (PreferenceHelper.getGestureHandler() != null) {
                Intent handlerIntent = new Intent("mono.hg.GESTURE_HANDLER");
                handlerIntent.setComponent(PreferenceHelper.getGestureHandler());
                handlerIntent.setType("text/plain");
                handlerIntent.putExtra("direction", direction);
                activity.startActivity(handlerIntent);
            }
            break;
        case "widget":
            WidgetsDialogFragment widgetFragment = new WidgetsDialogFragment();
            widgetFragment.show(activity.getSupportFragmentManager(), "Widgets Dialog");
            break;
        case "status":
            ActivityServiceUtils.expandStatusBar(activity);
            break;
        case "panel":
            ActivityServiceUtils.expandSettingsPanel(activity);
            break;
        case "list":
            // TODO: Maybe make this call less reliant on LauncherActivity?
            ((LauncherActivity) activity).doThis("show_panel");
            break;
        case "none":
            // We don't want to do anything.
            break;
        default:
            try {
                AppUtils.quickLaunch(activity,
                        PreferenceHelper.getGestureForDirection(direction));
            } catch (ActivityNotFoundException w) {
                // Maybe the user had an old configuration, but otherwise, this is harmless.
                // We should still notify them though.
                Toast.makeText(activity, activity.getString(R.string.err_activity_null), Toast.LENGTH_LONG).show();
            }
            break;
    }
}
 
Example 9
Source File: Util.java    From Audinaut with GNU General Public License v3.0 4 votes vote down vote up
public static void startActivityWithoutTransition(AppCompatActivity currentActivity, Intent intent) {
    currentActivity.startActivity(intent);
}
 
Example 10
Source File: Utils.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handles gesture actions based on the direction of the gesture.
 *
 * @param activity  The activity where the gesture is performed.
 * @param direction The direction of the gesture.
 *
 * @see Gesture Valid directions for the gestures.
 */
public static void handleGestureActions(AppCompatActivity activity, int direction) {
    UserUtils userUtils = new UserUtils(activity);

    switch (PreferenceHelper.getGestureForDirection(direction)) {
        case "handler":
            if (PreferenceHelper.getGestureHandler() != null) {
                Intent handlerIntent = new Intent("mono.hg.GESTURE_HANDLER");
                handlerIntent.setComponent(PreferenceHelper.getGestureHandler());
                handlerIntent.setType("text/plain");
                handlerIntent.putExtra("direction", direction);
                activity.startActivity(handlerIntent);
            }
            break;
        case "widget":
            WidgetsDialogFragment widgetFragment = new WidgetsDialogFragment();
            widgetFragment.show(activity.getSupportFragmentManager(), "Widgets Dialog");
            break;
        case "status":
            ActivityServiceUtils.expandStatusBar(activity);
            break;
        case "panel":
            ActivityServiceUtils.expandSettingsPanel(activity);
            break;
        case "list":
            // TODO: Maybe make this call less reliant on LauncherActivity?
            ((LauncherActivity) activity).doThis("show_panel");
            break;
        case "none":
            // We don't want to do anything.
            break;
        default:
            try {
                AppUtils.quickLaunch(activity,
                        PreferenceHelper.getGestureForDirection(direction));
            } catch (ActivityNotFoundException w) {
                // Maybe the user had an old configuration, but otherwise, this is harmless.
                // We should still notify them though.
                Toast.makeText(activity, activity.getString(R.string.err_activity_null), Toast.LENGTH_LONG).show();
            }
            break;
    }
}
 
Example 11
Source File: BigImagePagerActivity.java    From CloudReader with Apache License 2.0 4 votes vote down vote up
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);
        }
    });
}
 
Example 12
Source File: WelcomeActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
public static void launch(AppCompatActivity activity) {
    Intent intent = new Intent(activity, WelcomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    activity.startActivity(intent);
    activity.overridePendingTransition(0, 0);
}
 
Example 13
Source File: AppData.java    From MaterialScrollBar with Apache License 2.0 4 votes vote down vote up
private static void openMainActivity(AppCompatActivity activity) {
    Intent main = new Intent(activity.getApplicationContext(), MainActivity.class);
    activity.startActivity(main);
}
 
Example 14
Source File: MainMenuListingManager.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
private void onSubredditActionMenuItemSelected(
		final SubredditCanonicalId subredditCanonicalId,
		final AppCompatActivity activity,
		final SubredditAction action) {

	final String url = Constants.Reddit.getNonAPIUri(subredditCanonicalId.toString()).toString();

	RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager
			.getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount());

	switch (action) {
		case SHARE: {
			LinkHandler.shareText(activity, subredditCanonicalId.toString(), url);
			break;
		}

		case COPY_URL: {
			ClipboardManager manager = (ClipboardManager)activity.getSystemService(Context.CLIPBOARD_SERVICE);
			manager.setText(url);
			break;
		}

		case EXTERNAL: {
			final Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.setData(Uri.parse(url));
			activity.startActivity(intent);
			break;
		}

		case PIN:
			PrefsUtility.pref_pinned_subreddits_add(
					mActivity,
					PreferenceManager.getDefaultSharedPreferences(mActivity),
					subredditCanonicalId);
			break;

		case UNPIN:
			PrefsUtility.pref_pinned_subreddits_remove(
					mActivity,
					PreferenceManager.getDefaultSharedPreferences(mActivity),
					subredditCanonicalId);
			break;

		case BLOCK:
			PrefsUtility.pref_blocked_subreddits_add(
					mActivity,
					PreferenceManager.getDefaultSharedPreferences(mActivity),
					subredditCanonicalId);
			break;

		case UNBLOCK:
			PrefsUtility.pref_blocked_subreddits_remove(
					mActivity,
					PreferenceManager.getDefaultSharedPreferences(mActivity),
					subredditCanonicalId);
			break;

		case SUBSCRIBE:

			if (subMan.getSubscriptionState(subredditCanonicalId) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED){
				subMan.subscribe(subredditCanonicalId, activity);
				setPinnedSubreddits();
				setBlockedSubreddits();
				Toast.makeText(mActivity, R.string.options_subscribing, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(mActivity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show();
			}
			break;

		case UNSUBSCRIBE:

			if (subMan.getSubscriptionState(subredditCanonicalId) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED){
				subMan.unsubscribe(subredditCanonicalId, activity);
				setPinnedSubreddits();
				setBlockedSubreddits();
				Toast.makeText(mActivity, R.string.options_unsubscribing , Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(mActivity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show();
			}
			break;
	}
}