private void AddTabBadge(int tabIndex)
        {
            if (!(_tabLinearLayout.GetChildAt(tabIndex) is ViewGroup view) || tabIndex >= Element.Children.Count)
            {
                return;
            }

            var page = Element.GetChildPageWithBadge(tabIndex);

            var badgeView = view.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var badgeTarget = view.FindChildOfType <TextView>();
                if (badgeTarget == null)
                {
                    Console.WriteLine("Plugin.Badge: No Text view found to attach badge");
                    return;
                }

                //create badge for tab
                badgeView = BadgeView.ForTarget(Context, badgeTarget);
            }

            BadgeViews[page] = badgeView;

            badgeView.UpdateFromElement(page);

            page.PropertyChanged += OnTabbedPagePropertyChanged;
        }
        private void AddTabBadge(int tabIndex)
        {
            if (!(_tabLinearLayout.GetChildAt(tabIndex) is ViewGroup view))
            {
                return;
            }

            var element = Element.Children[tabIndex];

            var badgeView = view.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var badgeTarget = view.FindChildOfType <TextView>();
                if (badgeTarget == null)
                {
                    Console.WriteLine("Plugin.Badge: No Text view found to attach badge");
                    return;
                }

                //create badge for tab
                badgeView = new BadgeView(Context, badgeTarget);
            }

            BadgeViews[element] = badgeView;

            badgeView.UpdateFromElement(element);

            element.PropertyChanged += OnTabbedPagePropertyChanged;
        }
Example #3
0
        private void AddTabBadge(int tabIndex)
        {
            var element = Element.Children[tabIndex];
            var view    = _tabLayout?.GetTabAt(tabIndex).CustomView ?? _tabStrip?.GetChildAt(tabIndex);

            var badgeView = (view as ViewGroup)?.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var imageView = (view as ViewGroup)?.FindChildOfType <ImageView>();

                var badgeTarget = imageView?.Drawable != null
                    ? (Android.Views.View)imageView
                    : (view as ViewGroup)?.FindChildOfType <TextView>();

                //create badge for tab
                badgeView = new BadgeView(Context, badgeTarget);
            }

            BadgeViews[element] = badgeView;

            badgeView.UpdateFromElement(element);

            element.PropertyChanged -= OnTabbedPagePropertyChanged;
            element.PropertyChanged += OnTabbedPagePropertyChanged;
        }
Example #4
0
        private void AddTabBadge(int tabIndex)
        {
            var element = Element.Children[tabIndex];
            var view    = _tabLayout?.GetTabAt(tabIndex).CustomView ?? _tabStrip?.GetChildAt(tabIndex);

            var badgeView = (view as ViewGroup)?.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var imageView = (view as ViewGroup)?.FindChildOfType <ImageView>();

                var badgeTarget = imageView?.Drawable != null
                    ? (Android.Views.View)imageView
                    : (view as ViewGroup)?.FindChildOfType <TextView>();

                //create badge for tab
                badgeView = new BadgeView(Context, badgeTarget);
            }

            BadgeViews[element] = badgeView;

            //get text
            var badgeText = TabBadge.GetBadgeText(element);

            badgeView.Text = badgeText;

            // set color if not default
            var tabColor = TabBadge.GetBadgeColor(element);

            if (tabColor != Color.Default)
            {
                badgeView.BadgeColor = tabColor.ToAndroid();
            }

            // set text color if not default
            var tabTextColor = TabBadge.GetBadgeTextColor(element);

            if (tabTextColor != Color.Default)
            {
                badgeView.TextColor = tabTextColor.ToAndroid();
            }

            // set font if not default
            var font = TabBadge.GetBadgeFont(element);

            if (font != Font.Default)
            {
                badgeView.Typeface = font.ToTypeface();
            }

            var margin = TabBadge.GetBadgeMargin(element);

            badgeView.SetMargins((float)margin.Left, (float)margin.Top, (float)margin.Right, (float)margin.Bottom);

            // set position
            badgeView.Postion = TabBadge.GetBadgePosition(element);

            element.PropertyChanged += OnTabbedPagePropertyChanged;
        }
        private void AddTabBadge(int tabIndex)
        {
            var element = Element.Children[tabIndex];

            if (element is NavigationPage navigationPage)
            {
                //if the child page is a navigation page get its root page
                element = navigationPage.RootPage;
            }

            var placement  = Element.OnThisPlatform().GetToolbarPlacement();
            var targetView = placement == ToolbarPlacement.Bottom ? _bottomTabStrip?.GetChildAt(tabIndex) : _topTabLayout?.GetTabAt(tabIndex).CustomView ?? _topTabStrip?.GetChildAt(tabIndex);

            if (!(targetView is ViewGroup target))
            {
                Console.WriteLine("Plugin.Badge: Badge target cannot be null. Badge not added.");
                return;
            }

            var badgeView = target.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                if (placement == ToolbarPlacement.Bottom)
                {
                    // create for entire tab layout
                    badgeView = BadgeView.ForLayout(Context, target);
                }
                else
                {
                    var imageView = target.FindChildOfType <ImageView>();

                    //create badge for tab image or text
                    badgeView = BadgeView.ForView(Context, imageView?.Drawable != null
                        ? (Android.Views.View)imageView
                        : target.FindChildOfType <TextView>());
                }
            }

            BadgeViews[element] = badgeView;
            badgeView.UpdateFromElement(element);
            element.PropertyChanged -= OnTabbedPagePropertyChanged;
            element.PropertyChanged += OnTabbedPagePropertyChanged;
        }
Example #6
0
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <TabbedPage> e)
        {
            base.OnElementChanged(e);

            var tabLayout = FindChildOfType <TabLayout>(ViewGroup);

            if (tabLayout == null)
            {
                return;
            }

            var tabStrip = FindChildOfType <TabLayout.SlidingTabStrip>(tabLayout);

            BadgeViews = new BadgeView[tabLayout.TabCount];
            for (var i = 0; i < tabLayout.TabCount; i++)
            {
                var tab       = tabLayout.GetTabAt(i);
                var view      = tab.CustomView ?? tabStrip?.GetChildAt(i);
                var imageView = FindChildOfType <ImageView>(view as ViewGroup);

                var badgeTarget = imageView?.Drawable != null ? (Android.Views.View)imageView : FindChildOfType <TextView>(view as ViewGroup);

                //create bage for tab
                BadgeViews[i] = new BadgeView(Context, badgeTarget);

                //get text
                var badgeText = TabBadge.GetBadgeText(Element.Children[i]);
                BadgeViews[i].Text = badgeText;

                // set color if not default
                var tabColor = TabBadge.GetBadgeColor(Element.Children[i]);
                if (tabColor != Color.Default)
                {
                    BadgeViews[i].BadgeColor = tabColor.ToAndroid();
                }

                Element.Children[i].PropertyChanged += OnTabPagePropertyChanged;
            }
        }
Example #7
0
        public static void UpdateFromPropertyChangedEvent(this BadgeView badgeView, Element element, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == TabBadge.BadgeTextProperty.PropertyName)
            {
                badgeView.Text = TabBadge.GetBadgeText(element);
                return;
            }

            if (e.PropertyName == TabBadge.BadgeColorProperty.PropertyName)
            {
                badgeView.BadgeColor = TabBadge.GetBadgeColor(element).ToAndroid();
                return;
            }

            if (e.PropertyName == TabBadge.BadgeTextColorProperty.PropertyName)
            {
                badgeView.TextColor = TabBadge.GetBadgeTextColor(element).ToAndroid();
                return;
            }

            if (e.PropertyName == TabBadge.BadgeFontProperty.PropertyName)
            {
                badgeView.Typeface = TabBadge.GetBadgeFont(element).ToTypeface();
                return;
            }

            if (e.PropertyName == TabBadge.BadgePositionProperty.PropertyName)
            {
                badgeView.Postion = TabBadge.GetBadgePosition(element);
                return;
            }

            if (e.PropertyName == TabBadge.BadgeMarginProperty.PropertyName)
            {
                var margin = TabBadge.GetBadgeMargin(element);
                badgeView.SetMargins((float)margin.Left, (float)margin.Top, (float)margin.Right, (float)margin.Bottom);
                return;
            }
        }
Example #8
0
        public static void UpdateFromElement(this BadgeView badgeView, Page element)
        {
            //get text
            var badgeText = TabBadge.GetBadgeText(element);

            badgeView.Text = badgeText;

            // set color if not default
            var tabColor = TabBadge.GetBadgeColor(element);

            if (tabColor != Color.Default)
            {
                badgeView.BadgeColor = tabColor.ToAndroid();
            }

            // set text color if not default
            var tabTextColor = TabBadge.GetBadgeTextColor(element);

            if (tabTextColor != Color.Default)
            {
                badgeView.TextColor = tabTextColor.ToAndroid();
            }

            // set font if not default
            var font = TabBadge.GetBadgeFont(element);

            if (font != Font.Default)
            {
                badgeView.Typeface = font.ToTypeface();
            }

            var margin = TabBadge.GetBadgeMargin(element);

            badgeView.SetMargins((float)margin.Left, (float)margin.Top, (float)margin.Right, (float)margin.Bottom);

            // set position
            badgeView.Postion = TabBadge.GetBadgePosition(element);
        }
Example #9
0
        private void AddTabBadge(int tabIndex)
        {
            var page = Element.GetChildPageWithBadge(tabIndex);

            var placement  = Element.OnThisPlatform().GetToolbarPlacement();
            var targetView = placement == ToolbarPlacement.Bottom ? _bottomTabStrip?.GetChildAt(tabIndex) : _topTabLayout?.GetTabAt(tabIndex).CustomView ?? _topTabStrip?.GetChildAt(tabIndex);

            if (!(targetView is ViewGroup targetLayout))
            {
                Console.WriteLine("Plugin.Badge: Badge target cannot be null. Badge not added.");
                return;
            }

            var badgeView = targetLayout.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var imageView = targetLayout.FindChildOfType <ImageView>();
                if (placement == ToolbarPlacement.Bottom)
                {
                    // create for entire tab layout
                    badgeView = BadgeView.ForTargetLayout(Context, imageView);
                }
                else
                {
                    //create badge for tab image or text
                    badgeView = BadgeView.ForTarget(Context, imageView?.Drawable != null
                        ? (Android.Views.View)imageView
                        : targetLayout.FindChildOfType <TextView>());
                }
            }

            BadgeViews[page] = badgeView;
            badgeView.UpdateFromElement(page);

            page.PropertyChanged -= OnTabbedPagePropertyChanged;
            page.PropertyChanged += OnTabbedPagePropertyChanged;
        }
Example #10
0
        private void AddTabBadge(int tabIndex)
        {
            var element = Element.Children[tabIndex];
            var view    = _tabLayout?.GetTabAt(tabIndex).CustomView ?? _tabStrip?.GetChildAt(tabIndex);

            var badgeView = (view as ViewGroup)?.FindChildOfType <BadgeView>();

            if (badgeView == null)
            {
                var imageView = (view as ViewGroup)?.FindChildOfType <ImageView>();

                var badgeTarget = imageView?.Drawable != null
                    ? (Android.Views.View)imageView
                    : (view as ViewGroup)?.FindChildOfType <TextView>();

                //create badge for tab
                badgeView = new BadgeView(Context, badgeTarget);
            }

            BadgeViews[element] = badgeView;

            //get text
            var badgeText = TabBadge.GetBadgeText(element);

            badgeView.Text = badgeText;

            // set color if not default
            var tabColor = TabBadge.GetBadgeColor(element);

            if (tabColor != Color.Default)
            {
                badgeView.BadgeColor = tabColor.ToAndroid();
            }

            element.PropertyChanged += OnTabbedPagePropertyChanged;
        }