Example #1
0
        private static TextPaint InnerBuildPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, BaseLineAlignment baselineAlignment, UnderlineStyle underlineStyle)
        {
            var paint = new TextPaint(PaintFlags.AntiAlias);

            var paintSpecs = BuildPaintValueSpecs(fontSize, characterSpacing);

            paint.Density       = paintSpecs.density;
            paint.TextSize      = paintSpecs.textSize;
            paint.UnderlineText = underlineStyle == UnderlineStyle.Single;

            if (baselineAlignment == BaseLineAlignment.Superscript)
            {
                paint.BaselineShift += (int)(paint.Ascent() / 2);
            }

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                paint.LetterSpacing = paintSpecs.letterSpacing;
            }
            else
            {
                LogCharacterSpacingNotSupported();
            }

            var typefaceStyle = TypefaceStyleHelper.GetTypefaceStyle(fontStyle, fontWeight);
            var typeface      = FontHelper.FontFamilyToTypeFace(fontFamily, fontWeight, typefaceStyle);

            paint.SetTypeface(typeface);
            paint.Color = foreground;

            return(paint);
        }
        public override void OnChildDraw(Canvas c, RecyclerView recyclerView,
                                         ViewHolder viewHolder,
                                         float dX, float dY,
                                         int actionState, bool isCurrentlyActive)
        {
            var isInvalidIndex  = viewHolder.AdapterPosition == -1;
            var isTimeEntryCell = viewHolder is MainRecyclerViewLogViewHolder;

            if (isInvalidIndex || !isTimeEntryCell)
            {
                return;
            }

            var itemView        = viewHolder.ItemView;
            var isSwippingRight = dX > 0;

            int direction, leftOffset, rightOffset, textX = 0;

            if (isSwippingRight)
            {
                direction   = right;
                textX       = textMargin;
                leftOffset  = itemView.Left;
                rightOffset = itemView.Left + (int)dX;
            }
            else
            {
                direction   = left;
                leftOffset  = itemView.Right + (int)dX;
                rightOffset = itemView.Right;
                textX       = rightOffset - textMargin - deleteTextWidth;
            }

            var textY = (int)((itemView.Height / 2) - ((textPaint.Descent() + textPaint.Ascent()) / 2)) + itemView.Top;

            backgrounds[direction].SetBounds(leftOffset, itemView.Top, rightOffset, itemView.Bottom);
            backgrounds[direction].Draw(c);
            c.DrawText(text[direction], textX, textY, textPaint);

            base.OnChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }
Example #3
0
        private int MeasureHeight(int measureSpec)
        {
            int specMode = Convert.ToInt32(MeasureSpec.GetMode(measureSpec));
            int specSize = MeasureSpec.GetSize(measureSpec);
            int mAscent  = (int)mTextPaintOutline.Ascent();
            int result;

            if (specMode == (int)MeasureSpecMode.Exactly)
            {
                result = specSize;
            }
            else
            {
                result = (int)(-mAscent + mTextPaintOutline.Descent()) + PaddingTop + PaddingBottom;
                if (specMode == (int)MeasureSpecMode.Exactly)
                {
                    result = Math.Min(result, specSize);
                }
            }
            return(result);
        }
Example #4
0
        /// <summary>Define paints.</summary>
        private void InitPaint()
        {
            // Round rectangle paint
            _strokePaint = new Paint
            {
                Color       = _selectedColor.ToColor(),
                AntiAlias   = true,
                StrokeWidth = _strokeWidth
            };
            _strokePaint.SetStyle(Paint.Style.Stroke);


            // Selected paint
            _fillPaint = new Paint
            {
                Color = _selectedColor.ToColor()
            };
            _strokePaint.AntiAlias = true;
            _fillPaint.SetStyle(Paint.Style.FillAndStroke);


            // Selected text paint
            _selectedTextPaint = new TextPaint(PaintFlags.AntiAlias)
            {
                TextSize = _textSize,
                Color    = unchecked ((int)0xffffffff).ToColor()
            };
            _strokePaint.AntiAlias = true;

            // Unselected text paint
            _unselectedTextPaint = new TextPaint(PaintFlags.AntiAlias)
            {
                TextSize = _textSize,
                Color    = _selectedColor.ToColor()
            };

            _strokePaint.AntiAlias = true;
            _textHeightOffset      = -(_selectedTextPaint.Ascent() + _selectedTextPaint.Descent()) * 0.5f;
            _fontMetrics           = _selectedTextPaint.GetFontMetrics();
        }
        public Stream GetFilledCircleWithCenteredText(int imgSize, String rgbCircleColor, String txt, String rgbTextColor, string fontFamilyName, int fontSize)
        {
            Stream result = null;

            using (Bitmap bitmapResult = Bitmap.CreateBitmap(imgSize, imgSize, Bitmap.Config.Argb8888))
            {
                using (Canvas canvas = new Canvas(bitmapResult))
                {
                    using (Paint paintBgd = new Paint(PaintFlags.AntiAlias))
                    {
                        paintBgd.Color = Color.ParseColor(rgbCircleColor);

                        canvas.DrawColor(Color.Transparent);
                        canvas.DrawOval(new RectF(0, 0, imgSize, imgSize), paintBgd);
                    }

                    //TODO: use fontName...
                    using (TextPaint textPaint = new TextPaint(PaintFlags.AntiAlias))
                    {
                        textPaint.Color     = Color.ParseColor(rgbTextColor);
                        textPaint.TextAlign = Paint.Align.Center;
                        textPaint.TextSize  = (int)(fontSize * GetDensity());

                        float textHeight = textPaint.Descent() - textPaint.Ascent();
                        float textOffset = (textHeight / 2) - textPaint.Descent();

                        using (RectF bounds = new RectF(0, 0, imgSize, imgSize))
                            canvas.DrawText(txt, bounds.CenterX(), bounds.CenterY() + textOffset, textPaint);
                    }
                    result = GetStreamFromBitmap(bitmapResult);
                }
                //bitmapResult.Recycle();
            }

            return(result);
        }
Example #6
0
 void Apply(TextPaint paint)
 {
     paint.BaselineShift = (int)(_ratio * paint.Ascent());
 }