示例#1
0
        protected virtual void UpdateFlyoutHeader()
        {
            if (_headerView != null)
            {
                var oldHeaderView = _headerView;
                _headerView = null;
                _appBar.RemoveView(oldHeaderView);
                oldHeaderView.Dispose();
            }

            if (_flyoutHeader != null)
            {
                _flyoutHeader.MeasureInvalidated -= OnFlyoutHeaderMeasureInvalidated;
            }

            _flyoutHeader = ((IShellController)_shellContext.Shell).FlyoutHeader;
            if (_flyoutHeader != null)
            {
                _flyoutHeader.MeasureInvalidated += OnFlyoutHeaderMeasureInvalidated;
            }

            _headerView = new HeaderContainer(_shellContext.AndroidContext, _flyoutHeader)
            {
                MatchWidth = true
            };
            _headerView.SetMinimumHeight(_actionBarHeight);
            _headerView.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll
            };
            _appBar.AddView(_headerView);
            UpdateFlyoutHeaderBehavior();

            UpdateContentLayout();
        }
        protected virtual void LoadView(IShellContext shellContext)
        {
            var context = shellContext.AndroidContext;

            // Android designer can't load fragments or resources from layouts
            if (context.IsDesignerContext())
            {
                _rootView = new FrameLayout(context);
                return;
            }

            var coordinator = LayoutInflater.FromContext(context).Inflate(Resource.Layout.FlyoutContent, null);
            var recycler    = coordinator.FindViewById <RecyclerView>(Resource.Id.flyoutcontent_recycler);
            var appBar      = coordinator.FindViewById <AppBarLayout>(Resource.Id.flyoutcontent_appbar);

            _rootView = coordinator;

            appBar.AddOnOffsetChangedListener(this);

            int actionBarHeight = (int)context.ToPixels(56);

            _headerView = new HeaderContainer(context, ((IShellController)shellContext.Shell).FlyoutHeader)
            {
                MatchWidth = true
            };
            _headerView.SetMinimumHeight(actionBarHeight);
            _headerView.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll
            };
            appBar.AddView(_headerView);

            var adapter = new ShellFlyoutRecyclerAdapter(shellContext, OnElementSelected);

            recycler.SetPadding(0, (int)context.ToPixels(20), 0, 0);
            recycler.SetClipToPadding(false);
            recycler.SetLayoutManager(new LinearLayoutManager(context, (int)Orientation.Vertical, false));
            recycler.SetAdapter(adapter);

            var metrics = context.Resources.DisplayMetrics;
            var width   = Math.Min(metrics.WidthPixels, metrics.HeightPixels);

            using (TypedValue tv = new TypedValue())
            {
                if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ActionBarSize, tv, true))
                {
                    actionBarHeight = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
                }
            }

            width -= actionBarHeight;

            coordinator.LayoutParameters = new LP(width, LP.MatchParent);

            UpdateFlyoutHeaderBehavior();
            _shellContext.Shell.PropertyChanged += OnShellPropertyChanged;

            UpdateFlyoutBackgroundColor();
        }
示例#3
0
        protected virtual void LoadView(IShellContext shellContext)
        {
            Profile.FrameBegin();

            var context = shellContext.AndroidContext;

            // Android designer can't load fragments or resources from layouts
            if (context.IsDesignerContext())
            {
                _rootView = new FrameLayout(context);
                return;
            }

            var coordinator = LayoutInflater.FromContext(context).Inflate(Resource.Layout.FlyoutContent, null);

            Profile.FramePartition("Find Recycler");
            var recycler = coordinator.FindViewById <RecyclerView>(Resource.Id.flyoutcontent_recycler);

            Profile.FramePartition("Find AppBar");
            var appBar = coordinator.FindViewById <AppBarLayout>(Resource.Id.flyoutcontent_appbar);

            _rootView = coordinator as ViewGroup;

            Profile.FramePartition("Add Listener");
            appBar.AddOnOffsetChangedListener(this);

            Profile.FramePartition("Add HeaderView");
            _actionBarHeight = (int)context.ToPixels(56);

            _flyoutHeader = ((IShellController)shellContext.Shell).FlyoutHeader;
            if (_flyoutHeader != null)
            {
                _flyoutHeader.MeasureInvalidated += OnFlyoutHeaderMeasureInvalidated;
            }

            _headerView = new HeaderContainer(context, _flyoutHeader)
            {
                MatchWidth = true
            };
            _headerView.SetMinimumHeight(_actionBarHeight);
            _headerView.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll
            };
            appBar.AddView(_headerView);

            Profile.FramePartition("Recycler.SetAdapter");
            var adapter = new ShellFlyoutRecyclerAdapter(shellContext, OnElementSelected);

            recycler.SetClipToPadding(false);
            recycler.SetLayoutManager(_layoutManager = new ScrollLayoutManager(context, (int)Orientation.Vertical, false));
            recycler.SetAdapter(adapter);

            Profile.FramePartition("Initialize BgImage");
            var metrics = context.Resources.DisplayMetrics;
            var width   = Math.Min(metrics.WidthPixels, metrics.HeightPixels);

            using (TypedValue tv = new TypedValue())
            {
                if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ActionBarSize, tv, true))
                {
                    _actionBarHeight = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
                }
            }

            width -= _actionBarHeight;

            coordinator.LayoutParameters = new LP(width, LP.MatchParent);

            _bgImage = new ImageView(context)
            {
                LayoutParameters = new LP(coordinator.LayoutParameters)
            };

            Profile.FramePartition("UpdateFlyoutHeaderBehavior");
            UpdateFlyoutHeaderBehavior();
            _shellContext.Shell.PropertyChanged += OnShellPropertyChanged;

            Profile.FramePartition("UpdateFlyoutBackground");
            UpdateFlyoutBackground();

            Profile.FrameEnd();

            Profile.FramePartition(nameof(UpdateVerticalScrollMode));
            UpdateVerticalScrollMode();
            Profile.FrameEnd();
        }