List of usage examples for android.view ContextMenu setHeaderIcon
public ContextMenu setHeaderIcon(Drawable icon);
From source file:edu.mit.mobile.android.livingpostcards.CardListFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { getActivity().getMenuInflater().inflate(R.menu.activity_card_view, menu); final Cursor c = mAdapter.getCursor(); if (c == null) { return;/* w ww . j a v a 2s . com*/ } final String myUserUri = Authenticator.getUserUri(getActivity()); final boolean isEditable = PrivatelyAuthorable.canEdit(myUserUri, c); menu.findItem(R.id.delete).setVisible(isEditable); menu.findItem(R.id.edit).setVisible(isEditable); menu.setHeaderTitle(Card.getTitle(getActivity(), c)); Drawable icon; try { String iconUrl = c.getString(c.getColumnIndexOrThrow(Card.COL_COVER_PHOTO)); if (iconUrl == null || iconUrl.length() == 0) { iconUrl = c.getString(c.getColumnIndexOrThrow(Card.COL_THUMBNAIL)); } icon = mImageCache.loadImage(0, Uri.parse(iconUrl), (int) (133 * mDensity), (int) (100 * mDensity)); if (icon != null) { menu.setHeaderIcon(new InsetDrawable(icon, (int) (5 * mDensity))); } } catch (final IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.bombusim.lime.fragments.RosterFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); int pos = ((AdapterContextMenuInfo) menuInfo).position; contextItem = getListAdapter().getItem(pos); if (contextItem instanceof RosterGroup) { //TODO: context menu for group return;/*from w w w . j ava 2s . c om*/ } if (contextItem instanceof XmppAccount) { //TODO: context menu for account return; } if (contextItem instanceof Contact) { Contact c = (Contact) contextItem; menu.setHeaderTitle(c.getScreenName()); Drawable icon = new BitmapDrawable(c.getAvatar()); menu.setHeaderIcon(icon); MenuInflater inflater = getActivity().getMenuInflater(); if (contextItem instanceof SelfContact) { inflater.inflate(R.menu.contact_self_menu, menu); } else { inflater.inflate(R.menu.contact_menu, menu); } //enable items available only if logged in menu.setGroupEnabled(R.id.groupLoggedIn, sb.isLoggedIn(c.getRosterJid())); return; } }
From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java
private void setupList(final HorizontialListView listview, final SimpleCursorAdapter listAdapter, final Cursor cursr) { if (cursr == null || cursr != null && cursr.getCount() == 0) { Toast.makeText(getApplication(), "No books available", Toast.LENGTH_LONG); } else {// w w w . j a v a 2 s . co m listview.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(final ContextMenu conMenu, final View v, final ContextMenuInfo menuInfo) { final LinearLayout ll = (LinearLayout) ((HorizontialListView) v) .getChildAt(((AdapterContextMenuInfo) menuInfo).position); final Drawable bookCover = ((ImageView) ll.getChildAt(0)).getDrawable(); final String bookTitle = ((TextView) ll.getChildAt(1)).getText().toString(); conMenu.setHeaderIcon(bookCover); // set to book cover conMenu.setHeaderTitle(bookTitle); // set to book title conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_VIEW_DETAILS, 0, R.string.book_grid_context_item_view_book_details); conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_OPEN_BOOK, 1, R.string.book_grid_context_item_open_book); conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_DELETE_BOOK, 2, R.string.book_grid_context_item_delete_book); } }); listview.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> av, final View v, final int pos, final long id) { myApp.dataMdl.launchBook(EBookLauncherActivity.this, id); } @Override public void onNothingSelected(final AdapterView<?> arg0) { } }); listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) { boolean retval = false; final int idColIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID); final int thumbColIndex = cursor.getColumnIndexOrThrow(DeviceFactory.getCoverImgColumnName()); if (columnIndex == idColIndex) { try { final ImageView coverImg = (ImageView) view; final String thumbnailFilename = cursor.getString(thumbColIndex); final Bitmap bitmap = myApp.dataMdl.getBookCoverImg(EBookLauncherActivity.this, thumbnailFilename); coverImg.setImageDrawable(new BitmapDrawable(bitmap)); retval = true; } catch (final Exception e) { Log.e(EBookLauncherApplication.LOG_TAG, EBookLauncherActivity.LOG_TAG + "Exception ", e); } retval = true; } return retval; } }); listview.setAdapter(listAdapter); registerForContextMenu(listview); startManagingCursor(cursr); } }