コード例 #1
0
        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);
        }
コード例 #2
0
        public CompassViewDrawer(IPoiCategoryBitmapProvider poiCategoryBitmapProvider)
        {
            Typeface normal = Typeface.Create("Arial", TypefaceStyle.Normal);

            this.poiCategoryBitmapProvider = poiCategoryBitmapProvider;

            paintRect = new Paint();
            paintRect.SetARGB(150, 0, 0, 0);
            paintRect.SetStyle(Paint.Style.FillAndStroke);
            paintRect.StrokeWidth = 4;

            paintTapArea = new Paint();
            paintTapArea.SetARGB(100, 0, 0, 0);
            paintTapArea.SetStyle(Paint.Style.Fill);

            paintTapFavourite = new Paint();
            paintTapFavourite.SetARGB(150, 255, 195, 0);
            paintTapFavourite.SetStyle(Paint.Style.Fill);

            paintRectSelectedItem = new Paint();
            paintRectSelectedItem.SetARGB(150, 255, 255, 255);
            paintRectSelectedItem.SetStyle(Paint.Style.FillAndStroke);
            paintRectSelectedItem.StrokeWidth = 4;

            textpaint = new Paint();
            textpaint.SetARGB(255, 200, 255, 0);
            textpaint.TextSize  = 36;
            textpaint.AntiAlias = true;
            textpaint.SetTypeface(normal);

            textpaintSelected = new Paint();
            textpaintSelected.SetARGB(255, 0, 0, 0);
            textpaintSelected.TextSize  = 36;
            textpaintSelected.AntiAlias = true;
            textpaintSelected.SetTypeface(normal);

            textPaintForEllipsize = new TextPaint();
            textPaintForEllipsize.SetARGB(255, 200, 255, 0);
            textPaintForEllipsize.SetStyle(Paint.Style.Fill);
            textPaintForEllipsize.TextSize   = 36;
            textPaintForEllipsize.AntiAlias  = true;
            textPaintForEllipsize.TextAlign  = Paint.Align.Left;
            textPaintForEllipsize.LinearText = true;

            paintWhite = new Paint();
            paintWhite.SetARGB(255, 255, 255, 255);
            paintWhite.SetStyle(Paint.Style.Fill);

            paintGray = new Paint();
            paintGray.SetARGB(255, 186, 186, 186);
            paintGray.SetStyle(Paint.Style.Fill);

            paintBlack = new Paint();
            paintBlack.SetARGB(255, 0, 0, 0);
            paintBlack.SetStyle(Paint.Style.Fill);

            multiplier = 1;
        }
コード例 #3
0
        private static NativeCanvasState CreateNewState(object context)
        {
            if (_defaultFillPaint == null)
            {
                _defaultFillPaint = new global::Android.Graphics.Paint();
                _defaultFillPaint.SetARGB(255, 255, 255, 255);
                _defaultFillPaint.SetStyle(global::Android.Graphics.Paint.Style.Fill);
                _defaultFillPaint.AntiAlias = true;

                _defaultStrokePaint = new global::Android.Graphics.Paint();
                _defaultStrokePaint.SetARGB(255, 0, 0, 0);
                _defaultStrokePaint.StrokeWidth = 1;
                _defaultStrokePaint.StrokeMiter = CanvasDefaults.DefaultMiterLimit;
                _defaultStrokePaint.SetStyle(global::Android.Graphics.Paint.Style.Stroke);
                _defaultStrokePaint.AntiAlias = true;

                _defaultFontPaint = new TextPaint();
                _defaultFontPaint.SetARGB(255, 0, 0, 0);
                _defaultFontPaint.AntiAlias = true;

                var arial = NativeFontService.Instance.GetTypeface("Arial");
                if (arial != null)
                {
                    _defaultFontPaint.SetTypeface(arial);
                }
                else
                {
                    Logger.Warn("Unable to set the default font paint to Arial");
                }
            }

            var state = new NativeCanvasState
            {
                FillPaint   = new global::Android.Graphics.Paint(_defaultFillPaint),
                StrokePaint = new global::Android.Graphics.Paint(_defaultStrokePaint),
                FontPaint   = new TextPaint(_defaultFontPaint),
                FontName    = NativeFontService.SystemFont
            };

            return(state);
        }