Commit Graph

1423 Commits

Author SHA1 Message Date
TreeHugger Robot
3c159f6f1e Merge "Validate index for cursor on BiDi text" 2018-08-15 14:18:25 +00:00
Siyamed Sinir
58df795cbe Validate index for cursor on BiDi text
Previously we have updated the code not to check mHorizontals if offset
is invalid (I5c5778718f6b397adbb1e4f2cf95e9f635f6e5c8) However we should
also check the final index to make sure no invalid index is accessed.

Test: None

Bug: 111580019
Change-Id: I5c32820cde5f91bfe8688e9394b8ba3254cbd731
2018-08-15 11:37:44 +00:00
Mathew Inwood
efeab847f9 Add @UnsupportedAppUsage annotations
For packages:
  android.text.util
  android.text.style
  android.text.method
  android.text.format
  android.text

This is an automatically generated CL. See go/UnsupportedAppUsage
for more details.

Exempted-From-Owner-Approval: Mechanical changes to the codebase
which have been approved by Android API council and announced on
android-eng@

Bug: 110868826
Test: m
Change-Id: I9afbd4ca8826c37cb70db43252e39b9a674e5ae0
2018-08-15 11:16:12 +01:00
Siyamed Sinir
042856b46a Merge "Disable hyphenation by in default theme" 2018-08-07 18:46:15 +00:00
Seigo Nonaka
6f11c6e7e2 Extract native methods into isolated classes
StaticLayout/MeasuredParagraph uses native methods which is a pain point
of porting TextView to JetPack.
To make minimize the dependency to the native methods, extract native
methods and put them into a thin wrapper class.

The performance impact is limited:

android.text.StaticLayoutPerfTest:
    PrecomputedText Balanced Hyphenation  :    602 ->    644: ( +42, +7.0%)
    PrecomputedText Balanced NoHyphenation:    457 ->    476: ( +19, +4.2%)
    PrecomputedText Greedy Hyphenation    :    397 ->    412: ( +15, +3.8%)
    PrecomputedText Greedy NoHyphenation  :    397 ->    411: ( +14, +3.5%)
    RandomText Balanced Hyphenation       : 17,594 -> 17,715: (+121, +0.7%)
    RandomText Balanced NoHyphenation     :  7,146 ->  7,236: ( +90, +1.3%)
    RandomText Greedy Hyphenation         :  7,125 ->  7,196: ( +71, +1.0%)
    RandomText Greedy NoHyphenation       :  7,099 ->  7,187: ( +88, +1.2%)
  draw
    PrecomputedText NoStyle               :    614 ->    628: ( +14, +2.3%)
    PrecomputedText Style                 :    778 ->    826: ( +48, +6.2%)
    RandomText NoStyle                    :    537 ->    540: (  +3, +0.6%)
    RandomText Style                      :    786 ->    759: ( -27, -3.4%)

Bug: N/A
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest

Change-Id: I976df4db63be241af395dd30dd94182f76bdae53
2018-07-27 11:08:43 -07:00
Siyamed Sinir
c0dab36d6b Disable hyphenation by in default theme
Test: Added cts tests for default values
Test: atest CtsWidgetTestCases:EditTextTest
Test: atest CtsWidgetTestCases:TextViewTest
Test: atest FrameworksCoreTests:TextViewTest

Bug: 111096709
Change-Id: Ia4d13574557970432fdcd27581ee3fff4ec36c64
2018-07-23 14:25:28 -07:00
TreeHugger Robot
014a89593a Merge "Fix crash during cursor moving on BiDi text" 2018-07-20 02:56:26 +00:00
Seigo Nonaka
960647d582 Fix crash during cursor moving on BiDi text
The crash was introduced by Ib66ef392c19c937718e7101f6d48fac3abe51ad0
The root cause of the crashing is requesting out-of-line access for the
horizontal width. This invalid access is silently ignored by
TextLine#measure() method but new implementation end up with out of
bounds access.

To makes behavior as old implementation, calling getHorizontal instead
of accessing measured result array.

Bug: 111580019
Test: Manually done
Change-Id: I5c5778718f6b397adbb1e4f2cf95e9f635f6e5c8
2018-07-19 16:22:02 -07:00
Chris Craik
59ff32c4c4 Remove Path codepath in BulletSpan
Test: none

Circles are historically actually easier to draw than Paths for HW
acceleration, though they're equivalent in Skia.

