com.mikepenz.materialdrawer.model.interfaces.IDrawerItem Java Examples

The following examples show how to use com.mikepenz.materialdrawer.model.interfaces.IDrawerItem. 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: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerItemClick(IDrawerItem drawerItem) {
        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case SHOW_ALL:
                    clickAndUpdateMainFragmentData(new ArrayList<String>(), "全部文章",drawerItem.getIdentifier());
                    break;
                case SHOW_STAR:
                    StarActivity.activityStart(MainActivity.this);
                    break;
                case SHOW_DISCOVER:
                    FeedCategoryActivity.activityStart(MainActivity.this);
                    break;
                case DRAWER_FOLDER_ITEM:
//                    ALog.d("名称为" + ((SecondaryDrawerItem) drawerItem).getName() + "id为" + drawerItem.getIdentifier());
                    ArrayList<String> list = new ArrayList<>();
                    list.add(String.valueOf(drawerItem.getIdentifier()));
                    clickAndUpdateMainFragmentData(list, ((SecondaryDrawerItem) drawerItem).getName().toString(),drawerItem.getIdentifier());
                    break;

                case DRAWER_FOLDER:
                    break;

            }
        }

    }
 
Example #2
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerLongClick(IDrawerItem drawerItem) {

        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case DRAWER_FOLDER:
                    //获取到这个文件夹的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedFolderOperationPopupView(MainActivity.this, drawerItem.getIdentifier() - FEED_FOLDER_IDENTIFY_PLUS, ((ExpandableBadgeDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
                case DRAWER_FOLDER_ITEM:
                    //获取到这个feed的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedOperationPopupView(MainActivity.this, drawerItem.getIdentifier(), ((SecondaryDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
            }
        }
    }
 
Example #3
Source File: MyExpandableBadgeDrawerItem.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
    if (drawerItem instanceof AbstractDrawerItem && drawerItem.isEnabled()) {
        if (((AbstractDrawerItem) drawerItem).getSubItems() != null) {
            if (((AbstractDrawerItem) drawerItem).isExpanded()) {
                ViewCompat.animate(view.findViewById(R.id.material_drawer_arrow)).rotation(MyExpandableBadgeDrawerItem.this.arrowRotationAngleEnd).start();
            } else {
                ViewCompat.animate(view.findViewById(R.id.material_drawer_arrow))
                        .rotation(MyExpandableBadgeDrawerItem.this.arrowRotationAngleStart)
                        .start();
            }
        }
    }

    return mOnDrawerItemClickListener != null && mOnDrawerItemClickListener.onItemClick(view, position, drawerItem);
}
 
Example #4
Source File: MyExpandableBadgeDrawerItem.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
    if (drawerItem instanceof AbstractDrawerItem && drawerItem.isEnabled()) {
        if (((AbstractDrawerItem) drawerItem).getSubItems() != null) {
            if (((AbstractDrawerItem) drawerItem).isExpanded()) {
                ViewCompat.animate(view.findViewById(R.id.material_drawer_arrow)).rotation(MyExpandableBadgeDrawerItem.this.arrowRotationAngleEnd).start();
            } else {
                ViewCompat.animate(view.findViewById(R.id.material_drawer_arrow))
                        .rotation(MyExpandableBadgeDrawerItem.this.arrowRotationAngleStart)
                        .start();
            }
        }
    }

    return mOnDrawerItemClickListener != null && mOnDrawerItemClickListener.onItemClick(view, position, drawerItem);
}
 
