Java Code Examples for android.widget.PopupMenu#setOnMenuItemClickListener()

The following examples show how to use android.widget.PopupMenu#setOnMenuItemClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From homeassist with Apache License 2.0 8 votes vote down vote up
public void showSortOptions() {
    PopupMenu popup = new PopupMenu(this, ((BottomNavigationMenuView) mNavigation.getChildAt(0)).getChildAt(2));
    //Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.menu_sort, popup.getMenu());

    //registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            EntityFragment currentFragment = getCurrentEntityFragment();
            Group group = currentFragment.getGroup();
            if (group != null) {
                currentFragment.sortEntity(item.getOrder());
            }
            return true;
        }
    });

    popup.show();
}
 
Example 2
Source File: DetailedActivity.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
private void showPopup() {
  int menu_res_id = R.menu.popup_post;
  String currentLoggedInUser = HaprampPreferenceManager.getInstance().getCurrentSteemUsername();
  ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this, R.style.PopupMenuOverlapAnchor);
  PopupMenu popup = new PopupMenu(contextThemeWrapper, overflowBtn);
  //customize menu items
  //add Share
  popup.getMenu().add(PostMenu.Share);
  popup.getMenu().add(PostMenu.Repost);
  popup.getMenuInflater().inflate(menu_res_id, popup.getMenu());
  popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getTitle().equals(PostMenu.Share)) {
        ShareUtils.shareMixedContent(DetailedActivity.this, post);
        return true;
      } else if (item.getTitle().equals(PostMenu.Repost)) {
        showAlertDialogForRepost();
      }
      return false;
    }
  });
  popup.show();
}
 
Example 3
Source File: NonViewActivity.java    From TimetableView with MIT License 6 votes vote down vote up
/**
 * 显示弹出菜单
 */
public void showPopmenu() {
    PopupMenu popup = new PopupMenu(this, moreButton);
    popup.getMenuInflater().inflate(R.menu.popmenu_nonview, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.top1:
                    all();
                    break;
                case R.id.top2:
                    haveTime();
                    break;
                case R.id.top3:
                    haveTimeWithMonday();
                    break;
                default:
                    break;
            }
            return true;
        }
    });

    popup.show();
}
 
Example 4
Source File: FloatingActionMode.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public FloatingActionMode(Context context, ActionMode.Callback2 callback, View originatingView, FloatingToolbar floatingToolbar) {
    mContext = context;
    mCallback = callback;

    PopupMenu p = new PopupMenu(context, null);
    mMenu = p.getMenu();
    setType(ActionMode.TYPE_FLOATING);
    p.setOnMenuItemClickListener(menuItem -> mCallback.onActionItemClicked(FloatingActionMode.this, menuItem));
    mContentRect = new Rect();
    mContentRectOnScreen = new Rect();
    mPreviousContentRectOnScreen = new Rect();
    mViewPositionOnScreen = new int[2];
    mPreviousViewPositionOnScreen = new int[2];
    mRootViewPositionOnScreen = new int[2];
    mViewRectOnScreen = new Rect();
    mPreviousViewRectOnScreen = new Rect();
    mScreenRect = new Rect();
    mOriginatingView = originatingView;
    mOriginatingView.getLocationOnScreen(mViewPositionOnScreen);
    mBottomAllowance = AndroidUtilities.dp(20);
    mDisplaySize = new Point();
    setFloatingToolbar(floatingToolbar);
}
 
Example 5
Source File: ActivityGlobalAbstract.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void showMoreOptions(View view) {
    PopupMenu popupMenu = new PopupMenu(this, view, Gravity.BOTTOM);
    try {
        Field[] fields = popupMenu.getClass().getDeclaredFields();
        for (Field field : fields) {
            if ("mPopup".equals(field.getName())) {
                field.setAccessible(true);
                Object menuPopupHelper = field.get(popupMenu);
                Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
                Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
                setForceIcons.invoke(menuPopupHelper, true);
                break;
            }
        }
    } catch (Exception e) {
        Timber.e(e);
    }
    popupMenu.getMenuInflater().inflate(R.menu.home_menu, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(item -> {
        analyticsHelper.setEvent(SHOW_HELP, CLICK, SHOW_HELP);
        showTutorial(false);
        return false;
    });
    popupMenu.show();
}
 
Example 6
Source File: AlbumsRecyclerAdapter.java    From PainlessMusicPlayer with Apache License 2.0 6 votes vote down vote up
private void onMenuClick(@NonNull final View btnView, final int position) {
    final PopupMenu popup = new PopupMenu(btnView.getContext(), btnView);
    final Menu popupMenu = popup.getMenu();

    final MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.list_item_album, popupMenu);

    final long id = getItemId(position);
    final Cursor item = getCursor();

    if (item != null && item.moveToPosition(position)) {
        final String albumName = item.getString(AlbumsProviderKt.COLUMN_ALBUM);
        popup.setOnMenuItemClickListener(menuItem -> onMenuItemClick(menuItem, id, albumName));
        popup.show();
    }
}
 
