Java Code Examples for android.view.MenuItem.getMenuInfo()

The following are Jave code examples for showing how to use getMenuInfo() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: financisto1-holo   File: AccountListActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
	super.onContextItemSelected(item);
       AdapterView.AdapterContextMenuInfo mi = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
       switch (item.getItemId()) {
		case MENU_UPDATE_BALANCE: {
               updateAccountBalance(mi.id);
               return true;
           }
           case MENU_PURGE_ACCOUNT: {
               Intent intent = new Intent(this, PurgeAccountActivity.class);
               intent.putExtra(PurgeAccountActivity.ACCOUNT_ID, mi.id);
               startActivityForResult(intent, PURGE_ACCOUNT_REQUEST);
               return true;
           }
		case MENU_CLOSE_OPEN_ACCOUNT: {
			Account a = em.getAccount(mi.id);
			a.isActive = !a.isActive;
			em.saveAccount(a);
			recreateCursor();
			return true;
		} 			
	}
	return false;
}
 
Example 2
Project: firebase-testlab-instr-lib   File: NotesList.java   View Source Code Vote up 6 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
         info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }
    
    Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), info.id);

    switch (item.getItemId()) {
    case R.id.context_open:
        // Launch activity to view/edit the currently selected item
        startActivity(new Intent(Intent.ACTION_EDIT, noteUri));
        return true;
    case R.id.context_delete:
        // Delete the note that the context menu is for
        getContentResolver().delete(noteUri, null, null);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}
 
Example 3
Project: microMathematics   File: Commander.java   View Source Code Vote up 6 votes
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
    if (featureId != Window.FEATURE_CONTEXT_MENU)
    {
        return false;
    }
    try
    {
        AdapterView.AdapterContextMenuInfo info;
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        if (info == null)
            return false;
        fileListView.setSelection(info.position, 0);
        dispatchCommand(item.getItemId());
        return true;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
}
 
Example 4
Project: stynico   File: FileList.java   View Source Code Vote up 6 votes
@Override
   public boolean onContextItemSelected(MenuItem item)
   {
AdapterContextMenuInfo menuInfo =
    (AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0)
{
    //预览
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(curpath + "/" + files_name.get(menuInfo.position - dirs_name.size())));
    intent.setDataAndType(uri, "image/*");
    startActivity(intent);

}
return super.onOptionsItemSelected(item);
   }
 
Example 5
Project: CSipSimple   File: CodecsFragment.java   View Source Code Vote up 6 votes
@Override
@SuppressWarnings("unchecked")
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
         info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(THIS_FILE, "bad menuInfo", e);
        return false;
    }
    
    HashMap<String, Object> codec = null;
    codec = (HashMap<String, Object>) mAdapter.getItem(info.position);
    
    if (codec == null) {
        // If for some reason the requested item isn't available, do nothing
        return false;
    }
    int selId = item.getItemId();
    if (selId == MENU_ITEM_ACTIVATE) {
        boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
        userActivateCodec(codec, isDisabled);
        return true;
    }
    return false;
}
 
Example 6
Project: buildAPKsSamples   File: GestureBuilderActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)
            item.getMenuInfo();
    final NamedGesture gesture = (NamedGesture) menuInfo.targetView.getTag();

    switch (item.getItemId()) {
        case MENU_ID_RENAME:
            renameGesture(gesture);
            return true;
        case MENU_ID_REMOVE:
            deleteGesture(gesture);
            return true;
    }

    return super.onContextItemSelected(item);
}
 
Example 7
Project: encdroidMC   File: EDFileChooserActivity.java   View Source Code Vote up 5 votes
public boolean onContextItemSelected(MenuItem item) {
	AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
			.getMenuInfo();
	switch (item.getItemId()) {
		case R.id.file_chooser_menu_select:
		case R.id.file_picker_menu_import:
			if (info.id >= 0) {
				EDFileChooserItem selected = mAdapter.getItem((int) info.id);
				returnResult(selected.getPath());
			}
			return true;
		default:
			return super.onContextItemSelected(item);
	}
}
 
Example 8
Project: CCDownload   File: DownloadingFragment.java   View Source Code Vote up 5 votes
public boolean onContextItemSelected(MenuItem item) {
	if (item.getGroupId() != ConfigUtil.DOWNLOADING_MENU_GROUP_ID) {
		return false;
	}
	
	int selectedPosition = ((AdapterContextMenuInfo) item.getMenuInfo()).position;// 获取点击了第几行
	DownloadInfo downloadInfo = (DownloadInfo) downloadAdapter.getItem(selectedPosition);
	String title = downloadInfo.getTitle();

	// 删除数据库记录
	DataSet.removeDownloadInfo(title);

	File file = new File(Environment.getExternalStorageDirectory()+"/CCDownload", title+".mp4");
	if(file.exists()){
		file.delete();
	}
	
	// 通知service取消下载
	if (!binder.isStop() && binder.exists(title)) {
		binder.cancel(title);
		startWaitStatusDownload();
	}
	
	initData();
	downloadAdapter.notifyDataSetChanged();
	downloadingListView.invalidate();

	if (getUserVisibleHint()) {
		return true;
	}
	
	return false;
}
 
