Example usage for android.view ContextMenu findItem

List of usage examples for android.view ContextMenu findItem

Introduction

In this page you can find the example usage for android.view ContextMenu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.FavouriteStopsFragment.java

/**
 * {@inheritDoc}//from  w  ww  .  j a  v  a 2 s  .  com
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    // Get the menu inflater.
    final MenuInflater inflater = getActivity().getMenuInflater();
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor c = (Cursor) ca.getItem(info.position);
    final String selectedStopCode;

    // Get the stopCode.
    if (c != null) {
        selectedStopCode = String.valueOf(c.getString(0));
    } else {
        selectedStopCode = "";
    }

    // Set the header title of the context menu.
    menu.setHeaderTitle(getString(R.string.busstop, sd.getNameForStop(selectedStopCode), selectedStopCode));
    // Inflate the menu from XML.
    inflater.inflate(R.menu.favouritestops_context_menu, menu);

    // Set the title of the proximity alert item depending whether one is
    // set or not.
    MenuItem item = menu.findItem(R.id.favouritestops_context_menu_prox_alert);

    if (sd.isActiveProximityAlert(selectedStopCode)) {
        item.setTitle(R.string.favouritestops_menu_prox_rem);
    } else {
        item.setTitle(R.string.favouritestops_menu_prox_add);
    }

    // Set the title of the time alert item depending whether one is set or
    // not.
    item = menu.findItem(R.id.favouritestops_context_menu_time_alert);

    if (sd.isActiveTimeAlert(selectedStopCode)) {
        item.setTitle(R.string.favouritestops_menu_time_rem);
    } else {
        item.setTitle(R.string.favouritestops_menu_time_add);
    }

    // If the Google Play Services is not available, then don't show the
    // option to show the stop on the map.
    item = menu.findItem(R.id.favouritestops_context_menu_showonmap);

    if (!GenericUtils.isGoogleMapsAvailable(getActivity())) {
        item.setVisible(false);
    }
}

From source file:org.gateshipone.malp.application.activities.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (v.getId() == R.id.main_listview && mNowPlayingDragStatus == DRAG_STATUS.DRAGGED_UP) {
        int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.context_menu_current_playlist_track, menu);

        // Check if the menu is created for the currently playing song. If this is the case, do not show play as next item.
        MPDCurrentStatus status = MPDStateMonitoringHandler.getLastStatus();
        if (status != null && position == status.getCurrentSongIndex()) {
            menu.findItem(R.id.action_song_play_next).setVisible(false);
        }/*  w  ww. ja v  a  2  s .  c  o  m*/

        CurrentPlaylistView currentPlaylistView = (CurrentPlaylistView) findViewById(R.id.now_playing_playlist);
        if (currentPlaylistView
                .getItemViewType(position) == CurrentPlaylistAdapter.VIEW_TYPES.TYPE_SECTION_TRACK_ITEM) {
            menu.findItem(R.id.action_remove_album).setVisible(true);
        }
    }
}

From source file:il.ac.shenkar.todos.view.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
    menu.setHeaderTitle("Task Menu");

    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    // stores current item position
    int position = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    // current task description
    String taskDescription = taskListModel.getTaskAt(position).getTaskDescription();
    // is task marked as important
    boolean isImportant = taskListModel.getTaskAt(position).isImportant();

    if (Utils.ENGLISH_LANGUAGE == false) {
        // make hebrew menu
        menu.setHeaderTitle(" ");
        Utils.makeHebrewContextMenu(menu);

        if (taskDescription.equals(Utils.DEFAULT_DESCRIPTION)) {
            MenuItem item = menu.findItem(R.id.editDescription);
            item.setTitle(" ");
        }//ww  w . j  ava2s .c o  m
        if (isImportant) {
            MenuItem item = menu.findItem(R.id.markImportant);
            item.setTitle(" - ");
        }
    } else {
        // checks if description is empty
        if (taskDescription.equals(Utils.DEFAULT_DESCRIPTION)) {
            MenuItem item = menu.findItem(R.id.editDescription);
            item.setTitle("Add Task Description");
        }

        if (isImportant) {
            MenuItem item = menu.findItem(R.id.markImportant);
            item.setTitle("Mark As Unimportant");
        }
    }
}

From source file:net.sourceforge.servestream.fragment.AlarmClockFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    // Inflate the menu from xml.
    getActivity().getMenuInflater().inflate(R.menu.alarm_clock_context_menu, menu);

    // Use the current item to create a custom view for the header.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem((int) info.position);
    final Alarm alarm = new Alarm(c);

    // Construct the Calendar to compute the time.
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, alarm.hour);
    cal.set(Calendar.MINUTE, alarm.minutes);
    final String time = Alarms.formatTime(getActivity(), cal);

    // Inflate the custom view and set each TextView's text.
    final View v = mFactory.inflate(R.layout.context_menu_header, new LinearLayout(getActivity()), false);
    TextView textView = (TextView) v.findViewById(R.id.header_time);
    textView.setText(time);/* w w w  .ja  v  a2 s .c o  m*/
    textView = (TextView) v.findViewById(R.id.header_label);
    textView.setText(alarm.label);

    // Set the custom view on the menu.
    menu.setHeaderView(v);
    // Change the text based on the state of the alarm.
    if (alarm.enabled) {
        menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm);
    }
}

From source file:vn.cybersoft.obs.android.activities.TimeScheduleActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    // Inflate the menu from xml.
    getMenuInflater().inflate(R.menu.time_schedule_context_menu, menu);

    // Use the current item to create a custom view for the header.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor c = (Cursor) mScheduleList.getAdapter().getItem((int) info.position);
    final TimeSchedule schedule = new TimeSchedule(c);

    // Construct the Calendar to compute the time.
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, schedule.hour);
    cal.set(Calendar.MINUTE, schedule.minutes);
    final String time = TimeSchedule.formatTime(this, cal);

    // Inflate the custom view and set each TextView's text.
    final View v = mInflater.inflate(R.layout.context_menu_header, null);
    TextView textView = (TextView) v.findViewById(R.id.header_time);
    textView.setText(time);//from  w  ww  .  ja v a 2s.  c  o  m
    textView = (TextView) v.findViewById(R.id.header_mode);

    textView.setText(Utils.getString(this, OptimalMode.getMode(getContentResolver(), schedule.modeId).name,
            R.string.class));

    // Set the custom view on the menu.
    menu.setHeaderView(v);
    // Change the text based on the state of the schedule.
    if (schedule.enabled) {
        menu.findItem(R.id.enable_schedule).setTitle(R.string.disable_schedule);
    }
}

From source file:org.catrobat.catroid.ui.fragment.SoundFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);

    if (SoundController.getInstance().isSoundPlaying(mediaPlayer)) {
        SoundController.getInstance().stopSoundAndUpdateList(mediaPlayer, soundInfoList, adapter);
    }/*from   w ww.  ja  va 2  s.  c om*/
    selectedSoundInfo = adapter.getItem(selectedSoundPosition);
    menu.setHeaderTitle(selectedSoundInfo.getTitle());
    adapter.addCheckedItem(((AdapterContextMenuInfo) menuInfo).position);

    getSherlockActivity().getMenuInflater().inflate(R.menu.context_menu_default, menu);
    menu.findItem(R.id.context_menu_copy).setVisible(true);
    menu.findItem(R.id.context_menu_unpacking).setVisible(false);
    menu.findItem(R.id.context_menu_move_up).setVisible(true);
    menu.findItem(R.id.context_menu_move_down).setVisible(true);
    menu.findItem(R.id.context_menu_move_to_top).setVisible(true);
    menu.findItem(R.id.context_menu_move_to_bottom).setVisible(true);

    menu.findItem(R.id.context_menu_move_down).setEnabled(selectedSoundPosition != soundInfoList.size() - 1);
    menu.findItem(R.id.context_menu_move_to_bottom)
            .setEnabled(selectedSoundPosition != soundInfoList.size() - 1);

    menu.findItem(R.id.context_menu_move_up).setEnabled(selectedSoundPosition != 0);
    menu.findItem(R.id.context_menu_move_to_top).setEnabled(selectedSoundPosition != 0);
}

From source file:de.enlightened.peris.PostsFragment.java

public final void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    //Block profile viewing on restricted accounts
    final SharedPreferences appPreferences = this.activity.getSharedPreferences("prefs", 0);
    final boolean accountRestricted = appPreferences.getBoolean(this.storagePrefix + "logged_banned", false);
    if (accountRestricted) {
        return;//from   ww w  .  ja va  2s.c om
    }

    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    this.selectedPost = (Post) this.mainList.getItemAtPosition(info.position);

    super.onCreateContextMenu(menu, v, menuInfo);
    final MenuInflater inflater = this.activity.getMenuInflater();
    inflater.inflate(R.menu.posts_context, menu);

    if (this.userid != null) {
        final MenuItem item3 = menu.findItem(R.id.posts_quote);
        item3.setVisible(true);

        final MenuItem item5 = menu.findItem(R.id.posts_message);
        item5.setVisible(true);
    }

    if (this.selectedPost.authorId != null) {
        if (this.selectedPost.authorId.equals(this.userid)) {
            final MenuItem item5 = menu.findItem(R.id.posts_message);
            item5.setVisible(false);
        }
    }

    final MenuItem itemBan = menu.findItem(R.id.posts_context_ban);
    final MenuItem itemDelete = menu.findItem(R.id.posts_context_delete);
    final MenuItem itemEdit = menu.findItem(R.id.posts_edit);
    final MenuItem itemThank = menu.findItem(R.id.posts_thank);
    final MenuItem itemLike = menu.findItem(R.id.posts_like);

    if (this.selectedPost.canThank) {
        itemThank.setVisible(true);
    } else {
        itemThank.setVisible(false);
    }

    if (this.selectedPost.canLike) {
        itemLike.setVisible(true);
    } else {
        itemLike.setVisible(false);
    }

    if (this.selectedPost.canBan && !this.selectedPost.userBanned) {
        itemBan.setVisible(true);
    } else {
        itemBan.setVisible(false);
    }

    if (this.selectedPost.canDelete) {
        itemDelete.setVisible(true);
    } else {
        itemDelete.setVisible(false);
    }

    if (this.selectedPost.canEdit) {
        itemEdit.setVisible(true);
    } else {
        itemEdit.setVisible(false);
    }
}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    if (view == playlistView) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
        boolean offline = Util.isOffline(this);
        //  playlistView.setVisibility((downloadFile.getSong().getType().equals("ad"))?View.INVISIBLE:View.VISIBLE);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.nowplaying_context, menu);

        menu.findItem(R.id.menu_pin).setVisible(!offline && !downloadFile.isSaved());
        menu.findItem(R.id.menu_unpin).setVisible(!offline && downloadFile.isSaved());
        // menu.findItem(R.id.download_menu_star).setVisible(!offline && !downloadFile.getSong().isStarred());
        // menu.findItem(R.id.download_menu_unstar).setVisible(!offline && downloadFile.getSong().isStarred());
        // menu.findItem(R.id.download_menu_share).setVisible(!offline);
        menu.findItem(R.id.download_menu_remove).setVisible(true);
        // menu.findItem(R.id.download_menu_show_album).setVisible(downloadFile.getSong().getParent() != null);
        // menu.findItem(R.id.download_menu_lyrics).setVisible(!Util.isOffline(this));
    }/*from ww  w . j  ava 2  s  . c  o  m*/
}

