Example usage for android.view MenuItem setVisible

List of usage examples for android.view MenuItem setVisible

Introduction

In this page you can find the example usage for android.view MenuItem setVisible.

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:com.cypress.cysmart.BLEServiceFragments.HealthTemperatureService.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();/*  w w  w  .java 2 s. c  om*/
    inflater.inflate(R.menu.global, menu);
    ActionBar actionBar = getActivity().getActionBar();
    if (actionBar != null) {
        actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    }
    MenuItem graph = menu.findItem(R.id.graph);
    MenuItem log = menu.findItem(R.id.log);
    MenuItem search = menu.findItem(R.id.search);
    search.setVisible(false);
    graph.setVisible(true);
    log.setVisible(true);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.btmura.android.reddit.app.CommentListController.java

private void prepareShareActionItem(Menu menu, ListView lv, int pos) {
    MenuItem item = menu.findItem(R.id.menu_share_comment);
    item.setVisible(isCheckedCount(lv, 1) && hasThingId(pos));
}

From source file:com.zzolta.android.gfrecipes.fragments.RecipeDetailFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    final String recipeId = RecipeDetailHelper.getInstance().getCurrentRecipeId();
    if (recipeId != null) {
        try {/* w  ww  . j  a  v a 2 s  .  c om*/
            final Dao<Recipe, String> recipeDao = RecipeDBHelper
                    .getInstance(getActivity().getApplicationContext()).getDao();
            final Recipe recipe = recipeDao.queryForId(recipeId);
            final MenuItem addToMyRecipes = menu.findItem(R.id.action_add_to_my_recipes);
            final MenuItem removeFromMyRecipes = menu.findItem(R.id.action_remove_from_my_recipes);
            if (recipe.getMyRecipe()) {
                addToMyRecipes.setVisible(false);
                removeFromMyRecipes.setVisible(true);
            } else {
                addToMyRecipes.setVisible(true);
                removeFromMyRecipes.setVisible(false);
            }
        } catch (final SQLException e) {
            Log.e(LOG_TAG, e.getMessage());
        }
    }
}

From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    Log.v(TAG, "onCreateOptionsMenu: mMeeting =" + mMeeting);

    inflater.inflate(R.menu.meeting_menu, menu);
    // Only share and show charts for finished meetings
    final MenuItem shareItem = menu.findItem(R.id.action_share_meeting);
    if (shareItem != null)
        shareItem.setVisible(mMeeting != null && mMeeting.getState() == State.FINISHED);
    final MenuItem chartItem = menu.findItem(R.id.action_charts_meeting);
    if (chartItem != null)
        chartItem.setVisible(mMeeting != null && mMeeting.getState() == State.FINISHED);
    // Delete a meeting in any state.
    final MenuItem deleteItem = menu.findItem(R.id.action_delete_meeting);
    if (deleteItem != null)
        deleteItem.setVisible(mMeeting != null);
}

From source file:com.dabay6.android.apps.carlog.ui.vehicle.VehicleHomeActivity.java

/**
 * {@inheritDoc}//from   w  ww  . j  a va2  s. c  o  m
 */
@Override
protected void onHideOptionsMenuItems(final Menu menu, final boolean isDrawerOpen) {
    MenuItem item;

    item = menu.findItem(id.menu_vehicle_add);
    if (item != null) {
        item.setVisible(!isDrawerOpen);
    }

    item = menu.findItem(id.menu_vehicle_edit);
    if (item != null) {
        item.setVisible(!isDrawerOpen);
    }
}

