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.abewy.android.apps.klyph.app.MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    if (notificationsFragment != null && menu.findItem(R.id.menu_notifications) == null) {
        final MenuItem notificationItem = menu.add(Menu.NONE, R.id.menu_notifications, 2,
                R.string.menu_notifications);
        notificationItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        notificationItem.setActionView(R.layout.actionbar_item_notifications);

        final TextView notificationTextView = (TextView) notificationItem.getActionView()
                .findViewById(R.id.textView);

        int count = notificationsFragment.getUnreadCount();

        notificationTextView.setText(String.valueOf(count));

        if (count > 0) {
            notificationTextView/*w w  w .j  a  va 2 s  .c  om*/
                    .setBackgroundResource(AttrUtil.getResourceId(this, R.attr.notificationsItemBackground));
        } else {
            notificationTextView.setBackgroundResource(R.drawable.notifications_read_background);

        }

        notificationItem.getActionView().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onOptionsItemSelected(notificationItem);
            }
        });
    }

    if (!KlyphFlags.IS_PRO_VERSION && menu.findItem(R.id.menu_buy_pro) == null) {
        menu.add(Menu.NONE, R.id.menu_buy_pro, 2, R.string.menu_buy_pro)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    if (menu.findItem(R.id.menu_faq) == null) {
        menu.add(Menu.NONE, R.id.menu_faq, Menu.NONE, R.string.menu_faq)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:eu.thecoder4.gpl.pleftdroid.EventDetailActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (arole.equals(PleftDroidDbAdapter.R_INVITOR)) {
        menu.findItem(RESENDINV_ID).setVisible(curpid == invitee ? false : true);
    }/*from   w ww.jav  a  2 s. c om*/

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.cssweb.android.base.DialogActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (activityKind == Global.QUOTE_USERSTK) {
        MenuItem localMenuItem1 = menu.findItem(R.id.zr_hq_mystock);
        MenuItem localMenuItem2 = menu.findItem(R.id.zr_hq_addstock);
        MenuItem localMenuItem3 = menu.findItem(R.id.zr_hq_fundtrade);
        MenuItem localMenuItem4 = menu.findItem(R.id.zr_hq_gugle);
        MenuItem localMenuItem5 = menu.findItem(R.id.zr_hq_chicang);
        if (localMenuItem1 != null)
            localMenuItem1.setVisible(false);
        if (localMenuItem2 != null)
            localMenuItem2.setVisible(false);
        if (localMenuItem3 != null)
            localMenuItem3.setVisible(false);
        if (localMenuItem4 != null)
            localMenuItem4.setVisible(false);
        if (localMenuItem5 != null)
            localMenuItem5.setVisible(true);
    } else if (activityKind == Global.QUOTE_STOCK || activityKind == Global.QUOTE_BOND
            || activityKind == Global.QUOTE_MONETARY || activityKind == Global.QUOTE_MIX) {
        MenuItem localMenuItem1 = menu.findItem(R.id.zr_hq_mystock_set);
        MenuItem localMenuItem2 = menu.findItem(R.id.zr_hq_remove);
        MenuItem localMenuItem3 = menu.findItem(R.id.zr_hq_quickbuy);
        MenuItem localMenuItem4 = menu.findItem(R.id.zr_hq_quicksale);
        MenuItem localMenuItem5 = menu.findItem(R.id.zr_hq_revocation);
        MenuItem localMenuItem6 = menu.findItem(R.id.zr_hq_remove);

        MenuItem localMenuItem7 = menu.findItem(R.id.zr_hq_queryfund);

        if (localMenuItem1 != null)
            localMenuItem1.setVisible(false);
        if (localMenuItem2 != null)
            localMenuItem2.setVisible(false);
        if (localMenuItem3 != null)
            localMenuItem3.setVisible(false);
        if (localMenuItem4 != null)
            localMenuItem4.setVisible(false);
        if (localMenuItem5 != null)
            localMenuItem5.setVisible(false);
        if (localMenuItem6 != null)
            localMenuItem6.setVisible(false);
        if (localMenuItem7 != null) {
            localMenuItem7.setVisible(true);
        }/* ww  w  .java 2  s  . c om*/

    } else if (activityKind == Global.SUN_PRIVATE) {
        MenuItem localMenuItem1 = menu.findItem(R.id.zr_hq_mystock_set);
        MenuItem localMenuItem2 = menu.findItem(R.id.zr_hq_remove);
        MenuItem localMenuItem3 = menu.findItem(R.id.zr_hq_quickbuy);
        MenuItem localMenuItem4 = menu.findItem(R.id.zr_hq_quicksale);
        MenuItem localMenuItem5 = menu.findItem(R.id.zr_hq_revocation);
        MenuItem localMenuItem6 = menu.findItem(R.id.zr_hq_remove);
        MenuItem localMenuItem7 = menu.findItem(R.id.zr_hq_addstock);
        MenuItem localMenuItem8 = menu.findItem(R.id.zr_hq_gugle);

        MenuItem localMenuItem9 = menu.findItem(R.id.zr_hq_queryfund);

        if (localMenuItem1 != null)
            localMenuItem1.setVisible(false);
        if (localMenuItem2 != null)
            localMenuItem2.setVisible(false);
        if (localMenuItem3 != null)
            localMenuItem3.setVisible(false);
        if (localMenuItem4 != null)
            localMenuItem4.setVisible(false);
        if (localMenuItem5 != null)
            localMenuItem5.setVisible(false);
        if (localMenuItem6 != null)
            localMenuItem6.setVisible(false);
        if (localMenuItem7 != null)
            localMenuItem7.setVisible(false);
        if (localMenuItem8 != null)
            localMenuItem8.setVisible(false);
        if (localMenuItem9 != null)
            localMenuItem9.setVisible(true);
    } else if (activityKind == Global.QUOTE_DAPAN || activityKind == Global.QUOTE_HSZS
            || activityKind == Global.HK_CYB || activityKind == Global.HK_MAINBOARD
            || activityKind == Global.ZJS || activityKind == Global.SDZ) {
        MenuItem localMenuItem1 = menu.findItem(R.id.zr_hq_mystock_set);
        MenuItem localMenuItem2 = menu.findItem(R.id.zr_hq_remove);
        MenuItem localMenuItem3 = menu.findItem(R.id.zr_hq_fundtrade);
        MenuItem localMenuItem4 = menu.findItem(R.id.zr_hq_gugle);
        MenuItem localMenuItem5 = menu.findItem(R.id.zr_hq_quickbuy);
        MenuItem localMenuItem6 = menu.findItem(R.id.zr_hq_quicksale);
        MenuItem localMenuItem7 = menu.findItem(R.id.zr_hq_revocation);
        if (localMenuItem1 != null)
            localMenuItem1.setVisible(false);
        if (localMenuItem2 != null)
            localMenuItem2.setVisible(false);
        if (localMenuItem3 != null)
            localMenuItem3.setVisible(false);
        if (localMenuItem4 != null)
            localMenuItem4.setVisible(false);
        if (localMenuItem5 != null)
            localMenuItem5.setVisible(false);
        if (localMenuItem6 != null)
            localMenuItem6.setVisible(false);
        if (localMenuItem7 != null)
            localMenuItem7.setVisible(false);
    } else {
        MenuItem localMenuItem1 = menu.findItem(R.id.zr_hq_mystock_set);
        MenuItem localMenuItem2 = menu.findItem(R.id.zr_hq_remove);
        MenuItem localMenuItem3 = menu.findItem(R.id.zr_hq_fundtrade);
        //MenuItem localMenuItem4 = menu.findItem(R.id.zr_hq_gugle);
        if (localMenuItem1 != null)
            localMenuItem1.setVisible(false);
        if (localMenuItem2 != null)
            localMenuItem2.setVisible(false);
        if (localMenuItem3 != null)
            localMenuItem3.setVisible(false);
        //if(localMenuItem4!=null)
        //   localMenuItem4.setVisible(false);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:de.badaix.snapcast.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_snapcast, menu);
    miStartStop = menu.findItem(R.id.action_play_stop);
    miSettings = menu.findItem(R.id.action_settings);
    //        miRefresh = menu.findItem(R.id.action_refresh);
    updateStartStopMenuItem();//  w  ww. ja  va 2s.  c o m
    boolean isChecked = Settings.getInstance(this).getBoolean("hide_offline", false);
    MenuItem menuItem = menu.findItem(R.id.action_hide_offline);
    menuItem.setChecked(isChecked);
    sectionsPagerAdapter.setHideOffline(isChecked);
    //        setHost(host, port, controlPort);
    if (remoteControl != null) {
        updateMenuItems(remoteControl.isConnected());
    }
    return true;
}

From source file:app.sunstreak.yourpisd.ClassSwipeActivity.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.class_swipe_actions, menu);

    if (termIndex == 0)
        menu.findItem(R.id.previous_six_weeks).setEnabled(false);
    else if (termIndex == 7)
        menu.findItem(R.id.next_six_weeks).setEnabled(false);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == studentIndex)
                item.setEnabled(false);//from  w w w  . ja v  a2  s.  c o  m

            item.setOnMenuItemClickListener(new StudentSelectListener(i));
            item.setVisible(true);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getActivity().getMenuInflater().inflate(R.menu.fragment_events_list, menu);

    MenuItem showArchivedMenuItem = menu.findItem(R.id.fragment_events_list_menu_show_archived);
    showArchivedMenuItem.setChecked(showArchivedEvents);
    showArchivedMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override/*from  w w  w.  ja  v  a2s  .  co  m*/
        public boolean onMenuItemClick(MenuItem item) {
            item.setChecked(!item.isChecked());
            showArchivedEvents = item.isChecked();

            downloadData();
            downloadArchivedData();

            return false;
        }
    });
}

