Commit Graph

864 Commits

Author SHA1 Message Date
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
Raph Levien
d3ab692d28 Some refactoring of StaticLayout
This patch refactors construction of StaticLayout to use an explicit
Builder object, which is intended to hold state used for constructing
the layout but not needed for merely reading out the results.

Builder objects are allocated from a pool and explicitly recycled,
so there is insignificant additional allocation cost.

This patch has very little impact on performance (it does avoid
allocating a FontMetricsInt object) but opens the way for significant
performance and functionality improvements as more of the Builder
functionality migrates to native code.

Change-Id: I2a576643e573a38b61f895a80d5d92a85c94b6b4
2015-03-04 13:49:12 -08:00
John Spurlock
08c7116ab9 Remove unused imports in frameworks/base.
Change-Id: I031443de83f93eb57a98863001826671b18f3b17
2015-02-28 14:47:49 -05:00
Roozbeh Pournader
001f0b31b6 Merge "Document the limitations of Linkify addresses" 2015-02-25 21:43:50 +00:00
Roozbeh Pournader
1ff7196be9 Document the limitations of Linkify addresses
Explain that we are using WebView#findAddresses() which is
limited to US addresses at the moment (at least according
to its documentation), among various other limitations.

Bug: 5847264
Change-Id: If86c6d7c11cc080f0fe3401ffb7bce8068c6016f
2015-02-25 13:40:52 -08:00
Scott Kennedy
6cd132fef2 Annotate the parameter in TextUtils#isEmpty() as @Nullable
Change-Id: Iaccf7f568952399d5eb48c15a5428317dd75052a
2015-02-19 10:36:12 -08:00
Tor Norbye
7b9c912f53 Add @ResourceInt annotations on APIs
Change-Id: I119cc059c2f8bd98fd585fc84ac2b1b7d5892a08
2015-02-18 07:49:03 -08:00
Raph Levien
80955e105d Merge "Interval tree for SpannableStringBuilder" 2015-02-12 20:34:46 +00:00
Raph Levien
d7c020e9e5 Interval tree for SpannableStringBuilder
This CL greatly improves the speed of SpannableStringBuilder by storing
the spans as an interval tree with binary search.

Bug: 7404182
Change-Id: I2540b2cfe8aef128337e63829479660ba51e62b5
2015-02-12 12:30:52 -08:00
Tao Bao
0d27729dd8 resolve merge conflicts of 6d8886a to master.
Change-Id: If8798a1d87b35e2db56211bf0e7dea94bed91b6a
2015-02-12 11:26:00 -08:00
Tao Bao
6d8886ac46 resolved conflicts for merge of e1e1cd9d to lmp-mr1-dev-plus-aosp
Change-Id: If01cb9c91c4f980d422896aa5ebe713f540d4fd1
2015-02-11 22:32:05 -08:00
Tao Bao
67bfa0b083 Use ICU for relative time formatting
Rewrite the DateUtils' relative time formatting APIs
(getRelativeTimeSpanString, getRelativeDateTimeString) to use ICU ones.
Two APIs that take withPreposition parameter are not changed. Because
(a) ICU doesn't provide functionality to format preposition; (b) They
are not really computing relative time but instead calling
formatDateRange() to get the absolute time/date string.

Bug: 19146457
Bug: 5252772
Change-Id: Iea8d699d63cc4438513910da66d038912e44fb8d
2015-02-11 17:50:21 -08:00
Neil Fuller
0b1b82473d am 022cf57f: am a08934cf: am f789d45b: Merge "Avoid static initialization of Layout from TextUtils" into lmp-mr1-dev
automerge: c63efbd

* commit 'c63efbd928cc14e32fe19b2dec41d15ffc584182':
  Avoid static initialization of Layout from TextUtils
2015-02-06 17:52:57 +00:00
Neil Fuller
c63efbd928 am 022cf57f: am a08934cf: am f789d45b: Merge "Avoid static initialization of Layout from TextUtils" into lmp-mr1-dev
* commit '022cf57f82e40a103c4a48c083a59d7fa4936668':
  Avoid static initialization of Layout from TextUtils
2015-02-06 17:51:05 +00:00
Neil Fuller
d950ad034c Avoid static initialization of Layout from TextUtils
This works around a bug in standalone (e.g. non-Zygote)
runtimes when a device is attached to a host that is running
DDM.

There is a race condition:

When the runtime receives a HELLO from DDM it calls
TextUtils.isEmpty().

Calling any TextUtils methods statically initializes
Layout. Layout has dependencies on other classes, which in
turn have dependencies on native methods that are not always
registered when the call takes place. Registration and DDM
handling are done in separate threads.

This is not a fix, merely a workaround until the race can
be resolved.

Bug: 18081539
(cherry-picked from commit d29bdb266d)

Change-Id: Id0d8578eab9e59d479a7c1b2e7ea1890ac0c8de6
2015-02-06 17:34:37 +00:00
Neil Fuller
d29bdb266d Avoid static initialization of Layout from TextUtils
This works around a bug in standalone (e.g. non-Zygote)
runtimes when a device is attached to a host that is running
DDM.

