Java Code Examples for android.widget.PopupMenu

The following are top voted examples for showing how to use android.widget.PopupMenu. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: andcouchbaseentity   File: TaskActivity.java   View source code 7 votes vote down vote up
private void setListItemLongClick(ListView listView) {
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int pos, long id) {
            PopupMenu popup = new PopupMenu(TaskActivity.this, view);
            popup.inflate(R.menu.task_item);
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    TaskEntity task = (TaskEntity) mAdapter.getItem(pos - 1);
                    handleTaskPopupAction(item, task);
                    return true;
                }
            });
            popup.show();
            return true;
        }
    });
}
 
Example 2
Project: ultra-music-player   File: PlayListAdapter.java   View source code 7 votes vote down vote up
public void showMenu(View v) {
    PopupMenu popup = new PopupMenu(context, v);
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.playlist_popup_menu);
    // Force icons to show
    Object menuHelper;
    Class[] argTypes;
    try {
        Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
        fMenuHelper.setAccessible(true);
        menuHelper = fMenuHelper.get(popup);
        argTypes = new Class[]{boolean.class};
        menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
    } catch (Exception e) {
        e.printStackTrace();
        popup.show();
        return;
    }
    popup.show();
}
 
Example 3
Project: AndroidProjectsClient   File: RepoProjectsFragment.java   View source code 7 votes vote down vote up
public void showMenu(View view, Project project) {
    final PopupMenu pm = new PopupMenu(getContext(), view);
    pm.inflate(R.menu.menu_project);
    if(project.getState() == State.OPEN) {
        pm.getMenu().add(0, R.id.menu_toggle_project_state, 0, R.string.menu_close_project);
    } else {
        pm.getMenu().add(0, R.id.menu_toggle_project_state, 0, R.string.menu_reopen_project);
    }
    pm.setOnMenuItemClickListener(item -> {
        switch(item.getItemId()) {
            case R.id.menu_toggle_project_state:
                toggleProjectState(project);
                break;
            case R.id.menu_edit_project:
                editProject(project, view);
                break;
            case R.id.menu_delete_project:
                deleteProject(project);
                break;
        }
        return true;
    });
    pm.show();
}
 
Example 4
Project: AndroidProjectsClient   File: RepoIssuesFragment.java   View source code 7 votes vote down vote up
public void openMenu(View view, final Issue issue) {
    final PopupMenu menu = new PopupMenu(getContext(), view);
    menu.inflate(R.menu.menu_issue);
    menu.getMenu().add(0, R.id.menu_toggle_issue_state, Menu.NONE,
            issue.isClosed() ? R.string.menu_reopen_issue : R.string.menu_close_issue
    );
    menu.getMenu().add(0, R.id.menu_edit_issue, Menu.NONE, getString(R.string.menu_edit_issue));

    menu.setOnMenuItemClickListener(menuItem -> {
        switch(menuItem.getItemId()) {
            case R.id.menu_toggle_issue_state:
                toggleIssueState(issue);
                break;
            case R.id.menu_edit_issue:
                editIssue(view, issue);
                break;
            case R.id.menu_fullscreen:
                IntentHandler.showFullScreen(getContext(), issue.getBody(),
                        issue.getRepoFullName(), getFragmentManager()
                );
                break;
        }
        return false;
    });
    menu.show();
}
 
Example 5
Project: BBSSDK-for-Android   File: Theme1ForumThreadPullToRequestView.java   View source code 6 votes vote down vote up
public void popFilterMenu(View rootview) {
	int style = ResHelper.getStyleRes(getContext(), "BBS_PopupMenu");
	Context wrapper = new ContextThemeWrapper(getContext(), style);
	//Creating the instance of PopupMenu
	PopupMenu popup = new PopupMenu(wrapper, rootview);
	//Inflating the Popup using xml file
	popup.getMenuInflater().inflate(PageForumThreadDetail.getMenuRes(getContext(), "bbs_popup_forumthread"), popup.getMenu());

	//registering popup with OnMenuItemClickListener
	popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
		public boolean onMenuItemClick(MenuItem item) {
			//only one menu item.
			if (item.getItemId() == ResHelper.getIdRes(getContext(), "action_arrangebycomment")) {
				orderType = ThreadListOrderType.LAST_POST;
				performPullingDown(true);
			} else if (item.getItemId() == ResHelper.getIdRes(getContext(), "action_arrangebypost")) {
				orderType = ThreadListOrderType.CREATE_ON;
				performPullingDown(true);
			}
			return true;
		}
	});
	popup.show();
}
 
