List of usage examples for android.view MenuItem getMenuInfo
public ContextMenuInfo getMenuInfo();
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int rowId = (int) info.id; switch (item.getItemId()) { case Constants.SAVE_CONTEXT_ITEM: new SaveTask(true, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.UNSAVE_CONTEXT_ITEM: new SaveTask(false, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.HIDE_CONTEXT_ITEM: new HideTask(true, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.UNHIDE_CONTEXT_ITEM: new HideTask(false, getOpThingInfo(), mSettings, this).execute(); return true; case Constants.SHARE_CONTEXT_ITEM: Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, getOpThingInfo().getUrl()); try {//from w w w .jav a 2s .c o m startActivity(Intent.createChooser(intent, "Share Link")); } catch (android.content.ActivityNotFoundException ex) { } return true; case Constants.DIALOG_HIDE_COMMENT: hideComment(rowId); return true; case Constants.DIALOG_SHOW_COMMENT: showComment(rowId); return true; case Constants.DIALOG_GOTO_PARENT: int myIndent = mCommentsAdapter.getItem(rowId).getIndent(); int parentRowId; for (parentRowId = rowId - 1; parentRowId >= 0; parentRowId--) if (mCommentsAdapter.getItem(parentRowId).getIndent() < myIndent) break; getListView().setSelection(parentRowId); return true; case Constants.DIALOG_VIEW_PROFILE: Intent i = new Intent(this, ProfileActivity.class); i.setData(Util.createProfileUri(mCommentsAdapter.getItem(rowId).getAuthor())); startActivity(i); return true; case Constants.DIALOG_EDIT: mReplyTargetName = mCommentsAdapter.getItem(rowId).getName(); mEditTargetBody = mCommentsAdapter.getItem(rowId).getBody(); showDialog(Constants.DIALOG_EDIT); return true; case Constants.DIALOG_DELETE: mReplyTargetName = mCommentsAdapter.getItem(rowId).getName(); // It must be a comment, since the OP selftext is reached via options menu, not context menu mDeleteTargetKind = Constants.COMMENT_KIND; showDialog(Constants.DIALOG_DELETE); return true; case Constants.DIALOG_REPORT: mReportTargetName = mCommentsAdapter.getItem(rowId).getName(); showDialog(Constants.DIALOG_REPORT); return true; default: return super.onContextItemSelected(item); } }
From source file:com.oakesville.mythling.MediaActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getGroupId() == MEDIA_ACTIVITY_CONTEXT_MENU_GROUP_ID) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); if (item.getItemId() == LONG_CLICK_MENU_PLAY) { Item it = (Item) getListView().getItemAtPosition(info.position); playItem(it);/*from ww w . j av a2 s.c om*/ return true; } else if (item.getItemId() == LONG_CLICK_MENU_TRANSCODE) { Item it = (Item) getListView().getItemAtPosition(info.position); transcodeItem(it); return true; } else if (item.getItemId() == LONG_CLICK_MENU_DOWNLOAD) { Item it = (Item) getListView().getItemAtPosition(info.position); downloadItem(it); return true; } else if (item.getItemId() == LONG_CLICK_MENU_DELETE) { Recording rec = (Recording) getListView().getItemAtPosition(info.position); int size = getListables().size(); if (size == 1 || size == info.position + 1) setSelItemIndex(getSelItemIndex() - 1); deleteRecording(rec); return true; } } return false; }
From source file:org.uguess.android.sysinfo.ApplicationManager.java
@Override public boolean onContextItemSelected(MenuItem item) { int pos = ((AdapterContextMenuInfo) item.getMenuInfo()).position; if (pos >= 0 && pos < getListView().getCount()) { AppInfoHolder ai = (AppInfoHolder) getListView().getItemAtPosition(pos); if (item.getItemId() == MI_MANAGE) { handleAction(ai, ACTION_MANAGE); return true; } else if (item.getItemId() == MI_LAUNCH) { handleAction(ai, ACTION_LAUNCH); return true; } else if (item.getItemId() == MI_SEARCH) { handleAction(ai, ACTION_SEARCH); return true; } else if (item.getItemId() == MI_DETAILS) { handleAction(ai, ACTION_DETAILS); return true; }/*from w ww .j a va 2s . co m*/ } return false; }
From source file:com.shafiq.myfeedle.core.MyfeedleNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override//w ww .j a v a 2s . c o m protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); MyfeedleNotifications.this.getContentResolver().update( Notifications.getContentUri(MyfeedleNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } MyfeedleNotifications.this.finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); } return super.onContextItemSelected(item); // clear }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case DELETE_ID: AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Uri uri = Uri.parse(FlightsContentProvider.CONTENT_URI_FLIGHT + "/" + info.id); ContentValues values = new ContentValues(); values.put(GliderLogTables.F_SENT, "0"); values.put(GliderLogTables.F_ACK, "0"); values.put(GliderLogTables.F_DEL, "1"); String select = GliderLogTables.F_ID + "=?"; String selArgs[] = { "" + info.id }; getContentResolver().update(uri, values, select, selArgs); //Log.d(TAG, "TEST URI " + uri + " resp " + x + "Args " + selArgs[0]); // /getContentResolver().delete(uri, null, null); getLoaderManager().restartLoader(0, null, this); fillData();/*from w w w . ja va 2 s .co m*/ return true; } return super.onContextItemSelected(item); }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { EntryContextMenuInfo menuInfo;/* w ww . j a va 2s .co m*/ try { menuInfo = (EntryContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad menuInfo", e); return false; } switch (item.getItemId()) { case ContextMenuIds.COPY_TEXT: ClipboardUtils.copyText(this, menuInfo.getCopyLabel(), menuInfo.getCopyText(), true); return true; case ContextMenuIds.SET_DEFAULT: final Intent setIntent = ContactSaveService.createSetSuperPrimaryIntent(this, menuInfo.getId()); this.startService(setIntent); return true; case ContextMenuIds.CLEAR_DEFAULT: final Intent clearIntent = ContactSaveService.createClearPrimaryIntent(this, menuInfo.getId()); this.startService(clearIntent); return true; default: throw new IllegalArgumentException("Unknown menu option " + item.getItemId()); } }
From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId())); }/*from ww w. j a va 2 s. c o m*/ final AlertDialog.Builder builder = new AlertDialog.Builder(this); View v; ListViewHolder viewHolder; AdapterView.AdapterContextMenuInfo contextInfo; String app_name; final String package_name; switch (item.getItemId()) { case R.id.btnUncheckAll: builder.setTitle(R.string.dialog_confirm_title); builder.setMessage(getString(R.string.dialog_uncheck_message)); builder.setCancelable(false); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (lvPackages == null || lvPackages.getAdapter() == null || ((packageAdapter) lvPackages.getAdapter()).selected == null) { //something went wrong return; } ((packageAdapter) lvPackages.getAdapter()).selected.clear(); lvPackages.invalidateViews(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { //do nothing! } }); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.show(); return true; case R.id.btnSave: finish(); return true; case R.id.btnDonate: Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(Constants.DONATION_URL)); startActivity(i); return true; case R.id.btnSettings: Intent settings = new Intent(this, SettingsActivity.class); startActivity(settings); return true; case R.id.btnRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int position = contextInfo.position; long id = contextInfo.id; // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle(R.string.dialog_title_rename_notification); final EditText input = new EditText(this); input.setHint(app_name); builder.setView(input); builder.setPositiveButton(R.string.confirm, null); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); if (b != null) { b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //can't be nothing if (input.getText().length() > 0) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Adding rename for " + package_name + " to " + input.getText()); } JSONObject rename = new JSONObject(); try { rename.put("pkg", package_name); rename.put("to", input.getText()); arrayRenames.put(rename); } catch (JSONException e) { e.printStackTrace(); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); d.dismiss(); } else { input.setText(R.string.error_cant_be_blank); } } }); } } }); d.show(); return true; case R.id.btnRemoveRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null"); } //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle( getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?"); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length())); } JSONArray tmp = new JSONArray(); try { for (int i = 0; i < arrayRenames.length(); i++) { if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) { tmp.put(arrayRenames.getJSONObject(i)); } } } catch (JSONException e) { e.printStackTrace(); } arrayRenames = tmp; if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length())); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); builder.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:cm.aptoide.pt.MainActivity.java
@Override public boolean onContextItemSelected(final MenuItem item) { final ProgressDialog pd; switch (item.getItemId()) { case 0:/*from w ww. j a v a2s. c o m*/ pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); pd.setCancelable(false); new Thread(new Runnable() { private boolean result = false; @Override public void run() { try { result = service.deleteStore(db, ((AdapterContextMenuInfo) item.getMenuInfo()).id); } catch (Exception e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); if (result) { refreshAvailableList(false); installedLoader.forceLoad(); updatesLoader.forceLoad(); } else { Toast toast = Toast.makeText(mContext, mContext.getString(R.string.error_delete_store), Toast.LENGTH_SHORT); toast.show(); } } }); } } }).start(); break; case 1: pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); pd.setCancelable(false); new Thread(new Runnable() { @Override public void run() { try { service.parseServer(db, db.getServer(((AdapterContextMenuInfo) item.getMenuInfo()).id, false)); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); refreshAvailableList(false); } }); } } }).start(); break; } return super.onContextItemSelected(item); }