Example usage for android.view ContextMenu findItem

List of usage examples for android.view ContextMenu findItem

Introduction

In this page you can find the example usage for android.view ContextMenu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:eu.basicairdata.graziano.gpslogger.FragmentTracklist.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {

    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.card_menu, menu);

    final GPSApplication gpsApplication = GPSApplication.getInstance();

    //menu.setHeaderTitle("Track " + data.get(selectedtrackID).getName());
    //Log.w("myApp", "[#] FragmentTracklist.java - share + export");
    if (gpsApplication.getPrefExportGPX() || gpsApplication.getPrefExportKML()
            || gpsApplication.getPrefExportTXT()) {
        menu.findItem(R.id.cardmenu_export).setVisible(true); // menu export
        if ((gpsApplication.getShare() == -1) && gpsApplication.isContextMenuShareVisible())
            menu.findItem(R.id.cardmenu_share).setVisible(true); // menu share
    }//from   w ww .ja  v  a  2 s . com
    //Log.w("myApp", "[#] FragmentTracklist.java - view");
    if ((gpsApplication.getOpenInViewer() == -1) && gpsApplication.isContextMenuViewVisible()) { // menu view
        if (!gpsApplication.getViewInApp().equals(""))
            menu.findItem(R.id.cardmenu_view)
                    .setTitle(getResources().getString(R.string.card_menu_view, gpsApplication.getViewInApp()))
                    .setVisible(true);
        else
            menu.findItem(R.id.cardmenu_view).setVisible(true);
    }
    //Log.w("myApp", "[#] FragmentTracklist.java - delete");
    if (selectedtrackID == gpsApplication.getCurrentTrack().getId())
        menu.findItem(R.id.cardmenu_delete).setVisible(false);

    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        boolean shouldShowRationale = ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (!shouldShowRationale && gpsApplication.isStoragePermissionChecked()) {
            menu.findItem(R.id.cardmenu_share).setEnabled(false);
            menu.findItem(R.id.cardmenu_view).setEnabled(false);
            menu.findItem(R.id.cardmenu_export).setEnabled(false);
        }
    }
}

From source file:edu.mit.mobile.android.livingpostcards.CardMediaEditFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    switch (v.getId()) {
    case R.id.gallery: {
        getActivity().getMenuInflater().inflate(R.menu.context_card_media, menu);
        final Cursor c = mAdapter.getCursor();
        if (c == null) {
            return;
        }//w ww .j  a va 2s  .c  o m
        AdapterView.AdapterContextMenuInfo info;
        try {
            info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        } catch (final ClassCastException e) {
            Log.e(TAG, "bad menuInfo", e);
            return;
        }

        // the below is a special case due to a bug in the infinite gallery spinner.

        c.moveToPosition(info.position % mAdapter.getCount());

        final String myUserUri = Authenticator.getUserUri(getActivity());

        final boolean isEditable = Authorable.canEdit(myUserUri, c);

        menu.findItem(R.id.delete).setVisible(isEditable);

    }
        break;
    default:
        super.onCreateContextMenu(menu, v, menuInfo);
    }

}

From source file:hku.fyp14017.blencode.ui.fragment.LookFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);

    selectedLookData = adapter.getItem(selectedLookPosition);
    menu.setHeaderTitle(selectedLookData.getLookName());
    adapter.addCheckedItem(((AdapterContextMenuInfo) menuInfo).position);

    getSherlockActivity().getMenuInflater().inflate(hku.fyp14017.blencode.R.menu.context_menu_default, menu);
    menu.findItem(hku.fyp14017.blencode.R.id.context_menu_backpack).setVisible(false);
    menu.findItem(hku.fyp14017.blencode.R.id.context_menu_unpacking).setVisible(false);
}

