android.widget.PopupMenu Java Examples

The following examples show how to use android.widget.PopupMenu. 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 Project: Kore   Author: xbmc   File: TVShowEpisodeListFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(final View v) {
    final ViewHolder viewHolder = (ViewHolder)v.getTag();

    final PlaylistType.Item playListItem = new PlaylistType.Item();
    playListItem.episodeid = viewHolder.dataHolder.getId();

    final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
    popupMenu.getMenuInflater().inflate(R.menu.musiclist_item, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_play:
                    MediaPlayerUtils.play(TVShowEpisodeListFragment.this, playListItem);
                    return true;
                case R.id.action_queue:
                    MediaPlayerUtils.queue(TVShowEpisodeListFragment.this, playListItem, PlaylistType.GetPlaylistsReturnType.VIDEO);
                    return true;
            }
            return false;
        }
    });
    popupMenu.show();
}
 
Example #2
Source Project: a   Author: 804463258   File: SelectSourceDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void upGroupMenu() {

        List<String> groupList = BookSourceManager.getGroupList();
        if (groupList.size() == 0) {
            IbGroups.setVisibility(View.INVISIBLE);
        }else{
            IbGroups.setVisibility(View.VISIBLE);

            //创建弹出式菜单对象(最低版本11)
            popup = new PopupMenu(this.context, IbGroups);//第二个参数是绑定的那个view
            for (String groupName : new ArrayList<>(groupList)) {
                popup.getMenu().add(groupName);
            }

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {

                    searchView.setQuery(item.getTitle(), true);
                    return false;
                }
            });


        }
    }
 
Example #3
Source Project: stockita-point-of-sale   Author: Hishmad   File: AdapterViewUsersList.java    License: MIT License 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    // Initialize the PopupMenu object, and pass the View object in the second argument
    mPopupMenu = new PopupMenu(getContext(), mPopupMenuViewObject);

    // Get the menu inflater to inflate the xml file
    mPopupMenu.getMenuInflater().inflate(R.menu.popup_menu_adapter_view_item_list, mPopupMenu.getMenu());

    /**
     * Now we need to add a click listener on the view object, so when the user click
     * this view object the menu will popup, this can be done using show() method.
     */
    mPopupMenuViewObject.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {

            // Invoke show() to popup the menu.
            mPopupMenu.show();
        }
    });
}
 
Example #4
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 #5
Source Project: coursera-android   Author: aporter   File: DialtactsActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.searchButton: {
            enterSearchUi();
            break;
        }
        case R.id.overflow_menu: {
            if (mDialpadFragment != null) {
                PopupMenu popup = mDialpadFragment.constructPopupMenu(view);
                if (popup != null) {
                    popup.show();
                }
            } else {
                Log.w(TAG, "DialpadFragment is null during onClick() event for " + view);
            }
            break;
        }
        default: {
            Log.wtf(TAG, "Unexpected onClick event from " + view);
            break;
        }
    }
}
 
Example #6
Source Project: trekarta   Author: andreynovikov   File: GaugePanel.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    Context context = getContext();
    PopupMenu popup = new PopupMenu(context, v);
    Menu menu = popup.getMenu();
    int type = 0;
    if (v instanceof Gauge) {
        Gauge gauge = (Gauge) v;
        menu.add(0, gauge.getType(), Menu.NONE, context.getString(R.string.remove_gauge, getGaugeName(gauge.getType())));
        gauge.getType();
    }
    ArrayList<Integer> availableGauges = getAvailableGauges(type);
    for (int availableGauge : availableGauges) {
        menu.add(0, availableGauge, Menu.NONE, context.getString(R.string.add_gauge, getGaugeName(availableGauge)));
    }
    popup.setOnMenuItemClickListener(this);
    popup.show();
    return true;
}
 
