Java Code Examples for android.support.annotation.MenuRes

The following are top voted examples for showing how to use android.support.annotation.MenuRes. 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: Hitalk   File: FloatingSearchView.java   View source code 7 votes vote down vote up
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
Example 2
Project: JsoupSample   File: MainPresenterImpl.java   View source code 6 votes vote down vote up
@Override
public void switchId(@MenuRes int id) {
    switch (id) {
        case R.id.dytt:
        case FIRST_FRAGMENT:
            setSelectFragment(TYPE_DYTT_FRAGMENT);
            break;
        case R.id.dy_2018:
            setSelectFragment(TYPE_DY2018_FRAGMENT);
            break;
        case R.id.xiaopian:
            setSelectFragment(TYPE_XP_FRAGMENT);
            break;
        case R.id.piaohua:
            setSelectFragment(TYPE_PH_FRAGMENT);
            break;
        case R.id.k567:
            setSelectFragment(TYPE_K567_FRAGMENT);
            break;
    }
}
 
Example 3
Project: JsoupSample   File: MainPresenterImpl.java   View source code 6 votes vote down vote up
@Override
public void switchId(@MenuRes int id) {
    switch (id) {
        case R.id.search:
            view.switchSearch();
            break;
        case R.id.mark:
            view.switchMark();
            break;
        case FIRST_FRAGMENT:
        case R.id.fiction_81:
            setSelectFragment(TYPE_ZW_FRAGMENT);
            break;
        case R.id.bi_qu_ge:
            setSelectFragment(TYPE_BGQ_FRAGMENT);
            break;
        case R.id.ksw:
            setSelectFragment(TYPE_KSW_FRAGMENT);
            break;
        case R.id.piao_tian:
            setSelectFragment(TYPE_PT_FRAGMENT);
            break;
    }
}
 
Example 4
Project: JsoupSample   File: MainPresenterImpl.java   View source code 6 votes vote down vote up
@Override
public void switchId(@MenuRes int id) {
    switch (id) {
        case R.id.mzitu:
            setSelectFragment(TYPE_MZT_FRAGMENT);
            break;
        case FIRST_FRAGMENT:
        case R.id.dbmz:
            setSelectFragment(TYPE_DB_FRAGMENT);
            break;
        case R.id.mm:
            setSelectFragment(TYPE_MM_FRAGMENT);
            break;
        case R.id.meizitu:
            setSelectFragment(TYPE_MEIZITU_FRAGMENT);
            break;
        case R.id.kk:
            setSelectFragment(TYPE_KK_FRAGMENT);
            break;
        case R.id.collection:
            setSelectFragment(TYPE_COLLECTION_FRAGMENT);
            break;
        case R.id.search:
            view.switchSearch();
    }
}
 
Example 5
Project: GComic   File: FloatingSearchView.java   View source code 6 votes vote down vote up
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes == 0) return;
    getActivity().getMenuInflater()
                 .inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
Example 6
Project: SublimeNavigationView   File: SublimeNavigationView.java   View source code 6 votes vote down vote up
/**
 * Provides a mechanism for switching between any number of Menus.
 *
 * @param newMenuResId id of the menu that you wish
 *                     to switch to. Eg: R.menu.new_menu_id
 */
public void switchMenuTo(@MenuRes int newMenuResId) {
    if (newMenuResId < 1) {
        Log.e(TAG, "Could not switch to new menu: passed menuResourceId was invalid.");
        return;
    }

    mMenu = new SublimeMenu(newMenuResId);
    inflateMenu(newMenuResId);

    mMenu.setCallback(new SublimeMenu.Callback() {
        public boolean onMenuItemSelected(SublimeMenu menu, SublimeBaseMenuItem item,
                                          OnNavigationMenuEventListener.Event event) {
            return SublimeNavigationView.this.mEventListener != null
                    && SublimeNavigationView.this
                    .mEventListener.onNavigationMenuEvent(event, item);
        }
    });

    mMenu.setMenuPresenter(getContext(), mPresenter);
}
 
Example 7
Project: FloatingSearchView   File: FloatingSearchView.java   View source code 6 votes vote down vote up
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
Example 8
Project: material-components-android   File: TestUtilsActions.java   View source code 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 9
Project: FloatingSearchView   File: FloatingSearchView.java   View source code 6 votes vote down vote up
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
Example 10
Project: android_maplibui   File: BottomToolbar.java   View source code 6 votes vote down vote up
@Override
public void inflateMenu(@MenuRes int resId) {
    super.inflateMenu(resId);
    Menu menu = getMenu();
    MenuItem item = menu.getItem(0);
    int size = item.getIcon().getIntrinsicWidth() + ControlHelper.dpToPx(30, getResources());
    int width = getWidth();

    for (int i = 0; i < menu.size(); i++) {
        item = menu.getItem(i);
        if (size * (i + 2) < width)
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        else
            break;
    }
}
 
