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:eu.trentorise.smartcampus.eb.fragments.ExperiencesListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    menu.setHeaderTitle(R.string.exp_menu_header);
    android.view.MenuInflater inflater = getSherlockActivity().getMenuInflater();
    inflater.inflate(R.menu.exp_list_menu, menu);
    MenuItem item = menu.findItem(R.id.expmenu_share);
    if (item != null) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        Experience exp = experiencesList.get(info.position);
        item.setEnabled(exp.getEntityId() > 0).setVisible(exp.getEntityId() > 0);
    }//from   www .  j a  va  2 s.co  m
}

From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessIfaceQrCodeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.tile_wireless_iface_qr_code_options, menu);

    this.optionsMenu = menu;

    /* Getting the actionprovider associated with the menu item whose id is share */
    final MenuItem shareMenuItem = menu.findItem(R.id.tile_status_wireless_iface_qrcode_share);
    shareMenuItem.setEnabled(mException == null);

    mShareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider();

    final View viewToShare = findViewById(R.id.tile_status_wireless_iface_qrcode_view_to_share);
    //Construct Bitmap and share it
    final Bitmap bitmapToExport = Bitmap.createBitmap(viewToShare.getWidth(), viewToShare.getHeight(),
            Bitmap.Config.ARGB_8888);//from w  w w .  ja  va 2 s.  c  om
    final Canvas canvas = new Canvas(bitmapToExport);
    viewToShare.draw(canvas);

    mFileToShare = new File(getCacheDir(), String.format("QR-Code_for_Wireless_Network__%s__on_router_%s.png",
            nullToEmpty(mSsid), nullToEmpty(mRouterUuid)));
    OutputStream outputStream = null;
    try {
        outputStream = new BufferedOutputStream(new FileOutputStream(mFileToShare, false));
        bitmapToExport.compress(Bitmap.CompressFormat.PNG, COMPRESSION_QUALITY, outputStream);
        outputStream.flush();
    } catch (IOException e) {
        e.printStackTrace();
        Crouton.makeText(this, getString(R.string.internal_error_please_try_again), Style.ALERT).show();
    } finally {
        try {
            if (outputStream != null) {
                outputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
            //No Worries
        }
    }

    setShareFile(mFileToShare);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.cachirulop.moneybox.fragment.MovementsFragment.java

/**
 * Creates a context menu for the list of movements, showing an option for
 * delete the movement and another to get the movement.
 */// w w w . j a  v  a 2 s .c  om
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    if (v.getId() == R.id.lvMovements) {
        AdapterView.AdapterContextMenuInfo info;
        ListView listView;
        Movement selected;

        listView = (ListView) getActivity().findViewById(R.id.lvMovements);
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;

        selected = (Movement) ((MoneyboxMovementAdapter) listView.getAdapter()).getItem(info.position);

        MenuItem item;

        menu.setHeaderTitle(selected.getInsertDateFormatted());
        item = menu.add(Menu.NONE, CONTEXT_MENU_GET, 0, R.string.get_from_moneybox);
        item.setEnabled(MovementsManager.canGetMovement(selected));

        item = menu.add(Menu.NONE, CONTEXT_MENU_DROP, 1, R.string.drop_to_moneybox_again);
        item.setEnabled(MovementsManager.canDropMovement(selected));

        item = menu.add(Menu.NONE, CONTEXT_MENU_DELETE, 2, R.string.delete);
        item.setEnabled(MovementsManager.canDeleteMovement(selected));
    }
}

From source file:ca.rmen.android.palidamuerte.app.poem.detail.PoemDetailActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Log.v(TAG, "onPrepareOptionsMenu");
    super.onPrepareOptionsMenu(menu);
    MenuItem prev = menu.findItem(R.id.action_prev);
    MenuItem next = menu.findItem(R.id.action_next);
    prev.setVisible(true);/*from  w  w  w  .j  ava2s .c  om*/
    next.setVisible(true);
    if (mPoemPagerAdapter != null) {
        prev.setEnabled(mViewPager.getCurrentItem() > 0);
        next.setEnabled(mViewPager.getCurrentItem() < mPoemPagerAdapter.getCount() - 1);
    }
    final View view = menu.findItem(R.id.action_share).getActionView();
    ActionBar.hackSetMaxHeight(view, getActionBar().getHeight());
    return true;
}

From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java

