Beispiel #1
0
        /// <summary>
        /// Set the size of the drawable.
        /// </summary>
        /// <param name="size">The size in pixels (px).</param>
        /// <returns>The current IconDrawable for chaining.</returns>
        public IconDrawable SizePx(Int32 size)
        {
            _size = size;

            _paint.TextSize = _size;
            var textBounds = new Rect();
            var textValue  = _icon.Character.ToString();

            _paint.GetTextBounds(textValue, 0, 1, textBounds);

            SetBounds(0, 0, textBounds.Width(), textBounds.Height());
            InvalidateSelf();
            return(this);
        }
        private void DrawText(Canvas canvas, string text, float x, float y, float textSize, Typeface typeface,
                              Color color, float pictureWidth = 0)
        {
            var paintText = new TextPaint(PaintFlags.LinearText | PaintFlags.AntiAlias)
            {
                TextSize = textSize
            };

            var textRect = new Rect();

            paintText.GetTextBounds(text, 0, text.Length, textRect);
            paintText.SetARGB(color.A, color.R, color.G, color.B);
            paintText.SetTypeface(typeface);

            var p = new TextPaint();

            p.SetTypeface(typeface);

            p.TextSize = textSize;
            var ellipsizedText = TextUtils.Ellipsize(text, p, Width - 75.ToPixels(), TextUtils.TruncateAt.End);

            if (ellipsizedText.IsNullOrEmpty())
            {
                ellipsizedText = text;
            }

            if (this.Services().Localize.IsRightToLeft)
            {
                x = canvas.Width - pictureWidth - 15.ToPixels() - textRect.Width() - (ShowRightArrow ? 35.ToPixels() : 0);
            }

            canvas.DrawText(ellipsizedText, x, y, paintText);
        }
Beispiel #3
0
        void drawLabel(Canvas canvas, float xCoord, float yCoord, Paint.Align alignment, string label, bool centerVertical = false)
        {
            var fontColor = Color.White;

            var textPaint = new TextPaint();

            textPaint.Color = fontColor;

            textPaint.TextSize = fontSize;

            textPaint.TextAlign = alignment;

            textPaint.SetStyle(Paint.Style.Stroke);


            var frame = new Rect();

            textPaint.GetTextBounds(label, 0, label.Length, frame);

            if (centerVertical)
            {
                yCoord -= frame.CenterY();
            }
            else
            {
                yCoord += frame.Height();
            }

            canvas.DrawText(label, xCoord, yCoord, textPaint);
        }
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            canvas.Save();

            canvas.Translate(_width, _height);
            canvas.Rotate(-90);

            TextPaint paint = this.Paint;

            //Android.Graphics.Color Colorr = Color.  //this.TextColors.DefaultColor;
            //
            //var defcolor = this.TextColors.DefaultColor;
            //var Redd = Color.GetRedComponent(defcolor);
            //var Blue = Color.GetBlueComponent(defcolor);
            //var Greenn = Color.GetGreenComponent(defcolor);
            //var Birlestir = Color.Rgb(Redd, Greenn, Blue);
            //ColorFilter cf = new PorterDuffColorFilter(Birlestir, PorterDuff.Mode.SrcAtop);
            //paint.SetColorFilter(cf);
            paint.Color = Color.White;
            String text = getTextt();

            paint.GetTextBounds(text, 0, text.Length, _bounds);
            canvas.DrawText(text, this.CompoundPaddingLeft, (_bounds.Height() - _width) / 2, paint);

            canvas.Restore();
        }
Beispiel #5
0
        public override void Draw(Canvas canvas)
        {
            NumberButton button = (NumberButton)this.Element;

            Paint backgroundPaint = new Paint()
            {
                Color     = button.BackgroundColor.ToAndroid(),
                AntiAlias = true
            };
            TextPaint textPaint = new TextPaint()
            {
                Color     = button.TextColor.ToAndroid(),
                AntiAlias = true,
                TextSize  = (float)button.FontSize,
                TextAlign = Paint.Align.Center
            };


            Rect bounds = new Rect();

            textPaint.GetTextBounds(button.Text, 0, button.Text.Length, bounds);

            canvas.DrawCircle((float)canvas.Width / 2, (float)canvas.Height / 2, (float)button.WidthRequest, backgroundPaint);
            canvas.DrawText(button.Text,
                            (float)canvas.Width / 2,
                            ((float)canvas.Height + bounds.Height()) / 2, textPaint);
        }
