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:in.andres.kandroid.ui.TaskDetailActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.action_edit_comment:
        showCommentDialog((KanboardComment) commentListview.getAdapter().getItem(info.position));
        return true;
    case R.id.action_delete_comment:
        showDeleteCommentDialog((KanboardComment) commentListview.getAdapter().getItem(info.position));
        return true;
    case R.id.action_edit_subtask:
        showSubtaskDialog((KanboardSubtask) subtaskListview.getAdapter().getItem(info.position));
        return super.onContextItemSelected(item);
    case R.id.action_delete_subtask:
        showDeleteSubtaskDialog((KanboardSubtask) subtaskListview.getAdapter().getItem(info.position));
        return true;
    default:/*from   ww w . j  a v a2 s.  c  om*/
        return super.onContextItemSelected(item);
    }
}

From source file:com.almarsoft.GroundhogReader.MessageListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int order = item.getOrder();
    HeaderItemClass header = mHeaderItemsList.get(info.position);

    // "Mark thread as read"
    if (order == MENU_ITEM_MARKTHREADREAD)
        markThreadAsReadOrUnread(header, true);

    // "Mark thread as unread"
    if (order == MENU_ITEM_MARKTHREADUNREAD)
        markThreadAsReadOrUnread(header, false);

    if (order == MENU_ITEM_STARTHREAD) {

        ArrayList<HeaderItemClass> itemsProxy = mHeaderItemsList;
        int itemsSize = itemsProxy.size();
        String starred_thread_subject = header.getArticle().simplifiedSubject();

        for (int i = 0; i < itemsSize; i++) {
            if (itemsProxy.get(i).getArticle().simplifiedSubject() == starred_thread_subject) {
                itemStarClicked(i);/*from   ww  w.  j  a va 2  s  .co  m*/
            }
        }
    }

    if (order == MENU_ITEM_BANTHREAD) {
        banThread(header);
        Toast.makeText(this, getString(R.string.thread_ignore), Toast.LENGTH_LONG).show();
    }

    if (order == MENU_ITEM_BANUSER) {
        banUser(header);
        Toast.makeText(this, getString(R.string.author_banned_reload_tohide), Toast.LENGTH_LONG).show();
    }

    return true;
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    contextListPosition = info.position;
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()).setTitle("Move Meal To:");
    final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_list_item_1);
    mAdapterMoveMeal.add("Snack");
    mAdapterMoveMeal.add("Breakfast");
    mAdapterMoveMeal.add("Lunch");
    mAdapterMoveMeal.add("Dinner");
    builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
        @Override//from   w  w w .  j  ava  2s  . c o  m
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String strName = mAdapterMoveMeal.getItem(which);
            if (contextListChoice == 1) {
                LogMeal logMeals = mLogSnackAdapter.getItem(contextListPosition);
                logMeals.setMealChoice(strName);
                logMeals.edit();
                initializeAdapters(mDate);
            }
            if (contextListChoice == 2) {
                LogMeal logMeals = mLogBreakfastAdapter.getItem(contextListPosition);
                logMeals.setMealChoice(strName);
                logMeals.edit();
                initializeAdapters(mDate);
            }
            if (contextListChoice == 3) {
                LogMeal logMeals = mLogLunchAdapter.getItem(contextListPosition);
                logMeals.setMealChoice(strName);
                logMeals.edit();
                initializeAdapters(mDate);
            }
            if (contextListChoice == 4) {
                LogMeal logMeals = mLogDinnerAdapter.getItem(contextListPosition);
                logMeals.setMealChoice(strName);
                logMeals.edit();
                initializeAdapters(mDate);
            }
            updateListViews();
        }

    });
    switch (contextListChoice) {
    case 1:
        switch (menuItemIndex) {
        case 0:
            LogMeal logMeals = mLogSnackAdapter.getItem(contextListPosition);
            logMeals.delete();
            mLogSnackAdapter.remove(logMeals);
            mLogSnackAdapter.notifyDataSetChanged();
            testing();
            initializeAdapters(new Date());
            refreshOnDelete();
            updateListViews();
            equations();
            break;
        case 1:
            builderSingle.show();
            break;
        }
        break;
    case 2:
        switch (menuItemIndex) {
        case 0:
            LogMeal logMeals = mLogBreakfastAdapter.getItem(contextListPosition);
            logMeals.delete();
            mLogBreakfastAdapter.remove(logMeals);
            mLogBreakfastAdapter.notifyDataSetChanged();
            testing();
            initializeAdapters(new Date());
            refreshOnDelete();
            updateListViews();
            equations();
            break;
        case 1:
            builderSingle.show();
            break;
        }
        break;
    case 3:
        switch (menuItemIndex) {
        case 0:
            LogMeal logMeals = mLogLunchAdapter.getItem(contextListPosition);
            logMeals.delete();
            mLogLunchAdapter.remove(logMeals);
            mLogLunchAdapter.notifyDataSetChanged();
            testing();
            initializeAdapters(new Date());
            refreshOnDelete();
            updateListViews();
            equations();
            break;
        case 1:
            builderSingle.show();
            break;
        }
        break;
    case 4:
        switch (menuItemIndex) {
        case 0:
            LogMeal logMeals = mLogDinnerAdapter.getItem(contextListPosition);
            logMeals.delete();
            mLogDinnerAdapter.remove(logMeals);
            mLogDinnerAdapter.notifyDataSetChanged();
            testing();
            initializeAdapters(new Date());
            refreshOnDelete();
            updateListViews();
            equations();
            break;
        case 1:
            builderSingle.show();
            break;
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:edu.chalmers.dat255.audiobookplayer.view.BookshelfFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (getActivity() == null) {
        return false;
    }//from w  w  w.j a  v  a 2 s .c o m

    // this method is allowed to have quite a high cyclomatic complexity as
    // it would otherwise cause code duplication
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
    // get the provided book position
    int bookIndex = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    // will be -1 if the type is group
    int trackIndex = ExpandableListView.getPackedPositionChild(info.packedPosition);
    // get the type of the context menu
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);

    // create an empty array to prevent trying to loop over an uninitialized
    // variable
    IContextMenuItem[] menuItems = new IContextMenuItem[0];
    // fill the array with the correct items
    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        menuItems = ChildContextMenuItem.values();
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        menuItems = GroupContextMenuItem.values();
    }

    // get an item and store it with its dynamic type
    IContextMenuItem menuItem = menuItems[item.getItemId()];

    // if the type of the context menu is group
    if (menuItem instanceof GroupContextMenuItem) {

        // perform the correct task
        executeGroupMenuItem((GroupContextMenuItem) menuItem, bookIndex);

    }
    // if the type of the context menu is that of a child
    else if (menuItem instanceof ChildContextMenuItem) {
        // perform the correct task
        executeChildMenuItem((ChildContextMenuItem) menuItem, bookIndex, trackIndex);
    }
    return true;
}

