Example usage for android.view Menu findItem

List of usage examples for android.view Menu findItem

Introduction

In this page you can find the example usage for android.view Menu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    LibraryAdapter adapter = mCurrentAdapter;
    menu.findItem(MENU_GO_HOME).setVisible(adapter != null && adapter.getMediaType() == MediaUtils.TYPE_FILE
            && (!mSlidingView.isShrinkable() || !mSlidingView.isFullyExpanded()));
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (menu != null) {

        menu.findItem(R.id.action_resume_all).setVisible(false);
        menu.findItem(R.id.action_pause_all).setVisible(false);
        menu.findItem(R.id.action_add).setVisible(false);

        if (getActivity().findViewById(R.id.one_frame) != null) {
            menu.findItem(R.id.action_refresh).setVisible(false);
        } else {/*ww w .j  av a2 s. c  o m*/
            menu.findItem(R.id.action_refresh).setVisible(true);
        }

        if (getActivity().findViewById(R.id.one_frame) != null) {
            menu.findItem(R.id.action_sort_menu).setVisible(false);
        } else {
            menu.findItem(R.id.action_sort_menu).setVisible(true);
        }

        menu.findItem(R.id.action_resume).setVisible(true);
        menu.findItem(R.id.action_pause).setVisible(true);
        menu.findItem(R.id.action_priority_menu).setVisible(true);
        menu.findItem(R.id.action_increase_prio).setVisible(true);
        menu.findItem(R.id.action_decrease_prio).setVisible(true);
        menu.findItem(R.id.action_max_prio).setVisible(true);
        menu.findItem(R.id.action_min_prio).setVisible(true);
        menu.findItem(R.id.action_delete).setVisible(true);
        menu.findItem(R.id.action_delete_drive).setVisible(true);
        menu.findItem(R.id.action_download_rate_limit).setVisible(true);
        menu.findItem(R.id.action_upload_rate_limit).setVisible(true);
        menu.findItem(R.id.action_recheck).setVisible(true);

        if (getActivity().findViewById(R.id.one_frame) != null) {
            menu.findItem(R.id.action_search).setVisible(false);
        } else {
            menu.findItem(R.id.action_search).setVisible(true);
        }

        //            Log.d("Debug", "qb_version: " + MainActivity.qb_version);

        if (MainActivity.qb_version.equals("3.2.x")) {
            menu.findItem(R.id.action_first_last_piece_prio).setVisible(true);
            menu.findItem(R.id.action_sequential_download).setVisible(true);
            menu.findItem(R.id.action_toggle_alternative_rate).setVisible(true);
            // TODO: Change add_tracker to true
            //                menu.findItem(R.id.action_add_tracker).setVisible(false);
            menu.findItem(R.id.action_label_menu).setVisible(true);
            menu.findItem(R.id.action_set_label).setVisible(true);
            menu.findItem(R.id.action_delete_label).setVisible(true);

            if (Integer.parseInt(MainActivity.qb_api) < 8) {
                menu.findItem(R.id.action_delete_label).setVisible(false);
            }

            // Set Alternate Speed limit state
            if (MainActivity.alternative_speeds) {
                menu.findItem(R.id.action_toggle_alternative_rate).setChecked(true);
            } else {
                menu.findItem(R.id.action_toggle_alternative_rate).setChecked(true);
            }

        } else {
            menu.findItem(R.id.action_first_last_piece_prio).setVisible(false);
            menu.findItem(R.id.action_sequential_download).setVisible(false);
            menu.findItem(R.id.action_toggle_alternative_rate).setVisible(false);
            // TODO: Change add_tracker to true
            //                menu.findItem(R.id.action_add_tracker).setVisible(false);
            menu.findItem(R.id.action_label_menu).setVisible(false);
            menu.findItem(R.id.action_set_label).setVisible(false);
            menu.findItem(R.id.action_delete_label).setVisible(false);

        }

    }
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.poi_map, menu);

    miSearch = menu.findItem(R.id.action_search);
    miDirections = menu.findItem(R.id.action_directions);
    miPlay = menu.findItem(R.id.action_play);

    String[] poiNames = new String[gmm.pois.size()];
    for (int i = 0; i < gmm.pois.size(); i++) {
        poiNames[i] = gmm.pois.get(i).getName();
    }/*from ww w.  j ava  2  s  . c  om*/

    searchView = (ArrayAdapterSearchView) (SearchView) MenuItemCompat.getActionView(miSearch);

    mAdapter = new ArrayAdapter<String>(this, R.layout.dropdown_item, poiNames);

    searchView.setAdapter(mAdapter);

    searchView.setThreshold(1); // one letter is enough for auto complete

    searchView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // when clicked on suggested item
            SearchModule.searchGoogleMap(POIMapActivity.this, gmm.googleMap, gmm.pois, searchView,
                    mAdapter.getItem(position).toString());
            MenuItemCompat.collapseActionView(miSearch);

        }
    });

    searchView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // when clicked on search view (e.g. search icon)
            searchView.showDropDown();

        }
    });

    searchView.setQueryHint(POIMapActivity.this.getResources().getString(R.string.search_hint));

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // some action if needed
            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            // get entered query value and search
            SearchModule.searchGoogleMap(POIMapActivity.this, gmm.googleMap, gmm.pois, searchView, query);

            MenuItemCompat.collapseActionView(miSearch);

            return true;

        }
    };
    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);

    // return true;
}

