List of usage examples for android.widget PopupMenu getMenuInflater
public MenuInflater getMenuInflater()
From source file:org.catnut.adapter.TweetAdapter.java
private void showPopupMenu(View view) { final Bean bean = (Bean) view.getTag(); PopupMenu popup = new PopupMenu(mContext, view); Menu menu = popup.getMenu();/* w w w . ja v a2s . com*/ popup.getMenuInflater().inflate(R.menu.tweet_overflow, menu); MenuItem item = menu.findItem(R.id.action_favorite); item.setTitle(bean.favorited ? R.string.cancle_favorite : R.string.favorite); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_favorite: mRequestQueue.add(new CatnutRequest(mContext, bean.favorited ? FavoritesAPI.destroy(bean.id) : FavoritesAPI.create(bean.id), new StatusProcessor.FavoriteTweetProcessor(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(mContext, bean.favorited ? R.string.cancle_favorite_success : R.string.favorite_success, Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error); Toast.makeText(mContext, weiboAPIError.error, Toast.LENGTH_LONG).show(); } })); break; case R.id.action_like: Toast.makeText(mContext, "sina not provide this option...", Toast.LENGTH_SHORT).show(); break; case android.R.id.copy: CatnutUtils.copy2ClipBoard(mContext, mContext.getString(R.string.tweet), bean.text, mContext.getString(R.string.tweet_text_copied)); break; default: break; } return false; } }); popup.show(); }
From source file:im.vector.fragments.GroupsFragment.java
@SuppressLint("NewApi") private void displayGroupPopupMenu(final Group group, final View actionView) { final Context context = getActivity(); final PopupMenu popup; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { popup = new PopupMenu(context, actionView, Gravity.END); } else {//w w w.j av a 2 s . co m popup = new PopupMenu(context, actionView); } popup.getMenuInflater().inflate(R.menu.vector_home_group_settings, popup.getMenu()); CommonActivityUtils.tintMenuIcons(popup.getMenu(), ThemeUtils.getColor(context, R.attr.settings_icon_tint_color)); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.ic_action_select_remove_group: { leaveOrReject(group.getGroupId()); break; } } return false; } }); // force to display the icon try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { Log.e(LOG_TAG, "## displayGroupPopupMenu() : failed " + e.getMessage()); } popup.show(); }
From source file:com.notalenthack.blaster.CommandActivity.java
@Override public void onClick(View v) { Integer position = (Integer) v.getTag(); if (v.getId() == R.id.btnEditCommand) { final Command cmd = mListAdapter.getCommand(position); Log.d(TAG, "Edit button click for position " + position); //Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(this, v); //Inflating the Popup using xml file popup.getMenuInflater().inflate(R.menu.edit_delete, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from w ww . ja v a2s . c o m public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.edit) { editCommand(cmd); } else if (item.getItemId() == R.id.delete) { mListAdapter.deleteCommand(cmd); } else { return false; } saveCommands(); // update commands in pref for presistent mListAdapter.notifyDataSetChanged(); return true; } }); // show the popup popup.show(); } else if (v.getId() == R.id.btnCommandAction) { Log.d(TAG, "Play button click for position " + position); handlePlayCommand(position); } }
From source file:com.zigvine.zagriculture.UIActivity.java
@TargetApi(11) private void showPopupMenu() { final PopupMenu popupMenu = new PopupMenu(this, mOverflowMenuButton); final Menu menu = popupMenu.getMenu(); // popupMenu.inflate(R.menu.main_menu); popupMenu.getMenuInflater().inflate(R.menu.main_menu, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*from w w w .ja v a 2 s. co m*/ public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); onPrepareOptionsMenu(menu); if (popupMenu != null) { popupMenu.show(); } }
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;/*from ww w. ja va2s .c o m*/ 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:org.rm3l.ddwrt.tiles.status.wireless.WirelessClientsTile.java
/** * Called when a previously created loader has finished its load. Note * that normally an application is <em>not</em> allowed to commit fragment * transactions while in this call, since it can happen after an * activity's state is saved. See {@link android.support.v4.app.FragmentManager#beginTransaction() * FragmentManager.openTransaction()} for further discussion on this. * <p/>/*from w w w .ja va 2 s . co m*/ * <p>This function is guaranteed to be called prior to the release of * the last data that was supplied for this Loader. At this point * you should remove all use of the old data (since it will be released * soon), but should not do your own release of the data since its Loader * owns it and will take care of that. The Loader will take care of * management of its data so you don't have to. In particular: * <p/> * <ul> * <li> <p>The Loader will monitor for changes to the data, and report * them to you through new calls here. You should not monitor the * data yourself. For example, if the data is a {@link android.database.Cursor} * and you place it in a {@link android.widget.CursorAdapter}, use * the {@link android.widget.CursorAdapter#CursorAdapter(android.content.Context, * android.database.Cursor, int)} constructor <em>without</em> passing * in either {@link android.widget.CursorAdapter#FLAG_AUTO_REQUERY} * or {@link android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER} * (that is, use 0 for the flags argument). This prevents the CursorAdapter * from doing its own observing of the Cursor, which is not needed since * when a change happens you will get a new Cursor throw another call * here. * <li> The Loader will release the data once it knows the application * is no longer using it. For example, if the data is * a {@link android.database.Cursor} from a {@link android.content.CursorLoader}, * you should not call close() on it yourself. If the Cursor is being placed in a * {@link android.widget.CursorAdapter}, you should use the * {@link android.widget.CursorAdapter#swapCursor(android.database.Cursor)} * method so that the old Cursor is not closed. * </ul> * * @param loader The Loader that has finished. * @param data The data generated by the Loader. */ @Override public void onLoadFinished(Loader<ClientDevices> loader, ClientDevices data) { Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data); layout.findViewById(R.id.tile_status_wireless_clients_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_wireless_clients_layout_list_container).setVisibility(View.VISIBLE); layout.findViewById(R.id.tile_status_wireless_clients_togglebutton_container).setVisibility(View.VISIBLE); if (data == null || (data.getDevices().isEmpty() && !(data.getException() instanceof DDWRTTileAutoRefreshNotAllowedException))) { data = new ClientDevices().setException(new DDWRTNoDataException("No Data!")); } @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_wireless_clients_error); @Nullable final Exception exception = data.getException(); if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); } final GridLayout clientsContainer = (GridLayout) this.layout .findViewById(R.id.tile_status_wireless_clients_layout_list_container); clientsContainer.removeAllViews(); clientsContainer.setBackgroundColor( mParentFragmentActivity.getResources().getColor(android.R.color.transparent)); final Set<Device> devices = data.getDevices(MAX_CLIENTS_TO_SHOW_IN_TILE); final int themeBackgroundColor = getThemeBackgroundColor(mParentFragmentActivity, mRouter.getUuid()); final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid()); for (final Device device : devices) { final CardView cardView = (CardView) mParentFragmentActivity.getLayoutInflater() .inflate(R.layout.tile_status_wireless_client, null); //Create Options Menu final ImageButton tileMenu = (ImageButton) cardView .findViewById(R.id.tile_status_wireless_client_device_menu); if (!isThemeLight) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); } cardView.setCardBackgroundColor(themeBackgroundColor); //Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners. cardView.setPreventCornerOverlap(true); //Add padding in API v21+ as well to have the same measurements with previous versions. cardView.setUseCompatPadding(true); final TextView deviceName = (TextView) cardView .findViewById(R.id.tile_status_wireless_client_device_name); final String name = device.getName(); deviceName.setText(name); final TextView deviceMac = (TextView) cardView .findViewById(R.id.tile_status_wireless_client_device_mac); final String macAddress = device.getMacAddress(); deviceMac.setText(macAddress); final TextView deviceIp = (TextView) cardView .findViewById(R.id.tile_status_wireless_client_device_ip); final String ipAddress = device.getIpAddress(); final boolean isThisDevice = (ipAddress != null && ipAddress.equals(mCurrentIpAddress)); deviceIp.setText(ipAddress); if (isThisDevice) { final View thisDevice = cardView.findViewById(R.id.tile_status_wireless_client_device_this); if (isThemeLight) { //Set text color to blue ((TextView) thisDevice) .setTextColor(mParentFragmentActivity.getResources().getColor(R.color.blue)); } thisDevice.setVisibility(View.VISIBLE); } cardView.setOnClickListener(new DeviceOnClickListener(device)); clientsContainer.addView(cardView); tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(new DeviceOnMenuItemClickListener(device)); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_status_wireless_client_options, menu); if (isThisDevice) { //WOL not needed as this is the current device menu.findItem(R.id.tile_status_wireless_client_wol).setEnabled(false); } popup.show(); } }); } final Button showMore = (Button) this.layout.findViewById(R.id.tile_status_wireless_clients_show_more); //Whether to display 'Show more' button if (data.getDevicesCount() > MAX_CLIENTS_TO_SHOW_IN_TILE) { showMore.setVisibility(View.VISIBLE); showMore.setOnClickListener(this); } else { showMore.setVisibility(View.GONE); } } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); } doneWithLoaderInstance(this, loader, R.id.tile_status_wireless_clients_togglebutton_title, R.id.tile_status_wireless_clients_togglebutton_separator); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java
private void bindSound(View view, Cursor cursor) { AppState appState = AppState.getInstance(); final View card = view; final View downloadFrame = view.findViewById(R.id.sound_download_frame); final TextView tv = (TextView) view.findViewById(R.id.grid_text); final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image); final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav); final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu); final String soundName = cursor .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME)); String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME)); final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC)); final boolean favorite = appState.favSounds.contains(soundName) || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1; final boolean widget = appState.widgetSounds.contains(soundName) || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1; final boolean downloaded = cursor .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0; new Handler().post(new Runnable() { @Override// w ww . j a v a2 s.c o m public void run() { ContentValues cv = new ContentValues(); File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg"); if (downloaded && !sndFile.exists()) { cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0); mContext.getContentResolver().update( Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null, null); } } }); final View.OnClickListener playSound = new View.OnClickListener() { @Override public void onClick(View v) { String category = mContext.getString(R.string.ana_cat_sound); String action = mContext.getString(R.string.ana_act_play); Bundle extras = new Bundle(); extras.putString(SoundFragment.SOUND_TO_PLAY, soundName); extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet()); Intent intent = new Intent(mContext, SoundService.class); intent.putExtras(extras); mContext.startService(intent); AnalyticsUtils.sendEvent(category, action, soundName); } }; final View.OnClickListener downloadSound = new View.OnClickListener() { @Override public void onClick(View v) { card.setOnClickListener(null); RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setInterpolator(new BounceInterpolator()); animation.setFillAfter(true); animation.setFillEnabled(true); animation.setDuration(1000); animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.RESTART); downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation); DownloadService.startActionDownloadSound(mContext, soundName, new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this)); } }; if (downloaded) { downloadFrame.setVisibility(View.GONE); downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation(); card.setOnClickListener(playSound); } else { downloadFrame.setAlpha(1); downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1); downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1); downloadFrame.setVisibility(View.VISIBLE); card.setOnClickListener(downloadSound); } menu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final ImageView menuIc = (ImageView) v; PopupMenu popup = new PopupMenu(mContext, menuIc); Menu menu = popup.getMenu(); popup.getMenuInflater().inflate(R.menu.sound_menu, menu); if (favorite) menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris"); if (widget) menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget"); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_sound_fav: SoundUtils.addRemoveFavorite(mContext, soundName); return true; case R.id.action_sound_wid: SoundUtils.addRemoveWidget(mContext, soundName); return true; /*case R.id.action_sound_add: return true;*/ case R.id.action_sound_ring: SoundUtils.addRingtone(mContext, soundName, description); return true; case R.id.action_sound_share: AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext), mContext.getString(R.string.ana_act_weblink), soundName); ClipboardManager clipboard = (ClipboardManager) mContext .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName); clipboard.setPrimaryClip(clip); Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show(); return true; case R.id.action_sound_delete: SoundUtils.delete(mContext, soundName); return true; default: return false; } } }); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark)); } }); menuIc.setColorFilter(mContext.getResources().getColor(R.color.black)); popup.show(); } }); tv.setText(description); siv.setTag(imgId); if (appState.favSounds.contains(soundName)) { star.setVisibility(View.VISIBLE); } else if (favorite) { star.setVisibility(View.VISIBLE); appState.favSounds.add(soundName); } else { star.setVisibility(View.INVISIBLE); } File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg"); Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_addChannel_youtube(final View anchor) { PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_addchannel_youtube, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//www.j a v a 2s . com public boolean onMenuItemClick(MenuItem item) { onOpt_addChannel_youtubeEditDiag(item); return true; } }); popup.show(); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_category(final View anchor) { PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_category, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from www . jav a2 s . c om public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.add: onOpt_category_add(anchor); break; case R.id.rename: onOpt_category_rename(anchor); break; case R.id.delete: onOpt_category_delete(anchor); break; default: eAssert(false); } return true; } }); popup.show(); }
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_moreMenu(final View anchor) { PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_more_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*from w w w .j a v a 2s.c om*/ public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.about: onOpt_moreMenu_about(anchor); break; case R.id.license: onOpt_moreMenu_license(anchor); break; case R.id.media_delete_all: onOpt_moreMenu_deleteAllDnFiles(anchor); break; case R.id.media_delete_used_all: onOpt_moreMenu_deleteAllUsedDnFiles(anchor); break; case R.id.feedback_opinion: onOpt_moreMenu_feedbackOpinion(anchor); break; case R.id.db_management: onOpt_moreMenu_dbManagement(anchor); break; default: eAssert(false); } return true; } }); popup.show(); }