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

The following examples show how to use android.view.MenuItem#getMenuInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoryFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    if(!getUserVisibleHint()) return super.onContextItemSelected(item);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    if(info == null) // info can be null
        return super.onContextItemSelected(item);
    int id = item.getItemId();

    if(id == R.id.history_view_play) {
        playListIndex(info.position);
        return true;
    } else if(id == R.id.history_view_delete) {
        mHistoryAdapter.remove(info.position);
        return true;
    }
    return super.onContextItemSelected(item);
}
 
Example 2
Source File: DetectedBeaconsFragment.java    From beaconloc with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    ContextMenuRecyclerView.RecyclerContextMenuInfo info = (ContextMenuRecyclerView
            .RecyclerContextMenuInfo) item
            .getMenuInfo();

    switch (item.getItemId()) {
        case R.id.action_manage_add:
            selectBeacon(new TrackedBeacon((IManagedBeacon) mBeaconsAdapter.getItem(info.position)));
            return true;
        case R.id.action_filter_add:
            //TODO
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }

}
 
Example 3
Source File: FileList.java    From stynico with MIT License 6 votes vote down vote up
@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 4
Source File: MainActivity.java    From android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
	
	/*
	 *  Contiene información sobre el elemento del menú contextual
	 *  sobre el que se ha pulsado
	 */
	AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
	
	switch (item.getItemId()) {
		case R.id.ctx_eliminar:
			
			eliminarContacto(info);
			return true;
		default:
			return super.onContextItemSelected(item);
	}
}
 
Example 5
Source File: ArtistAlbumsFragment.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 */
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
    OdysseyRecyclerView.RecyclerViewContextMenuInfo info =
            (OdysseyRecyclerView.RecyclerViewContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
        case R.id.fragment_artist_albums_action_enqueue:
            enqueueAlbum(info.position);
            return true;
        case R.id.fragment_artist_albums_action_play:
            playAlbum(info.position);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 6
Source File: BudgetActivity.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item)
{
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    ListView listView = (ListView) findViewById(R.id.list);

    if(info != null)
    {
        Budget budget = (Budget) listView.getItemAtPosition(info.position);

        if (budget != null && item.getItemId() == R.id.action_edit)
        {
            Intent i = new Intent(getApplicationContext(), BudgetViewActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("id", budget.name);
            bundle.putBoolean("view", true);
            i.putExtras(bundle);
            startActivity(i);

            return true;
        }
    }

    return super.onContextItemSelected(item);
}
 
Example 7
Source File: SessionManagerActivity.java    From sniffer154 with GNU General Public License v3.0 6 votes vote down vote up
@Override
	public boolean onContextItemSelected(MenuItem item) {
		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
				.getMenuInfo();
		switch (item.getItemId()) {
		case R.id.itemLoad:
			loadSession(info.id);
			return true;
		case R.id.itemDelete:
			deleteSession(info.id);
			return true;
//		case R.id.itemExport:
//			exportSession(info.id);
//			return true;
		default:
			return false;
		}
	}
 
Example 8
Source File: Commander.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
@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 9
Source File: AudioBrowserFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem menu) {
    if(!getUserVisibleHint())
        return super.onContextItemSelected(menu);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menu.getMenuInfo();
    if (info != null && handleContextItemSelected(menu, info.position))
        return true;
    return super.onContextItemSelected(menu);
}
 
Example 10
Source File: PlaylistsView.java    From ampdroid with MIT License 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
	AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
	Playlist selected = controller.getPlaylists().get((int) info.id);
	String urlString = controller.getServer().getHost() + "/server/xml.server.php?action=playlist_songs&auth="
			+ controller.getServer().getAuthKey() + "&filter=" + String.valueOf(selected.getId());
	Log.d("url", urlString);
	switch (item.getItemId()) {
	case R.id.contextMenuAdd:
		controller.parsePlaylistSongs(urlString, controller.getPlayNow());
		Context context = getView().getContext();
		CharSequence text = getResources().getString(R.string.playlistsViewPlaylistAdded);
		int duration = Toast.LENGTH_SHORT;
		Toast toast = Toast.makeText(context, text, duration);
		toast.show();
		return true;
	case R.id.contextMenuOpen:
		controller.getSelectedSongs().clear();
		controller.parsePlaylistSongs(urlString, controller.getSelectedSongs());
		// Create new fragment and transaction
		SelectedSongsView newFragment = new SelectedSongsView();
		FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();

		// Replace whatever is in the fragment_container view with this fragment,
		// and add the transaction to the back stack
		transaction.replace(R.id.content_frame, newFragment);
		transaction.addToBackStack(null);

		// Commit the transaction
		transaction.commit();
		return true;
	default:
		return super.onContextItemSelected(item);
	}
}
 
