Comments (4)
the infinite loop is a workaround for this bug, so that if the IndexOutOfBoundsException
is thrown, we can remove the spans and try again. it's possible to re-write this with a method instead (and just re-call the method without the Spannables in the IndexOutOfBounds
scenario, but that's not much nicer either).
is there any specific issue your'e running into with this? this should never actually infinite loop (due to the break when no exception is thrown, a single loop if an IndexOutOfBoundsException
is thrown and we are in the spannable case, or an exception being bubbled up).
from textlayoutbuilder.
Ok, then better remove loop, because it's confused
try {
layout = makeStaticLayout(numLines, width);
} catch (IndexOutOfBoundsException e) {
// Workaround for https://code.google.com/p/android/issues/detail?id=35412
if (!(mParams.text instanceof String)) {
// remove all Spannables and re-try
Log.e("TextLayoutBuilder", "Hit bug #35412, retrying with Spannables removed", e);
mParams.text = mParams.text.toString();
layout = makeStaticLayout(numLines, width);
} else {
// If it still happens with all Spannables removed we'll bubble the exception up
throw e;
}
}
private StaticLayout makeStaticLayout(int numLines, int width) {
return StaticLayoutHelper.make(
mParams.text,
0,
mParams.text.length(),
mParams.paint,
width,
mParams.alignment,
mParams.spacingMult,
mParams.spacingAdd,
mParams.includePadding,
mParams.ellipsize,
width,
numLines,
mParams.textDirection);
}
from textlayoutbuilder.
If you try the workaround for a bug on some Android API version, then better to check current API version, because current solution is not optimal.
from textlayoutbuilder.
Can you please send in a pull request? Closing this for now.
from textlayoutbuilder.
Related Issues (19)
- Support for break strategy HOT 3
- AbsoluteSizeSpan doesn't Scale Correctly
- `public Layout build()` method should contain @Nullable annotation for better kotlin interop
- Layout on background thread? HOT 5
- Set alignment is not work HOT 2
- No support for letter spacing
- Add support for setJustificationMode HOT 1
- Gradle fails to resolve version 1.3.1 HOT 4
- No release notes for 1.5.0 HOT 1
- How to set clickable span with staticLayout HOT 1
- What about migration on AndroidX?
- Restrictions on non-SDK interfaces HOT 1
- Abc
- Threre is no "setTextAppearance()" method in TextLayoutBuilder HOT 2
- the hide constructor method of android.text.StaticLayout HOT 2
- Usage 3 the method onDraw is wrong HOT 1
- GlyphWarmerImpl's Picture is not drawn on View? HOT 2
- Creation of StaticLayout HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textlayoutbuilder.