Rotate text inside wheel of fortune - Android

2

I am using this library to make a wheel of fortune to my app. I have edited some things to make it look like I want but there's something that I couldn't achieve.

I have this: Look at the text directionenter image description here

I want this: Look at the text direction

enter image description here

I couldn't rotate the text values like the second image.

Here's the class that I think is used to draw the text:

public class PielView extends View {

private RectF mRange = new RectF();
private int mRadius;

private Paint mArcPaint;
private Paint mBackgroundPaint;
private Paint mTextPaint;

private float mStartAngle = 0;
private int mCenter;
private int mPadding;
private int mTargetIndex;
private int mRoundOfNumber = 4;
private boolean isRunning = false;

private int defaultBackgroundColor = -1;
private Drawable drawableCenterImage;
private int textColor = 0xffffffff;


private void init() {
    mArcPaint = new Paint();
    mArcPaint.setAntiAlias(true);
    mArcPaint.setDither(true);

    mTextPaint = new Paint();
    mTextPaint.setColor(textColor);
    mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14,
            getResources().getDisplayMetrics()));

    mRange = new RectF(mPadding, mPadding, mPadding+mRadius, mPadding+mRadius);
}


private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mStr) {
    Path path = new Path();
    path.addArc(mRange,tmpAngle,sweepAngle);

    float textWidth = mTextPaint.measureText(mStr);
    int hOffset = (int) (mRadius * Math.PI / mLuckyItemList.size()/2-textWidth/2);

    int vOffset = mRadius/2/4;

    canvas.drawTextOnPath(mStr, path, hOffset, vOffset, mTextPaint);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mLuckyItemList == null) {
        return;
    }

    drawBackgroundColor(canvas, defaultBackgroundColor);

    init();

    float tmpAngle = mStartAngle;
    float sweepAngle = 360 / mLuckyItemList.size();

    for(int i = 0; i < mLuckyItemList.size(); i++) {
        mArcPaint.setColor(mLuckyItemList.get(i).color);
        canvas.drawArc(mRange, tmpAngle, sweepAngle, true, mArcPaint);

        drawText(canvas, tmpAngle, sweepAngle, mLuckyItemList.get(i).text);
        drawImage(canvas, tmpAngle, BitmapFactory.decodeResource(getResources(), mLuckyItemList.get(i).icon));

        tmpAngle += sweepAngle;
      }  
   }
}
android
asked on Stack Overflow Aug 9, 2018 by Jorge Requez • edited Aug 9, 2018 by Jorge Requez

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0