Commit Graph

891 Commits

Author SHA1 Message Date
Roozbeh Pournader
f156cb31c0 Make unicodeWrap() return null if the input string is null.
Previously, a NullPointerException was raised if the input was null.

Bug: 12894042
Change-Id: I5c5db484e5659659c1da91079adcba773ba7d83d
2015-05-16 18:50:18 +00:00
Mady Mellor
21623faa44 Merge "Fix issue where handle is in front of word rather than end of word" into mnc-dev 2015-05-13 17:34:13 +00:00
Roozbeh Pournader
95c7a13f2a Add hyphenationFrequency attribute to TextView and StaticLayout.
This patch adds plumbing to TextView and StaticLayout to control the
frequency of automatic hyphenation used in laying out paragraphs.

Bug: 21038249
Change-Id: Ib45de190eb0a1ed738e69fd61f2b39561b11aec7
2015-05-12 14:56:57 -07:00
Mady Mellor
58c9087137 Fix issue where handle is in front of word rather than end of word
Previous getWordEnd and getWordStart functions would return a boundary
rather than a word end / start boundary in some cases. This behavior is
most evident when moving between short lines -- the handle would go to
the next boundary rather than the word end on the next line (and the
start handle would go to the word end rather than the word start on
the prev line).

This CL ensures that word or punctuation boundaries are returned and moves
most of the punctuation boundary logic into WordIterator since it makes
a bit more sense there.

Bug: 21030788
Change-Id: I96c6aff7f2c213aa3c4f66ac87ca913ca16fd347
2015-05-12 11:09:37 -07:00
Mady Mellor
6c7b4ad690 Consider punctuation treatment when selecting text.
This treats punctuation as "words", so groups of punctuation will be
selected together, i.e. "Hmm... yay!!!" would be treated as four words:
Hmm-...-yay-!!!

Bug: 19950062
Change-Id: Ic9514c524092734fad1abdf19a736bfa1406157b
2015-05-07 21:05:36 +00:00
Raph Levien
6402dc7e4a Merge "Clear all StaticLayout.Builder fields on pool recycle" into mnc-dev 2015-05-06 21:35:13 +00:00
Raph Levien
3bd60c7b11 Clear all StaticLayout.Builder fields on pool recycle
When returning a StaticLayout.Builder object to the pool, it is
important to clear everything out. If not, then the object may have
stale state from a previous layout operation. This was causing CTS
test failures and probably other mischief.

Bug: 20636917
Change-Id: I76fb20076ee954fcb476131a8fbe8833d72fbc0d
2015-05-06 14:26:35 -07:00
Raph Levien
8e71a397c6 Fix NPE in Html.inParagraph()
The typeface in a TypefaceSpan can be the null string. This patch
fixes the string comparison to not throw a NullPointerException.

Bug: 20849738
Change-Id: Ied049305794966bcbca00cfd11fe97a91b685d79
2015-05-05 10:13:54 -07:00
Raph Levien
531c30c62b Expose StaticLayout.Builder publicly
Expose the new Builder pattern for creating StaticLayout. This allows
access to a number of features that have been available to TextView
through a hidden constructor. Some of these features have existed
for a while (mostly maxLines), while others are new (breakStrategy,
indents).

The builder is cleaner and has a better upgrade path than the old
pattern of lots of constructors with varying numbers of arguments.

Bug: 20190561
Change-Id: Ia3cd124825ab0cb469d22d1fc576ad26454545b8
2015-05-01 15:15:48 -07:00
Raph Levien
ebd66ca600 Make Paint a required field of StaticLayout Builder
This patch moves the Paint parameter from being an option set from
setPaint to being a required field passed into the obtain() method
of StaticLayout.Builder. Thus, it is now possible to get a valid
StaticLayout object just doing .build() on the Builder; all other
fields are optional.

This is in preparation for exposing the builder publicly, but that
is to be a separate CL.

Bug: 20190561

Change-Id: Iefd7800203004e565d068b0c76502cf7cf52d91f
2015-04-30 15:38:17 -07:00
Keisuke Kuroyanagi
65769551df Merge "Enable mouse drag text selection for unfocused TextView." 2015-04-20 04:49:50 +00:00
Michael Wright
666b2b75ce Merge "Stop Shift+Backspace from foward deleting." 2015-04-16 21:46:14 +00:00
Roozbeh Pournader
83ab3b44df Merge "Fix various conformance issues with TextDirectionHeuristics." 2015-04-16 20:38:55 +00:00
Keisuke Kuroyanagi
88d92da325 Enable mouse drag text selection for unfocused TextView.
Bug: 17643755
Change-Id: If6ca064a082feaf6faf9555b1455c4b2f6312952
2015-04-16 17:41:06 +09:00
Raph Levien
e319d5a362 Add left and right indent arrays to TextView
In support of layout of paragraphs to non-rectangular regions, add
arrays for left and right indents to TextView, along with supporting
StaticLayout builder setters.

Bug: 20182243
Change-Id: I015bcef8f258c89001fcf8a54c179d2dfc0d7943
2015-04-15 18:57:53 -07:00
Roozbeh Pournader
4736010139 Fix various conformance issues with TextDirectionHeuristics.
1. The algorithms no longer consider directional embeddings and
overrides as strong characters.

2. The algorithms are updated to Unicode 7.0, and consider the
directional isolates in determining the direction of input.

3. Codepoints are used instead of code units for looking up bidi
properties.

4. The bidi direction of unassigned characters is considered.

Bug: 20142480
Change-Id: I9be161c112b8f23565ed8961bb7d44ced234f67a
2015-04-15 14:34:59 -07:00
Michael Wright
375f3153a9 Stop Shift+Backspace from foward deleting.
Bug: 17538139
Change-Id: Ia193c59058d99880ea5afe5bd1bbcc0dce97f9d4
2015-04-15 12:30:31 +01:00
Keisuke Kuroyanagi
e26bd2c361 Merge "Fix crash when ellipsize="start" is applied to short line." 2015-04-15 04:04:46 +00:00
Keisuke Kuroyanagi
ed2eea1bfc Fix crash when ellipsize="start" is applied to short line.
Bug: 19833548
Change-Id: I05a36f00f5c7aa6f0ce1993337585f6cfc64649a
2015-04-14 18:18:35 +09:00
Seigo Nonaka
f2b233d44c Introduce Ctrl+Backspace/Ctrl+ForwardDelete shortcut.
Ctrl+Backspace deletes preceding one word and Ctrl+ForwardDelete delets
following one word.
Used Chrome's implementation/behvior as a reference.

Bug: 17810742
Change-Id: I7b2ca515b2f017e457f7104ec7b8e7473ca4e081
2015-04-10 15:18:10 +09:00
Seigo Nonaka
eaddec8c70 Use TextView's text locale for capitalization.
BUG: 19284889
Change-Id: Icd3c1dd3b31c23025bc974bcbb5a3618196434e7
2015-04-09 21:57:20 +09:00
Raph Levien
97f09ae8b0 Merge "Clear hyphenEdit from Layout's paint" 2015-04-08 21:09:09 +00:00
Raph Levien
9a174dda42 Clear hyphenEdit from Layout's paint
The paint of a layout may be reused with other things (in particular,
it can be passed to a BoringLayout), so make sure the hyphenEdit is
zeroed out after use.

Change-Id: If58c5588af9642c3ba827acefea7895e814daab9
2015-04-08 13:38:51 -07:00
Romain Guy
492c836f83 am 5b61a282: am e4d787b2: am 80e455e3: Merge "Prevent possible memory leak in SpanSet"
* commit '5b61a282255b5273f5194db73f3c88550dc11a57':
  Prevent possible memory leak in SpanSet
2015-04-08 07:38:58 +00:00
Romain Guy
b3a9bc038d Prevent possible memory leak in SpanSet
If SpanSet.init() is called several times in a row with different
values, it is possible to change "numberOfSpans" in a way that
will prevent SpanSet.recycle() from nulling out all the spans.

