void AdjustHorizontalScroll(int index, ScrollToPosition scrollToPosition)
        {
            _pendingScrollAdjustment = null;

            var viewRect = GetViewRect(index);

            if (viewRect == null)
            {
                return;
            }

            var offset = 0;

            var rvRect = new ARect();

            _recyclerView.GetGlobalVisibleRect(rvRect);

            if (scrollToPosition == ScrollToPosition.Center)
            {
                offset = viewRect.CenterX() - rvRect.CenterX();
            }
            else if (scrollToPosition == ScrollToPosition.End)
            {
                offset = viewRect.Right - rvRect.Right;
            }

            _recyclerView.ScrollBy(offset, 0);
        }
示例#2
0
		private int CalculateXPos(Rect anchorRect)
		{
			int xPos;
			if (anchorRect.Left + RootSize.X > _displaySize.X)
			{
				xPos = _displaySize.X - RootSize.X;
			}

			else if (anchorRect.Left - (RootSize.X / 2) < 0)
			{
				xPos = anchorRect.Left;
			}
			else
			{
				xPos = anchorRect.CenterX() - (RootSize.X / 2);
			}
			return xPos;
		}
示例#3
0
 protected override void OnDraw(Canvas canvas)
 {
     base.OnDraw (canvas);
                 //create an instance of class Paint, set color and font size
                 var textPaint = new Paint {
                         AntiAlias = true,
                         Color = _textColor,
                         TextSize = _textSize };
                 //In order to show text in a middle, we need to know its size
                 var bounds = new Rect ();
                 textPaint.GetTextBounds (_text, 0, _text.Length, bounds);
                 //Now we store font size in bounds variable and can calculate it's position
                 var x = (Width / 2) - bounds.CenterX ();
                 var y = (Height / 2) - bounds.CenterY ();
                 //drawing text with appropriate color and size in the center
                 canvas.DrawText (_text, x, y, textPaint);
 }
示例#4
0
        protected override void OnDraw(Canvas canvas)
        {
            if (Element != null && Element.Text != null)
            {
                var   density     = DeviceDisplay.MainDisplayInfo.Density;
                float strokeWidth = Convert.ToSingle(Element.StrokeWidth * density);
                float strokeMiter = 10.0f;

                var rect = new Android.Graphics.Rect();
                this.GetDrawingRect(rect);

                float progressAngle = 360 * Convert.ToSingle(Element.Progress / Element.Total);

                float radius = Math.Min(rect.Height(), rect.Width()) / 2 - strokeWidth;

                RectF circleRect = new RectF(
                    rect.ExactCenterX() - radius,
                    rect.ExactCenterY() - radius,
                    rect.ExactCenterX() + radius,
                    rect.ExactCenterY() + radius
                    );

                TextPaint paint = new TextPaint();
                paint.Color    = Element.TextColor.ToAndroid();
                paint.TextSize = Element.TextSize;
                paint.GetTextBounds(Element.Text.ToString(), 0, Element.Text.ToString().Length, rect);
                if (((this.Width / 2) - (Element.TextMargin * 4)) < rect.Width())
                {
                    float ratio = (float)((this.Width / 2) - Element.TextMargin * 4) / (float)rect.Width();
                    paint.TextSize = paint.TextSize * ratio;
                    paint.GetTextBounds(Element.Text.ToString(), 0, Element.Text.ToString().Length, rect);
                }
                int x = this.Width / 2 - rect.CenterX();
                int y = this.Height / 2 - rect.CenterY();

                Paint progressPaint = new Paint(PaintFlags.AntiAlias)
                {
                    StrokeWidth = strokeWidth,
                    StrokeMiter = strokeMiter,
                    Color       = Element.ProgressStrokeColor.ToAndroid()
                };
                progressPaint.SetStyle(Paint.Style.Stroke);

                Paint availablePaint = new Paint(PaintFlags.AntiAlias)
                {
                    StrokeWidth = strokeWidth,
                    StrokeMiter = strokeMiter,
                    Color       = Element.AvailableStrokeColor.ToAndroid()
                };
                availablePaint.SetStyle(Paint.Style.Stroke);

                Paint paintCircle = new Paint(PaintFlags.AntiAlias)
                {
                    Color = Element.FillColor.ToAndroid()
                };

                canvas.DrawArc(circleRect, -90, progressAngle, false, progressPaint);
                canvas.DrawArc(circleRect, -90 + progressAngle, 360 - progressAngle, false, availablePaint);
                canvas.DrawText(Element.Text.ToString(), x, y, paint);
            }
        }
