List of usage examples for android.widget PopupMenu setOnMenuItemClickListener
public void setOnMenuItemClickListener(OnMenuItemClickListener listener)
From source file:com.untappedkegg.rally.home.ActivityMain.java
public void onScheduleMenuClick(View v) { menuView = ((View) v.getParent().getParent()); final boolean isFinished = DbSchedule .isEventFinished(((TextView) menuView.findViewById(R.id.sched_id)).getText().toString()); final String date = ((TextView) menuView.findViewById(R.id.sched_date)).getText().toString(); PopupMenu popup = new PopupMenu(this, v); popup.inflate(R.menu.schedule);//from w w w . j av a 2 s .co m if (AppState.isNullOrEmpty(((TextView) menuView.findViewById(R.id.sched_website)).getText().toString())) { popup.getMenu().removeItem(R.id.menu_schedule_website); } if (!isFinished) { popup.getMenu().removeItem(R.id.menu_schedule_photos); } if (isFinished || "TBD".equalsIgnoreCase(date) || "CANCELLED".equalsIgnoreCase(date)) { popup.getMenu().removeItem(R.id.menu_schedule_add_to_cal); } popup.setOnMenuItemClickListener(this); popup.show(); }
From source file:org.alfresco.mobile.android.application.fragments.user.UserProfileFragment.java
private void display() { TextView tv = null;/* w w w . j a v a 2s .c o m*/ ImageView bIm = null; // HEADER tv = (TextView) viewById(R.id.name); tv.setText(person.getFullName()); // JOB TITLE tv = (TextView) viewById(R.id.jobTitle); if (person.getJobTitle() != null && !person.getJobTitle().isEmpty() && person.getCompany() != null && person.getCompany().getName() != null && !person.getCompany().getName().isEmpty()) { tv.setText(String.format(getString(R.string.work_at), person.getJobTitle(), person.getCompany().getName())); } else if (person.getJobTitle() != null) { tv.setText(person.getJobTitle()); } else { tv.setText(person.getCompany().getName()); } // Location tv = (TextView) viewById(R.id.location); tv.setText(person.getLocation()); // Summary displayOrHide(R.id.description, person.getSummary(), R.id.summary_group); // Email displayOrHide(R.id.email_value, person.getEmail(), R.id.email_group); // Telephone displayOrHide(R.id.telephone_value, person.getTelephoneNumber(), R.id.telephone_group); // Mobile displayOrHide(R.id.mobile_value, person.getMobileNumber(), R.id.mobile_group); if (person.getTelephoneNumber() != null || person.getMobileNumber() != null || person.getCompany().getTelephoneNumber() != null) { bIm = (ImageView) viewById(R.id.action_call); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), MODE_CALL); popup.setOnMenuItemClickListener(UserProfileFragment.this); popup.show(); } }); } else { hide(R.id.action_call); } // SKype if (person.getSkypeId() != null && !person.getSkypeId().isEmpty()) { displayGroup(); tv = (TextView) viewById(R.id.skypeId_value); tv.setText(person.getSkypeId()); bIm = (ImageView) viewById(R.id.action_skype); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), MODE_SKYPE); popup.setOnMenuItemClickListener(UserProfileFragment.this); popup.show(); } }); } else { hide(R.id.action_skype); hide(R.id.skypeId_group); } // IM if (person.getInstantMessageId() != null && !person.getInstantMessageId().isEmpty()) { displayGroup(); tv = (TextView) viewById(R.id.instantMessagingId_value); tv.setText(person.getInstantMessageId()); } else { hide(R.id.instantMessagingId_group); } // Google if (person.getGoogleId() != null && !person.getGoogleId().isEmpty()) { displayGroup(); tv = (TextView) viewById(R.id.googleId_value); tv.setText(person.getGoogleId()); bIm = (ImageView) viewById(R.id.action_im); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionStartIm(getActivity(), person.getGoogleId()); } }); } else { hide(R.id.action_im); hide(R.id.googleId_group); } if (!displayContactDetails) { hide(R.id.contactInfo_group); displayContactDetails = false; } // Company Company cp = person.getCompany(); displayCompanyOrHide(R.id.companyName_value, cp.getName(), R.id.companyName_group); displayCompanyOrHide(R.id.companyAdress1_value, cp.getAddress1(), R.id.companyAdress1_group); displayCompanyOrHide(R.id.companyAdress2_value, cp.getAddress2(), R.id.companyAdress2_group); displayCompanyOrHide(R.id.companyAdress3_value, cp.getAddress3(), R.id.companyAdress3_group); displayCompanyOrHide(R.id.companyPostcode_value, cp.getPostCode(), R.id.companyPostcode_group); displayCompanyOrHide(R.id.companyTelephone_value, cp.getTelephoneNumber(), R.id.companyTelephone_group); displayCompanyOrHide(R.id.companyFax_value, cp.getFaxNumber(), R.id.companyFax_group); displayCompanyOrHide(R.id.companyEmail_value, cp.getEmail(), R.id.companyEmail_group); // Add Contact bIm = (ImageView) viewById(R.id.action_addcontact); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionAddContact(getActivity(), person); } }); // Add Contact if (person.getEmail() != null || person.getCompany().getEmail() != null) { bIm = (ImageView) viewById(R.id.action_email); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), MODE_EMAIL); popup.setOnMenuItemClickListener(UserProfileFragment.this); popup.show(); } }); } else { hide(R.id.action_email); } // Geolocalisation if (person.getCompany().getFullAddress() != null) { displayGroup(); bIm = (ImageView) viewById(R.id.action_geolocation); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionGeolocalisation(getActivity(), person.getCompany().getFullAddress(), person.getCompany().getName()); } }); } else { hide(R.id.action_geolocation); } if (!displayCompanyDetails) { hide(R.id.company_group); } }
From source file:me.albertonicoletti.latex.activities.EditorActivity.java
/** * Initializes the symbols shortcut bar. *///from w w w. ja v a 2 s . c om private void initSymbols() { // It actually only initializes the "+" button, creating a popup menu final Button button = (Button) findViewById(R.id.maths_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Shows a popup menu PopupMenu popup = new PopupMenu(EditorActivity.this, button); popup.getMenuInflater().inflate(R.menu.menu_maths, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { // On symbol click insertSymbol(menuItem.getTitle().toString()); return false; } }); popup.show(); } }); }
From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java
private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener, final int trackType) { if (player == null) { return;//from w ww . j a v a 2 s . c o m } String[] tracks = player.getTracks(trackType); if (tracks == null) { return; } popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return (customActionClickListener != null && customActionClickListener.onMenuItemClick(item)) || onTrackItemClick(item, trackType); } }); Menu menu = popup.getMenu(); // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0) menu.add(MENU_GROUP_TRACKS, DemoPlayer.DISABLED_TRACK + ID_OFFSET, Menu.NONE, R.string.off); if (tracks.length == 1 && TextUtils.isEmpty(tracks[0])) { menu.add(MENU_GROUP_TRACKS, DemoPlayer.PRIMARY_TRACK + ID_OFFSET, Menu.NONE, R.string.on); } else { for (int i = 0; i < tracks.length; i++) { menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, tracks[i]); } } menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true); menu.findItem(player.getSelectedTrackIndex(trackType) + ID_OFFSET).setChecked(true); }
From source file:com.syncedsynapse.kore2.ui.NowPlayingFragment.java
@OnClick(R.id.overflow) public void onOverflowClicked(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); popup.inflate(R.menu.video_overflow); popup.setOnMenuItemClickListener(overflowMenuClickListener); popup.show();/*from w w w . j av a 2 s .c om*/ }
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 w w . ja v a 2 s . co 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:tk.eatheat.omnisnitch.ui.SwitchLayout.java
private void handleLongPress(final TaskDescription ad, View view) { final PopupMenu popup = new PopupMenu(mContext, view); mPopup = popup;/* w ww .ja v a2s .c o m*/ popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.recent_remove_item) { mRecentsManager.killTask(ad); } else if (item.getItemId() == R.id.recent_inspect_item) { startApplicationDetailsActivity(ad.getPackageName()); } else { return false; } return true; } }); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopup = null; } }); popup.show(); }
From source file:freed.viewer.gridview.GridViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); this.mImageThumbSize = getResources().getDimensionPixelSize(dimen.image_thumbnail_size); viewerActivityInterface = (ActivityInterface) getActivity(); executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1); ImageButton gobackButton = (ImageButton) view.findViewById(id.button_goback); gobackButton.setOnClickListener(onGobBackClick); filetypeButton = (Button) view.findViewById(id.button_filetype); filetypeButton.setOnClickListener(new OnClickListener() { @Override/*from w w w . j a va 2 s . co m*/ public void onClick(View v) { showFileSelectionPopup(v); } }); filesSelected = (TextView) view.findViewById(id.textView_filesSelected); optionsButton = (Button) view.findViewById(id.button_options); optionsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getContext(), v); popup.getMenu().add(0, 0, 0, "Delete File"); if (!isRootDir && VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN_MR2) popup.getMenu().add(0, 1, 1, "StackJpeg"); if (!isRootDir) popup.getMenu().add(0, 2, 2, "Raw to Dng"); if (!isRootDir) popup.getMenu().add(0, 3, 3, "DngStack"); popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case 0: onDeltedButtonClick.onClick(null); break; case 1: onStackClick.onClick(null); break; case 2: onRawToDngClick.onClick(null); break; case 3: onDngStackClick.onClick(null); } return false; } }); popup.show(); } }); doActionButton = (Button) view.findViewById(id.button_DoAction); doActionButton.setVisibility(View.GONE); firstload(); return view; }
From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java
public void showVerboseLogPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu();/*from w w w .ja va2s . c o m*/ menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal); menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose); menu.setGroupCheckable(Menu.NONE, true, true); menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true); popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == 0) { VerboseLogUtil.setEnableAllTags(false); } else { VerboseLogUtil.setEnableAllTags(true); } return true; } }); popup.show(); }
From source file:com.custom.music.MusicBrowserActivity.java
/** * M: Create fake menu./*from w w w . ja v a 2 s. c o m*/ */ private void createFakeMenu() { if (mHasMenukey) { Log.w(TAG, "<createFakeMenu> Quit when there has Menu Key", Log.APP); return; } if (mOrientaiton == Configuration.ORIENTATION_LANDSCAPE) { mOverflowMenuButtonId = R.id.overflow_menu; mOverflowMenuButton = findViewById(R.id.overflow_menu); } else { mOverflowMenuButtonId = R.id.overflow_menu_nowplaying; mOverflowMenuButton = findViewById(R.id.overflow_menu_nowplaying); View parent = (View) mOverflowMenuButton.getParent(); if (parent != null) { parent.setVisibility(View.VISIBLE); } } mOverflowMenuButton.setVisibility(View.VISIBLE); mOverflowMenuButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.i(TAG, "<createFakeMenu> onClick()", Log.APP); if (v.getId() == mOverflowMenuButtonId) { final PopupMenu popupMenu = new PopupMenu(MusicBrowserActivity.this, mOverflowMenuButton); mPopupMenu = popupMenu; final Menu menu = popupMenu.getMenu(); onCreateOptionsMenu(menu); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); popupMenu.setOnDismissListener(new OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopupMenuShowing = false; Log.i(TAG, "<createFakeMenu> onDismiss() called", Log.APP); return; } }); onPrepareOptionsMenu(menu); mPopupMenuShowing = true; if (popupMenu != null) { Log.i(TAG, "<createFakeMenu> popupMenu.show()", Log.APP); popupMenu.show(); } } } }); }