From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    this.menu = menu;
    MenuItem itemNotification = menu.findItem(R.id.notifications);
    if (itemNotification != null) {
        if (notificationCount > 0) {
            itemNotification.setIcon(R.drawable.ic_bell_ring_white_24dp);
        } else {//from  ww w.  j  a va  2s.c  o  m
            itemNotification.setIcon(R.drawable.ic_bell_outline_white_24dp);
        }

        MenuItem itemConversation = menu.findItem(R.id.conversations);
        if (conversationCount > 0) {
            itemConversation.setIcon(R.drawable.ic_message_text_white_24dp);
        } else {
            itemConversation.setIcon(R.drawable.ic_message_text_outline_white_24dp);
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.gimranov.zandy.app.ItemActivity.java

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

    // Turn on sort item
    MenuItem sort = menu.findItem(R.id.do_sort);
    sort.setEnabled(true);/*from   w  w  w  . j  a  va2s. c o m*/
    sort.setVisible(true);

    // Turn on search item
    MenuItem search = menu.findItem(R.id.do_search);
    search.setEnabled(true);
    search.setVisible(true);

    // Turn on identifier item
    MenuItem identifier = menu.findItem(R.id.do_identifier);
    identifier.setEnabled(true);
    identifier.setVisible(true);

    return true;
}

From source file:com.adamas.client.android.MainActivity.java

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

    _menuItemStartStop = menu.findItem(R.id.action_start_stop_vpn);
    final Switch mySwitch = (Switch) _menuItemStartStop.getActionView()
            .findViewById(R.id.switchForStartStopConnector);
    if (_checked != null) {
        mySwitch.setChecked(_checked.booleanValue());
        _checked = null;//  ww  w  .  java2  s  .c  om
    } else {
        mySwitch.setChecked(_connected);
    }
    if (_connecting.get() || _disconnecting.get()) {
        _menuItemStartStop.getActionView().findViewById(R.id.switchForStartStopConnector)
                .setVisibility(View.GONE);
        _menuItemStartStop.getActionView().findViewById(R.id.progressBarConnecting).setVisibility(View.VISIBLE);
    }
    //attach a listener to check for changes in state
    mySwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (_runProcessConnectDisconnectKey) {
                if (isChecked) {
                    processConnectDisconnectKey();
                } else {
                    processConnectDisconnectKey();
                }
            } else {
                _runProcessConnectDisconnectKey = true;
            }
        }
    });

    return true;
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);
    menu.findItem(R.id.MENU_AUTHOR_LINK).setTitle(comicDef.getAuthorLinkText());
    return true;//  w  w  w.  j  a v a 2s  . c o  m
}

From source file:bf.io.openshop.ux.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    // Prepare search view
    MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        prepareSearchView(searchItem);//from  w ww.j  a  v a  2 s  .c  o m
    }

    // Prepare cart count info
    MenuItem cartItem = menu.findItem(R.id.action_cart);
    MenuItemCompat.setActionView(cartItem, R.layout.action_icon_shopping_cart);
    View view = MenuItemCompat.getActionView(cartItem);
    cartCountView = (TextView) view.findViewById(R.id.shopping_cart_notify);
    showNotifyCount(cartCountNotificationValue);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onCartSelected();
        }
    });
    if (cartCountNotificationValue == CONST.DEFAULT_EMPTY_ID) {
        // If first cart count check, then sync server cart data.
        getCartCount(true);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.vmihalachi.turboeditor.fragment.EditorFragment.java

/**
 * {@inheritDoc}/*  w  ww.j  a v a2s. c  o  m*/
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_editor, menu);
    menu.findItem(R.id.im_line_numbers).setChecked(this.sLineNumbers);
    menu.findItem(R.id.im_syntax_highlight).setChecked(this.sColorSyntax);
    menu.findItem(R.id.im_use_monospace).setChecked(this.mUseMonospace);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:fr.cph.chicago.activity.BusActivity.java

@Override
public final boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.mMenu = menu;

    // Inflate menu with no search
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_no_search, menu);

    // Modify action bar title
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("Bus");

    // Load top bar animation
    MenuItem refreshMenuItem = menu.findItem(R.id.action_refresh);
    refreshMenuItem.setActionView(R.layout.progressbar);
    refreshMenuItem.expandActionView();/* www  .  j  a  v  a2  s.c om*/

    return true;
}