List of usage examples for android.view MenuItem getMenuInfo
public ContextMenuInfo getMenuInfo();
From source file:com.github.nutomic.pegasus.activities.AreaList.java
/** * Handle ActionBar item selections./* w w w . jav a2 s . c om*/ */ @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.profiles: startActivity(new Intent(this, ProfileList.class)); return true; case R.id.new_area: new UpdateTask() { @Override protected Long doInBackground(Void... arg0) { ContentValues cv = new ContentValues(); cv.put(AreaColumns.NAME, getResources().getString(R.string.arealist_new)); cv.put(AreaColumns.PROFILE_ID, Database.ROW_NONE); cv.put(AreaColumns.WIFI_ENABLED, true); cv.put(AreaColumns.BLUETOOTH_ENABLED, false); return Database.getInstance(AreaList.this).getWritableDatabase().insert(AreaColumns.TABLE_NAME, null, cv); } @Override protected void onPostExecute(Long result) { super.onPostExecute(result); renameArea(result, getAreaName((AdapterContextMenuInfo) item.getMenuInfo())); } }.execute((Void) null); return true; default: return super.onOptionsItemSelected(item); } }
From source file:sjizl.com.ChatActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int index = info.position; String textTocopy = ArrChatLines.get(index).getLaatstBericht(); switch (item.getItemId()) { case R.id.delete: // quoteResult.remove(info.position); // ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged(); Toast.makeText(getApplicationContext(), "delete almost implementated", Toast.LENGTH_SHORT).show(); return false; case R.id.copy: // quoteResult.remove(info.position); // ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("simple text", textTocopy); clipboard.setPrimaryClip(clip); } else {// w ww. j av a 2 s.c o m android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText(textTocopy); } //place your TextView's text in clipboard Toast.makeText(getApplicationContext(), "Item copied", Toast.LENGTH_SHORT).show(); return false; } return false; }
From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { // Declare... AdapterView.AdapterContextMenuInfo info; // Let's try to get some menu information via a try/catch try {//from w w w. j a v a2 s. com info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { e.printStackTrace(); return false; } try { // Let's get the item ForumPostData data = (ForumPostData) info.targetView.getTag(); // Divide & conquer if (item.getGroupId() == 0) { // REQUESTS switch (item.getItemId()) { case 0: startActivity( new Intent(context, ProfileActivity.class).putExtra("profile", data.getProfileData())); break; case 1: Toast.makeText(context, R.string.info_forum_quote_warning, Toast.LENGTH_SHORT).show(); textareaContent.setText( textareaContent.getText().insert( textareaContent.getSelectionStart(), Constants.BBCODE_TAG_QUOTE_IN.replace( "{number}", data.getPostId() + "" ).replace( "{username}", data.getProfileData().getUsername() ) ) ); selectedQuotes.put(data.getPostId(), (data.isCensored() ? getString(R.string.general_censored) : data.getContent())); break; case 2: generatePopupWithLinks(data.getContent()); break; case 3: startActivity( new Intent(context, ForumReportActivity.class).putExtra("postId", data.getPostId())); break; default: Toast.makeText(context, R.string.msg_unimplemented, Toast.LENGTH_SHORT).show(); break; } } } catch (Exception ex) { ex.printStackTrace(); return false; } return true; }
From source file:com.moonpi.tapunlock.MainActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { // Get pressed item information final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // If Rename Tag pressed if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) { // Create new EdiText and configure final EditText tagTitle = new EditText(this); tagTitle.setSingleLine(true);//from www . j a v a 2 s.c o m tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); // Set tagTitle maxLength int maxLength = 50; InputFilter[] array = new InputFilter[1]; array[0] = new InputFilter.LengthFilter(maxLength); tagTitle.setFilters(array); // Get tagName text into EditText try { assert info != null; tagTitle.setText(tags.getJSONObject(info.position).getString("tagName")); } catch (JSONException e) { e.printStackTrace(); } final LinearLayout l = new LinearLayout(this); l.setOrientation(LinearLayout.VERTICAL); l.addView(tagTitle); // Show rename dialog new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l) .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 'Rename' pressed, change tagName and store try { JSONObject newTagName = tags.getJSONObject(info.position); newTagName.put("tagName", tagTitle.getText()); tags.put(info.position, newTagName); adapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } writeToJSON(); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed, Toast.LENGTH_SHORT); toast.show(); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); } }).show(); tagTitle.requestFocus(); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); return true; } // If Delete Tag pressed else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) { // Construct dialog message String dialogMessage = ""; assert info != null; try { dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '" + tags.getJSONObject(info.position).getString("tagName") + "'?"; } catch (JSONException e) { e.printStackTrace(); dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2); } // Show delete dialog new AlertDialog.Builder(this).setMessage(dialogMessage) .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONArray newArray = new JSONArray(); // Copy contents to new array, without the deleted item for (int i = 0; i < tags.length(); i++) { if (i != info.position) { try { newArray.put(tags.get(i)); } catch (JSONException e) { e.printStackTrace(); } } } // Equal original array to new array tags = newArray; // Write to file try { settings.put("tags", tags); root.put("settings", settings); } catch (JSONException e) { e.printStackTrace(); } writeToJSON(); adapter.adapterData = tags; adapter.notifyDataSetChanged(); updateListViewHeight(listView); // If no tags, show 'Press + to add Tags' textView if (tags.length() == 0) noTags.setVisibility(View.VISIBLE); else noTags.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted, Toast.LENGTH_SHORT); toast.show(); } }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing, close dialog } }).show(); return true; } return super.onContextItemSelected(item); }
From source file:com.github.nutomic.pegasus.activities.ProfileList.java
/** * Handle ActionBar item selections.//from w w w . j av a 2 s . co m */ @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.new_item: new UpdateTask() { @Override protected Long doInBackground(Void... params) { // Insert new profile into database. ContentValues cv = new ContentValues(); cv.put(ProfileColumns.NAME, getResources().getString(R.string.profilelist_new)); cv.put(ProfileColumns.RINGTONE_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE); cv.put(ProfileColumns.NOTIFICATION_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE); cv.put(ProfileColumns.MEDIA_VOLUME, 10 - ProfileColumns.VOLUME_APPLY_FALSE); cv.put(ProfileColumns.ALARM_VOLUME, 5 - ProfileColumns.VOLUME_APPLY_FALSE); cv.put(ProfileColumns.RINGER_MODE, AudioManager.RINGER_MODE_NORMAL); return Database.getInstance(ProfileList.this).getWritableDatabase() .insert(ProfileColumns.TABLE_NAME, null, cv); } @Override protected void onPostExecute(Long result) { super.onPostExecute(result); renameProfile(result, getProfileName((AdapterContextMenuInfo) item.getMenuInfo())); } }.execute((Void) null); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (page != null) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); return page.onContextItemSelected(item, info.position, info.targetView); }/* w w w. j a v a 2 s .c om*/ return false; }
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); ThingInfo _item = mThreadsAdapter.getItem(info.position); switch (item.getItemId()) { case Constants.VIEW_SUBREDDIT_CONTEXT_ITEM: new MyDownloadThreadsTask(_item.getSubreddit()).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, _item.getUrl()); try {//from w w w .j a v a 2s . c o m startActivity(Intent.createChooser(intent, "Share Link")); } catch (android.content.ActivityNotFoundException ex) { if (Constants.LOGGING) Log.e(TAG, "Share Link", ex); } return true; case Constants.OPEN_IN_BROWSER_CONTEXT_ITEM: setLinkClicked(_item); Common.launchBrowser(this, _item.getUrl(), Util.createThreadUri(_item).toString(), false, true, true, mSettings.isSaveHistory()); return true; case Constants.SAVE_CONTEXT_ITEM: new SaveTask(true, _item, mSettings, getApplicationContext()).execute(); return true; case Constants.UNSAVE_CONTEXT_ITEM: new SaveTask(false, _item, mSettings, getApplicationContext()).execute(); return true; case Constants.HIDE_CONTEXT_ITEM: new MyHideTask(true, _item, mSettings, getApplicationContext()).execute(); return true; case Constants.UNHIDE_CONTEXT_ITEM: new MyHideTask(false, _item, mSettings, getApplicationContext()).execute(); case Constants.DIALOG_VIEW_PROFILE: Intent i = new Intent(this, ProfileActivity.class); i.setData(Util.createProfileUri(_item.getAuthor())); startActivity(i); return true; default: return super.onContextItemSelected(item); } }
From source file:org.brandroid.openmanager.fragments.ContentFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item == null) return false; OpenPath path = null;//from w ww . j a va 2 s. c om if (item.getMenuInfo() != null && item.getMenuInfo() instanceof OpenContextMenuInfo) path = ((OpenContextMenuInfo) item.getMenuInfo()).getPath(); else if (mMenuContextItemIndex >= 0 && mMenuContextItemIndex < getContentAdapter().getCount()) path = getContentAdapter().getItem(mMenuContextItemIndex); if (path == null) { Logger.LogWarning("Couldn't find path for context menu"); return false; } return executeMenu(item.getItemId(), null, path); }
From source file:net.phase.wallet.Currency.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.updateItem: updateWalletBalance(wallets[info.position], false, maxlength); return true; case R.id.removeItem: removeWallet(wallets[info.position].name); updateWalletList();/*from w ww .ja v a 2 s .c o m*/ return true; case R.id.pasteClipKeys: ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clip != null) { if (clip.getText() != null) { int added = 0; try { InputStream is = new ByteArrayInputStream(clip.getText().toString().getBytes()); BufferedReader br = new BufferedReader(new InputStreamReader(is)); added = wallets[info.position].addFromReader(br); } catch (IOException e) { } if (added > 0) { toastMessage("Added " + added + " key(s)"); updateWalletList(); } else { toastMessage("Found no new keys "); } } else { toastMessage("Nothing on clipboard"); } } else { toastMessage("Could not obtain clipboard"); } return true; case R.id.viewItem: if (wallets[info.position].transactions == null) { toastMessage("Please update wallet first"); } else { showTransactions(wallets[info.position]); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:in.shick.diode.threads.ThreadsListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); ThingInfo _item = mThreadsAdapter.getItem(info.position); switch (item.getItemId()) { case Constants.VIEW_SUBREDDIT_CONTEXT_ITEM: mObjectStates.mCurrentDownloadThreadsTask = new MyDownloadThreadsTask(_item.getSubreddit()); mObjectStates.mCurrentDownloadThreadsTask.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, _item.getUrl()); intent.putExtra(Intent.EXTRA_SUBJECT, _item.getTitle()); try {//from ww w.j a va 2 s . c o m startActivity(Intent.createChooser(intent, "Share Link")); } catch (android.content.ActivityNotFoundException ex) { if (Constants.LOGGING) Log.e(TAG, "Share Link", ex); } return true; case Constants.OPEN_IN_BROWSER_CONTEXT_ITEM: setLinkClicked(_item); Common.launchBrowser(this, _item.getUrl(), Util.createThreadUri(_item).toString(), false, true, true, mSettings.isSaveHistory()); return true; case Constants.SAVE_CONTEXT_ITEM: new SaveTask(true, _item, mSettings, getApplicationContext()).execute(); return true; case Constants.UNSAVE_CONTEXT_ITEM: new SaveTask(false, _item, mSettings, getApplicationContext()).execute(); return true; case Constants.HIDE_CONTEXT_ITEM: new MyHideTask(true, _item, mSettings, getApplicationContext()).execute(); return true; case Constants.UNHIDE_CONTEXT_ITEM: new MyHideTask(false, _item, mSettings, getApplicationContext()).execute(); case Constants.DIALOG_VIEW_PROFILE: assert (!_item.isDeletedUser()); Intent i = new Intent(this, ProfileActivity.class); i.setData(Util.createProfileUri(_item.getAuthor())); startActivity(i); return true; default: return super.onContextItemSelected(item); } }