public void UpdateCurrentGroupMenu() {
    StartActivity rootactivity = (StartActivity) getActivity();
    Menu menu = rootactivity.getActionMenu();
    if (menu != null) {
        MenuItem automation = menu.findItem(R.id.menu_automation);
        if (automation != null) {
            automation.setEnabled(false);
            Menu submenu = automation.getSubMenu();
            if (submenu == null)
                return;
            ////  w  ww  .  j  a  v  a2s  . c om
            submenu.removeGroup(Menu.NONE);
            if (mGroupPrograms.size() > 0) {
                for (Module program : mGroupPrograms) {
                    MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName());
                    prg.setIcon(R.drawable.ic_action_flash_on);
                    MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                    final String paddress = program.Address;
                    String groupname = "";
                    try {
                        groupname = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8");
                    } catch (Exception e) {
                    }
                    final String gname = groupname;
                    prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            String apicall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" + paddress
                                    + "/" + gname + "/" + new Date().getTime();
                            Control.callServiceApi(apicall, null);
                            return true;
                        }
                    });
                }
                automation.setEnabled(true);
            }
        }
        //
        //            MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro");
        //            recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        //                @Override
        //                public boolean onMenuItemClick(MenuItem menuItem) {
        //                    StartActivity sa = (StartActivity)getActivity();
        //                    sa.openMacroRecordMenu();
        //                    return true;
        //                }
        //            });
        //            rootactivity.supportInvalidateOptionsMenu();
    }
}

From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java

private void setSaveMenuEnabled(boolean enabled) {
    if (fragmentMenu != null) {
        MenuItem item = fragmentMenu.findItem(R.id.saveContact);
        if (item != null)
            item.setEnabled(enabled);
    } else if (getView() != null) {
        View saveContact = getView().findViewById(R.id.save_contact);
        if (saveContact != null)
            saveContact.setVisibility(enabled ? View.VISIBLE : View.GONE);
    }//from ww w.  j  a  va2  s  .  c  o m
}

From source file:ch.kanti_baden.pu_marc_14b.traffictimewaste.SORT_TYPE.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_post_list, menu);

    // Disable create post button if user isn't logged in
    if (DatabaseLink.instance.isLoggedIn()) {
        MenuItem menuItem = menu.findItem(R.id.action_login);
        menuItem.setEnabled(false);
    } else {/*from   w ww .  j  a v  a2  s  .  c o  m*/
        MenuItem menuItem = menu.findItem(R.id.action_create);
        menuItem.setEnabled(false);
        Drawable icon = menuItem.getIcon();
        icon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
        menuItem.setIcon(icon);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchView.setTranslationX(500f);
            searchView.setAlpha(0f);
            searchView.animate().translationX(0);
            searchView.animate().alpha(1f);
        }
    });
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;
}

From source file:com.janela.mobile.ui.gist.GistFragment.java

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

    boolean owner = isOwner();
    if (!owner) {
        menu.removeItem(R.id.m_delete);/*from w  w  w.  j a va 2 s.co m*/
        MenuItem starItem = menu.findItem(R.id.m_star);
        starItem.setEnabled(loadFinished && !owner);
        if (starred)
            starItem.setTitle(R.string.unstar);
        else
            starItem.setTitle(R.string.star);
    } else
        menu.removeItem(R.id.m_star);
}

From source file:com.mtomczak.nausicaa.MainActivity.java

@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {

    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
        MenuItem status = menu.findItem(R.id.status_view_option);
        status.setVisible(currentSubview != NausicaaSubview.STATUS);
        status.setEnabled(currentSubview != NausicaaSubview.STATUS);

        MenuItem docking = menu.findItem(R.id.docking_view_option);
        docking.setVisible(currentSubview != NausicaaSubview.DOCKING);
        docking.setEnabled(currentSubview != NausicaaSubview.DOCKING);

        return true;
    }/*  w w  w  .  j a  v a2s  .co  m*/
    return super.onPreparePanel(featureId, view, menu);
}

From source file:bbct.android.common.activity.BaseballCardList.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Log.d(TAG, "onPrepareOptionsMenu()");

    MenuItem filter = menu.findItem(R.id.filter_menu);
    MenuItem clearFilter = menu.findItem(R.id.clear_filter_menu);
    if (this.filterParams == null) {
        filter.setVisible(true);// w w w  .j  a va2 s  . com
        filter.setEnabled(true);

        clearFilter.setVisible(false);
        clearFilter.setEnabled(false);
    } else {
        filter.setVisible(false);
        filter.setEnabled(false);

        clearFilter.setVisible(true);
        clearFilter.setEnabled(true);
    }
}