Example 11
Project: MaterialMasterDetail   File: CustomAppBar.java   View source code 5 votes vote down vote up
public void setMenuRes(@MenuRes int menuGeneral, @MenuRes int menuSpecific, @MenuRes int menuMerged) {
    toolbarSpecific.getMenu().clear();
    if (toolbarGeneral != null) {
        toolbarGeneral.getMenu().clear();
        toolbarGeneral.inflateMenu(menuGeneral);
        toolbarSpecific.inflateMenu(menuSpecific);
    } else {
        toolbarSpecific.inflateMenu(menuMerged);
    }
}
 
Example 12
Project: IslamicLibraryAndroid   File: BooksCollection.java   View source code 5 votes vote down vote up
@MenuRes
public int getMoreMenuRes() {
    if (isAutomatic()) {
        return R.menu.automatic_collection;
    } else {
        if (!isFavourie()) {
            return R.menu.user_collection;
        } else {
            return R.menu.favourite_collection;
        }
    }
}
 
Example 13
Project: fluentAppBar   File: MenuSecondaryItemsAdapter.java   View source code 5 votes vote down vote up
MenuSecondaryItemsAdapter(Context context, @MenuRes int secondaryMenuId, View.OnClickListener onClickListener,
                                 @ColorInt int foregroundColour) {
    this.context = context;
    this.onClickListener = onClickListener;
    this.foregroundColour = foregroundColour;
    this.itemss = new ArrayList<>();

    MenuParserHelper.parseMenu(context, secondaryMenuId, itemss);
}
 
Example 14
Project: fluentAppBar   File: FluentAppBar.java   View source code 5 votes vote down vote up
public void setNavigationMenu(@MenuRes int menuRes, OnClickListener onClickListener) {
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nav_items_recycler);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
    menuNavigationItemsAdapter = new MenuNavigationItemsAdapter(getContext(), menuRes, onClickListener,
            foregroundColour);
    recyclerView.setAdapter(menuNavigationItemsAdapter);
}
 
Example 15
Project: fluentAppBar   File: FluentAppBar.java   View source code 5 votes vote down vote up
public void setSecondaryMenu(@MenuRes int menuRes, OnClickListener onClickListener) {
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.secondary_menu_items_recyler);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    menuSecondaryItemsAdapter = new MenuSecondaryItemsAdapter(getContext(), menuRes, onClickListener,
            foregroundColour);
    recyclerView.setAdapter(menuSecondaryItemsAdapter);
}
 
Example 16
Project: fluentAppBar   File: MenuParserHelper.java   View source code 5 votes vote down vote up
public static void parseMenu(Context context, @MenuRes int menuRes, List<MenuEntry> menuEntryList){
    PopupMenu p = new PopupMenu(context, null);
    Menu menu = p.getMenu();
    new MenuInflater(context).inflate(menuRes, menu);

    for (int i = 0; i < menu.size(); i++) {
        android.view.MenuItem item = menu.getItem(i);
        menuEntryList.add(new MenuEntry(item.getTitle().toString(), item.getIcon(), item.getItemId()));
    }
}
 
Example 17
Project: fluentAppBar   File: MenuNavigationItemsAdapter.java   View source code 5 votes vote down vote up
MenuNavigationItemsAdapter(Context context, @MenuRes int menuRes, View.OnClickListener onClickListener,
                                  @ColorInt int foregroundColour) {
    this.context = context;
    this.onClickListener = onClickListener;
    this.foregroundColour = foregroundColour;
    this.navItems = new ArrayList<>();

    populateNavigationItems(menuRes);
}
 
Example 18
Project: ChromeLikeTabSwitcher   File: TabSwitcherModel.java   View source code 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 19
Project: QuickActionView   File: QuickActionView.java   View source code 5 votes vote down vote up
/**
 * Add actions to the QuickActionView from the given menu resource id.
 *
 * @param menuId menu resource id
 * @return the QuickActionView
 */
public QuickActionView addActions(@MenuRes int menuId) {
    Menu menu = new MenuBuilder(mContext);
    new MenuInflater(mContext).inflate(menuId, menu);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        Action action = new Action(item.getItemId(), item.getIcon(), item.getTitle());
        addAction(action);
    }
    return this;
}
 
