Exemplo n.º 1
0
            public ModalContainer(
                IMauiContext windowMauiContext,
                Page modal,
                ViewGroup parentView)
                : base(windowMauiContext?.Context ?? throw new ArgumentNullException($"{nameof(windowMauiContext.Context)}"))
            {
                _windowMauiContext = windowMauiContext;
                Modal = modal;

                _backgroundView = new AView(_windowMauiContext.Context);
                UpdateBackgroundColor();
                AddView(_backgroundView);

                Id = AView.GenerateViewId();

                _modalFragment   = new ModalFragment(_windowMauiContext, modal);
                _fragmentManager = _windowMauiContext.GetFragmentManager();

                parentView.AddView(this);

                _fragmentManager
                .BeginTransaction()
                .Add(this.Id, _modalFragment)
                .Commit();

                UpdateMargin();
            }
Exemplo n.º 2
0
        protected virtual void OnElementSet(Shell shell)
        {
            Element = shell;
            Profile.FrameBegin();

            Profile.FramePartition("Flyout");
            _flyoutView = CreateShellFlyoutView();

            Profile.FramePartition("Frame");
            _frameLayout = new CustomFrameLayout(AndroidContext)
            {
                LayoutParameters = new LP(LP.MatchParent, LP.MatchParent),
                Id = AView.GenerateViewId(),
            };

            Profile.FramePartition("SetFitsSystemWindows");
            _frameLayout.SetFitsSystemWindows(true);

            Profile.FramePartition("AttachFlyout");
            _flyoutView.AttachFlyout(this, _frameLayout);

            Profile.FramePartition("AddAppearanceObserver");
            ((IShellController)shell).AddAppearanceObserver(this, shell);

            // Previewer Hack
            Profile.FramePartition("Previewer Hack");
            if (AndroidContext.GetActivity() != null && shell.CurrentItem != null)
            {
                SwitchFragment(FragmentManager, _frameLayout, shell.CurrentItem, false);
            }

            Profile.FrameEnd();
        }
Exemplo n.º 3
0
 public PageContainer(Context context, IViewHandler child, bool inFragment = false) : base(context)
 {
     Id           = AView.GenerateViewId();
     Child        = child;
     IsInFragment = inFragment;
     AddView((AView)child.NativeView);
 }
Exemplo n.º 4
0
        public virtual FragmentNavigator.Destination AddFragmentDestination()
        {
            var destination = new FragmentNavigator.Destination(FragmentNavigator);

            destination.SetClassName(Java.Lang.Class.FromType(typeof(NavigationViewFragment)).CanonicalName);
            destination.Id = AView.GenerateViewId();
            NavGraph.AddDestination(destination);
            return(destination);
        }
Exemplo n.º 5
0
        internal PickerInnerView(Android.Content.Context context, PickerAdapter adapter) : base(context)
        {
            this.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            var padding = (int)context.ToPixels(8);

            SetPadding(padding, padding, padding, padding);

            SetBackgroundColor(adapter._background);

            _textLabel    = new TextView(context);
            _textLabel.Id = AView.GenerateViewId();

            _detailLabel    = new TextView(context);
            _detailLabel.Id = AView.GenerateViewId();

            _textContainr             = new LinearLayout(context);
            _textContainr.Orientation = Orientation.Vertical;

            using (var param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)){
                _textContainr.AddView(_textLabel, param);
                _textContainr.AddView(_detailLabel, param);
            }

            _checkBox           = new SimpleCheck(context);
            _checkBox.Focusable = false;

            _textLabel.SetTextColor(adapter._titleColor);
            _textLabel.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)adapter._fontSize);
            _detailLabel.SetTextColor(adapter._detailColor);
            _detailLabel.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)adapter._detailFontSize);
            _checkBox.Color = adapter._accentColor;
            SetBackgroundColor(adapter._background);

            using (var param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)) {
                param.AddRule(LayoutRules.AlignParentStart);
                param.AddRule(LayoutRules.CenterVertical);
                AddView(_textContainr, param);
            }

            using (var param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent)
            {
                Width = (int)context.ToPixels(30),
                Height = (int)context.ToPixels(30)
            }) {
                param.AddRule(LayoutRules.AlignParentEnd);
                param.AddRule(LayoutRules.CenterVertical);
                AddView(_checkBox, param);
            }
        }
Exemplo n.º 6
0
            public ModalContainer(IMauiContext context, Page modal) : base(context.Context ?? throw new ArgumentNullException($"{nameof(context.Context)}"))
            {
                _modal = modal;

                _backgroundView = new AView(context.Context);
                UpdateBackgroundColor();
                AddView(_backgroundView);
                var nativeView = modal.ToNative(context);

                AddView(nativeView);

                Id = AView.GenerateViewId();

                _modal.PropertyChanged += OnModalPagePropertyChanged;
            }
Exemplo n.º 7
0
        public static async Task <T> AttachAndRun <T>(this AView view, Func <Task <T> > action)
        {
            if (view.Parent is WrapperView wrapper)
            {
                view = wrapper;
            }

            if (view.Parent == null)
            {
                var context = view.Context !;
                var layout  = new FrameLayout(context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)
                };
                view.LayoutParameters = new FrameLayout.LayoutParams(view.Width, view.Height)
                {
                    Gravity = GravityFlags.Center
                };

                var act      = context.GetActivity() !;
                var rootView = act.FindViewById <FrameLayout>(Android.Resource.Id.Content) !;

                view.Id   = AView.GenerateViewId();
                layout.Id = AView.GenerateViewId();

                try
                {
                    await _attachAndRunSemaphore.WaitAsync();

                    layout.AddView(view);
                    rootView.AddView(layout);
                    return(await Run(view, action));
                }
                finally
                {
                    rootView.RemoveView(layout);
                    layout.RemoveView(view);
                    _attachAndRunSemaphore.Release();
                }
            }
            else
            {
                return(await Run(view, action));
            }
Exemplo n.º 8
0
        protected virtual void OnElementSet(Shell shell)
        {
            Element = shell;

            _flyoutView  = CreateShellFlyoutRenderer();
            _frameLayout = new CustomFrameLayout(AndroidContext)
            {
                LayoutParameters = new LP(LP.MatchParent, LP.MatchParent),
                Id = AView.GenerateViewId(),
            };

            _frameLayout.SetFitsSystemWindows(true);

            _flyoutView.AttachFlyout(this, _frameLayout);

            ((IShellController)shell).AddAppearanceObserver(this, shell);

            SwitchFragment(FragmentManager, _frameLayout, shell.CurrentItem, false);
        }
Exemplo n.º 9
0
            public ModalContainer(IWindow window, Page modal) : base(window.Handler?.MauiContext?.Context ?? throw new ArgumentNullException($"{nameof(window.Handler.MauiContext.Context)}"))
            {
                _windowMauiContext = window.Handler.MauiContext;
                Modal = modal;

                _backgroundView = new AView(_windowMauiContext.Context);
                UpdateBackgroundColor();
                AddView(_backgroundView);

                Id = AView.GenerateViewId();

                Modal.PropertyChanged += OnModalPagePropertyChanged;

                _modalFragment   = new ModalFragment(_windowMauiContext, modal);
                _fragmentManager = _windowMauiContext.GetFragmentManager();

                _fragmentManager
                .BeginTransaction()
                .Add(this.Id, _modalFragment)
                .Commit();
            }
        // TODO MAUI
        // THIS probably isn't how we're going to set LabeledBy insied Maui
        internal static void SetLabeledBy(AView control, Element element)
        {
            if (element == null || control == null)
            {
                return;
            }

            var elemValue = (VisualElement)element.GetValue(AutomationProperties.LabeledByProperty);

            if (elemValue != null)
            {
                var id = control.Id;
                if (id == AView.NoId)
                {
                    id = control.Id = AView.GenerateViewId();
                }

                // TODO MAUI
                // THIS probably isn't how we're going to set LabeledBy insied Maui
                //var renderer = elemValue?.GetRenderer();
                //renderer?.SetLabelFor(id);
            }
        }
Exemplo n.º 11
0
 public FakeActivityRootView(Context context) : base(context)
 {
     Id = AView.GenerateViewId();
 }
Exemplo n.º 12
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

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

            if (shellSection.CurrentItem == null)
            {
                throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.");
            }

            var root = inflater.Inflate(Resource.Layout.shellrootlayout, null).JavaCast <CoordinatorLayout>();

            _toolbar = root.FindViewById <Toolbar>(Resource.Id.maui_toolbar);
            if (Context.GetActivity() is AppCompatActivity aca)
            {
                aca.SetSupportActionBar(_toolbar);
            }

            _viewPager = root.FindViewById <ViewPager2>(Resource.Id.main_viewpager);
            _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout);

            //_viewPager.EnableGesture = false;

            //_viewPager.AddOnPageChangeListener(this);
            _viewPager.Id = AView.GenerateViewId();

            _viewPager.Adapter        = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, MauiContext);
            _viewPager.OverScrollMode = OverScrollMode.Never;

            new TabLayoutMediator(_tablayout, _viewPager, this)
            .Attach();

            //_tablayout.SetupWithViewPager(_viewPager);

            Page currentPage  = null;
            int  currentIndex = -1;
            var  currentItem  = ShellSection.CurrentItem;

            while (currentIndex < 0 && SectionController.GetItems().Count > 0 && ShellSection.CurrentItem != null)
            {
                currentItem = ShellSection.CurrentItem;
                currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();

                // current item hasn't changed
                if (currentItem == shellSection.CurrentItem)
                {
                    currentIndex = SectionController.GetItems().IndexOf(currentItem);
                }
            }

            _toolbarTracker      = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.Page = currentPage;

            _viewPager.CurrentItem = currentIndex;

            if (SectionController.GetItems().Count == 1)
            {
                UpdateTablayoutVisibility();
            }

            _tablayout.LayoutChange += OnTabLayoutChange;

            _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
            _toolbarAppearanceTracker   = _shellContext.CreateToolbarAppearanceTracker();

            HookEvents();

            return(_rootView = root);
        }