Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i have a circular progress bar that has a thumb, i would want the percentage text to be written inside the thumb.
Here is what i have tried

What I have tried:

this updates the progress value(thumb sweep ) on the circular bar
C#
private void updateProgress(int progress, bool fromUser)
{

    if (progress == INVALID_PROGRESS_VALUE)
    {
        return;
    }

    progress = (progress > mMax) ? mMax : progress;
    progress = (progress < 0) ? 0 : progress;
    mProgress = progress;

    if (mOnSeekArcChangeListener != null)
    {
        mOnSeekArcChangeListener.onProgressChanged(this, progress, fromUser);
    }

    mProgressSweep = (float)progress / mMax * mSweepAngle;

    updateThumbPosition();

    Invalidate();
}


this updates the thumb position.
C#
private void updateThumbPosition()
        {
            int thumbAngle = (int)(mStartAngle + mProgressSweep + mRotation + 90);
            mThumbXPos = (int)(mArcRadius * Math.Cos(ToRadian(thumbAngle)));
            mThumbYPos = (int)(mArcRadius * Math.Sin(ToRadian(thumbAngle)));
        }


those are working fine
here is where my issue lie.
C#
public void setProgressBar(int progress, Context context, SeekArc defkk)
        {
            Drawable d = ContextCompat.GetDrawable(context, Resource.Drawable.seek_arc_control_selector);
            Canvas c = new Canvas();
            Bitmap bitmap = Bitmap.CreateBitmap(d.IntrinsicWidth, d.IntrinsicHeight, Bitmap.Config.Argb8888);
            c.SetBitmap(bitmap);
            d.SetBounds(0, 0, d.IntrinsicWidth, d.IntrinsicHeight);
            d.Draw(c);
            //Bitmap bmp = bitmap.Copy(Bitmap.Config.Argb8888, true);
            string text = progress.ToString() + "%";
            Paint p = new Paint();
            p.SetTypeface(Typeface.CreateFromAsset(context.Assets, "fonts/Brandon_bld.otf"));
            p.TextSize = 18;
            p.Color = Color.White;

            int thumbAngle = (int)(mStartAngle + mProgressSweep + mRotation + 90);
            
            int width = (int)p.MeasureText(text);
            int yPos = (int)((c.Height / 2) - ((p.Descent() + p.Ascent()) / 2));
            c.DrawText(text, (bitmap.Width - width) / 2, yPos, p);
            defkk.SetThumb(new BitmapDrawable(Resources, bitmap));
        }


i need to insert the code in the function above in updateProgress. so that as the progress updates, it inserts the text.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900