This can lead to memory leaks of large objects through spans
references. User @piwai reported this leak:

     com.squareup.marketfont.MarketSpan
     `-[1] of array android.text.style.CharacterStyle[]
       `-spans of object android.text.SpanSet
         `-mCharacterStyleSpanSet of object android.text.TextLine
           `-[1] of array android.text.TextLine[]
             `-sCached of class android.text.TextLine

The MarketSpan instance is kept alive through a recycled TextLine
which itself contains a SpanSet.

Change-Id: Idfb2233ca16895dbe735c312662eaf0b4a2ecd65
2015-04-07 11:07:05 -07:00
Raph Levien
f1f9902b19 Merge "Load hyphenation data at Zygote init" 2015-04-06 20:02:16 +00:00
Raph Levien
c3dd1c1b91 Load hyphenation data at Zygote init
Loading hyphenation data on demand can cause UI jank (and can be a
strict mode violation). This patch explicitly loads the data at
Zygote init time. It also chooses /system/usr/hyphen-data as the path
for this data.

Bug: 20060770

Change-Id: Idac68e3971f8638f1d70960594bf6c1050bb23d6
2015-04-06 19:53:30 +00:00
Raph Levien
39b4db73c3 Add breakStrategy attribute to TextView
This patch adds plumbing to TextView to control the strategy used
for breaking paragraphs into lines.

The default for TextView is "quality", while the default for EditText
is "simple", largely to avoid too much re-layout when editing.

StaticLayout now has a builder which provides access to more
functionality and is also cleaner than the old mechanism of having
lots of constructors with varying numbers of arguments. This patch
changes TextView to use that builder, and also contains cleanups
of the Builder within StaticLayout.

Change-Id: Iee3cf3a05a3e51ba0834554e4a3ec606e9cabca5
2015-04-01 11:01:41 -07:00
Raph Levien
26d443aee4 Revert "Fix build: Revert "Record hyphens from Minikin and draw them""
This reverts commit 5a6eeb3cbe and
fixes the underlying issue (needed to @hide getHyphen() for subclasses
of Layout, not just the base class), and layoutlib changes for
checkbuild.

Change-Id: I7a2b5f20ae014ea8e224d8c4079cf9131e17e1c1
2015-03-30 15:13:50 -07:00
Ed Heyl
7298d1f079 Merge "Fix build: Revert "Record hyphens from Minikin and draw them"" 2015-03-30 20:35:58 +00:00
Ed Heyl
5a6eeb3cbe Fix build: Revert "Record hyphens from Minikin and draw them"
This reverts commit 27fb878c04e18d3bdd6c42ed347194a7c816ed97.

Change-Id: I2b3390cb0b258a2e1a38ad72ae9686177d6ffdb8
2015-03-30 20:34:02 +00:00
Raph Levien
683ab2afc5 Merge "Record hyphens from Minikin and draw them" 2015-03-30 19:34:11 +00:00
Elliott Hughes
6fd63402f5 Merge "Document that Time doesn't support pseudo-zones." 2015-03-27 22:45:09 +00:00
Elliott Hughes
5c955ee541 Document that Time doesn't support pseudo-zones.
Bug: 19110194
Change-Id: I653b7dc46d5f15da70435f6bddd49042f4d03b54
2015-03-27 15:18:12 -07:00
Raph Levien
71cbc72e70 Record hyphens from Minikin and draw them
This patch plumbs up hyphens computed in Minikin's LineBreaker,
records them in a new column in StaticLayout, and draws them.
DynamicLayout mirrors the new column, and TextLine is also changed to
make sure the hyphen is only drawn for the last run in a line.

There is a rather primitive mechanism for loading hyphenation
patterns, for testing only at this point.

Change-Id: Ib208568c0f6cff12cf834047500ec1da9ea9f430
2015-03-27 11:13:25 -07:00
Raph Levien
c94f742f7e Calculate line breaks using Minikin
This patch moves the calculation of line breaks for StaticLayout into
the new LineBreaker class provided by Minikin. This specific patch
should preserve existing functionality, but perhaps performance is
better, and the movement opens the door to much more sophisticated
line-breaking.

Change-Id: Iafccb9da4e3559bbeaeb2c7c85f86ddfd8ae2fa1
2015-03-26 22:52:32 -07:00
Alan Viverette
16802f0de2 am 46c95313: am ddb30cd3: am 7506f499: Merge "Fix to crash when clicking text link without view activity"
* commit '46c953138298285d9cb06a75030fc73081ccc121':
  Fix to crash when clicking text link without view activity
2015-03-25 21:07:34 +00:00
Alan Viverette
7506f499b5 Merge "Fix to crash when clicking text link without view activity" 2015-03-25 16:35:37 +00:00
Roozbeh Pournader
2243ae17a9 Make Html#toHTML() generate correct bidi directions.
Previously, after the first paragraph, the the detected bidi
direction of the text in the last paragraph was used, nstead of the
detected bidi direction of the current one.

Bug: 12027356
Change-Id: I51622a3156f1e321f53f7ca1855bc37aa6f77319
2015-03-23 17:47:33 +00:00
Alan Viverette
4a357cd2e5 Replace usages of deprecated Resources.getColor() and getColorStateList()
Change-Id: I8f64fe6c4c44a92ff6d07250223ba590a1d691b0
2015-03-18 18:37:18 -07:00
James Cook
f2560e62cf Merge "Improve undo support for text entered with IME" 2015-03-18 21:39:03 +00:00
James Cook
d202668670 Improve undo support for text entered with IME
Use span properties to detect:
* Composing text - don't record undo operations
* Completing a composition - record an insert undo operation
* Canceling a composition - don't record

Save the composition state on parcel/unparcel.

Stop using begin/end batch edit to try to detect when a TextWatcher
is modifying the text. IMEs trigger multiple InputFilter passes in
a single batch edit. Use SpannableStringBuilder to determine when
we're in a TextWatcher callback because it is the authority on that
state.

Fix a bug in undo manager where it doesn't forget undos correctly if
there are more than one in the stack.

Bug: 19332904
Change-Id: Iaa9b0b2a7bf6683302cc85e7616e5d5fcc9fa202
2015-03-18 14:36:41 -07:00
Andreas Gampe
d75a3b4d2c am 17eda7d0: am 4d907643: Merge "Frameworks/base: Fix trivial equals implementation"
* commit '17eda7d0bed1d32a9b8f4a6a9d572aeabb43810a':
  Frameworks/base: Fix trivial equals implementation
2015-03-17 20:47:33 +00:00
Andreas Gampe
610b2c778c Frameworks/base: Fix trivial equals implementation
The comparator's equal implementation doesn't satisfy the constraints
of an equals method, namely being reflexive. Use the standard Object
implementation instead.

Bug: 19797138
Change-Id: I74f888e99533e1945aab7ab10fe8ee3ded6388f4
2015-03-17 20:24:45 +00:00
Raph Levien
70616ecd22 Start moving text measurement into native code
We want to move text measurement into native code, mostly so that
alternate measurement for hyphens can be performant. This patch begins
that migration, in the main StaticLayout case, but still surfaces the
widths array to Java (for ellipsis calculation), and also includes a
hack (used mostly for testing) for computing widths in Java and sending
them down to native code when TextPaint is subclassed.

Change-Id: I476c9e8b3aa8e4e3552eb18f66c4bcd5683f3a72
2015-03-13 10:11:57 -07:00
Raph Levien
ce4155a204 Fix android.text.cts.StaticLayoutTest#testGetEllipsisCount
The "moreChars" predicate (which is used in ellipsis computation) was
slightly incorrect, sometimes being computed as false when the line
break is at the end of a paragraph but not the end of the buffer.
This patch makes the behavior consistent with shipping versions.

Bug: 19676414
Change-Id: I72e16794e895c2eb765b21feaf59fcdccc4857f1
2015-03-11 11:02:33 -07:00
Tor Norbye
80756e3888 Annotate ARGB integer parameters with @ColorInt
Change-Id: I307f72a382272cf18ddb6b07d9fcb81228568d9a
2015-03-05 16:34:12 -08:00
Raph Levien
560a433c44 Merge "Add JNI StaticLayout.Builder" 2015-03-05 21:26:32 +00:00
Raph Levien
4c1f12efcf Add JNI StaticLayout.Builder
This patch adds a native C++ Builder object for StaticLayout to
complement the Java one introduced in a previous patch.

The Builder object contains state used in constructing a layout, as well
as temporary buffers, to avoid having to allocate such. In particular,
it holds a break iterator, so avoids the cost of constructing that in
the common case of a single locale.

Change-Id: I1125103b7ccf00b8674c1586c3ea8d5d915fdd5b
2015-03-05 10:07:33 -08:00
Raph Levien
35091569b9 Merge "Some refactoring of StaticLayout" 2015-03-04 22:28:19 +00:00