Example #5
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerItemClick(IDrawerItem drawerItem) {
        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case SHOW_ALL:
                    clickAndUpdateMainFragmentData(new ArrayList<String>(), "全部文章",drawerItem.getIdentifier());
                    break;
                case SHOW_STAR:
                    StarActivity.activityStart(MainActivity.this);
                    break;
                case SHOW_DISCOVER:
                    FeedCategoryActivity.activityStart(MainActivity.this);
                    break;
                case DRAWER_FOLDER_ITEM:
//                    ALog.d("名称为" + ((SecondaryDrawerItem) drawerItem).getName() + "id为" + drawerItem.getIdentifier());
                    ArrayList<String> list = new ArrayList<>();
                    list.add(String.valueOf(drawerItem.getIdentifier()));
                    clickAndUpdateMainFragmentData(list, ((SecondaryDrawerItem) drawerItem).getName().toString(),drawerItem.getIdentifier());
                    break;

                case DRAWER_FOLDER:
                    break;

            }
        }

    }
 
Example #6
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerLongClick(IDrawerItem drawerItem) {

        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case DRAWER_FOLDER:
                    //获取到这个文件夹的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedFolderOperationPopupView(MainActivity.this, drawerItem.getIdentifier() - FEED_FOLDER_IDENTIFY_PLUS, ((ExpandableBadgeDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
                case DRAWER_FOLDER_ITEM:
                    //获取到这个feed的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedOperationPopupView(MainActivity.this, drawerItem.getIdentifier(), ((SecondaryDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
            }
        }
    }
 
Example #7
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
/**
 * call this method to trigger the onItemClick on the MiniDrawer
 *
 * @param selectedDrawerItem
 * @return
 */
public boolean onItemClick(IDrawerItem selectedDrawerItem) {
    //We only need to clear if the new item is selectable
    if (selectedDrawerItem.isSelectable()) {
        //crossfade if we are cross faded
        if (mCrossFader != null) {
            if (mCrossFader.isCrossfaded()) {
                mCrossFader.crossfade();
            }
        }

        //get the identifier
        int identifier = selectedDrawerItem.getIdentifier();

        //update everything
        setSelection(identifier);

        return false;
    } else {
        return true;
    }
}
 
Example #8
Source File: MainActivity.java    From Droid2JoyStick with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
    String item = drawerItem.getTag().toString();
    if (item.equalsIgnoreCase(KEY_DEVICE_CONNECTION)) {
        BluetoothManager.getInstance().openBluetoothConnection(this);
    } else if (item.equalsIgnoreCase("settings")) {
        Log.e("Check", "Settings");
    } else if (item.equalsIgnoreCase(KEY_ASSAULT_HORIZON)) {
        openAssaultHorizonFragment();
    } else if (item.equalsIgnoreCase(KEY_FINAL_FANTASY_XIII)) {
        openFinalFantasyXIIIFragment();
    } else if (item.equalsIgnoreCase(KEY_AWESOMENAUTS)) {
        openAwesomenautsFragment();
    } else if (item.equalsIgnoreCase(KEY_BOMBSQUAD)) {
        openBombSquadFragment();
    } else if (item.equalsIgnoreCase(KEY_BASIC_GAMEPAD_1)) {
        openBasicGamepadFragment();
    }
    return true;
}
 
Example #9
Source File: Drawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
/**
 * method to switch the drawer content to new elements
 *
 * @param onDrawerItemClickListener
 * @param drawerItems
 * @param drawerSelection
 */
public void switchDrawerContent(@NonNull OnDrawerItemClickListener onDrawerItemClickListener, OnDrawerItemLongClickListener onDrawerItemLongClickListener, @NonNull ArrayList<IDrawerItem> drawerItems, int drawerSelection) {
    //just allow a single switched drawer
    if (!switchedDrawerContent()) {
        //save out previous values
        originalOnDrawerItemClickListener = getOnDrawerItemClickListener();
        originalOnDrawerItemLongClickListener = getOnDrawerItemLongClickListener();
        originalDrawerItems = getDrawerItems();
        originalDrawerSelection = getCurrentSelectedPosition();
    }

    //set the new items
    setOnDrawerItemClickListener(onDrawerItemClickListener);
    setOnDrawerItemLongClickListener(onDrawerItemLongClickListener);
    setItems(drawerItems, true);
    setSelectionAtPosition(drawerSelection, false);

    //hide stickyFooter and it's shadow
    if (getStickyFooter() != null) {
        getStickyFooter().setVisibility(View.GONE);
    }
    if (getStickyFooterShadow() != null) {
        getStickyFooterShadow().setVisibility(View.GONE);
    }
}
 
Example #10
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
/**
 * call this method to trigger the onProfileClick on the MiniDrawer
 */
public void onProfileClick() {
    //crossfade if we are cross faded
    if (mCrossFader != null) {
        if (mCrossFader.isCrossfaded()) {
            mCrossFader.crossfade();
        }
    }

    //update the current profile
    if (mAccountHeader != null) {
        IProfile profile = mAccountHeader.getActiveProfile();
        if (profile instanceof IDrawerItem) {
            mDrawerAdapter.setDrawerItem(0, generateMiniDrawerItem((IDrawerItem) profile));
        }
    }
}
 
Example #11
Source File: Drawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * replace the current DrawerItems with the new ArrayList.
 *
 * @param drawerItems
 * @param switchedItems
 */
private void setItems(@NonNull ArrayList<IDrawerItem> drawerItems, boolean switchedItems) {
    //if we are currently at a switched list set the new reference
    if (originalDrawerItems != null && !switchedItems) {
        originalDrawerItems = drawerItems;
        mDrawerBuilder.mCurrentSelection = -1;
    } else {
        mDrawerBuilder.getAdapter().setDrawerItems(drawerItems);
    }

    mDrawerBuilder.mAdapter.notifyDataSetChanged();
}
 
Example #12
Source File: MainActivity.java    From wifi_backend with GNU General Public License v3.0 5 votes vote down vote up
private void updateTitle() {
    IDrawerItem item = drawer == null ? null : drawer.getDrawerItem(drawer.getCurrentSelection());

    if (item != null && item instanceof PrimaryDrawerItem) {
        toolbar.setSubtitle(((PrimaryDrawerItem) item).getName().getText(this));
    } else {
        toolbar.setSubtitle(null);
    }
}
 
Example #13
Source File: HexDrawer.java    From hex with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
    position -= 1;

    this.mHandler.onItemSelectedHandler(
            position <= primaryItems.size() ?
                    primaryItemsOrder.get(position) :
                    secondaryItemsOrder.get(position - (primaryItems.size() + 1)));

    mDrawer.closeDrawer();

    return true;
}
 
Example #14
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * generates a MiniDrawerItem from a IDrawerItem
 *
 * @param drawerItem
 * @return
 */
