Giter Site home page Giter Site logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on September 22, 2024
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 [email protected] on 29 May 2013 at 11:44

from android-augment-reality-framework.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 22, 2024
hi Mr phishman, thx for your reply , but the problem is still there , the 
activity still force closed

Original comment by [email protected] on 30 May 2013 at 12:00

from android-augment-reality-framework.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 22, 2024
this is the logcat that i run with your third solution -pastebin.com/j7Vsp2pg 
,thank you

Original comment by [email protected] on 30 May 2013 at 12:01

from android-augment-reality-framework.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 22, 2024
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 [email protected] on 31 May 2013 at 5:10

from android-augment-reality-framework.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 22, 2024
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 [email protected] on 31 May 2013 at 5:16

  • Changed state: Verified

from android-augment-reality-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.