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:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void addNewItem(Menu menu, int group, int order, String text, MenuMetadata meta, @DrawableRes int icon,
        @DrawableRes Integer actionViewIcon) {
    if (BuildConfig.DEBUG && menu.findItem(order) != null)
        throw new IllegalStateException("Item already id exists: " + order);

    MenuItem item = menu.add(group, order, order, text).setIcon(icon);
    dataUtils.putDrawerMetadata(item, meta);

    if (actionViewIcon != null) {
        item.setActionView(R.layout.layout_draweractionview);

        ImageView imageView = item.getActionView().findViewById(R.id.imageButton);
        imageView.setImageResource(actionViewIcon);
        if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
            imageView.setColorFilter(Color.WHITE);
        }/*w ww  . jav  a  2s.com*/

        item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item));
    }
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void addNewItem(Menu menu, int group, int order, @StringRes int text, MenuMetadata meta,
        @DrawableRes int icon, @DrawableRes Integer actionViewIcon) {
    if (BuildConfig.DEBUG && menu.findItem(order) != null)
        throw new IllegalStateException("Item already id exists: " + order);

    MenuItem item = menu.add(group, order, order, text).setIcon(icon);
    dataUtils.putDrawerMetadata(item, meta);
    if (actionViewIcon != null) {
        item.setActionView(R.layout.layout_draweractionview);

        ImageView imageView = item.getActionView().findViewById(R.id.imageButton);
        imageView.setImageResource(actionViewIcon);
        if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
            imageView.setColorFilter(Color.WHITE);
        }/*from   w w  w  . j av  a2 s .  com*/

        item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item));
    }
}

From source file:com.nearnotes.NoteEdit.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.findItem(R.id.action_done).setVisible(true);
    menu.findItem(R.id.action_new).setVisible(false);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.example.android.bluetoothlegatt.DeviceControlActivity.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_control, menu);
    menu.findItem(R.id.menu_disconnect).setEnabled(isDeviceConnected);
    if (isReadRequested || isWriteRequested) {
        menu.findItem(R.id.action_requesting).setVisible(true);
        menu.findItem(R.id.action_requesting).setActionView(R.layout.actionbar_indeterminate_progress);
    } else {//from w w w .  ja  va 2s .c o  m
        menu.findItem(R.id.action_requesting).setActionView(null);
        menu.findItem(R.id.action_requesting).setVisible(false);
    }
    return true;
}

From source file:net.sf.diningout.app.ui.FriendsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    if (!mListener.onFriendsOptionsMenu()) {
        return;//from w  w  w.  j av a2 s . c om
    }
    inflater.inflate(R.menu.friends, menu);
    if (mInit) {
        menu.removeItem(R.id.search);
    } else {
        MenuItem item = menu.findItem(R.id.search);
        mSearch = (SearchView) item.getActionView();
        mSearch.setSearchableInfo(Managers.search(a).getSearchableInfo(a.getComponentName()));
        SearchViews.setBackground(mSearch, R.drawable.textfield_searchview);
        mSearch.setOnSearchClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                event("friends", "search");
            }
        });
        mSearch.setOnQueryTextListener(new SearchTextListener());
        item.setOnActionExpandListener(new SearchExpandListener());
    }
    if (!Intents.hasActivity(a, sAddIntent)) {
        menu.removeItem(R.id.add);
    }
}

From source file:com.spydiko.rotationmanager.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.main, menu);
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "createOptions");
    if (AppSpecificOrientation.isServiceRunning()) {
        menu.findItem(R.id.itemToggleService).setTitle(R.string.titleServiceStart);
        //         menu.findItem(R.id.itemToggleService).setIcon(android.R.drawable.ic_media_pause);
        //         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        menu.findItem(R.id.itemToggleService).setIcon(R.drawable.ic_on_button_rotation_manager);
    } else {//  www .  j a  v  a 2 s . c om
        menu.findItem(R.id.itemToggleService).setTitle(R.string.titleServiceStop);
        //         menu.findItem(R.id.itemToggleService).setIcon(android.R.drawable.ic_media_play);
        //         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        menu.findItem(R.id.itemToggleService).setIcon(R.drawable.ic_off_button_rotation_manager);
    }
    if (AppSpecificOrientation.getBoot()) {
        menu.findItem(R.id.setOnBoot).setChecked(true);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            menu.findItem(R.id.setOnBoot).setIcon(android.R.drawable.button_onoff_indicator_on);
    } else {
        menu.findItem(R.id.setOnBoot).setChecked(false);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            menu.findItem(R.id.setOnBoot).setIcon(android.R.drawable.button_onoff_indicator_off);
    }
    if (AppSpecificOrientation.isPermNotification()) {
        menu.findItem(R.id.permNotification).setChecked(true);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            menu.findItem(R.id.permNotification).setIcon(android.R.drawable.button_onoff_indicator_on);
    } else {
        menu.findItem(R.id.permNotification).setChecked(false);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            menu.findItem(R.id.permNotification).setIcon(android.R.drawable.button_onoff_indicator_off);
    }

    return true;
}

From source file:android.com.example.contactslist.ui.ContactDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    // Inflates the options menu for this fragment
    inflater.inflate(R.menu.contact_detail_menu, menu);

    // Gets a handle to the "find" menu item
    mEditContactMenuItem = menu.findItem(R.id.menu_edit_contact);

    // If contactUri is null the edit menu item should be hidden, otherwise
    // it is visible.
    mEditContactMenuItem.setVisible(mContactUri != null);
}

From source file:net.reichholf.dreamdroid.fragment.MediaPlayerFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (getMultiPaneHandler().isDrawerOpen())
        return;/*from   w w w . j av a2s.com*/
    if (mMedia != null) {
        String rootPath = (String) mMedia.get(Mediaplayer.KEY_ROOT);
        MenuItem homeMenuItem = menu.findItem(Statics.ITEM_MEDIA_HOME);
        MenuItem backMenuItem = menu.findItem(Statics.ITEM_MEDIA_BACK);

        boolean isPaneOpen = true;
        SlidingPaneLayout spl = getSlidingPaneLayout();
        if (spl != null)
            isPaneOpen = spl.isOpen();

        if (!isPaneOpen || rootPath.equals("None")) {
            homeMenuItem.setVisible(false);
            backMenuItem.setVisible(false);
        } else {
            homeMenuItem.setVisible(true);
            backMenuItem.setVisible(true);
        }
    }
}

From source file:chaitanya.im.searchforreddit.LauncherActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.d(TAG, "onCreateOptionsMenu");
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    MenuItem actionDark = menu.findItem(R.id.action_dark);

    if (donate == 1) {
        menu.findItem(R.id.action_donate).setVisible(false);
    }//from   w  w w . ja va  2 s.c  o  m

    if (theme != 0) {
        actionDark.setChecked(true);
        isChecked = true;
        searchEditText.getText().clear();
        menu.findItem(R.id.action_refresh).setIcon(R.drawable.ic_refresh_white);
    }

    return true;
}