From source file:com.doomy.decode.ScanActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    MenuItem mItemClear = menu.findItem(R.id.action_clear);

    if (mList.size() == 0) {
        mItemClear.setVisible(false);
    } else {//from  www .  j  ava2 s  .c o m
        mItemClear.setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:org.creativecommons.thelist.activities.CategoryListActivity.java

private void updateList() {
    Log.v(TAG, "> updateList");
    //mProgressBar.setVisibility(View.INVISIBLE);
    if (mCategoryData == null) {
        mMessageHelper.showDialog(mContext, getString(R.string.error_title), getString(R.string.error_message));
    } else {/*from  w w  w  .  j  av a2s . co  m*/
        try {
            for (int i = 0; i < mCategoryData.length(); i++) {
                JSONObject jsonSingleCategory = mCategoryData.getJSONObject(i);
                CategoryListItem categoryListItem = new CategoryListItem();
                categoryListItem.setCategoryName(jsonSingleCategory.getString(ApiConstants.CATEGORY_NAME));
                categoryListItem.setCategoryID(jsonSingleCategory.getInt(ApiConstants.CATEGORY_ID));
                categoryListItem
                        .setCategoryColour("#" + jsonSingleCategory.getString(ApiConstants.CATEGORY_COLOUR));

                //Add to array list to be adapted
                mCategoryList.add(categoryListItem);
            }
        } catch (JSONException e) {
            Log.e(TAG, "Exception Caught: ", e);
        }
        mGridView.setAdapter(adapter);
        mGridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

        //if category has been previously selected by user, set item in gridview as checked
        if (mUserCategories != null && mUserCategories.size() > 0) {
            for (int i = 0; i < mCategoryList.size(); i++) {
                CategoryListItem checkItem = mCategoryList.get(i);
                if (mUserCategories.contains(checkItem.getCategoryID())) {
                    mGridView.setItemChecked(i, true);
                    checkItem.setCategoryChecked(true);
                }
            }
            MenuItem doneButton = menu.findItem(R.id.action_done);
            doneButton.setVisible(true);
        }

        adapter.notifyDataSetChanged();
    }
}

From source file:com.jecelyin.android.file_explorer.FileListPagerFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.paste_menu) {
        ((FileExplorerActivity) getActivity()).getFileClipboard().paste(getCurrentDirectory());
        item.setVisible(false);
        onRefresh();/*w  w w.j  ava  2 s.  co m*/
    } else if (item.getItemId() == R.id.add_folder_menu) {
        action.doCreateFolder();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.murati.oszk.audiobook.ui.MusicPlayerActivity.java

public void updateBookButtons(String mediaId) {
    if (mMenu == null)
        return;/*w  ww.j av a  2  s.c  o m*/

    boolean isValidBook = (mediaId != null && mediaId.startsWith(MediaIDHelper.MEDIA_ID_BY_EBOOK + "/"));

    // Set Favorite Menu visibility
    MenuItem mFavorite = null;
    try {
        mFavorite = mMenu.findItem(R.id.option_favorite);
        mFavorite.setVisible(isValidBook);

        // Set Favorite icon
        if (isValidBook && FavoritesHelper.isFavorite(mediaId))
            mFavorite.setIcon(R.drawable.ic_star_on);
        else
            mFavorite.setIcon(R.drawable.ic_star_off);

    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }

    // Set Download/Delete menu visibility based on offline status
    boolean isOfflineBook = false;
    if (isValidBook) {
        try {
            isOfflineBook = OfflineBookService.isOfflineBook(mediaId);
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }
    }

    MenuItem mDownload = null;
    MenuItem mDelete = null;
    try {
        mDownload = mMenu.findItem(R.id.option_download);
        mDownload.setVisible(isValidBook && !isOfflineBook);

        mDelete = mMenu.findItem(R.id.option_delete);
        mDelete.setVisible(isValidBook && isOfflineBook);
    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }
}

From source file:com.agateau.equiv.ui.MealItemDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.meal_item_detail_activity_actions, menu);
    if (mMealItemPosition == NEW_MEAL_ITEM_POSITION) {
        MenuItem removeMenuItem = menu.findItem(R.id.action_remove);
        removeMenuItem.setVisible(false);
    }// www .jav a  2  s. c  o  m
    mSaveMenuItem = menu.findItem(R.id.action_save);

    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mFullListAdapter.getFilter().filter(newText);
            mFavoritesListAdapter.getFilter().filter(newText);
            return false;
        }
    });

    updateMenuItems();
    return super.onCreateOptionsMenu(menu);
}