示例#1
0
        public static void UpdateTitleIcon(this AToolbar nativeToolbar, Toolbar toolbar)
        {
            _ = nativeToolbar.Context ?? throw new ArgumentNullException(nameof(nativeToolbar.Context));
            _ = toolbar?.Handler?.MauiContext ?? throw new ArgumentNullException(nameof(toolbar.Handler.MauiContext));

            ImageSource source = toolbar.TitleIcon;

            if (source == null || source.IsEmpty)
            {
                if (nativeToolbar.GetChildAt(0) is ToolbarTitleIconImageView existingImageView)
                {
                    nativeToolbar.RemoveView(existingImageView);
                }

                return;
            }

            var iconView = new ToolbarTitleIconImageView(nativeToolbar.Context);

            nativeToolbar.AddView(iconView, 0);
            iconView.SetImageResource(global::Android.Resource.Color.Transparent);

            source.LoadImage(toolbar.Handler.MauiContext, (result) =>
            {
                iconView.SetImageDrawable(result?.Value);
                AutomationPropertiesProvider.AccessibilitySettingsChanged(iconView, source);
            });
        }
        AImageButton CreateImageButton(Context context, BindableObject bindable, BindableProperty property, int defaultImage, int leftMargin, int rightMargin, string tag)
        {
            var result = new AImageButton(context);

            result.Tag = tag;
            result.SetPadding(0, 0, 0, 0);
            result.Focusable = false;
            result.SetScaleType(ImageView.ScaleType.FitCenter);

            if (bindable.GetValue(property) is ImageSource image)
            {
                AutomationPropertiesProvider.SetContentDescription(result, image, null, null);
            }

            new ImageSourceLoader()
            {
                Source      = (ImageSource)bindable.GetValue(property),
                MauiContext = MauiContext
            }.LoadImage(result);

            var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent)
            {
                LeftMargin  = leftMargin,
                RightMargin = rightMargin
            };

            result.LayoutParameters = lp;
            lp.Dispose();
            result.SetBackground(null);

            return(result);
        }
        void UpdateTitleIcon()
        {
            Page currentPage = CurrentPage;

            if (currentPage == null)
            {
                return;
            }

            ImageSource source = NavigationPage.GetTitleIconImageSource(currentPage);

            if (source == null || source.IsEmpty)
            {
                Toolbar.RemoveView(_titleIconView);
                _titleIconView?.Dispose();
                _titleIconView = null;
                _imageSource   = null;
                return;
            }

            if (_titleIconView == null)
            {
                _titleIconView = new Android.Widget.ImageView(NavigationLayout.Context);
                Toolbar.AddView(_titleIconView, 0);
            }

            if (_imageSource != source)
            {
                _imageSource = source;
                _titleIconView.SetImageResource(global::Android.Resource.Color.Transparent);

                ImageSourceLoader.LoadImage(source, MauiContext, (result) =>
                {
                    _titleIconView.SetImageDrawable(result.Value);
                    AutomationPropertiesProvider.AccessibilitySettingsChanged(_titleIconView, source);
                });
            }
        }
        void OnTabLayoutChange(object sender, AView.LayoutChangeEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            var items = SectionController.GetItems();

            for (int i = 0; i < _tablayout.TabCount; i++)
            {
                if (items.Count <= i)
                {
                    break;
                }

                var tab = _tablayout.GetTabAt(i);

                if (tab.View != null)
                {
                    AutomationPropertiesProvider.AccessibilitySettingsChanged(tab.View, items[i]);
                }
            }
        }
示例#5
0
 void UpdateAutomationId()
 {
     AutomationPropertiesProvider
     .SetAutomationId(_editText, _searchHandler?.AutomationId);
 }
        void RegisterToolbar()
        {
            Context  context = NavigationLayout.Context;
            AToolbar bar     = Toolbar;
            Element  page    = NavigationView.RealParent;

            _flyoutPage = null;
            while (page != null)
            {
                if (page is FlyoutPage)
                {
                    _flyoutPage = page as FlyoutPage;
                    break;
                }
                page = page.RealParent;
            }

            if (_flyoutPage == null)
            {
                if (PageController.InternalChildren.Count > 0)
                {
                    _flyoutPage = PageController.InternalChildren[0] as FlyoutPage;
                }

                if (_flyoutPage == null)
                {
                    return;
                }
            }

            if (((IFlyoutPageController)_flyoutPage).ShouldShowSplitMode)
            {
                return;
            }

            var renderer = _flyoutPage.ToNative(NavigationView.Handler.MauiContext) as DrawerLayout;

            if (renderer == null)
            {
                return;
            }

            _drawerLayout = renderer;

            AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _flyoutPage, out int resourceIdOpen, out int resourceIdClose);

            if (_drawerToggle != null)
            {
                _drawerToggle.ToolbarNavigationClickListener = null;
                _drawerToggle.Dispose();
            }

            _drawerToggle = new ActionBarDrawerToggle(context.GetActivity(), _drawerLayout, bar,
                                                      resourceIdOpen == 0 ? global::Android.Resource.String.Ok : resourceIdOpen,
                                                      resourceIdClose == 0 ? global::Android.Resource.String.Ok : resourceIdClose)
            {
                ToolbarNavigationClickListener = new ClickListener(NavigationView)
            };

            if (_drawerListener != null)
            {
                _drawerLayout.RemoveDrawerListener(_drawerListener);
                _drawerListener.Dispose();
            }

            _drawerListener = new DrawerMultiplexedListener {
                Listeners = { _drawerToggle, (DrawerLayout.IDrawerListener)_drawerLayout }
            };
            _drawerLayout.AddDrawerListener(_drawerListener);
        }