| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.text; |
| 18 |
|
| 19 |
import android.annotation.FloatRange; |
| 20 |
import android.annotation.IntRange; |
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.compat.annotation.UnsupportedAppUsage; |
| 24 |
import android.graphics.Paint; |
| 25 |
import android.graphics.Rect; |
| 26 |
import android.os.Build; |
| 27 |
import android.text.style.ReplacementSpan; |
| 28 |
import android.text.style.UpdateLayout; |
| 29 |
import android.text.style.WrapTogetherSpan; |
| 30 |
import android.util.ArraySet; |
| 31 |
import android.util.Pools.SynchronizedPool; |
| 32 |
|
| 33 |
import com.android.internal.annotations.VisibleForTesting; |
| 34 |
import com.android.internal.util.ArrayUtils; |
| 35 |
import com.android.internal.util.GrowingArrayUtils; |
| 36 |
|
| 37 |
import java.lang.ref.WeakReference; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public class DynamicLayout extends Layout { |
| 48 |
private static final int PRIORITY = 128; |
| 49 |
private static final int BLOCK_MINIMUM_CHARACTER_LENGTH = 400; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static final class Builder { |
| 60 |
private Builder() { |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
@NonNull |
| 67 |
public static Builder obtain(@NonNull CharSequence base, @NonNull TextPaint paint, |
| 68 |
@IntRange(from = 0) int width) { |
| 69 |
Builder b = sPool.acquire(); |
| 70 |
if (b == null) { |
| 71 |
b = new Builder(); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
b.mBase = base; |
| 76 |
b.mDisplay = base; |
| 77 |
b.mPaint = paint; |
| 78 |
b.mWidth = width; |
| 79 |
b.mAlignment = Alignment.ALIGN_NORMAL; |
| 80 |
b.mTextDir = TextDirectionHeuristics.FIRSTSTRONG_LTR; |
| 81 |
b.mSpacingMult = DEFAULT_LINESPACING_MULTIPLIER; |
| 82 |
b.mSpacingAdd = DEFAULT_LINESPACING_ADDITION; |
| 83 |
b.mIncludePad = true; |
| 84 |
b.mFallbackLineSpacing = false; |
| 85 |
b.mEllipsizedWidth = width; |
| 86 |
b.mEllipsize = null; |
| 87 |
b.mBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE; |
| 88 |
b.mHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE; |
| 89 |
b.mJustificationMode = Layout.JUSTIFICATION_MODE_NONE; |
| 90 |
return b; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
private static void recycle(@NonNull Builder b) { |
| 98 |
b.mBase = null; |
| 99 |
b.mDisplay = null; |
| 100 |
b.mPaint = null; |
| 101 |
sPool.release(b); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
@NonNull |
| 113 |
public Builder setDisplayText(@NonNull CharSequence display) { |
| 114 |
mDisplay = display; |
| 115 |
return this; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
@NonNull |
| 125 |
public Builder setAlignment(@NonNull Alignment alignment) { |
| 126 |
mAlignment = alignment; |
| 127 |
return this; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
@NonNull |
| 139 |
public Builder setTextDirection(@NonNull TextDirectionHeuristic textDir) { |
| 140 |
mTextDir = textDir; |
| 141 |
return this; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
@NonNull |
| 155 |
public Builder setLineSpacing(float spacingAdd, @FloatRange(from = 0.0) float spacingMult) { |
| 156 |
mSpacingAdd = spacingAdd; |
| 157 |
mSpacingMult = spacingMult; |
| 158 |
return this; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
@NonNull |
| 171 |
public Builder setIncludePad(boolean includePad) { |
| 172 |
mIncludePad = includePad; |
| 173 |
return this; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
@NonNull |
| 190 |
public Builder setUseLineSpacingFromFallbacks(boolean useLineSpacingFromFallbacks) { |
| 191 |
mFallbackLineSpacing = useLineSpacingFromFallbacks; |
| 192 |
return this; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
@NonNull |
| 204 |
public Builder setEllipsizedWidth(@IntRange(from = 0) int ellipsizedWidth) { |
| 205 |
mEllipsizedWidth = ellipsizedWidth; |
| 206 |
return this; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public Builder setEllipsize(@Nullable TextUtils.TruncateAt ellipsize) { |
| 221 |
mEllipsize = ellipsize; |
| 222 |
return this; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
@NonNull |
| 234 |
public Builder setBreakStrategy(@BreakStrategy int breakStrategy) { |
| 235 |
mBreakStrategy = breakStrategy; |
| 236 |
return this; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
@NonNull |
| 250 |
public Builder setHyphenationFrequency(@HyphenationFrequency int hyphenationFrequency) { |
| 251 |
mHyphenationFrequency = hyphenationFrequency; |
| 252 |
return this; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
@NonNull |
| 264 |
public Builder setJustificationMode(@JustificationMode int justificationMode) { |
| 265 |
mJustificationMode = justificationMode; |
| 266 |
return this; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
@NonNull |
| 279 |
public DynamicLayout build() { |
| 280 |
final DynamicLayout result = new DynamicLayout(this); |
| 281 |
Builder.recycle(this); |
| 282 |
return result; |
| 283 |
} |
| 284 |
|
| 285 |
private CharSequence mBase; |
| 286 |
private CharSequence mDisplay; |
| 287 |
private TextPaint mPaint; |
| 288 |
private int mWidth; |
| 289 |
private Alignment mAlignment; |
| 290 |
private TextDirectionHeuristic mTextDir; |
| 291 |
private float mSpacingMult; |
| 292 |
private float mSpacingAdd; |
| 293 |
private boolean mIncludePad; |
| 294 |
private boolean mFallbackLineSpacing; |
| 295 |
private int mBreakStrategy; |
| 296 |
private int mHyphenationFrequency; |
| 297 |
private int mJustificationMode; |
| 298 |
private TextUtils.TruncateAt mEllipsize; |
| 299 |
private int mEllipsizedWidth; |
| 300 |
|
| 301 |
private final Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt(); |
| 302 |
|
| 303 |
private static final SynchronizedPool<Builder> sPool = new SynchronizedPool<>(3); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
@Deprecated |
| 310 |
public DynamicLayout(@NonNull CharSequence base, |
| 311 |
@NonNull TextPaint paint, |
| 312 |
@IntRange(from = 0) int width, @NonNull Alignment align, |
| 313 |
@FloatRange(from = 0.0) float spacingmult, float spacingadd, |
| 314 |
boolean includepad) { |
| 315 |
this(base, base, paint, width, align, spacingmult, spacingadd, |
| 316 |
includepad); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
@Deprecated |
| 323 |
public DynamicLayout(@NonNull CharSequence base, @NonNull CharSequence display, |
| 324 |
@NonNull TextPaint paint, |
| 325 |
@IntRange(from = 0) int width, @NonNull Alignment align, |
| 326 |
@FloatRange(from = 0.0) float spacingmult, float spacingadd, |
| 327 |
boolean includepad) { |
| 328 |
this(base, display, paint, width, align, spacingmult, spacingadd, |
| 329 |
includepad, null, 0); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
@Deprecated |
| 336 |
public DynamicLayout(@NonNull CharSequence base, @NonNull CharSequence display, |
| 337 |
@NonNull TextPaint paint, |
| 338 |
@IntRange(from = 0) int width, @NonNull Alignment align, |
| 339 |
@FloatRange(from = 0.0) float spacingmult, float spacingadd, |
| 340 |
boolean includepad, |
| 341 |
@Nullable TextUtils.TruncateAt ellipsize, |
| 342 |
@IntRange(from = 0) int ellipsizedWidth) { |
| 343 |
this(base, display, paint, width, align, TextDirectionHeuristics.FIRSTSTRONG_LTR, |
| 344 |
spacingmult, spacingadd, includepad, |
| 345 |
Layout.BREAK_STRATEGY_SIMPLE, Layout.HYPHENATION_FREQUENCY_NONE, |
| 346 |
Layout.JUSTIFICATION_MODE_NONE, ellipsize, ellipsizedWidth); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
@Deprecated |
| 358 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 359 |
public DynamicLayout(@NonNull CharSequence base, @NonNull CharSequence display, |
| 360 |
@NonNull TextPaint paint, |
| 361 |
@IntRange(from = 0) int width, |
| 362 |
@NonNull Alignment align, @NonNull TextDirectionHeuristic textDir, |
| 363 |
@FloatRange(from = 0.0) float spacingmult, float spacingadd, |
| 364 |
boolean includepad, @BreakStrategy int breakStrategy, |
| 365 |
@HyphenationFrequency int hyphenationFrequency, |
| 366 |
@JustificationMode int justificationMode, |
| 367 |
@Nullable TextUtils.TruncateAt ellipsize, |
| 368 |
@IntRange(from = 0) int ellipsizedWidth) { |
| 369 |
super(createEllipsizer(ellipsize, display), |
| 370 |
paint, width, align, textDir, spacingmult, spacingadd); |
| 371 |
|
| 372 |
final Builder b = Builder.obtain(base, paint, width) |
| 373 |
.setAlignment(align) |
| 374 |
.setTextDirection(textDir) |
| 375 |
.setLineSpacing(spacingadd, spacingmult) |
| 376 |
.setEllipsizedWidth(ellipsizedWidth) |
| 377 |
.setEllipsize(ellipsize); |
| 378 |
mDisplay = display; |
| 379 |
mIncludePad = includepad; |
| 380 |
mBreakStrategy = breakStrategy; |
| 381 |
mJustificationMode = justificationMode; |
| 382 |
mHyphenationFrequency = hyphenationFrequency; |
| 383 |
|
| 384 |
generate(b); |
| 385 |
|
| 386 |
Builder.recycle(b); |
| 387 |
} |
| 388 |
|
| 389 |
private DynamicLayout(@NonNull Builder b) { |
| 390 |
super(createEllipsizer(b.mEllipsize, b.mDisplay), |
| 391 |
b.mPaint, b.mWidth, b.mAlignment, b.mTextDir, b.mSpacingMult, b.mSpacingAdd); |
| 392 |
|
| 393 |
mDisplay = b.mDisplay; |
| 394 |
mIncludePad = b.mIncludePad; |
| 395 |
mBreakStrategy = b.mBreakStrategy; |
| 396 |
mJustificationMode = b.mJustificationMode; |
| 397 |
mHyphenationFrequency = b.mHyphenationFrequency; |
| 398 |
|
| 399 |
generate(b); |
| 400 |
} |
| 401 |
|
| 402 |
@NonNull |
| 403 |
private static CharSequence createEllipsizer(@Nullable TextUtils.TruncateAt ellipsize, |
| 404 |
@NonNull CharSequence display) { |
| 405 |
if (ellipsize == null) { |
| 406 |
return display; |
| 407 |
} else if (display instanceof Spanned) { |
| 408 |
return new SpannedEllipsizer(display); |
| 409 |
} else { |
| 410 |
return new Ellipsizer(display); |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
private void generate(@NonNull Builder b) { |
| 415 |
mBase = b.mBase; |
| 416 |
mFallbackLineSpacing = b.mFallbackLineSpacing; |
| 417 |
if (b.mEllipsize != null) { |
| 418 |
mInts = new PackedIntVector(COLUMNS_ELLIPSIZE); |
| 419 |
mEllipsizedWidth = b.mEllipsizedWidth; |
| 420 |
mEllipsizeAt = b.mEllipsize; |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
final Ellipsizer e = (Ellipsizer) getText(); |
| 437 |
e.mLayout = this; |
| 438 |
e.mWidth = b.mEllipsizedWidth; |
| 439 |
e.mMethod = b.mEllipsize; |
| 440 |
mEllipsize = true; |
| 441 |
} else { |
| 442 |
mInts = new PackedIntVector(COLUMNS_NORMAL); |
| 443 |
mEllipsizedWidth = b.mWidth; |
| 444 |
mEllipsizeAt = null; |
| 445 |
} |
| 446 |
|
| 447 |
mObjects = new PackedObjectVector<>(1); |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
int[] start; |
| 453 |
|
| 454 |
if (b.mEllipsize != null) { |
| 455 |
start = new int[COLUMNS_ELLIPSIZE]; |
| 456 |
start[ELLIPSIS_START] = ELLIPSIS_UNDEFINED; |
| 457 |
} else { |
| 458 |
start = new int[COLUMNS_NORMAL]; |
| 459 |
} |
| 460 |
|
| 461 |
final Directions[] dirs = new Directions[] { DIRS_ALL_LEFT_TO_RIGHT }; |
| 462 |
|
| 463 |
final Paint.FontMetricsInt fm = b.mFontMetricsInt; |
| 464 |
b.mPaint.getFontMetricsInt(fm); |
| 465 |
final int asc = fm.ascent; |
| 466 |
final int desc = fm.descent; |
| 467 |
|
| 468 |
start[DIR] = DIR_LEFT_TO_RIGHT << DIR_SHIFT; |
| 469 |
start[TOP] = 0; |
| 470 |
start[DESCENT] = desc; |
| 471 |
mInts.insertAt(0, start); |
| 472 |
|
| 473 |
start[TOP] = desc - asc; |
| 474 |
mInts.insertAt(1, start); |
| 475 |
|
| 476 |
mObjects.insertAt(0, dirs); |
| 477 |
|
| 478 |
|
| 479 |
reflow(mBase, 0, 0, mDisplay.length()); |
| 480 |
|
| 481 |
if (mBase instanceof Spannable) { |
| 482 |
if (mWatcher == null) |
| 483 |
mWatcher = new ChangeWatcher(this); |
| 484 |
|
| 485 |
|
| 486 |
final Spannable sp = (Spannable) mBase; |
| 487 |
final int baseLength = mBase.length(); |
| 488 |
final ChangeWatcher[] spans = sp.getSpans(0, baseLength, ChangeWatcher.class); |
| 489 |
for (int i = 0; i < spans.length; i++) { |
| 490 |
sp.removeSpan(spans[i]); |
| 491 |
} |
| 492 |
|
| 493 |
sp.setSpan(mWatcher, 0, baseLength, |
| 494 |
Spannable.SPAN_INCLUSIVE_INCLUSIVE | |
| 495 |
(PRIORITY << Spannable.SPAN_PRIORITY_SHIFT)); |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 501 |
public void reflow(CharSequence s, int where, int before, int after) { |
| 502 |
if (s != mBase) |
| 503 |
return; |
| 504 |
|
| 505 |
CharSequence text = mDisplay; |
| 506 |
int len = text.length(); |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
int find = TextUtils.lastIndexOf(text, '\n', where - 1); |
| 511 |
if (find < 0) |
| 512 |
find = 0; |
| 513 |
else |
| 514 |
find = find + 1; |
| 515 |
|
| 516 |
{ |
| 517 |
int diff = where - find; |
| 518 |
before += diff; |
| 519 |
after += diff; |
| 520 |
where -= diff; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
int look = TextUtils.indexOf(text, '\n', where + after); |
| 526 |
if (look < 0) |
| 527 |
look = len; |
| 528 |
else |
| 529 |
look++; |
| 530 |
|
| 531 |
int change = look - (where + after); |
| 532 |
before += change; |
| 533 |
after += change; |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
if (text instanceof Spanned) { |
| 538 |
Spanned sp = (Spanned) text; |
| 539 |
boolean again; |
| 540 |
|
| 541 |
do { |
| 542 |
again = false; |
| 543 |
|
| 544 |
Object[] force = sp.getSpans(where, where + after, |
| 545 |
WrapTogetherSpan.class); |
| 546 |
|
| 547 |
for (int i = 0; i < force.length; i++) { |
| 548 |
int st = sp.getSpanStart(force[i]); |
| 549 |
int en = sp.getSpanEnd(force[i]); |
| 550 |
|
| 551 |
if (st < where) { |
| 552 |
again = true; |
| 553 |
|
| 554 |
int diff = where - st; |
| 555 |
before += diff; |
| 556 |
after += diff; |
| 557 |
where -= diff; |
| 558 |
} |
| 559 |
|
| 560 |
if (en > where + after) { |
| 561 |
again = true; |
| 562 |
|
| 563 |
int diff = en - (where + after); |
| 564 |
before += diff; |
| 565 |
after += diff; |
| 566 |
} |
| 567 |
} |
| 568 |
} while (again); |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
int startline = getLineForOffset(where); |
| 574 |
int startv = getLineTop(startline); |
| 575 |
|
| 576 |
int endline = getLineForOffset(where + before); |
| 577 |
if (where + after == len) |
| 578 |
endline = getLineCount(); |
| 579 |
int endv = getLineTop(endline); |
| 580 |
boolean islast = (endline == getLineCount()); |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
StaticLayout reflowed; |
| 585 |
StaticLayout.Builder b; |
| 586 |
|
| 587 |
synchronized (sLock) { |
| 588 |
reflowed = sStaticLayout; |
| 589 |
b = sBuilder; |
| 590 |
sStaticLayout = null; |
| 591 |
sBuilder = null; |
| 592 |
} |
| 593 |
|
| 594 |
if (reflowed == null) { |
| 595 |
reflowed = new StaticLayout(null); |
| 596 |
b = StaticLayout.Builder.obtain(text, where, where + after, getPaint(), getWidth()); |
| 597 |
} |
| 598 |
|
| 599 |
b.setText(text, where, where + after) |
| 600 |
.setPaint(getPaint()) |
| 601 |
.setWidth(getWidth()) |
| 602 |
.setTextDirection(getTextDirectionHeuristic()) |
| 603 |
.setLineSpacing(getSpacingAdd(), getSpacingMultiplier()) |
| 604 |
.setUseLineSpacingFromFallbacks(mFallbackLineSpacing) |
| 605 |
.setEllipsizedWidth(mEllipsizedWidth) |
| 606 |
.setEllipsize(mEllipsizeAt) |
| 607 |
.setBreakStrategy(mBreakStrategy) |
| 608 |
.setHyphenationFrequency(mHyphenationFrequency) |
| 609 |
.setJustificationMode(mJustificationMode) |
| 610 |
.setAddLastLineLineSpacing(!islast); |
| 611 |
|
| 612 |
reflowed.generate(b, false , true ); |
| 613 |
int n = reflowed.getLineCount(); |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
if (where + after != len && reflowed.getLineStart(n - 1) == where + after) |
| 619 |
n--; |
| 620 |
|
| 621 |
|
| 622 |
mInts.deleteAt(startline, endline - startline); |
| 623 |
mObjects.deleteAt(startline, endline - startline); |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
int ht = reflowed.getLineTop(n); |
| 628 |
int toppad = 0, botpad = 0; |
| 629 |
|
| 630 |
if (mIncludePad && startline == 0) { |
| 631 |
toppad = reflowed.getTopPadding(); |
| 632 |
mTopPadding = toppad; |
| 633 |
ht -= toppad; |
| 634 |
} |
| 635 |
if (mIncludePad && islast) { |
| 636 |
botpad = reflowed.getBottomPadding(); |
| 637 |
mBottomPadding = botpad; |
| 638 |
ht += botpad; |
| 639 |
} |
| 640 |
|
| 641 |
mInts.adjustValuesBelow(startline, START, after - before); |
| 642 |
mInts.adjustValuesBelow(startline, TOP, startv - endv + ht); |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
int[] ints; |
| 647 |
|
| 648 |
if (mEllipsize) { |
| 649 |
ints = new int[COLUMNS_ELLIPSIZE]; |
| 650 |
ints[ELLIPSIS_START] = ELLIPSIS_UNDEFINED; |
| 651 |
} else { |
| 652 |
ints = new int[COLUMNS_NORMAL]; |
| 653 |
} |
| 654 |
|
| 655 |
Directions[] objects = new Directions[1]; |
| 656 |
|
| 657 |
for (int i = 0; i < n; i++) { |
| 658 |
final int start = reflowed.getLineStart(i); |
| 659 |
ints[START] = start; |
| 660 |
ints[DIR] |= reflowed.getParagraphDirection(i) << DIR_SHIFT; |
| 661 |
ints[TAB] |= reflowed.getLineContainsTab(i) ? TAB_MASK : 0; |
| 662 |
|
| 663 |
int top = reflowed.getLineTop(i) + startv; |
| 664 |
if (i > 0) |
| 665 |
top -= toppad; |
| 666 |
ints[TOP] = top; |
| 667 |
|
| 668 |
int desc = reflowed.getLineDescent(i); |
| 669 |
if (i == n - 1) |
| 670 |
desc += botpad; |
| 671 |
|
| 672 |
ints[DESCENT] = desc; |
| 673 |
ints[EXTRA] = reflowed.getLineExtra(i); |
| 674 |
objects[0] = reflowed.getLineDirections(i); |
| 675 |
|
| 676 |
final int end = (i == n - 1) ? where + after : reflowed.getLineStart(i + 1); |
| 677 |
ints[HYPHEN] = StaticLayout.packHyphenEdit( |
| 678 |
reflowed.getStartHyphenEdit(i), reflowed.getEndHyphenEdit(i)); |
| 679 |
ints[MAY_PROTRUDE_FROM_TOP_OR_BOTTOM] |= |
| 680 |
contentMayProtrudeFromLineTopOrBottom(text, start, end) ? |
| 681 |
MAY_PROTRUDE_FROM_TOP_OR_BOTTOM_MASK : 0; |
| 682 |
|
| 683 |
if (mEllipsize) { |
| 684 |
ints[ELLIPSIS_START] = reflowed.getEllipsisStart(i); |
| 685 |
ints[ELLIPSIS_COUNT] = reflowed.getEllipsisCount(i); |
| 686 |
} |
| 687 |
|
| 688 |
mInts.insertAt(startline + i, ints); |
| 689 |
mObjects.insertAt(startline + i, objects); |
| 690 |
} |
| 691 |
|
| 692 |
updateBlocks(startline, endline - 1, n); |
| 693 |
|
| 694 |
b.finish(); |
| 695 |
synchronized (sLock) { |
| 696 |
sStaticLayout = reflowed; |
| 697 |
sBuilder = b; |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
private boolean contentMayProtrudeFromLineTopOrBottom(CharSequence text, int start, int end) { |
| 702 |
if (text instanceof Spanned) { |
| 703 |
final Spanned spanned = (Spanned) text; |
| 704 |
if (spanned.getSpans(start, end, ReplacementSpan.class).length > 0) { |
| 705 |
return true; |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
final Paint paint = getPaint(); |
| 711 |
if (text instanceof PrecomputedText) { |
| 712 |
PrecomputedText precomputed = (PrecomputedText) text; |
| 713 |
precomputed.getBounds(start, end, mTempRect); |
| 714 |
} else { |
| 715 |
paint.getTextBounds(text, start, end, mTempRect); |
| 716 |
} |
| 717 |
final Paint.FontMetricsInt fm = paint.getFontMetricsInt(); |
| 718 |
return mTempRect.top < fm.top || mTempRect.bottom > fm.bottom; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
private void createBlocks() { |
| 726 |
int offset = BLOCK_MINIMUM_CHARACTER_LENGTH; |
| 727 |
mNumberOfBlocks = 0; |
| 728 |
final CharSequence text = mDisplay; |
| 729 |
|
| 730 |
while (true) { |
| 731 |
offset = TextUtils.indexOf(text, '\n', offset); |
| 732 |
if (offset < 0) { |
| 733 |
addBlockAtOffset(text.length()); |
| 734 |
break; |
| 735 |
} else { |
| 736 |
addBlockAtOffset(offset); |
| 737 |
offset += BLOCK_MINIMUM_CHARACTER_LENGTH; |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
mBlockIndices = new int[mBlockEndLines.length]; |
| 743 |
for (int i = 0; i < mBlockEndLines.length; i++) { |
| 744 |
mBlockIndices[i] = INVALID_BLOCK_INDEX; |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
public ArraySet<Integer> getBlocksAlwaysNeedToBeRedrawn() { |
| 752 |
return mBlocksAlwaysNeedToBeRedrawn; |
| 753 |
} |
| 754 |
|
| 755 |
private void updateAlwaysNeedsToBeRedrawn(int blockIndex) { |
| 756 |
int startLine = blockIndex == 0 ? 0 : (mBlockEndLines[blockIndex - 1] + 1); |
| 757 |
int endLine = mBlockEndLines[blockIndex]; |
| 758 |
for (int i = startLine; i <= endLine; i++) { |
| 759 |
if (getContentMayProtrudeFromTopOrBottom(i)) { |
| 760 |
if (mBlocksAlwaysNeedToBeRedrawn == null) { |
| 761 |
mBlocksAlwaysNeedToBeRedrawn = new ArraySet<>(); |
| 762 |
} |
| 763 |
mBlocksAlwaysNeedToBeRedrawn.add(blockIndex); |
| 764 |
return; |
| 765 |
} |
| 766 |
} |
| 767 |
if (mBlocksAlwaysNeedToBeRedrawn != null) { |
| 768 |
mBlocksAlwaysNeedToBeRedrawn.remove(blockIndex); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
private void addBlockAtOffset(int offset) { |
| 778 |
final int line = getLineForOffset(offset); |
| 779 |
if (mBlockEndLines == null) { |
| 780 |
|
| 781 |
mBlockEndLines = ArrayUtils.newUnpaddedIntArray(1); |
| 782 |
mBlockEndLines[mNumberOfBlocks] = line; |
| 783 |
updateAlwaysNeedsToBeRedrawn(mNumberOfBlocks); |
| 784 |
mNumberOfBlocks++; |
| 785 |
return; |
| 786 |
} |
| 787 |
|
| 788 |
final int previousBlockEndLine = mBlockEndLines[mNumberOfBlocks - 1]; |
| 789 |
if (line > previousBlockEndLine) { |
| 790 |
mBlockEndLines = GrowingArrayUtils.append(mBlockEndLines, mNumberOfBlocks, line); |
| 791 |
updateAlwaysNeedsToBeRedrawn(mNumberOfBlocks); |
| 792 |
mNumberOfBlocks++; |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 814 |
public void updateBlocks(int startLine, int endLine, int newLineCount) { |
| 815 |
if (mBlockEndLines == null) { |
| 816 |
createBlocks(); |
| 817 |
return; |
| 818 |
} |
| 819 |
|
| 820 |
int firstBlock = -1; |
| 821 |
int lastBlock = -1; |
| 822 |
for (int i = 0; i < mNumberOfBlocks; i++) { |
| 823 |
if (mBlockEndLines[i] >= startLine) { |
| 824 |
firstBlock = i; |
| 825 |
break; |
| 826 |
} |
| 827 |
} |
| 828 |
for (int i = firstBlock; i < mNumberOfBlocks; i++) { |
| 829 |
if (mBlockEndLines[i] >= endLine) { |
| 830 |
lastBlock = i; |
| 831 |
break; |
| 832 |
} |
| 833 |
} |
| 834 |
final int lastBlockEndLine = mBlockEndLines[lastBlock]; |
| 835 |
|
| 836 |
final boolean createBlockBefore = startLine > (firstBlock == 0 ? 0 : |
| 837 |
mBlockEndLines[firstBlock - 1] + 1); |
| 838 |
final boolean createBlock = newLineCount > 0; |
| 839 |
final boolean createBlockAfter = endLine < mBlockEndLines[lastBlock]; |
| 840 |
|
| 841 |
int numAddedBlocks = 0; |
| 842 |
if (createBlockBefore) numAddedBlocks++; |
| 843 |
if (createBlock) numAddedBlocks++; |
| 844 |
if (createBlockAfter) numAddedBlocks++; |
| 845 |
|
| 846 |
final int numRemovedBlocks = lastBlock - firstBlock + 1; |
| 847 |
final int newNumberOfBlocks = mNumberOfBlocks + numAddedBlocks - numRemovedBlocks; |
| 848 |
|
| 849 |
if (newNumberOfBlocks == 0) { |
| 850 |
|
| 851 |
mBlockEndLines[0] = 0; |
| 852 |
mBlockIndices[0] = INVALID_BLOCK_INDEX; |
| 853 |
mNumberOfBlocks = 1; |
| 854 |
return; |
| 855 |
} |
| 856 |
|
| 857 |
if (newNumberOfBlocks > mBlockEndLines.length) { |
| 858 |
int[] blockEndLines = ArrayUtils.newUnpaddedIntArray( |
| 859 |
Math.max(mBlockEndLines.length * 2, newNumberOfBlocks)); |
| 860 |
int[] blockIndices = new int[blockEndLines.length]; |
| 861 |
System.arraycopy(mBlockEndLines, 0, blockEndLines, 0, firstBlock); |
| 862 |
System.arraycopy(mBlockIndices, 0, blockIndices, 0, firstBlock); |
| 863 |
System.arraycopy(mBlockEndLines, lastBlock + 1, |
| 864 |
blockEndLines, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); |
| 865 |
System.arraycopy(mBlockIndices, lastBlock + 1, |
| 866 |
blockIndices, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); |
| 867 |
mBlockEndLines = blockEndLines; |
| 868 |
mBlockIndices = blockIndices; |
| 869 |
} else if (numAddedBlocks + numRemovedBlocks != 0) { |
| 870 |
System.arraycopy(mBlockEndLines, lastBlock + 1, |
| 871 |
mBlockEndLines, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); |
| 872 |
System.arraycopy(mBlockIndices, lastBlock + 1, |
| 873 |
mBlockIndices, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); |
| 874 |
} |
| 875 |
|
| 876 |
if (numAddedBlocks + numRemovedBlocks != 0 && mBlocksAlwaysNeedToBeRedrawn != null) { |
| 877 |
final ArraySet<Integer> set = new ArraySet<>(); |
| 878 |
final int changedBlockCount = numAddedBlocks - numRemovedBlocks; |
| 879 |
for (int i = 0; i < mBlocksAlwaysNeedToBeRedrawn.size(); i++) { |
| 880 |
Integer block = mBlocksAlwaysNeedToBeRedrawn.valueAt(i); |
| 881 |
if (block < firstBlock) { |
| 882 |
|
| 883 |
set.add(block); |
| 884 |
} |
| 885 |
if (block > lastBlock) { |
| 886 |
|
| 887 |
block += changedBlockCount; |
| 888 |
set.add(block); |
| 889 |
} |
| 890 |
} |
| 891 |
mBlocksAlwaysNeedToBeRedrawn = set; |
| 892 |
} |
| 893 |
|
| 894 |
mNumberOfBlocks = newNumberOfBlocks; |
| 895 |
int newFirstChangedBlock; |
| 896 |
final int deltaLines = newLineCount - (endLine - startLine + 1); |
| 897 |
if (deltaLines != 0) { |
| 898 |
|
| 899 |
|
| 900 |
newFirstChangedBlock = firstBlock + numAddedBlocks; |
| 901 |
for (int i = newFirstChangedBlock; i < mNumberOfBlocks; i++) { |
| 902 |
mBlockEndLines[i] += deltaLines; |
| 903 |
} |
| 904 |
} else { |
| 905 |
newFirstChangedBlock = mNumberOfBlocks; |
| 906 |
} |
| 907 |
mIndexFirstChangedBlock = Math.min(mIndexFirstChangedBlock, newFirstChangedBlock); |
| 908 |
|
| 909 |
int blockIndex = firstBlock; |
| 910 |
if (createBlockBefore) { |
| 911 |
mBlockEndLines[blockIndex] = startLine - 1; |
| 912 |
updateAlwaysNeedsToBeRedrawn(blockIndex); |
| 913 |
mBlockIndices[blockIndex] = INVALID_BLOCK_INDEX; |
| 914 |
blockIndex++; |
| 915 |
} |
| 916 |
|
| 917 |
if (createBlock) { |
| 918 |
mBlockEndLines[blockIndex] = startLine + newLineCount - 1; |
| 919 |
updateAlwaysNeedsToBeRedrawn(blockIndex); |
| 920 |
mBlockIndices[blockIndex] = INVALID_BLOCK_INDEX; |
| 921 |
blockIndex++; |
| 922 |
} |
| 923 |
|
| 924 |
if (createBlockAfter) { |
| 925 |
mBlockEndLines[blockIndex] = lastBlockEndLine + deltaLines; |
| 926 |
updateAlwaysNeedsToBeRedrawn(blockIndex); |
| 927 |
mBlockIndices[blockIndex] = INVALID_BLOCK_INDEX; |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 936 |
public void setBlocksDataForTest(int[] blockEndLines, int[] blockIndices, int numberOfBlocks, |
| 937 |
int totalLines) { |
| 938 |
mBlockEndLines = new int[blockEndLines.length]; |
| 939 |
mBlockIndices = new int[blockIndices.length]; |
| 940 |
System.arraycopy(blockEndLines, 0, mBlockEndLines, 0, blockEndLines.length); |
| 941 |
System.arraycopy(blockIndices, 0, mBlockIndices, 0, blockIndices.length); |
| 942 |
mNumberOfBlocks = numberOfBlocks; |
| 943 |
while (mInts.size() < totalLines) { |
| 944 |
mInts.insertAt(mInts.size(), new int[COLUMNS_NORMAL]); |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
@UnsupportedAppUsage |
| 952 |
public int[] getBlockEndLines() { |
| 953 |
return mBlockEndLines; |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
@UnsupportedAppUsage |
| 960 |
public int[] getBlockIndices() { |
| 961 |
return mBlockIndices; |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
public int getBlockIndex(int index) { |
| 968 |
return mBlockIndices[index]; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
public void setBlockIndex(int index, int blockIndex) { |
| 976 |
mBlockIndices[index] = blockIndex; |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
@UnsupportedAppUsage |
| 983 |
public int getNumberOfBlocks() { |
| 984 |
return mNumberOfBlocks; |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 991 |
public int getIndexFirstChangedBlock() { |
| 992 |
return mIndexFirstChangedBlock; |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 999 |
public void setIndexFirstChangedBlock(int i) { |
| 1000 |
mIndexFirstChangedBlock = i; |
| 1001 |
} |
| 1002 |
|
| 1003 |
@Override |
| 1004 |
public int getLineCount() { |
| 1005 |
return mInts.size() - 1; |
| 1006 |
} |
| 1007 |
|
| 1008 |
@Override |
| 1009 |
public int getLineTop(int line) { |
| 1010 |
return mInts.getValue(line, TOP); |
| 1011 |
} |
| 1012 |
|
| 1013 |
@Override |
| 1014 |
public int getLineDescent(int line) { |
| 1015 |
return mInts.getValue(line, DESCENT); |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
@Override |
| 1022 |
public int getLineExtra(int line) { |
| 1023 |
return mInts.getValue(line, EXTRA); |
| 1024 |
} |
| 1025 |
|
| 1026 |
@Override |
| 1027 |
public int getLineStart(int line) { |
| 1028 |
return mInts.getValue(line, START) & START_MASK; |
| 1029 |
} |
| 1030 |
|
| 1031 |
@Override |
| 1032 |
public boolean getLineContainsTab(int line) { |
| 1033 |
return (mInts.getValue(line, TAB) & TAB_MASK) != 0; |
| 1034 |
} |
| 1035 |
|
| 1036 |
@Override |
| 1037 |
public int getParagraphDirection(int line) { |
| 1038 |
return mInts.getValue(line, DIR) >> DIR_SHIFT; |
| 1039 |
} |
| 1040 |
|
| 1041 |
@Override |
| 1042 |
public final Directions getLineDirections(int line) { |
| 1043 |
return mObjects.getValue(line, 0); |
| 1044 |
} |
| 1045 |
|
| 1046 |
@Override |
| 1047 |
public int getTopPadding() { |
| 1048 |
return mTopPadding; |
| 1049 |
} |
| 1050 |
|
| 1051 |
@Override |
| 1052 |
public int getBottomPadding() { |
| 1053 |
return mBottomPadding; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
@Override |
| 1060 |
public @Paint.StartHyphenEdit int getStartHyphenEdit(int line) { |
| 1061 |
return StaticLayout.unpackStartHyphenEdit(mInts.getValue(line, HYPHEN) & HYPHEN_MASK); |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
@Override |
| 1068 |
public @Paint.EndHyphenEdit int getEndHyphenEdit(int line) { |
| 1069 |
return StaticLayout.unpackEndHyphenEdit(mInts.getValue(line, HYPHEN) & HYPHEN_MASK); |
| 1070 |
} |
| 1071 |
|
| 1072 |
private boolean getContentMayProtrudeFromTopOrBottom(int line) { |
| 1073 |
return (mInts.getValue(line, MAY_PROTRUDE_FROM_TOP_OR_BOTTOM) |
| 1074 |
& MAY_PROTRUDE_FROM_TOP_OR_BOTTOM_MASK) != 0; |
| 1075 |
} |
| 1076 |
|
| 1077 |
@Override |
| 1078 |
public int getEllipsizedWidth() { |
| 1079 |
return mEllipsizedWidth; |
| 1080 |
} |
| 1081 |
|
| 1082 |
private static class ChangeWatcher implements TextWatcher, SpanWatcher { |
| 1083 |
public ChangeWatcher(DynamicLayout layout) { |
| 1084 |
mLayout = new WeakReference<>(layout); |
| 1085 |
} |
| 1086 |
|
| 1087 |
private void reflow(CharSequence s, int where, int before, int after) { |
| 1088 |
DynamicLayout ml = mLayout.get(); |
| 1089 |
|
| 1090 |
if (ml != null) { |
| 1091 |
ml.reflow(s, where, before, after); |
| 1092 |
} else if (s instanceof Spannable) { |
| 1093 |
((Spannable) s).removeSpan(this); |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
public void beforeTextChanged(CharSequence s, int where, int before, int after) { |
| 1098 |
|
| 1099 |
} |
| 1100 |
|
| 1101 |
public void onTextChanged(CharSequence s, int where, int before, int after) { |
| 1102 |
reflow(s, where, before, after); |
| 1103 |
} |
| 1104 |
|
| 1105 |
public void afterTextChanged(Editable s) { |
| 1106 |
|
| 1107 |
} |
| 1108 |
|
| 1109 |
public void onSpanAdded(Spannable s, Object o, int start, int end) { |
| 1110 |
if (o instanceof UpdateLayout) |
| 1111 |
reflow(s, start, end - start, end - start); |
| 1112 |
} |
| 1113 |
|
| 1114 |
public void onSpanRemoved(Spannable s, Object o, int start, int end) { |
| 1115 |
if (o instanceof UpdateLayout) |
| 1116 |
reflow(s, start, end - start, end - start); |
| 1117 |
} |
| 1118 |
|
| 1119 |
public void onSpanChanged(Spannable s, Object o, int start, int end, int nstart, int nend) { |
| 1120 |
if (o instanceof UpdateLayout) { |
| 1121 |
if (start > end) { |
| 1122 |
|
| 1123 |
|
| 1124 |
start = 0; |
| 1125 |
} |
| 1126 |
reflow(s, start, end - start, end - start); |
| 1127 |
reflow(s, nstart, nend - nstart, nend - nstart); |
| 1128 |
} |
| 1129 |
} |
| 1130 |
|
| 1131 |
private WeakReference<DynamicLayout> mLayout; |
| 1132 |
} |
| 1133 |
|
| 1134 |
@Override |
| 1135 |
public int getEllipsisStart(int line) { |
| 1136 |
if (mEllipsizeAt == null) { |
| 1137 |
return 0; |
| 1138 |
} |
| 1139 |
|
| 1140 |
return mInts.getValue(line, ELLIPSIS_START); |
| 1141 |
} |
| 1142 |
|
| 1143 |
@Override |
| 1144 |
public int getEllipsisCount(int line) { |
| 1145 |
if (mEllipsizeAt == null) { |
| 1146 |
return 0; |
| 1147 |
} |
| 1148 |
|
| 1149 |
return mInts.getValue(line, ELLIPSIS_COUNT); |
| 1150 |
} |
| 1151 |
|
| 1152 |
private CharSequence mBase; |
| 1153 |
private CharSequence mDisplay; |
| 1154 |
private ChangeWatcher mWatcher; |
| 1155 |
private boolean mIncludePad; |
| 1156 |
private boolean mFallbackLineSpacing; |
| 1157 |
private boolean mEllipsize; |
| 1158 |
private int mEllipsizedWidth; |
| 1159 |
private TextUtils.TruncateAt mEllipsizeAt; |
| 1160 |
private int mBreakStrategy; |
| 1161 |
private int mHyphenationFrequency; |
| 1162 |
private int mJustificationMode; |
| 1163 |
|
| 1164 |
private PackedIntVector mInts; |
| 1165 |
private PackedObjectVector<Directions> mObjects; |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
public static final int INVALID_BLOCK_INDEX = -1; |
| 1173 |
|
| 1174 |
private int[] mBlockEndLines; |
| 1175 |
|
| 1176 |
|
| 1177 |
private int[] mBlockIndices; |
| 1178 |
|
| 1179 |
private ArraySet<Integer> mBlocksAlwaysNeedToBeRedrawn; |
| 1180 |
|
| 1181 |
private int mNumberOfBlocks; |
| 1182 |
|
| 1183 |
private int mIndexFirstChangedBlock; |
| 1184 |
|
| 1185 |
private int mTopPadding, mBottomPadding; |
| 1186 |
|
| 1187 |
private Rect mTempRect = new Rect(); |
| 1188 |
|
| 1189 |
@UnsupportedAppUsage |
| 1190 |
private static StaticLayout sStaticLayout = null; |
| 1191 |
private static StaticLayout.Builder sBuilder = null; |
| 1192 |
|
| 1193 |
private static final Object[] sLock = new Object[0]; |
| 1194 |
|
| 1195 |
|
| 1196 |
private static final int START = 0; |
| 1197 |
private static final int DIR = START; |
| 1198 |
private static final int TAB = START; |
| 1199 |
private static final int TOP = 1; |
| 1200 |
private static final int DESCENT = 2; |
| 1201 |
private static final int EXTRA = 3; |
| 1202 |
|
| 1203 |
private static final int HYPHEN = 4; |
| 1204 |
private static final int MAY_PROTRUDE_FROM_TOP_OR_BOTTOM = HYPHEN; |
| 1205 |
private static final int COLUMNS_NORMAL = 5; |
| 1206 |
|
| 1207 |
private static final int ELLIPSIS_START = 5; |
| 1208 |
private static final int ELLIPSIS_COUNT = 6; |
| 1209 |
private static final int COLUMNS_ELLIPSIZE = 7; |
| 1210 |
|
| 1211 |
private static final int START_MASK = 0x1FFFFFFF; |
| 1212 |
private static final int DIR_SHIFT = 30; |
| 1213 |
private static final int TAB_MASK = 0x20000000; |
| 1214 |
private static final int HYPHEN_MASK = 0xFF; |
| 1215 |
private static final int MAY_PROTRUDE_FROM_TOP_OR_BOTTOM_MASK = 0x100; |
| 1216 |
|
| 1217 |
private static final int ELLIPSIS_UNDEFINED = 0x80000000; |
| 1218 |
} |