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);
        }
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }