Example usage for android.view ContextMenu getItem

List of usage examples for android.view ContextMenu getItem

Introduction

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

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

private void showDialogMenu(String title, CharSequence[] items, final ContextMenu menu) {
    if (items == null || items.length == 0) {
        return;/*from  w  w  w.j a  v a 2  s .com*/
    }

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            final ContextMenuItem menuItem = menu.getItem(item);
            if (menuItem.hasSubMenu()) {
                menuItem.onClickPerformed();
            } else {
                mDeferredAction = getDeferredAction(menuItem);
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(mService);
    builder.setTitle(title);
    builder.setItems(items, listener);
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mMenuShown--;
            if (mMenuShown == 0) {
                long delay = 0;
                if (mDeferredAction != null) {
                    mService.addEventListener(ListMenuManager.this);

                    if (needFocusDelay(mDeferredAction.actionId)) {
                        delay = RESET_FOCUS_DELAY;
                    }
                }

                mService.resetFocusedNode(delay);
                mCurrentDialog = null;
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        alert.getWindow().setType(WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY);
    } else {
        alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
    }

    alert.show();
    mCurrentDialog = alert;
    mMenuShown++;
}

From source file:at.ac.uniklu.mobile.sportal.CourseListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    int position = ((AdapterContextMenuInfo) menuInfo).position;
    getActivity().getMenuInflater().inflate(R.menu.course_context_menu, menu);

    Lehrveranstaltung course = mCourseModel.getCourse(position);
    menu.setHeaderTitle(course.getTyp() + " " + course.getName());
    menu.getItem(1).setVisible(course.getWebsiteUrl() != null);
    menu.getItem(2).setVisible(course.getMoodleUrl() != null);
    menu.getItem(3).setVisible(course.getStatus().equals("aufgenommen"));
    menu.getItem(4).setVisible(course.isKreuzellisten());
    if (mIndex > 0) {
        // hide the blacklist menu item for past semesters
        menu.getItem(5).setVisible(false);
    } else if (!mDB.courseBlacklist_isListed(course.getKey())) {
        menu.getItem(5).setChecked(true);
    }//w w  w  .java 2 s. c  om
    //http://stackoverflow.com/questions/5440601/android-how-to-enable-disable-option-menu-item-on-button-click

    Analytics.onEvent(Analytics.EVENT_CONTEXTMENU_COURSE);
}

From source file:com.workingagenda.democracydroid.Adapters.ViewHolders.EpisodeViewHolder.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    MenuInflater inflater = new MenuInflater(itemView.getContext());
    menu.setHeaderTitle("Democracy Now!");
    inflater.inflate(R.menu.context_menu, menu);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(itemView.getContext());
    int DEFAULT_STREAM = Integer.parseInt(preferences.getString("stream_preference", "0")); // 0=video
    int DEFAULT_OPEN = Integer.parseInt(preferences.getString("open_preference", "0")); // 0 = within this app

    if (DEFAULT_STREAM == 0)
        menu.getItem(2).setTitle("Stream Audio");
    else//from ww w  .j  av  a 2 s  . c o m
        menu.getItem(2).setTitle("Stream Video");

    if (DEFAULT_OPEN == 0)
        menu.getItem(3).setTitle("Stream in Another App");
    else
        menu.getItem(3).setTitle("Stream in This App");
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setOnMenuItemClickListener(this);
    }
}

From source file:org.thaliproject.nativetest.app.fragments.PeerListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.menu_peers, menu);

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    int position = info.position;
    PeerProperties peerProperties = (PeerProperties) mListView.getItemAtPosition(position);

    MenuUtils.PeerMenuItemsAvailability availability = MenuUtils
            .resolvePeerMenuItemsAvailability(peerProperties, mModel);

    MenuItem connectMenuItem = menu.getItem(0);
    MenuItem disconnectMenuItem = menu.getItem(1);
    MenuItem sendDataMenuItem = menu.getItem(2);

    connectMenuItem.setEnabled(availability.connectMenuItemAvailable);
    sendDataMenuItem.setEnabled(availability.sendDataMenuItemAvailable);
    disconnectMenuItem.setEnabled(availability.disconnectMenuItemAvailable);
}

From source file:org.mozilla.mozstumbler.client.serialize.KMLFragment.java

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final ListView list = (ListView) v;
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    final int position = info.position;
    final Object object = list.getAdapter().getItem(position);

    menu.add(R.string.load_file);/*from   ww w .  java2  s. c  o m*/
    menu.add(R.string.share_file);
    menu.add(R.string.delete_file);
    menu.add(R.string.delete_all);

    MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            contextItemSelected(item, (object == null) ? null : object.toString());
            if (mLoadFileDialog != null && mLoadFileDialog.isShowing()) {
                mLoadFileDialog.dismiss();
            }
            return false;
        }
    };

    for (int i = 0, n = menu.size(); i < n; i++)
        menu.getItem(i).setOnMenuItemClickListener(listener);
}

From source file:com.android.browser.BookmarksPageCallbacks.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    BookmarkContextMenuInfo info = (BookmarkContextMenuInfo) menuInfo;
    BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition);
    Cursor cursor = adapter.getItem(info.childPosition);
    if (!canEdit(cursor)) {
        return;//from  w ww .j  a v a2s. c om
    }
    boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0;

    final Activity activity = getActivity();
    MenuInflater inflater = activity.getMenuInflater();
    inflater.inflate(R.menu.bookmarkscontext, menu);
    if (isFolder) {
        menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true);
    } else {
        menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true);
        if (mDisableNewWindow) {
            menu.findItem(R.id.new_window_context_menu_id).setVisible(false);
        }
    }
    BookmarkItem header = new BookmarkItem(activity);
    header.setEnableScrolling(true);
    populateBookmarkItem(cursor, header, isFolder);
    menu.setHeaderView(header);

    int count = menu.size();
    for (int i = 0; i < count; i++) {
        menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener);
    }
}

From source file:com.baohume.browser.BookmarksPageCallbacks.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    BookmarkExpandableView.BookmarkContextMenuInfo info = (BookmarkExpandableView.BookmarkContextMenuInfo) menuInfo;
    BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition);
    Cursor cursor = adapter.getItem(info.childPosition);
    if (!canEdit(cursor)) {
        return;//  w  w w .jav a 2s.c om
    }
    boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0;

    final Activity activity = getActivity();
    MenuInflater inflater = activity.getMenuInflater();
    inflater.inflate(R.menu.bookmarkscontext, menu);
    if (isFolder) {
        menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true);
    } else {
        menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true);
        if (mDisableNewWindow) {
            menu.findItem(R.id.new_window_context_menu_id).setVisible(false);
        }
    }
    BookmarkItem header = new BookmarkItem(activity);
    header.setEnableScrolling(true);
    populateBookmarkItem(cursor, header, isFolder);
    menu.setHeaderView(header);

    int count = menu.size();
    for (int i = 0; i < count; i++) {
        menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener);
    }
}

From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    BookmarkContextMenuInfo info = (BookmarkContextMenuInfo) menuInfo;
    BrowserBookmarksAdapter adapter = getChildAdapter(info.groupPosition);
    Cursor cursor = adapter.getItem(info.childPosition);
    if (!canEdit(cursor)) {
        return;/*from  ww  w.  j  a  v  a 2s.  c  om*/
    }
    boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0;

    final Activity activity = this;
    MenuInflater inflater = activity.getMenuInflater();
    inflater.inflate(R.menu.bookmarkscontext, menu);
    if (isFolder) {
        menu.setGroupVisible(R.id.FOLDER_CONTEXT_MENU, true);
    } else {
        menu.setGroupVisible(R.id.BOOKMARK_CONTEXT_MENU, true);
        if (mDisableNewWindow) {
            menu.findItem(R.id.new_window_context_menu_id).setVisible(false);
        }
    }
    BookmarkItem header = new BookmarkItem(activity);
    header.setEnableScrolling(true);
    populateBookmarkItem(cursor, header, isFolder);
    menu.setHeaderView(header);

    int count = menu.size();
    for (int i = 0; i < count; i++) {
        menu.getItem(i).setOnMenuItemClickListener(mContextItemClickListener);
    }
}

From source file:com.pdftron.pdf.controls.UserBookmarkDialogFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.controls_bookmark_recycler_view) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        UserBookmarkItem item = mBookmarkViewAdapter.getItem(info.position);
        menu.setHeaderTitle(item.title);
        String[] menuItems = getResources().getStringArray(R.array.user_bookmark_dialog_context_menu);
        menu.add(Menu.NONE, CONTEXT_MENU_EDIT_ITEM, CONTEXT_MENU_EDIT_ITEM, menuItems[CONTEXT_MENU_EDIT_ITEM]);
        menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, CONTEXT_MENU_DELETE_ITEM,
                menuItems[CONTEXT_MENU_DELETE_ITEM]);
        menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ALL, CONTEXT_MENU_DELETE_ALL,
                menuItems[CONTEXT_MENU_DELETE_ALL]);

        MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
            @Override/*from   www.  ja v a2 s.c  o m*/
            public boolean onMenuItemClick(MenuItem item) {
                onContextItemSelected(item);
                return true;
            }
        };
        menu.getItem(CONTEXT_MENU_EDIT_ITEM).setOnMenuItemClickListener(listener);
        menu.getItem(CONTEXT_MENU_DELETE_ITEM).setOnMenuItemClickListener(listener);
        menu.getItem(CONTEXT_MENU_DELETE_ALL).setOnMenuItemClickListener(listener);
    }
}

From source file:jackpal.androidterm.Term.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(R.string.edit_text);
    menu.add(0, SELECT_TEXT_ID, 0, R.string.select_text);
    menu.add(0, COPY_ALL_ID, 0, R.string.copy_all);
    menu.add(0, PASTE_ID, 0, R.string.paste);
    // menu.add(0, SEND_CONTROL_KEY_ID, 0, R.string.send_control_key);
    // menu.add(0, SEND_FN_KEY_ID, 0, R.string.send_fn_key);
    menu.add(0, SEND_MENU_ID, 0, R.string.title_functionbar_menu);
    // menu.add(0, SEND_FUNCTION_BAR_ID, 0, R.string.toggle_function_bar);
    if (!canPaste()) {
        menu.getItem(PASTE_ID).setEnabled(false);
    }//from w  w  w. j  ava  2  s  .  co m
}