Example usage for android.view MenuItem getIntent

List of usage examples for android.view MenuItem getIntent

Introduction

In this page you can find the example usage for android.view MenuItem getIntent.

Prototype

public Intent getIntent();

Source Link

Document

Return the Intent associated with this item.

Usage

From source file:com.android.music.TrackBrowserFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case PLAY_SELECTION: {
        // play the track
        int position = mSelectedPosition;
        MusicUtils.playAll(getActivity(), mTrackCursor, position);
        return true;
    }/*  ww  w.  j a v  a  2 s .  co m*/

    case QUEUE: {
        long[] list = new long[] { mSelectedId };
        MusicUtils.addToCurrentPlaylist(getActivity(), list);
        return true;
    }

    case NEW_PLAYLIST: {
        Intent intent = new Intent();
        intent.setClass(getActivity(), CreatePlaylist.class);
        startActivityForResult(intent, NEW_PLAYLIST);
        return true;
    }

    case PLAYLIST_SELECTED: {
        long[] list = new long[] { mSelectedId };
        long playlist = item.getIntent().getLongExtra("playlist", 0);
        MusicUtils.addToPlaylist(getActivity(), list, playlist);
        return true;
    }

    case USE_AS_RINGTONE:
        // Set the system setting to make this the current ringtone
        MusicUtils.setRingtone(getActivity(), mSelectedId);
        return true;

    case DELETE_ITEM: {
        long[] list = new long[1];
        list[0] = (int) mSelectedId;
        Bundle b = new Bundle();
        String f;
        if (android.os.Environment.isExternalStorageRemovable()) {
            f = getString(R.string.delete_song_desc);
        } else {
            f = getString(R.string.delete_song_desc_nosdcard);
        }
        String desc = String.format(f, mCurrentTrackName);
        b.putString("description", desc);
        b.putLongArray("items", list);
        Intent intent = new Intent();
        intent.setClass(getActivity(), DeleteItems.class);
        intent.putExtras(b);
        startActivityForResult(intent, -1);
        return true;
    }

    case REMOVE:
        removePlaylistItem(mSelectedPosition);
        return true;

    case SEARCH:
        doSearch();
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:com.cyanogenmod.eleven.utils.PopupMenuHelper.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    if (item.getGroupId() == getGroupId()) {
        switch (item.getItemId()) {
        case FragmentMenuItems.REMOVE_FROM_RECENT:
            RecentStore.getInstance(mActivity).removeItem(getId());
            MusicUtils.refresh();/*w  w w  .j  a v a2  s  .  c  om*/
            return true;
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(mActivity, getIdList(), 0, getSourceId(), getSourceType(), false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(mActivity, getIdList(), getSourceId(), getSourceType());
            return true;
        case FragmentMenuItems.ADD_TO_PLAYLIST:
            ContextMenuBuilder builder = new ContextMenuBuilder(mActivity);
            MusicUtils.makePlaylistMenu(mActivity, getGroupId(), builder);
            builder.setHeaderTitle(R.string.add_to_playlist);
            builder.setCallback(new MenuBuilder.Callback() {
                @Override
                public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
                    return onMenuItemClick(item);
                }

                @Override
                public void onMenuModeChange(MenuBuilder menu) {
                    // do nothing
                }
            });
            builder.show(null, null);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(getIdList()).show(mFragmentManager, "CreatePlaylist");
            return true;
        case FragmentMenuItems.RENAME_PLAYLIST:
            RenamePlaylist.getInstance(getId()).show(mFragmentManager, "RenameDialog");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(mActivity, getIdList(), mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(mActivity, getArtistName());
            return true;
        case FragmentMenuItems.DELETE:
            onDeleteClicked();
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(mActivity, getId());
            return true;
        case FragmentMenuItems.REMOVE_FROM_PLAYLIST:
            removeFromPlaylist();
            return true;
        case FragmentMenuItems.REMOVE_FROM_QUEUE:
            removeFromQueue();
            return true;
        case FragmentMenuItems.PLAY_NEXT:
            playNext();
            return true;
        case FragmentMenuItems.PLAY_ALBUM:
            playAlbum();
            return true;
        default:
            break;
        }
    }

    return false;
}