From source file:com.acrylicgoat.devchat.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();/* www .j a  v  a  2 s.co m*/
    getMenuInflater().inflate(R.menu.activity_main, menu);
    readDB();
    if (devs != null && devs.size() > 0) {
        for (int i = 0; i < devs.size(); i++) {
            Developer dev = devs.get(i);
            menu.add(0, MENUITEM, 0, dev.getName());

        }
    }
    boolean drawerOpen = drawerLayout.isDrawerOpen(drawerList);
    menu.findItem(R.id.save).setVisible(!drawerOpen);
    return true;
}

From source file:br.com.bioscada.apps.biotracks.TrackDetailActivity.java

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

    Track track = myTracksProviderUtils.getTrack(trackId);
    boolean isSharedWithMe = track != null ? track.isSharedWithMe() : true;

    menu.findItem(R.id.track_detail_edit).setVisible(!isSharedWithMe);
    menu.findItem(R.id.track_detail_help_feedback).setTitle(
            ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable() ? R.string.menu_help_feedback
                    : R.string.menu_help);

    insertMarkerMenuItem = menu.findItem(R.id.track_detail_insert_marker);
    insertPhotoMenuItem = menu.findItem(R.id.track_detail_insert_photo);
    playMenuItem = menu.findItem(R.id.track_detail_play);

    shareMenuItem = menu.findItem(R.id.track_detail_share);
    shareMenuItem.setEnabled(!isSharedWithMe);
    shareMenuItem.setVisible(!isSharedWithMe);

    exportMenuItem = menu.findItem(R.id.track_detail_export);
    sensorStateMenuItem = menu.findItem(R.id.track_detail_sensor_state);
    return super.onCreateOptionsMenu(menu);
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar

    mMenu = menu;/*www .  j  av a2  s .c  o m*/
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search_notice);
    android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu
            .findItem(R.id.search_notice).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setMaxWidth(3800);
    SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete) searchView
            .findViewById(R.id.search_src_text);
    theTextArea.setTextColor(Color.WHITE);//or any color that you want

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);

    return true;

}

From source file:anastasoft.rallyvision.activity.MenuPrincipal.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem aMenuItem = menu.findItem(R.id.action_slider_carregar_trecho);
    if (aMenuItem != null) {
        aMenuItem.setVisible(isSliderActive);

    }//from w  ww. j a  va 2  s.  com

    aMenuItem = menu.findItem(R.id.action_slider_agendar_prova);
    if (aMenuItem != null) {
        //                    aMenuItem.setVisible(true);
        aMenuItem.setVisible(isAgendamentoInicioProvaSliderActive);

    }
    return super.onPrepareOptionsMenu(menu);

}