예제 #1
0
        /**
         * Tells us about the "Target" which is the view we want to anchor to.
         * We figure out where it is on screen and (optionally) how big it is.
         * We also figure out whether to place our content and dismiss button above or below it.
         *
         * @param target
         */
        public void SetTarget(Target.Target target)
        {
            _target = target;

            // update dismiss button state
            UpdateDismissButton();

            if (_target != null)
            {
                /**
                 * If we're on lollipop then make sure we don't draw over the nav bar
                 */
                if (!_renderOverNav && Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    _bottomMargin = GetSoftButtonsBarSizePort((Activity)Context);
                    var contentLp = (LayoutParams)LayoutParameters;

                    if (contentLp != null && contentLp.BottomMargin != _bottomMargin)
                    {
                        contentLp.BottomMargin = _bottomMargin;
                    }
                }

                // apply the target position
                var targetPoint  = _target.Point;
                var targetBounds = _target.Bounds;
                Position = targetPoint;

                // now figure out whether to put content above or below it
                var height   = MeasuredHeight;
                var midPoint = height / 2;
                var yPos     = targetPoint.Y;

                var radius = Math.Max(targetBounds.Height(), targetBounds.Width()) / 2;
                if (_shape != null)
                {
                    _shape.UpdateTarget(_target);
                    radius = _shape.Height / 2;
                }

                if (yPos > midPoint)
                {
                    // target is in lower half of screen, we'll sit above it
                    _contentTopMargin    = 0;
                    _contentBottomMargin = (height - yPos) + radius + _shapePadding;
                    _gravity             = GravityFlags.Bottom;
                }
                else
                {
                    // target is in upper half of screen, we'll sit below it
                    _contentTopMargin    = yPos + radius + _shapePadding;
                    _contentBottomMargin = 0;
                    _gravity             = GravityFlags.Top;
                }
            }

            ApplyLayoutParams();
        }
예제 #2
0
 public void OnGlobalLayout()
 {
     try
     {
         SetTarget(_target);
     }
     catch (ObjectDisposedException e)
     {
         // target object is disposed, ditch the target
         _target = null;
     }
 }
예제 #3
0
        /**
         * Tells us about the "Target" which is the view we want to anchor to.
         * We figure out where it is on screen and (optionally) how big it is.
         * We also figure out whether to place our content and dismiss button above or below it.
         *
         * @param target
         */
        public void SetTarget(Target.Target target)
        {
            _target = target;
            // update dismiss button state
            UpdateDismissButton();

            if (_target != null)
            {
                var lp = (LayoutParams)LayoutParameters;

                /**
                 * If we're on lollipop then make sure we don't draw over the nav bar
                 */
                if (!_renderOverNav && Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    //					_bottomMargin = GetSoftButtonsBarSize((Activity)Context);
                    //					_bottomMargin = GetStatusBarSize((Activity)Context);
                    var activity    = (Activity)Context;
                    var buttonSize  = GetSoftButtonsBarSize(activity);
                    var statusSize  = GetStatusBarSize(activity);
                    var orientation = activity.Resources.Configuration.Orientation;
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
                    {
                        var windowInsets = activity.Window.DecorView.RootWindowInsets;
                        statusSize = windowInsets.StableInsetTop;
                        buttonSize = orientation == Orientation.Landscape ? windowInsets.StableInsetRight : windowInsets.StableInsetBottom;
                    }
                    if (lp != null)
                    {
                        lp.TopMargin = statusSize;
                        if (orientation == Orientation.Landscape)
                        {
                            lp.RightMargin  = buttonSize;
                            lp.BottomMargin = 0;
                        }
                        else
                        {
                            lp.BottomMargin = buttonSize;
                            lp.RightMargin  = 0;
                        }
                    }
                }

                // apply the target position
                var targetPoint  = _target.Point;
                var targetBounds = _target.Bounds;
                if (lp != null)
                {
                    targetPoint = new Point(targetPoint.X - lp.LeftMargin, targetPoint.Y - lp.TopMargin);
                }
                Position = targetPoint;

                // now figure out whether to put content above or below it
                var height   = MeasuredHeight;
                var midPoint = height / 2;
                var yPos     = targetPoint.Y;

                var radius = Math.Max(targetBounds.Height(), targetBounds.Width()) / 2;
                if (_shape != null)
                {
                    _shape.UpdateTarget(_target);
                    radius = _shape.Height / 2;
                }

                if (_shape is NoShape)
                {
                    _contentTopMargin    = 0;
                    _contentBottomMargin = 0;
                    _gravity             = GravityFlags.Center;
                }
                else
                {
                    if (yPos > midPoint)
                    {
                        // target is in lower half of screen, we'll sit above it
                        _contentTopMargin    = 0;
                        _contentBottomMargin = (height - yPos) + radius + _shapePadding;
                        _gravity             = GravityFlags.Bottom;
                    }
                    else
                    {
                        // target is in upper half of screen, we'll sit below it
                        _contentTopMargin    = yPos + radius + _shapePadding;
                        _contentBottomMargin = 0;
                        _gravity             = GravityFlags.Top;
                    }
                }
            }

            ApplyLayoutParams();
        }