Example 6
Project: xlight_android_native   File: ShareMainFragment.java   View source code 6 votes vote down vote up
private void showPopup() {
    PopupMenu popup = new PopupMenu(getActivity(), btn_more);
    //Inflating the Popup using xml file
    popup.getMenuInflater()
            .inflate(R.menu.share_menu, popup.getMenu());

    //registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.menu_send:
                    initShare(1);
                    break;
                case R.id.menu_receive:
                    initShare(0);
                    break;
            }
            return true;
        }
    });
    popup.show();
}
 
Example 7
Project: javaide   File: LogLineViewHolder.java   View source code 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    PopupMenu menu = new PopupMenu(v.getContext(), v);
    menu.getMenu().add(0, CONTEXT_MENU_FILTER_ID, 0, R.string.filter_choice);
    menu.getMenu().add(0, CONTEXT_MENU_COPY_ID, 0, R.string.copy_to_clipboard);
    menu.setOnMenuItemClickListener(LogLineViewHolder.this);
    menu.show();
    return true;
}
 
Example 8
Project: xifan   File: StatusAdapter.java   View source code 6 votes vote down vote up
private void showPopupMenu(View view, final StatusRes statusRes) {
    PopupMenu popupMenu = new PopupMenu(mContext, view);
    if (statusRes.isIs_self()) {
        popupMenu.inflate(R.menu.menu_item_status_self);
    } else {
        popupMenu.inflate(R.menu.menu_item_status);
    }
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.action_delete:
                    showDeleteStatusDailog(statusRes);
                    break;
                case R.id.action_copy:
                    copyStatus(statusRes);
                    break;
                case R.id.action_share:
                    break;
            }
            return false;
        }
    });
    popupMenu.show();
}
 
Example 9
Project: BookyMcBookface   File: ReaderActivity.java   View source code 6 votes vote down vote up
protected void showToc() {
    Map<String,String> tocmap = book.getToc();
    PopupMenu tocmenu = new PopupMenu(this, findViewById(R.id.contents_button));
    for (final String point: tocmap.keySet()) {
        String text = tocmap.get(point);
        MenuItem m = tocmenu.getMenu().add(text);
        //Log.d("EPUB", "TOC2: " + text + ". File: " + point);
        m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                handleLink(point);
                return true;
            }
        });
    }
    if (tocmap.size()==0) {
        tocmenu.getMenu().add(R.string.no_toc_found);
    }

    tocmenu.show();

}
 
Example 10
Project: BookyMcBookface   File: GetBooksActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onLongClick(final View v) {

    PopupMenu p = new PopupMenu(this, v);
    MenuItem m = p.getMenu().add("Delete");

    m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            list.removeView(v);
            db.deleteWebSite((String)v.getTag());
            return true;
        }
    });
    p.show();
    return true;
}
 
Example 11
Project: LaunchTime   File: MainActivity.java   View source code 6 votes vote down vote up
public static void setForceShowIcon(PopupMenu popupMenu) {
    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 (Throwable e) {
        e.printStackTrace();
    }
}
 
Example 12
Project: boohee_v5.6   File: WebFavoriteFragment.java   View source code 6 votes vote down vote up
protected void showPopupMenu(View view, final int position) {
    final FavoriteArticle article = (FavoriteArticle) getItem(position);
    PopupMenu popup = new PopupMenu(this.context, view);
    popup.getMenu().add(0, 0, 0, "取消收藏");
    popup.show();
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case 0:
                    WebFavoriteFragment.this.deleteFavoriteArticle(article, position);
                    break;
            }
            return false;
        }
    });
}
 