示例#5
0
        internal void Draw(Canvas canvas, bool isRound)
        {
            if (Hidden)
            {
                return;
            }

            canvas.Save();
            var resizerPaint = new Paint { Color = new Color(255, 255, 255, 200) };

            //if (!Focused)
            //{
            //    outlinePaint.Color = Color.White;
            //    canvas.DrawRect(DrawRect, outlinePaint);
            //    //canvas.DrawCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width(), resizerPaint);
            //}
            //else
            //{
            Rect viewDrawingRect = new Rect();
            context.GetDrawingRect(viewDrawingRect);

            outlinePaint.Color = Color.White;// new Color(0XFF, 0xFF, 0x8A, 0x00);
            focusPaint.Color = new Color(50, 50, 50, 125);

            Path path = new Path();

            if (isRound)
            {
                path.AddCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width() / 2, Path.Direction.Cw);
                canvas.ClipPath(path, Region.Op.Difference);
                canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint);
            }
            else
            {
                path.AddRect(new RectF(DrawRect), Path.Direction.Cw);
                canvas.ClipPath(path, Region.Op.Difference);
                canvas.DrawRect(viewDrawingRect, focusPaint);

            }

            //canvas.ClipPath(path, Region.Op.Difference);

            //if (isRound)
            //    canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint);
            //else
            //    canvas.DrawRect(viewDrawingRect, focusPaint);

            canvas.Restore();
            canvas.DrawPath(path, outlinePaint);

            var resizerTriangle = new Path();
            var resizerOffset = 4;
            var triangleSize = resizerSize + resizerOffset;
            resizerTriangle.MoveTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - triangleSize);
            resizerTriangle.LineTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - resizerOffset);
            resizerTriangle.LineTo(DrawRect.Right - triangleSize, DrawRect.Bottom - resizerOffset);
            resizerPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(resizerTriangle, resizerPaint);

            if (isRound)
            {
                // Draw the rectangle around the round cropper                
                var roundCropperRectangle = new Path();
                roundCropperRectangle.MoveTo(DrawRect.Left, DrawRect.Top);
                roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Top);
                roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Bottom);
                roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Bottom);
                roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Top);

                resizerPaint.SetStyle(Paint.Style.Stroke);
                canvas.DrawPath(roundCropperRectangle, resizerPaint);
            }
        }
		/**
	 * Calculates the rect for showing the view with Arrow Down
	 * @param originRect The origin rect
	 * @return The calculated rect to show the view
	 */
		private Rect getRectForArrowDown (Rect originRect)
		{

			//Get available space		
			int xAvailable = popoverLayoutRect.Width ();
			if (xAvailable < 0)
				xAvailable = 0;
			int yAvailable = (originRect.Top - popoverLayoutRect.Top);
			if (yAvailable < 0)
				yAvailable = 0;

			//Get final width and height
			int finalX = xAvailable;
			if ((realContentSize.X > 0) && (realContentSize.X < finalX))
				finalX = realContentSize.X;
			int finalY = yAvailable;
			if ((realContentSize.Y > 0) && (realContentSize.Y < finalY))
				finalY = realContentSize.Y;

			//Get final origin X and Y
			int originX = (originRect.CenterX () - popoverLayoutRect.Left) - (finalX / 2);
			if (originX < 0)
				originX = 0;
			else if (originX + finalX > popoverLayoutRect.Width ())
				originX = popoverLayoutRect.Width () - finalX;
			int originY = (originRect.Top - popoverLayoutRect.Top) - finalY;

			//Create rect
			Rect finalRect = new Rect (originX, originY, originX + finalX, originY + finalY);
			//And return
			return finalRect;

		}
		private void addArrow (Rect originRect, int arrowDirection)
		{
			//Add arrow drawable
			ImageView arrowImageView = new ImageView (Application.Context);
			Drawable arrowDrawable = null;
			int xPos = 0;
			int arrowWidth = 0;
			int yPos = 0;
			int arrowHeight = 0;
			//Get correct drawable, and get Width, Height, Xpos and yPos depending on the selected arrow direction
			if (arrowDirection == PopoverView.PopoverArrowDirectionUp) {
				arrowDrawable = Resources.GetDrawable (popoverArrowUpDrawable);
				arrowWidth = arrowDrawable.IntrinsicWidth;
				arrowHeight = arrowDrawable.IntrinsicHeight;
				xPos = originRect.CenterX () - (arrowWidth / 2) - popoverLayoutRect.Left;
				yPos = originRect.Bottom - popoverLayoutRect.Top;
			} else if (arrowDirection == PopoverView.PopoverArrowDirectionDown) {
				arrowDrawable = Resources.GetDrawable (popoverArrowDownDrawable);
				arrowWidth = arrowDrawable.IntrinsicWidth;
				arrowHeight = arrowDrawable.IntrinsicHeight;
				xPos = originRect.CenterX () - (arrowWidth / 2) - popoverLayoutRect.Left;
				yPos = originRect.Top - arrowHeight - popoverLayoutRect.Top;
			} else if (arrowDirection == PopoverView.PopoverArrowDirectionLeft) {
				arrowDrawable = Resources.GetDrawable (popoverArrowLeftDrawable);
				arrowWidth = arrowDrawable.IntrinsicWidth;
				arrowHeight = arrowDrawable.IntrinsicHeight;
				xPos = originRect.Right - popoverLayoutRect.Left;
				yPos = originRect.CenterY () - (arrowHeight / 2) - popoverLayoutRect.Top;
			} else if (arrowDirection == PopoverView.PopoverArrowDirectionRight) {
				arrowDrawable = Resources.GetDrawable (popoverArrowRightDrawable);
				arrowWidth = arrowDrawable.IntrinsicWidth;
				arrowHeight = arrowDrawable.IntrinsicHeight;
				xPos = originRect.Left - arrowWidth - popoverLayoutRect.Left;
				yPos = originRect.CenterY () - (arrowHeight / 2) - popoverLayoutRect.Top;
			}
			//Set drawable
			arrowImageView.SetImageDrawable (arrowDrawable);
			//Init layout params
			LayoutParams arrowParams = new LayoutParams (arrowWidth, arrowHeight);
			arrowParams.LeftMargin = xPos;
			arrowParams.TopMargin = yPos;
			//add view :)
			AddView (arrowImageView, arrowParams);
		}