Commit Graph

901 Commits

Author SHA1 Message Date
Alan Viverette
5299968517 Merge "Prevent poorly-extended ParcelableSpans from writing to parcels" into mnc-dev 2015-06-04 16:55:57 +00:00
Raph Levien
a6a082862b Rename setTextDir to setTextDirection
StaticLayout.Builder used "setTextDir" as a shorthand, but it's not
as clear as spelling it out. So, setTextDirection.

Bug: 21572282
Change-Id: Ia94476562d70678f963196b87bb63511d30836b6
2015-06-03 13:20:45 -07:00
Roozbeh Pournader
c021632e07 Merge "Load hyphenation data for more languages." into mnc-dev 2015-06-03 00:56:24 +00:00
Alan Viverette
a70d4a90a0 Prevent poorly-extended ParcelableSpans from writing to parcels
If a developer extends an existing ParcelableSpan and overwrites
writeToParcel, TextUtils will crash when attempting to unparcel
since the span type ID is not accurate. This CL makes a separate
framework-private method for writeToParcel to ensure that even if
a developer extends a ParcelableSpan class, they won't modify the
parceling or unparceling code that's tied to the span type ID.

Bug: 21274544
Change-Id: If4c3506a55999df7a3b6d87cb8d550235d7a02c6
2015-06-02 16:11:00 -07:00
Raph Levien
edb27f14ec Revert "Revert "Use getRunAdvance to position cursor""
This reverts commit 5730c97480.
2015-06-01 14:34:47 -07:00
Raph Levien
5730c97480 Revert "Use getRunAdvance to position cursor"
This reverts commit cb5499c850.

Bug: 21549197
2015-06-01 12:40:42 -07:00
Neil Fuller
3b7f9615b7 Merge "Fix javadocs based on recent case consistency change" into mnc-dev 2015-06-01 12:04:44 +00:00
Neil Fuller
a5e389ddd2 Fix javadocs based on recent case consistency change
Commit a40d2447b6f516116135ee7f126579771ba98a2c made the
case consistently "as for the beginning of a sentence".
This updates the docs to reflect that. Previously the
result depended on the string returned (e.g. "Tomorrow"
was capitalized in English) and the casing varied
within and between locales.

Bug: 20247811
(cherry-picked from commit 0e1c0e11e4)

Change-Id: I7b48958725b32b13bee00347585472f8073e7761
2015-06-01 13:02:18 +01:00
Raph Levien
cb5499c850 Use getRunAdvance to position cursor
TextLine used to use getTextRunAdvances on a substring to compute a
cursor position, but this had a number of problems, especially when
the substring is a wider than the full string (as can happen in
certain Tamil ligatures).

This patch changes the implementation to use getRunAdvance, which was
explicitly designed for this use case.

We should also change Layout.getHorizontal to use the dual
getOffsetForAdvance, but that's basically a performance optimization,
the functionality should be basically equivalent.

Bug: 21125816
Change-Id: I669b85eaecfbf6f7aa6c6a9dddbf1a210eb94571
2015-05-28 16:36:36 -07:00
Roozbeh Pournader
4d4202bf57 Load hyphenation data for more languages.
This loads hyphenation data for the languages we currently provide at
initialization time. It also has a poor man's locale fallback
mechanism for finding hyphenation patterns where the locale doesn't
exactly match what may be available and caches the results.

Bug: 20088132
Change-Id: If7b2a8d5295df9cb2bdae7418df27bf77fb44e58
2015-05-28 13:03:26 -07:00
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