Example 13
Project: okwallet   File: BlockListFragment.java   View source code 6 votes vote down vote up
@Override
public void onBlockMenuClick(final View view, final StoredBlock block) {
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.blocks_context);
    popupMenu.getMenu().findItem(R.id.blocks_context_browse).setVisible(Constants.ENABLE_BROWSE);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.blocks_context_browse:
                final String blockHash = block.getHeader().getHashAsString();
                final Uri blockExplorerUri = config.getBlockExplorer();
                log.info("Viewing block {} on {}", blockHash, blockExplorerUri);
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.withAppendedPath(blockExplorerUri, "block/" + blockHash)));
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}
 
Example 14
Project: CowBit   File: CowDetailsActivity.java   View source code 6 votes vote down vote up
public void pickDateButtonClick(View view) {
        //Creating the instance of PopupMenu
        PopupMenu popup = new PopupMenu(CowDetailsActivity.this, pickDateButton);
        //Inflating the Popup using xml file
        popup.getMenuInflater().inflate(R.menu.date_popup_menu, popup.getMenu());

        //registering popup with OnMenuItemClickListener
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                popupSelectedItemId = item.getItemId();
                DatePickerFragment newFragment = new DatePickerFragment();
                newFragment.setListener(CowDetailsActivity.this);

/*                Bundle args = new Bundle();
                args.putInt("num", num);
                newFragment.setArguments(args);*/

                newFragment.show(getFragmentManager(), "datePickr");

                return true;
            }
        });

        popup.show();//showing popup menu
    }
 
Example 15
Project: Tusky   File: ComposeActivity.java   View source code 6 votes vote down vote up
private void onMediaClick(QueuedMedia item, View view) {
    PopupMenu popup = new PopupMenu(this, view);
    final int addCaptionId = 1;
    final int removeId = 2;
    popup.getMenu().add(0, addCaptionId, 0, R.string.action_set_caption);
    popup.getMenu().add(0, removeId, 0, R.string.action_remove_media);
    popup.setOnMenuItemClickListener(menuItem -> {
        switch (menuItem.getItemId()) {
            case addCaptionId:
                makeCaptionDialog(item);
                break;
            case removeId:
                removeMediaFromQueue(item);
                break;
        }
        return true;
    });
    popup.show();
}
 
Example 16
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
 
Example 17
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
 
Example 18
Project: Android-Example-HLS-ExoPlayer   File: PlayerActivity.java   View source code 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
Project: TenguChat   File: ConversationFragment.java   View source code 6 votes vote down vote up
private void showBlockSubmenu(View view) {
	final Jid jid = conversation.getJid();
		if (jid.isDomainJid()) {
			BlockContactDialog.show(activity, conversation);
		} else {
			PopupMenu popupMenu = new PopupMenu(activity, view);
			popupMenu.inflate(R.menu.block);
			popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
				@Override
				public boolean onMenuItemClick(MenuItem menuItem) {
					Blockable blockable;
					switch (menuItem.getItemId()) {
						case R.id.block_domain:
							blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid());
							break;
						default:
							blockable = conversation;
					}
					BlockContactDialog.show(activity, blockable);
					return true;
				}
			});
			popupMenu.show();
		}
}
 
