Example usage for android.view MenuItem setEnabled

List of usage examples for android.view MenuItem setEnabled

Introduction

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

Prototype

public MenuItem setEnabled(boolean enabled);

Source Link

Document

Sets whether the menu item is enabled.

Usage

From source file:org.wikipedia.edit.EditSectionActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_edit_section, menu);
    MenuItem item = menu.findItem(R.id.menu_save_section);

    if (editSummaryFragment.isActive()) {
        item.setTitle(getString(R.string.edit_next));
    } else if (editPreviewFragment.isActive()) {
        item.setTitle(getString(R.string.edit_done));
    } else {/*w ww  . j  a v  a  2s  .  com*/
        item.setTitle(getString(R.string.edit_next));
    }

    if (abusefilterEditResult != null) {
        if (abusefilterEditResult.getType() == EditAbuseFilterResult.TYPE_ERROR) {
            item.setEnabled(false);
        } else {
            item.setEnabled(true);
        }
    } else {
        item.setEnabled(sectionTextModified);
    }

    View v = getLayoutInflater().inflate(R.layout.item_edit_actionbar_button, null);
    item.setActionView(v);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    v.setLayoutParams(params);
    TextView txtView = v.findViewById(R.id.edit_actionbar_button_text);
    txtView.setText(item.getTitle());
    txtView.setTypeface(null, item.isEnabled() ? Typeface.BOLD : Typeface.NORMAL);
    v.setTag(item);
    v.setClickable(true);
    v.setEnabled(item.isEnabled());
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onOptionsItemSelected((MenuItem) view.getTag());
        }
    });

    v.setBackgroundColor(ContextCompat.getColor(this,
            item.isEnabled()
                    ? (editPreviewFragment.isActive() ? R.color.accent50
                            : ResourceUtil.getThemedAttributeId(this, R.attr.colorAccent))
                    : R.color.base50));

    return true;
}

From source file:co.uk.socialticker.ticker.TickerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Boolean toggle = true;/* w w  w . j  a  v  a2s . c  o  m*/

    MenuItem update = menu.findItem(R.id.menu_twitter_update);
    MenuItem logout = menu.findItem(R.id.menu_twitter_logout);

    if (!isTwitterLoggedInAlready()) {
        toggle = false;
    }
    update.setEnabled(toggle);
    logout.setEnabled(toggle);

    super.onPrepareOptionsMenu(menu);
    return true;
}

From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java