Change-Id: I1a7e2ca6439b6a09fdac784237065668db8cadc6
2018-07-19 14:58:39 -07:00
Seigo Nonaka
73146e7ceb Remove unused line in PrecomputedText
Bug: N/A
Test: N/A
Change-Id: I2456116657d8be893a8c477df14a5de490fbaa37
2018-07-16 18:09:32 -07:00
Siyamed Sinir
4636cc848e Merge "Add UrlSpanFactory to Linkify" 2018-07-10 23:32:27 +00:00
Aaron Heuckroth
09d6bd8a66 Merge "Move channel logging to dump method and redact name." 2018-07-10 18:05:34 +00:00
Aaron Heuckroth
51d3288431 Move channel logging to dump method and redact name.
Test: Generate bug report and confirm that NotificationChannel logs contain redacted name strings.
Change-Id: Iebaf7b165de0276e69ead862aa7ec864ef912282
Fixes: 78326066
2018-07-09 13:26:48 -04:00
Siyamed Sinir
9c6c097604 Add UrlSpanFactory to Linkify
Enable API user to create their own URLSpan for Linkify operations.

Test: atest android.text.util.cts.LinkifyTest
Test: atest android.text.util.LinkifyTest

Bug: 28536972
Bug: 32613009
Bug: 29150779
Change-Id: I9a2f995656bd1510502e5517ac737b47ebd33130
2018-07-08 12:41:38 -07:00
Ian Pedowitz
0a35c20bc3 Revert "Add UrlSpanFactory to Linkify"
This reverts commit ad4883bb1b.

Reason for revert: b/111218263

Bug: 28536972
Bug: 32613009
Bug: 29150779
Change-Id: Idc1621d472d742929f56d10d72b077b774b9e56e
2018-07-07 22:02:29 +00:00
Siyamed Sinir
ad4883bb1b Add UrlSpanFactory to Linkify
Enable API user to create their own URLSpan for Linkify operations.

Test: atest android.text.util.cts.LinkifyTest
Test: atest android.text.util.LinkifyTest

Bug: 28536972
Bug: 32613009
Bug: 29150779

Change-Id: Ia4495dc7e656044b91a79804d3b50a30cae98225
2018-07-03 10:53:16 -07:00
Tobias Thierer
13b96fc1a1 Merge "TextUtils: track behavior change of Pattern.split() when targeting > 28." am: b5f35aeaf3 am: 5442964205
am: e4449497ed

Change-Id: I3bbb854c61f476caaef20eeae2bbcc9473c49469
2018-06-27 08:40:26 -07:00
Tobias Thierer
5442964205 Merge "TextUtils: track behavior change of Pattern.split() when targeting > 28."
am: b5f35aeaf3

Change-Id: I55ba23bfae8f578eb75a4cbfeb2ed4ad1492867d
2018-06-27 08:14:58 -07:00
Tobias Thierer
3e76c04c96 TextUtils: track behavior change of Pattern.split() when targeting > 28.
Another CL in this topic changes the behavior of String.split() and
Pattern.split() to omit a "" generated by a leading zero-width match.
TextUtils.split() is implemented on top of these methods and therefore
adopts the behavior change by default.

The behavior change only affects apps targeting API versions > 28.

Test: cts-tradefed run singleCommand cts-dev -m CtsTextTestCases \
      -t android.text.cts.TextUtilsTest
Test: cts-tradefed run singleCommand cts-dev -m CtsLibcoreTestCases
Bug: 109659282

Change-Id: I8abe251353f8eacf1429ac9a8e272d50a0944c29
2018-06-26 14:48:47 +01:00
TreeHugger Robot
4291ea0c3c Merge "Cleanup: Remove unused padding arguments" 2018-06-08 16:57:55 +00:00
Seigo Nonaka
9155fa6e41 Cleanup: Remove unused padding arguments
Bug: N/A
Test: N/A
Change-Id: I05f5a7d45fcbdc5aacee3e2e915b62017b9cd178
2018-06-05 18:22:03 -07:00
Aurimas Liutikas
7f6641b890 Merge "Fix broken links in @see tags in framework docs." 2018-06-04 19:51:34 +00:00
TreeHugger Robot
232e558006 Merge "Annotate Parcel param/return reference types." 2018-06-04 19:33:59 +00:00
Aurimas Liutikas
e701dc1799 Fix broken links in @see tags in framework docs.
doclava was accidentally suppressing all these broken links
in @see tags. This CL fixes issues so we can start enfocing
checks for broken @see links.