Example 20
Project: Ymir   File: ListLayoutConfigAdapter.java   View source code 6 votes vote down vote up
@Override
public void onClick(View v) {
          RecordMenuData menuData = (RecordMenuData) v.getTag();
          YmirMenuItem actionItem = menuData.getActionItem();
          IEntityRecord record = menuData.getRecord();

          if (actionItem == overflowMenuItem) {
              PopupMenu popup = new PopupMenu(context, v);
              popup.setOnMenuItemClickListener(new PopupMenuItemClickListner(menuData, provider));
              Menu popupMenu = popup.getMenu();

              List<YmirMenuItem> items = menuData.getItems();
              for (int i = 0; i < items.size(); i++) {
                  YmirMenuItem menuItem = items.get(i);
                  popupMenu.add(Menu.NONE, i, Menu.NONE, menuItem.getTitle());
              }

              popup.show();
              return;
          }

          provider.onRecordActionItemSelected(record, actionItem);
}
 
Example 21
Project: RespawnIRC-Android   File: ShowTopicActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onLongClick(View buttonView) {
    PopupMenu popup = new PopupMenu(ShowTopicActivity.this, buttonView);
    MenuItem postAsModoItem;

    popup.getMenuInflater().inflate(R.menu.menu_sendmessage_action, popup.getMenu());
    popup.setOnMenuItemClickListener(onSendmessageActionClickedListener);

    postAsModoItem = popup.getMenu().findItem(R.id.enable_postasmodo_sendmessage_action);
    postAsModoItem.setChecked(PrefsManager.getBool(PrefsManager.BoolPref.Names.POST_AS_MODO_WHEN_POSSIBLE));
    postAsModoItem.setEnabled(userCanPostAsModo);
    popup.getMenu().findItem(R.id.action_past_last_message_sended_showtopic).setEnabled(!lastMessageSended.isEmpty());

    popup.show();

    return true;
}
 
Example 22
Project: ExoPlayerController   File: PlayerActivity.java   View source code 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 23
Project: ExoPlayerController   File: PlayerActivity.java   View source code 6 votes vote down vote up
private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener,
		final int trackType) {
	if (player == null) {
		return;
	}
	int trackCount = player.getTrackCount(trackType);
	if (trackCount == 0) {
		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.TRACK_DISABLED + ID_OFFSET, Menu.NONE, R.string.off);
	for (int i = 0; i < trackCount; i++) {
		menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, buildTrackName(player.getTrackFormat(trackType, i)));
	}
	menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
	menu.findItem(player.getSelectedTrack(trackType) + ID_OFFSET).setChecked(true);
}
 
Example 24
Project: react-native-ibeacon-android   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
 
Example 25
Project: k3b-geoHelper   File: HistoryEditText.java   View source code 6 votes vote down vote up
protected void showHistory() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
    List<String> items = getHistory(sharedPref);

    PopupMenu popup = new PopupMenu(mContext, mEditor);
    Menu root = popup.getMenu();
    int len = items.size();
    if (len > 10) len = 10;
    for (int i = 0; i < len; i++) {
        String text = items.get(i).trim();

        if ((text != null) && (text.length() > 0)) {
            root.add(text);
        }
    }

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            mEditor.setText(item.getTitle());
            mEditor.setSelection(0, mEditor.length());
            return true;
        }
    });
    popup.show();
}
 
Example 26
Project: PainlessMusicPlayer   File: AlbumsRecyclerAdapter.java   View source code 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.moveToPosition(position)) {
        final String albumName = item.getString(AlbumsProvider.COLUMN_ALBUM);
        popup.setOnMenuItemClickListener(menuItem -> onMenuItemClick(menuItem, id, albumName));
        popup.show();
    }
}
 
Example 27
Project: ultra-music-player   File: RecyclerSongAdapter.java   View source code 6 votes vote down vote up
public void showMenu(View v) {
    currentSong = songs.get(songPosition);
    PopupMenu popup = new PopupMenu(context, v);
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.menu_songlist_pop);
    // Force icons to show
    Object menuHelper;
    Class[] argTypes;
    try {
        Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
        fMenuHelper.setAccessible(true);
        menuHelper = fMenuHelper.get(popup);
        argTypes = new Class[]{boolean.class};
        menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
    } catch (Exception e) {
        Log.w("TAG", "error forcing menu icons to show", e);
        popup.show();
        return;
    }
    popup.show();
}
 