Example #7
private void setMenu(List<Trio<String, String, Boolean>> data) {
    menu = new PopupMenu(binding.levelText.getContext(), binding.levelText, Gravity.BOTTOM);

    for (Trio<String, String, Boolean> ou : data)
        menu.getMenu().add(Menu.NONE, Menu.NONE, data.indexOf(ou), ou.val1());

    menu.setOnMenuItemClickListener(item -> {
        selectedOrgUnit = item.getOrder() < 0 ? null : ouItem.getLevelOrgUnits().get(item.getOrder()).val0();
        binding.levelText.setText(item.getOrder() < 0 ? data.get(0).val1() : data.get(item.getOrder()).val1());
        ouItem.setName(item.getOrder() < 0 ? data.get(0).val1() : data.get(item.getOrder()).val1());
        ouItem.setUid(item.getOrder() < 0 ? data.get(0).val0() : data.get(item.getOrder()).val0());
        adapter.setSelectedLevel(
                getAdapterPosition() + 1,
                selectedOrgUnit,
                selectionType == OrgUnitCascadeDialog.OUSelectionType.SEARCH ?
                        ouRepository.uid(selectedOrgUnit).blockingExists():
                        ouRepository.byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE).uid(selectedOrgUnit).blockingExists()
                );
        return false;
    });
}
 
Example #8
Source Project: Exoplayer_VLC   Author: tyazid   File: PlayerActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void showVerboseLogPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);
  Menu menu = popup.getMenu();
  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();
}
 
Example #9
Source Project: scanvine-android   Author: rezendi   File: SourceListActivity.java    License: MIT License 6 votes vote down vote up
public void openSectionPopup() {
       final String[] sections = {"All","World","Tech","Business","Entertainment","Sports","Life"};
       PopupMenu popupMenu = new PopupMenu(this, findViewById(R.id.action_section));
       Menu menu = popupMenu.getMenu();
       for (int i=0; i<sections.length; i++) {
       	boolean addCheck = currentSection!=null &&
       					   (currentSection.equalsIgnoreCase(sections[i]) ||
       					   currentSection.length()==0 && "All".equalsIgnoreCase(sections[i]));
       	menu.add(Menu.NONE, i, Menu.NONE, addCheck ? sections[i]+"✓" : sections[i]);
       }
       popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       	@Override
		public boolean onMenuItemClick(MenuItem item) {
       		currentSection = item.getItemId()==0 ? null : (""+item.getTitle()).replace("✓","");
       		SourceListFragment slf = (SourceListFragment) getSupportFragmentManager().findFragmentById(R.id.source_list);
       		slf.refreshList(currentSection);
       		return false;
       	}
       });
       popupMenu.show();
}
 
Example #10
Source Project: 1Rramp-Android   Author: hapramp   File: DetailedActivity.java    License: 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 #11
Source Project: allenglish   Author: veeson   File: WordDetailsActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void showFilterPopup(View v) {
        PopupMenu popup = new PopupMenu(this, v);
        // Inflate the menu from xml
        popup.getMenuInflater().inflate(R.menu.popup_filter, popup.getMenu());
        // Setup menu item selection
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.copy:
                        StringUtils.copyToClipboard(mContext, mWord.getText().toString());
                        return true;
//                    case R.id.open_bookmark:
//                        Intent intent = new Intent(mContext, BookmarkActivity.class);
//                        startActivity(intent);
//                        return true;
                    default:
                        return false;
                }
            }
        });
        // Handle dismissal with: popup.setOnDismissListener(...);
        // Show the menu
        popup.show();
    }
 
Example #12
Source Project: android-kubernetes-blockchain   Author: IBM   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void showPopup(View v) {
    PopupMenu popupMenu = new PopupMenu(this, v);
    MenuInflater inflater = popupMenu.getMenuInflater();
    inflater.inflate(R.menu.privacy, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.menu_privacy) {
                Uri uri = Uri.parse("https://github.com/AnthonyAmanse/fitcoin-android/blob/master/Privacy.md");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}
 
Example #13
Source Project: yoke-android   Author: rmst   File: YokeActivity.java    License: MIT License 6 votes vote down vote up
public void showOverflowMenu(View view) {
    PopupMenu popup = new PopupMenu(this, view);
    popup.inflate(R.menu.overflow);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.upgradeLayout:
                    if (currentHost != null) {
                        new DownloadFilesFromURL().execute(
                            "http://" + currentHost + ":" + Integer.toString(currentPort) + "/"
                        );
                    } else {
                        Toast.makeText(YokeActivity.this,
                            res.getString(R.string.toast_connected_to_nowhere), Toast.LENGTH_LONG
                        ).show();
                    }
                    return true;
                default:
                    return false;
            }
        }
    });
    popup.show();
}
 
Example #14
Source Project: itag   Author: s4ysolutions   File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void onAppMenu(@NonNull View sender) {
    final PopupMenu popupMenu = new PopupMenu(this, sender);
    popupMenu.inflate(R.menu.app);
    popupMenu.setOnMenuItemClickListener(item -> {
        //noinspection SwitchStatementWithTooFewBranches
        switch (item.getItemId()) {
            case R.id.exit:
                ITag.close();
                Waytoday.stop();
                ITagsService.stop(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    finishAndRemoveTask();
                } else {
                    finishAffinity();
                }
                new Handler(getMainLooper()).postDelayed(() -> System.exit(0), 5000);
                break;
        }
        return true;
    });
    popupMenu.show();
}
 
Example #15
Source Project: ui   Author: JimSeker   File: menuV4.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
private void showPopupMenu(View v){
	//the popupMenu didn't exist in android 2.3.3 and below, so we are checking to see what version of android
	//this is running on and then running only code we can.
	if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {  //should kept this demo from force closing if run on the wrong API... I think...
		PopupMenu popupM = new PopupMenu(this, v);
		popupM.inflate(R.menu.popup);
		popupM.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

			@Override
			public boolean onMenuItemClick(MenuItem item) {
				Toast.makeText(getApplicationContext(), item.toString(),Toast.LENGTH_LONG).show();
				label1.append("\n you clicked "+item.toString());
				return true;
			}
		});

		popupM.show();
	}
}
 
Example #16
Source Project: Telegram   Author: DrKLO   File: FloatingActionMode.java    License: 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 #17
Source Project: triviums   Author: princessdharmy   File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    initBinding();

    //load the category fragment by default
    binding.title.setText(R.string.categories);
    loadFragment(new CategoryFragment());

    binding.menuBtn.setOnClickListener(view -> {
        PopupMenu popupMenu = new PopupMenu(MainActivity.this, view);
        popupMenu.setOnMenuItemClickListener(MainActivity.this);
        popupMenu.inflate(R.menu.menu);
        popupMenu.show();
    });
}
 
Example #18
Source Project: Android-Example-HLS-ExoPlayer   Author: sakurabird   File: PlayerActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void showVerboseLogPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    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();
}
 
Example #19
Source Project: financisto   Author: dsolonenko   File: SmsTemplateListAsyncAdapter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public LocalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.generic_list_item, parent, false);
    view.setOnClickListener(clickedView -> {
        final PopupMenu popupMenu = new PopupMenu(context, clickedView);
        int i = 0;
        for (MenuItemInfo m : createContextMenus()) {
            if (m.enabled) {
                popupMenu.getMenu().add(0, m.menuId, i++, m.titleId);
            }
        }
        popupMenu.setOnMenuItemClickListener(item -> onItemAction(item.getItemId(), clickedView));
        popupMenu.show();
    });
    return new LocalViewHolder(view);
}
 
Example #20
Source Project: RetroMusicPlayer   Author: deepshooter   File: SongMenuHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    PopupMenu popupMenu = new PopupMenu(activity, v);
    popupMenu.inflate(getMenuRes());
    popupMenu.setOnMenuItemClickListener(this);
    popupMenu.show();
}
 
Example #21
Source Project: a   Author: 804463258   File: FindBookFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGroupItemLongClick(int position, int groupPosition, View view) {
    if (getActivity() == null) return;
    FindKindGroupBean groupBean;
    if (isFlexBox()) {
        groupBean = (FindKindGroupBean) findRightAdapter.getData().get(groupPosition).getGroupData();
    } else {
        groupBean = (FindKindGroupBean) findKindAdapter.getAllDatas().get(groupPosition).getGroupData();
    }
    BookSourceBean sourceBean = BookSourceManager.getBookSourceByUrl(groupBean.getGroupTag());
    if (sourceBean == null) {
        return;
    }
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.getMenu().add(R.string.edit);
    popupMenu.getMenu().add(R.string.to_top);
    popupMenu.getMenu().add(R.string.delete);
    popupMenu.setOnMenuItemClickListener(item -> {
        if (item.getTitle().equals(getString(R.string.edit))) {
            SourceEditActivity.startThis(this, sourceBean);
        } else if (item.getTitle().equals(getString(R.string.to_top))) {
            BookSourceManager.toTop(sourceBean)
                    .subscribe(new MySingleObserver<Boolean>() {
                        @Override
                        public void onSuccess(Boolean aBoolean) {
                            refreshData();
                        }
                    });
        } else if (item.getTitle().equals(getString(R.string.delete))) {
            BookSourceManager.removeBookSource(sourceBean);
            refreshData();
        }
        return true;
    });
    popupMenu.show();

}
 
