androidx.annotation.MenuRes Java Examples

The following examples show how to use androidx.annotation.MenuRes. 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: TestUtilsActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Clears and inflates the menu.
 *
 * @param menuResId The menu resource XML to be used.
 */
public static ViewAction reinflateMenu(final @MenuRes int menuResId) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(NavigationView.class);
    }

    @Override
    public String getDescription() {
      return "clear and inflate menu " + menuResId;
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();
      final NavigationView nv = (NavigationView) view;
      nv.getMenu().clear();
      nv.inflateMenu(menuResId);
      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
Example #2
Source File: MysplashPopupWindow.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void show(MysplashActivity activity, View anchor, @MenuRes int resId,
                        @NonNull PopupMenu.OnMenuItemClickListener l) {
    PopupMenu popupMenu = new PopupMenu(activity, anchor);
    popupMenu.getMenuInflater().inflate(resId, popupMenu.getMenu());
    popupMenu.show();
    popupMenu.setOnMenuItemClickListener(l);

    // DisplayUtils.setOverflowMenuIconsVisible(popupMenu.getMenu());

    popupMenu.show();
}
 
Example #3
Source File: MenuBindingAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
@BindingAdapter("menu") public static void inflateMenu(final ActionMenuView amv, final @MenuRes int old_menu, final @MenuRes int new_menu) {
	if (SDK_INT < LOLLIPOP) return;
	if (new_menu == old_menu) return;
	final Menu menu = amv.getMenu();
	menu.clear();
	new MenuInflater(amv.getContext()).inflate(new_menu, menu);
}
 
Example #4
Source File: MenuBindingAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
@BindingAdapter("menu") public static void inflateMenu(final Toolbar toolbar, final @MenuRes int old_menu, final @MenuRes int new_menu) {
	if (SDK_INT < LOLLIPOP) return;
	if (new_menu == old_menu) return;
	final Menu menu = toolbar.getMenu();
	menu.clear();
	toolbar.inflateMenu(new_menu);
}
 
Example #5
Source File: ToolbarHelper.java    From Paginize with MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
public static void setupMenu(Toolbar toolbar,
                             @MenuRes int menuResId,
                             Toolbar.OnMenuItemClickListener listener) {
  if (menuResId > 0) {
    toolbar.inflateMenu(menuResId);
    if (listener != null) {
      toolbar.setOnMenuItemClickListener(listener);
    }
  }
}
 
Example #6
Source File: FramePage.java    From Paginize with MIT License 5 votes vote down vote up
protected final void setupMenu(@MenuRes int menuResId) {
  ToolbarHelper.setupMenu(mTbToolbar, menuResId, new Toolbar.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      return FramePage.this.onMenuItemClick(item);
    }
  });
}
 
Example #7
Source File: BasePage.java    From Paginize with MIT License 5 votes vote down vote up
protected final void setMenu(@MenuRes int menuResId) {
  setToolbarEnabled(true);

  ToolbarHelper.setupMenu(mToolbar, menuResId, new Toolbar.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      return BasePage.this.onMenuItemClick(item);
    }
  });
}
 
Example #8
Source File: BaseInnerPage.java    From Paginize with MIT License 5 votes vote down vote up
protected final void setMenu(@MenuRes int menuResId) {
  setToolbarEnabled(true);

  ToolbarHelper.setupMenu(mToolbar, menuResId, new Toolbar.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      return BaseInnerPage.this.onMenuItemClick(item);
    }
  });
}
 
Example #9
Source File: BaseTabsPage.java    From Paginize with MIT License 5 votes vote down vote up
protected final void setMenu(@MenuRes int menuResId) {
  setToolbarEnabled(true);

  ToolbarHelper.setupMenu(mToolbar, menuResId, new Toolbar.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      return BaseTabsPage.this.onMenuItemClick(item);
    }
  });
}
 
Example #10
Source File: ToolbarHelper.java    From Paginize with MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
public static void setupMenu(Toolbar toolbar,
                             @MenuRes int menuResId,
                             Toolbar.OnMenuItemClickListener listener) {
  if (menuResId > 0) {
    toolbar.inflateMenu(menuResId);
    if (listener != null) {
      toolbar.setOnMenuItemClickListener(listener);
    }
  }
}
 