Example 28
Project: ultra-music-player   File: AlbumAdapter.java   View source code 6 votes vote down vote up
public void showMenu(View v) {
    PopupMenu popup = new PopupMenu(activity, v);
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.album_popoup_menu);
    // Force icons to show
    Object menuHelper;
    Class[] argTypes;
    try {
        Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
        fMenuHelper.setAccessible(true);
        menuHelper = fMenuHelper.get(popup);
        argTypes = new Class[]{boolean.class};
        menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
    } catch (Exception e) {
        Log.w("TAG", "error forcing menu icons to show", e);
        popup.show();
        return;
    }
    popup.show();
}
 
Example 29
Project: ultra-music-player   File: FavouritesAdapter.java   View source code 6 votes vote down vote up
public void showMenu(View v) {
    PopupMenu popup = new PopupMenu(context, v);
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.menu_fav_song_list_pop);
    // Force icons to show
    Object menuHelper;
    Class[] argTypes;
    try {
        Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
        fMenuHelper.setAccessible(true);
        menuHelper = fMenuHelper.get(popup);
        argTypes = new Class[]{boolean.class};
        menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
    } catch (Exception e) {
        Log.w("TAG", "error forcing menu icons to show", e);
        popup.show();
        return;
    }
    popup.show();
}
 
Example 30
Project: ultra-music-player   File: FullScreenPlayListSongsAdapter.java   View source code 6 votes vote down vote up
public void showMenu(View v) {
    PopupMenu popup = new PopupMenu(activity, v);
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.song_list);
    // Force icons to show
    Object menuHelper;
    Class[] argTypes;
    try {
        Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
        fMenuHelper.setAccessible(true);
        menuHelper = fMenuHelper.get(popup);
        argTypes = new Class[]{boolean.class};
        menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
    } catch (Exception e) {
        Log.w("TAG", "error forcing menu icons to show", e);
        popup.show();
        return;
    }
    popup.show();
}
 
Example 31
Project: science-journal   File: ExperimentDetailsFragment.java   View source code 6 votes vote down vote up
private void setupTrialHeader(DetailsViewHolder holder, final ExperimentDetailItem item) {
    holder.timeHeader.setTime(item.getViewType() == VIEW_TYPE_RUN_CARD ?
            item.getTrial().getFirstTimestamp() : item.getLabel().getTimeStamp());

    ColorUtils.colorDrawable(holder.captionIcon.getContext(),
            holder.captionIcon.getDrawable(), R.color.text_color_light_grey);
    ColorUtils.colorDrawable(holder.menuButton.getContext(),
            holder.menuButton.getDrawable(), R.color.text_color_light_grey);

    holder.menuButton.setOnClickListener(view -> {
        Context context = holder.menuButton.getContext();
        PopupMenu popup = new PopupMenu(context, holder.menuButton);
        setupTrialMenu(item, popup);
        popup.show();
    });
}
 
Example 32
Project: science-journal   File: ExperimentDetailsFragment.java   View source code 6 votes vote down vote up
private void setupTrialMenu(ExperimentDetailItem item, PopupMenu popup) {
    popup.getMenuInflater().inflate(R.menu.menu_experiment_trial, popup.getMenu());
    boolean archived = item.getTrial().isArchived();
    popup.getMenu().findItem(R.id.menu_item_archive).setVisible(!archived);
    popup.getMenu().findItem(R.id.menu_item_unarchive).setVisible(archived);
    popup.getMenu().findItem(R.id.menu_item_delete).setEnabled(archived);
    popup.setOnMenuItemClickListener(menuItem -> {
        if (menuItem.getItemId() == R.id.menu_item_archive) {
            mParentReference.get().setTrialArchived(item.getTrial(), true);
            return true;
        } else if (menuItem.getItemId() == R.id.menu_item_unarchive) {
            mParentReference.get().setTrialArchived(item.getTrial(), false);
            return true;
        } else if (menuItem.getItemId() == R.id.menu_item_delete) {
            if (mParentReference.get() != null) {
                mParentReference.get().deleteTrial(item.getTrial());
            }
            return true;
        }
        return false;
    });
}
 
