DynamicLayout.java revision 531c30c62b14881aab31a5133920a971b1fbb50e
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.text; 18 19import android.graphics.Paint; 20import android.text.style.UpdateLayout; 21import android.text.style.WrapTogetherSpan; 22 23import com.android.internal.util.ArrayUtils; 24import com.android.internal.util.GrowingArrayUtils; 25 26import java.lang.ref.WeakReference; 27 28/** 29 * DynamicLayout is a text layout that updates itself as the text is edited. 30 * <p>This is used by widgets to control text layout. You should not need 31 * to use this class directly unless you are implementing your own widget 32 * or custom display object, or need to call 33 * {@link android.graphics.Canvas#drawText(java.lang.CharSequence, int, int, float, float, android.graphics.Paint) 34 * Canvas.drawText()} directly.</p> 35 */ 36public class DynamicLayout extends Layout 37{ 38 private static final int PRIORITY = 128; 39 private static final int BLOCK_MINIMUM_CHARACTER_LENGTH = 400; 40 41 /** 42 * Make a layout for the specified text that will be updated as 43 * the text is changed. 44 */ 45 public DynamicLayout(CharSequence base, 46 TextPaint paint, 47 int width, Alignment align, 48 float spacingmult, float spacingadd, 49 boolean includepad) { 50 this(base, base, paint, width, align, spacingmult, spacingadd, 51 includepad); 52 } 53 54 /** 55 * Make a layout for the transformed text (password transformation 56 * being the primary example of a transformation) 57 * that will be updated as the base text is changed. 58 */ 59 public DynamicLayout(CharSequence base, CharSequence display, 60 TextPaint paint, 61 int width, Alignment align, 62 float spacingmult, float spacingadd, 63 boolean includepad) { 64 this(base, display, paint, width, align, spacingmult, spacingadd, 65 includepad, null, 0); 66 } 67 68 /** 69 * Make a layout for the transformed text (password transformation 70 * being the primary example of a transformation) 71 * that will be updated as the base text is changed. 72 * If ellipsize is non-null, the Layout will ellipsize the text 73 * down to ellipsizedWidth. 74 */ 75 public DynamicLayout(CharSequence base, CharSequence display, 76 TextPaint paint, 77 int width, Alignment align, 78 float spacingmult, float spacingadd, 79 boolean includepad, 80 TextUtils.TruncateAt ellipsize, int ellipsizedWidth) { 81 this(base, display, paint, width, align, TextDirectionHeuristics.FIRSTSTRONG_LTR, 82 spacingmult, spacingadd, includepad, StaticLayout.BREAK_STRATEGY_SIMPLE, 83 ellipsize, ellipsizedWidth); 84 } 85 86 /** 87 * Make a layout for the transformed text (password transformation 88 * being the primary example of a transformation) 89 * that will be updated as the base text is changed. 90 * If ellipsize is non-null, the Layout will ellipsize the text 91 * down to ellipsizedWidth. 92 * * 93 * *@hide 94 */ 95 public DynamicLayout(CharSequence base, CharSequence display, 96 TextPaint paint, 97 int width, Alignment align, TextDirectionHeuristic textDir, 98 float spacingmult, float spacingadd, 99 boolean includepad, int breakStrategy, 100 TextUtils.TruncateAt ellipsize, int ellipsizedWidth) { 101 super((ellipsize == null) 102 ? display 103 : (display instanceof Spanned) 104 ? new SpannedEllipsizer(display) 105 : new Ellipsizer(display), 106 paint, width, align, textDir, spacingmult, spacingadd); 107 108 mBase = base; 109 mDisplay = display; 110 111 if (ellipsize != null) { 112 mInts = new PackedIntVector(COLUMNS_ELLIPSIZE); 113 mEllipsizedWidth = ellipsizedWidth; 114 mEllipsizeAt = ellipsize; 115 } else { 116 mInts = new PackedIntVector(COLUMNS_NORMAL); 117 mEllipsizedWidth = width; 118 mEllipsizeAt = null; 119 } 120 121 mObjects = new PackedObjectVector<Directions>(1); 122 123 mIncludePad = includepad; 124 mBreakStrategy = breakStrategy; 125 126 /* 127 * This is annoying, but we can't refer to the layout until 128 * superclass construction is finished, and the superclass 129 * constructor wants the reference to the display text. 130 * 131 * This will break if the superclass constructor ever actually 132 * cares about the content instead of just holding the reference. 133 */ 134 if (ellipsize != null) { 135 Ellipsizer e = (Ellipsizer) getText(); 136 137 e.mLayout = this; 138 e.mWidth = ellipsizedWidth; 139 e.mMethod = ellipsize; 140 mEllipsize = true; 141 } 142 143 // Initial state is a single line with 0 characters (0 to 0), 144 // with top at 0 and bottom at whatever is natural, and 145 // undefined ellipsis. 146 147 int[] start; 148 149 if (ellipsize != null) { 150 start = new int[COLUMNS_ELLIPSIZE]; 151 start[ELLIPSIS_START] = ELLIPSIS_UNDEFINED; 152 } else { 153 start = new int[COLUMNS_NORMAL]; 154 } 155 156 Directions[] dirs = new Directions[] { DIRS_ALL_LEFT_TO_RIGHT }; 157 158 Paint.FontMetricsInt fm = paint.getFontMetricsInt(); 159 int asc = fm.ascent; 160 int desc = fm.descent; 161 162 start[DIR] = DIR_LEFT_TO_RIGHT << DIR_SHIFT; 163 start[TOP] = 0; 164 start[DESCENT] = desc; 165 mInts.insertAt(0, start); 166 167 start[TOP] = desc - asc; 168 mInts.insertAt(1, start); 169 170 mObjects.insertAt(0, dirs); 171 172 // Update from 0 characters to whatever the real text is 173 reflow(base, 0, 0, base.length()); 174 175 if (base instanceof Spannable) { 176 if (mWatcher == null) 177 mWatcher = new ChangeWatcher(this); 178 179 // Strip out any watchers for other DynamicLayouts. 180 Spannable sp = (Spannable) base; 181 ChangeWatcher[] spans = sp.getSpans(0, sp.length(), ChangeWatcher.class); 182 for (int i = 0; i < spans.length; i++) 183 sp.removeSpan(spans[i]); 184 185 sp.setSpan(mWatcher, 0, base.length(), 186 Spannable.SPAN_INCLUSIVE_INCLUSIVE | 187 (PRIORITY << Spannable.SPAN_PRIORITY_SHIFT)); 188 } 189 } 190 191 private void reflow(CharSequence s, int where, int before, int after) { 192 if (s != mBase) 193 return; 194 195 CharSequence text = mDisplay; 196 int len = text.length(); 197 198 // seek back to the start of the paragraph 199 200 int find = TextUtils.lastIndexOf(text, '\n', where - 1); 201 if (find < 0) 202 find = 0; 203 else 204 find = find + 1; 205 206 { 207 int diff = where - find; 208 before += diff; 209 after += diff; 210 where -= diff; 211 } 212 213 // seek forward to the end of the paragraph 214 215 int look = TextUtils.indexOf(text, '\n', where + after); 216 if (look < 0) 217 look = len; 218 else 219 look++; // we want the index after the \n 220 221 int change = look - (where + after); 222 before += change; 223 after += change; 224 225 // seek further out to cover anything that is forced to wrap together 226 227 if (text instanceof Spanned) { 228 Spanned sp = (Spanned) text; 229 boolean again; 230 231 do { 232 again = false; 233 234 Object[] force = sp.getSpans(where, where + after, 235 WrapTogetherSpan.class); 236 237 for (int i = 0; i < force.length; i++) { 238 int st = sp.getSpanStart(force[i]); 239 int en = sp.getSpanEnd(force[i]); 240 241 if (st < where) { 242 again = true; 243 244 int diff = where - st; 245 before += diff; 246 after += diff; 247 where -= diff; 248 } 249 250 if (en > where + after) { 251 again = true; 252 253 int diff = en - (where + after); 254 before += diff; 255 after += diff; 256 } 257 } 258 } while (again); 259 } 260 261 // find affected region of old layout 262 263 int startline = getLineForOffset(where); 264 int startv = getLineTop(startline); 265 266 int endline = getLineForOffset(where + before); 267 if (where + after == len) 268 endline = getLineCount(); 269 int endv = getLineTop(endline); 270 boolean islast = (endline == getLineCount()); 271 272 // generate new layout for affected text 273 274 StaticLayout reflowed; 275 StaticLayout.Builder b; 276 277 synchronized (sLock) { 278 reflowed = sStaticLayout; 279 b = sBuilder; 280 sStaticLayout = null; 281 sBuilder = null; 282 } 283 284 if (reflowed == null) { 285 reflowed = new StaticLayout(null); 286 b = StaticLayout.Builder.obtain(text, where, where + after, getPaint(), getWidth()); 287 } 288 289 b.setText(text, where, where + after) 290 .setPaint(getPaint()) 291 .setWidth(getWidth()) 292 .setTextDir(getTextDirectionHeuristic()) 293 .setLineSpacing(getSpacingAdd(), getSpacingMultiplier()) 294 .setEllipsizedWidth(mEllipsizedWidth) 295 .setEllipsize(mEllipsizeAt) 296 .setBreakStrategy(mBreakStrategy); 297 reflowed.generate(b, false, true); 298 int n = reflowed.getLineCount(); 299 300 // If the new layout has a blank line at the end, but it is not 301 // the very end of the buffer, then we already have a line that 302 // starts there, so disregard the blank line. 303 304 if (where + after != len && reflowed.getLineStart(n - 1) == where + after) 305 n--; 306 307 // remove affected lines from old layout 308 mInts.deleteAt(startline, endline - startline); 309 mObjects.deleteAt(startline, endline - startline); 310 311 // adjust offsets in layout for new height and offsets 312 313 int ht = reflowed.getLineTop(n); 314 int toppad = 0, botpad = 0; 315 316 if (mIncludePad && startline == 0) { 317 toppad = reflowed.getTopPadding(); 318 mTopPadding = toppad; 319 ht -= toppad; 320 } 321 if (mIncludePad && islast) { 322 botpad = reflowed.getBottomPadding(); 323 mBottomPadding = botpad; 324 ht += botpad; 325 } 326 327 mInts.adjustValuesBelow(startline, START, after - before); 328 mInts.adjustValuesBelow(startline, TOP, startv - endv + ht); 329 330 // insert new layout 331 332 int[] ints; 333 334 if (mEllipsize) { 335 ints = new int[COLUMNS_ELLIPSIZE]; 336 ints[ELLIPSIS_START] = ELLIPSIS_UNDEFINED; 337 } else { 338 ints = new int[COLUMNS_NORMAL]; 339 } 340 341 Directions[] objects = new Directions[1]; 342 343 for (int i = 0; i < n; i++) { 344 ints[START] = reflowed.getLineStart(i) | 345 (reflowed.getParagraphDirection(i) << DIR_SHIFT) | 346 (reflowed.getLineContainsTab(i) ? TAB_MASK : 0); 347 348 int top = reflowed.getLineTop(i) + startv; 349 if (i > 0) 350 top -= toppad; 351 ints[TOP] = top; 352 353 int desc = reflowed.getLineDescent(i); 354 if (i == n - 1) 355 desc += botpad; 356 357 ints[DESCENT] = desc; 358 objects[0] = reflowed.getLineDirections(i); 359 360 ints[HYPHEN] = reflowed.getHyphen(i); 361 362 if (mEllipsize) { 363 ints[ELLIPSIS_START] = reflowed.getEllipsisStart(i); 364 ints[ELLIPSIS_COUNT] = reflowed.getEllipsisCount(i); 365 } 366 367 mInts.insertAt(startline + i, ints); 368 mObjects.insertAt(startline + i, objects); 369 } 370 371 updateBlocks(startline, endline - 1, n); 372 373 b.finish(); 374 synchronized (sLock) { 375 sStaticLayout = reflowed; 376 sBuilder = b; 377 } 378 } 379 380 /** 381 * Create the initial block structure, cutting the text into blocks of at least 382 * BLOCK_MINIMUM_CHARACTER_SIZE characters, aligned on the ends of paragraphs. 383 */ 384 private void createBlocks() { 385 int offset = BLOCK_MINIMUM_CHARACTER_LENGTH; 386 mNumberOfBlocks = 0; 387 final CharSequence text = mDisplay; 388 389 while (true) { 390 offset = TextUtils.indexOf(text, '\n', offset); 391 if (offset < 0) { 392 addBlockAtOffset(text.length()); 393 break; 394 } else { 395 addBlockAtOffset(offset); 396 offset += BLOCK_MINIMUM_CHARACTER_LENGTH; 397 } 398 } 399 400 // mBlockIndices and mBlockEndLines should have the same length 401 mBlockIndices = new int[mBlockEndLines.length]; 402 for (int i = 0; i < mBlockEndLines.length; i++) { 403 mBlockIndices[i] = INVALID_BLOCK_INDEX; 404 } 405 } 406 407 /** 408 * Create a new block, ending at the specified character offset. 409 * A block will actually be created only if has at least one line, i.e. this offset is 410 * not on the end line of the previous block. 411 */ 412 private void addBlockAtOffset(int offset) { 413 final int line = getLineForOffset(offset); 414 415 if (mBlockEndLines == null) { 416 // Initial creation of the array, no test on previous block ending line 417 mBlockEndLines = ArrayUtils.newUnpaddedIntArray(1); 418 mBlockEndLines[mNumberOfBlocks] = line; 419 mNumberOfBlocks++; 420 return; 421 } 422 423 final int previousBlockEndLine = mBlockEndLines[mNumberOfBlocks - 1]; 424 if (line > previousBlockEndLine) { 425 mBlockEndLines = GrowingArrayUtils.append(mBlockEndLines, mNumberOfBlocks, line); 426 mNumberOfBlocks++; 427 } 428 } 429 430 /** 431 * This method is called every time the layout is reflowed after an edition. 432 * It updates the internal block data structure. The text is split in blocks 433 * of contiguous lines, with at least one block for the entire text. 434 * When a range of lines is edited, new blocks (from 0 to 3 depending on the 435 * overlap structure) will replace the set of overlapping blocks. 436 * Blocks are listed in order and are represented by their ending line number. 437 * An index is associated to each block (which will be used by display lists), 438 * this class simply invalidates the index of blocks overlapping a modification. 439 * 440 * This method is package private and not private so that it can be tested. 441 * 442 * @param startLine the first line of the range of modified lines 443 * @param endLine the last line of the range, possibly equal to startLine, lower 444 * than getLineCount() 445 * @param newLineCount the number of lines that will replace the range, possibly 0 446 * 447 * @hide 448 */ 449 void updateBlocks(int startLine, int endLine, int newLineCount) { 450 if (mBlockEndLines == null) { 451 createBlocks(); 452 return; 453 } 454 455 int firstBlock = -1; 456 int lastBlock = -1; 457 for (int i = 0; i < mNumberOfBlocks; i++) { 458 if (mBlockEndLines[i] >= startLine) { 459 firstBlock = i; 460 break; 461 } 462 } 463 for (int i = firstBlock; i < mNumberOfBlocks; i++) { 464 if (mBlockEndLines[i] >= endLine) { 465 lastBlock = i; 466 break; 467 } 468 } 469 final int lastBlockEndLine = mBlockEndLines[lastBlock]; 470 471 boolean createBlockBefore = startLine > (firstBlock == 0 ? 0 : 472 mBlockEndLines[firstBlock - 1] + 1); 473 boolean createBlock = newLineCount > 0; 474 boolean createBlockAfter = endLine < mBlockEndLines[lastBlock]; 475 476 int numAddedBlocks = 0; 477 if (createBlockBefore) numAddedBlocks++; 478 if (createBlock) numAddedBlocks++; 479 if (createBlockAfter) numAddedBlocks++; 480 481 final int numRemovedBlocks = lastBlock - firstBlock + 1; 482 final int newNumberOfBlocks = mNumberOfBlocks + numAddedBlocks - numRemovedBlocks; 483 484 if (newNumberOfBlocks == 0) { 485 // Even when text is empty, there is actually one line and hence one block 486 mBlockEndLines[0] = 0; 487 mBlockIndices[0] = INVALID_BLOCK_INDEX; 488 mNumberOfBlocks = 1; 489 return; 490 } 491 492 if (newNumberOfBlocks > mBlockEndLines.length) { 493 int[] blockEndLines = ArrayUtils.newUnpaddedIntArray( 494 Math.max(mBlockEndLines.length * 2, newNumberOfBlocks)); 495 int[] blockIndices = new int[blockEndLines.length]; 496 System.arraycopy(mBlockEndLines, 0, blockEndLines, 0, firstBlock); 497 System.arraycopy(mBlockIndices, 0, blockIndices, 0, firstBlock); 498 System.arraycopy(mBlockEndLines, lastBlock + 1, 499 blockEndLines, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); 500 System.arraycopy(mBlockIndices, lastBlock + 1, 501 blockIndices, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); 502 mBlockEndLines = blockEndLines; 503 mBlockIndices = blockIndices; 504 } else { 505 System.arraycopy(mBlockEndLines, lastBlock + 1, 506 mBlockEndLines, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); 507 System.arraycopy(mBlockIndices, lastBlock + 1, 508 mBlockIndices, firstBlock + numAddedBlocks, mNumberOfBlocks - lastBlock - 1); 509 } 510 511 mNumberOfBlocks = newNumberOfBlocks; 512 int newFirstChangedBlock; 513 final int deltaLines = newLineCount - (endLine - startLine + 1); 514 if (deltaLines != 0) { 515 // Display list whose index is >= mIndexFirstChangedBlock is valid 516 // but it needs to update its drawing location. 517 newFirstChangedBlock = firstBlock + numAddedBlocks; 518 for (int i = newFirstChangedBlock; i < mNumberOfBlocks; i++) { 519 mBlockEndLines[i] += deltaLines; 520 } 521 } else { 522 newFirstChangedBlock = mNumberOfBlocks; 523 } 524 mIndexFirstChangedBlock = Math.min(mIndexFirstChangedBlock, newFirstChangedBlock); 525 526 int blockIndex = firstBlock; 527 if (createBlockBefore) { 528 mBlockEndLines[blockIndex] = startLine - 1; 529 mBlockIndices[blockIndex] = INVALID_BLOCK_INDEX; 530 blockIndex++; 531 } 532 533 if (createBlock) { 534 mBlockEndLines[blockIndex] = startLine + newLineCount - 1; 535 mBlockIndices[blockIndex] = INVALID_BLOCK_INDEX; 536 blockIndex++; 537 } 538 539 if (createBlockAfter) { 540 mBlockEndLines[blockIndex] = lastBlockEndLine + deltaLines; 541 mBlockIndices[blockIndex] = INVALID_BLOCK_INDEX; 542 } 543 } 544 545 /** 546 * This package private method is used for test purposes only 547 * @hide 548 */ 549 void setBlocksDataForTest(int[] blockEndLines, int[] blockIndices, int numberOfBlocks) { 550 mBlockEndLines = new int[blockEndLines.length]; 551 mBlockIndices = new int[blockIndices.length]; 552 System.arraycopy(blockEndLines, 0, mBlockEndLines, 0, blockEndLines.length); 553 System.arraycopy(blockIndices, 0, mBlockIndices, 0, blockIndices.length); 554 mNumberOfBlocks = numberOfBlocks; 555 } 556 557 /** 558 * @hide 559 */ 560 public int[] getBlockEndLines() { 561 return mBlockEndLines; 562 } 563 564 /** 565 * @hide 566 */ 567 public int[] getBlockIndices() { 568 return mBlockIndices; 569 } 570 571 /** 572 * @hide 573 */ 574 public int getNumberOfBlocks() { 575 return mNumberOfBlocks; 576 } 577 578 /** 579 * @hide 580 */ 581 public int getIndexFirstChangedBlock() { 582 return mIndexFirstChangedBlock; 583 } 584 585 /** 586 * @hide 587 */ 588 public void setIndexFirstChangedBlock(int i) { 589 mIndexFirstChangedBlock = i; 590 } 591 592 @Override 593 public int getLineCount() { 594 return mInts.size() - 1; 595 } 596 597 @Override 598 public int getLineTop(int line) { 599 return mInts.getValue(line, TOP); 600 } 601 602 @Override 603 public int getLineDescent(int line) { 604 return mInts.getValue(line, DESCENT); 605 } 606 607 @Override 608 public int getLineStart(int line) { 609 return mInts.getValue(line, START) & START_MASK; 610 } 611 612 @Override 613 public boolean getLineContainsTab(int line) { 614 return (mInts.getValue(line, TAB) & TAB_MASK) != 0; 615 } 616 617 @Override 618 public int getParagraphDirection(int line) { 619 return mInts.getValue(line, DIR) >> DIR_SHIFT; 620 } 621 622 @Override 623 public final Directions getLineDirections(int line) { 624 return mObjects.getValue(line, 0); 625 } 626 627 @Override 628 public int getTopPadding() { 629 return mTopPadding; 630 } 631 632 @Override 633 public int getBottomPadding() { 634 return mBottomPadding; 635 } 636 637 /** 638 * @hide 639 */ 640 @Override 641 public int getHyphen(int line) { 642 return mInts.getValue(line, HYPHEN); 643 } 644 645 @Override 646 public int getEllipsizedWidth() { 647 return mEllipsizedWidth; 648 } 649 650 private static class ChangeWatcher implements TextWatcher, SpanWatcher { 651 public ChangeWatcher(DynamicLayout layout) { 652 mLayout = new WeakReference<DynamicLayout>(layout); 653 } 654 655 private void reflow(CharSequence s, int where, int before, int after) { 656 DynamicLayout ml = mLayout.get(); 657 658 if (ml != null) 659 ml.reflow(s, where, before, after); 660 else if (s instanceof Spannable) 661 ((Spannable) s).removeSpan(this); 662 } 663 664 public void beforeTextChanged(CharSequence s, int where, int before, int after) { 665 // Intentionally empty 666 } 667 668 public void onTextChanged(CharSequence s, int where, int before, int after) { 669 reflow(s, where, before, after); 670 } 671 672 public void afterTextChanged(Editable s) { 673 // Intentionally empty 674 } 675 676 public void onSpanAdded(Spannable s, Object o, int start, int end) { 677 if (o instanceof UpdateLayout) 678 reflow(s, start, end - start, end - start); 679 } 680 681 public void onSpanRemoved(Spannable s, Object o, int start, int end) { 682 if (o instanceof UpdateLayout) 683 reflow(s, start, end - start, end - start); 684 } 685 686 public void onSpanChanged(Spannable s, Object o, int start, int end, int nstart, int nend) { 687 if (o instanceof UpdateLayout) { 688 reflow(s, start, end - start, end - start); 689 reflow(s, nstart, nend - nstart, nend - nstart); 690 } 691 } 692 693 private WeakReference<DynamicLayout> mLayout; 694 } 695 696 @Override 697 public int getEllipsisStart(int line) { 698 if (mEllipsizeAt == null) { 699 return 0; 700 } 701 702 return mInts.getValue(line, ELLIPSIS_START); 703 } 704 705 @Override 706 public int getEllipsisCount(int line) { 707 if (mEllipsizeAt == null) { 708 return 0; 709 } 710 711 return mInts.getValue(line, ELLIPSIS_COUNT); 712 } 713 714 private CharSequence mBase; 715 private CharSequence mDisplay; 716 private ChangeWatcher mWatcher; 717 private boolean mIncludePad; 718 private boolean mEllipsize; 719 private int mEllipsizedWidth; 720 private TextUtils.TruncateAt mEllipsizeAt; 721 private int mBreakStrategy; 722 723 private PackedIntVector mInts; 724 private PackedObjectVector<Directions> mObjects; 725 726 /** 727 * Value used in mBlockIndices when a block has been created or recycled and indicating that its 728 * display list needs to be re-created. 729 * @hide 730 */ 731 public static final int INVALID_BLOCK_INDEX = -1; 732 // Stores the line numbers of the last line of each block (inclusive) 733 private int[] mBlockEndLines; 734 // The indices of this block's display list in TextView's internal display list array or 735 // INVALID_BLOCK_INDEX if this block has been invalidated during an edition 736 private int[] mBlockIndices; 737 // Number of items actually currently being used in the above 2 arrays 738 private int mNumberOfBlocks; 739 // The first index of the blocks whose locations are changed 740 private int mIndexFirstChangedBlock; 741 742 private int mTopPadding, mBottomPadding; 743 744 private static StaticLayout sStaticLayout = null; 745 private static StaticLayout.Builder sBuilder = null; 746 747 private static final Object[] sLock = new Object[0]; 748 749 private static final int START = 0; 750 private static final int DIR = START; 751 private static final int TAB = START; 752 private static final int TOP = 1; 753 private static final int DESCENT = 2; 754 private static final int HYPHEN = 3; 755 private static final int COLUMNS_NORMAL = 4; 756 757 private static final int ELLIPSIS_START = 4; 758 private static final int ELLIPSIS_COUNT = 5; 759 private static final int COLUMNS_ELLIPSIZE = 6; 760 761 private static final int START_MASK = 0x1FFFFFFF; 762 private static final int DIR_SHIFT = 30; 763 private static final int TAB_MASK = 0x20000000; 764 765 private static final int ELLIPSIS_UNDEFINED = 0x80000000; 766} 767