From source file:com.gsma.rcs.ri.messaging.GroupTalkView.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_gchat_item, menu);
    menu.findItem(R.id.menu_display_content).setVisible(false);
    menu.findItem(R.id.menu_listen_content).setVisible(false);
    /* Get the list item position. */
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    Cursor cursor = (Cursor) mAdapter.getItem(info.position);
    int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID));
    Direction direction = Direction.valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(Message.DIRECTION)));
    if (FileTransferLog.HISTORYLOG_MEMBER_ID == providerId) {
        String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.MIME_TYPE));
        if (Utils.isImageType(mimeType)) {
            if (Direction.OUTGOING == direction) {
                menu.findItem(R.id.menu_display_content).setVisible(true);

            } else {
                Long transferred = cursor.getLong(cursor.getColumnIndexOrThrow(HistoryLog.TRANSFERRED));
                Long size = cursor.getLong(cursor.getColumnIndexOrThrow(HistoryLog.FILESIZE));
                if (size.equals(transferred)) {
                    menu.findItem(R.id.menu_display_content).setVisible(true);
                }/*from   ww  w.j a va  2  s. c o  m*/
            }
        } else if (Utils.isAudioType(mimeType)) {
            if (Direction.OUTGOING == direction) {
                menu.findItem(R.id.menu_listen_content).setVisible(true);

            } else {
                Long transferred = cursor.getLong(cursor.getColumnIndexOrThrow(HistoryLog.TRANSFERRED));
                Long size = cursor.getLong(cursor.getColumnIndexOrThrow(HistoryLog.FILESIZE));
                if (size.equals(transferred)) {
                    menu.findItem(R.id.menu_listen_content).setVisible(true);
                }
            }
        }
    }
    if (Direction.OUTGOING != direction) {
        menu.findItem(R.id.menu_view_group_delivery).setVisible(false);
    }
}

From source file:uk.org.ngo.squeezer.NowPlayingFragment.java

/**
 * Builds a context menu suitable for the currently playing song.
 * <p>// www. jav  a2s .co m
 * Takes the general song context menu, and disables items that make no sense for the song that
 * is currently playing.
 * <p>
 * {@inheritDoc}
 *
 * @param menu
 * @param v
 * @param menuInfo
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.songcontextmenu, menu);

    menu.findItem(R.id.play_now).setVisible(false);
    menu.findItem(R.id.play_next).setVisible(false);
    menu.findItem(R.id.add_to_playlist).setVisible(false);

    menu.findItem(R.id.view_this_album).setVisible(true);
    menu.findItem(R.id.view_albums_by_song).setVisible(true);
    menu.findItem(R.id.view_songs_by_artist).setVisible(true);
}

From source file:vn.cybersoft.obs.android.activities.PowerScheduleActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    // Inflate the menu from xml.
    getMenuInflater().inflate(R.menu.time_schedule_context_menu, menu);

    // Use the current item to create a custom view for the header.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor c = (Cursor) mScheduleList.getAdapter().getItem((int) info.position);
    final PowerSchedule schedule = new PowerSchedule(c);

    // Inflate the custom view and set each TextView's text.
    final View v = mInflater.inflate(R.layout.context_menu_header, null);
    TextView textView = (TextView) v.findViewById(R.id.header_time);
    textView.setText(getString(R.string.percentage, schedule.level));
    textView = (TextView) v.findViewById(R.id.header_mode);
    textView.setText(Utils.getString(this, OptimalMode.getMode(getContentResolver(), schedule.modeId).name,
            R.string.class));

    // Set the custom view on the menu.
    menu.setHeaderView(v);//from  w  w  w .  j a  v a 2 s .com
    // Change the text based on the state of the schedule.
    if (schedule.enabled) {
        menu.findItem(R.id.enable_schedule).setTitle(R.string.disable_schedule);
    }
}

From source file:com.dattasmoon.pebble.plugin.IgnorePreference.java

@Override
protected void onBindDialogView(View view) {

    btnAdd = (Button) view.findViewById(R.id.btnAdd);
    etMatch = (EditText) view.findViewById(R.id.etMatch);
    chkRawRegex = (CheckBox) view.findViewById(R.id.chkRawRegex);
    chkCaseInsensitive = (CheckBox) view.findViewById(R.id.chkCaseInsensitive);
    actvApplications = (AutoCompleteTextView) view.findViewById(R.id.actvApplications);

    spnApplications = (Spinner) view.findViewById(R.id.spnApplications);
    spnMode = (Spinner) view.findViewById(R.id.spnMode);
    lvIgnore = (ListView) view.findViewById(R.id.lvIgnore);
    lvIgnore.setAdapter(arrayAdapter);// w w w . j a va 2 s .com
    lvIgnore.setEmptyView(view.findViewById(android.R.id.empty));
    new LoadAppsTask().execute();

    lvIgnore.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
            AdapterView.AdapterContextMenuInfo contextInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
            int position = contextInfo.position;
            long id = contextInfo.id;
            // the child view who's info we're viewing (should be equal to v)
            final View v = contextInfo.targetView;
            MenuInflater inflater = new MenuInflater(getContext());
            inflater.inflate(R.menu.preference_ignore_context, menu);

            //we have to do this mess because DialogPreference doesn't allow for onMenuItemSelected or onOptionsItemSelected. Bleh
            menu.findItem(R.id.btnEdit).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final int arrayPosition = (Integer) v.getTag();
                    final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString();
                    JSONArray temp = new JSONArray();
                    for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) {
                        try {
                            JSONObject ignore = arrayAdapter.getJSONArray().getJSONObject(i);
                            if (i == arrayPosition) {
                                etMatch.setText(ignore.getString("match"));
                                chkRawRegex.setChecked(ignore.getBoolean("raw"));
                                chkCaseInsensitive.setChecked(ignore.optBoolean("insensitive", true));
                                String app = ignore.getString("app");
                                if (app == "-1") {
                                    actvApplications.setText(getContext().getString(R.string.ignore_any));
                                } else {
                                    actvApplications.setText(app);
                                }
                                boolean exclude = ignore.optBoolean("exclude", true);
                                if (exclude) {
                                    spnMode.setSelection(Constants.IgnoreMode.EXCLUDE.ordinal());
                                } else {
                                    spnMode.setSelection(Constants.IgnoreMode.INCLUDE.ordinal());
                                }
                                continue;
                            }

                            temp.put(ignore);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    arrayAdapter.setJSONArray(temp);

                    arrayAdapter.notifyDataSetChanged();
                    return true;
                }
            });
            menu.findItem(R.id.btnDelete).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());

                    final int arrayPosition = (Integer) v.getTag();
                    final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString();
                    builder.setMessage(getContext().getResources().getString(R.string.confirm_delete) + " '"
                            + text + "' ?")
                            .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    JSONArray temp = new JSONArray();
                                    for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) {
                                        if (i == arrayPosition) {
                                            continue;
                                        }
                                        try {
                                            temp.put(arrayAdapter.getJSONArray().getJSONObject(i));
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                    arrayAdapter.setJSONArray(temp);

                                    arrayAdapter.notifyDataSetChanged();
                                }
                            }).setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    // User cancelled the dialog
                                }
                            });
                    builder.create().show();
                    return true;
                }
            });
        }
    });
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            JSONObject item = new JSONObject();
            try {
                item.put("match", etMatch.getText().toString());
                item.put("raw", chkRawRegex.isChecked());
                item.put("insensitive", chkCaseInsensitive.isChecked());
                if (actvApplications.getText().toString()
                        .equalsIgnoreCase(getContext().getString(R.string.ignore_any))) {
                    item.put("app", "-1");
                } else {
                    item.put("app", actvApplications.getText().toString());
                }
                if (spnMode.getSelectedItemPosition() == Constants.IgnoreMode.INCLUDE.ordinal()) {
                    item.put("exclude", false);
                } else {
                    item.put("exclude", true);
                }
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Item is: " + item.toString());
                }
                arrayAdapter.getJSONArray().put(item);
                etMatch.setText("");
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    });
    actvApplications.setText(getContext().getString(R.string.ignore_any));
    actvApplications.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actvApplications.showDropDown();
        }
    });
    actvApplications.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ApplicationInfo pkg = (ApplicationInfo) parent.getItemAtPosition(position);
            if (pkg == null) {
                actvApplications.setText(getContext().getString(R.string.ignore_any));
            } else {
                actvApplications.setText(pkg.packageName);
            }
        }
    });
    actvApplications.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                actvApplications.showDropDown();
            } else {
                if (actvApplications.getText().length() == 0) {
                    actvApplications.setText(getContext().getString(R.string.ignore_any));
                }
            }
        }
    });
    super.onBindDialogView(view);

}

From source file:org.catrobat.catroid.ui.fragment.LookFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);

    selectedLookData = adapter.getItem(selectedLookPosition);
    menu.setHeaderTitle(selectedLookData.getLookName());
    adapter.addCheckedItem(((AdapterContextMenuInfo) menuInfo).position);

    getSherlockActivity().getMenuInflater().inflate(R.menu.context_menu_default, menu);
    menu.findItem(R.id.context_menu_backpack).setVisible(false);
    menu.findItem(R.id.context_menu_unpacking).setVisible(false);
    menu.findItem(R.id.context_menu_move_up).setVisible(true);
    menu.findItem(R.id.context_menu_move_down).setVisible(true);
    menu.findItem(R.id.context_menu_move_to_top).setVisible(true);
    menu.findItem(R.id.context_menu_move_to_bottom).setVisible(true);

    menu.findItem(R.id.context_menu_move_down).setEnabled(selectedLookPosition != lookDataList.size() - 1);
    menu.findItem(R.id.context_menu_move_to_bottom).setEnabled(selectedLookPosition != lookDataList.size() - 1);

    menu.findItem(R.id.context_menu_move_up).setEnabled(selectedLookPosition != 0);
    menu.findItem(R.id.context_menu_move_to_top).setEnabled(selectedLookPosition != 0);
}

From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    spriteToEdit = spriteAdapter.getItem(info.position);
    spritePosition = info.position;// w  w w  .j  av a 2s  .  c om
    spriteAdapter.addCheckedSprite(info.position);

    if (ProjectManager.getInstance().getCurrentProject().getSpriteList().indexOf(spriteToEdit) == 0) {
        return;
    }

    menu.setHeaderTitle(spriteToEdit.getName());

    getSherlockActivity().getMenuInflater().inflate(R.menu.context_menu_default, menu);
    menu.findItem(R.id.context_menu_copy).setVisible(true);
    if (!BuildConfig.FEATURE_BACKPACK_ENABLED) {
        menu.findItem(R.id.context_menu_backpack).setVisible(false);
        menu.findItem(R.id.context_menu_unpacking).setVisible(false);
    }
    menu.findItem(R.id.context_menu_move_up).setVisible(true);
    menu.findItem(R.id.context_menu_move_down).setVisible(true);
    menu.findItem(R.id.context_menu_move_to_top).setVisible(true);
    menu.findItem(R.id.context_menu_move_to_bottom).setVisible(true);

    menu.findItem(R.id.context_menu_move_down).setEnabled(!(spritePosition == spriteList.size() - 1));
    menu.findItem(R.id.context_menu_move_to_bottom).setEnabled(!(spritePosition == spriteList.size() - 1));

    menu.findItem(R.id.context_menu_move_up).setEnabled(!(spritePosition == 1));
    menu.findItem(R.id.context_menu_move_to_top).setEnabled(!(spritePosition == 1));
}

From source file:edu.mit.mobile.android.locast.ver2.itineraries.ItineraryDetail.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {//www . j a v a 2 s  .c  o  m
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (final ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    // XXX the "- 1" below is due to having a header. I'm not sure where this is supposed to be handled.
    final Cursor c = (Cursor) mCastAdapter.getItem(info.position - 1);
    if (c == null) {
        return;
    }

    // load the base menus.
    final MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.cast_context, menu);
    menuInflater.inflate(R.menu.cast_options, menu);

    menu.setHeaderTitle(c.getString(c.getColumnIndex(Cast._TITLE)));

    final boolean canEdit = Cast.canEdit(this, c);
    menu.findItem(R.id.cast_edit).setVisible(canEdit);
    menu.findItem(R.id.cast_delete).setVisible(canEdit);

}