Example 9
Project: CCDownload   File: DownloadedFragment.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public boolean onContextItemSelected(MenuItem item) {
	if (item.getGroupId() != ConfigUtil.DOWNLOADED_MENU_GROUP_ID) {
		return false;
	}
	
	int selectedPosition = ((AdapterContextMenuInfo) item.getMenuInfo()).position;
	
	Pair<String, Integer> pair = (Pair<String, Integer>)videoListViewAdapter.getItem(selectedPosition);
	
	DataSet.removeDownloadInfo(pair.first);
	
	File file = new File(Environment.getExternalStorageDirectory()+"/"+ConfigUtil.DOWNLOAD_DIR, pair.first+".mp4");
	if(file.exists()){
		file.delete();
	}
	
	initData();
	videoListViewAdapter.notifyDataSetChanged();
	downloadedListView.invalidate();

	if (getUserVisibleHint()) {
		return true;
	}

	return false;
}
 
Example 10
Project: financisto1-holo   File: LocationsListActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
	if (super.onContextItemSelected(item)) {
		return true;
	}
	if (item.getItemId() == MENU_RESOLVE) {
		AdapterView.AdapterContextMenuInfo mi = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
		resolveAddress(mi.position, mi.id);
	}
	return false;
}
 
Example 11
Project: encdroidMC   File: EDVolumeListActivity.java   View Source Code Vote up 5 votes
public boolean onContextItemSelected(MenuItem item) {
	AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
			.getMenuInfo();
	EDVolume selected = mAdapter.getItem((int) info.id);

	switch (item.getItemId()) {
	case R.id.volume_list_menu_lock:
		if (selected.isLocked()) {
			mSelectedVolume = selected;
			mSelectedVolIdx = info.position;
			unlockSelectedVolume();
		} else {
			selected.lock();
		}
		mAdapter.notifyDataSetChanged();
		return true;
	case R.id.volume_list_menu_rename:
		this.mSelectedVolume = selected;
		showDialog(DIALOG_VOL_RENAME);
		return true;
	case R.id.volume_list_menu_delete:
		this.mSelectedVolume = selected;
		showDialog(DIALOG_VOL_DELETE);
		return true;
	default:
		return super.onContextItemSelected(item);
	}
}
 
Example 12
Project: ultrasonic   File: DownloadActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(final MenuItem menuItem)
{
	final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();

	DownloadFile downloadFile = null;

	if (info != null)
	{
		downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
	}

	return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem);
}
 
Example 13
Project: DoorAccess   File: LocationFragment.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem menuItem) {

    final AdapterView.AdapterContextMenuInfo menuInfo;
    menuInfo = (AdapterView.AdapterContextMenuInfo)menuItem.getMenuInfo();

    /**
     * menuInfo.position for List index
     * menuItem.getItemId for operation index
     */
    ReaderLocation rLocation = mRLocaitonList.get(menuInfo.position);
    switch(menuItem.getItemId()) {
        case LOC_CONTEXT_MENU_MODIFY:
            Toast.makeText(getContext(), "LOC_CONTEXT_MENU_MODIFY", Toast.LENGTH_SHORT);
            ModifyLocationFragment modifyLocationFragment = new ModifyLocationFragment(rLocation, menuInfo.position);
            modifyLocationFragment.setTargetFragment(this, 0);
            modifyLocationFragment.show(mFragmentManager, "ModifyLocation");
            break;
        case LOC_CONTEXT_MENU_TAG:
            Toast.makeText(getContext(), "LOC_CONTEXT_MENU_TAG", Toast.LENGTH_SHORT);
            AssociateTagFragment associateTagFragment = new AssociateTagFragment(rLocation, menuInfo.position);
            associateTagFragment.setTargetFragment(this, 0);
            associateTagFragment.show(mFragmentManager, "AssociateTag");
            break;
        case LOC_CONTEXT_MENU_DELETE:
            Toast.makeText(getContext(), "LOC_CONTEXT_MENU_DELETE", Toast.LENGTH_SHORT);
            DeleteLocation(rLocation);
            break;
    }

    return false;
}
 
Example 14
Project: mobile-grammar   File: UserGroupLessonsActivity.java   View Source Code Vote up 5 votes
/**
 * Provides two actions: edit and hide a group
 *
 * @param item MenuItem
 * @return
 */
