Rotate text inside wheel of fortune - Android









up vote
2
down vote

favorite
1












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;












share|improve this question























  • Broken link for second immage
    – Marcos Vasconcelos
    Aug 9 at 17:31










  • @MarcosVasconcelos Really? well, I have uploaded it again
    – Jorge Requez
    Aug 9 at 18:35






  • 1




    Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
    – Marcos Vasconcelos
    Aug 9 at 19:46










  • I solved my problem, thank you anyway!
    – Jorge Requez
    Aug 9 at 20:55










  • My solution worked or something else?
    – Marcos Vasconcelos
    Aug 9 at 21:01














up vote
2
down vote

favorite
1












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;












share|improve this question























  • Broken link for second immage
    – Marcos Vasconcelos
    Aug 9 at 17:31










  • @MarcosVasconcelos Really? well, I have uploaded it again
    – Jorge Requez
    Aug 9 at 18:35






  • 1




    Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
    – Marcos Vasconcelos
    Aug 9 at 19:46










  • I solved my problem, thank you anyway!
    – Jorge Requez
    Aug 9 at 20:55










  • My solution worked or something else?
    – Marcos Vasconcelos
    Aug 9 at 21:01












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





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;












share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 9 at 18:32

























asked Aug 9 at 16:39









Jorge Requez

4919




4919











  • Broken link for second immage
    – Marcos Vasconcelos
    Aug 9 at 17:31










  • @MarcosVasconcelos Really? well, I have uploaded it again
    – Jorge Requez
    Aug 9 at 18:35






  • 1




    Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
    – Marcos Vasconcelos
    Aug 9 at 19:46










  • I solved my problem, thank you anyway!
    – Jorge Requez
    Aug 9 at 20:55










  • My solution worked or something else?
    – Marcos Vasconcelos
    Aug 9 at 21:01
















  • Broken link for second immage
    – Marcos Vasconcelos
    Aug 9 at 17:31










  • @MarcosVasconcelos Really? well, I have uploaded it again
    – Jorge Requez
    Aug 9 at 18:35






  • 1




    Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
    – Marcos Vasconcelos
    Aug 9 at 19:46










  • I solved my problem, thank you anyway!
    – Jorge Requez
    Aug 9 at 20:55










  • My solution worked or something else?
    – Marcos Vasconcelos
    Aug 9 at 21:01















Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31




Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31












@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35




@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35




1




1




Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46




Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46












I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55




I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55












My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01




My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51772117%2frotate-text-inside-wheel-of-fortune-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51772117%2frotate-text-inside-wheel-of-fortune-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands