Search in sources :

Example 6 with BottomNavigationMenuView

use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.

the class BottomNavigationViewEx method setCurrentItem.

/**
 * set the current checked item
 *
 * @param item start from 0.
 */
public void setCurrentItem(int item) {
    // check bounds
    if (item < 0 || item >= getMaxItemCount()) {
        throw new ArrayIndexOutOfBoundsException("item is out of bounds, we expected 0 - " + (getMaxItemCount() - 1) + ". Actually " + item);
    }
    /*
        1. get field in this class
        private final BottomNavigationMenuView mMenuView;

        2. get field in mMenuView
        private BottomNavigationItemView[] mButtons;
        private final OnClickListener mOnClickListener;

        3. call mOnClickListener.onClick();
         */
    // 1. get mMenuView
    BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
    // 2. get mButtons
    BottomNavigationItemView[] mButtons = getBottomNavigationItemViews();
    // get mOnClickListener
    View.OnClickListener mOnClickListener = getField(mMenuView.getClass(), mMenuView, "mOnClickListener");
    // System.out.println("mMenuView:" + mMenuView + " mButtons:" + mButtons + " mOnClickListener" + mOnClickListener);
    // 3. call mOnClickListener.onClick();
    mOnClickListener.onClick(mButtons[item]);
}
Also used : BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView) BottomNavigationItemView(android.support.design.internal.BottomNavigationItemView) BottomNavigationItemView(android.support.design.internal.BottomNavigationItemView) BottomNavigationView(android.support.design.widget.BottomNavigationView) ImageView(android.widget.ImageView) BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView) TextView(android.widget.TextView) View(android.view.View)

Example 7 with BottomNavigationMenuView

use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.

the class BottomNavigationViewEx method getBottomNavigationItemViews.

/**
 * get private mButtons in mMenuView
 *
 * @return
 */
public BottomNavigationItemView[] getBottomNavigationItemViews() {
    if (null != mButtons)
        return mButtons;
    /*
         * 1 private final BottomNavigationMenuView mMenuView;
         * 2 private BottomNavigationItemView[] mButtons;
         */
    BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
    mButtons = getField(mMenuView.getClass(), mMenuView, "mButtons");
    return mButtons;
}
Also used : BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView)

Example 8 with BottomNavigationMenuView

use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.

the class BottomNavigationViewEx method setTextVisibility.

/**
 * change the visibility of text
 *
 * @param visibility
 */
public void setTextVisibility(boolean visibility) {
    this.textVisibility = visibility;
    /*
        1. get field in this class
        private final BottomNavigationMenuView mMenuView;

        2. get field in mButtons
        private BottomNavigationItemView[] mButtons;

        3. set text size in mButtons
        private final TextView mLargeLabel
        private final TextView mSmallLabel

        4. change mItemHeight to only icon size in mMenuView
         */
    // 1. get mMenuView
    BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
    // 2. get mButtons
    BottomNavigationItemView[] mButtons = getBottomNavigationItemViews();
    // 3. change field mShiftingMode value in mButtons
    for (BottomNavigationItemView button : mButtons) {
        TextView mLargeLabel = getField(button.getClass(), button, "mLargeLabel");
        TextView mSmallLabel = getField(button.getClass(), button, "mSmallLabel");
        if (!visibility) {
            // if not record the font size, record it
            if (!visibilityTextSizeRecord && !animationRecord) {
                visibilityTextSizeRecord = true;
                mLargeLabelSize = mLargeLabel.getTextSize();
                mSmallLabelSize = mSmallLabel.getTextSize();
            }
            // if not visitable, set font size to 0
            mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0);
            mSmallLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0);
        } else {
            // if not record the font size, we need do nothing.
            if (!visibilityTextSizeRecord)
                break;
            // restore it
            mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeLabelSize);
            mSmallLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSmallLabelSize);
        }
    }
    // 4 change mItemHeight to only icon size in mMenuView
    if (!visibility) {
        // if not record mItemHeight
        if (!visibilityHeightRecord) {
            visibilityHeightRecord = true;
            mItemHeight = getItemHeight();
        }
        // change mItemHeight to only icon size in mMenuView
        // private final int mItemHeight;
        // change mItemHeight
        // System.out.println("mLargeLabel.getMeasuredHeight():" + getFontHeight(mSmallLabelSize));
        setItemHeight(mItemHeight - getFontHeight(mSmallLabelSize));
    } else {
        // if not record the mItemHeight, we need do nothing.
        if (!visibilityHeightRecord)
            return;
        // restore mItemHeight
        setItemHeight(mItemHeight);
    }
    mMenuView.updateMenuView();
}
Also used : TextView(android.widget.TextView) BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView) BottomNavigationItemView(android.support.design.internal.BottomNavigationItemView)

Example 9 with BottomNavigationMenuView

use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.

the class BottomNavigationViewEx method enableShiftingMode.

/**
 * enable the shifting mode for navigation
 *
 * @param enable It will has a shift animation if true. Otherwise all items are the same width.
 */
public void enableShiftingMode(boolean enable) {
    /*
        1. get field in this class
        private final BottomNavigationMenuView mMenuView;

        2. change field mShiftingMode value in mMenuView
        private boolean mShiftingMode = true;
         */
    // 1. get mMenuView
    BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
    // 2. change field mShiftingMode value in mMenuView
    setField(mMenuView.getClass(), mMenuView, "mShiftingMode", enable);
    mMenuView.updateMenuView();
}
Also used : BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView)

Example 10 with BottomNavigationMenuView

use of android.support.design.internal.BottomNavigationMenuView in project Awesome-WanAndroid by JsonChao.

the class BottomNavigationViewHelper method disableShiftMode.

@SuppressLint("RestrictedApi")
public static void disableShiftMode(BottomNavigationView view) {
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
    try {
        Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
        shiftingMode.setAccessible(true);
        shiftingMode.setBoolean(menuView, false);
        shiftingMode.setAccessible(false);
        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
            // noinspection RestrictedApi
            item.setShiftingMode(false);
            // set once again checked value, so view will be updated
            // noinspection RestrictedApi
            item.setChecked(item.getItemData().isChecked());
        }
    } catch (NoSuchFieldException e) {
        Log.e("BNVHelper", "Unable to get shift mode field", e);
    } catch (IllegalAccessException e) {
        Log.e("BNVHelper", "Unable to change value of shift mode", e);
    }
}
Also used : Field(java.lang.reflect.Field) BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView) BottomNavigationItemView(android.support.design.internal.BottomNavigationItemView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

BottomNavigationMenuView (android.support.design.internal.BottomNavigationMenuView)16 BottomNavigationItemView (android.support.design.internal.BottomNavigationItemView)12 Field (java.lang.reflect.Field)6 TextView (android.widget.TextView)4 SuppressLint (android.annotation.SuppressLint)3 ImageView (android.widget.ImageView)2 Paint (android.graphics.Paint)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 Transition (android.support.transition.Transition)1 TransitionSet (android.support.transition.TransitionSet)1 View (android.view.View)1