Example usage for android.view MenuItem getMenuInfo

List of usage examples for android.view MenuItem getMenuInfo

Introduction

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

Prototype

public ContextMenuInfo getMenuInfo();

Source Link

Document

Gets the extra information linked to this menu item.

Usage

From source file:com.mahali.gpslogger.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    String[] menuItems = getResources().getStringArray(R.array.sessionLongMenu);
    String menuItemName = menuItems[menuItemIndex];
    String listItemName = sessionList.get(info.position).getFileName();

    GPSSession clickedSession = sessionList.get(info.position);
    Log.v(TAG, String.format("Selected %s for item %s", menuItemName, listItemName));

    // Share session
    if (menuItemIndex == 0) {
        Log.v(TAG, "Sharing session " + clickedSession.getFileName());
        shareSession(clickedSession);/* ww  w  . j a v  a 2  s. c  o  m*/
    }

    // Delete session
    if (menuItemIndex == 1) {
        Log.v(TAG, "Deleting session " + clickedSession.getFileName());
        deleteSession(clickedSession);
    }

    return true;
}

From source file:com.nttec.everychan.ui.NewTabFragment.java

private void openChansList() {
    final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) {
        private LayoutInflater inflater = LayoutInflater.from(activity);
        private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f);

        {//from w w w  .  ja  v  a  2s  .c o  m
            for (ChanModule chan : MainApplication.getInstance().chanModulesList)
                add(chan);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ChanModule chan = getItem(position);
            TextView view = (TextView) (convertView == null
                    ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
                    : convertView);
            view.setText(chan.getDisplayingName());
            view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null);
            view.setCompoundDrawablePadding(drawablePadding);
            return view;
        }
    };

    DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ChanModule chan = chansAdapter.getItem(which);
            UrlPageModel model = new UrlPageModel();
            model.chanName = chan.getChanName();
            model.type = UrlPageModel.TYPE_INDEXPAGE;
            openNewTab(chan.buildUrl(model));
        }
    };

    final AlertDialog chansListDialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected)
            .setNegativeButton(android.R.string.cancel, null).create();

    chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() {
                @SuppressLint("InlinedApi")
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final ChanModule chan = chansAdapter
                            .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position);
                    switch (item.getItemId()) {
                    case R.id.context_menu_favorites_from_fragment:
                        if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null,
                                null)) {
                            MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null,
                                    null, null);
                        } else {
                            try {
                                UrlPageModel indexPage = new UrlPageModel();
                                indexPage.chanName = chan.getChanName();
                                indexPage.type = UrlPageModel.TYPE_INDEXPAGE;
                                MainApplication.getInstance().database.addFavorite(chan.getChanName(), null,
                                        null, null, chan.getChanName(), chan.buildUrl(indexPage));
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }
                        return true;
                    case R.id.context_menu_quickaccess_add:
                        QuickAccess.Entry newEntry = new QuickAccess.Entry();
                        newEntry.chan = chan;
                        list.add(0, newEntry);
                        adapter.notifyDataSetChanged();
                        saveQuickAccessToPreferences();
                        chansListDialog.dismiss();
                        return true;
                    case R.id.context_menu_quickaccess_custom_board:
                        LinearLayout dialogLayout = new LinearLayout(activity);
                        dialogLayout.setOrientation(LinearLayout.VERTICAL);
                        final EditText boardField = new EditText(activity);
                        final EditText descriptionField = new EditText(activity);
                        boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode);
                        descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc);
                        LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                        dialogLayout.addView(boardField, fieldsParams);
                        dialogLayout.addView(descriptionField, fieldsParams);
                        DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String boardName = boardField.getText().toString();
                                for (QuickAccess.Entry entry : list)
                                    if (entry.boardName != null && entry.chan != null)
                                        if (entry.chan.getChanName().equals(chan.getChanName())
                                                && entry.boardName.equals(boardName)) {
                                            Toast.makeText(activity,
                                                    R.string.newtab_quickaccess_addcustom_already_exists,
                                                    Toast.LENGTH_LONG).show();
                                            return;
                                        }

                                try {
                                    if (boardName.trim().length() == 0)
                                        throw new Exception();
                                    UrlPageModel boardPageModel = new UrlPageModel();
                                    boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE;
                                    boardPageModel.chanName = chan.getChanName();
                                    boardPageModel.boardName = boardName;
                                    boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
                                    chan.buildUrl(boardPageModel); //,  ??  ?    
                                } catch (Exception e) {
                                    Toast.makeText(activity,
                                            R.string.newtab_quickaccess_addcustom_incorrect_code,
                                            Toast.LENGTH_LONG).show();
                                    return;
                                }

                                QuickAccess.Entry newEntry = new QuickAccess.Entry();
                                newEntry.chan = chan;
                                newEntry.boardName = boardName;
                                newEntry.boardDescription = descriptionField.getText().toString();
                                list.add(0, newEntry);
                                adapter.notifyDataSetChanged();
                                saveQuickAccessToPreferences();
                                chansListDialog.dismiss();
                            }
                        };
                        new AlertDialog.Builder(activity)
                                .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title,
                                        chan.getChanName()))
                                .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked)
                                .setNegativeButton(android.R.string.cancel, null).show();
                        return true;
                    }
                    return false;
                }
            };
            String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)
                    .getChanName();
            boolean canAddToQuickAccess = true;
            for (QuickAccess.Entry entry : list)
                if (entry.boardName == null && entry.chan != null
                        && entry.chan.getChanName().equals(thisChanName)) {
                    canAddToQuickAccess = false;
                    break;
                }
            menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1,
                    MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null)
                            ? R.string.context_menu_remove_favorites
                            : R.string.context_menu_add_favorites)
                    .setOnMenuItemClickListener(contextMenuHandler);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add)
                    .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3,
                    R.string.context_menu_quickaccess_custom_board)
                    .setOnMenuItemClickListener(contextMenuHandler);
            if (isSingleboardChan(
                    chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)))
                menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false);
        }
    });
    chansListDialog.show();
}