Example #11
Source File: PanelMenuFragment.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void setMenu(@MenuRes int menuId, OnPrepareMenuListener onPrepareMenuListener) {
    mMenuId = menuId;
    mOnPrepareMenuListener = onPrepareMenuListener;
    if (isVisible()) {
        populateMenu();
        mAdapter.notifyDataSetChanged();
    }
}
 
Example #12
Source File: MenuViewHolder.java    From RecyclerExt with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the menu specified with the <code>menuResourceId</code> starting
 * at the <code>anchor</code>
 *
 * @param anchor The view to show the popup menu from
 * @param menuResourceId The resource id for the menu to show
 */
protected void showMenu(@NonNull View anchor, @MenuRes int menuResourceId) {
    PopupMenu menu = new PopupMenu(anchor.getContext(), anchor);
    MenuInflater inflater = menu.getMenuInflater();
    inflater.inflate(menuResourceId, menu.getMenu());

    onPreparePopupMenu(menu.getMenu());
    menu.setOnMenuItemClickListener(this);
    menu.show();
}
 
Example #13
Source File: FormFragment.java    From shaky-android with Apache License 2.0 5 votes vote down vote up
public static FormFragment newInstance(@NonNull String title,
                                       @NonNull String hint,
                                       @Nullable Uri screenshotUri,
                                       @Nullable @MenuRes int menu) {
    Bundle args = new Bundle();
    args.putParcelable(KEY_SCREENSHOT_URI, screenshotUri);
    args.putString(KEY_TITLE, title);
    args.putString(KEY_HINT, hint);
    args.putInt(KEY_MENU, menu);

    FormFragment fragment = new FormFragment();
    fragment.setArguments(args);
    return fragment;
}
 
Example #14
Source File: FeedbackActivity.java    From shaky-android with Apache License 2.0 5 votes vote down vote up
@NonNull
public static Intent newIntent(@NonNull Context context,
                               @Nullable Uri screenshotUri,
                               @Nullable Bundle userData,
                               @MenuRes int resMenu) {
    Intent intent = new Intent(context, FeedbackActivity.class);
    intent.putExtra(SCREENSHOT_URI, screenshotUri);
    intent.putExtra(USER_DATA, userData);
    intent.putExtra(RES_MENU, resMenu);
    return intent;
}
 
Example #15
Source File: BottomSheetBuilder.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
public BottomSheetBuilder setMenu(@MenuRes int menu) {
    @SuppressWarnings("ConstantConditions")
    PopupMenu popupMenu = new PopupMenu(mContext, null);
    mMenu = popupMenu.getMenu();
    popupMenu.getMenuInflater().inflate(menu, mMenu);
    return setMenu(mMenu);
}
 
Example #16
Source File: TabSwitcherModel.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public final void inflateToolbarMenu(@MenuRes final int resourceId,
                                     @Nullable final OnMenuItemClickListener listener) {
    this.toolbarMenuId = resourceId;
    this.toolbarMenuItemListener = listener;
    notifyOnToolbarMenuInflated(resourceId, listener);
}
 
Example #17
Source File: GridViewHolder.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
private PopupMenu createPopup(@MenuRes int menuId, View view) {
	final PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
	popupMenu.getMenuInflater().inflate(menuId, popupMenu.getMenu());
	return popupMenu;
}
 
Example #18
Source File: PopupMenuView.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void setMenu(@MenuRes int menu, @NonNull PrepareOptionsMenuItem prepareOptionsMenuItem, @NonNull ItemClick callback) {
  this.menu                           = menu;
  this.prepareOptionsMenuItemCallback = prepareOptionsMenuItem;
  this.callback                       = callback;
}
 
Example #19
Source File: ConversationListArchiveFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected @MenuRes int getActionModeMenuRes() {
  return R.menu.conversation_list_batch_unarchive;
}
 
Example #20
Source File: ConversationListFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
protected @MenuRes int getActionModeMenuRes() {
  return R.menu.conversation_list_batch_archive;
}
 
Example #21
Source File: AbsMultiSelectAdapter.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public AbsMultiSelectAdapter(Context context, @Nullable CabHolder cabHolder, @MenuRes int menuRes) {
    this.cabHolder = cabHolder;
    checked = new ArrayList<>();
    this.menuRes = menuRes;
    this.context = context;
}
 