Example 7
Source File: ViewUserActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void menu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_view_user, popup.getMenu());
    onPrepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    popup.show();
}
 
Example 8
Source File: MainActivity.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 显示分组菜单
 */
private void showBookGroupMenu(View view) {
    PopupMenu popupMenu = new PopupMenu(this, view);
    for (int j = 0; j < getResources().getStringArray(R.array.book_group_array).length; j++) {
        popupMenu.getMenu().add(0, 0, j, getResources().getStringArray(R.array.book_group_array)[j]);
    }
    popupMenu.setOnMenuItemClickListener(menuItem -> {
        upGroup(menuItem.getOrder());
        return true;
    });
    popupMenu.setOnDismissListener(popupMenu1 -> updateTabItemIcon(0, false));
    popupMenu.show();
    updateTabItemIcon(0, true);
}
 
Example 9
Source File: IncompleteCardsFragment.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
@Override
public void onCardPressed(final SubmissionCard card, final Submission submission) {
    PopupMenu popup = new PopupMenu(getActivity(), card.cardView);
    popup.getMenuInflater().inflate(R.menu.popup_incomplete_cards, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.action_open) {
                new ShowAnswerList(getActivity(), card, submission).execute();
            }
            else if (item.getItemId() == R.id.action_edit) {
                new ShowQuestionTab(getActivity(), card, submission).execute();
            }
            else if (item.getItemId() == R.id.action_discard) {
                new Alert(getActivity(), R.string.discard_submission, R.string.discard_submission_description) {
                    @Override
                    public void discard() {
                        submission.deleteAnswers();
                        submission.delete();
                        getListAdapter().refresh();
                        Toast.showLong(getActivity(), R.string.submission_discarded);
                    }
                }.showCancelDiscard(R.string.cancel, R.string.discard);
            }
            return true;
        }
    });
    popup.show();
}
 
Example 10
Source File: ForumActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void menu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_forum, popup.getMenu());
    onPrepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    popup.show();
}
 
Example 11
Source File: LiveChatActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void menu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
	MenuInflater inflater = popup.getMenuInflater();
	inflater.inflate(R.menu.menu_livechat, popup.getMenu());
	onPrepareOptionsMenu(popup.getMenu());
	popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
		@Override
		public boolean onMenuItemClick(MenuItem item) {
			return onOptionsItemSelected(item);
		}
	});
	popup.show();
}
 
Example 12
Source File: CustomActionsPopup.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public boolean show() {
    List<AccessibilityAction> actions = getActionList();
    if (actions.isEmpty()) {
        return false;
    }

    PopupMenu popup = new PopupMenu(mLauncher, mIcon);
    popup.setOnMenuItemClickListener(this);
    Menu menu = popup.getMenu();
    for (AccessibilityAction action : actions) {
        menu.add(Menu.NONE, action.getId(), Menu.NONE, action.getLabel());
    }
    popup.show();
    return true;
}
 
Example 13
Source File: UpdatePasswordInfoBar.java    From delion with Apache License 2.0 5 votes vote down vote up
private void onUsernameLinkClicked(View v) {
    PopupMenu popup = new PopupMenu(getContext(), v);
    for (int i = 0; i < mUsernames.length; ++i) {
        MenuItem item = popup.getMenu().add(Menu.NONE, i, i, mUsernames[i]);
    }
    popup.setOnMenuItemClickListener(this);
    popup.show();
}
 
Example 14
Source File: BrowseIssueActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void menu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.menu_browse_issue, popup.getMenu());
    onPrepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    popup.show();
}
 