Example 20
Project: NeoTerm   File: TabSwitcherModel.java   View source code 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 21
Project: Material-BottomNavigation   File: BottomNavigation.java   View source code 5 votes vote down vote up
/**
 * Inflate a menu resource into this navigation component
 *
 * @param menuResId the menu resource id
 */
public void inflateMenu(@MenuRes final int menuResId) {
    defaultSelectedIndex = 0;
    if (isAttachedToWindow()) {
        setItems(MenuParser.inflateMenu(getContext(), menuResId));
        pendingMenu = null;
    } else {
        pendingMenu = MenuParser.inflateMenu(getContext(), menuResId);
    }
}
 
Example 22
Project: AndroidSweetSheet-master   File: SweetSheet.java   View source code 5 votes vote down vote up
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
 
Example 23
Project: MoonlightNote   File: MenuUtils.java   View source code 5 votes vote down vote up
/**
 * 显示Popup菜单
 *
 * @param context  上下文
 * @param v        视图
 * @param menu     菜单资源文件
 * @param listener 菜单项目点击监听器
 */
public static void showPopupMenu(@NonNull Context context, @NonNull View v, @MenuRes int menu,
                                 @NonNull PopupMenu.OnMenuItemClickListener listener) {
    //新建PopupMenu对像
    PopupMenu popupMenu = new PopupMenu(context, v);
    //生成Menu视图
    popupMenu.getMenuInflater().inflate(menu, popupMenu.getMenu());
    //setOnMenuItemClickListener
    popupMenu.setOnMenuItemClickListener(listener);
    //显示PopupMenu
    popupMenu.show();
}
 
Example 24
Project: CycleMenu   File: CycleMenuWidget.java   View source code 5 votes vote down vote up
/**
 * Set the menu items from the menu res.
 *
 * @param menuResId menu resource from which need to get menuItems and add to the cycleMenu
 */
public void setMenuRes(@MenuRes int menuResId) {
    mInitialized = false;
    Menu menu = new MenuBuilder(getContext());
    MenuInflater inflater = new MenuInflater(getContext());
    inflater.inflate(menuResId, menu);
    setMenu(menu);
}
 
Example 25
Project: FABRevealMenu-master   File: FABRevealMenu.java   View source code 5 votes vote down vote up
/**
 * Set menu from menu xml
 *
 * @param menuRes menu xml resource
 */
public void setMenu(@MenuRes int menuRes) {
    mCustomView = null;
    mMenuRes = menuRes;
    removeAllViews();
    @SuppressLint("RestrictedApi")
    Menu menu = new MenuBuilder(getContext());
    new MenuInflater(getContext()).inflate(menuRes, menu);
    setUpMenu(menu);
}
 
Example 26
Project: Bottom-sheet-Listview   File: MenuSheetView.java   View source code 5 votes vote down vote up
/**
 * Inflates a menu resource into the menu backing this sheet.
 *
 * @param menuRes Menu resource ID
 */
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes != -1) {
        MenuInflater inflater = new MenuInflater(getContext());
        inflater.inflate(menuRes, menu);
    }

    prepareMenuItems();
}
 
Example 27
Project: Mysplash   File: ThemeManager.java   View source code 5 votes vote down vote up
public static void inflateMenu(Toolbar toolbar,
                               @MenuRes int lightResId, @MenuRes int darkResId) {
    if (getInstance(toolbar.getContext()).isLightTheme()) {
        toolbar.inflateMenu(lightResId);
    } else {
        toolbar.inflateMenu(darkResId);
    }
}
 
Example 28
Project: MousePaintYzz   File: SweetSheet.java   View source code 5 votes vote down vote up
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
 
Example 29
Project: MaterialDrawer   File: DrawerBuilder.java   View source code 5 votes vote down vote up
/**
 * Inflates the DrawerItems from a menu.xml
 *
 * @param menuRes
 * @return
 */
public DrawerBuilder inflateMenu(@MenuRes int menuRes) {
    MenuInflater menuInflater = new SupportMenuInflater(mActivity);
    MenuBuilder mMenu = new MenuBuilder(mActivity);

    menuInflater.inflate(menuRes, mMenu);

    addMenuItems(mMenu, false);

    return this;
}
 
Example 30
Project: YouJoin-Android   File: DrawerBuilder.java   View source code 5 votes vote down vote up
/**
 * Inflates the DrawerItems from a menu.xml
 *
 * @param menuRes
 * @return
 */
public DrawerBuilder inflateMenu(@MenuRes int menuRes) {
    MenuInflater menuInflater = new SupportMenuInflater(mActivity);
    MenuBuilder mMenu = new MenuBuilder(mActivity);

    menuInflater.inflate(menuRes, mMenu);

    addMenuItems(mMenu, false);

    return this;
}
 
Example 31
Project: Climb   File: ToolbarFragment.java   View source code 5 votes vote down vote up
/**
     * @param title 标题
     * @param menu 菜单
     */
    public void setupToolbar(String title, @MenuRes int menu) {

        mToolbar.setTitle(title);
        mToolbar.inflateMenu(menu);
        mToolbar.setOnMenuItemClickListener(this);
        mToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_menu_white));
        mToolbar.setNavigationOnClickListener(v -> {
            OldDriver.getIns().post(new OpenDrawerEvent());
        });
//        ((AppCompatActivity)mActivity).setSupportActionBar(mToolbar);
//        ((AppCompatActivity)mActivity).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    }
 
Example 32
Project: ThreePhasesBottomSheet   File: MenuSheetView.java   View source code 5 votes vote down vote up
/**
 * Inflates a menu resource into the menu backing this sheet.
 *
 * @param menuRes Menu resource ID
 */
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes != -1) {
        MenuInflater inflater = new MenuInflater(getContext());
        inflater.inflate(menuRes, menu);
    }

    prepareMenuItems();
}
 
Example 33
Project: XanderPanel   File: XanderPanel.java   View source code 5 votes vote down vote up
public Builder setMenu(@MenuRes int xmlRes, PanelInterface.PanelMenuListener menuListener) {
    if (null == mPanelParams.actionMenu) {
        mPanelParams.actionMenu = new ActionMenu(mContext);
    }
    (new MenuInflater(mContext)).inflate(xmlRes, mPanelParams.actionMenu);
    mPanelParams.menuListener = menuListener;
    return this;
}
 
Example 34
Project: RecyclerExt   File: MenuViewHolder.java   View source code 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 35
Project: AndroidSweetSheet   File: SweetSheet.java   View source code 5 votes vote down vote up
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
 
Example 36
Project: MousePaint   File: SweetSheet.java   View source code 5 votes vote down vote up
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
 
Example 37
Project: trekarta   File: PanelMenuFragment.java   View source code 5 votes vote down vote up
public void setMenu(@MenuRes int menuId, OnPrepareMenuListener onPrepareMenuListener) {
    mMenuId = menuId;
    mOnPrepareMenuListener = onPrepareMenuListener;
    if (isVisible()) {
        populateMenu();
        mAdapter.notifyDataSetChanged();
    }
}
 
Example 38
Project: vuze-remote-for-android   File: SideActionsAdapter.java   View source code 5 votes vote down vote up
public SideActionsAdapter(Context context, String remoteProfileID,
		@MenuRes int menuRes, @Nullable int[] restrictToMenuIDs,
	SideActionSelectionListener selector) {
	super(selector);
	this.context = context;
	this.remoteProfileID = remoteProfileID;
	this.restrictToMenuIDs = restrictToMenuIDs;
	this.selector = selector;
	setHasStableIds(true);

	menuBuilder = new MenuBuilder(context);
	new MenuInflater(context).inflate(menuRes, menuBuilder);

	updateMenuItems();
}
 
Example 39
Project: material-cab   File: MaterialCab.java   View source code 5 votes vote down vote up
@UiThread
public MaterialCab menu(@MenuRes int menuRes) {
  menu = menuRes;
  if (toolbar != null) {
    if (toolbar.getMenu() != null) {
      toolbar.getMenu().clear();
    }
    if (menuRes != 0) {
      toolbar.inflateMenu(menuRes);
    }
    toolbar.setOnMenuItemClickListener(this);
  }
  return this;
}
 
Example 40
Project: MaterialDrawer-Xamarin   File: DrawerBuilder.java   View source code 5 votes vote down vote up
/**
 * Inflates the DrawerItems from a menu.xml
 *
 * @param menuRes
 * @return
 */
public DrawerBuilder inflateMenu(@MenuRes int menuRes) {
    MenuInflater menuInflater = new SupportMenuInflater(mActivity);
    MenuBuilder mMenu = new MenuBuilder(mActivity);

    menuInflater.inflate(menuRes, mMenu);

    addMenuItems(mMenu, false);

    return this;
}