android.widget.PopupMenu#setOnMenuItemClickListener ( )源码实例Demo

下面列出了android.widget.PopupMenu#setOnMenuItemClickListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: homeassist   文件: MainActivity.java
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();
}
 
源代码2 项目: Telegram   文件: FloatingActionMode.java
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);
}
 
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();
}
 
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();
    }
}
 
源代码5 项目: TimetableView   文件: NonViewActivity.java
/**
 * 显示弹出菜单
 */
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();
}
 
源代码6 项目: 1Rramp-Android   文件: DetailedActivity.java
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();
}
 
源代码7 项目: BotLibre   文件: BotScriptsActivity.java
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();
}
 
源代码8 项目: Ruisi   文件: PostActivity.java
@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;
    }
}
 
源代码9 项目: BotLibre   文件: ForumPostActivity.java
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();
}
 
源代码10 项目: BotLibre   文件: BrowseIssueActivity.java
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();
}
 
源代码11 项目: delion   文件: UpdatePasswordInfoBar.java
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();
}
 
源代码12 项目: LaunchEnr   文件: CustomActionsPopup.java
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;
}
 
源代码13 项目: BotLibre   文件: LiveChatActivity.java
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();
}
 
源代码14 项目: BotLibre   文件: ForumActivity.java
@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();
}
 
@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();
}
 
源代码16 项目: MyBookshelf   文件: MainActivity.java
/**
 * 显示分组菜单
 */
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);
}
 
源代码17 项目: BotLibre   文件: ViewUserActivity.java
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();
}
 
源代码18 项目: emerald-dialer   文件: DialerActivity.java
private void showPopupMenu(View view) {
	PopupMenu popup = new PopupMenu(this, view);
	popup.setOnMenuItemClickListener(this);
	popup.inflate(R.menu.dialer_options);
	popup.show();
}
 
源代码19 项目: jellyfin-androidtv   文件: KeyProcessor.java
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();
}
 
@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);
}