Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Ellipsis placement for multiline TextView #132

Closed
nathanielwolf opened this issue Feb 6, 2015 · 5 comments
Closed

Incorrect Ellipsis placement for multiline TextView #132

nathanielwolf opened this issue Feb 6, 2015 · 5 comments

Comments

@nathanielwolf
Copy link

When ellipsizing multiline TextView's that use Calligraphy, the results look like the following about 20% of the time:

screen shot 2015-02-06 at 8 19 35 am

The xml used is:

  <TextView
      android:id="@+id/text"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:maxLines="4"
      android:ellipsize="end"
      fontPath="fonts/Lato-Light.ttf"
      tools:ignore="MissingPrefix"/>

Using solutions like Micah's here results in the TextView loosing it's custom font.
http://stackoverflow.com/questions/2160619/android-ellipsize-multiline-textview

Any suggestions?

@chrisjenx
Copy link
Owner

Interesting. There was an issue with ellipsize on the ActionBar as we use Spans to set typeface on those, everywhere else we use native methods.

Calligraphy won't cause the above effect, we just call setTypeface on TextViews which in turn calls setTypeface() on mTextPaint in the TextView.

Looking at the linked solution, it's hard to decipher what is going on let alone what could potentially cause the issue. I would assume something like calling the StaticLayout is clearing (or overriding) the TextViews Paint object.

Someone else here might be able to spread some more light on the issue. As per usual this feels like an Android bug (although can't confirm that yet).

@nathanielwolf
Copy link
Author

I agree ellipsizing multiline text in Android is buggy, hence the stackoverflow question and solution, so perhaps the issue is not with Calligraphy here.

Perhaps the reason why the EllipsizingTextView does not have the specified custom font is because we call builder.disableCustomViewInflation(); when initializing Calligraphy. Without calling this we get a crash in Mortar

The documentation of 'disableCustomViewInflation' states:

But if you want Calligraphy to inject the correct typeface then you will need to make sure your CustomView's are created before reaching the LayoutInflater onViewCreated.

How can we insure a view is created before onViewCreated is reached?

@chrisjenx
Copy link
Owner

Have a look at the ActionBarActivity#onCreateViewfor an example.

Not sure why you need to disable it? I use mortar and calligraphy fine.

Create an issue with that stack trace so I can compare with my setup.

On Mon, 9 Feb 2015 23:38 Nathaniel Wolf [email protected] wrote:

I agree ellipsizing multiline text in Android is buggy, hence the
stackoverflow question and solution, so perhaps the issue is not with
Calligraphy here.

Perhaps the reason why the EllipsizingTextView does not have the specified
custom font is because we call 'builder.disableCustomViewInflation();` when
initializing Calligraphy. Without calling this we get a crash in Mortar
https://github.com/square/mortar

The documentation of 'disableCustomViewInflation' states:

But if you want Calligraphy to inject the correct typeface then you will
need to make sure your CustomView's are created before reaching the
LayoutInflater onViewCreated.

How can we insure a view is created before onViewCreated is reached?


Reply to this email directly or view it on GitHub
#132 (comment)
.

@nathanielwolf
Copy link
Author

Mortar crash issue created: #135

@chrisjenx
Copy link
Owner

So @nathanielwolf, If you enable disableCustomViewInflation() You'll need to inflate your custom views manually otherwise Calligraphy can not apply the Typeface to it.

e.g. MyActivity

    @Override
    public View onCreateView(final String name, @NonNull final Context context, @NonNull final AttributeSet attrs) {
        switch (name) {
            case "EllipsizeTextView":
                return new EllipsizeTextView(this, attrs);
        }
        return super.onCreateView(name, context, attrs);
    }

I'm going to close as it will apply the Typeface if you allow Calligraphy to create the view. Or you create it. I'll look into the Mortar issue separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants