Example #1
0
 public PageContainer(Context context, IVisualElementRenderer child, bool inFragment = false) : base(context)
 {
     Id           = Platform.GenerateViewId();
     Child        = child;
     IsInFragment = inFragment;
     AddView(child.View);
 }
Example #2
0
        protected virtual void OnElementSet(Shell shell)
        {
            Profile.FrameBegin();

            Profile.FramePartition("Flyout");
            _flyoutRenderer = CreateShellFlyoutRenderer();

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

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

            Profile.FramePartition("AttachFlyout");
            _flyoutRenderer.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();
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Stepper> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null)
            {
                _downButton = new AButton(Context)
                {
                    Text = "-", Gravity = GravityFlags.Center, Tag = this, Focusable = true
                };
                _downButton.SetHeight((int)Context.ToPixels(10.0));

                _downButton.SetOnClickListener(StepperListener.Instance);

                _upButton = new AButton(Context)
                {
                    Text = "+", Tag = this, Focusable = true
                };

                _upButton.SetOnClickListener(StepperListener.Instance);
                _upButton.SetHeight((int)Context.ToPixels(10.0));

                _downButton.NextFocusForwardId = _upButton.Id = Platform.GenerateViewId();

                var layout = CreateNativeControl();

                layout.AddView(_downButton);
                layout.AddView(_upButton);

                SetNativeControl(layout);
            }

            UpdateButtonEnabled();
        }
Example #4
0
        public static void CreateStepperButtons <TButton>(IStepperRenderer renderer, out TButton downButton, out TButton upButton)
            where TButton : AButton
        {
            downButton           = (TButton)renderer.CreateButton();
            downButton.Id        = Platform.GenerateViewId();
            downButton.Focusable = true;
            upButton             = (TButton)renderer.CreateButton();
            upButton.Id          = Platform.GenerateViewId();
            upButton.Focusable   = true;

            downButton.Gravity = GravityFlags.Center;
            downButton.Tag     = renderer as Java.Lang.Object;
            downButton.SetOnClickListener(StepperListener.Instance);
            upButton.Gravity = GravityFlags.Center;
            upButton.Tag     = renderer as Java.Lang.Object;
            upButton.SetOnClickListener(StepperListener.Instance);

            // IMPORTANT:
            // Do not be decieved. These are NOT the same characters. Neither are a "minus" either.
            // The Text is a visually pleasing "minus", and the description is the phonetically correct "minus".
            // The little key on your keyboard is a dash/hyphen.
            downButton.Text = "-";
            downButton.ContentDescription = "−";

            // IMPORTANT:
            // Do not be decieved. These are NOT the same characters.
            // The Text is a visually pleasing "plus", and the description is the phonetically correct "plus"
            // (which, unlike the minus, IS found on your keyboard).
            upButton.Text = "+";
            upButton.ContentDescription = "+";

            downButton.NextFocusForwardId = upButton.Id;
        }
Example #5
0
        public static void EnsureId(this AView view)
        {
            if (view.IsDisposed())
            {
                return;
            }

            if (view.Id == AView.NoId)
            {
                view.Id = Platform.GenerateViewId();
            }
        }
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

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

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

            _toolbar = root.FindViewById <Toolbar>(Resource.Id.main_toolbar);
            var scrollview = root.FindViewById <NestedScrollView>(Resource.Id.main_scrollview);

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

            _viewPager = new FormsViewPager(Context)
            {
                LayoutParameters = new LP(LP.MatchParent, LP.MatchParent),
            };

            _viewPager.AddOnPageChangeListener(this);
            _viewPager.Id = Platform.GenerateViewId();

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

            _tablayout.SetupWithViewPager(_viewPager);

            var currentPage  = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();
            var currentIndex = ShellSection.Items.IndexOf(ShellSection.CurrentItem);

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

            _viewPager.CurrentItem = currentIndex;
            scrollview.AddView(_viewPager);

            if (shellSection.Items.Count == 1)
            {
                _tablayout.Visibility = ViewStates.Gone;
            }

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

            HookEvents();

            scrollview.Dispose();

            return(_rootView = root);
        }
Example #7
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            if (Id == NoId)
            {
                Id = Platform.GenerateViewId();
            }

            UpdateBackground(false);

            Clickable = true;
        }
Example #8
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.RootLayout, null).JavaCast <CoordinatorLayout>();

            _toolbar   = root.FindViewById <Toolbar>(Resource.Id.main_toolbar);
            _viewPager = root.FindViewById <FormsViewPager>(Resource.Id.main_viewpager);
            _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout);

            _viewPager.EnableGesture = false;

            _viewPager.AddOnPageChangeListener(this);
            _viewPager.Id = Platform.GenerateViewId();

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

            _tablayout.SetupWithViewPager(_viewPager);

            var currentPage  = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();
            var currentIndex = SectionController.GetItems().IndexOf(ShellSection.CurrentItem);

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

            _viewPager.CurrentItem = currentIndex;

            if (SectionController.GetItems().Count == 1)
            {
                _tablayout.Visibility = ViewStates.Gone;
            }

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

            HookEvents();

            return(_rootView = root);
        }
Example #9
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            Page view = e.NewElement;

            base.OnElementChanged(e);

            if (Id == NoId)
            {
                Id = Platform.GenerateViewId();
            }

            UpdateBackgroundColor(view);
            UpdateBackgroundImage(view);

            Clickable = true;
        }
Example #10
0
        protected virtual void OnElementSet(Shell shell)
        {
            _flyoutRenderer = CreateShellFlyoutRenderer();
            _frameLayout    = new CustomFrameLayout(AndroidContext)
            {
                LayoutParameters = new LP(LP.MatchParent, LP.MatchParent),
                Id = Platform.GenerateViewId(),
            };
            _frameLayout.SetFitsSystemWindows(true);

            _flyoutRenderer.AttachFlyout(this, _frameLayout);

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

            SwitchFragment(FragmentManager, _frameLayout, shell.CurrentItem, false);
        }
Example #11
0
        public static void SetLabeledBy(this global::Android.Views.View Control, Element Element)
        {
            if (Element == null)
            {
                return;
            }

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

            if (elemValue != null)
            {
                var id = Control.Id;
                if (id == -1)
                {
                    id = Control.Id = Platform.GenerateViewId();
                }

                var renderer = elemValue?.GetRenderer();
                renderer?.SetLabelFor(id);
            }
        }
Example #12
0
        internal static void UpdateMenuItem(AToolbar toolbar,
                                            ToolbarItem item,
                                            int?menuItemIndex,
                                            Context context,
                                            Color?tintColor,
                                            PropertyChangedEventHandler toolbarItemChanged,
                                            List <IMenuItem> menuItemsCreated,
                                            List <ToolbarItem> toolbarItemsCreated,
                                            Action <Context, IMenuItem, ToolbarItem> updateMenuItemIcon = null)
        {
            IMenu menu = toolbar.Menu;

            item.PropertyChanged -= toolbarItemChanged;
            item.PropertyChanged += toolbarItemChanged;

            IMenuItem menuitem;

            Java.Lang.ICharSequence newTitle = null;

            if (!String.IsNullOrWhiteSpace(item.Text))
            {
                if (item.Order != ToolbarItemOrder.Secondary && tintColor != null && tintColor != Color.Default)
                {
                    var             color       = item.IsEnabled ? tintColor.Value.ToAndroid() : tintColor.Value.MultiplyAlpha(0.302).ToAndroid();
                    SpannableString titleTinted = new SpannableString(item.Text);
                    titleTinted.SetSpan(new ForegroundColorSpan(color), 0, titleTinted.Length(), 0);
                    newTitle = titleTinted;
                }
                else
                {
                    newTitle = new Java.Lang.String(item.Text);
                }
            }
            else
            {
                newTitle = new Java.Lang.String();
            }

            if (menuItemIndex == null)
            {
                menuitem = menu.Add(0, Platform.GenerateViewId(), 0, newTitle);
                menuItemsCreated?.Add(menuitem);
                toolbarItemsCreated?.Add(item);
            }
            else
            {
                if (menuItemsCreated == null || menuItemsCreated.Count < menuItemIndex.Value)
                {
                    return;
                }

                menuitem = menuItemsCreated[menuItemIndex.Value];

                if (!menuitem.IsAlive())
                {
                    return;
                }

                menuitem.SetTitle(newTitle);
            }

            menuitem.SetEnabled(item.IsEnabled);
            menuitem.SetTitleOrContentDescription(item);

            if (updateMenuItemIcon != null)
            {
                updateMenuItemIcon(context, menuitem, item);
            }
            else
            {
                UpdateMenuItemIcon(context, menuitem, item, tintColor);
            }

            if (item.Order != ToolbarItemOrder.Secondary)
            {
                menuitem.SetShowAsAction(ShowAsAction.Always);
            }

            menuitem.SetOnMenuItemClickListener(new GenericMenuClickListener(((IMenuItemController)item).Activate));

            if (item.Order != ToolbarItemOrder.Secondary && !Forms.IsOreoOrNewer && (tintColor != null && tintColor != Color.Default))
            {
                var view = toolbar.FindViewById(menuitem.ItemId);
                if (view is ATextView textView)
                {
                    if (item.IsEnabled)
                    {
                        textView.SetTextColor(tintColor.Value.ToAndroid());
                    }
                    else
                    {
                        textView.SetTextColor(tintColor.Value.MultiplyAlpha(0.302).ToAndroid());
                    }
                }
            }
        }
Example #13
0
 public FlyoutPageContainer(FlyoutPage parent, bool isFlyout, Context context) : base(context)
 {
     Id        = Platform.GenerateViewId();
     _parent   = parent;
     _isFlyout = isFlyout;
 }