@SuppressWarnings("JavaDoc")
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    // get data of row where context menu has been fired
    int groupIdToRemove = info.position;
    /**
     * When we click on listview, we get variable "position", which counts since 0, having in mind just simple order of row.
     * In order to edit group we must to define his id from database
     */
    Cursor c = (Cursor) userGroupLessonsViewAdapter.getItem(groupIdToRemove);
    Long id = c.getLong(c.getColumnIndexOrThrow("_id"));
    // We extract name of group if user would want to edit name
    String groupNameToEdit = c.getString(c.getColumnIndexOrThrow("title"));

    switch (item.getItemId()) {
        case R.id.context_menu_edit_group:
            // edit group
            Intent intent = new Intent(getApplicationContext(), FormCreateNewGroupActivity.class);
            intent.putExtra("edit_group", id);
            intent.putExtra("group_name", groupNameToEdit);
            startActivity(intent);
            return true;
        case R.id.context_menu_remove_group:
            // remove group. User must confirm the removing
            new AlertDialog.Builder(this)
                    .setIcon(R.drawable.drawer_icon)
                    .setTitle(R.string.removing_group)
                    .setMessage(R.string.this_will_remove_selected_group)
                    .setPositiveButton(message_ok, new AlertRemoveGroupById(id))
                    .setNegativeButton(message_cancel, null)
                    .show();
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 15
Project: aos-Video   File: BrowserPlaylists.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    int index = item.getItemId();
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    long listId = mBrowserAdapter.getItemId(info.position);
    switch (index) {
        case R.string.delete:
            getActivity().getContentResolver().delete(VideoStore.List.LIST_CONTENT_URI, VideoStore.List.Columns.ID +" = ?", new String[]{listId+""});
            break;
    }
    return true;
}
 
Example 16
Project: buildAPKsSamples   File: AccountsActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
  AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item
      .getMenuInfo();
  Account account = (Account) adapter.getItem(menuInfo.position);

  switch (item.getItemId()) {
  case CONTEXT_MENU_EDIT:
    return true;
  case CONTEXT_MENU_DELETE:
    showAreYouSureDialog(account.position);
    return true;
  }
  return super.onContextItemSelected(item);
}
 
Example 17
Project: AndroidRTC   File: ConnectActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == REMOVE_FAVORITE_INDEX) {
        AdapterView.AdapterContextMenuInfo info =
                (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        roomList.remove(info.position);
        adapter.notifyDataSetChanged();
        return true;
    }

    return super.onContextItemSelected(item);
}
 
Example 18
Project: HabitUp   File: ViewHabitActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int position = info.position;

    final Habit habit = (Habit) adapter.getItem(position);
    int hid = habit.getHID();
    String habitName = habit.getHabitName();

    switch (item.getItemId()) {
        case 1:
            if (!HabitUpApplication.isOnline(getApplicationContext())) {
                Toast.makeText(getApplicationContext(),
                        "Error: No connection to the internet.",
                        Toast.LENGTH_SHORT).show();
                return false;
            }
            goToEditActivity(EDIT_HABIT, hid, habitName);
            return true;
        case 2:
            if (!HabitUpApplication.isOnline(getApplicationContext())) {
                Toast.makeText(getApplicationContext(),
                        "Error: No connection to the internet.",
                        Toast.LENGTH_SHORT).show();
                return false;
            }
            deleteHabit(habit);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 19
Project: orgzly-android   File: BooksFragment.java   View Source Code Vote up 5 votes
@Override
public boolean onContextItemSelected(MenuItem item) {
    /* Get ID of the item. */
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    long bookId = info.id;

    switch (item.getItemId()) {
        case R.id.books_context_menu_rename: /* Rename book. */
            mListener.onBookRenameRequest(bookId);
            return true;

        case R.id.books_context_menu_set_link: /* Set link to remote book. */
            mListener.onBookLinkSetRequest(bookId);
            return true;

        case R.id.books_context_menu_force_save:
            mListener.onForceSaveRequest(bookId);
            return true;

        case R.id.books_context_menu_force_load:
            mListener.onForceLoadRequest(bookId);
            return true;

        case R.id.books_context_menu_export: /* Export book. */
            mListener.onBookExportRequest(bookId);
            return true;

        case R.id.books_context_menu_delete: /* Delete book. */
            mListener.onBookDeleteRequest(bookId);
            return true;

        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 20
Project: ultrasonic   File: SelectAlbumActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onContextItemSelected(MenuItem menuItem)
{
	AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();

	if (info == null)
	{
		return true;
	}

	MusicDirectory.Entry entry = (MusicDirectory.Entry) albumListView.getItemAtPosition(info.position);

	if (entry == null)
	{
		return true;
	}

	String entryId = entry.getId();

	switch (menuItem.getItemId())
	{
		case R.id.album_menu_play_now:
			downloadRecursively(entryId, false, false, true, false, false, false, false, false);
			break;
		case R.id.album_menu_play_next:
			downloadRecursively(entryId, false, false, false, false, false, true, false, false);
			break;
		case R.id.album_menu_play_last:
			downloadRecursively(entryId, false, true, false, false, false, false, false, false);
			break;
		case R.id.album_menu_pin:
			downloadRecursively(entryId, true, true, false, false, false, false, false, false);
			break;
		case R.id.album_menu_unpin:
			downloadRecursively(entryId, false, false, false, false, false, false, true, false);
			break;
		case R.id.album_menu_download:
			downloadRecursively(entryId, false, false, false, false, true, false, false, false);
			break;
		case R.id.select_album_play_all:
			playAll();
			break;
		case R.id.menu_item_share:
			List<MusicDirectory.Entry> entries = new ArrayList<MusicDirectory.Entry>(1);
			entries.add(entry);
			createShare(entries);
			return true;
		default:
			return super.onContextItemSelected(menuItem);
	}
	return true;
}