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(); } }
@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; } }
@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; } }
@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(); } }
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(); } }
/** * 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); }
/** * 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(); } }; }
@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; } }
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); } }
@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; } } }
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); }
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); }
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); }
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())); } }
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); }
@Override public final void inflateToolbarMenu(@MenuRes final int resourceId, @Nullable final OnMenuItemClickListener listener) { this.toolbarMenuId = resourceId; this.toolbarMenuItemListener = listener; notifyOnToolbarMenuInflated(resourceId, listener); }
/** * 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; }
/** * 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); } }
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; } }
/** * 显示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(); }
/** * 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); }
/** * 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); }
/** * 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(); }
public static void inflateMenu(Toolbar toolbar, @MenuRes int lightResId, @MenuRes int darkResId) { if (getInstance(toolbar.getContext()).isLightTheme()) { toolbar.inflateMenu(lightResId); } else { toolbar.inflateMenu(darkResId); } }
/** * 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; }
/** * @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); }
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; }
/** * 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(); }
public void setMenu(@MenuRes int menuId, OnPrepareMenuListener onPrepareMenuListener) { mMenuId = menuId; mOnPrepareMenuListener = onPrepareMenuListener; if (isVisible()) { populateMenu(); mAdapter.notifyDataSetChanged(); } }
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(); }
@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; }