public IDrawerItem generateMiniDrawerItem(IDrawerItem drawerItem) {
    if (drawerItem instanceof PrimaryDrawerItem) {
        return new MiniDrawerItem((PrimaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground);
    } else if (drawerItem instanceof SecondaryDrawerItem && mIncludeSecondaryDrawerItems) {
        return new MiniDrawerItem((SecondaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground);
    } else if (drawerItem instanceof ProfileDrawerItem) {
        MiniProfileDrawerItem mpdi = new MiniProfileDrawerItem((ProfileDrawerItem) drawerItem);
        mpdi.withEnabled(mEnableProfileClick);
        return mpdi;
    }
    return null;
}
 
Example #15
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 5 votes vote down vote up
@Override
public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {

    int id = (int) drawerItem.getIdentifier();
    switch (id) {

        case ID_TOGGLE_DONE:
            toggleDoneTab();
            break;

        case ID_TOGGLE_BIG_TEXT:
            if (isChecked) {
                HorizontalAdapter.setBigText(true);
                mTinyDB.putBoolean(getString(R.string.big_text_pref), true);
                DatabaseHelper.notifyAllLists();

            } else {
                HorizontalAdapter.setBigText(false);
                mTinyDB.putBoolean(getString(R.string.big_text_pref), false);
                DatabaseHelper.notifyAllLists();
            }
            break;

        case ID_DARK_THEME:
            changeDarkTheme(isChecked);
            break;
    }

}
 
Example #16
Source File: BaseDrawerAdapter.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
public void addFooterDrawerItems(IDrawerItem... drawerItems) {
    if (drawerItems != null) {
        Collections.addAll(mFooterDrawerItems, drawerItems);
        notifyItemRangeInserted(0, drawerItems.length);
    }
    mapPossibleTypes(mFooterDrawerItems);
}
 
Example #17
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * gets the type of a IDrawerItem
 *
 * @param drawerItem
 * @return
 */
public int getMiniDrawerType(IDrawerItem drawerItem) {
    if (drawerItem instanceof MiniProfileDrawerItem) {
        return PROFILE;
    } else if (drawerItem instanceof MiniDrawerItem) {
        return ITEM;
    }
    return -1;
}
 
Example #18
Source File: DrawerUtils.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * helper method to set the selection of the footer
 *
 * @param drawer
 * @param position
 * @param fireOnClick
 */
public static void setStickyFooterSelection(DrawerBuilder drawer, int position, Boolean fireOnClick) {
    if (position > -1) {
        if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
            LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;

            if (footer.getChildCount() > position && position >= 0) {
                IDrawerItem drawerItem = (IDrawerItem) footer.getChildAt(position).getTag();
                onFooterDrawerItemClick(drawer, drawerItem, footer.getChildAt(position), fireOnClick);
            }
        }
    }
}
 
Example #19
Source File: BaseDrawerAdapter.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * internal mapper to remember and add possible types for the RecyclerView
 */
private void mapPossibleTypes(List<IDrawerItem> drawerItemList) {
    if (drawerItemList != null) {
        for (IDrawerItem drawerItem : drawerItemList) {
            mapPossibleType(drawerItem);
        }
    }
}
 
Example #20
Source File: DrawerBuilder.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * Add a initial DrawerItem or a DrawerItem Array for the StickyDrawerFooter
 *
 * @param stickyDrawerItems
 * @return
 */
public DrawerBuilder addStickyDrawerItems(@NonNull IDrawerItem... stickyDrawerItems) {
    if (this.mStickyDrawerItems == null) {
        this.mStickyDrawerItems = new ArrayList<>();
    }

    Collections.addAll(this.mStickyDrawerItems, IdDistributor.checkIds(stickyDrawerItems));

    return this;
}
 
Example #21
Source File: RecyclerViewCacheUtil.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * init the cache on your own.
 *
 * @param recyclerView
 * @param drawerItems
 */
public void init(RecyclerView recyclerView, IDrawerItem... drawerItems) {
    if (drawerItems != null) {
        for (IDrawerItem d : drawerItems) {
            if (!CACHE.containsKey(d.getType())) {
                CACHE.put(d.getType(), new Stack<RecyclerView.ViewHolder>());
            }

            if (CACHE_SIZE == -1 || CACHE.get(d.getType()).size() <= CACHE_SIZE) {
                CACHE.get(d.getType()).push(d.getViewHolder(recyclerView));
            }
        }
    }
}
 
Example #22
Source File: DrawerUtils.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * helper method to fill the sticky footer with it's elements
 *
 * @param drawer
 * @param container
 * @param onClickListener
 */
public static void fillStickyDrawerItemFooter(DrawerBuilder drawer, ViewGroup container, View.OnClickListener onClickListener) {
    //add all drawer items
    for (IDrawerItem drawerItem : drawer.mStickyDrawerItems) {
        //get the selected_color
        int selected_color = UIUtils.getThemeColorFromAttrOrRes(container.getContext(), R.attr.material_drawer_selected, R.color.material_drawer_selected);
        if (drawerItem instanceof PrimaryDrawerItem) {
            selected_color = ColorHolder.color(((PrimaryDrawerItem) drawerItem).getSelectedColor(), container.getContext(), R.attr.material_drawer_selected, R.color.material_drawer_selected);
        } else if (drawerItem instanceof SecondaryDrawerItem) {
            selected_color = ColorHolder.color(((SecondaryDrawerItem) drawerItem).getSelectedColor(), container.getContext(), R.attr.material_drawer_selected, R.color.material_drawer_selected);
        }

        View view = drawerItem.generateView(container.getContext(), container);
        view.setTag(drawerItem);

        if (drawerItem.isEnabled()) {
            UIUtils.setBackground(view, DrawerUIUtils.getSelectableBackground(container.getContext(), selected_color));
            view.setOnClickListener(onClickListener);
        }

        container.addView(view);

        //for android API 17 --> Padding not applied via xml
        DrawerUIUtils.setDrawerVerticalPadding(view);
    }
    //and really. don't ask about this. it won't set the padding if i don't set the padding for the container
    container.setPadding(0, 0, 0, 0);
}
 
Example #23
Source File: SwitchDrawerItem.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void bindView(RecyclerView.ViewHolder holder) {
    //get our viewHolder
    final ViewHolder viewHolder = (ViewHolder) holder;

    //bind the basic view parts
    bindViewHelper((BaseViewHolder) holder);

    //handle the switch
    viewHolder.switchView.setOnCheckedChangeListener(null);
    viewHolder.switchView.setChecked(checked);
    viewHolder.switchView.setOnCheckedChangeListener(checkedChangeListener);
    viewHolder.switchView.setEnabled(switchEnabled);

    //add a onDrawerItemClickListener here to be able to check / uncheck if the drawerItem can't be selected
    withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!isSelectable()) {
                checked = !checked;
                viewHolder.switchView.setChecked(checked);
            }

            return false;
        }
    });

    //call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
    onPostBindView(this, holder.itemView);
}
 
