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:mp.teardrop.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == MENU_GROUP_ROUND_BUTTON) {

        Limiter limiter = mPagerAdapter.getCurrentLimiter();
        Intent intent = null;/*from  w ww .ja  va  2 s . c om*/

        switch (mPagerAdapter.getCurrentType()) {
        case MediaUtils.TYPE_FILE:
            intent = new Intent();
            intent.putExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_FILE);
            intent.putExtra("file", limiter == null ? "/" : limiter.data.toString());
            break;
        case MediaUtils.TYPE_UNIFIED:
            if (limiter != null && limiter.type <= 20) {
                intent = new Intent();
                intent.putExtra(LibraryAdapter.DATA_TYPE, limiter.type);
                intent.putExtra(LibraryAdapter.DATA_ID, (Long) limiter.data);
            } //else continue with null limiter, which will play the entire MediaStore
            break;
        }

        mRoundPlayAllButton.setVisibility(View.GONE);

        pickSongs(intent, item.getItemId() == MENU_PLAY_ALL ? ACTION_PLAY_ALL : ACTION_ENQUEUE_ALL);

        return true;
    }

    if (item.getGroupId() != 0) {
        return super.onContextItemSelected(item);
    }

    final Intent intent = item.getIntent();

    switch (item.getItemId()) {
    case MENU_EXPAND:
        expand(intent);
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
        }
        break;
    case MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case MENU_NEW_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_RENAME_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename,
                intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_DELETE:
        String delete_message = getString(R.string.delete_item, intent.getStringExtra("title"));
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.delete);
        dialog.setMessage(delete_message)
                .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case MENU_ADD_TO_PLAYLIST: {
        SubMenu playlistMenu = item.getSubMenu();
        playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent);
        Cursor cursor = Playlist.queryPlaylists(getContentResolver());
        if (cursor != null) {
            for (int i = 0, count = cursor.getCount(); i != count; ++i) {
                cursor.moveToPosition(i);
                long id = cursor.getLong(0);
                String name = cursor.getString(1);
                Intent copy = new Intent(intent);
                copy.putExtra("playlist", id);
                copy.putExtra("playlistName", name);
                playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy);
            }
            cursor.close();
        }
        break;
    }
    case MENU_SELECT_PLAYLIST:
        mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent));
        break;
    case MENU_MORE_FROM_ARTIST: {
        String selection = "_id=";
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(-1, selection);
        updateLimiterViews();
        break;
    }
    case MENU_MORE_FROM_ALBUM:
        setLimiter(-1, "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    }

    return true;
}