Test: make docs
Change-Id: If7830ece85f8d1f27c991eae282230814726e115
Exempt-From-Owner-Approval: Fixing @see javadoc link issues that are currently completely broken
2018-06-04 10:15:22 -07:00
Jake Wharton
b1f474c066 Annotate Parcel param/return reference types.
Bug: 78245676
Test: atest ParcelNullabilityTest
Change-Id: I7bb844164d4b417445ff2d6f2f99c8a88d7f7f48
2018-06-04 12:47:45 -04:00
Mihai Popa
138b106402 Optimise the hit test algorithm
Layout#getOffsetForHorizontal was running in O(n^2) time, where n is the
length of the current line. The method is used when a touch event
happens on a text line, to compute the cursor offset (and the character)
where it happened. Although this is not an issue in common usecases,
where the number of characters on a line is relatively small, this can
be very inefficient as a consequence of Unicode containing 0-width
(invisible) characters. Specifically, there are characters defining the
text direction (LTR or RTL), which cause our algorithm to touch the
worst case quadratic runtime. For example, a person is able to send a
message containing a few visible characters, and also a lot of these
direction changing invisible ones. When the receiver touches the message
(causing the Layout#getOffsetForHorizontal method to be called), the
receiver's application would become not responsive.

This CL optimizes the method to run in O(n) worst case. This is achieved
by computing the measurements of all line prefixes at first, which can
be done in a single pass. Then, all the prefix measurement queries will
be answered in O(1), rather than O(n) as it was happening before.

Bug: 79215201
Test: manual testing
Change-Id: Ib66ef392c19c937718e7101f6d48fac3abe51ad0
Merged-In: Ib66ef392c19c937718e7101f6d48fac3abe51ad0
2018-05-31 19:14:17 +01:00
Mihai Popa
ce642dc2ff Supress text replacement spans for ellipsis
When a sequence of characters belonging to a text is ellipsized, we
usually replace the first characters with ... and then all the others
with a 0 width character, knowing that they will be drawn, but will be
invisible. However, these positions could have had ReplacementSpans
attached to them, such as EmojiTypefaceSpan when the EmojiCompat library
is used. When this happened, all the ellipsized out characters were
invisible, apart from emojis, which were still drawn as usual (as they
were replacing sequences of 0 width characters).
This CL fixes this behaviour, by skipping those ReplacementSpans that
were completely included in ellipsis. Please check the bug for a more
detailed explanation.

Bug: 69802699
Test: manual testing
Test: atest FrameworksCoreTests:android.text.TextLineTest
Change-Id: If9758537948abaa0226fe6b551a703110c5457b9
2018-05-30 12:52:50 +01:00
Mihai Popa
7626c86ad7 Optimise the hit test algorithm
Layout#getOffsetForHorizontal was running in O(n^2) time, where n is the
length of the current line. The method is used when a touch event
happens on a text line, to compute the cursor offset (and the character)
where it happened. Although this is not an issue in common usecases,
where the number of characters on a line is relatively small, this can
be very inefficient as a consequence of Unicode containing 0-width
(invisible) characters. Specifically, there are characters defining the
text direction (LTR or RTL), which cause our algorithm to touch the
worst case quadratic runtime. For example, a person is able to send a
message containing a few visible characters, and also a lot of these
direction changing invisible ones. When the receiver touches the message
(causing the Layout#getOffsetForHorizontal method to be called), the
receiver's application would become not responsive.

This CL optimizes the method to run in O(n) worst case. This is achieved
by computing the measurements of all line prefixes at first, which can
be done in a single pass. Then, all the prefix measurement queries will
be answered in O(1), rather than O(n) as it was happening before.

Bug: 79215201
Test: manual testing
Change-Id: Ib66ef392c19c937718e7101f6d48fac3abe51ad0
2018-05-22 23:44:00 +00:00
Seigo Nonaka
50fe78805d Reorder the drawing of underline/stroke and text
The underline and stroke should be top of the text.
This regression happens on O-MR1 and the root cause is still unknown,
but the drawning underline/stroke should do before drawing text.

Bug: 79906191
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest

Change-Id: Idc2f99b9c0fa125af331e496da8daa326d14bfac
2018-05-21 14:56:40 -07:00
TreeHugger Robot
ff63291986 Merge "Add test cases for Layout.primaryIsTrailingPrevious" 2018-05-17 17:30:21 +00:00
Seigo Nonaka
32afe26a00 Add TextLayout.measure test cases
Bug: 78464361
Test: atest android.text.TextLineTest
Change-Id: I62e05d4fe18c115060da918a2c9105f0e94fe4b0
2018-05-16 22:20:57 -07:00
Seigo Nonaka
19e75a6a42 Add test cases for Layout.primaryIsTrailingPrevious
Bug: 78464361
Test: atest FrameworksCoreTests:android.text.LayoutTest
Change-Id: Id2735e993849bced47f9b361c99e13f91fe88070
2018-05-16 17:00:02 -07:00
Mihai Popa
a875271fcc Check against null text in TextView constructor
It is common for TextView subclasses to override the #setText method,
and there is nothing preventing the new implementations from leaving
mText and mTransformed unchanged. On the other hand, TextView assumes
mText and mTransformed will be non null at all times after the first
overridden implementations, these can remain null, causing null pointer
exceptions later.

Bug: 74411872
Test: atest FrameworksCoreTests:android.widget.TextViewTest
Test: atest FrameworksCoreTests:android.widget.TextViewActivityTest
Test: atest CtsWidgetTestCases:android.widget.cts.TextViewTest
Change-Id: Ifaddb46d156c495a371789c6f32cfd67ffaaaef2
2018-05-14 16:54:00 +01:00
Jake Wharton
fe16dfe76d Avoid internal method call and its branching.
This is a simple check that can be done locally.

Test: TextUtilsTest.java
Change-Id: I00f2a4fd087aa98ece2c3aa032e106496663b13f
2018-04-23 15:34:57 -04:00
Siyamed Sinir
5ee0f5c1d7 Merge "Update Emoji.java for emoji 11" into pi-dev 2018-04-23 18:19:22 +00:00
Abodunrinwa Toki
85767df8cf Merge "SmartLinkify - handle keyboard clicks" into pi-dev am: 686fab1464
am: f8a770a515

Change-Id: I534794c28c13fc44829427a1d4dd567fe683c6b9
2018-04-20 12:25:43 -07:00
TreeHugger Robot
686fab1464 Merge "SmartLinkify - handle keyboard clicks" into pi-dev 2018-04-20 18:44:02 +00:00
Abodunrinwa Toki
33fa382b8f SmartLinkify - handle keyboard clicks
Bug: 77998709
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Change-Id: Ibb95a736248643949a7b521368374084f9f133ca
2018-04-20 14:37:23 +01:00
Siyamed Sinir
adcb6cac12 Update Emoji.java for emoji 11
This CL removes the Emoji 5.0 info from Emoji.java since they are
supported by ICU. It adds emoji added in Emoji 11.

Test: atest android.text.EmojiTest
Test: Verified that ICU handles Emoji 5.0 emoji
Test: Verified hardware keyboard backspace with hair color emoji
Test: Visually verified cursor moves with hardware keyboard

Bug: 77148691
Change-Id: I40b290fcea201cf5e35ad4c461f8d8056b8c3739
(cherry picked from commit 213388d254)
2018-04-19 19:19:39 +00:00
Siyamed Sinir
213388d254 Update utility class Emoji.java for Emoji 11
This CL removes the Emoji 5.0 info from Emoji.java since they are
supported by ICU. It adds emoji added in Emoji 11.

Test: atest android.text.EmojiTest
Test: Verified that ICU handles Emoji 5.0 emoji
Test: Verified hardware keyboard backspace with hair color emoji
Test: Visually verified cursor moves with hardware keyboard

Bug: 77148691
Change-Id: I40b290fcea201cf5e35ad4c461f8d8056b8c3739
2018-04-13 14:00:15 -07:00
Jeff Sharkey
266ee2b1f1 Merge "Fix broken target SDK checks." into pi-dev am: aab3304a22
am: 87caa7b9ad

Change-Id: I2d0d813284e483b05bf73d5d91fcfa13bce967d8
2018-04-11 21:58:49 -07:00
Siyamed Sinir
90b3147dd8 Remove Linkify.addAsync functions
Smart Linkify changed their interface to use TextClassifier and
previously @hide addLinksAsync functions. Currently the core tests fail
and the functions are not being used.

Test: N/A
Bug: 77641809
Change-Id: Id1f595bf3e0c4d8c77da4d52e6699a8bb3117659
2018-04-11 11:51:44 -07:00
Jeff Sharkey
aa1a911d9a Fix broken target SDK checks.
Consider an app targeting the final API 28, but running on an older
build where "P" is still API 10000.  Those apps need to be treated as
legacy apps.

In general, the logical pattern that should be used when enforcing
target SDK behaviors is below.

For applying behavior to legacy apps:
    // BROKEN
    if (targetSdkVersion <= Build.VERSION_CODES.N_MR1) {
    // CORRECT
    if (targetSdkVersion < Build.VERSION_CODES.O) {

For applying behavior to new apps:
    // BROKEN
    if (targetSdkVersion > Build.VERSION_CODES.N_MR1) {
    // CORRECT
    if (targetSdkVersion >= Build.VERSION_CODES.O) {

Bug: 77865751
Test: builds, boots
Change-Id: Ia83bd446a940751d51a6542c7a5b9cca174c5296
2018-04-10 15:18:15 -06:00
Seigo Nonaka
f418d345c9 Merge "Update JNI interface of GetBounds in PrecomputedText" into pi-dev am: 42c686861c
am: 0b860336cc

Change-Id: I3462041a85b8dec647f60479e768b92a874472b9
2018-04-10 12:35:14 -07:00
TreeHugger Robot
42c686861c Merge "Update JNI interface of GetBounds in PrecomputedText" into pi-dev 2018-04-10 19:06:51 +00:00
Jeff Sharkey
7fa50c393d Merge "Offer to format data sizes in either IEC or SI." into pi-dev am: 52b4692192
am: da28d3d2e5

Change-Id: Id49d518271783b1622e89bcefd55b58c40b5b1a3
2018-04-10 08:27:39 -07:00
Jeff Sharkey
415716915e Offer to format data sizes in either IEC or SI.
Add flags to let callers specify if they want IEC (power-of-two) or
SI (power-of-ten) units when formatting bytes.

Continue using SI units by default, since certain folks seem to have
strong opinions about that.

Bug: 76159924
Test: atest android.text.format.FormatterTest
Exempt-From-Owner-Approval: previous PS approved
Change-Id: I0074bb2578c2230e938b3f39c2564b1083feb825
2018-04-09 20:23:54 -06:00
Clara Bayarri
536720ab31 Merge "Fix crash when modifying Selection" into pi-dev am: 1f2c6dea41
am: 82b8682922

Change-Id: I092f67aa3422b9a09ab969c3a2a794e62222dcc8
2018-04-09 02:48:41 -07:00
TreeHugger Robot
1f2c6dea41 Merge "Fix crash when modifying Selection" into pi-dev 2018-04-09 09:26:42 +00:00
Clara Bayarri
4e51877f5c Fix crash when modifying Selection
The root of this bug was in the fact that Selection.removeSelection
removes two spans, the start index and end index of the selection.
Each span removal triggers Editor#onSpanRemoved, which in turn tries
to set a selection. This meant that if we started with selection
(100, 120), then removeSpan(start) was called, so we had (-1, 120),
then the onSpanRemoved code tried to set a selection so set it to
(120, 120), then removeSpan(end) was called, ending up in (120, -1).

There are two stages to this fix
1. A lot of our code assumes that when either start or end selection
are larger than -1, both are valid. Therefore when we have one of them
out of sync, we crash. Fixed this assumption in all the places I found

2. We didn't have a mechanism to use FLAG_INTERMEDIATE when removing
spans, only when adding them, so this CL adds a remove with flags. This
allows us to not trigger onSpanRemoved when only one of the selection
indexes is removed.
Because this is an added method to an interface, the default just
calls the existing method. The new method is implemented in
SpannableStringInternal and SpannableStringBuilder to read
FLAG_INTERMEDIATE and avoid sending a spans changed event.
Selection.removeSelection then uses FLAG_INTERMEDIATE when removing
the first of the two selection spans.

Note that 2. would be enough to fix the current bug, but we want to
avoid other implementations of Spannable from crashing in the wild.
In general, it seems like a good idea to verify both selection indexes
are valid whenever they are used.

Bug: 72101848
Test: atest FrameworksCoreTests:SpannableStringBuilderTest
Test: atest FrameworksCoreTests:SpannableStringTest
Test: atest CtsWidgetTestCases:TextViewTest
Test: atest CtsWidgetTestCases:EditTextTest
Test: atest android.text.cts.SelectionTest (note new test as well)
Test: atest android.view.inputmethod.cts.BaseInputConnectionTest
Test: atest android.text.DynamicLayoutTest
Change-Id: I0d647fad152d0bef0f2115a46c3d17ebd8642281
2018-04-06 16:51:53 +01:00