From source file:org.yammp.app.ArtistFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {

    ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) info;

    int itemtype = ExpandableListView.getPackedPositionType(mi.packedPosition);
    mSelectedGroupPosition = ExpandableListView.getPackedPositionGroup(mi.packedPosition);
    int gpos = mSelectedGroupPosition;
    mSelectedGroupId = mGroupCursor.getLong(mGroupArtistIdIdx);
    if (itemtype == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        mGroupSelected = true;/*from ww w  .  j ava 2  s. com*/
        mChildSelected = false;
        getSherlockActivity().getMenuInflater().inflate(R.menu.music_browser_item, menu);
        if (gpos == -1) {
            // this shouldn't happen
            Log.d("Artist/Album", "no group");
            return;
        }
        gpos = gpos - mListView.getHeaderViewsCount();
        mGroupCursor.moveToPosition(gpos);
        mCurrentGroupArtistName = mGroupCursor.getString(mGroupArtistIdx);
        if (mCurrentGroupArtistName == null || MediaStore.UNKNOWN_STRING.equals(mCurrentGroupArtistName)) {
            menu.setHeaderTitle(getString(R.string.unknown_artist));
            menu.findItem(R.id.search).setEnabled(false);
            menu.findItem(R.id.search).setVisible(false);
        } else {
            menu.setHeaderTitle(mCurrentGroupArtistName);
        }
    }
}

From source file:de.enlightened.peris.CategoriesFragment.java

public final void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    final String serverUserId = this.application.getSession().getServer().serverUserId;
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    this.clickedTopicItem = (TopicItem) CategoriesFragment.this.getListView().getItemAtPosition(info.position);

    if (serverUserId == null) {
        return;/*w w w .j a va2  s  .  c om*/
    }
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(this.clickedTopicItem.getHeading());
    final MenuInflater inflater = this.activity.getMenuInflater();

    inflater.inflate(R.menu.categories_context, menu);

    final MenuItem ubsubItem = menu.findItem(R.id.categories_unsubscribe);
    final MenuItem subItem = menu.findItem(R.id.categories_subscribe);
    final MenuItem stickyItem = menu.findItem(R.id.categories_context_sticky);
    final MenuItem lockItem = menu.findItem(R.id.categories_context_lock);
    final MenuItem deleteItem = menu.findItem(R.id.categories_context_delete);

    final MenuItem subscribeItem = menu.findItem(R.id.categories_add_favorite);
    final MenuItem unsubscribeItem = menu.findItem(R.id.categories_remove_favorite);

    if (this.clickedTopicItem instanceof Category) {
        final Category category = (Category) this.clickedTopicItem;
        ubsubItem.setVisible(false);
        subItem.setVisible(false);
        stickyItem.setVisible(false);
        lockItem.setVisible(false);
        deleteItem.setVisible(false);

        if (category.isCanSubscribe()) {
            subscribeItem.setVisible(true);
        } else {
            subscribeItem.setVisible(false);
        }

        if (category.isSubscribed()) {
            unsubscribeItem.setVisible(true);
            subscribeItem.setVisible(false);
        } else {
            unsubscribeItem.setVisible(false);
        }
    } else {
        final Topic topic = (Topic) this.clickedTopicItem;

        unsubscribeItem.setVisible(false);
        subscribeItem.setVisible(false);

        if (topic.isCanStick()) {
            stickyItem.setVisible(true);

            if (Topic.Type.Sticky == topic.getType()) {
                stickyItem.setTitle("Unstick Topic");
            } else {
                stickyItem.setTitle("Stick Topic");
            }
        } else {
            stickyItem.setVisible(false);
        }

        if (topic.isCanDelete()) {
            deleteItem.setVisible(true);
        } else {
            deleteItem.setVisible(false);
        }

        if (topic.isCanClose()) {
            lockItem.setVisible(true);

            if (topic.isClosed()) {
                lockItem.setTitle("Unlock Topic");
            } else {
                lockItem.setTitle("Lock Topic");
            }
        } else {
            lockItem.setVisible(false);
        }

        if (this.subforumId.contentEquals("favs")) {
            ubsubItem.setVisible(true);
            subItem.setVisible(false);
        } else {
            ubsubItem.setVisible(false);
            subItem.setVisible(true);
        }
    }
}