Example 11
Source File: SingleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableRecyclerView.ExpandableRecyclerViewContextMenuInfo menuInfo =
            (ExpandableRecyclerView.ExpandableRecyclerViewContextMenuInfo) item.getMenuInfo();
    Logger.e(TAG, menuInfo.toString());
    return true;
}
 
Example 12
Source File: FormRecordListActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    try {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
        FormRecord selectedRecord = (FormRecord)adapter.getItem(info.position);
        switch (item.getItemId()) {
            case OPEN_RECORD:
                returnItem(info.position);
                return true;
            case DELETE_RECORD:
                FormRecord toDelete =
                        CommCareApplication.instance().getUserStorage(FormRecord.class).read((int)info.id);
                toDelete.logPendingDeletion(TAG, "the user manually selected 'DELETE' in FormRecordListActivity");
                FormRecordCleanupTask.wipeRecord(toDelete);
                listView.post(adapter::notifyDataSetInvalidated);
                return true;
            case RESTORE_RECORD:
                new FormRecordProcessor(this).updateRecordStatus(selectedRecord, FormRecord.STATUS_UNSENT);
                adapter.resetRecords();
                adapter.notifyDataSetChanged();
                return true;
            case SCAN_RECORD:
                FormRecord theRecord = (FormRecord)adapter.getItem(info.position);
                Pair<Boolean, String> result = new FormRecordProcessor(this).verifyFormRecordIntegrity(theRecord);
                createFormRecordScanResultDialog(result, theRecord);
                logIntegrityScanResult(theRecord, result);
                return true;
            case VIEW_QUARANTINE_REASON:
                createQuarantineReasonDialog(selectedRecord);
                return true;
        }
        return true;
    } catch (SessionUnavailableException e) {
        //TODO: Login and try again
        return true;
    }
}
 
Example 13
Source File: ReminderListActivity.java    From Task-Reminder-App with MIT License 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
	switch(item.getItemId()) {
   	case R.id.menu_delete:
   		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        mDbHelper.deleteReminder(info.id);
        fillData();
        return true;
	}
	return super.onContextItemSelected(item);
}
 
Example 14
Source File: NewTabFragment.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
    switch (item.getItemId()) {
        case R.id.context_menu_quickaccess_move:
            adapter.setDraggingItem(position);
            return true;
        case R.id.context_menu_quickaccess_remove:
            list.remove(position);
            adapter.notifyDataSetChanged();
            saveQuickAccessToPreferences();
            return true;
    }
    return false;
}
 
Example 15
Source File: AutohideActivity.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.context_menu_delete) {
        if (item.getMenuInfo() != null && item.getMenuInfo() instanceof AdapterView.AdapterContextMenuInfo) {
            int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
            if (position > 0) {
                rulesJson.remove(position-1);
                rulesChanged();
            }
        }
    }
    return super.onContextItemSelected(item);
}
 
Example 16
Source File: AlbumTracksFragment.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 */
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
    OdysseyRecyclerView.RecyclerViewContextMenuInfo info =
            (OdysseyRecyclerView.RecyclerViewContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
        case R.id.fragment_album_tracks_action_play:
            playTrack(info.position);
            return true;
        case R.id.fragment_album_tracks_action_enqueue:
            enqueueTrack(info.position, false);
            return true;
        case R.id.fragment_album_tracks_action_enqueueasnext:
            enqueueTrack(info.position, true);
            return true;
        case R.id.fragment_album_tracks_action_showartist:
            showArtist(info.position);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
Example 17
Source File: TodosOverviewActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case DELETE_ID:
		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
				.getMenuInfo();
		Uri uri = Uri.parse(MyTodoContentProvider.CONTENT_URI + "/"
				+ info.id);
		getContentResolver().delete(uri, null, null);
		fillData();
		return true;
	}
	return super.onContextItemSelected(item);
}
 