Beispiel #6
0
        public override void Draw(Canvas canvas)
        {
            paint.TextSize = Bounds.Height();
            var textBounds = new Rect();

            paint.GetTextBounds(text, 0, 1, textBounds);
            var textHeight = textBounds.Height();
            var textBottom = Bounds.Top + (paint.TextSize - textHeight) / 2f + textHeight - textBounds.Bottom;

            canvas.DrawText(text, Bounds.ExactCenterX(), textBottom, paint);
        }
 /// <summary>
 /// Draws the specified canvas.
 /// </summary>
 /// <param name="canvas">The canvas.</param>
 public override void Draw(Canvas canvas)
 {
     var bounds = Bounds;
     var height = bounds.Height();
     _paint.TextSize = height;
     var textBounds = new Rect();
     var textValue = _icon.Character.ToString();
     _paint.GetTextBounds(textValue, 0, 1, textBounds);
     var textHeight = textBounds.Height();
     var textBottom = bounds.Top + (height - textHeight) / 2f + textHeight - textBounds.Bottom;
     canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, _paint);
 }
        /// <summary>
        /// Callback method to be invoked when the view tree is about to be drawn
        /// </summary>
        ///
        /// <Precondition>
        /// the method is supposed to be called by Android framework
        /// </Precondition>
        ///
        /// <Postcondition>
        /// the view is drawn
        /// </Postcondition>
        protected override void OnDraw(Canvas canvas)
        {
            canvas.DrawColor(Color.White);
            this.circleData.X = (float)canvas.Width / 2;
            this.circleData.Y = (float)canvas.Height / 2;
            canvas.DrawCircle(this.circleData.X, this.circleData.Y, this.circleData.Radius, this.backgroundPaint);

            Rect textBounds = new Rect();

            textPaint.GetTextBounds(this.DisplayText, 0, this.DisplayText.Length, textBounds);

            canvas.DrawText(this.DisplayText, this.circleData.X - (textBounds.Left + textBounds.Width() / 2), this.circleData.Y + (textBounds.Bottom + textBounds.Height() / 2), this.textPaint);
        }
Beispiel #9
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            Rect      bounds = new Rect();
            TextPaint paint  = new TextPaint();

            paint.Color    = Element.TextColor.ToAndroid();
            paint.TextSize = Element.TextSize;
            paint.GetTextBounds(Element.Text.ToString(), 0, Element.Text.ToString().Length, bounds);
            if (((this.Width / 2) - (Element.TextMargin * 4)) < bounds.Width())
            {
                float ratio = (float)((this.Width / 2) - Element.TextMargin * 4) / (float)bounds.Width();
                paint.TextSize *= ratio;
                paint.GetTextBounds(Element.Text.ToString(), 0, Element.Text.ToString().Length, bounds);
            }

            int x = this.Width / 2 - bounds.CenterX();
            int y = this.Height / 2 - bounds.CenterY();

            canvas.DrawText(Element.Text.ToString(), x, y, paint);
        }
Beispiel #10
0
        public void OnDraw(Canvas c, RectF rect, int pos, float dX, View itemView)
        {
            _clickRegion = rect;
            _pos         = pos;

            float cHeight = rect.Height();
            float cWidth  = rect.Width();

            // Draw background
            DrawBackground(c, rect);

            var r         = new Rect();
            var textPaint = new TextPaint
            {
                TextSize = AndroidUtils.ToPixel(TextSize, _context),
                Color    = TextColor
            };

            textPaint.GetTextBounds(Text, 0, Text.Length, r);

            int box      = (int)(r.Height() + cHeight * 0.05 + _iconHeight);
            var extraTop = GetExtraTop(cHeight, box);

            //int iconTop = (int)(rect.Top + GetTop(cHeight, _iconHeight));
            int iconTop    = (int)(rect.Top + extraTop);
            int iconBottom = iconTop + _iconHeight;
            int iconLeft   = 0;
            int iconRight  = 0;

            if (dX > 0)
            {
                iconLeft  = (int)(rect.Left + cWidth / 2 - _iconWidth / 2);
                iconRight = iconLeft + _iconWidth;
            }
            else if (dX < 0)
            {
                iconLeft  = (int)(rect.Left + cWidth / 2 - _iconWidth / 2);
                iconRight = iconLeft + _iconWidth;
            }

            //Draw Text
            bool textWasDrawed = DrawText(c, rect, textPaint, r, iconBottom);

            // Draw Icon
            if (textWasDrawed)
            {
                DrawIcon(c, dX, iconLeft, iconTop, iconRight, iconBottom);
            }
        }
Beispiel #11
0
        public override void Draw(Canvas canvas)
        {
            Rect bounds = Bounds;
            int  height = bounds.Height();

            paint.TextSize = height;
            Rect   textBounds = new Rect();
            string textValue  = icon.Character.ToString();

            paint.GetTextBounds(textValue, 0, 1, textBounds);
            int   textHeight = textBounds.Height();
            float textBottom = bounds.Top + (height - textHeight) / 2f + textHeight - textBounds.Bottom;

            canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, paint);
        }
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            TextPaint paint = new TextPaint();

            paint.AntiAlias = true;
            paint.SetTypeface(Control.Typeface);
            paint.TextSize = myFontSize * scaledDensity;
            paint.Color    = Android.Graphics.Color.Red;

            Paint.FontMetrics metrics = paint.GetFontMetrics();

            Rect bounds = new Rect();

            paint.GetTextBounds(Element.Text, 0, Element.Text.Length, bounds);

            canvas.DrawText(
                Element.Text,
                0.5f * MeasuredWidth - bounds.Left - 0.5f * bounds.Width(),
                0.5f * MeasuredHeight - metrics.Ascent - 0.5f * (metrics.Bottom - metrics.Top),
                paint
                );
        }
Beispiel #13
0
        void DrawChart(Canvas canvas)
        {
            if (barRect == null || barRect.Count == 0)
            {
                return;
            }

            try
            {
                var contentWidth  = Width;
                var contentHeight = Height;

                // background color of the canvas
                canvas.DrawColor(Color.White);

                mTextPaint.SetStyle(Paint.Style.Stroke);
                mTextPaint.AntiAlias   = true;
                mTextPaint.TextAlign   = Paint.Align.Left;
                mTextPaint.StrokeWidth = 0;
                mTextPaint.TextSize    = textSize12;

                //get the text width
                string text   = "0120";
                Rect   bounds = new Rect();
                mTextPaint.GetTextBounds(text, 0, text.Length, bounds);
                int textWidth  = bounds.Width();
                int textHeight = bounds.Height();

                float fcontentWidth  = contentWidth - textWidth;
                float fcontentHeight = contentHeight - textHeight * 2;

                rectGraph.Top    = textHeight + (chartData.Radius * 3) + 5;
                rectGraph.Left   = textWidth * 2;
                rectGraph.Right  = (int)fcontentWidth;
                rectGraph.Bottom = (int)fcontentHeight;

                canvas.DrawRect(rectGraph, mBarPaint);

                // vertical data  preparation
                int   noOfBars  = chartData.BarColors.Count;
                float boxHeight = rectGraph.Height() / noOfBars;

                float prevVal = chartData.BaseValue;
                float diffVal = float.Parse(chartData.YValues[noOfBars - 1]) - prevVal;

                float boxHeight1 = 0;

                mTextPaint.TextSize  = textSize12;
                mTextPaint.Color     = Color.White;
                mTextPaint.TextAlign = Paint.Align.Left;

                mLinePaint.Color       = Color.White;
                mLinePaint.StrokeWidth = mHorizontalLineStroke;

                //Draw vertical data
                for (int i = 0; i < noOfBars; i++)
                {
                    //dynamic height

                    float cVal = float.Parse(chartData.YValues[i]) - prevVal;
                    boxHeight = (cVal * 100) / diffVal;
                    boxHeight = (rectGraph.Height() * boxHeight) / 100;
                    prevVal   = float.Parse(chartData.YValues[i]);

                    mBarPaint.Color = Color.ParseColor(chartData.BarColors[i]);

                    barRect[i].Left   = rectGraph.Left;
                    barRect[i].Top    = rectGraph.Bottom - boxHeight1 - boxHeight;
                    barRect[i].Right  = rectGraph.Right;
                    barRect[i].Bottom = rectGraph.Bottom - boxHeight1;

                    canvas.DrawRect(barRect[i], mBarPaint);

                    mTextPaint.TextSize  = textSize12;
                    mTextPaint.Color     = Color.White;
                    mTextPaint.TextAlign = Paint.Align.Left;

                    canvas.DrawText(chartData.BarText[i], barRect[i].Left + 20, barRect[i].Top + barRect[i].Height() / 2 + textHeight / 2, mTextPaint);
                    canvas.DrawLine(barRect[i].Left, barRect[i].Bottom, barRect[i].Right, barRect[i].Bottom, mLinePaint);

                    mTextPaint.TextSize = textSize10;
                    mTextPaint.Color    = Color.Black;

                    //Draw Vertical texts
                    mTextPaint.TextAlign = Paint.Align.Right;
                    canvas.DrawText(chartData.YValues[i], barRect[i].Left - 10, barRect[i].Top + textHeight / 2, mTextPaint);

                    boxHeight1 += boxHeight;
                }

                canvas.DrawText("" + chartData.BaseValue, barRect[0].Left - 10, barRect[0].Bottom, mTextPaint);

                //409bd6 Circle Color
                mBarPaint.Color = Color.ParseColor("#409bd6");

                //Draw x & Y axis borders
                mTextPaint.StrokeWidth = 5;
                canvas.DrawLine(rectGraph.Left, rectGraph.Top, rectGraph.Left, rectGraph.Bottom, mTextPaint);
                canvas.DrawLine(rectGraph.Left, rectGraph.Bottom, rectGraph.Right, rectGraph.Bottom, mTextPaint);

                //Draw horizontal data
                int horizantalpadding = 20;

                mTextPaint.TextSize = textSize10;
                mTextPaint.Color    = Color.Black;

                int pointdistance = (rectGraph.Width() - horizantalpadding * 2) / (chartData.XValues.Count + 1);

                for (int i = 0; i < chartData.XValues.Count; i++)
                {
                    mTextPaint.Color       = Color.Black;
                    mTextPaint.StrokeWidth = 0;

                    float currentValue = float.Parse(chartData.XValues[i]);

                    int quadrant = GetQuadrant(currentValue);

                    float tempvalue  = 0;
                    int   percentage = 0;
                    float difference = 0;

                    if (quadrant > 0)
                    {
                        tempvalue = currentValue - float.Parse(chartData.YValues[quadrant - 1]);

                        difference = float.Parse(chartData.YValues[quadrant]) - float.Parse(chartData.YValues[quadrant - 1]);

                        percentage = (int)((tempvalue * 100) / (difference));
                    }
                    else
                    {
                        tempvalue = currentValue - chartData.BaseValue;

                        difference = float.Parse(chartData.YValues[quadrant]) - chartData.BaseValue;

                        percentage = (int)((tempvalue * 100) / (difference));
                    }

                    //Avoid drawing out of the bounds

                    if (percentage > 100)
                    {
                        percentage = percentage + (chartData.Radius);
                    }



                    //calculate box height
                    float ycenterpoint = 0;
                    if (barRect.Count - 1 >= i)
                    {
                        ycenterpoint = (barRect[i].Height() * percentage) / 100;
                    }
                    else
                    {
                        ycenterpoint = (barRect[i - 1].Height() * percentage) / 100;
                    }



                    mTextPaint.TextAlign = Paint.Align.Center;

                    //draw x legends
                    mTextPaint.TextSize = textSize10;
                    mTextPaint.GetTextBounds(chartData.Legends[i], 0, chartData.Legends[i].Length, bounds);
                    textHeight = bounds.Height();
                    canvas.DrawText(chartData.Legends[i], (pointdistance * (i + 2)), rectGraph.Bottom + textHeight + 10, mTextPaint);


                    // draw vertical Lines
                    mTextPaint.Color       = (Color.DarkGray);
                    mTextPaint.TextAlign   = (Paint.Align.Center);
                    mTextPaint.StrokeWidth = 1;
                    linesRect[i].Left      = (pointdistance * (i + 2));
                    // modify the top value if the last value is beyond last stripe
                    linesRect[i].Top = (int)(barRect[quadrant].Bottom - ycenterpoint);
                    canvas.DrawLine(linesRect[i].Left, linesRect[i].Top, linesRect[i].Left, rectGraph.Bottom, mTextPaint);

                    //draw lines between points
                    mTextPaint.Color       = (Color.Aqua);
                    mTextPaint.StrokeWidth = 2;
                    mTextPaint.SetStyle(Paint.Style.Stroke);

                    if (i == 0)
                    {
                        mLinePath.MoveTo((pointdistance * (i + 2)), linesRect[i].Top);
                    }
                    else
                    {
                        mLinePath.LineTo((pointdistance * (i + 2)), linesRect[i].Top);
                    }
                }

                canvas.DrawPath(mLinePath, mLinePathPaint);


                // plot X  values and draw Circle for them
                for (int i = 0; i < linesRect.Count; i++)
                {
                    // draw Inner circle
                    canvas.DrawCircle(linesRect[i].Left, linesRect[i].Top, chartData.Radius, mBarPaint);

                    // draw outer circle
                    mTextPaint.Color = (Color.Black);
                    canvas.DrawCircle(linesRect[i].Left, linesRect[i].Top, chartData.Radius, mTextPaint);

                    // draw x values
                    mTextPaint.Color    = (Color.White);
                    mTextPaint.TextSize = textSize8;
                    canvas.DrawText(chartData.XValues[i], linesRect[i].Left, linesRect[i].Top + textHeight / 2, mTextPaint);
                }
            }
            catch (System.Exception e)
            {
                throw new System.Exception("Withdrawal failed", e);
            }
        }
