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:org.addhen.smssync.presentation.view.ui.activity.MainActivity.java

private void setupDrawerContent() {
    PrefsFactory prefs = getAppComponent().prefsFactory();
    MenuItem phoneName = mNavigationView.getMenu().findItem(R.id.nav_device_name);
    if (phoneName != null && !TextUtils.isEmpty(prefs.uniqueName().get())) {
        phoneName.setVisible(true);
        phoneName.setTitle(//  w  w  w  . j a  va2 s.  c o  m
                Utility.capitalizeFirstLetter(prefs.uniqueName().get()) + " - " + prefs.uniqueId().get());
    }
    mNavigationView.setNavigationItemSelectedListener(menuItem -> {
        setupFragment(menuItem);
        mDrawerLayout.closeDrawers();
        return true;
    });
}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

private void setupAddComment(Menu menu) {
    MenuItem newCommentMenuItem = menu.findItem(R.id.menu_new_comment);
    newCommentMenuItem.setVisible(true);
    newCommentMenuItem.getActionView().setOnClickListener(new View.OnClickListener() {
        @Override//w w  w.j  a  va2s. com
        public void onClick(View v) {
            setupPostCommentFragment(null);
        }
    });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category_list);
    mContext = this;
    mMessageHelper = new MessageHelper(mContext);
    mRequestMethods = new RequestMethods(mContext);
    mSharedPref = new SharedPreferencesMethods(mContext);
    mCurrentUser = new ListUser(CategoryListActivity.this);

    //Google Analytics Tracker
    ((ListApplication) getApplication()).getTracker(ListApplication.TrackerName.GLOBAL_TRACKER);

    //Set List Adapter
    mGridView = (GridView) findViewById(R.id.categoryGrid);
    adapter = new CategoryListAdapter(this, mCategoryList);

    //Set up Helper Message if new user
    if (!mSharedPref.getCategoryHelperViewed()) {

        //UI Elements
        final View helperMessage = findViewById(R.id.category_helper_message);
        ImageButton helperCloseButton = (ImageButton) findViewById(R.id.helper_close_button);

        helperCloseButton.setOnClickListener(new View.OnClickListener() {
            @Override//  ww w . ja v a 2  s. c  o m
            public void onClick(View v) {
                helperMessage.setVisibility(View.GONE);
                mSharedPref.setCategoryHelperViewed(true);
            }
        });

        helperMessage.setVisibility(View.VISIBLE);
    }

    //Get Categories
    mRequestMethods.getCategories(new RequestMethods.ResponseCallback() {
        @Override
        public void onSuccess(JSONArray response) {
            Log.v(TAG, "> getCategories > onSuccess: " + response);
            mCategoryData = response;

            //Get users pre-selected categories
            if (!(mCurrentUser.isTempUser())) {
                //If user is logged in, request any pre-selected categories
                mRequestMethods.getUserCategories(new RequestMethods.ResponseCallback() {
                    @Override
                    public void onSuccess(JSONArray response) {
                        Log.v(TAG, "> getUserCategories > onSuccess " + response.toString());

                        //Create list of category ids
                        if (response.length() > 0) {
                            //Get array of catIds
                            for (int i = 0; i < response.length(); i++) {
                                try {
                                    JSONObject singleCat = response.getJSONObject(i);
                                    mUserCategories.add(i, singleCat.getInt("categoryid"));
                                    Log.v("USERCATS", "add: " + singleCat.getInt("categoryid"));
                                } catch (JSONException e) {
                                    Log.e(TAG, e.getMessage());
                                }
                            }
                            Log.v(TAG, "users category list: " + mUserCategories.toString());
                        }
                        updateList();
                    } //onSuccess

                    @Override
                    public void onFail(VolleyError error) {
                        Log.v(TAG, "> getUserCategories > onFail " + error.toString());
                        mMessageHelper.showDialog(mContext, getString(R.string.error_title),
                                getString(R.string.error_message));
                    }
                });
            } else {

                JSONArray tempUserCategories = mSharedPref.getCategorySharedPreference();

                if (tempUserCategories != null && tempUserCategories.length() > 0) {
                    //Convert to list + add to mUserCategories
                    for (int i = 0; i < tempUserCategories.length(); i++) {
                        try {
                            mUserCategories.add(i, tempUserCategories.getInt(i));
                            Log.v(TAG, " TEMPUSER CATEGORIES: " + mUserCategories.toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                updateList();
            }
        } //onSuccess

        @Override
        public void onFail(VolleyError error) {
            Log.d(TAG, "> getCategories > onFail: " + error.getMessage());
            mMessageHelper.showDialog(mContext, getString(R.string.error_title),
                    getString(R.string.error_message));
        }
    });

    //When Category is tapped
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //ImageView checkmarkView = (ImageView)view.findViewById(R.id.checkmark);
            CheckableRelativeLayout checkableLayout = (CheckableRelativeLayout) view
                    .findViewById(R.id.checkable_layout);
            ImageView checkIcon = (ImageView) view.findViewById(R.id.category_checkmark);
            TextView categoryNameLabel = (TextView) view.findViewById(R.id.category_title);

            //Get item clicked + its category id
            CategoryListItem item = (CategoryListItem) mGridView.getItemAtPosition(position);
            String catId = String.valueOf(item.getCategoryID());

            if (mGridView.isItemChecked(position)) {
                checkableLayout.getBackground().setAlpha(128);
                checkIcon.setVisibility(View.VISIBLE);
                categoryNameLabel.setTextColor(getResources().getColor(R.color.secondary_text_material_dark));
                item.setCategoryChecked(true);
                mRequestMethods.addCategory(catId);
                //Log.v(TAG, "ADDED " + catId);
            } else {
                checkableLayout.getBackground().setAlpha(255);
                checkIcon.setVisibility(View.GONE);
                categoryNameLabel
                        .setTextColor(getResources().getColor(R.color.primary_text_default_material_dark));
                item.setCategoryChecked(false);
                mRequestMethods.removeCategory(catId);
                //Log.v(TAG, "REMOVED " + catId);
            }
            //Count how many items are checked: if at least 3, show done button
            SparseBooleanArray positions = mGridView.getCheckedItemPositions();
            int length = positions.size();
            int ItemsChecked = 0;
            if (positions.size() > 0) {
                for (int i = 0; i < length; i++) {
                    if (positions.get(positions.keyAt(i))) {
                        ItemsChecked++;
                    }
                }
            }
            if (ItemsChecked >= 1) {
                MenuItem doneButton = menu.findItem(R.id.action_done);
                doneButton.setVisible(true);
            } else {
                MenuItem doneButton = menu.findItem(R.id.action_done);
                doneButton.setVisible(false);
            }
        }
    }); //setOnItemClickListener

}