From source file:org.getlantern.firetweet.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;//from w w  w.j a v a 2  s .com
    }
    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;
    }
    case MENU_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.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  ava 2  s . co  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: {
        if (isMyRetweet(status)) {
            cancelRetweet(twitter, status);
        } else {
            final long id_to_retweet = status.retweet_id > 0 ? status.retweet_id : status.id;
            twitter.retweetStatus(status.account_id, id_to_retweet);
        }
        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_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: {
        if (status.is_favorite) {
            twitter.destroyFavoriteAsync(status.account_id, status.id);
        } else {
            twitter.createFavoriteAsync(status.account_id, status.id);
        }
        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) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

public boolean handleMenuItem(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_TAKE_PHOTO:
    case R.id.take_photo_sub_item: {
        takePhoto();// ww  w .j  av a2  s. c o  m
        break;
    }
    case MENU_ADD_IMAGE:
    case R.id.add_image_sub_item: {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || !openDocument()) {
            pickImage();
        }
        break;
    }
    case MENU_ADD_LOCATION: {
        toggleLocation();
        break;
    }
    case MENU_DRAFTS: {
        startActivity(new Intent(INTENT_ACTION_DRAFTS));
        break;
    }
    case MENU_DELETE: {
        AsyncTaskUtils.executeTask(new DeleteImageTask(this));
        break;
    }
    case MENU_TOGGLE_SENSITIVE: {
        if (!hasMedia())
            return false;
        mIsPossiblySensitive = !mIsPossiblySensitive;
        setMenu();
        updateTextCount();
        break;
    }
    case MENU_VIEW: {
        if (mInReplyToStatus == null)
            return false;
        final DialogFragment fragment = new ViewStatusDialogFragment();
        final Bundle args = new Bundle();
        args.putParcelable(EXTRA_STATUS, mInReplyToStatus);
        fragment.setArguments(args);
        fragment.show(getSupportFragmentManager(), "view_status");
        break;
    }
    default: {
        final Intent intent = item.getIntent();
        if (intent != null) {
            try {
                final String action = intent.getAction();
                if (INTENT_ACTION_EXTENSION_COMPOSE.equals(action)) {
                    final long[] accountIds = mAccountsAdapter.getSelectedAccountIds();
                    intent.putExtra(EXTRA_TEXT, ParseUtils.parseString(mEditText.getText()));
                    intent.putExtra(EXTRA_ACCOUNT_IDS, accountIds);
                    if (accountIds.length > 0) {
                        final long account_id = accountIds[0];
                        intent.putExtra(EXTRA_NAME, getAccountName(this, account_id));
                        intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(this, account_id));
                    }
                    if (mInReplyToStatusId > 0) {
                        intent.putExtra(EXTRA_IN_REPLY_TO_ID, mInReplyToStatusId);
                    }
                    if (mInReplyToStatus != null) {
                        intent.putExtra(EXTRA_IN_REPLY_TO_NAME, mInReplyToStatus.user_name);
                        intent.putExtra(EXTRA_IN_REPLY_TO_SCREEN_NAME, mInReplyToStatus.user_screen_name);
                    }
                    startActivityForResult(intent, REQUEST_EXTENSION_COMPOSE);
                } else if (INTENT_ACTION_EXTENSION_EDIT_IMAGE.equals(action)) {
                    // final ComponentName cmp = intent.getComponent();
                    // if (cmp == null || !hasMedia()) return false;
                    // final String name = new
                    // File(mMediaUri.getPath()).getName();
                    // final Uri data =
                    // Uri.withAppendedPath(CacheFiles.CONTENT_URI,
                    // Uri.encode(name));
                    // intent.setData(data);
                    // grantUriPermission(cmp.getPackageName(), data,
                    // Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    // startActivityForResult(intent,
                    // REQUEST_EDIT_IMAGE);
                } else {
                    startActivity(intent);
                }
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.BaseStatusesMultiColumnListFragment.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;// w w  w .jav a 2 s.c o  m
    }
    case MENU_SHARE: {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "@" + status.user_screen_name + ": " + status.text_plain);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case MENU_COPY: {
        if (ClipboardUtils.setText(getActivity(), status.text_plain)) {
            showOkMessage(getActivity(), R.string.text_copied, false);
        }
        break;
    }
    case R.id.direct_retweet:
    case MENU_RETWEET: {
        if (isMyRetweet(status)) {
            cancelRetweet(twitter, status);
        } else {
            final long id_to_retweet = status.retweet_id > 0 ? status.retweet_id : status.id;
            twitter.retweetStatus(status.account_id, id_to_retweet);
        }
        break;
    }
    case R.id.direct_quote:
    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_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: {
        if (status.is_favorite) {
            twitter.destroyFavoriteAsync(status.account_id, status.id);
        } else {
            twitter.createFavoriteAsync(status.account_id, status.id);
        }
        break;
    }
    case MENU_DELETE: {
        twitter.destroyStatusAsync(status.account_id, status.id);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        AddStatusFilterDialogFragment.show(getFragmentManager(), status);
        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:de.vanita5.twittnuker.fragment.support.BaseStatusesListFragment.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;/*  w ww . jav  a2 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: {
        DestroyStatusDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        AddStatusFilterDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_TRANSLATE: {
        final AccountWithCredentials account = Account.getAccountWithCredentials(getActivity(),
                status.account_id);
        if (AccountWithCredentials.isOfficialCredentials(getActivity(), account)) {
            StatusTranslateDialogFragment.show(getFragmentManager(), status);
        } else {

        }
        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.activity.support.ComposeActivity.java

@Override
public boolean onMenuItemClick(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_TAKE_PHOTO:
    case R.id.take_photo_sub_item: {
        takePhoto();/* w w w  . ja  v a  2s  . c  om*/
        break;
    }
    case MENU_ADD_IMAGE:
    case R.id.add_image_sub_item: {
        pickImage();
        break;
    }
    case MENU_ADD_LOCATION: {
        toggleLocation();
        break;
    }
    case MENU_DRAFTS: {
        Utils.openDrafts(this);
        break;
    }
    case MENU_DELETE: {
        AsyncTaskUtils.executeTask(new DeleteImageTask(this));
        break;
    }
    case MENU_TOGGLE_SENSITIVE: {
        if (!hasMedia())
            return false;
        mIsPossiblySensitive = !mIsPossiblySensitive;
        setMenu();
        updateTextCount();
        break;
    }
    case MENU_VIEW: {
        if (mInReplyToStatus == null)
            return false;
        final DialogFragment fragment = new ViewStatusDialogFragment();
        final Bundle args = new Bundle();
        args.putParcelable(EXTRA_STATUS, mInReplyToStatus);
        fragment.setArguments(args);
        fragment.show(getSupportFragmentManager(), "view_status");
        break;
    }
    case R.id.link_to_quoted_status: {
        final boolean newValue = !item.isChecked();
        item.setChecked(newValue);
        mPreferences.edit().putBoolean(KEY_LINK_TO_QUOTED_TWEET, newValue).apply();
        break;
    }
    default: {
        final Intent intent = item.getIntent();
        if (intent != null) {
            try {
                final String action = intent.getAction();
                if (INTENT_ACTION_EXTENSION_COMPOSE.equals(action)) {
                    final long[] accountIds = mAccountsAdapter.getSelectedAccountIds();
                    intent.putExtra(EXTRA_TEXT, ParseUtils.parseString(mEditText.getText()));
                    intent.putExtra(EXTRA_ACCOUNT_IDS, accountIds);
                    if (accountIds.length > 0) {
                        final long account_id = accountIds[0];
                        intent.putExtra(EXTRA_NAME, Utils.getAccountName(this, account_id));
                        intent.putExtra(EXTRA_SCREEN_NAME, Utils.getAccountScreenName(this, account_id));
                    }
                    if (mInReplyToStatusId > 0) {
                        intent.putExtra(EXTRA_IN_REPLY_TO_ID, mInReplyToStatusId);
                    }
                    if (mInReplyToStatus != null) {
                        intent.putExtra(EXTRA_IN_REPLY_TO_NAME, mInReplyToStatus.user_name);
                        intent.putExtra(EXTRA_IN_REPLY_TO_SCREEN_NAME, mInReplyToStatus.user_screen_name);
                    }
                    startActivityForResult(intent, REQUEST_EXTENSION_COMPOSE);
                } else if (INTENT_ACTION_EXTENSION_EDIT_IMAGE.equals(action)) {
                    // final ComponentName cmp = intent.getComponent();
                    // if (cmp == null || !hasMedia()) return false;
                    // final String name = new
                    // File(mMediaUri.getPath()).getName();
                    // final Uri data =
                    // Uri.withAppendedPath(CacheFiles.CONTENT_URI,
                    // Uri.encode(name));
                    // intent.setData(data);
                    // grantUriPermission(cmp.getPackageName(), data,
                    // Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    // startActivityForResult(intent,
                    // REQUEST_EDIT_IMAGE);
                } else {
                    startActivity(intent);
                }
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.BaseStatusesListFragment.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;//from  ww w  .j  a v  a 2 s .  com
    }
    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: {
        if (isMyRetweet(status)) {
            cancelRetweet(twitter, status);
        } else {
            final long id_to_retweet = status.retweet_id > 0 ? status.retweet_id : status.id;
            twitter.retweetStatus(status.account_id, id_to_retweet);
        }
        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_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: {
        if (status.is_favorite) {
            twitter.destroyFavoriteAsync(status.account_id, status.id);
        } else {
            twitter.createFavoriteAsync(status.account_id, status.id);
        }
        break;
    }
    case MENU_DELETE: {
        DestroyStatusDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        AddStatusFilterDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_TRANSLATE: {
        final AccountWithCredentials account = Account.getAccountWithCredentials(getActivity(),
                status.account_id);
        if (AccountWithCredentials.isOfficialCredentials(getActivity(), account)) {
            StatusTranslateDialogFragment.show(getFragmentManager(), status);
        } else {

        }
        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) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.openintents.notepad.NoteEditor.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle all of the possible menu actions.
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent intent = new Intent(this, NotesList.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);//from   w w  w  . j  a v a  2  s .com
        break;
    case MENU_SEARCH:
        menuSearch();
        break;
    case MENU_DELETE:
        deleteNoteWithConfirm();
        break;
    case MENU_DISCARD:
        revertNote();
        break;
    case MENU_REVERT:
        revertNote();
        break;
    case MENU_ENCRYPT:
        encryptNote(true);
        break;
    case MENU_UNENCRYPT:
        unencryptNote();
        break;
    case MENU_IMPORT:
        importNote();
        break;
    case MENU_SAVE:
        saveNoteWithPermissionCheck();
        break;
    case MENU_SAVE_AS:
        saveAsNote();
        break;
    case MENU_THEME:
        setThemeSettings();
        return true;
    case MENU_SETTINGS:
        showNotesListSettings();
        return true;
    case MENU_SEND:
        shareNote();
        return true;
    case MENU_WORD_COUNT:
        showWordCount();
        break;
    }
    if (item.getGroupId() == GROUP_ID_TEXT_SELECTION_ALTERNATIVE) {
        // Process manually:
        // We pass the current selection along with the intent
        startTextSelectionActivity(item.getIntent());

        // Consume event
        return true;
    }
    return super.onOptionsItemSelected(item);
}

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

@Override
public boolean onMenuItemClick(final MenuItem item) {
    if (mUser == null || mTwitterWrapper == null)
        return false;
    switch (item.getItemId()) {
    case MENU_TAKE_PHOTO: {
        takePhoto();//from ww w.j a  v a2s . co m
        break;
    }
    case MENU_ADD_IMAGE: {
        pickImage();
        break;
    }
    case MENU_BLOCK: {
        if (mTwitterWrapper == null || mFriendship == null) {
            break;
        }
        if (mFriendship.isSourceBlockingTarget()) {
            mTwitterWrapper.destroyBlock(mAccountId, mUser.user_id);
        } else {
            mTwitterWrapper.createBlockAsync(mAccountId, mUser.user_id);
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        mTwitterWrapper.reportSpam(mAccountId, mUser.user_id);
        break;
    }
    case MENU_MUTE_USER: {
        final String screen_name = mUser.screen_name;
        final Uri uri = Filters.Users.CONTENT_URI;
        final ContentValues values = new ContentValues();
        final ContentResolver resolver = getContentResolver();
        values.put(Filters.Users.TEXT, screen_name);
        resolver.delete(uri, Filters.Users.TEXT + " = '" + screen_name + "'", null);
        resolver.insert(uri, values);
        Toast.makeText(getActivity(), R.string.user_muted, Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final String name = mUser.name;
        final String screen_name = mUser.screen_name;
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putString(INTENT_KEY_TEXT, "@" + screen_name + " ");
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWIDERE);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(mAccountId));
        builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(mUser.user_id));
        startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), SetColorActivity.class);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_COLOR: {
        clearUserColor(getActivity(), mUserId);
        mProfileNameContainer.drawLeft(getUserColor(getActivity(), mUserId));
        break;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}