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:org.mariotaku.twidere.fragment.BaseStatusesListFragment.java

@Override
public final boolean onMenuItemClick(final MenuItem item) {
    final ParcelableStatus status = mSelectedStatus;
    if (status == null)
        return false;
    switch (item.getItemId()) {
    case MENU_VIEW: {
        openStatus(getActivity(), status);
        break;/*from www  .  j  a va 2s . c om*/
    }
    case MENU_SHARE: {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "@" + status.screen_name + ": " + status.text_plain);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case MENU_COPY: {
        final CharSequence text = Html.fromHtml(status.text_html);
        if (ClipboardUtils.setText(getActivity(), text)) {
            Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    case R.id.direct_retweet:
    case MENU_RETWEET: {
        if (isMyRetweet(status)) {
            cancelRetweet(mTwitterWrapper, status);
        } else {
            final long id_to_retweet = mSelectedStatus.is_retweet && mSelectedStatus.retweet_id > 0
                    ? mSelectedStatus.retweet_id
                    : mSelectedStatus.status_id;
            mTwitterWrapper.retweetStatus(status.account_id, id_to_retweet);
        }
        break;
    }
    case R.id.direct_quote:
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final List<String> mentions = new Extractor().extractMentionedScreennames(status.text_plain);
        mentions.remove(status.screen_name);
        mentions.add(0, status.screen_name);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_FAVORITE: {
        if (mSelectedStatus.is_favorite) {
            mTwitterWrapper.destroyFavorite(status.account_id, status.status_id);
        } else {
            mTwitterWrapper.createFavoriteAsync(status.account_id, status.status_id);
        }
        break;
    }
    case MENU_DELETE: {
        mTwitterWrapper.destroyStatus(status.account_id, status.status_id);
        break;
    }
    case MENU_LOAD_FROM_POSITION: {
        getStatuses(new long[] { status.account_id }, new long[] { status.status_id }, null);
        break;
    }
    case MENU_MULTI_SELECT: {
        if (!mApplication.isMultiSelectActive()) {
            mApplication.startMultiSelect();
        }
        final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems();
        if (!list.contains(status)) {
            list.add(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.StatusFragment.java

protected boolean handleMenuItemClick(final MenuItem item) {
    if (mStatus == null)
        return false;
    final ParcelableStatus status = mStatus;
    switch (item.getItemId()) {
    case MENU_SHARE: {
        startStatusShareChooser(getActivity(), status);
        break;/*from  ww  w  .j  av a  2 s  .  c o m*/
    }
    case MENU_COPY: {
        if (ClipboardUtils.setText(getActivity(), status.text_plain)) {
            showOkMessage(getActivity(), R.string.text_copied, false);
        }
        break;
    }
    case MENU_RETWEET: {
        retweet(status, mTwitterWrapper);
        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, mTwitterWrapper);
        favorite(status, mTwitterWrapper);
        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, mTwitterWrapper);
        break;
    }
    case MENU_DELETE: {
        DestroyStatusDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        AddStatusFilterDialogFragment.show(getFragmentManager(), status);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        final int color = getUserColor(getActivity(), status.user_id, true);
        if (color != 0) {
            intent.putExtra(EXTRA_COLOR, color);
        }
        intent.putExtra(EXTRA_CLEAR_BUTTON, color != 0);
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(getActivity(), status.user_id);
        displayStatus(status);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(getActivity(), status.user_id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), status.user_id, nick);
        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_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) {
                if (Utils.isDebugBuild())
                    Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (debug) {/* w w w  .  java2s .  c  o m*/
        Log.d(TAG, "onOptionsItemSelected getItemId: " + item.getItemId());
    }
    Intent intent;
    switch (item.getItemId()) {
    case MENU_NEW_LIST:
        showDialog(DIALOG_NEW_LIST);
        return true;

    case MENU_CLEAN_UP_LIST:
        cleanupList();
        return true;

    case MENU_RENAME_LIST:
        showDialog(DIALOG_RENAME_LIST);
        return true;

    case MENU_DELETE_LIST:
        deleteListConfirm();
        return true;

    case MENU_PICK_ITEMS:
        pickItems();
        return true;

    case MENU_SHARE:
        setShareSettings();
        return true;

    case MENU_THEME:
        setThemeSettings();
        return true;

    case MENU_ADD_LOCATION_ALERT:
        addLocationAlert();
        return true;

    case MENU_PREFERENCES:
        intent = new Intent(this, PreferenceActivity.class);
        startActivity(intent);
        return true;
    case MENU_SEND:
        sendList();
        return true;
    case MENU_INSERT_FROM_EXTRAS:
        insertItemsFromExtras();
        return true;
    case MENU_MARK_ALL_ITEMS:
        mItemsView.toggleAllItems(true);
        return true;
    case MENU_UNMARK_ALL_ITEMS:
        mItemsView.toggleAllItems(false);
        return true;
    case MENU_SYNC_WEAR:
        mItemsView.pushItemsToWear();
        return true;
    }
    if (debug) {
        Log.d(TAG, "Start intent group id : " + item.getGroupId());
    }
    if (Menu.CATEGORY_ALTERNATIVE == item.getGroupId()) {
        // Start alternative cateogory intents with option to return a
        // result.
        if (debug) {
            Log.d(TAG, "Start alternative intent for : " + item.getIntent().getDataString());
        }
        startActivityForResult(item.getIntent(), REQUEST_CODE_CATEGORY_ALTERNATIVE);
        return true;
    }
    if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    return super.onOptionsItemSelected(item);

}

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

private boolean handleMenuItemClick(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mFriendship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mFriendship != null) {
            if (mFriendship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }//from   www . j  av  a2 s .  c  om
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_MUTE_USER: {
        final ContentResolver resolver = getContentResolver();
        resolver.delete(Filters.Users.CONTENT_URI, Where.equals(Filters.Users.USER_ID, user.id).getSQL(), null);
        resolver.insert(Filters.Users.CONTENT_URI, makeFilterdUserContentValues(user));
        showInfoMessage(getActivity(), R.string.user_muted, false);
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        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(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_RECIPIENT_ID, String.valueOf(user.id));
        startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, getUserColor(getActivity(), user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(getActivity(), user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(getActivity(), user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    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;
    }
    case MENU_EDIT: {
        final Bundle extras = new Bundle();
        extras.putLong(EXTRA_ACCOUNT_ID, user.account_id);
        final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
        intent.setClass(getActivity(), UserProfileEditorActivity.class);
        intent.putExtras(extras);
        startActivity(intent);
        return true;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    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.UserProfileFragment.java

private boolean handleMenuItemClick(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }//from  w  w w  . j  ava  2  s.co m
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final ContentResolver resolver = getContentResolver();
        resolver.delete(Filters.Users.CONTENT_URI, Where.equals(Filters.Users.USER_ID, user.id).getSQL(), null);
        resolver.insert(Filters.Users.CONTENT_URI, makeFilterdUserContentValues(user));
        showInfoMessage(getActivity(), R.string.message_user_muted, false);
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWITTNUKER);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_RECIPIENT_ID, String.valueOf(user.id));
        startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, getUserColor(getActivity(), user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(getActivity(), user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(getActivity(), user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    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;
    }
    case MENU_EDIT: {
        final Bundle extras = new Bundle();
        extras.putLong(EXTRA_ACCOUNT_ID, user.account_id);
        final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
        intent.setClass(getActivity(), UserProfileEditorActivity.class);
        intent.putExtras(extras);
        startActivity(intent);
        return true;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.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.mms.ui.ComposeMessageActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_ADD_SUBJECT:
        showSubjectEditor(true);//from  w ww  .  jav a2s. co m
        mWorkingMessage.setSubject("", true);
        updateSendButtonState();
        mSubjectTextEditor.requestFocus();
        break;
    case MENU_ADD_ATTACHMENT:
        // Launch the add-attachment list dialog
        showAddAttachmentDialog(false);
        break;
    case MENU_DISCARD:
        mWorkingMessage.discard();
        finish();
        break;
    case MENU_SEND:
        if (isPreparedForSending()) {
            confirmSendMessageIfNeeded();
        }
        break;
    case MENU_SEARCH:
        onSearchRequested();
        break;
    case MENU_DELETE_THREAD:
        confirmDeleteThread(mConversation.getThreadId());
        break;

    case android.R.id.home:
    case MENU_CONVERSATION_LIST:
        exitComposeMessageActivity(new Runnable() {
            @Override
            public void run() {
                goToConversationList();
            }
        });
        break;
    case MENU_CALL_RECIPIENT:
        dialRecipient();
        break;
    case MENU_INSERT_SMILEY:
        showSmileyDialog();
        break;
    case MENU_GROUP_PARTICIPANTS: {
        Intent intent = new Intent(this, RecipientListActivity.class);
        intent.putExtra(THREAD_ID, mConversation.getThreadId());
        startActivity(intent);
        break;
    }
    case MENU_VIEW_CONTACT: {
        // View the contact for the first (and only) recipient.
        ContactList list = getRecipients();
        if (list.size() == 1 && list.get(0).existsInDatabase()) {
            Uri contactUri = list.get(0).getUri();
            Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            startActivity(intent);
        }
        break;
    }
    case MENU_ADD_ADDRESS_TO_CONTACTS:
        mAddContactIntent = item.getIntent();
        startActivityForResult(mAddContactIntent, REQUEST_CODE_ADD_CONTACT);
        break;
    case MENU_CONVERSATION_OPTIONS: {
        Intent intent = new Intent(this, ConversationOptionsActivity.class);
        intent.putExtra(THREAD_ID, mConversation.getThreadId());
        startActivityIfNeeded(intent, -1);
        break;
    }
    case MENU_PREFERENCES: {
        Intent intent = new Intent(this, MessagingPreferenceActivity.class);
        startActivityIfNeeded(intent, -1);
        break;
    }
    case MENU_DEBUG_DUMP:
        mWorkingMessage.dump();
        Conversation.dump();
        LogTag.dumpInternalTables(this);
        break;
    case MENU_ADD_TEMPLATE:
        startLoadingTemplates();
        break;
    case MENU_ADD_TO_BLACKLIST:
        confirmAddBlacklist();
        break;
    }

    return true;
}

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }/*  w w w  . j  a v  a2 s  .  c o  m*/
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
        final ContentResolver cr = getContentResolver();
        if (filtering) {
            final Expression where = Expression.equals(Filters.Users.USER_ID, user.id);
            cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null);
            showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        break;
    }
    case MENU_MUTE_USER: {
        if (mRelationship != null) {
            if (mRelationship.isSourceMutingTarget()) {
                twitter.destroyMuteAsync(user.account_id, user.id);
            } else {
                CreateUserMuteDialogFragment.show(getFragmentManager(), user);
            }
        }
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_FIRETWEET);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentials.getAccount(getActivity(), user.account_id));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, getUserColor(getActivity(), user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(getActivity(), user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(getActivity(), user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    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;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    case R.id.muted_users: {
        openMutesUsers(getActivity(), user.account_id);
        return true;
    }
    case R.id.blocked_users: {
        openUserBlocks(getActivity(), user.account_id);
        return true;
    }
    case R.id.incoming_friendships: {
        openIncomingFriendships(getActivity(), user.account_id);
        return true;
    }
    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.util.Utils.java

public static boolean handleMenuItemClick(Context context, Fragment fragment, FragmentManager fm,
        AsyncTwitterWrapper twitter, ParcelableStatus status, MenuItem item) {
    switch (item.getItemId()) {
    case MENU_COPY: {
        if (ClipboardUtils.setText(context, status.text_plain)) {
            showOkMessage(context, R.string.text_copied, false);
        }/*from w  w  w . j a v a 2  s.  c o  m*/
        break;
    }
    case MENU_RETWEET: {
        if (isMyRetweet(status)) {
            twitter.cancelRetweetAsync(status.account_id, status.id, status.my_retweet_id);
        } else {
            twitter.retweetStatusAsync(status.account_id, status.id);
        }
        break;
    }
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_QUOTE);
        intent.putExtra(EXTRA_STATUS, status);
        context.startActivity(intent);
        break;
    }
    case MENU_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_REPLY);
        intent.putExtra(EXTRA_STATUS, status);
        context.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(fm, status);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        AddStatusFilterDialogFragment.show(fm, status);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(context, ColorPickerDialogActivity.class);
        final int color = getUserColor(context, status.user_id, true);
        if (color != 0) {
            intent.putExtra(EXTRA_COLOR, color);
        }
        intent.putExtra(EXTRA_CLEAR_BUTTON, color != 0);
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        if (fragment != null) {
            fragment.startActivityForResult(intent, REQUEST_SET_COLOR);
        } else if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(intent, REQUEST_SET_COLOR);
        }
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        clearUserNickname(context, status.user_id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = getUserNickname(context, status.user_id, true);
        SetUserNicknameDialogFragment.show(fm, status.user_id, nick);
        break;
    }
    case MENU_TRANSLATE: {
        final ParcelableCredentials account = ParcelableAccount.getCredentials(context, status.account_id);
        if (isOfficialCredentials(context, account)) {
            StatusTranslateDialogFragment.show(fm, status);
        } else {
            final Resources resources = context.getResources();
            final Locale locale = resources.getConfiguration().locale;
            try {
                final String template = "http://translate.google.com/#%s|%s|%s";
                final String sourceLang = "auto";
                final String targetLang = URLEncoder.encode(locale.getLanguage(), HTTP.UTF_8);
                final String text = URLEncoder.encode(status.text_unescaped, HTTP.UTF_8);
                final Uri uri = Uri.parse(String.format(Locale.ROOT, template, sourceLang, targetLang, text));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                context.startActivity(intent);
            } catch (UnsupportedEncodingException ignore) {

            }
        }
        break;
    }
    case MENU_OPEN_WITH_ACCOUNT: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(context, AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        if (fragment != null) {
            fragment.startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        } else if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        }
        break;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                context.startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Crashlytics.logException(e);
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }//  w  w  w .j a  v a  2 s . c o  m
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
        final ContentResolver cr = getContentResolver();
        if (filtering) {
            final Expression where = Expression.equals(Filters.Users.USER_ID, user.id);
            cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null);
            Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        break;
    }
    case MENU_MUTE_USER: {
        if (mRelationship != null) {
            if (mRelationship.isSourceMutingTarget()) {
                twitter.destroyMuteAsync(user.account_id, user.id);
            } else {
                CreateUserMuteDialogFragment.show(getFragmentManager(), user);
            }
        }
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        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(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentials.getAccount(getActivity(), user.account_id));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        final UserColorNameManager manager = UserColorNameManager.getInstance(getActivity());
        manager.clearUserNickname(user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = mUserColorNameManager.getUserNickname(user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, Utils.getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    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;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    case MENU_ENABLE_RETWEETS: {
        final boolean newState = !item.isChecked();
        final FriendshipUpdate update = new FriendshipUpdate();
        update.retweets(newState);
        twitter.updateFriendship(user.account_id, user.id, update);
        item.setChecked(newState);
        return true;
    }
    case R.id.muted_users: {
        Utils.openMutesUsers(getActivity(), user.account_id);
        return true;
    }
    case R.id.blocked_users: {
        Utils.openUserBlocks(getActivity(), user.account_id);
        return true;
    }
    case R.id.incoming_friendships: {
        Utils.openIncomingFriendships(getActivity(), user.account_id);
        return true;
    }
    case R.id.user_mentions: {
        Utils.openUserMentions(getActivity(), user.account_id, user.screen_name);
        return true;
    }
    case R.id.saved_searches: {
        Utils.openSavedSearches(getActivity(), user.account_id);
        return true;
    }
    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.UserFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final Context context = getContext();
    final AsyncTwitterWrapper twitter = mTwitterWrapper;
    final ParcelableUser user = getUser();
    final UserRelationship userRelationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case R.id.block: {
        if (userRelationship == null)
            return true;
        if (userRelationship.blocking) {
            twitter.destroyBlockAsync(user.account_key, user.key);
        } else {//from  w w  w.  j  a v  a  2 s .  c  o  m
            CreateUserBlockDialogFragment.show(getFragmentManager(), user);
        }
        break;
    }
    case R.id.report_spam: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case R.id.add_to_filter: {
        if (userRelationship == null)
            return true;
        final ContentResolver cr = getContentResolver();
        if (userRelationship.filtering) {
            final String where = Expression.equalsArgs(Filters.Users.USER_KEY).getSQL();
            final String[] whereArgs = { user.key.toString() };
            cr.delete(Filters.Users.CONTENT_URI, where, whereArgs);
            Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        getFriendship();
        break;
    }
    case R.id.mute_user: {
        if (userRelationship == null)
            return true;
        if (userRelationship.muting) {
            twitter.destroyMuteAsync(user.account_key, user.key);
        } else {
            CreateUserMuteDialogFragment.show(getFragmentManager(), user);
        }
        break;
    }
    case R.id.mention: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case R.id.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_KEY, user.account_key.toString());
        builder.appendQueryParameter(QUERY_PARAM_USER_KEY, user.key.toString());
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT,
                ParcelableCredentialsUtils.getCredentials(getActivity(), user.account_key));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case R.id.set_color: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.key));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case R.id.clear_nickname: {
        mUserColorNameManager.clearUserNickname(user.key);
        break;
    }
    case R.id.set_nickname: {
        final String nick = mUserColorNameManager.getUserNickname(user.key);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.key, nick);
        break;
    }
    case R.id.add_to_list: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_KEY, user.account_key);
        intent.putExtra(EXTRA_SCREEN_NAME,
                DataStoreUtils.getAccountScreenName(getActivity(), user.account_key));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    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);
        intent.putExtra(EXTRA_ACCOUNT_HOST, user.key.getHost());
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    case R.id.follow: {
        if (userRelationship == null)
            return true;
        final boolean updatingRelationship = twitter.isUpdatingRelationship(user.account_key, user.key);
        if (!updatingRelationship) {
            if (userRelationship.following) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_key, user.key);
            }
        }
        return true;
    }
    case R.id.enable_retweets: {
        final boolean newState = !item.isChecked();
        final FriendshipUpdate update = new FriendshipUpdate();
        update.retweets(newState);
        twitter.updateFriendship(user.account_key, user.key.getId(), update);
        item.setChecked(newState);
        return true;
    }
    case R.id.muted_users: {
        IntentUtils.openMutesUsers(getActivity(), user.account_key);
        return true;
    }
    case R.id.blocked_users: {
        IntentUtils.openUserBlocks(getActivity(), user.account_key);
        return true;
    }
    case R.id.incoming_friendships: {
        IntentUtils.openIncomingFriendships(getActivity(), user.account_key);
        return true;
    }
    case R.id.user_mentions: {
        IntentUtils.openUserMentions(context, user.account_key, user.screen_name);
        return true;
    }
    case R.id.saved_searches: {
        IntentUtils.openSavedSearches(context, user.account_key);
        return true;
    }
    case R.id.scheduled_statuses: {
        IntentUtils.openScheduledStatuses(context, user.account_key);
        return true;
    }
    case R.id.open_in_browser: {
        final Uri uri = LinkCreator.getUserWebLink(user);
        final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setPackage(IntentUtils.getDefaultBrowserPackage(context, uri, true));
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            startActivity(intent);
        }
        return true;
    }
    default: {
        final Intent intent = item.getIntent();
        if (intent != null && intent.resolveActivity(context.getPackageManager()) != null) {
            startActivity(intent);
        }
        break;
    }
    }
    return true;
}