Beispiel #14
0
        protected override void OnDraw(Canvas canvas)
        {
            var scale = this.Context.Resources.DisplayMetrics.Density;

            var frame = GetFramingRect();

            if (frame == null)
            {
                return;
            }

            var width  = canvas.Width;
            var height = canvas.Height;

            paint.Color = resultBitmap != null ? resultColor : maskColor;
            paint.Alpha = 100;

            canvas.DrawRect(0, 0, width, frame.Top, paint);
            //canvas.DrawRect(0, frame.Top, frame.Left, frame.Bottom + 1, paint);
            //canvas.DrawRect(frame.Right + 1, frame.Top, width, frame.Bottom + 1, paint);
            canvas.DrawRect(0, frame.Bottom + 1, width, height, paint);

            var textPaint = new TextPaint();

            textPaint.Color    = Color.White;
            textPaint.TextSize = 16 * scale;

            if (!string.IsNullOrEmpty(this.TopText))
            {
                var topTextLayout = new StaticLayout(this.TopText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);
                canvas.Save();
                Rect topBounds = new Rect();

                textPaint.GetTextBounds(this.TopText, 0, this.TopText.Length, topBounds);
                canvas.Translate(0, frame.Top / 2 - (topTextLayout.Height / 2));

                //canvas.Translate(topBounds.Left, topBounds.Bottom);
                topTextLayout.Draw(canvas);

                canvas.Restore();
            }


            if (!string.IsNullOrEmpty(this.BottomText))
            {
                var botTextLayout = new StaticLayout(this.BottomText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);
                canvas.Save();
                Rect botBounds = new Rect();

                textPaint.GetTextBounds(this.BottomText, 0, this.BottomText.Length, botBounds);
                canvas.Translate(0, (frame.Bottom + (canvas.Height - frame.Bottom) / 2) - (botTextLayout.Height / 2));

                //canvas.Translate(topBounds.Left, topBounds.Bottom);
                botTextLayout.Draw(canvas);

                canvas.Restore();
            }



            if (resultBitmap != null)
            {
                paint.Alpha = CURRENT_POINT_OPACITY;
                canvas.DrawBitmap(resultBitmap, null, new RectF(frame.Left, frame.Top, frame.Right, frame.Bottom), paint);
            }
            else
            {
                // Draw a two pixel solid black border inside the framing rect
                paint.Color = frameColor;
                //canvas.DrawRect(frame.Left, frame.Top, frame.Right + 1, frame.Top + 2, paint);
                //canvas.DrawRect(frame.Left, frame.Top + 2, frame.Left + 2, frame.Bottom - 1, paint);
                //canvas.DrawRect(frame.Right - 1, frame.Top, frame.Right + 1, frame.Bottom - 1, paint);
                //canvas.DrawRect(frame.Left, frame.Bottom - 1, frame.Right + 1, frame.Bottom + 1, paint);

                // Draw a red "laser scanner" line through the middle to show decoding is active
                paint.Color  = laserColor;
                paint.Alpha  = SCANNER_ALPHA[scannerAlpha];
                scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.Length;
                int middle = frame.Height() / 2 + frame.Top;
                //int middle = frame.Width() / 2 + frame.Left;

                //canvas.DrawRect(frame.Left + 2, middle - 1, frame.Right - 1, middle + 2, paint);

                canvas.DrawRect(0, middle - 1, width, middle + 2, paint);
                //canvas.DrawRect(middle - 1, frame.Top + 2, middle + 2, frame.Bottom - 1, paint); //frame.Top + 2, middle - 1, frame.Bottom - 1, middle + 2, paint);

                //var previewFrame = scanner.GetFramingRectInPreview();
                //float scaleX = frame.Width() / (float) previewFrame.Width();
                //float scaleY = frame.Height() / (float) previewFrame.Height();

                /*var currentPossible = possibleResultPoints;
                 * var currentLast = lastPossibleResultPoints;
                 *
                 * int frameLeft = frame.Left;
                 * int frameTop = frame.Top;
                 *
                 * if (currentPossible == null || currentPossible.Count <= 0)
                 * {
                 * lastPossibleResultPoints = null;
                 * }
                 * else
                 * {
                 *      possibleResultPoints = new List<com.google.zxing.ResultPoint>(5);
                 *      lastPossibleResultPoints = currentPossible;
                 *      paint.Alpha = CURRENT_POINT_OPACITY;
                 *      paint.Color = resultPointColor;
                 *
                 *      lock (currentPossible)
                 *      {
                 *              foreach (var point in currentPossible)
                 *              {
                 *                      canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                 * frameTop + (int) (point.Y * scaleY), POINT_SIZE, paint);
                 *              }
                 *      }
                 * }
                 *
                 * if (currentLast != null)
                 * {
                 *      paint.Alpha = CURRENT_POINT_OPACITY / 2;
                 *      paint.Color = resultPointColor;
                 *
                 *      lock (currentLast)
                 *      {
                 *              float radius = POINT_SIZE / 2.0f;
                 *              foreach (var point in currentLast)
                 *              {
                 *                      canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                 * frameTop + (int) (point.Y * scaleY), radius, paint);
                 *              }
                 *      }
                 * }
                 */

                // Request another update at the animation interval, but only repaint the laser line,
                // not the entire viewfinder mask.
                PostInvalidateDelayed(ANIMATION_DELAY,
                                      frame.Left - POINT_SIZE,
                                      frame.Top - POINT_SIZE,
                                      frame.Right + POINT_SIZE,
                                      frame.Bottom + POINT_SIZE);
            }

            base.OnDraw(canvas);
        }
		protected override void OnDraw (Canvas canvas)
		{
			
			var scale = this.Context.Resources.DisplayMetrics.Density;

			var frame = GetFramingRect();
			if (frame == null)
				return;

			var width = canvas.Width;
			var height = canvas.Height;

			paint.Color = resultBitmap != null ? resultColor : maskColor;
			paint.Alpha = 100;

			canvas.DrawRect(0, 0, width, frame.Top, paint);
			//canvas.DrawRect(0, frame.Top, frame.Left, frame.Bottom + 1, paint);
			//canvas.DrawRect(frame.Right + 1, frame.Top, width, frame.Bottom + 1, paint);
			canvas.DrawRect(0, frame.Bottom + 1, width, height, paint);

		
			var textPaint = new TextPaint();
			textPaint.Color = Color.White;
			textPaint.TextSize = 16 * scale;

			var topTextLayout = new StaticLayout(this.TopText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);
			canvas.Save();
			Rect topBounds = new Rect();

			textPaint.GetTextBounds(this.TopText, 0, this.TopText.Length, topBounds);
			canvas.Translate(0, frame.Top / 2 - (topTextLayout.Height / 2));

			//canvas.Translate(topBounds.Left, topBounds.Bottom);
			topTextLayout.Draw(canvas);

			canvas.Restore();


			var botTextLayout = new StaticLayout(this.BottomText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);
			canvas.Save();
			Rect botBounds = new Rect();
			
			textPaint.GetTextBounds(this.BottomText, 0, this.BottomText.Length, botBounds);
			canvas.Translate(0, (frame.Bottom + (canvas.Height - frame.Bottom) / 2) - (botTextLayout.Height / 2));
			
			//canvas.Translate(topBounds.Left, topBounds.Bottom);
			botTextLayout.Draw(canvas);
			
			canvas.Restore();





			if (resultBitmap != null)
			{
				paint.Alpha = CURRENT_POINT_OPACITY;
				canvas.DrawBitmap(resultBitmap, null, new RectF(frame.Left, frame.Top, frame.Right, frame.Bottom), paint);
			}
			else
			{
				 // Draw a two pixel solid black border inside the framing rect
				paint.Color = frameColor;
				//canvas.DrawRect(frame.Left, frame.Top, frame.Right + 1, frame.Top + 2, paint);
				//canvas.DrawRect(frame.Left, frame.Top + 2, frame.Left + 2, frame.Bottom - 1, paint);
				//canvas.DrawRect(frame.Right - 1, frame.Top, frame.Right + 1, frame.Bottom - 1, paint);
				//canvas.DrawRect(frame.Left, frame.Bottom - 1, frame.Right + 1, frame.Bottom + 1, paint);

				// Draw a red "laser scanner" line through the middle to show decoding is active
				paint.Color = laserColor;
				paint.Alpha = SCANNER_ALPHA[scannerAlpha];
				scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.Length;
				int middle = frame.Height() / 2 + frame.Top;
				//int middle = frame.Width() / 2 + frame.Left;

				//canvas.DrawRect(frame.Left + 2, middle - 1, frame.Right - 1, middle + 2, paint);

				canvas.DrawRect(0, middle - 1, width, middle + 2, paint);
				//canvas.DrawRect(middle - 1, frame.Top + 2, middle + 2, frame.Bottom - 1, paint); //frame.Top + 2, middle - 1, frame.Bottom - 1, middle + 2, paint);

				//var previewFrame = scanner.GetFramingRectInPreview();
      			//float scaleX = frame.Width() / (float) previewFrame.Width();
      			//float scaleY = frame.Height() / (float) previewFrame.Height();

				/*var currentPossible = possibleResultPoints;
				var currentLast = lastPossibleResultPoints;

				int frameLeft = frame.Left;
				int frameTop = frame.Top;

				if (currentPossible == null || currentPossible.Count <= 0) 
				{
        			lastPossibleResultPoints = null;
				} 
				else 
				{
					possibleResultPoints = new List<com.google.zxing.ResultPoint>(5);
					lastPossibleResultPoints = currentPossible;
					paint.Alpha = CURRENT_POINT_OPACITY;
					paint.Color = resultPointColor;

					lock (currentPossible) 
					{
						foreach (var point in currentPossible) 
						{
							canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                              frameTop + (int) (point.Y * scaleY), POINT_SIZE, paint);
						}
					}
				}

				if (currentLast != null) 
				{
					paint.Alpha = CURRENT_POINT_OPACITY / 2;
					paint.Color = resultPointColor;

					lock (currentLast) 
					{
						float radius = POINT_SIZE / 2.0f;
						foreach (var point in currentLast) 
						{
							canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                              frameTop + (int) (point.Y * scaleY), radius, paint);
						}
					}
				}
				*/

				// Request another update at the animation interval, but only repaint the laser line,
				// not the entire viewfinder mask.
				PostInvalidateDelayed(ANIMATION_DELAY,
				                      frame.Left - POINT_SIZE,
				                      frame.Top - POINT_SIZE,
				                      frame.Right + POINT_SIZE,
				                      frame.Bottom + POINT_SIZE);
			}

			base.OnDraw (canvas);
		}
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if (Control.GetCompoundDrawables() != null && BaseElement.CenterImage)
            {
                var text            = Control.Text;
                int iconTextSpacing = 0;

                if (!string.IsNullOrWhiteSpace(text))
                {
                    TextPaint textPaint = Control.Paint;
                    textPaint.GetTextBounds(text, 0, text.Length, textBounds);
                    iconTextSpacing = 20;
                }
                else
                {
                    textBounds.SetEmpty();
                }

                int width = Control.Width - (Control.PaddingLeft + Control.PaddingRight);

                Drawable[] drawables = Control.GetCompoundDrawables();

                if (drawables[0] != null)
                {
                    drawables[0].CopyBounds(drawableBounds);

                    int leftOffset =
                        (width - (textBounds.Width() + drawableBounds.Width())) / 2 - Control.CompoundDrawablePadding - iconTextSpacing;

                    if (drawableBounds.Left == 0 && drawableBounds.Left != leftOffset)
                    {
                        drawableBounds.Offset(leftOffset, 0);
                        drawables[0].SetBounds(drawableBounds.Left, drawableBounds.Top, drawableBounds.Right, drawableBounds.Bottom);
                    }
                }

                if (drawables[2] != null)
                {
                    drawables[2].CopyBounds(drawableBounds);

                    int rightOffset =
                        ((textBounds.Width() + drawableBounds.Width()) - width) / 2 + Control.CompoundDrawablePadding + iconTextSpacing;

                    if (drawableBounds.Left == 0 && drawableBounds.Right != rightOffset)
                    {
                        drawableBounds.Offset(rightOffset, 0);
                        drawables[2].SetBounds(drawableBounds.Left, drawableBounds.Top, drawableBounds.Right, drawableBounds.Bottom);
                    }
                }
            }


            //if (Control.GetCompoundDrawables() != null)
            //{
            //    if (BaseElement.CenterImage)
            //    {
            //        var imageRight = Control.GetCompoundDrawables()[2];
            //        if (imageRight != null)
            //        {
            //            var drawableBounds = new Android.Graphics.Rect();
            //            imageRight.CopyBounds(drawableBounds);
            //            SetImagePadding(drawableBounds.Width());
            //        }

            //        var imageLeft = Control.GetCompoundDrawables()[0];
            //        if (imageLeft != null)
            //        {
            //            var drawableBounds = new Android.Graphics.Rect();
            //            imageLeft.CopyBounds(drawableBounds);
            //            SetImagePadding(drawableBounds.Width());
            //        }
            //    }
            //}
        }
		void drawLabel (Canvas canvas, float xCoord, float yCoord, Paint.Align alignment, string label, bool centerVertical = false)
		{
			var fontColor = Color.White;

			var textPaint = new TextPaint ();

			textPaint.Color = fontColor;

			textPaint.TextSize = fontSize;

			textPaint.TextAlign = alignment;

			textPaint.SetStyle (Paint.Style.Stroke);


			var frame = new Rect ();

			textPaint.GetTextBounds (label, 0, label.Length, frame);

			if (centerVertical) {

				yCoord -= frame.CenterY ();

			} else {

				yCoord += frame.Height ();
			}

			canvas.DrawText (label, xCoord, yCoord, textPaint);
		}