Example #22
Source Project: BotLibre   Author: BotLibre   File: BotActivity.java    License: 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, popup.getMenu());
    onPrepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    popup.show();
}
 
Example #23
Source Project: a   Author: 804463258   File: MyMainActivity.java    License: 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(false));
    popupMenu.show();
    updateTabItemIcon(true);
}
 
Example #24
Source Project: YTPlayer   Author: KaustubhPatange   File: LocalSearchFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
void setAdapterClicks2() {
    albumAdapter.setSingleClickListener((view, model, position) -> {
        openClick(model);
    });


    albumAdapter.setLongClickListener((view, model, position) -> {
        PopupMenu popupMenu = new PopupMenu(activity,view);
        popupMenu.inflate(R.menu.local_popup_menu3);
        popupMenu.setOnMenuItemClickListener(menuItem -> {
            switch (menuItem.getItemId()){
                case R.id.action_play:
                    albumPlay(model);
                    break;
                case R.id.action_add_queue:
                    if (MusicService.yturls.isEmpty()) {
                        albumPlay(model);
                    }else {
                        AddItems(model);
                    }
                    break;
            }
            return true;
        });
        popupMenu.show();
    });
}
 
Example #25
Source Project: BotLibre   Author: BotLibre   File: AvatarEditorActivity.java    License: 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_avatar_editor, popup.getMenu());
    onPrepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });
    popup.show();
}
 
Example #26
Source Project: android-clean-sample-app   Author: dmilicic   File: CostItemView.java    License: MIT License 5 votes vote down vote up
@OnClick(R.id.button_menu)
void onClickMenu() {
    PopupMenu popupMenu = new PopupMenu(getContext(), mMenuButton);
    popupMenu.setOnMenuItemClickListener(this);
    popupMenu.inflate(R.menu.menu_cost_item);
    popupMenu.show();
}
 
Example #27
@Override
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.event_menu, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
            case R.id.showHelp:
                analyticsHelper().setEvent(SHOW_HELP, CLICK, SHOW_HELP);
                setTutorial();
                break;
            case R.id.menu_delete:
                confirmDeleteEvent();
                break;
            default:
                break;
        }
        return false;
    });
    popupMenu.getMenu().getItem(1).setVisible(accessData && presenter.isEnrollmentOpen());
    popupMenu.show();
}
 
Example #28
Source Project: Field-Book   Author: PhenoApps   File: FieldAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
private View.OnClickListener makeMenuPopListener(final int position) {
    return new View.OnClickListener() {
        // Do it when clicking ":"
        @Override
        public void onClick(final View view) {
            PopupMenu popup = new PopupMenu(FieldEditorActivity.thisActivity, view);
            //Inflating the Popup using xml file
            popup.getMenuInflater().inflate(R.menu.menu_field_listitem, popup.getMenu());

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(makeSelectMenuListener(position));
            popup.show();//showing popup menu
        }
    };
}
 
Example #29
Source Project: AndroidStudyDemo   Author: DIY-green   File: PopupMenuDemoActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void createPopupMenuFromXML() {
    mPopupMenu2 = new PopupMenu(this, findViewById(R.id.btn_popupmenu2));
    Menu menu = mPopupMenu2.getMenu();

    // 通过XML文件添加菜单项
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.popupmenu, menu);
}
 
Example #30
Source Project: VinylMusicPlayer   Author: AdrienPoupa   File: SongMenuHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    PopupMenu popupMenu = new PopupMenu(activity, v);
    popupMenu.inflate(getMenuRes());
    popupMenu.setOnMenuItemClickListener(this);
    popupMenu.show();
}