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.androguide.honamicontrol.kernel.KernelFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.profiles, menu);
    MenuItem item = menu.findItem(R.id.profile_spinner);
    View spinner = item != null ? item.getActionView() : null;
    if (spinner instanceof android.widget.Spinner) {
        final SharedPreferences profilePrefs = super.getActivity().getSharedPreferences("PROFILES", 0);
        Spinner profiles = (Spinner) spinner;
        profiles.setAdapter(ArrayAdapter.createFromResource(super.getActivity(), R.array.profiles_array,
                R.layout.spinner_action_row));
        profiles.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override//from w w  w . j  a va  2 s  .co m
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                final int currProfile = profilePrefs.getInt("CURR_PROFILE", 5);
                ActionBarActivity context = (ActionBarActivity) getActivity();
                switch (i) {
                case 0:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryMaxProfile(), context);
                    profileCounter++;
                    break;
                case 1:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryProfile(), context);
                    profileCounter++;
                    break;
                case 2:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BalancedProfile(), context);
                    profileCounter++;
                    break;
                case 3:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new PerformanceProfile(), context);
                    profileCounter++;
                    break;
                case 4:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BenchmarkProfile(), context);
                    profileCounter++;
                    break;
                }
                profilePrefs.edit().putInt("CURR_PROFILE", i).commit();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        profiles.setSelection(profilePrefs.getInt("CURR_PROFILE", 5));
    }
}

From source file:com.aman.stockcalculator.Calculator.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.findItem(R.id.basic).setVisible(!getBasicVisibility());
    menu.findItem(R.id.advanced).setVisible(!getAdvancedVisibility());
    return true;/*from  w  w w  .j av a2s.  co  m*/
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.v(TAG, "onCreateOptionsMenu");
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_poem, menu);
    menu.findItem(R.id.action_about).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.action_share).getActionProvider();
    if (mPoemPagerAdapter != null) {
        long poemId = mPoemPagerAdapter.getPoemIdAt(mViewPager.getCurrentItem());
        Poems.updateShareIntent(mShareActionProvider, PoemDetailActivity.this, poemId);
    }/*w ww. ja v a 2 s  . c  o m*/
    return true;
}

From source file:com.andremion.louvre.home.GalleryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean isMedia = mAdapter.getItemViewType(0) == GalleryAdapter.VIEW_TYPE_MEDIA;
    MenuItem selectAll = menu.findItem(R.id.action_select_all);
    selectAll.setVisible(isMedia);//w  ww . j av a  2  s  .  c om
    MenuItem clear = menu.findItem(R.id.action_clear);
    clear.setVisible(isMedia);
}

From source file:fr.simon.marquis.secretcodes.ui.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    setSupportProgressBarIndeterminateVisibility(CrawlerService.isCrawling);
    menu.findItem(R.id.action_scan).setVisible(!CrawlerService.isCrawling && !mGridView.getAdapter().isEmpty());
    menu.findItem(R.id.action_cancel).setVisible(CrawlerService.isCrawling);
    return super.onPrepareOptionsMenu(menu);
}

From source file:br.com.dsasoft.example.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // If the nav drawer is open, hide action items related to the content view
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
}

From source file:ca.farrelltonsolar.classic.HourLogChart.java

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

    inflater.inflate(R.menu.hour_log_chart_menu, menu); // inflate the menu
    MenuItem shareItem = menu.findItem(R.id.hour_log_chart_preference);
    setupSpinner(shareItem);/*  w w  w.j  a  v  a2s  .c  om*/
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.chinaftw.music.ui.ActionBarCastActivity.java

/**
 * Shows the Cast First Time User experience to the user (an overlay that explains what is
 * the Cast icon)/*w  w w.j  ava  2 s . c o m*/
 */
private void showFtu() {
    Menu menu = mToolbar.getMenu();
    View view = menu.findItem(R.id.media_route_menu_item).getActionView();
    if (view != null && view instanceof MediaRouteButton) {
        new ShowcaseView.Builder(this).setTarget(new ViewTarget(view)).setContentTitle(R.string.touch_to_cast)
                .hideOnTouchOutside().build();
    }
}

From source file:circleplus.app.MainActivity.java

/**
 * Called whenever we call invalidateOptionsMenu()
 *//*from w w w  .  j a v  a  2  s  . com*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // If the nav drawer is open, hide action items related to the content view
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    menu.findItem(R.id.action_search).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
}

From source file:ca.rmen.android.palidamuerte.app.poem.list.PoemListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.v(TAG, "onCreateOptionsMenu");
    super.onCreateOptionsMenu(menu);
    if (mTwoPane && mPoemId >= 0) {
        getMenuInflater().inflate(R.menu.menu_poem, menu);
        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.action_share).getActionProvider();
        Poems.updateShareIntent(mShareActionProvider, this, mPoemId);
    }//  w  w w  . j a va2s .  co  m
    return true;
}