Example usage for android.view MenuItem getIcon

List of usage examples for android.view MenuItem getIcon

Introduction

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

Prototype

public Drawable getIcon();

Source Link

Document

Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).

Usage

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem muteItem = menu.findItem(R.id.menu_mute_button);
    MenuItem deafenItem = menu.findItem(R.id.menu_deafen_button);

    if (getService() != null && getService().isSynchronized()) {
        // Color the action bar icons to the primary text color of the theme, TODO move this elsewhere
        int foregroundColor = getActivity().getTheme()
                .obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }).getColor(0, -1);

        IUser self = getService().getSessionUser();
        muteItem.setIcon(//  w w w. j a  v a2s.  c  o m
                self.isSelfMuted() ? R.drawable.ic_action_microphone_muted : R.drawable.ic_action_microphone);
        deafenItem
                .setIcon(self.isSelfDeafened() ? R.drawable.ic_action_audio_muted : R.drawable.ic_action_audio);
        muteItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
        deafenItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);

        MenuItem bluetoothItem = menu.findItem(R.id.menu_bluetooth);
        bluetoothItem.setChecked(getService().usingBluetoothSco());
    }
}

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext()).inflate(getMenuItemLayoutId(), this,
            false);/*w ww .j  a  v  a  2s .c  o m*/

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);

        if (miniFabTitleTextColorArray != null) {
            titleView.setTextColor(ContextCompat.getColorStateList(getContext(),
                    miniFabTitleTextColorArray[menuItem.getOrder()]));
        }
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);

    if (miniFabBackgroundTintArray != null) {
        miniFab.setBackgroundTintList(
                ContextCompat.getColorStateList(getContext(), miniFabBackgroundTintArray[menuItem.getOrder()]));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}

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

@Override
public void onClick(final View view) {
    if (getActivity() == null)
        return;/*w w w  .  ja v a 2 s .c  om*/
    switch (view.getId()) {
    case R.id.edit_follow: {
        if (mUser == null || mAccountId <= 0)
            return;
        if (mAccountId == mUserId) {
            final Bundle bundle = getArguments();
            final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
            intent.setClass(getActivity(), EditUserProfileActivity.class);
            if (bundle != null) {
                intent.putExtras(bundle);
            }
            startActivity(intent);
        } else {
            if (mUser.is_follow_request_sent)
                return;
            if (mFriendship.isSourceFollowingTarget()) {
                mPopupMenu = PopupMenu.getInstance(getActivity(), view);
                mPopupMenu.inflate(R.menu.action_user_profile_follow);
                mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(final MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.unfollow: {
                            mFollowProgress.setVisibility(View.VISIBLE);
                            mEditFollowButton.setVisibility(View.GONE);
                            mTwitterWrapper.destroyFriendship(mAccountId, mUser.user_id);
                            return true;
                        }
                        }
                        return false;
                    }
                });
                mPopupMenu.show();
            } else {
                mFollowProgress.setVisibility(View.VISIBLE);
                mEditFollowButton.setVisibility(View.GONE);
                mTwitterWrapper.createFriendship(mAccountId, mUser.user_id);
            }
        }
        break;
    }
    case R.id.retry: {
        getUserInfo(true);
        break;
    }
    case R.id.profile_image_container: {
        final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url));
        openImage(getActivity(), uri, false);
        break;
    }
    case R.id.tweets_container: {
        if (mUser == null)
            return;
        openUserTimeline(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.followers_container: {
        if (mUser == null)
            return;
        openUserFollowers(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.friends_container: {
        if (mUser == null)
            return;
        openUserFriends(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.more_options: {
        if (mUser == null)
            return;
        mPopupMenu = PopupMenu.getInstance(getActivity(), view);
        mPopupMenu.inflate(R.menu.action_user_profile);
        final Menu menu = mPopupMenu.getMenu();
        if (mUser.user_id != mAccountId) {
            if (mFriendship == null)
                return;
            final MenuItem blockItem = menu.findItem(MENU_BLOCK);
            if (blockItem != null) {
                final Drawable blockIcon = blockItem.getIcon();
                if (mFriendship.isSourceBlockingTarget()) {
                    blockItem.setTitle(R.string.unblock);
                    blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright),
                            PorterDuff.Mode.MULTIPLY);
                } else {
                    blockItem.setTitle(R.string.block);
                    blockIcon.clearColorFilter();
                }
            }
            final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE);
            if (sendDirectMessageItem != null) {
                sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource());
            }
        } else {
            final int size = menu.size();
            for (int i = 0; i < size; i++) {
                final MenuItem item = menu.getItem(i);
                final int id = item.getItemId();
                item.setVisible(id == R.id.set_color_submenu || id == MENU_EXTENSIONS_SUBMENU);
            }
        }
        final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
        if (extensions != null) {
            final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
            final Bundle extras = new Bundle();
            extras.putParcelable(INTENT_KEY_USER, mUser);
            intent.putExtras(extras);
            addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent);
        }
        mPopupMenu.setOnMenuItemClickListener(this);
        mPopupMenu.show();
        break;
    }
    case R.id.name_container: {
        if (mUser == null || mAccountId != mUserId)
            return;
        startActivity(new Intent(getActivity(), EditUserProfileActivity.class));
        break;
    }
    }

}

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

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mFriendship;
    if (twitter == null || user == null)
        return;//from  w ww  .  j  ava2  s . c  om
    final boolean isMyself = user.account_id == user.id;
    final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget();
    final boolean isProtected = user.is_protected;
    final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
    final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
    setMenuItemAvailability(menu, MENU_EDIT, isMyself);
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    followItem.setVisible(!isMyself);
    final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
            && relationship != null;
    followItem.setEnabled(shouldShowFollowItem);
    if (shouldShowFollowItem) {
        followItem.setTitle(
                isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow);
        followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add);
    } else {
        followItem.setTitle(null);
        followItem.setIcon(null);
    }
    if (user.id != user.account_id) {
        setMenuItemAvailability(menu, MENU_BLOCK, mFriendship != null);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (mFriendship != null && blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (mFriendship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate().setColorFilter(ThemeUtils.getUserThemeColor(getActivity()),
                        PorterDuff.Mode.MULTIPLY);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
        final boolean is_following_me = mFriendship != null && mFriendship.isTargetFollowingSource();
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, is_following_me);
    } else {
        setMenuItemAvailability(menu, MENU_MENTION, false);
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
    final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
    final Bundle extras = new Bundle();
    extras.putParcelable(EXTRA_USER, user);
    intent.putExtras(extras);
    menu.removeGroup(MENU_GROUP_USER_EXTENSION);
    addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION);
}

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

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mRelationship;
    if (twitter == null || user == null)
        return;/*from w w w .j a v  a  2 s  .c  o  m*/
    final int activatedColor = ThemeUtils.getUserThemeColor(getActivity());
    final boolean isMyself = user.account_id == user.id;
    final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget();
    final boolean isProtected = user.is_protected;
    final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
    final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
    setMenuItemAvailability(menu, MENU_EDIT, isMyself);
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    followItem.setVisible(!isMyself);
    final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
            && relationship != null;
    followItem.setEnabled(shouldShowFollowItem);
    if (shouldShowFollowItem) {
        followItem.setTitle(
                isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow);
        followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add);
    } else {
        followItem.setTitle(null);
        followItem.setIcon(null);
    }
    if (user.id != user.account_id && relationship != null) {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget());
        setMenuItemAvailability(menu, MENU_BLOCK, true);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (relationship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate();
                blockIcon.setColorFilter(activatedColor, PorterDuff.Mode.SRC_ATOP);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
    } else {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
}