Example #24
Source File: SecondaryToggleDrawerItem.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void bindView(RecyclerView.ViewHolder holder) {
    //get our viewHolder
    final ViewHolder viewHolder = (ViewHolder) holder;

    //bind the basic view parts
    bindViewHelper((BaseViewHolder) holder);

    //handle the toggle
    viewHolder.toggle.setOnCheckedChangeListener(null);
    viewHolder.toggle.setChecked(checked);
    viewHolder.toggle.setOnCheckedChangeListener(checkedChangeListener);
    viewHolder.toggle.setEnabled(toggleEnabled);

    //add a onDrawerItemClickListener here to be able to check / uncheck if the drawerItem can't be selected
    withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!isSelectable()) {
                checked = !checked;
                viewHolder.toggle.setChecked(checked);
            }

            return false;
        }
    });

    //call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
    onPostBindView(this, holder.itemView);
}
 
Example #25
Source File: DrawerItemViewHelper.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
public View build() {
    //create the container view
    LinearLayout linearLayout = new LinearLayout(mContext);
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    //create the divider
    if (mDivider) {
        LinearLayout divider = new LinearLayout(mContext);
        divider.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        divider.setMinimumHeight((int) UIUtils.convertDpToPixel(1, mContext));
        divider.setOrientation(LinearLayout.VERTICAL);
        divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mContext, R.attr.material_drawer_divider, R.color.material_drawer_divider));
        linearLayout.addView(divider);
    }

    //add all drawer items
    for (IDrawerItem drawerItem : mDrawerItems) {
        View view = drawerItem.generateView(mContext);
        view.setTag(drawerItem);

        if (drawerItem.isEnabled()) {
            view.setBackgroundResource(DrawerUIUtils.getSelectableBackground(mContext));
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnDrawerItemClickListener != null) {
                        mOnDrawerItemClickListener.onItemClick(v, (IDrawerItem) v.getTag());
                    }
                }
            });
        }

        linearLayout.addView(view);
    }

    return linearLayout;
}
 
