/////////////////////////////////////////////////////////////////////////// // Internal Methods /////////////////////////////////////////////////////////////////////////// private void refreshDrawable() { if (WeakReferenceValid) { TextView textView = (TextView)mTextViewRef.Get(); textView.SetBackgroundDrawable(BottomNavigationHelper.getBadgeDrawable(this, textView.Context)); } }
/// <summary> /// Internal Method to select a tab /// </summary> /// <param name="newPosition"> to select a tab after bottom navigation bar is initialised </param> /// <param name="firstTab"> if firstTab the no ripple animation will be done </param> /// <param name="callListener"> is listener callbacks enabled for this change </param> /// <param name="forcedSelection"> if bottom navigation bar forced to select tab (in this case call on selected irrespective of previous state </param> private void selectTabInternal(int newPosition, bool firstTab, bool callListener, bool forcedSelection) { int oldPosition = mSelectedPosition; if (mSelectedPosition != newPosition) { if (mBackgroundStyle == BackgroundStyle.BACKGROUND_STYLE_STATIC) { if (mSelectedPosition != -1) { mBottomNavigationTabs[mSelectedPosition].unSelect(true, mAnimationDuration); } mBottomNavigationTabs[newPosition].Select(true, mAnimationDuration); } else if (mBackgroundStyle == BackgroundStyle.BACKGROUND_STYLE_RIPPLE) { if (mSelectedPosition != -1) { mBottomNavigationTabs[mSelectedPosition].unSelect(false, mAnimationDuration); } mBottomNavigationTabs[newPosition].Select(false, mAnimationDuration); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final BottomNavigationTab clickedView = mBottomNavigationTabs.get(newPosition); BottomNavigationTab clickedView = mBottomNavigationTabs[newPosition]; if (firstTab) { // Running a ripple on the opening app won't be good so on firstTab this won't run. mContainer.SetBackgroundColor(new Color(clickedView.ActiveColor)); mBackgroundOverlay.Visibility = ViewStates.Gone; } else { mBackgroundOverlay.Post(() => { // try { BottomNavigationHelper.setBackgroundWithRipple(clickedView, mContainer, mBackgroundOverlay, clickedView.ActiveColor, mRippleAnimationDuration); // } catch (Exception e) { // mContainer.setBackgroundColor(clickedView.getActiveColor()); // mBackgroundOverlay.setVisibility(ViewStates.Gone); // } }); } } mSelectedPosition = newPosition; } ThreadPool.QueueUserWorkItem(o => { if (callListener) { sendListenerCall(oldPosition, newPosition, forcedSelection); } }); }
/////////////////////////////////////////////////////////////////////////// // Internal Methods of the class /////////////////////////////////////////////////////////////////////////// /// <summary> /// Internal method to setup tabs /// </summary> /// <param name="bottomNavigationTab"> Tab item </param> /// <param name="currentItem"> data structure for tab item </param> /// <param name="itemWidth"> tab item in-active width </param> /// <param name="itemActiveWidth"> tab item active width </param> private void setUpTab(BottomNavigationTab bottomNavigationTab, BottomNavigationItem currentItem, int itemWidth, int itemActiveWidth) { bottomNavigationTab.InactiveWidth = itemWidth; bottomNavigationTab.ActiveWidth = itemActiveWidth; bottomNavigationTab.Position = mBottomNavigationItems.IndexOf(currentItem); bottomNavigationTab.SetOnClickListener(new OnClickListenerAnonymousInnerClass(this)); mBottomNavigationTabs.Add(bottomNavigationTab); BottomNavigationHelper.bindTabWithData(currentItem, bottomNavigationTab, this); bottomNavigationTab.initialise(mBackgroundStyle == BackgroundStyle.BACKGROUND_STYLE_STATIC); mTabContainer.AddView(bottomNavigationTab); }
/////////////////////////////////////////////////////////////////////////// // Initialise Method /////////////////////////////////////////////////////////////////////////// /// <summary> /// This method should be called at the end of all customisation method. /// This method will take all changes in to consideration and redraws tabs. /// </summary> public virtual void Initialise() { mSelectedPosition = DEFAULT_SELECTED_POSITION; mBottomNavigationTabs.Clear(); if (mBottomNavigationItems.Count > 0) { mTabContainer.RemoveAllViews(); if (mMode == Mode.MODE_DEFAULT) { if (mBottomNavigationItems.Count <= MIN_SIZE) { mMode = Mode.MODE_FIXED; } else { mMode = Mode.MODE_SHIFTING; } } if (mBackgroundStyle == BackgroundStyle.BACKGROUND_STYLE_DEFAULT) { if (mMode == Mode.MODE_FIXED) { mBackgroundStyle = BackgroundStyle.BACKGROUND_STYLE_STATIC; } else { mBackgroundStyle = BackgroundStyle.BACKGROUND_STYLE_RIPPLE; } } if (mBackgroundStyle == BackgroundStyle.BACKGROUND_STYLE_STATIC) { mBackgroundOverlay.Visibility = ViewStates.Gone; mContainer.SetBackgroundColor(new Color(mBackgroundColor)); } int screenWidth = Utils.getScreenWidth(Context); if (mMode == Mode.MODE_FIXED) { int[] widths = BottomNavigationHelper.getMeasurementsForFixedMode(Context, screenWidth, mBottomNavigationItems.Count, mScrollable); int itemWidth = widths[0]; foreach (BottomNavigationItem currentItem in mBottomNavigationItems) { FixedBottomNavigationTab bottomNavigationTab = new FixedBottomNavigationTab(Context); setUpTab(bottomNavigationTab, currentItem, itemWidth, itemWidth); } } else if (mMode == Mode.MODE_SHIFTING) { int[] widths = BottomNavigationHelper.getMeasurementsForShiftingMode(Context, screenWidth, mBottomNavigationItems.Count, mScrollable); int itemWidth = widths[0]; int itemActiveWidth = widths[1]; foreach (BottomNavigationItem currentItem in mBottomNavigationItems) { ShiftingBottomNavigationTab bottomNavigationTab = new ShiftingBottomNavigationTab(Context); setUpTab(bottomNavigationTab, currentItem, itemWidth, itemActiveWidth); } } if (mBottomNavigationTabs.Count > mFirstSelectedPosition) { selectTabInternal(mFirstSelectedPosition, true, false, false); } else if (mBottomNavigationTabs.Count > 0) { selectTabInternal(0, true, false, false); } } }