From source file:com.github.dfa.diaspora_android.activity.MainActivity.java

/**
 * Set the notification and messages counter in the top toolbar
 *
 * @param menu menu//from  w  w w.j a  v  a2s . c om
 * @return boolean
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item;
    updateNavigationViewEntryVisibilities();

    if ((item = menu.findItem(R.id.action_notifications)) != null) {
        LayerDrawable icon = (LayerDrawable) item.getIcon();
        BadgeDrawable.setBadgeCount(this, icon, diasporaUserProfile.getNotificationCount());
    }

    if ((item = menu.findItem(R.id.action_conversations)) != null) {
        LayerDrawable icon = (LayerDrawable) item.getIcon();
        BadgeDrawable.setBadgeCount(this, icon, diasporaUserProfile.getUnreadMessagesCount());
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.terracom.mumbleclient.channel.ChannelListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem muteItem = menu.findItem(R.id.menu_mute_button);
    MenuItem deafenItem = menu.findItem(R.id.menu_deafen_button);

    try {/*from   w  ww.ja v a 2s. co  m*/
        if (getService() != null && getService().isConnected() && getService().getSessionUser() != null) {
            // Color the action bar icons to the primary text color of the theme, TODO move this elsewhere
            int foregroundColor = getActivity().getTheme()
                    .obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse })
                    .getColor(0, -1);

            User self = getService().getSessionUser();
            muteItem.setIcon(self.isSelfMuted() ? R.drawable.ic_action_microphone_muted
                    : R.drawable.ic_action_microphone);
            deafenItem.setIcon(
                    self.isSelfDeafened() ? R.drawable.ic_action_audio_muted : R.drawable.ic_action_audio);
            muteItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
            deafenItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    /*try {
    if(getService() != null) {
        MenuItem bluetoothItem = menu.findItem(R.id.menu_bluetooth);
        bluetoothItem.setChecked(getService().isBluetoothAvailable());
    }
    } catch (RemoteException e) {
    e.printStackTrace();
    }*/
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private ArrayList<ImageButton> generateFollowCircles() {

    int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL
            ? Utils.getDimension(mContext, R.dimen.fab_size_normal) - 2
            : Utils.getDimension(mContext, R.dimen.fab_size_mini);

    ArrayList<ImageButton> circles = new ArrayList<>(mMenuItems.size());
    for (MenuItem item : mMenuItems) {
        ImageButton circle = new ImageButton(mContext);
        circle.setScaleType(ImageView.ScaleType.FIT_CENTER);
        OvalShape ovalShape = new OvalShape();
        ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
        shapeDrawable.getPaint().setColor(getResources().getColor(item.getBgColor()));
        circle.setBackgroundDrawable(shapeDrawable);

        if (TextUtils.isEmpty(item.getIconFilePath())) {
            circle.setImageResource(item.getIcon());
        } else {/*www.j a v a  2s.  co m*/
            circle.setImageURI(Uri.fromFile(new File(item.getIconFilePath())));
        }

        LayoutParams lp = new LayoutParams(diameter, diameter);
        circle.setLayoutParams(lp);
        circles.add(circle);
    }

    return circles;
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // menu items
    MenuItem imSettings = menu.findItem(R.id.action_settings);
    if (imSettings != null) {
        // set visible is the other is invisible
        Drawable closeIcon = imSettings.getIcon();
        ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
        imSettings.setIcon(closeIcon);//from  w w  w . ja va2 s.  c o m
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:ru.orangesoftware.financisto.activity.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    //Checking if the item is in checked state or not, if not make it in checked state
    if (menuItem.isCheckable()) {
        menuItem.setChecked(true);/* w  w w  .  jav  a2s. co  m*/
    }

    //Closing drawer on item click
    mDrawerLayout.closeDrawers();

    if (menuItem.isChecked()) {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(menuItem.getTitle());
        actionBar.setIcon(menuItem.getIcon());
    }

    FragmentManager fm = getSupportFragmentManager();

    navMenuItemId = menuItem.getItemId();
    //Check to see which item was being clicked and perform appropriate action
    switch (navMenuItemId) {

    //Replacing the main content with ContentFragment Which is our Inbox View;
    case R.id.accounts:
        selectedAccountId = -1;
        android.support.v4.app.FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.replace(R.id.main_content_frame, AccountListFragment.newInstance(), "accounts");
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();

        fab.show();
        break;
    case R.id.blotter:
        android.support.v4.app.FragmentTransaction blotterFragmentTransaction = fm.beginTransaction();
        blotterFragmentTransaction.replace(R.id.main_content_frame,
                BlotterFragment.newInstance(true, selectedAccountId), "blotter");
        blotterFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        blotterFragmentTransaction.addToBackStack(null);
        blotterFragmentTransaction.commit();

        fab.show();
        break;
    case R.id.scheduled_transactions:
        startActivity(new Intent(this, ScheduledListActivity.class));
        break;
    case R.id.budgets:
        android.support.v4.app.FragmentTransaction budgetFragmentTransaction = fm.beginTransaction();
        budgetFragmentTransaction.replace(R.id.main_content_frame, new BudgetListFragment());
        budgetFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        budgetFragmentTransaction.addToBackStack(null);
        budgetFragmentTransaction.commit();

        fab.show();
        break;
    case R.id.reports:
        android.support.v4.app.FragmentTransaction reportsFragmentTransaction = fm.beginTransaction();
        reportsFragmentTransaction.replace(R.id.main_content_frame, new ReportListFragment());
        reportsFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        reportsFragmentTransaction.addToBackStack(null);
        reportsFragmentTransaction.commit();

        fab.hide();
        break;
    case R.id.planner:
        startActivity(new Intent(this, PlannerActivity.class));
        break;
    case R.id.entities:
        final MenuEntities[] entities = MenuEntities.values();
        ListAdapter adapter = EnumUtils.createEntityEnumAdapter(this, entities);
        final AlertDialog d = new AlertDialog.Builder(this)
                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        MenuEntities e = entities[which];
                        startActivity(new Intent(MainActivity.this, e.getActivityClass()));
                    }
                }).create();
        d.setTitle(R.string.entities);
        d.show();
        break;
    case R.id.menu_sync_online:
        doOnlineSync();
        break;
    //            case R.id.menu_sync_flowzr:
    //                doFlowzrSync();
    //                break;
    case R.id.menu_mass_operations:
        startActivity(new Intent(this, MassOpActivity.class));
        break;
    case R.id.menu_restore_database:
        doImport();
        break;
    case R.id.menu_backup_database:
        doBackup();
        break;
    case R.id.menu_backup_database_to:
        doBackupTo();
        break;
    case R.id.menu_backup_restore_database_online:
        showPickOneDialog(this, R.string.backup_restore_database_online, BackupRestoreEntities.values(), this);
        break;
    case R.id.menu_import_export:
        showPickOneDialog(this, R.string.import_export, ImportExportEntities.values(), this);
        break;
    case R.id.menu_settings:
        startActivityForResult(new Intent(this, PreferencesActivity.class), CHANGE_PREFERENCES_RESULT);
        break;
    case R.id.menu_integrity_fix:
        doIntegrityFix();
        break;
    case R.id.menu_donate:
        openBrowser("market://search?q=pname:ru.orangesoftware.financisto.support");
        break;
    case R.id.menu_about:
        startActivity(new Intent(this, AboutActivity.class));
        break;
    default:
        Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
        fab.hide();
        break;
    }

    fm.executePendingTransactions();
    return true;
}