From source file:de.vanita5.twittnuker.fragment.support.UserListDetailsFragment.java

@Override
public boolean onMenuItemClick(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    if (twitter == null || userList == null)
        return false;
    switch (item.getItemId()) {
    case MENU_ADD: {
        if (userList.user_id != userList.account_id)
            return false;
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, userList.account_id);
        startActivityForResult(intent, REQUEST_SELECT_USER);
        break;// www.  ja  v a2 s.  c om
    }
    case MENU_DELETE: {
        if (userList.user_id != userList.account_id)
            return false;
        DestroyUserListDialogFragment.show(getFragmentManager(), userList);
        break;
    }
    case MENU_EDIT: {
        final Bundle args = new Bundle();
        args.putLong(EXTRA_ACCOUNT_ID, userList.account_id);
        args.putString(EXTRA_LIST_NAME, userList.name);
        args.putString(EXTRA_DESCRIPTION, userList.description);
        args.putBoolean(EXTRA_IS_PUBLIC, userList.is_public);
        args.putLong(EXTRA_LIST_ID, userList.id);
        final DialogFragment f = new EditUserListDialogFragment();
        f.setArguments(args);
        f.show(getFragmentManager(), "edit_user_list_details");
        return true;
    }
    case MENU_FOLLOW: {
        if (userList.is_following) {
            DestroyUserListSubscriptionDialogFragment.show(getFragmentManager(), userList);
        } else {
            twitter.createUserListSubscriptionAsync(userList.account_id, userList.id);
        }
        return true;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                if (Utils.isDebugBuild())
                    Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:de.vanita5.twittnuker.fragment.support.UserListFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    if (twitter == null || userList == null)
        return false;
    switch (item.getItemId()) {
    case MENU_ADD: {
        if (userList.user_id != userList.account_id)
            return false;
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, userList.account_id);
        startActivityForResult(intent, REQUEST_SELECT_USER);
        break;/* w  w w. j  a  v  a 2  s  . c  om*/
    }
    case MENU_DELETE: {
        if (userList.user_id != userList.account_id)
            return false;
        DestroyUserListDialogFragment.show(getFragmentManager(), userList);
        break;
    }
    case MENU_EDIT: {
        final Bundle args = new Bundle();
        args.putLong(EXTRA_ACCOUNT_ID, userList.account_id);
        args.putString(EXTRA_LIST_NAME, userList.name);
        args.putString(EXTRA_DESCRIPTION, userList.description);
        args.putBoolean(EXTRA_IS_PUBLIC, userList.is_public);
        args.putLong(EXTRA_LIST_ID, userList.id);
        final DialogFragment f = new EditUserListDialogFragment();
        f.setArguments(args);
        f.show(getFragmentManager(), "edit_user_list_details");
        return true;
    }
    case MENU_FOLLOW: {
        if (userList.is_following) {
            DestroyUserListSubscriptionDialogFragment.show(getFragmentManager(), userList);
        } else {
            twitter.createUserListSubscriptionAsync(userList.account_id, userList.id);
        }
        return true;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                if (Utils.isDebugBuild())
                    Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:com.android.music.MediaPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    badSymptoms.saveMenu("menu", item.toString());

    Intent intent;//from   w ww. ja v a 2s.co  m
    try {
        switch (item.getItemId()) {
        case GOTO_START:
            intent = new Intent();
            intent.setClass(this, MusicBrowserActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
            break;
        case USE_AS_RINGTONE: {
            // Set the system setting to make this the current ringtone
            if (mService != null) {
                MusicUtils.setRingtone(this, mService.getAudioId());
            }
            return true;
        }
        case PARTY_SHUFFLE:
            MusicUtils.togglePartyShuffle();
            setShuffleButtonImage();
            break;

        case NEW_PLAYLIST: {
            intent = new Intent();
            intent.setClass(this, CreatePlaylist.class);
            startActivityForResult(intent, NEW_PLAYLIST);
            return true;
        }

        case PLAYLIST_SELECTED: {
            long[] list = new long[1];
            list[0] = MusicUtils.getCurrentAudioId();
            long playlist = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(this, list, playlist);
            return true;
        }

        case DELETE_ITEM: {
            if (mService != null) {
                long[] list = new long[1];
                list[0] = MusicUtils.getCurrentAudioId();
                Bundle b = new Bundle();
                String f;
                if (android.os.Environment.isExternalStorageRemovable()) {
                    f = getString(R.string.delete_song_desc, mService.getTrackName());
                } else {
                    f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName());
                }
                b.putString("description", f);
                b.putLongArray("items", list);
                intent = new Intent();
                intent.setClass(this, DeleteItems.class);
                intent.putExtras(b);
                startActivityForResult(intent, -1);
            }
            return true;
        }

        case EFFECTS_PANEL: {
            Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
            i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mService.getAudioSessionId());
            startActivityForResult(i, EFFECTS_PANEL);
            return true;
        }
        }
    } catch (RemoteException ex) {
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.vanita5.twittnuker.fragment.support.BaseStatusesStaggeredGridFragment.java

@Override
public final boolean onMenuItemClick(final MenuItem item) {
    final ParcelableStatus status = mSelectedStatus;
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    if (status == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_VIEW: {
        openStatus(getActivity(), status);
        break;//www  . j  a v a 2  s.  c o m
    }
    case MENU_SHARE: {
        startStatusShareChooser(getActivity(), status);
        break;
    }
    case MENU_COPY: {
        if (ClipboardUtils.setText(getActivity(), status.text_plain)) {
            showOkMessage(getActivity(), R.string.text_copied, false);
        }
        break;
    }
    case MENU_RETWEET: {
        retweet(status, twitter);
        break;
    }
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_QUOTE);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_STATUS, status);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_LOVE: {
        retweet(status, twitter);
        favorite(status, twitter);
        break;
    }
    case MENU_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_REPLY);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_STATUS, status);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_FAVORITE: {
        favorite(status, twitter);
        break;
    }
    case MENU_DELETE: {
        twitter.destroyStatusAsync(status.account_id, status.id);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        AddStatusFilterDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_MULTI_SELECT: {
        final boolean isSelected = !mMultiSelectManager.isSelected(status);
        setItemSelected(status, mSelectedPosition, isSelected);
        break;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                if (Utils.isDebugBuild())
                    Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.UserListFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = mTwitterWrapper;
    final ParcelableUserList userList = mUserList;
    if (twitter == null || userList == null)
        return false;
    switch (item.getItemId()) {
    case R.id.add: {
        if (!userList.user_key.equals(userList.account_key))
            return false;
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_KEY, userList.account_key);
        startActivityForResult(intent, REQUEST_SELECT_USER);
        break;// ww w  .  j  a  v  a2  s . c  o m
    }
    case R.id.delete: {
        if (!userList.user_key.equals(userList.account_key))
            return false;
        DestroyUserListDialogFragment.show(getFragmentManager(), userList);
        break;
    }
    case R.id.edit: {
        final Bundle args = new Bundle();
        args.putParcelable(EXTRA_ACCOUNT_KEY, userList.account_key);
        args.putString(EXTRA_LIST_NAME, userList.name);
        args.putString(EXTRA_DESCRIPTION, userList.description);
        args.putBoolean(EXTRA_IS_PUBLIC, userList.is_public);
        args.putString(EXTRA_LIST_ID, userList.id);
        final DialogFragment f = new EditUserListDialogFragment();
        f.setArguments(args);
        f.show(getFragmentManager(), "edit_user_list_details");
        return true;
    }
    case R.id.follow: {
        if (userList.is_following) {
            DestroyUserListSubscriptionDialogFragment.show(getFragmentManager(), userList);
        } else {
            twitter.createUserListSubscriptionAsync(userList.account_key, userList.id);
        }
        return true;
    }
    case R.id.open_with_account: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(getActivity(), AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.mariotaku.twidere.activity.ComposeActivity.java

@Override
public boolean onMenuItemClick(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_TAKE_PHOTO: {
        takePhoto();/*from ww  w . j  a v a  2 s  .c om*/
        break;
    }
    case MENU_ADD_IMAGE: {
        pickImage();
        break;
    }
    case MENU_ADD_LOCATION: {
        final boolean attach_location = mPreferences.getBoolean(PREFERENCE_KEY_ATTACH_LOCATION, false);
        if (!attach_location) {
            getLocation();
        }
        mPreferences.edit().putBoolean(PREFERENCE_KEY_ATTACH_LOCATION, !attach_location).commit();
        setMenu();
        break;
    }
    case MENU_DRAFTS: {
        startActivity(new Intent(INTENT_ACTION_DRAFTS));
        break;
    }
    case MENU_DELETE: {
        if (mImageUri == null)
            return false;
        if (mIsPhotoAttached && !mIsImageAttached) {
            final File image_file = "file".equals(mImageUri.getScheme()) ? new File(mImageUri.getPath()) : null;
            if (image_file != null) {
                image_file.delete();
            }
        }
        mImageUri = null;
        mIsPhotoAttached = false;
        mIsImageAttached = false;
        reloadAttachedImageThumbnail(null);
        setMenu();
        break;
    }
    case MENU_VIEW: {
        openImage(this, mImageUri, false);
        break;
    }
    case MENU_TOGGLE_SENSITIVE: {
        final boolean has_media = (mIsImageAttached || mIsPhotoAttached) && mImageUri != null;
        if (!has_media)
            return false;
        mIsPossiblySensitive = !mIsPossiblySensitive;
        setMenu();
        break;
    }
    default: {
        final Intent intent = item.getIntent();
        if (intent != null) {
            try {
                if (INTENT_ACTION_EXTENSION_COMPOSE.equals(intent.getAction())) {
                    startActivityForResult(intent, REQUEST_EXTENSION_COMPOSE);
                } else if (INTENT_ACTION_EXTENSION_EDIT_IMAGE.equals(intent.getAction())) {
                    startActivityForResult(intent, REQUEST_EDIT_IMAGE);
                } else {
                    startActivity(intent);
                }
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;// w  w w . j  av  a  2  s.co m
    try {
        switch (item.getItemId()) {
        case GOTO_START:
            intent = new Intent();
            intent.setClass(this, MusicBrowserActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
            break;
        case USE_AS_RINGTONE: {
            // Set the system setting to make this the current ringtone
            if (mService != null) {
                MusicUtils.setRingtone(this, mService.getAudioId());
            }
            return true;
        }
        case PARTY_SHUFFLE:
            MusicUtils.togglePartyShuffle();
            setShuffleButtonImage();
            break;

        case NEW_PLAYLIST: {
            intent = new Intent();
            intent.setClass(this, CreatePlaylist.class);
            startActivityForResult(intent, NEW_PLAYLIST);
            return true;
        }

        case PLAYLIST_SELECTED: {
            long[] list = new long[1];
            list[0] = MusicUtils.getCurrentAudioId();
            long playlist = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(this, list, playlist);
            return true;
        }

        case DELETE_ITEM: {
            if (mService != null) {
                long[] list = new long[1];
                list[0] = MusicUtils.getCurrentAudioId();
                Bundle b = new Bundle();
                String f;
                if (android.os.Environment.isExternalStorageRemovable()) {
                    f = getString(R.string.delete_song_desc, mService.getTrackName());
                } else {
                    f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName());
                }
                b.putString("description", f);
                b.putLongArray("items", list);
                intent = new Intent();
                intent.setClass(this, DeleteItems.class);
                intent.putExtras(b);
                startActivityForResult(intent, -1);
            }
            return true;
        }

        case EFFECTS_PANEL: {
            Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
            i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mService.getAudioSessionId());
            startActivityForResult(i, EFFECTS_PANEL);
            return true;
        }
        }
    } catch (RemoteException ex) {
    }
    return super.onOptionsItemSelected(item);
}