There is a race condition:

When the runtime receives a HELLO from DDM it calls
TextUtils.isEmpty().

Calling any TextUtils methods statically initializes
Layout. Layout has dependencies on other classes, which in
turn have dependencies on native methods that are not always
registered when the call takes place. Registration and DDM
handling are done in separate threads.

This is not a fix, merely a workaround until the race can
be resolved.

Bug: 18081539
Change-Id: If1bd3de6597bc93da381c8f86dacf40156449561
2015-02-06 10:29:54 +00:00
Igor Viarheichyk
6f9f1d4b3b Use constants instead of resources for ellipsis.
All supported locales use only U+2025 and U+2026 to represent
ellipses, and it will unlikely change in future. Given translated
resources are inconsistent and often use three dots it is safer
to use constants instead of resources.

(cherry-pick of ed0daa93e48d38e54a7ad1c99c461510a4c07599.)

Bug: 18542179
Change-Id: I51a6cb903f62f739fbadd6b78e5765c0028d641a
2015-01-29 15:00:13 -08:00
Svet Ganov
22a08757b2 am 605ba802: am 2004fdf8: am 830f39ad: Merge "Fixing a memory leak: activities are leaked." into lmp-mr1-dev
* commit '605ba802778ed67ddd2ca1af7f55df6f2d257765':
  Fixing a memory leak: activities are leaked.
2015-01-16 22:31:38 +00:00
Svet Ganov
605ba80277 am 2004fdf8: am 830f39ad: Merge "Fixing a memory leak: activities are leaked." into lmp-mr1-dev
* commit '2004fdf8e54daa84a8c4da20909f81f37add66d5':
  Fixing a memory leak: activities are leaked.
2015-01-16 22:25:01 +00:00
Svet Ganov
893d6fe48d Fixing a memory leak: activities are leaked.
TextLine was not fully cleared before recycling it which leads to
activity leaks if the activity happens: to register a text watcher.

bug:19045507

Change-Id: Ife0f7ce29865bd30ca2dfe8795023f51f275d659
2015-01-16 18:14:36 +00:00
Scott Kennedy
adc6b85072 Add @Nullable annotation where necessary in Rfc822Token
Change-Id: I9b3088cbdfa09a8085b525674ff2540f23d4c96e
2015-01-15 10:50:31 -08:00
Raph Levien
faf2190334 am 3ac280c9: am 078ce5fc: Merge "Revert "Change Linkify leniency to VALID"" into lmp-mr1-dev
automerge: d946753

* commit 'd946753aa4ac3ac9b16ff1627a19fb05f1608660':
  Revert "Change Linkify leniency to VALID"
2014-12-17 23:21:16 +00:00
Raph Levien
d946753aa4 am 3ac280c9: am 078ce5fc: Merge "Revert "Change Linkify leniency to VALID"" into lmp-mr1-dev
* commit '3ac280c93bdebe4ca698e9a2e3d6d2daf3598e7a':
  Revert "Change Linkify leniency to VALID"
2014-12-17 23:19:25 +00:00
Raph Levien
047e816fe2 Revert "Change Linkify leniency to VALID"
This reverts commit 9dfe86d410.

That change moved the lenience from POSSIBLE to VALID, which eliminated
false positive links, especially 4 digit phone numbers, but caused
significant false negatives, leading to CTS test failures
(android.text.util.cts.LinkifyTest#testAddLinks7 in particular).

The true fix requires new functionality to validate phone numbers in
a mobile context. In the meantime, the best solution is to revert.

Bug: 18708556
2014-12-17 14:31:39 -08:00
Raph Levien
4c02e83172 Revert "Fix missing ellipsis when just one character is truncated"
This reverts commit 93e48e8cf1.

The existing code in master already worked correctly for the original
problem, and this change just introduced a new problem.

Bug: 18576264
2014-12-12 11:24:45 -08:00
Daniel 2 Olofsson
7bd9b7f73d Fix to crash when clicking text link without view activity
A generated quick link to telephone number gets clicked and
crashes if corresponding activity doesn't exist in device.
It attempts to open up an activity to view content which will
in turn generate an uncaught ActivityNotFoundException.
Solved by catching exception when launching activity for the
specified content.

Change-Id: I47364519f1eceb5b978b29382107deae1891c7da
2014-12-10 00:40:53 +00:00
Raph Levien
e04cfa8aa5 am 1918d027: am 8aa97d26: am 238efad0: Merge "Change Linkify leniency to VALID" into lmp-mr1-dev
* commit '1918d0276ad502e45944bd75a187dd22021790c5':
  Change Linkify leniency to VALID
2014-12-09 00:17:09 +00:00
Raph Levien
1a91d8df50 resolved conflicts for merge of b9d21d62 to master
Change-Id: I2936c2a47290c3ea0fc66d460215f9e75d17ebf2
2014-12-08 13:46:15 -08:00