/**
 * {@inheritDoc}//from ww  w  . j a  v a 2s  .c o m
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    Bundle args = getArguments();
    boolean allowContextualActions = (args == null) ? true
            : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
    if (allowContextualActions) {
        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.file_actions_menu, menu);
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        OCFile targetFile = (OCFile) mAdapter.getItem(info.position);

        if (mContainerActivity.getStorageManager() != null) {
            FileMenuFilter mf = new FileMenuFilter(targetFile,
                    mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity());
            mf.filter(menu);
        }

        /// TODO break this direct dependency on FileDisplayActivity... if possible
        MenuItem item = menu.findItem(R.id.action_open_file_with);
        FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment();
        if (frag != null && frag instanceof FileDetailFragment
                && frag.getFile().getFileId() == targetFile.getFileId()) {
            item = menu.findItem(R.id.action_see_details);
            if (item != null) {
                item.setVisible(false);
                item.setEnabled(false);
            }
        }

        //            String.format(mContext.getString(R.string.subject_token),
        //                    getClient().getCredentials().getUsername(), file.getFileName()));

    }
}

From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java

private void showFileAction(int fileIndex) {
    Bundle args = getArguments();//from   w ww  . j  a v  a  2  s.  co  m
    PopupMenu pm = new PopupMenu(getActivity(), null);
    Menu menu = pm.getMenu();

    boolean allowContextualActions = (args == null) ? true
            : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);

    if (allowContextualActions) {
        MenuInflater inflater = getActivity().getMenuInflater();

        inflater.inflate(R.menu.file_actions_menu, menu);
        OCFile targetFile = (OCFile) mAdapter.getItem(fileIndex);

        if (mContainerActivity.getStorageManager() != null) {
            FileMenuFilter mf = new FileMenuFilter(targetFile,
                    mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity());
            mf.filter(menu);
        }

        /// TODO break this direct dependency on FileDisplayActivity... if possible
        MenuItem item = menu.findItem(R.id.action_open_file_with);
        FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment();
        if (frag != null && frag instanceof FileDetailFragment
                && frag.getFile().getFileId() == targetFile.getFileId()) {
            item = menu.findItem(R.id.action_see_details);
            if (item != null) {
                item.setVisible(false);
                item.setEnabled(false);
            }
        }

        FileActionsDialogFragment dialog = FileActionsDialogFragment.newInstance(menu, fileIndex,
                targetFile.getFileName());
        dialog.setTargetFragment(this, 0);
        dialog.show(getFragmentManager(), FileActionsDialogFragment.FTAG_FILE_ACTIONS);
    }
}

From source file:org.andstatus.app.msg.TimelineActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MyAccount ma = MyContextHolder.get().persistentAccounts().getCurrentAccount();
    boolean enableReload = isTimelineCombined() || ma.isValidAndSucceeded();
    MenuItem item = menu.findItem(R.id.reload_menu_item);
    item.setEnabled(enableReload);
    item.setVisible(enableReload);//  w  ww .  ja v  a  2 s . c  om

    prepareDrawer();

    if (mContextMenu != null) {
        mContextMenu.setAccountUserIdToActAs(0);
    }

    if (mMessageEditor != null) {
        mMessageEditor.onPrepareOptionsMenu(menu);
    }

    boolean enableGlobalSearch = MyContextHolder.get().persistentAccounts().isGlobalSearchSupported(ma,
            isTimelineCombined());
    item = menu.findItem(R.id.global_search_menu_id);
    item.setEnabled(enableGlobalSearch);
    item.setVisible(enableGlobalSearch);

    return super.onPrepareOptionsMenu(menu);
}

From source file:org.videolan.vlc.gui.MyFragment.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (menu == null)
        return false;
    Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
    MenuItem item;
    // Disable the sort option if we can't use it on the current fragment.
    if (current == null || !(current instanceof ISortable)) {
        item = menu.findItem(R.id.ml_menu_sortby);
        if (item == null)
            return false;
        item.setEnabled(false);
        item.setVisible(false);//from  w  w  w.j  ava  2 s  .  co  m
    } else {
        ISortable sortable = (ISortable) current;
        item = menu.findItem(R.id.ml_menu_sortby);
        if (item == null)
            return false;
        item.setEnabled(true);
        item.setVisible(true);
        item = menu.findItem(R.id.ml_menu_sortby_name);
        if (sortable.sortDirection(VideoListAdapter.SORT_BY_TITLE) == 1)
            item.setTitle(R.string.sortby_name_desc);
        //item.setTitle(R.string.sortby_name_desc);
        else
            item.setTitle(R.string.sortby_name);
        item = menu.findItem(R.id.ml_menu_sortby_length);
        if (sortable.sortDirection(VideoListAdapter.SORT_BY_LENGTH) == 1)
            item.setTitle(R.string.sortby_length_desc);
        else
            item.setTitle(R.string.sortby_length);
        item = menu.findItem(R.id.ml_menu_sortby_date);
        if (sortable.sortDirection(VideoListAdapter.SORT_BY_DATE) == 1)
            item.setTitle(R.string.sortby_date_desc);
        else
            item.setTitle(R.string.sortby_date);
    }

    boolean networkSave = current instanceof NetworkBrowserFragment
            && !((NetworkBrowserFragment) current).isRootDirectory();
    if (networkSave) {
        item = menu.findItem(R.id.ml_menu_save);
        item.setVisible(true);
        String mrl = ((BaseBrowserFragment) current).mMrl;
        item.setIcon(
                MediaDatabase.getInstance().networkFavExists(Uri.parse(mrl)) ? R.drawable.ic_menu_bookmark_w
                        : R.drawable.ic_menu_bookmark_outline_w);
    } else
        menu.findItem(R.id.ml_menu_save).setVisible(false);
    if (current instanceof MRLPanelFragment)
        menu.findItem(R.id.ml_menu_clean).setVisible(!((MRLPanelFragment) current).isEmpty());
    boolean showLast = current instanceof AudioBrowserFragment || (current instanceof VideoGridFragment
            && mSettings.getString(PreferencesActivity.VIDEO_LAST, null) != null);
    menu.findItem(R.id.ml_menu_last_playlist).setVisible(showLast);
    return true;
}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActionMode.java

private void getMenu(Menu menu) {
    MenuItem mi;
    menu.clear();// w w w .  ja  v  a  2 s  . c  o  m

    mi = menu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_DELETE_ID,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings);
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // GROUP MENU
    if (selectedSpenObjects.size() > 1) {
        SubMenu groupSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
                R.string.editor_group_menu);
        groupSubMenu.setIcon(R.drawable.ic_group);
        groupSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID,
                Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID, R.string.editor_group);

        mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID,
                Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID, R.string.editor_ungroup);

        mi.setEnabled(false);
        for (SpenObjectBase obj : selectedSpenObjects) {
            if (obj.getType() == SpenObjectBase.TYPE_CONTAINER) {
                mi.setEnabled(true);
                break;
            }
        }
    }

    // UP MENU
    SubMenu upMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_front_menu);
    upMenu.setIcon(R.drawable.ic_move_up);
    upMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID, R.string.editor_forward);

    mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID, R.string.editor_front);

    // DOWN MENU
    SubMenu downMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_back_menu);
    downMenu.setIcon(R.drawable.ic_move_down);
    downMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID, R.string.editor_backward);

    mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID, R.string.editor_back);
}

From source file:t0mm13b.dmesglog.ui.DMesgViewer.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_clear:
        this.mAdapter.clear();
        mDmesgViewerHandler.obtainMessage(DmesgLogHelpers.MSG_LISTVIEW_ADAPTER_REFRESH).sendToTarget();
        fixUpTitle(this.mDmesgLogHandler.getIsPaused());
        return true;
    case R.id.menu_pause:
        handlePauseResume(item);//from w w w.j a va 2 s  .  c om
        return true;
    case R.id.menu_preferences:
        Intent intentLaunchPrefs = new Intent(this, t0mm13b.dmesglog.prefs.DMesgPrefs.class);
        intentLaunchPrefs.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intentLaunchPrefs);
        return true;
    case R.id.menu_share:
        handlePause(item);
        new asyncSaveDmesg(this, this.mAdapter.getEntries(), item, true).execute();
        item.setEnabled(false); // Prevent multiple spawning of async tasks!
        break;
    case R.id.menu_save:
        handlePause(item);
        new asyncSaveDmesg(this, this.mAdapter.getEntries(), item, false).execute();
        item.setEnabled(false);
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem noteMenu = menu.findItem(MENU_NOTE);
    noteMenu.setEnabled(mLoggerServiceManager.isMediaPrepared());

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.gsma.rcs.ri.messaging.GroupTalkView.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem menuItemParticipants = menu.findItem(R.id.menu_participants);
    MenuItem menuItemSendFile = menu.findItem(R.id.menu_send_file);
    MenuItem menuItemLeave = menu.findItem(R.id.menu_close_session);
    try {/*from www.j  a v  a2  s .  co m*/
        if (mGroupChat != null) {
            menuItemParticipants.setEnabled(mGroupChat.isAllowedToInviteParticipants());
            menuItemLeave.setEnabled(mGroupChat.isAllowedToLeave());
            FileTransferService fileTransferService = getFileTransferApi();
            menuItemSendFile.setEnabled(fileTransferService.isAllowedToTransferFileToGroupChat(mChatId));
        } else {
            menuItemParticipants.setEnabled(false);
            menuItemSendFile.setEnabled(false);
            menuItemLeave.setEnabled(false);
        }
    } catch (RcsServiceException e) {
        showException(e);
    }
    return true;
}