Example #1
0
        /// <summary>
        /// Attach the specified view and savedInstanceState.
        /// </summary>
        /// <returns>The attach.</returns>
        /// <param name="view">View.</param>
        /// <param name="savedInstanceState">Saved instance state.</param>
        public static BottomBar Attach(View view, Bundle savedInstanceState)
        {
            BottomBar bottomBar = new BottomBar(view.Context);

            bottomBar.OnRestoreInstanceState(savedInstanceState);

            ViewGroup contentView = (ViewGroup)view.Parent;

            if (contentView != null)
            {
                View oldLayout = contentView.GetChildAt(0);
                contentView.RemoveView(oldLayout);

                bottomBar.PendingUserContentView = oldLayout;
                contentView.AddView(bottomBar, 0);
            }
            else
            {
                bottomBar.PendingUserContentView = view;
            }

            return(bottomBar);
        }
Example #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <TabbedPageBottom> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null)
            {
                TabbedPageBottom bottomBarPage = e.NewElement;

                if (_bottomBar == null)
                {
                    _pageController = PageController.Create(bottomBarPage);

                    // create a view which will act as container for Page's
                    _frameLayout = new FrameLayout(Context);
                    _frameLayout.LayoutParameters = new FrameLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent, GravityFlags.Fill);
                    AddView(_frameLayout, 0);

                    // create bottomBar control
                    _bottomBar = BottomBar.Attach(_frameLayout, null);
                    _bottomBar.NoTabletGoodness();

                    _bottomBar.UseFixedMode();

                    _bottomBar.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                    _bottomBar.SetOnTabClickListener(this);

                    // create tab items
                    SetTabItems();
                }

                if (bottomBarPage.CurrentPage != null)
                {
                    SwitchContent(bottomBarPage.CurrentPage);
                    UpdateSelectedTabIndex(Element.CurrentPage);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Navs the bar magic.
        /// </summary>
        /// <param name="activity">Activity.</param>
        /// <param name="bottomBar">Bottom bar.</param>
        private static void NavBarMagic(Activity activity, BottomBar bottomBar)
        {
            var res = activity.Resources;

            int softMenuIdentifier = res.GetIdentifier("config_showNavigationBar", "bool", "android");
            int navBarIdentifier   = res.GetIdentifier("navigation_bar_height", "dimen", "android");
            int navBarHeight       = 0;

            if (navBarIdentifier > 0)
            {
                navBarHeight = res.GetDimensionPixelSize(navBarIdentifier);
            }

            if (!bottomBar.DrawBehindNavBar || navBarHeight == 0)
            {
                return;
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich &&
                ViewConfiguration.Get(activity).HasPermanentMenuKey)
            {
                return;
            }

            if (Build.VERSION.SdkInt < BuildVersionCodes.JellyBeanMr1 &&
                (!(softMenuIdentifier > 0 && res.GetBoolean(softMenuIdentifier))))
            {
                return;
            }

            /* Copy-paste coding made possible by: http://stackoverflow.com/a/14871974/940036 */
            if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
            {
                var d = activity.WindowManager.DefaultDisplay;

                DisplayMetrics realDisplayMetrics = new DisplayMetrics();
                d.GetRealMetrics(realDisplayMetrics);

                int realHeight = realDisplayMetrics.HeightPixels;
                int realWidth  = realDisplayMetrics.WidthPixels;

                DisplayMetrics displayMetrics = new DisplayMetrics();
                d.GetMetrics(displayMetrics);

                int displayHeight = displayMetrics.HeightPixels;
                int displayWidth  = displayMetrics.WidthPixels;

                var hasSoftwareKeys = (realWidth - displayWidth) > 0 ||
                                      (realHeight - displayHeight) > 0;

                if (!hasSoftwareKeys)
                {
                    return;
                }
            }
            /* End of delicious copy-paste code */

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat &&
                res.Configuration.Orientation == Android.Content.Res.Orientation.Portrait)
            {
                activity.Window.Attributes.Flags |= WindowManagerFlags.TranslucentNavigation;

                View outerContainer   = bottomBar.OuterContainer;
                int  navBarHeightCopy = navBarHeight;
                bottomBar.ViewTreeObserver.AddOnGlobalLayoutListener(new NavBarMagicOnGlobalLayoutListener(bottomBar, outerContainer, navBarHeightCopy, bottomBar._isTabletMode));
            }
        }