Example 18
Source File: PrivateMessageListFragment.java    From something.apk with MIT License 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()){
        case R.id.menu_delete:
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
            FastItem pm = adapter.getItem(info.position);
            if(pm != null){
                queueRequest(new PMDeleteRequest(folderId, deleteListener, null, pm.getId()));
                return true;
            }
    }
    return super.onContextItemSelected(item);
}
 
Example 19
Source File: LyricExplorerFragment.java    From LyricHere with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    boolean handled = false;
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    // info.id will return row id
    // select * from lyric where title like "De%";

    Cursor cursor = (Cursor) mAdapter.getItem(info.position);
    String path = cursor.getString(cursor.getColumnIndex(Constants.Column.PATH));
    switch (item.getItemId()) {
        case R.id.menu_encoding_big5:
            new LyricEncodingUpdater(getActivity()).execute(path,
                    cursor.getString(cursor.getColumnIndex(Constants.Column.ID)),
                    Constants.ENCODE_BIG5);
            handled = true;
            break;
        case R.id.menu_encoding_gbk:
            new LyricEncodingUpdater(getActivity()).execute(path,
                    cursor.getString(cursor.getColumnIndex(Constants.Column.ID)),
                    Constants.ENCODE_GBK);
            handled = true;
            break;
        case R.id.menu_encoding_sjis:
            new LyricEncodingUpdater(getActivity()).execute(path,
                    cursor.getString(cursor.getColumnIndex(Constants.Column.ID)),
                    Constants.ENCODE_SJIS);
            handled = true;
            break;
        case R.id.menu_encoding_utf_8:
            new LyricEncodingUpdater(getActivity()).execute(path,
                    cursor.getString(cursor.getColumnIndex(Constants.Column.ID)),
                    Constants.ENCODE_UTF_8);
            handled = true;
            break;
        default:
            break;
    }
    if (handled) {
        return true;
    } else {
        return super.onContextItemSelected(item);
    }
}
 
Example 20
Source File: AllTasksListFragment.java    From ActivityLauncher with ISC License 4 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
    ExpandableListView list = getView().findViewById(R.id.expandableListView1);

    switch (ExpandableListView.getPackedPositionType(info.packedPosition)) {
        case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
            MyActivityInfo activity = (MyActivityInfo) list.getExpandableListAdapter().getChild(ExpandableListView.getPackedPositionGroup(info.packedPosition), ExpandableListView.getPackedPositionChild(info.packedPosition));
            switch (item.getItemId()) {
                case 0:
                    LauncherIconCreator.createLauncherIcon(getActivity(), activity);
                    break;
                case 1:
                    LauncherIconCreator.launchActivity(getActivity(), activity.component_name);
                    break;
                case 2:
                    DialogFragment dialog = new ShortcutEditDialogFragment();
                    Bundle args = new Bundle();
                    args.putParcelable("activity", activity.component_name);
                    dialog.setArguments(args);
                    dialog.show(getFragmentManager(), "ShortcutEditor");
                    break;
            }
            break;

        case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
            MyPackageInfo pack = (MyPackageInfo) list.getExpandableListAdapter().getGroup(ExpandableListView.getPackedPositionGroup(info.packedPosition));
            switch (item.getItemId()) {
                case 0:
                    boolean success = LauncherIconCreator.createLauncherIcon(getActivity(), pack);
                    Toast.makeText(getActivity(), getString(R.string.error_no_default_activity), Toast.LENGTH_LONG).show();
                    break;
                case 1:
                    PackageManager pm = getActivity().getPackageManager();
                    Intent intent = pm.getLaunchIntentForPackage(pack.package_name);
                    if (intent != null) {
                        Toast.makeText(getActivity(), String.format(getText(R.string.starting_application).toString(), pack.name), Toast.LENGTH_LONG).show();
                        getActivity().startActivity(intent);
                    } else {
                        Toast.makeText(getActivity(), getString(R.string.error_no_default_activity), Toast.LENGTH_LONG).show();
                    }
                    break;
            }
    }
    return super.onContextItemSelected(item);
}