@@ -258,26 +258,14 @@ private static Layout createLayout(
258
258
// unicode characters.
259
259
260
260
int hintWidth = (int ) Math .ceil (desiredWidth );
261
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) {
262
- layout =
263
- new StaticLayout (
264
- text ,
265
- sTextPaintInstance ,
266
- hintWidth ,
267
- Layout .Alignment .ALIGN_NORMAL ,
268
- 1.f ,
269
- 0.f ,
270
- includeFontPadding );
271
- } else {
272
- layout =
273
- StaticLayout .Builder .obtain (text , 0 , spanLength , sTextPaintInstance , hintWidth )
274
- .setAlignment (Layout .Alignment .ALIGN_NORMAL )
275
- .setLineSpacing (0.f , 1.f )
276
- .setIncludePad (includeFontPadding )
277
- .setBreakStrategy (textBreakStrategy )
278
- .setHyphenationFrequency (hyphenationFrequency )
279
- .build ();
280
- }
261
+ layout =
262
+ StaticLayout .Builder .obtain (text , 0 , spanLength , sTextPaintInstance , hintWidth )
263
+ .setAlignment (Layout .Alignment .ALIGN_NORMAL )
264
+ .setLineSpacing (0.f , 1.f )
265
+ .setIncludePad (includeFontPadding )
266
+ .setBreakStrategy (textBreakStrategy )
267
+ .setHyphenationFrequency (hyphenationFrequency )
268
+ .build ();
281
269
} else if (boring != null && (unconstrainedWidth || boring .width <= width )) {
282
270
int boringLayoutWidth = boring .width ;
283
271
if (boring .width < 0 ) {
@@ -300,32 +288,19 @@ private static Layout createLayout(
300
288
includeFontPadding );
301
289
} else {
302
290
// Is used for multiline, boring text and the width is known.
303
-
304
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) {
305
- layout =
306
- new StaticLayout (
307
- text ,
308
- sTextPaintInstance ,
309
- (int ) width ,
310
- Layout .Alignment .ALIGN_NORMAL ,
311
- 1.f ,
312
- 0.f ,
313
- includeFontPadding );
314
- } else {
315
- StaticLayout .Builder builder =
316
- StaticLayout .Builder .obtain (text , 0 , spanLength , sTextPaintInstance , (int ) width )
317
- .setAlignment (Layout .Alignment .ALIGN_NORMAL )
318
- .setLineSpacing (0.f , 1.f )
319
- .setIncludePad (includeFontPadding )
320
- .setBreakStrategy (textBreakStrategy )
321
- .setHyphenationFrequency (hyphenationFrequency );
322
-
323
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
324
- builder .setUseLineSpacingFromFallbacks (true );
325
- }
326
-
327
- layout = builder .build ();
291
+ StaticLayout .Builder builder =
292
+ StaticLayout .Builder .obtain (text , 0 , spanLength , sTextPaintInstance , (int ) width )
293
+ .setAlignment (Layout .Alignment .ALIGN_NORMAL )
294
+ .setLineSpacing (0.f , 1.f )
295
+ .setIncludePad (includeFontPadding )
296
+ .setBreakStrategy (textBreakStrategy )
297
+ .setHyphenationFrequency (hyphenationFrequency );
298
+
299
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
300
+ builder .setUseLineSpacingFromFallbacks (true );
328
301
}
302
+
303
+ layout = builder .build ();
329
304
}
330
305
return layout ;
331
306
}
@@ -423,7 +398,7 @@ public static long measureText(
423
398
// Android 11+ introduces changes in text width calculation which leads to cases
424
399
// where the container is measured smaller than text. Math.ceil prevents it
425
400
// See T136756103 for investigation
426
- if (android . os . Build .VERSION .SDK_INT > android . os . Build .VERSION_CODES .Q ) {
401
+ if (Build .VERSION .SDK_INT > Build .VERSION_CODES .Q ) {
427
402
calculatedWidth = (float ) Math .ceil (calculatedWidth );
428
403
}
429
404
0 commit comments