Example #26
Source File: SecondarySwitchDrawerItem.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void bindView(RecyclerView.ViewHolder holder) {
    //get our viewHolder
    final ViewHolder viewHolder = (ViewHolder) holder;

    //bind the basic view parts
    bindViewHelper((BaseViewHolder) holder);

    //handle the switch
    viewHolder.switchView.setOnCheckedChangeListener(null);
    viewHolder.switchView.setChecked(checked);
    viewHolder.switchView.setOnCheckedChangeListener(checkedChangeListener);
    viewHolder.switchView.setEnabled(switchEnabled);

    //add a onDrawerItemClickListener here to be able to check / uncheck if the drawerItem can't be selected
    withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!isSelectable()) {
                checked = !checked;
                viewHolder.switchView.setChecked(checked);
            }

            return false;
        }
    });

    //call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
    onPostBindView(this, holder.itemView);
}
 
Example #27
Source File: BaseDrawerAdapter.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
public void addDrawerItems(IDrawerItem... drawerItems) {
    int length = mDrawerItems.size();
    if (drawerItems != null) {
        Collections.addAll(mDrawerItems, drawerItems);
        mapPossibleTypes(mDrawerItems);
        notifyItemRangeInserted(length, drawerItems.length);
    }
}
 
Example #28
Source File: BaseDrawerAdapter.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
public void addDrawerItems(int position, IDrawerItem... drawerItems) {
    if (drawerItems != null) {
        mDrawerItems.addAll(position, Arrays.asList(drawerItems));
        mapPossibleTypes(mDrawerItems);
        notifyItemRangeInserted(position + 1, drawerItems.length);

        //fix wrong remembered position
        if (position < previousSelection) {
            previousSelection = previousSelection + drawerItems.length;
        }
    }
}
 
Example #29
Source File: MainViewModel.java    From hacker-news-android with Apache License 2.0 5 votes vote down vote up
List<IDrawerItem> getDrawerItems() {
    if (mDrawerItems != null && !mDrawerItems.isEmpty()) {
        return mDrawerItems;
    }

    List<PrimaryDrawerItem> primaryDrawerItems = new ArrayList<>();
    List<SecondaryDrawerItem> secondaryDrawerItems = new ArrayList<>();
    mDrawerItems = new ArrayList<>();

    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_TOP).withName(R.string.title_section_top).withIcon(R.drawable.ic_action_whatshot));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_BEST).withName(R.string.title_section_best).withIcon(R.drawable.ic_action_grade));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_NEWEST).withName(R.string.title_section_newest).withIcon(R.drawable.ic_action_note_add));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_SHOW_HN).withName(R.string.title_section_show).withIcon(R.drawable.ic_action_visibility));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_SHOW_HN_NEW).withName(R.string.title_section_show_new).withIcon(R.drawable.ic_action_visibility));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_ASK).withName(R.string.title_section_ask).withIcon(R.drawable.ic_action_live_help));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_SAVED).withName(R.string.title_section_saved).withIcon(R.drawable.ic_action_archive));
    mDrawerItems.addAll(primaryDrawerItems);

    mDrawerItems.add(new DividerDrawerItem());

    secondaryDrawerItems.add(new SecondaryDrawerItem().withIdentifier(SECTION_SETTINGS).withName(R.string.title_section_settings).withCheckable(false));
    secondaryDrawerItems.add(new SecondaryDrawerItem().withIdentifier(SECTION_ABOUT).withName(R.string.title_section_about).withCheckable(false));

    mDrawerItems.addAll(secondaryDrawerItems);

    return mDrawerItems;
}
 
Example #30
Source File: BaseDrawerAdapter.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
public void addDrawerItem(int position, IDrawerItem drawerItem) {
    mDrawerItems.add(position - getHeaderItemCount(), drawerItem);
    mapPossibleType(drawerItem);
    notifyItemInserted(position);

    //fix wrong remembered position
    if (position < previousSelection) {
        previousSelection = previousSelection + 1;
    }
}