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.adkdevelopment.earthquakesurvival.ui.DetailFragment.java

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

    MenuItem menuItem = menu.findItem(R.id.menu_item_share);
    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
    setShareIntent();//from   ww w  . j  a  va2s. c  om
}

From source file:co.malm.heusum.mobile.activities.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_home, menu);
    MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
    MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat
            .getActionProvider(mediaRouteMenuItem);
    mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
    return true;/*  w w w.j a  va 2 s.  c  om*/
}

From source file:ch.hesso.master.sweetcity.activity.map.MapActivity.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.map, menu);

    progressHelper = new ProgressMenuItemHelper(menu.findItem(R.id.action_refresh_report));
    reportList.load(this, new MapReportCallback(this));

    return true;//from  www . java 2s . co  m
}

From source file:at.flack.activity.NewSMSContactActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.new_contact, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);
    return true;// w  w  w  .ja va2  s . c o m
}

From source file:com.andrada.sitracker.ui.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView view = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView = view;// w w w.  j  av a  2 s.  com
        if (view == null) {
            LOGW(TAG, "Could not set up search view, view is null.");
        } else {
            view.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            view.setIconified(false);
            view.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    view.clearFocus();
                    if (mAuthorsFragment != null) {
                        mAuthorsFragment.requestQueryUpdate(s, mCurrentSearchType);
                    }
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    mQuery = s;
                    return true;
                }
            });
            view.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    finish();
                    return false;
                }
            });

            ShowcaseView.Builder bldr = new ShowcaseView.Builder(this).setTarget(new ViewTarget(mSearchView))
                    .setContentTitle(getString(R.string.showcase_search_title))
                    .setContentText(getString(R.string.showcase_search_detail))
                    .setStyle(R.style.ShowcaseView_Base);
            if (!BuildConfig.DEBUG) {
                bldr.singleShot(Constants.SHOWCASE_ADD_AUTHORS_SEARCH_SHOT_ID);
            }
            bldr.build();

            if (!TextUtils.isEmpty(mQuery)) {
                view.setQuery(mQuery, false);
            }
        }
    }
    return true;
}

From source file:net.bible.android.control.page.window.WindowControl.java

/**
 * Add the Window sub-menu resource which is not included in the main.xml for the main menu
 * Set the synchronised checkbox in the app menu before displayed
 * Disable various menu items if links window selected
 *///from www. j av  a2  s  .  c o  m
public void updateOptionsMenu(Menu menu) {
    // when updating main menu rather than Window options menu
    MenuItem windowSubmenuItemPosition = menu.findItem(R.id.windowSubMenu);
    if (windowSubmenuItemPosition != null) {
        // check the Window sub-menu has been added
        Menu subMenuToPopulate = windowSubmenuItemPosition.getSubMenu();
        if (subMenuToPopulate.findItem(R.id.windowNew) == null) {
            new MenuInflater(BibleApplication.getApplication()).inflate(R.menu.window_popup_menu,
                    subMenuToPopulate);
        }
    }

    MenuItem synchronisedMenuItem = menu.findItem(R.id.windowSynchronise);
    MenuItem moveFirstMenuItem = menu.findItem(R.id.windowMoveFirst);
    MenuItem closeMenuItem = menu.findItem(R.id.windowClose);
    MenuItem minimiseMenuItem = menu.findItem(R.id.windowMinimise);
    MenuItem maximiseMenuItem = menu.findItem(R.id.windowMaximise);
    Window window = getActiveWindow();

    if (synchronisedMenuItem != null && moveFirstMenuItem != null) {
        // set synchronised & maximised checkbox state
        synchronisedMenuItem.setChecked(window.isSynchronised());
        maximiseMenuItem.setChecked(window.isMaximised());

        // the dedicated links window cannot be treated as a normal window
        boolean isDedicatedLinksWindowActive = isActiveWindow(windowRepository.getDedicatedLinksWindow());
        synchronisedMenuItem.setEnabled(!isDedicatedLinksWindowActive);
        moveFirstMenuItem.setEnabled(!isDedicatedLinksWindowActive);

        // cannot close last normal window
        closeMenuItem.setEnabled(isWindowRemovable(window));
        minimiseMenuItem.setEnabled(isWindowMinimisable(window));

        // if window is already first then cannot promote
        List<Window> visibleWindows = windowRepository.getVisibleWindows();
        if (visibleWindows.size() > 0 && window.equals(visibleWindows.get(0))) {
            moveFirstMenuItem.setEnabled(false);
        }
    }
}

From source file:ca.mymenuapp.ui.activities.RestaurantActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_restaurant, menu);
    android.view.MenuItem item = menu.findItem(R.id.restaurant_share);
    shareActionProvider = (ShareActionProvider) item.getActionProvider();
    return true;//from  ww w  . ja v a  2  s .  co m
}

From source file:my.madet.uniteninfo.MainHome.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.krayzk9s.imgurholo.activities.ImgurHoloActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (getApiCall().settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT))
        inflater.inflate(R.menu.main, menu);
    else//w  w w .  j  a va 2  s.c  om
        inflater.inflate(R.menu.main_dark, menu);
    menu.findItem(R.id.action_settings).setVisible(true);
    return super.onCreateOptionsMenu(menu);
}

From source file:ar.com.lapotoca.resiliencia.gallery.ui.ImageDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.image_menu, menu);
    MenuItem shareItem = menu.findItem(R.id.menu_share);
    shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/*from  w  w w  .j  a  va 2 s .  c  o  m*/
        public boolean onMenuItemClick(MenuItem item) {
            try {

                ImageHolder img = Images.image[mPager.getCurrentItem()];
                if (img == null) {
                    return false;
                }

                AnalyticsHelper.getInstance().sendImageShareEvent(img.getUrl());

                Uri bmpUri;
                if (img.isLocal()) {
                    bmpUri = Uri.parse("content://" + AssetProvider.CONTENT_URI + "/" + img.getUrl());
                } else {
                    ImageView iv = (ImageView) findViewById(R.id.picImageView);
                    bmpUri = getLocalBitmapUri(iv);
                }
                if (bmpUri != null) {
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                    shareIntent.setType("image/*");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_item)));

                    AnalyticsHelper.getInstance().sendImageShareCompleted();
                    return true;
                } else {

                    AnalyticsHelper.getInstance().sendImageShareCanceled();
                    return false;
                }
            } catch (Exception e) {
                AnalyticsHelper.getInstance().sendImageShareFailed(e.getMessage());
                return false;
            }
        }
    });

    MenuItem downloadItem = menu.findItem(R.id.download_asset);
    downloadItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {

            Context context = ImageDetailActivity.this;

            String appDirectoryName = context.getString(R.string.app_name);
            File imageRoot = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                    appDirectoryName);

            ImageHolder img = Images.image[mPager.getCurrentItem()];
            if (img == null) {
                return false;
            }

            AssetManager assetManager = context.getAssets();
            try {
                InputStream is = assetManager.open(img.getUrl());
                String fileName = img.getUrl().split("/")[1];

                imageRoot.mkdirs();
                File image = new File(imageRoot, fileName);

                byte[] buffer = new byte[BUFFER_LENGHT];
                FileOutputStream fos = new FileOutputStream(image);
                int read = 0;

                while ((read = is.read(buffer, 0, 1024)) >= 0) {
                    fos.write(buffer, 0, read);
                }

                fos.flush();
                fos.close();
                is.close();

                String[] paths = { image.getAbsolutePath() };

                MediaScannerConnection.scanFile(context, paths, null, null);
                NotificationHelper.showNotification(context,
                        context.getString(R.string.download_image_succesfull));
                AnalyticsHelper.getInstance().sendDownloadImage(fileName);

            } catch (Exception e) {
                NotificationHelper.showNotification(context,
                        context.getString(R.string.download_no_permissions));
                AnalyticsHelper.getInstance().sendImageDownloadFailed(e.getMessage());
            }

            return true;
        }
    });

    return true;
}