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.irateam.vkplayer.activities.ListActivity.java

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

    toolbarMenu = menu;/* ww  w. j a  v  a 2s  .c o m*/

    MenuItem itemSort = menu.findItem(R.id.action_sort);
    MenuItem itemSortDone = menu.findItem(R.id.action_sort_done);
    MenuItem itemSearch = menu.findItem(R.id.action_search);

    audioAdapter.setSortModeListener(new AudioAdapter.SortModeListener() {
        @Override
        public void onStartSortMode() {
            itemSort.setVisible(false);
            itemSortDone.setVisible(true);
            listView.setDragEnabled(true);
            refreshLayout.setEnabled(false);
        }

        @Override
        public void onFinishSortMode() {
            itemSort.setVisible(true);
            itemSortDone.setVisible(false);
            listView.setDragEnabled(false);
            refreshLayout.setEnabled(true);
        }
    });

    searchView = (SearchView) itemSearch.getActionView();
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            audioAdapter.getFilter().filter(newText);
            return true;
        }
    });
    return true;
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mHistoryManager.hasHistoryItems()) {
        getMenuInflater().inflate(R.menu.history_menu, menu);

        SearchView searchView = (SearchView) menu.findItem(R.id.history_menu_search).getActionView();
        searchView.setOnQueryTextListener(queryListener);

        MenuItem copyItem = menu.findItem(R.id.history_menu_copy_code_row);
        MenuItem sendItem = menu.findItem(R.id.history_menu_send_code_row);

        if (twoPane && this.historyFragment.getActivatedPosition() != ListView.INVALID_POSITION) {
            copyItem.setVisible(true);

            sendItem.setVisible(true);//  w  w  w .  j  a v a  2s. c  om
        } else {
            copyItem.setVisible(false);
            sendItem.setVisible(false);
        }

        MenuItem item = menu.findItem(R.id.history_menu_send_dta);

        if (dtaFileCreator.getFirstErrorId() != 0) {
            item.setVisible(false);
        }

        return true;
    }
    return false;
}

From source file:com.keepassdroid.EntryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.entry, menu);

    MenuItem togglePassword = menu.findItem(R.id.menu_toggle_pass);
    if (mShowPassword) {
        togglePassword.setTitle(R.string.menu_hide_password);
    } else {//from  ww  w .  ja v  a 2  s  .  co m
        togglePassword.setTitle(R.string.menu_showpass);
    }

    MenuItem gotoUrl = menu.findItem(R.id.menu_goto_url);
    MenuItem copyUser = menu.findItem(R.id.menu_copy_user);
    MenuItem copyPass = menu.findItem(R.id.menu_copy_pass);

    // In API >= 11 onCreateOptionsMenu may be called before onCreate completes
    // so mEntry may not be set
    if (mEntry == null) {
        gotoUrl.setVisible(false);
        copyUser.setVisible(false);
        copyPass.setVisible(false);
    } else {
        String url = mEntry.getUrl();
        if (EmptyUtils.isNullOrEmpty(url)) {
            // disable button if url is not available
            gotoUrl.setVisible(false);
        }
        if (mEntry.getUsername().length() == 0) {
            // disable button if username is not available
            copyUser.setVisible(false);
        }
        if (mEntry.getPassword().length() == 0) {
            // disable button if password is not available
            copyPass.setVisible(false);
        }
    }

    return true;
}

From source file:com.example.android.touroflondon.MainActivity.java

/**
 * Called when an option item is selected.
 *
 * @param item//from   w ww.  jav a2s  . c  o  m
 * @return
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_poi: {
        // Show the POI fragment

        // Initialise if required
        if (mPoiListFragment == null) {
            mPoiListFragment = new PoiListFragment();
        }

        // Display the fragment
        getFragmentManager().beginTransaction().replace(R.id.fragment_container, mPoiListFragment)
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).addToBackStack(null).commit();

        // Hide the POI action item
        item.setVisible(false);

        // Enable up navigation from POI fragment
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setTitle(R.string.menu_poi_home_action);

        return true;
    }
    case android.R.id.home: {
        // Home action item, close POI fragment
        closePoiFragment();
        return true;
    }
    case R.id.menu_about:
        // Display about dialog
        new AboutDialog().show(getFragmentManager(), null);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.embeddedlog.LightUpDroid.DeskClock.java

private void updateMenu(Menu menu) {
    // Hide "help" if we don't have a URI for it.
    MenuItem help = menu.findItem(R.id.menu_item_help);
    if (help != null) {
        Utils.prepareHelpMenuItem(this, help);
    }// ww  w .j a v a 2 s .com

    // Hide "lights out" if not in Clock tab.
    MenuItem nightMode = menu.findItem(R.id.menu_item_night_mode);
    if (mActionBar.getSelectedNavigationIndex() == CLOCK_TAB_INDEX) {
        nightMode.setVisible(true);
    } else {
        nightMode.setVisible(false);
    }

    // Hide "reset alarm" and "sync/push with LightUpPi" if not in alarm tab
    MenuItem syncLightuppi = menu.findItem(R.id.menu_item_sync_lightuppi);
    MenuItem resetAlarms = menu.findItem(R.id.menu_item_reset_db);
    MenuItem pushPiAlarms = menu.findItem(R.id.menu_item_push_to_lightuppi);
    MenuItem pushPhoneAlarms = menu.findItem(R.id.menu_item_push_to_phone);
    if (mActionBar.getSelectedNavigationIndex() == ALARM_TAB_INDEX) {
        syncLightuppi.setVisible(true);
        resetAlarms.setVisible(true);
        pushPiAlarms.setVisible(true);
        pushPhoneAlarms.setVisible(true);
    } else {
        syncLightuppi.setVisible(false);
        resetAlarms.setVisible(false);
        pushPiAlarms.setVisible(false);
        pushPhoneAlarms.setVisible(false);
    }
}

From source file:net.mceoin.cominghome.MainActivity.java

public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem fake_arrived = menu.findItem(R.id.fake_arrived);
    fake_arrived.setVisible(debug);
    MenuItem fake_left = menu.findItem(R.id.fake_left);
    fake_left.setVisible(debug);/* w ww  . j a v  a2s.c  o m*/
    MenuItem fake_left_work = menu.findItem(R.id.fake_left_work);
    fake_left_work.setVisible(debug);
    MenuItem stop_tracking = menu.findItem(R.id.stop_tracking);
    stop_tracking.setVisible(false);

    MenuItem select_structures = menu.findItem(R.id.select_structure);
    int structures = StructuresUpdate.countStructureIds(getApplicationContext());
    if (structures > 1) {
        select_structures.setVisible(true);
    } else {
        select_structures.setVisible(false);
    }
    return true;
}

From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // Make sure the 'Import photos' MenuItem is set up properly based on the number of
    // activities that handle ACTION_GET_CONTENT
    // 0 = hide the MenuItem
    // 1 = show 'Import photos from APP_NAME' to go to the one app that exists
    // 2 = show 'Import photos...' to have the user pick which app to import photos from
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    List<ResolveInfo> getContentActivities = getPackageManager().queryIntentActivities(intent, 0);
    mGetContentActivites.clear();//from w  ww.jav a 2  s  .  c  o  m
    for (ResolveInfo info : getContentActivities) {
        // Filter out the default system UI
        if (!TextUtils.equals(info.activityInfo.packageName, "com.android.documentsui")) {
            mGetContentActivites.add(info.activityInfo);
        }
    }

    // Hide the 'Import photos' action if there are no activities found
    MenuItem importPhotosMenuItem = menu.findItem(R.id.action_import_photos);
    importPhotosMenuItem.setVisible(!mGetContentActivites.isEmpty());
    // If there's only one app that supports ACTION_GET_CONTENT, tell the user what that app is
    if (mGetContentActivites.size() == 1) {
        importPhotosMenuItem.setTitle(getString(R.string.gallery_action_import_photos_from,
                mGetContentActivites.get(0).loadLabel(getPackageManager())));
    } else {
        importPhotosMenuItem.setTitle(R.string.gallery_action_import_photos);
    }
    return true;
}

From source file:com.numberx.kkmctimer.DeskClock.java

private void updateMenu(Menu menu) {
    // Hide "help" if we don't have a URI for it.
    MenuItem help = menu.findItem(R.id.menu_item_help);
    if (help != null) {
        Utils.prepareHelpMenuItem(this, help);
    }/* www . java2  s  .  c  o m*/

    // Hide "lights out" if not in Clock tab.
    MenuItem nightMode = menu.findItem(R.id.menu_item_night_mode);
    if (mActionBar.getSelectedNavigationIndex() == CLOCK_TAB_INDEX) {
        nightMode.setVisible(true);
    } else {
        nightMode.setVisible(false);
    }

    // Hide "reset alarm" and "sync/push with KKMCTimer" if not in alarm tab
    MenuItem syncLightuppi = menu.findItem(R.id.menu_item_sync_kkmctimer);
    MenuItem resetAlarms = menu.findItem(R.id.menu_item_reset_db);
    MenuItem pushPiAlarms = menu.findItem(R.id.menu_item_push_to_kkmctimer);
    MenuItem pushPhoneAlarms = menu.findItem(R.id.menu_item_push_to_phone);
    if (mActionBar.getSelectedNavigationIndex() == ALARM_TAB_INDEX) {
        syncLightuppi.setVisible(true);
        resetAlarms.setVisible(true);
        pushPiAlarms.setVisible(true);
        pushPhoneAlarms.setVisible(true);
    } else {
        syncLightuppi.setVisible(false);
        resetAlarms.setVisible(false);
        pushPiAlarms.setVisible(false);
        pushPhoneAlarms.setVisible(false);
    }
}

From source file:com.android.messaging.ui.conversationlist.ConversationListFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final MenuItem startNewConversationMenuItem = menu.findItem(R.id.action_start_new_conversation);
    if (startNewConversationMenuItem != null) {
        // It is recommended for the Floating Action button functionality to be duplicated as a
        // menu/*from   ww  w .  ja  va2s  .  c o  m*/
        AccessibilityManager accessibilityManager = (AccessibilityManager) getActivity()
                .getSystemService(Context.ACCESSIBILITY_SERVICE);
        startNewConversationMenuItem.setVisible(accessibilityManager.isTouchExplorationEnabled());
    }

    final MenuItem archive = menu.findItem(R.id.action_show_archived);
    if (archive != null) {
        archive.setVisible(true);
    }
}

From source file:cgeo.geocaching.cgeocaches.java

private static void setVisible(final Menu menu, final int itemId, final boolean visible) {
    final MenuItem item = menu.findItem(itemId);
    if (item != null) {
        item.setVisible(visible);/* www  . ja  v  a2s.c o  m*/
    }
}