Example 15
Source File: ForumPostActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void menu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
	MenuInflater inflater = popup.getMenuInflater();
	inflater.inflate(R.menu.menu_post, popup.getMenu());
	onPrepareOptionsMenu(popup.getMenu());
	popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
		@Override
		public boolean onMenuItemClick(MenuItem item) {
			return onOptionsItemSelected(item);
		}
	});
	popup.show();
}
 
Example 16
Source File: PostActivity.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
@Override
public void onListItemClick(View v, final int position) {
    switch (v.getId()) {
        case R.id.btn_reply_cz:
            if (isLogin()) {
                SingleArticleData single = datas.get(position);
                Intent i = new Intent(PostActivity.this, ReplyCzActivity.class);
                i.putExtra("islz", single.uid == datas.get(0).uid);
                i.putExtra("data", single);
                startActivityForResult(i, 20);
            }
            break;
        case R.id.need_loading_item:
            refresh();
            break;
        case R.id.btn_more:
            clickPosition = position;
            PopupMenu popup = new PopupMenu(this, v);
            popup.setOnMenuItemClickListener(this);
            MenuInflater inflater = popup.getMenuInflater();
            inflater.inflate(R.menu.menu_post_more, popup.getMenu());

            //判断是不是自己
            if (!datas.get(position).canManage
                    && (!App.isLogin(this)
                    || !App.getUid(this).equals(datas.get(position).uid))) {
                popup.getMenu().removeItem(R.id.tv_edit);
            }

            //如果有管理权限,则显示除了关闭之外的全部按钮
            if (!datas.get(position).canManage) {
                popup.getMenu().removeGroup(R.id.menu_manege);
            }

            popup.show();
            break;
        default:
            break;
    }
}
 
Example 17
Source File: BotScriptsActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void menu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
	MenuInflater inflater = popup.getMenuInflater();
	inflater.inflate(R.menu.menu_bot_scripts, popup.getMenu());
	popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

		@Override
		public boolean onMenuItemClick(MenuItem item) {
			return onOptionsItemSelected(item);
		}
	});
	popup.show();
}
 
Example 18
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    setShareIntent();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_reminder) {
        //open the schedule dialog
        final Calendar c = Calendar.getInstance();

        //fill the notificationCursor
        notificationCursor = DbAccess.getNotificationByNoteId(getBaseContext(), this.id);
        hasAlarm = notificationCursor.moveToFirst();
        if (hasAlarm) {
            notification_id = notificationCursor.getInt(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_ID));
        }

        if (hasAlarm) {
            //ask whether to delete or update the current alarm
            PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_reminder));
            popupMenu.inflate(R.menu.reminder);
            popupMenu.setOnMenuItemClickListener(this);
            popupMenu.show();
        } else {
            //create a new one
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog dpd = new DatePickerDialog(ChecklistNoteActivity.this, this, year, month, day);
            dpd.getDatePicker().setMinDate(c.getTimeInMillis());
            dpd.show();
        }
        return true;
    } else if (id == R.id.action_save) {
        if (ContextCompat.checkSelfPermission(ChecklistNoteActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(ChecklistNoteActivity.this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                // Show an expanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                ActivityCompat.requestPermissions(ChecklistNoteActivity.this,
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        REQUEST_CODE_EXTERNAL_STORAGE);
            } else {
                // No explanation needed, we can request the permission.
                ActivityCompat.requestPermissions(ChecklistNoteActivity.this,
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        REQUEST_CODE_EXTERNAL_STORAGE);
            }
        } else {
            saveToExternalStorage();
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 19
Source File: KeyProcessor.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
private static void createItemMenu(BaseRowItem rowItem, UserItemDataDto userData, BaseActivity activity) {
    BaseItemDto item = rowItem.getBaseItem();
    PopupMenu menu = Utils.createPopupMenu(activity, activity.getCurrentFocus(), Gravity.RIGHT);
    int order = 0;

    if (rowItem instanceof AudioQueueItem) {
        if (!(activity instanceof AudioNowPlayingActivity)) {
            menu.getMenu().add(0, MENU_GOTO_NOW_PLAYING, order++, R.string.lbl_goto_now_playing);
        }
        if (rowItem.getBaseItem() != MediaManager.getCurrentAudioItem()) {
            menu.getMenu().add(0, MENU_ADVANCE_QUEUE, order++, R.string.lbl_play_from_here);
        }
        // don't allow removal of last item - framework will crash trying to animate an empty row
        if (MediaManager.getCurrentAudioQueue().size() > 1) {
            menu.getMenu().add(0, MENU_REMOVE_FROM_QUEUE, order++, R.string.lbl_remove_from_queue);
        }
    } else {
        if (BaseItemUtils.canPlay(item)) {
            if (item.getIsFolderItem()
                    && item.getBaseItemType() != BaseItemType.MusicAlbum
                    && item.getBaseItemType() != BaseItemType.Playlist
                    && item.getBaseItemType() != BaseItemType.MusicArtist
                    && userData!= null
                    && userData.getUnplayedItemCount() !=null
                    && userData.getUnplayedItemCount() > 0) {
                menu.getMenu().add(0, MENU_PLAY_FIRST_UNWATCHED, order++, R.string.lbl_play_first_unwatched);
            }
            menu.getMenu().add(0, MENU_PLAY, order++, item.getIsFolderItem() ? R.string.lbl_play_all : R.string.lbl_play);
            if (item.getIsFolderItem()) {
                menu.getMenu().add(0, MENU_PLAY_SHUFFLE, order++, R.string.lbl_shuffle_all);
            }
        }

        isMusic = item.getBaseItemType() == BaseItemType.MusicAlbum
                || item.getBaseItemType() == BaseItemType.MusicArtist
                || item.getBaseItemType() == BaseItemType.Audio
                || (item.getBaseItemType() == BaseItemType.Playlist && "Audio".equals(item.getMediaType()));

        if (isMusic || !item.getIsFolderItem()) {
            menu.getMenu().add(0, MENU_ADD_QUEUE, order++, R.string.lbl_add_to_queue);
        }

        if (isMusic) {
            if (item.getBaseItemType() != BaseItemType.Playlist) {
                menu.getMenu().add(0, MENU_INSTANT_MIX, order++, R.string.lbl_instant_mix);
            }
        } else {
            if (userData != null && userData.getPlayed()) {
                menu.getMenu().add(0, MENU_UNMARK_PLAYED, order++, activity.getString(R.string.lbl_mark_unplayed));
            } else {
                menu.getMenu().add(0, MENU_MARK_PLAYED, order++, activity.getString(R.string.lbl_mark_played));
            }
        }
    }

    if (userData != null) {
        if (userData.getIsFavorite()) {
            menu.getMenu().add(0, MENU_UNMARK_FAVORITE, order++, activity.getString(R.string.lbl_remove_favorite));
        } else {
            menu.getMenu().add(0, MENU_MARK_FAVORITE, order++, activity.getString(R.string.lbl_add_favorite));
        }

        if (userData.getLikes() == null) {
            menu.getMenu().add(0, MENU_LIKE, order++, activity.getString(R.string.lbl_like));
            menu.getMenu().add(0, MENU_DISLIKE, order++, activity.getString(R.string.lbl_dislike));
        } else if (userData.getLikes()) {
            menu.getMenu().add(0, MENU_UNLIKE, order++, activity.getString(R.string.lbl_unlike));
            menu.getMenu().add(0, MENU_DISLIKE, order++, activity.getString(R.string.lbl_dislike));
        } else {
            menu.getMenu().add(0, MENU_LIKE, order++, activity.getString(R.string.lbl_like));
            menu.getMenu().add(0, MENU_UNDISLIKE, order++, activity.getString(R.string.lbl_remove_dislike));
        }
    }

    //Not sure I like this but I either duplicate processing with in-line events or do this and
    // use a single event handler
    mCurrentItem = item;
    mCurrentRowItemNdx = rowItem.getIndex();
    mCurrentItemId = item.getId();
    mCurrentActivity = activity;
    currentItemIsFolder = item.getIsFolderItem();

    menu.setOnMenuItemClickListener(menuItemClickListener);
    menu.show();
}
 
Example 20
Source File: DialerActivity.java    From emerald-dialer with GNU General Public License v3.0 4 votes vote down vote up
private void showPopupMenu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
	popup.setOnMenuItemClickListener(this);
	popup.inflate(R.menu.dialer_options);
	popup.show();
}