From source file:org.tigase.mobile.roster.RosterFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    long lastId = extractId(lastMenuInfo);

    if (item.getItemId() == R.id.contactDetails) {
        Long infoId = extractId(item.getMenuInfo());
        Intent intent = new Intent(getActivity().getApplicationContext(), VCardViewActivity.class);
        intent.putExtra("itemId", infoId);
        this.startActivityForResult(intent, 0);
        return true;
    } else if (item.getItemId() == R.id.contactEdit) {
        Long infoId = extractId(item.getMenuInfo());
        Intent intent = new Intent(getActivity().getApplicationContext(), ContactEditActivity.class);
        intent.putExtra("itemId", infoId);
        this.startActivityForResult(intent, 0);
        return true;
    } else if (item.getItemId() == R.id.contactRemove) {
        Long infoId = extractId(item.getMenuInfo());
        DialogFragment newFragment = ContactRemoveDialog.newInstance(infoId);
        newFragment.show(getFragmentManager(), "dialog");
        return true;
    } else if (item.getItemId() == R.id.contactAuthorization) {
        this.lastMenuInfo = item.getMenuInfo();
        return true;
    } else if (item.getItemId() == R.id.contactAuthResend) {
        sendAuthResend(lastId);// w  w w .j  a  va 2 s  . c o  m
        return true;
    } else if (item.getItemId() == R.id.contactAuthRerequest) {
        sendAuthRerequest(lastId);
        return true;
    } else if (item.getItemId() == R.id.contactAuthRemove) {
        sendAuthRemove(lastId);
        return true;
    } else
        return super.onContextItemSelected(item);

}

From source file:com.gsma.rcs.ri.sharing.SharingListView.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Cursor cursor = (Cursor) mAdapter.getItem(info.position);
    int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID));
    String sharingId = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID));
    if (LogUtils.isActive) {
        Log.d(LOGTAG, "onContextItemSelected sharing ID=".concat(sharingId));
    }/*from   w  ww  .j  av  a  2 s  . com*/
    try {
        switch (item.getItemId()) {
        case R.id.menu_sharing_delete:
            Log.d(LOGTAG, "Delete sharing ID=".concat(sharingId));
            switch (providerId) {
            case ImageSharingLog.HISTORYLOG_MEMBER_ID:
                if (!mImageSharingListenerSet) {
                    mImageSharingService.addEventListener(mImageSharingListener);
                    mImageSharingListenerSet = true;
                }
                mImageSharingService.deleteImageSharing(sharingId);
                return true;

            case VideoSharingLog.HISTORYLOG_MEMBER_ID:
                if (!mVideoSharingListenerSet) {
                    mVideoSharingService.addEventListener(mVideoSharingListener);
                    mVideoSharingListenerSet = true;
                }
                mVideoSharingService.deleteVideoSharing(sharingId);
                return true;
            case GeolocSharingLog.HISTORYLOG_MEMBER_ID:
                if (!mGeolocSharingListenerSet) {
                    mGeolocSharingService.addEventListener(mGeolocSharingListener);
                    mGeolocSharingListenerSet = true;
                }
                mGeolocSharingService.deleteGeolocSharing(sharingId);
                return true;
            default:
                return true;
            }
        case R.id.menu_sharing_display:
            Utils.showPicture(this,
                    Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.CONTENT))));
            return true;

        default:
            return super.onContextItemSelected(item);
        }
    } catch (RcsServiceNotAvailableException e) {
        showMessage(R.string.label_service_not_available);
        return true;

    } catch (RcsGenericException e2) {
        showExceptionThenExit(e2);
        return true;
    }
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.context_menu_open:
        open(info.position);//w  w  w.ja  v a  2 s . c  om
        return true;
    case R.id.context_menu_share:
        share(info.position);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.hx.hxchat.activity.ContactlistFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete_contact) {
        User tobeDeleteUser = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
        if (tobeDeleteUser.getreferee().equals("1")) {
            // ?/* w  ww .  j  av  a 2 s .  c o  m*/
            deleteContact(tobeDeleteUser);
            // ?
            InviteMessgeDao dao = new InviteMessgeDao(getActivity());
            dao.deleteMessage(tobeDeleteUser.getUsername());
            return true;
        } else {
            Toast.makeText(getActivity(), "????", Toast.LENGTH_SHORT).show();
            return true;
        }

    }

    // else if (item.getItemId() == R.id.add_to_blacklist) {
    // User user = adapter.getItem(((AdapterContextMenuInfo)
    // item.getMenuInfo()).position);
    // try {
    // // ???
    // EMContactManager.getInstance().addUserToBlackList(user.getUsername(),
    // true);
    // Toast.makeText(getActivity(), "????", 0).show();
    // } catch (EaseMobException e) {
    // e.printStackTrace();
    // Toast.makeText(getActivity(), "???", 0).show();
    // }
    // }

    return super.onContextItemSelected(item);
}

