marcelpinto / RealTextView

A new textview for Android that includes a compilation of libaries to make a real TextView
Apache License 2.0
65 stars 13 forks source link

Crash on RealEditText when setting maxLines #5

Open AndroidDeveloperLB opened 9 years ago

AndroidDeveloperLB commented 9 years ago

Try this XML tag to be added to the sample's "view_activity_example_main.xml" file :

  <com.hardsoftstudio.real.textview.views.RealEditText
        android:id="@+id/w_rtv_example6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:maxLines="2"
        android:padding="10dp"
        android:text="@string/txt_example1"
        android:textSize="30sp"
        real:minTextSize="5sp"/>

Then try to press ENTER twice inside the RealEditText.

The bug:it crashes. Here's the log:

FATAL EXCEPTION: main Process: org.hardsoft.real.textview, PID: 32379 java.lang.StackOverflowError at android.graphics.Paint.getTextRunAdvances(Paint.java:1842) at android.text.MeasuredText.addStyleRun(MeasuredText.java:164) at android.text.MeasuredText.addStyleRun(MeasuredText.java:204) at android.text.StaticLayout.generate(StaticLayout.java:281) at android.text.StaticLayout.(StaticLayout.java:140) at android.text.StaticLayout.(StaticLayout.java:90) at android.text.StaticLayout.(StaticLayout.java:68) at android.text.StaticLayout.(StaticLayout.java:48) at com.hardsoftstudio.real.textview.utils.AutofitHelper.getAutofitTextSize(AutofitHelper.java:151) at com.hardsoftstudio.real.textview.utils.AutofitHelper.getAutofitTextSize(AutofitHelper.java:161) ...

And after this, I have the last line repeating itself.

AndroidDeveloperLB commented 9 years ago

A possible workaround is to add a precision check for getAutofitTextSize :

    if (RealTextView.DEBUG)
        Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid +
            " target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);

    if (lineCount > maxLines&&(high - low) >= precision) {

Also , add for "autofit" the part of setting the min size of the text font:

    float low = minTextSize;

This causes a behavior that will actually permit more lines of text, but at least it won't crash...