From source file:org.mariotaku.twidere.fragment.MessagesConversationFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (!getUserVisibleHint())
        return false;
    final ContextMenu.ContextMenuInfo menuInfo = item.getMenuInfo();
    final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo = (ExtendedRecyclerView.ContextMenuInfo) menuInfo;
    ParcelableDirectMessage message = mAdapter.getDirectMessage(contextMenuInfo.getPosition());
    if (message == null)
        return false;
    switch (item.getItemId()) {
    case R.id.copy: {
        ClipboardUtils.setText(getContext(), message.text_plain);
        return true;
    }/*from   w  w w .j av a  2s  .  c o  m*/
    case R.id.delete: {
        Bundle args = new Bundle();
        args.putParcelable(EXTRA_ACCOUNT, mAccount);
        args.putParcelable(EXTRA_MESSAGE, message);
        DeleteMessageConfirmDialogFragment df = new DeleteMessageConfirmDialogFragment();
        df.setArguments(args);
        df.show(getFragmentManager(), "delete_message_confirm");
        return true;
    }
    }
    return false;
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * Handle activity menu//  w w  w. j  a  v  a 2  s . c  o m
 */
@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    final long waypointId = waypointsArrayAdapter.getItem((int) info.id).getId();

    Cursor tmpCursor;
    String sql;

    switch (item.getItemId()) {

    case 0:

        // update waypoint in db
        updateWaypoint(waypointId);

        return true;

    case 1:

        deleteWaypoint(waypointId);

        return true;

    case 2:

        // email waypoint data using default email client

        String elevationUnit = app.getPreferences().getString("elevation_units", "m");
        String elevationUnitLocalized = Utils.getLocalizedElevationUnit(this, elevationUnit);

        sql = "SELECT * FROM waypoints WHERE _id=" + waypointId + ";";
        tmpCursor = app.getDatabase().rawQuery(sql, null);
        tmpCursor.moveToFirst();

        double lat1 = tmpCursor.getDouble(tmpCursor.getColumnIndex("lat")) / 1E6;
        double lng1 = tmpCursor.getDouble(tmpCursor.getColumnIndex("lng")) / 1E6;

        String messageBody = getString(R.string.title) + ": "
                + tmpCursor.getString(tmpCursor.getColumnIndex("title")) + "\n\n" + getString(R.string.lat)
                + ": " + Utils.formatLat(lat1, 0) + "\n" + getString(R.string.lng) + ": "
                + Utils.formatLng(lng1, 0) + "\n" + getString(R.string.elevation) + ": "
                + Utils.formatElevation(tmpCursor.getFloat(tmpCursor.getColumnIndex("elevation")),
                        elevationUnit)
                + elevationUnitLocalized + "\n\n" + "http://maps.google.com/?ll=" + lat1 + "," + lng1 + "&z=10";

        tmpCursor.close();

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                getResources().getString(R.string.email_subject_waypoint));
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageBody);

        this.startActivity(Intent.createChooser(emailIntent, getString(R.string.sending_email)));

        return true;

    case 3:

        this.showOnMap(waypointId);

        return true;

    case 4:

        // TODO: use a thread for online sync

        // sync one waypoint data with remote server

        // create temp waypoint from current record
        Waypoint wp = Waypoints.get(app.getDatabase(), waypointId);

        try {

            // preparing query string for calling web service
            String lat = Location.convert(wp.getLocation().getLatitude(), 0);
            String lng = Location.convert(wp.getLocation().getLongitude(), 0);
            String title = URLEncoder.encode(wp.getTitle());

            String userName = app.getPreferences().getString("user_name", "");
            String userPassword = app.getPreferences().getString("user_password", "");
            String sessionValue = userName + "@" + Utils.md5("aripuca_session" + userPassword);

            if (userName.equals("") || userPassword.equals("")) {
                Toast.makeText(WaypointsListActivity.this, R.string.username_or_password_required,
                        Toast.LENGTH_SHORT).show();
                return false;
            }

            String queryString = "?do=ajax_map_handler&aripuca_session=" + sessionValue
                    + "&action=add_point&lat=" + lat + "&lng=" + lng + "&z=16&n=" + title + "&d=AndroidSync";

            // http connection
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpGet httpGet = new HttpGet(
                    app.getPreferences().getString("online_sync_url", "http://tracker.aripuca.com")
                            + queryString);
            HttpResponse response = httpClient.execute(httpGet, localContext);

            ByteArrayOutputStream outstream = new ByteArrayOutputStream();
            response.getEntity().writeTo(outstream);

            // parsing JSON return
            JSONObject jsonObject = new JSONObject(outstream.toString());

            Toast.makeText(WaypointsListActivity.this, jsonObject.getString("message").toString(),
                    Toast.LENGTH_SHORT).show();

        } catch (ClientProtocolException e) {
            Toast.makeText(WaypointsListActivity.this, "ClientProtocolException: " + e.getMessage(),
                    Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            Toast.makeText(WaypointsListActivity.this, "IOException " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        } catch (JSONException e) {
            Toast.makeText(WaypointsListActivity.this, "JSONException " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        }

        return true;

    default:
        return super.onContextItemSelected(item);
    }

}

From source file:com.markuspage.android.atimetracker.Tasks.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    selectedTask = (Task) adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case SHOW_TIMES:
        Intent intent = new Intent(this, TaskTimes.class);
        intent.putExtra(TASK_ID, selectedTask.getId());
        if (adapter.currentRangeStart != -1) {
            intent.putExtra(START, adapter.currentRangeStart);
            intent.putExtra(END, adapter.currentRangeEnd);
        }// w  w  w .  j  a v a  2 s. c o  m
        startActivity(intent);
        break;
    default:
        showDialog(item.getItemId());
        break;
    }
    return super.onContextItemSelected(item);
}

From source file:cm.aptoide.pt.ManageRepos.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    TextView selectedView = (TextView) ((View) (info.targetView)).findViewById(R.id.uri);
    final String repo_selected = selectedView.getText().toString();
    popupOptions popupOption = popupOptions.values()[item.getItemId()];
    switch (popupOption) {
    case EDIT_REPO:
        validateRepo(repo_selected, true);
        refreshReposList();/*  ww  w . j  a v  a  2 s  .  c om*/
        break;

    case REMOVE_REPO:
        AlertDialog.Builder builder = new AlertDialog.Builder(theme);
        builder.setTitle(getString(R.string.remove_repo));
        builder.setIcon(R.drawable.ic_menu_close_clear_cancel);
        builder.setMessage(getString(R.string.remove_repo_confirm) + " " + repo_selected + " ?");
        builder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                removeDisplayRepo(repo_selected.hashCode());
                alert3.dismiss();
                refreshReposList();
            }
        });
        builder.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                alert3.dismiss();
                return;
            }
        });
        alert3 = builder.create();
        alert3.show();

        break;

    default:
        break;
    }

    return super.onContextItemSelected(item);
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.DisplayStopDataFragment.java

/**
 * {@inheritDoc}/*  w  w  w  . j a va  2 s . c o  m*/
 */
@Override
public boolean onContextItemSelected(final MenuItem item) {
    // Cast the information parameter.
    final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
    case R.id.displaystopdata_context_menu_addarrivalalert:
        // Get the position where this data lives.
        final int position = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        if (listAdapter != null) {
            final HashMap<String, String> groupData = (HashMap<String, String>) listAdapter.getGroup(position);
            // Fire off the Activity.
            callbacks.onShowAddTimeAlert(stopCode, new String[] { groupData.get(SERVICE_NAME_KEY) });
        }
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}