List of usage examples for android.widget PopupMenu PopupMenu
public PopupMenu(Context context, View anchor)
From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java
private void showPalettePopupMenu(View v) { PopupMenu popup = new PopupMenu(getContext(), v); popup.setOnMenuItemClickListener(this); popup.inflate(R.menu.palette);/*from w w w. j a v a 2s .c om*/ popup.show(); }
From source file:org.alfresco.mobile.android.application.fragments.sync.SyncCursorAdapter.java
protected void updateBottomText(TwoLinesProgressViewHolder vh, final Cursor cursor) { int status = cursor.getInt(SyncContentSchema.COLUMN_STATUS_ID); String nodeId = cursor.getString(SyncContentSchema.COLUMN_NODE_ID_ID); long favoriteId = cursor.getLong(SyncContentSchema.COLUMN_ID_ID); boolean syncRoot = cursor.getInt(SyncContentSchema.COLUMN_IS_SYNC_ROOT_ID) > 0; if (syncRoot) { vh.favoriteIcon.setVisibility(View.VISIBLE); vh.favoriteIcon.setImageResource(R.drawable.ic_sync_light); } else {//from w ww . jav a 2 s . c om vh.favoriteIcon.setVisibility(View.GONE); } vh.progress.setVisibility(View.GONE); switch (status) { case SyncContentStatus.STATUS_PENDING: displayStatut(vh, R.drawable.sync_status_pending); break; case SyncContentStatus.STATUS_RUNNING: displayStatut(vh, R.drawable.sync_status_loading); vh.progress.setVisibility(View.VISIBLE); vh.favoriteIcon.setVisibility(View.GONE); long totalSize = cursor.getLong(SyncContentSchema.COLUMN_TOTAL_SIZE_BYTES_ID); if (totalSize == -1) { vh.progress.setIndeterminate(true); } else { long progress = cursor.getLong(SyncContentSchema.COLUMN_BYTES_DOWNLOADED_SO_FAR_ID); float value = (((float) progress / ((float) totalSize)) * 100); int percentage = Math.round(value); vh.progress.setIndeterminate(false); vh.progress.setMax(100); vh.progress.setProgress(percentage); } break; case SyncContentStatus.STATUS_HIDDEN: vh.favoriteIcon.setVisibility(View.GONE); vh.iconRight.setVisibility(View.GONE); break; case SyncContentStatus.STATUS_PAUSED: displayStatut(vh, R.drawable.sync_status_pending); break; case SyncContentStatus.STATUS_MODIFIED: displayStatut(vh, R.drawable.sync_status_pending); break; case SyncContentStatus.STATUS_SUCCESSFUL: displayStatut(vh, R.drawable.sync_status_success); break; case SyncContentStatus.STATUS_FAILED: displayStatut(vh, R.drawable.sync_status_failed); break; case SyncContentStatus.STATUS_CANCEL: displayStatut(vh, R.drawable.sync_status_failed); break; case SyncContentStatus.STATUS_REQUEST_USER: displayStatut(vh, R.drawable.sync_status_failed); break; default: break; } if (selectedItems != null && selectedItems.contains(nodeId)) { UIUtils.setBackground(((View) vh.icon.getParent()), context.getResources().getDrawable(R.drawable.list_longpressed_holo)); } else { UIUtils.setBackground(((View) vh.icon.getParent()), null); } if (SyncContentStatus.STATUS_RUNNING != status) { vh.bottomText.setVisibility(View.VISIBLE); vh.bottomText.setText(createContentBottomText(context, cursor)); AccessibilityUtils.addContentDescription(vh.bottomText, createContentDescriptionBottomText(context, cursor)); } else { vh.bottomText.setVisibility(View.GONE); } if (mode == SyncFragment.MODE_LISTING && fragmentRef.get().getActivity() instanceof MainActivity) { if (status != SyncContentStatus.STATUS_REQUEST_USER) { UIUtils.setBackground(vh.choose, null); return; } vh.choose.setImageResource(R.drawable.ic_more_options); vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light); int d_16 = DisplayUtils.getPixels(context, R.dimen.d_16); vh.choose.setPadding(d_16, d_16, d_16, d_16); vh.choose.setVisibility(View.VISIBLE); vh.choose.setTag(R.id.node_action, nodeId); vh.choose.setTag(R.id.favorite_id, favoriteId); vh.choose.setTag(R.id.operation_status, status); vh.choose.setTag(R.id.is_synced, syncRoot); AccessibilityUtils.addContentDescription(vh.choose, String.format(context.getString(R.string.more_options_favorite), cursor.getString(SyncContentSchema.COLUMN_TITLE_ID))); vh.choose.setOnClickListener(new OnClickListener() { @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onClick(View v) { String item = (String) v.getTag(R.id.node_action); Integer statut = (Integer) v.getTag(R.id.operation_status); long favoriteId = (Long) v.getTag(R.id.favorite_id); boolean rootSynced = (Boolean) v.getTag(R.id.is_synced); selectedOptionItems.add(item); selectedOptionItemId.add(favoriteId); PopupMenu popup = new PopupMenu(context, v); getMenu(popup.getMenu(), statut, rootSynced); popup.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { selectedOptionItems.clear(); } }); popup.setOnMenuItemClickListener(SyncCursorAdapter.this); popup.show(); } }); } else { UIUtils.setBackground(vh.choose, null); } }
From source file:com.javielinux.fragments.MyActivityFragment.java
private void showMenuOptions(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { PopupMenu popupMenu = new PopupMenu(getActivity(), v); popupMenu.getMenuInflater().inflate(R.menu.my_activity_more_options, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from ww w . j ava 2s .c o m public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.popupmenu_more_options_size) { showSizeText(); } else if (item.getItemId() == R.id.popupmenu_more_options_theme) { showThemeDialog(); } else if (item.getItemId() == R.id.popupmenu_more_options_preferences) { Intent i = new Intent(getActivity(), Preferences.class); startActivity(i); } else if (item.getItemId() == R.id.popupmenu_more_options_exit) { showDialogExit(); } return true; } }); popupMenu.show(); } else { AlertDialogFragment frag = new AlertDialogFragment(); Bundle args = new Bundle(); args.putInt(AlertDialogFragment.KEY_ALERT_TITLE, R.string.actions); args.putBoolean(AlertDialogFragment.KEY_ALERT_HAS_POSITIVE_BUTTON, false); args.putBoolean(AlertDialogFragment.KEY_ALERT_CANCELABLE, false); args.putInt(AlertDialogFragment.KEY_ALERT_ARRAY_ITEMS, R.array.popupmenu_my_activity_more_options); frag.setArguments(args); frag.setAlertButtonListener(new AlertDialogFragment.AlertButtonListener() { @Override public void OnAlertButtonOk() { } @Override public void OnAlertButtonCancel() { } @Override public void OnAlertButtonNeutral() { } @Override public void OnAlertItems(int which) { if (which == 0) { showSizeText(); } else if (which == 1) { Intent i = new Intent(getActivity(), Preferences.class); startActivity(i); } else if (which == 2) { showThemeDialog(); } else if (which == 3) { showDialogExit(); } } }); frag.show(getFragmentManager(), "dialog"); } }
From source file:com.jwetherell.quick_response_code.EncoderActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.btnshare: OnClickShare(null);//from w w w .j av a2s .co m return true; case android.R.id.home: onBackPressed(); return true; case R.id.empty: Statistics.getInstance(EncoderActivity.this).click(); View menuItemView = findViewById(R.id.empty); PopupMenu popupMenu = new PopupMenu(this, menuItemView); popupMenu.inflate(R.menu.menu_contextual_wps); for (int i = 0; i < popupMenu.getMenu().size(); i++) { MenuItem itemMenu = popupMenu.getMenu().getItem(i); SpannableString spanString = new SpannableString( popupMenu.getMenu().getItem(i).getTitle().toString()); spanString.setSpan(new ForegroundColorSpan(Color.BLACK), 0, spanString.length(), 0); itemMenu.setTitle(spanString); } popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Statistics.getInstance(EncoderActivity.this).click(); // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.wps: Statistics.getInstance(EncoderActivity.this).sendStatistics(TAGS.TAG_31); Intent mIntent = new Intent(EncoderActivity.this, AVActivateWpsActivity.class); mIntent.putExtra("is_5ghz", getIntent().getBooleanExtra("is_5ghz", false)); startActivity(mIntent); break; default: break; } return false; } }); popupMenu.show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java
private void showResetPopupMenu(View v) { PopupMenu popup = new PopupMenu(getContext(), v); popup.setOnMenuItemClickListener(this); popup.inflate(R.menu.reset);//from ww w .j a va 2 s. co m popup.show(); }
From source file:com.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java
/** * Run during fragment initialization, this sets up the cover art popup menu and the coverArt * ImageView./* w w w. j a v a2s . c om*/ * * @param view The view to setup the coverArt ImageView in. * @return The resulting ImageView. */ private ImageView getCoverArt(final View view) { final ImageView coverArt = (ImageView) view.findViewById(R.id.albumCover); final PopupMenu coverMenu = new PopupMenu(mActivity, coverArt); final Menu menu = coverMenu.getMenu(); coverArt.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { scrollToNowPlaying(); } }); menu.add(Menu.NONE, POPUP_COVER_BLACKLIST, Menu.NONE, R.string.otherCover); menu.add(Menu.NONE, POPUP_COVER_SELECTIVE_CLEAN, Menu.NONE, R.string.resetCover); coverMenu.setOnMenuItemClickListener(this); coverArt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(final View v) { final boolean isConsumed; if (mCurrentSong != null) { menu.setGroupVisible(Menu.NONE, new AlbumInfo(mCurrentSong).isValid()); coverMenu.show(); isConsumed = true; } else { isConsumed = false; } return isConsumed; } }); return coverArt; }
From source file:org.akop.crosswords.fragment.CrosswordFragment.java
@Override public void onCellLongPressed(CrosswordView view, Crossword.Word word, int cell) { // Get the highlighted cell's rectangle Rect rect = view.getCellRect(word, cell); // Offset the placeholder to the same position as the cell FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(rect.width(), rect.height()); lp.setMargins(rect.left, rect.top, 0, 0); mMenuPlaceholder.setLayoutParams(lp); // Save the word/cell associated with the popup mPopupWord = word;// www . j ava 2 s .c om mPopupCell = cell; // Initialize and show the popup menu PopupMenu popup = new PopupMenu(getActivity(), mMenuPlaceholder); popup.setOnMenuItemClickListener(mCellPopupListener); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.fragment_crossword_popup_cell, popup.getMenu()); popup.show(); }
From source file:com.battlelancer.seriesguide.extensions.ExtensionsConfigurationFragment.java
private void showAddExtensionPopupMenu(View anchorView) { if (mAddExtensionPopupMenu != null) { mAddExtensionPopupMenu.dismiss(); }/*from www . j a v a2s .c o m*/ mAddExtensionPopupMenu = new PopupMenu(getActivity(), anchorView); for (int i = 0; i < mAvailableExtensions.size(); i++) { ExtensionManager.Extension extension = mAvailableExtensions.get(i); mAddExtensionPopupMenu.getMenu().add(Menu.NONE, i, Menu.NONE, extension.label); } mAddExtensionPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(android.view.MenuItem item) { // add to enabled extensions ExtensionManager.Extension extension = mAvailableExtensions.get(item.getItemId()); mEnabledExtensions.add(extension.componentName); // re-populate extension list getLoaderManager().restartLoader(ExtensionsConfigurationActivity.LOADER_ACTIONS_ID, null, mExtensionsLoaderCallbacks); // scroll to end of list mListView.smoothScrollToPosition(mAdapter.getCount() - 1); return true; } }); mAddExtensionPopupMenu.show(); }
From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java
@Override public void onPopupMenuClick(View v, final int seasonTvdbId, final int seasonNumber) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); popupMenu.inflate(R.menu.seasons_popup_menu); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// w w w .ja v a2 s.c om public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_action_seasons_watched_all: { onFlagSeasonWatched(seasonTvdbId, seasonNumber, true); fireTrackerEventContextMenu("Flag all watched"); return true; } case R.id.menu_action_seasons_watched_none: { onFlagSeasonWatched(seasonTvdbId, seasonNumber, false); fireTrackerEventContextMenu("Flag all unwatched"); return true; } case R.id.menu_action_seasons_collection_add: { onFlagSeasonCollected(seasonTvdbId, seasonNumber, true); fireTrackerEventContextMenu("Flag all collected"); return true; } case R.id.menu_action_seasons_collection_remove: { onFlagSeasonCollected(seasonTvdbId, seasonNumber, false); fireTrackerEventContextMenu("Flag all uncollected"); return true; } case R.id.menu_action_seasons_skip: { onFlagSeasonSkipped(seasonTvdbId, seasonNumber); fireTrackerEventContextMenu("Flag all skipped"); return true; } case R.id.menu_action_seasons_manage_lists: { ManageListsDialogFragment.showListsDialog(seasonTvdbId, ListItemTypes.SEASON, getFragmentManager()); fireTrackerEventContextMenu("Manage lists"); return true; } } return false; } }); popupMenu.show(); }
From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java
private void showViewMenu() { View menuView = findViewById(R.id.action_view); PopupMenu popup = new PopupMenu(menuView.getContext(), menuView); final List<IExperimentSensor> experimentRuns = getActiveSensors(); for (int i = 0; i < experimentRuns.size(); i++) { IExperimentSensor experiment = experimentRuns.get(i); MenuItem item = popup.getMenu().add(1, i, i, experiment.getClass().getSimpleName()); item.setCheckable(true);// w w w .j ava2 s . co m } popup.getMenu().setGroupCheckable(1, true, true); IExperimentSensor currentExperimentSensor = experiment.getCurrentExperimentSensor(); if (currentExperimentSensor != null) popup.getMenu().getItem(experimentRuns.indexOf(currentExperimentSensor)).setChecked(true); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int itemPosition = menuItem.getItemId(); IExperimentSensor experimentRun = experimentRuns.get(itemPosition); setCurrentSensor(experimentRun); pager.requestLayout(); pager.setCurrentItem(itemPosition, true); return true; } }); popup.show(); }