From source file:com.mercandalli.android.apps.files.file.local.FileLocalPagerFragment.java

private boolean setMenuVisibility(@Nullable final MenuItem menuItem, final boolean visible) {
    if (menuItem == null) {
        return false;
    }// w  w w.  ja v a 2s  .  com
    menuItem.setVisible(visible);
    return true;
}

From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from ww w .  ja  va  2 s.  c o m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.contact_list_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (isSearchResultView) {
        searchItem.setVisible(false);
    }
    if (ApiHelper.hasHoneycomb()) {
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);
        final SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                if (searchString == null && newFilter == null) {
                    return true;
                }
                if (searchString != null && searchString.equals(newFilter)) {
                    return true;
                }
                searchString = newFilter;
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (ApiHelper.hasICS()) {
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    if (!TextUtils.isEmpty(searchString)) {
                        onSelectionCleared();
                    }
                    searchString = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (searchString != null) {
            final String savedSearchTerm = searchString;

            // Expands the search menu item
            if (ApiHelper.hasICS()) {
                searchItem.expandActionView();
            }
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.daskiworks.ghwatch.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    MenuItem mi = menu.findItem(R.id.action_notifCheck);
    if (mi != null) {
        mi.setVisible(GHConstants.DEBUG);
    }//from   w ww  .j  a  va 2s . c o m
    return super.onCreateOptionsMenu(menu);
}

From source file:com.murrayc.galaxyzoo.app.ZooFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);

    //Before the menu item is displayed,
    //show either "Log in" or "Log out":
    //This depends on cacheLoggedInStatus() having been called in onResume().
    final MenuItem itemLogin = menu.findItem(R.id.option_menu_item_login);
    final MenuItem itemLogout = menu.findItem(R.id.option_menu_item_logout);

    if ((itemLogin == null) || (itemLogout == null)) {
        Log.error("onPrepareOptionsMenu(): Could not find menu items.");
        return;// ww  w .  java2 s . c om
    }

    final boolean loggedIn = getCachedLoggedIn();
    itemLogin.setVisible(!loggedIn);
    itemLogout.setVisible(loggedIn);
}

From source file:it.gulch.linuxday.android.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Hide & disable primary (contextual) action items when the main menu is opened
    if (drawerLayout.isDrawerOpen(mainMenu)) {
        final int size = menu.size();
        for (int i = 0; i < size; ++i) {
            MenuItem item = menu.getItem(i);
            if ((item.getOrder() & 0xFFFF0000) == 0) {
                item.setVisible(false).setEnabled(false);
            }//from   ww w .  j av  a2 s.  co  m
        }
    }

    MenuItem refreshMenuItem = menu.findItem(R.id.refresh);

    boolean isRefreshing = refreshItem != null;
    Log.d(TAG, "isRefreshing: " + Boolean.toString(isRefreshing));
    refreshMenuItem.setEnabled(!isRefreshing);

    return super.onPrepareOptionsMenu(menu);
}

From source file:de.aw.monma.mainscreen.ActivityMainScreen.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;/*from   ww w .  ja va  2s  .  c  o  m*/
    boolean consumed;
    mDrawerLayout.closeDrawer(Gravity.START, false);
    switch (item.getItemId()) {
    case R.id.menu_item_hbci_ums_vorhanden:
        item.setVisible(false);
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.edit().putBoolean(getString(R.string.pref_OnlineUms), false).apply();
        intent = new Intent(this, ActivityHBCIActions.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowNeueOnlineUmsaetze);
        startActivity(intent);
        consumed = true;
        break;
    case R.id.menu_item_Ertraege:
        intent = new Intent(this, ActivityActions.class);
        intent.putExtra(ACTION, (Parcelable) Action.EditErtraege);
        startActivity(intent);
        consumed = true;
        break;
    case R.id.awlib_menu_item_hilfe:
        intent = new Intent(this, AWWebViewActivity.class);
        intent.putExtra(ID, "hilfe_finanzuebersicht.html");
        startActivity(intent);
        consumed = true;
        break;
    case R.id.menu_item_show_AllBuchungRegelm:
        intent = new Intent(this, ActivityCash.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowRegelmBuchungen);
        startActivity(intent);
        consumed = true;
        break;
    default:
        consumed = super.onOptionsItemSelected(item);
        break;
    }
    return consumed;
}

From source file:com.baruckis.nanodegree.spotifystreamer.fragments.PlayerDialogFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem nowPlayingActionButton = menu.findItem(R.id.now_playing);
    if (!mIsLargeLayout) {
        nowPlayingActionButton.setVisible(false);
    }/*from w w w  .  jav  a  2  s.  c  o m*/
}