Beispiel #18
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);
            }
        }
Beispiel #19
0
        protected override void DrawCallout(Canvas canvas, NMapView mapView, bool shadow, long when)
        {
            AdjustTextBounds(mapView);

            StepAnimations(canvas, mapView, when);

            DrawBackground(canvas);

            float left, top;

            // draw title
            mOffsetX  = MTempPoint.X - MTempRect.Width() / 2;
            mOffsetX -= mPaddingOffset;
            mOffsetY  = MTempRectF.Top + mPaddingY + mTextPaint.TextSize + mTitleOffsetY;
            canvas.DrawText(mTitleTruncated, mOffsetX, mOffsetY, mTextPaint);

            // draw right button
            if (mDrawableRightButton != null)
            {
                left = MTempRectF.Right - mPaddingX - mCalloutRightButtonWidth;
                top  = MTempRectF.Top + (mBackgroundHeight - mCalloutRightButtonHeight) / 2;

                // Use background drawables depends on current state
                mRightButtonRect.Left   = (int)(left + 0.5F);
                mRightButtonRect.Top    = (int)(top + 0.5F);
                mRightButtonRect.Right  = (int)(left + mCalloutRightButtonWidth + 0.5F);
                mRightButtonRect.Bottom = (int)(top + mCalloutRightButtonHeight + 0.5F);

                int      itemState = base.GetItemState(0);
                Drawable drawable  = GetDrawable(0, itemState);
                if (drawable != null)
                {
                    drawable.Bounds = mRightButtonRect;
                    drawable.Draw(canvas);
                }

                if (mRightButtonText != null)
                {
                    mTextPaint.GetTextBounds(mRightButtonText, 0, mRightButtonText.Length, MTempRect);

                    left = mRightButtonRect.Left + (mCalloutRightButtonWidth - MTempRect.Width()) / 2;
                    top  = mRightButtonRect.Top + (mCalloutRightButtonHeight - MTempRect.Height()) / 2 + MTempRect.Height() + mTitleOffsetY;
                    canvas.DrawText(mRightButtonText, left, top, mTextPaint);
                }
            }

            // draw tail text
            if (mTailText != null)
            {
                if (mRightButtonRect != null)
                {
                    left = mRightButtonRect.Left;
                }
                else
                {
                    left = MTempRectF.Right;
                }
                left -= mPaddingX + mTailTextWidth;
                top   = mOffsetY;

                canvas.DrawText(mTailText, left, top, mTextPaint);
            }
        }