Example 33
Project: stockita-point-of-sale   File: AdapterViewUsersList.java   View source code 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 34
Project: stockita-point-of-sale   File: AdapterViewSalesHeaderList.java   View source code 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(), mHeaderPopupMenu);

    // Get the menu inflater to inflate the xml file
    mPopupMenu.getMenuInflater().inflate(R.menu.popup_menu_adapter_view_sales_header, 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.
     */
    mHeaderPopupMenu.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {

            // Invoke show() to popup the menu.
            mPopupMenu.show();
        }
    });

}
 
Example 35
Project: stockita-point-of-sale   File: AdapterViewItemList.java   View source code 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 36
Project: react-native-box-loaders   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
 
Example 37
Project: delern   File: DeckViewHolder.java   View source code 6 votes vote down vote up
/**
 * Method shows Popup menu on chosen deck menu.
 * Access to method is package-private due to ButterKnife
 *
 * @param v clicked view
 */
@OnClick(R.id.deck_popup_menu)
/* default */ void showPopup(final View v) {
    PopupMenu popup = new PopupMenu(v.getContext(), v);
    popup.setOnMenuItemClickListener(this);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.deck_menu, popup.getMenu());
    manageSharingMenu(popup.getMenu());
    // mDeckAccess can be null due to asynchronous operations.
    if (mDeckAccess != null) {
        popup.show();
        return;
    }
    Toast.makeText(mDeckTextView.getContext(),
            R.string.not_all_data_loaded_user_warning, Toast.LENGTH_SHORT).show();
    LOGGER.warn("mDeckAccess is null in DeckViewHolder", new Throwable());
}
 
Example 38
Project: cidrawing   File: MainActivity.java   View source code 6 votes vote down vote up
public void select(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    popup.getMenuInflater().inflate(R.menu.menu_select, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            PointerMode mode = new PointerMode();
            switch (item.getItemId()) {
                case R.id.rect_select_menu:
                    mode.setSelectionMode(new RectSelectionMode());
                    break;
                case R.id.oval_select_menu:
                    mode.setSelectionMode(new OvalSelectionMode());
                    break;
                case R.id.lasso_menu:
                    mode.setSelectionMode(new LassoSelectionMode());
                    break;
            }
            drawingBoard.getDrawingContext().setDrawingMode(mode);
            return true;
        }
    });
    popup.show();
}
 
Example 39
Project: cidrawing   File: MainActivity.java   View source code 6 votes vote down vote up
public void stroke(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    popup.getMenuInflater().inflate(R.menu.menu_stroke, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            DrawingMode mode = null;
            switch (item.getItemId()) {
                case R.id.plain_stroke_menu:
                    mode = new PlainStrokeMode();
                    break;
                case R.id.smooth_stroke_menu:
                    mode = new SmoothStrokeMode();
                    break;
                case R.id.eraser_stroke_menu:
                    mode = new EraserStrokeMode();
                    break;
            }
            if (mode != null) {
                drawingBoard.getDrawingContext().setDrawingMode(mode);
            }
            return true;
        }
    });
    popup.show();
}
 
Example 40
Project: CarPathRecorder   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.fab).setOnClickListener(this);

    mPopupMenu = new PopupMenu(this, findViewById(R.id.fab));
    mPopupMenu.getMenuInflater().inflate(R.menu.menu_main, mPopupMenu.getMenu());
    mPopupMenu.setOnMenuItemClickListener(this);

    mapView = (MapView) findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);// 必须要写
    if (aMap == null) {
        aMap = mapView.getMap();
        setUpMap();
    }

    startLocationService();

    mDownloadInfoBar = (LinearLayout) findViewById(R.id.downloadInfoBar);
    mDownloadInfoBar.setVisibility(View.GONE);
}