Closed GoogleCodeExporter closed 8 years ago
I've answered on SO but here is "an" answer to help anyone else which
experiences the problem..
In com/jwetherell/augmented_reality/ui/objects/PaintableObject.java
Try changing the method:
public float getTextWidth(String txt) {
if (txt == null) throw new NullPointerException();
//return paint.measureText(txt);
return paint.measureText(txt, 0, txt.length);
}
Or try this if that doesn't work:
public float getTextWidth(String txt) {
if (txt == null) throw new NullPointerException();
//return paint.measureText(txt);
char[] seq = new char[txt.length()];
for(int i =0; i < txt.length(); i++) {
seq[i] = txt.charAt(i);
}
return paint.measureText(seq, 0, seq.length);
}
If all else fails, try this:
public float getTextWidth(String txt) {
if (txt == null) throw new NullPointerException();
//return paint.measureText(txt);
char[] seq = new char[txt.length()];
for(int i =0; i < txt.length(); i++) {
seq[i] = txt.charAt(i);
}
Rect bounds = new Rect();
paint.getTextBounds(seq, 0, seq.length, bounds);
return bounds.width();
}
I believe this is a JNI issue and theses are work arounds for the known JNI
issue. I haven't compiled the code, so there may some mistakes but you get the
idea.
Original comment by phishman3579@gmail.com
on 29 May 2013 at 11:44
hi Mr phishman, thx for your reply , but the problem is still there , the
activity still force closed
Original comment by ronyong9...@gmail.com
on 30 May 2013 at 12:00
this is the logcat that i run with your third solution -pastebin.com/j7Vsp2pg
,thank you
Original comment by ronyong9...@gmail.com
on 30 May 2013 at 12:01
Thank you so much Mr Justin , your solution and effort saved me from getting
fail of this subject, thank you , the problem is solved, thank you
Original comment by ronyong9...@gmail.com
on 31 May 2013 at 5:10
This is another work around, if the ones above do not work.
private StaticLayout measure(TextPaint textPaint, String text, Integer
wrapWidth) {
int boundedWidth = Integer.MAX_VALUE;
if (wrapWidth != null && wrapWidth > 0) {
boundedWidth = wrapWidth;
}
StaticLayout layout = new StaticLayout(text, textPaint, boundedWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
return layout;
}
private float getMaxLineWidth(StaticLayout layout) {
float maxLine = 0.0f;
int lineCount = layout.getLineCount();
for (int i=0; i<lineCount; i++) {
if (layout.getLineWidth(0) > maxLine) {
maxLine = layout.getLineWidth(0);
}
}
return maxLine;
}
public float getTextWidth(String text) {
if (text == null) throw new NullPointerException();
TextPaint textPaint = new TextPaint(paint);
int widthWrap = 1000; // you may have to change this
StaticLayout layout = measure(textPaint, text, widthWrap);
return getMaxLineWidth(layout);
}
Original comment by phishman3579@gmail.com
on 31 May 2013 at 5:16
Original issue reported on code.google.com by
ronyong9...@gmail.com
on 29 May 2013 at 3:51