From source file:com.yattatech.dbtc.activity.MainScreen.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    mIndex = info.position;/*from  www  .j  a  v a  2  s .c o m*/
    if (Debug.isDebugable()) {
        Debug.d(mTag, "onContextItemSelected item=" + item + " view=" + info.targetView + " position="
                + info.position + " id=" + info.id);
    }
    switch (item.getItemId()) {
    case R.id.editItem: {
        Debug.d(mTag, "editing task into the chain");
        final Task task = getSelectedTask(false);
        if (task != null) {
            startActivityWithTask(task, NewTaskScreen.class);
        }
        break;
    }
    case R.id.removeItem: {
        Debug.d(mTag, "removing a task from the chain");
        final Task task = getSelectedTask(true);
        if (task != null) {
            FACADE.removeTask(task);
        }
        break;
    }
    case R.id.finishItem: {
        Debug.d(mTag, "Marking task as finished");
        final Task task = getSelectedTask(true);
        if (!task.mFinished) {
            task.mFinished = true;
            FACADE.editTask(task);
        }
        break;
    }
    default: {
        // It's not supposed to reach here
        assert false;
    }
    }
    return true;
}

From source file:com.orangelabs.rcs.ri.messaging.chat.group.GroupChatView.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Cursor cursor = (Cursor) (mAdapter.getItem(info.position));
    String messageId = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID));
    if (LogUtils.isActive) {
        Log.d(LOGTAG, "onContextItemSelected Id=".concat(messageId));
    }//from ww  w  .  j  a va 2s. co m
    int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID));
    switch (item.getItemId()) {
    case GROUPCHAT_MENU_ITEM_VIEW_GC_INFO:
        GroupDeliveryInfoList.startActivity(this, messageId);
        return true;

    case GROUPCHAT_MENU_ITEM_DELETE:
        try {
            if (ChatLog.Message.HISTORYLOG_MEMBER_ID == providerId) {
                mChatService.deleteMessage(messageId);
            } else {
                mFileTransferService.deleteFileTransfer(messageId);
            }
        } catch (RcsServiceException e) {
            showException(e);
        }
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.tvheadend.tvhclient.fragments.TimerRecordingListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // The context menu is triggered for all fragments that are in a
    // fragment pager. Do nothing for invisible fragments.
    if (!getUserVisibleHint()) {
        return super.onContextItemSelected(item);
    }//from  www.  j  a v  a2 s  . c  o m
    // Get the currently selected program from the list where the context
    // menu has been triggered
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    // Check for a valid adapter size and objects
    if (info == null || adapter == null || adapter.getCount() <= info.position) {
        return super.onContextItemSelected(item);
    }

    final TimerRecording trec = adapter.getItem(info.position);

    switch (item.getItemId()) {
    case R.id.menu_record_remove:
        Utils.confirmRemoveRecording(activity, trec);
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.jefftharris.passwdsafe.PasswdSafeListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    int group = itsIsContents ? PasswdSafe.CONTEXT_GROUP_LIST_CONTENTS : PasswdSafe.CONTEXT_GROUP_LIST;
    if (item.getGroupId() != group) {
        return super.onContextItemSelected(item);
    }/*  w  w  w  .  j a va 2 s. co  m*/

    switch (item.getItemId()) {
    case R.id.menu_copy_password:
    case R.id.menu_copy_user: {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        final PasswdRecordListData listItem = itsAdapter.getItem(info.position);
        if (listItem.itsIsRecord) {
            itsSelectedRecord = listItem.itsUuid;
            itsListener.copyField(
                    (item.getItemId() == R.id.menu_copy_password) ? CopyField.PASSWORD : CopyField.USER_NAME,
                    listItem.itsUuid);
        }

        return true;
    }
    }
    return super.onContextItemSelected(item);
}