Example #22
Source File: AbsMultiSelectAdapter.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
protected void setMultiSelectMenuRes(@MenuRes int menuRes) {
    this.menuRes = menuRes;
}
 
Example #23
Source File: TabSwitcher.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@Override
public final void inflateToolbarMenu(@MenuRes final int resourceId,
                                     @Nullable final OnMenuItemClickListener listener) {
    model.inflateToolbarMenu(resourceId, listener);
}
 
Example #24
Source File: PanelMenuFragment.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parse the given XML file as a header description, adding each
 * parsed Header into the target list.
 *
 * @param resId  The XML resource to load and parse.
 * @param target The list in which the parsed headers should be placed.
 */
@SuppressWarnings("ResourceType")
private void loadHeadersFromResource(@MenuRes int resId, List<PanelMenuItem> target) {
    Resources resources = getResources();
    try (XmlResourceParser parser = resources.getXml(resId)) {
        AttributeSet attrs = Xml.asAttributeSet(parser);

        int type;
        //noinspection StatementWithEmptyBody
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
            // Parse next until start tag is found
        }

        String nodeName = parser.getName();
        if (!"menu".equals(nodeName)) {
            throw new RuntimeException("XML document must start with <menu> tag; found" + nodeName + " at " + parser.getPositionDescription());
        }

        final int outerDepth = parser.getDepth();
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                continue;
            }

            nodeName = parser.getName();
            if ("item".equals(nodeName)) {
                PanelMenuItem item = new PanelMenuItem(getContext());
                int[] set = {
                        android.R.attr.id,
                        android.R.attr.title,
                        android.R.attr.icon,
                        android.R.attr.checkable,
                        android.R.attr.actionLayout
                };
                TypedArray sa = getContext().obtainStyledAttributes(attrs, set);
                item.setItemId(sa.getResourceId(0, PanelMenuItem.HEADER_ID_UNDEFINED));
                TypedValue tv = sa.peekValue(1);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        item.setTitle(tv.resourceId);
                    } else {
                        item.setTitle(tv.string);
                    }
                }
                int iconRes = sa.getResourceId(2, 0);
                if (iconRes != 0)
                    item.setIcon(iconRes);

                item.setCheckable(sa.getBoolean(3, false));

                int actionRes = sa.getResourceId(4, 0);
                if (actionRes != 0)
                    item.setActionView(actionRes);

                sa.recycle();

                target.add(item);
            } else {
                XmlUtils.skipCurrentTag(parser);
            }
        }
    } catch (XmlPullParserException | IOException e) {
        throw new RuntimeException("Error parsing headers", e);
    }
}
 
Example #25
Source File: AbsMultiSelectAdapter.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
protected void setMultiSelectMenuRes(@MenuRes int menuRes) {
    this.menuRes = menuRes;
}
 
Example #26
Source File: AbsMultiSelectAdapter.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
public AbsMultiSelectAdapter(Context context, @Nullable CabHolder cabHolder, @MenuRes int menuRes) {
    this.cabHolder = cabHolder;
    checked = new ArrayList<>();
    this.menuRes = menuRes;
    this.context = context;
}
 
Example #27
Source File: TabletContentRecyclerAdapterWrapper.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
@Override
public final void onToolbarMenuInflated(@MenuRes final int resourceId,
                                        @Nullable final Toolbar.OnMenuItemClickListener listener) {

}
 
Example #28
Source File: PopupMenu.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Override
public PopupMenu inflate(@MenuRes int menuRes) {
    mSupportPopupMenu.inflate(menuRes);
    return this;
}
 
Example #29
Source File: AbsMultiSelectAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public AbsMultiSelectAdapter(Context context, @Nullable CabHolder cabHolder, @MenuRes int menuRes) {
    this.cabHolder = cabHolder;
    checked = new ArrayList<>();
    this.menuRes = menuRes;
    this.context = context;
}
 
Example #30
Source File: AbsMultiSelectAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
protected void setMultiSelectMenuRes(@MenuRes int menuRes) {
    this.menuRes = menuRes;
}