Commit Graph

1388 Commits

Author SHA1 Message Date
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
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
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
Jan Althaus
92556299ff Merge "Add deprecation notice to Linkify MAP_ADDRESSES" into pi-dev am: 28709538fe
am: 44249c227f

Change-Id: I778ae94b99cf88ec0f6d943195f0074bdbdca5b2
2018-04-06 08:11:06 -07:00
Jan Althaus
003889a275 Add deprecation notice to Linkify MAP_ADDRESSES
Bug: 22362008
Test: N/A
Change-Id: Ib70e0cbdd8c454a96e5e75b906ace7b6f1e21cba
2018-04-05 19:04:26 +02:00
Seigo Nonaka
fb0abe1feb Update JNI interface of GetBounds in PrecomputedText
Bug: 77495049
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest

Change-Id: I54a70a91f6fba90720b702b52ed6ad430e17c87d
2018-04-04 18:25:12 +00:00
Seigo Nonaka
3a458c3fe8 Merge "Make getText hidden and getWidth/getBounds public" into pi-dev am: 3a2d4143ee
am: 88226e2e3e

Change-Id: I63df61818bef595c9d2e83c5bfe9c678471291c1
2018-04-03 09:26:38 -07:00
Seigo Nonaka
3a2d4143ee Merge "Make getText hidden and getWidth/getBounds public" into pi-dev 2018-04-03 15:54:49 +00:00
Abodunrinwa Toki
dd5bc6f127 Merge "Merge "TextClassifier API updates." into pi-dev am: bf9dfb16be" into pi-dev-plus-aosp
am: 008a5d01af

Change-Id: I4efb43ab74ac98244c6f4145855a75480e2c85b0
2018-04-02 22:20:45 +00:00
Seigo Nonaka
40a1890d31 Merge "Fills font metrics before passing to ReplacementSpan" into pi-dev am: 138148425c
am: f0a302f119

Change-Id: I30e9dfd37853001f77f655b74445d2861f05e12b
2018-04-02 21:21:59 +00:00
Seigo Nonaka
151108a2c6 Make getText hidden and getWidth/getBounds public
This is from advice from API review.
- make getText() hidden
- make getWidth()/getBounds() public.

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

Change-Id: Ic22a266a932cda60de6d8b37b8bbf5704291b953
2018-04-02 09:58:47 -07:00
TreeHugger Robot
bf9dfb16be Merge "TextClassifier API updates." into pi-dev 2018-04-02 09:08:52 +00:00
Abodunrinwa Toki
080c8542b6 TextClassifier API updates.
1. Wraps TC queries in Request objects
2. Adds create/destroyTextClassificationSession system APIs
3. Adds the session Ids to system API calls
4. Change setSignature() to setId() on result objects
5. Plumbing to make the API updates work as things currently work
6. Hide Linkify.addLinksAsync APIs

Bug: 74461129

Test: bit FrameworksCoreTests:android.view.textclassifier.TextClassificationManagerTest
Test: bit CtsViewTestCases:android.view.textclassifier.cts.TextClassificationManagerTest
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest
Test: bit FrameworksCoreTests:android.view.textclassifier.TextClassificationTest
Test: bit FrameworksCoreTests:android.view.textclassifier.TextSelectionTest
Test: bit FrameworksCoreTests:android.view.textclassifier.TextLinksTest

Change-Id: I933ada8b37ef9893331a265e3b4fc08e043f1029
2018-04-01 20:04:47 +01:00
Seigo Nonaka
0903665f97 Fills font metrics before passing to ReplacementSpan
Bug: 74518333
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest
    Change-Id: Ifbc8625882919e6498a2758433e80f059a797fd4

Change-Id: I6181fd712aae38e0bba702374e01a40ee3b522dd
2018-03-30 12:30:56 -07:00
Joshua Baxter
6f56c58c46 docs: fixed typo am: eb5d2d96ad am: 2ae75ba1ab
am: c9f1581ad6

Change-Id: Ib3001f83a15acd5ecb1c74c909e542fdd547a393
2018-03-28 03:11:21 +00:00
Joshua Baxter
2ae75ba1ab docs: fixed typo
am: eb5d2d96ad

Change-Id: I60e1befd90c14fe0ef6b3b8813bb2a791f8a7399
2018-03-28 00:33:50 +00:00
Joshua Baxter
eb5d2d96ad docs: fixed typo
Test: make ds-docs

Bug: 36944055
Change-Id: I52c6d6404340ada5a18b99fd37a2f1d75af00677
2018-03-27 10:28:05 -07:00
Abodunrinwa Toki
b1b18064eb Merge "Fix random SmartLinkify-related TextView bugs." into pi-dev am: d982f561cc
am: 62c135418d

Change-Id: Ibf482b7f40eb99ea53d9ed7187beeed0e7ff8195
2018-03-27 00:18:34 +00:00
TreeHugger Robot
d982f561cc Merge "Fix random SmartLinkify-related TextView bugs." into pi-dev 2018-03-26 23:21:37 +00:00
Abodunrinwa Toki
520969191b Fix random SmartLinkify-related TextView bugs.
1. Preserve selection when the TC times out. (See: SelectionActionModeHelper)

2. Fix highlight/toolbar flicker when tapping on a smart link.
   - Highlight flicker happening because we reset the selection while in
     the process of starting a link action mode.
     i.e. onLinkDown: show highlight
          onLinkUp: start the link action mode asynchronously
	  onLinkUp: reset the selection to an insertion cursor*
	  onLinkActionModeStarted: reset the highlight
	  *Fix: Don't reset selection while starting a link action mode.
   - Toolbar flicker happening because the toolbar positions itself over
     the current selection. The way link highlights have traditionally
     been done is to set the selection to the links bounds*
     *Fix: Hide the toolbar for a few milliseconds when changing
     selection for smoother transition.

3. Fix Paste menu overriding link action mode toolbar after a recent
   "Copy" action. The Paste menu appearing is a feature. Whenever the
   user inserts a cursor after just copying some text, we show the Paste
   menu as a way to make it easy for the user to select the text.
   Because of the problem described in (2) above, changing the selection
   to an insertion triggers the Paste menu feature. Fixing (2) fixes
   this.

4. Fix IME popping up on non-selectable + focusable TextViews.
   See: imm.showSoftInput(...) in Editor. And see comment in the code
   around that. We should only pop up the IME for editable text.

Fixes: 73872461
Fixes: 75985239
Fixes: 76011461

Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest
Change-Id: If9ddb7f4e6d4db480ba4a495a22f7f2924ab937e
2018-03-26 18:11:03 +01:00
Seigo Nonaka
f6be26ca20 Merge "Fix BoringLayout with PrecomputedText" into pi-dev am: 5dbb3fe124
am: 18f36b076d

Change-Id: Idb0a74af56294eb8eb4efd26575bad92a6a4870e
2018-03-24 21:34:22 +00:00
Seigo Nonaka
53145635e4 Fix BoringLayout with PrecomputedText
The special logic for PrecomputedText in BoringLayout has problem.
The special logic is no longer necessary since TextLine is now aware of
PrecomputedText. So, just removing special logic from BoringLayout.

On the other hand, the metrics parameters check in TextLine has removed
Ie73bce52c6c673cda58973ddad04627a7cf2e5e9, but that was wrong. TextLine
can be used by BoringLayout too. Thus, need to reject PrecomputedText
if the given TextPaint is not compatible with given param.

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

Change-Id: I172b5f655402e797b53b9667b49cb4ab89ec0dc0
2018-03-23 18:19:06 -07:00
Seigo Nonaka
284a0ae76b Merge "Make PrecomputedText Spannable for supporting selection" into pi-dev am: 02c8d1b07f
am: 42033475dd

Change-Id: Ibac099cd1256e4a87299196dcfeda8d50c900197
2018-03-23 03:34:31 +00:00
Abodunrinwa Toki
80f5725d1e Merge "Fix smart_linkify_enabled flag." into pi-dev am: e9a7cb8158
am: 27d8cf774a

Change-Id: I4d0c13b480cdd0f2fa134716575e86630a7e90d4
2018-03-23 02:31:56 +00:00
TreeHugger Robot
02c8d1b07f Merge "Make PrecomputedText Spannable for supporting selection" into pi-dev 2018-03-22 23:21:54 +00:00
TreeHugger Robot
e9a7cb8158 Merge "Fix smart_linkify_enabled flag." into pi-dev 2018-03-22 22:56:58 +00:00
Abodunrinwa Toki
6563833cf3 Fix smart_linkify_enabled flag.
The flag should only ensure that smart linkify calls behave in the
legacy way instead of totally disabling linkify.
Also, to keep the flag consistent with smart_selection_enabled and
smart_text_share_enabled flags, the flag should only disable the
SmartLinkify (i.e. Linkify.addLinksAsync) feature not TextClassifier
APIs (i.e. TextClassifier.generateLinks).

Also fixes issue with non-focusable TextViews by firing the primary
action instead of showing the floating toolbar. (b/73156794)

Bug: 75967597
Bug: 73156794
Test: bit FrameworksCoreTests:android.text.util.LinkifyTest
Test: bit CtsTextTestCases:android.text.util.cts.LinkifyTest
Test: bit FrameworksCoreTests:android.view.textclassifier.TextClassificationManagerTest
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest
Test: manual - checked behaviour turning flag on/off
Test: manual - checked behaviour with TextView.setFocusableInTouchMode(true/false)
Change-Id: I541f60161b9cd63ce7e57235607500f2fb0841e7
2018-03-22 19:25:14 +00:00
Seigo Nonaka
72fbfebcb1 Merge "Stop creating PrecomputedText in StaticLayout" into pi-dev am: be8b90b966
am: ccaf61ff44

Change-Id: I450b62679599144eb202344d464a3167a3fb2611
2018-03-21 09:26:53 +00:00
Seigo Nonaka
802064fc67 Merge "Introduce new constructor for not copying NoCopySpan" into pi-dev am: 54ff524a2b
am: 5494171dd6

Change-Id: I1268e1848dd6247b170f12549193562e886e0efa
2018-03-21 05:54:01 +00:00
Seigo Nonaka
a553477ddf Make PrecomputedText Spannable for supporting selection
This is 2nd attempt of I072dfd70b9a687d9c47e310d8cdb34f988fbb32e

The root cause of crashing is unexpected copying of NoCopySpan by
SpannableString constructor. To prevent crashing, stop copying
NoCopySpan by passing ignoreNoCopySpan=true to SpannableString
copy constructor.

The original commit message is following:

To support selectable TextView, make PrecomputedText spannable.
By this change, TextView start using DynamicLayout instead of
StaticLayout. DynamicLayout requires boundary rectangle of the
text, so this CL also adds getBounds method to PrecomputedText
which retrieves measured boundary box from native.

By this change, the selectable TextView performance for the
precomputed text 10x faster. On the other hand, the performacne
for the non-selectable text gets 2.5x slower. However, we concluded
that we accept this performance regression since it still 10 times
faster than non precomputed text.

Here is a precomputed text performance result of TextView.
android.widget.TextViewPrecomputedTextPerfTest:
  newLayout_PrecomputedText           :    736,130 ->  1,648,694: (+124.0%)
  newLayout_PrecomputedText_Selectable: 17,379,765 ->  1,700,146: (-90.2%)
  onDraw_PrecomputedText              :  1,274,921 ->  1,848,076: (+45.0%)
  onDraw_PrecomputedText_Selectable   : 17,367,238 ->  1,399,169: (-91.9%)
  onMeasure_PrecomputedText           :    752,875 ->  1,766,606: (+134.6%)
  onMeasure_PrecomputedText_Selectable: 17,647,842 ->  1,810,704: (-89.7%)
  setText_PrecomputedText             :     92,894 ->    135,471: (+45.8%)
  setText_PrecomputedText_Selectable  :    145,134 ->    215,757: (+48.7%)

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

Change-Id: Ie98c75d8b4ba962eaf0a544357b2ff1ade891118
2018-03-20 22:22:30 -07:00
Seigo Nonaka
c3328d648e Stop creating PrecomputedText in StaticLayout
No performance regressions are expected

android.text.PrecomputedTextPerfTest:
  create NoStyled Hyphenation                  : 17,849,966 -> 17,858,570: (+0.0%)
  create NoStyled Hyphenation WidthOnly        : 17,814,338 -> 17,801,205: (-0.1%)
  create NoStyled NoHyphenation                :  7,123,449 ->  7,068,308: (-0.8%)
  create NoStyled NoHyphenation WidthOnly      :  7,108,169 ->  7,074,908: (-0.5%)
  create Styled Hyphenation                    : 12,179,203 -> 12,131,020: (-0.4%)
  create Styled Hyphenation WidthOnly          : 12,112,347 -> 12,241,311: (+1.1%)
  create Styled NoHyphenation                  : 11,870,126 -> 11,880,442: (+0.1%)
  create Styled NoHyphenation WidthOnly        : 11,836,742 -> 11,860,292: (+0.2%)

android.text.StaticLayoutPerfTest:
  create PrecomputedText Balanced Hyphenation  :    697,713 ->    691,148: (-0.9%)
  create PrecomputedText Balanced NoHyphenation:    517,113 ->    498,106: (-3.7%)
  create PrecomputedText Greedy Hyphenation    :    468,243 ->    455,015: (-2.8%)
  create PrecomputedText Greedy NoHyphenation  :    479,514 ->    461,617: (-3.7%)
  create RandomText Balanced Hyphenation       : 17,183,044 -> 17,049,811: (-0.8%)
  create RandomText Balanced NoHyphenation     :  7,183,745 ->  7,025,070: (-2.2%)
  create RandomText Greedy Hyphenation         :  7,130,841 ->  6,995,785: (-1.9%)
  create RandomText Greedy NoHyphenation       :  7,122,398 ->  7,037,074: (-1.2%)

  draw PrecomputedText NoStyled                :    520,306 ->    551,465: (+6.0%)
  draw PrecomputedText NoStyled WithoutCache   :    545,773 ->    566,956: (+3.9%)
  draw PrecomputedText Styled                  :    826,044 ->    838,979: (+1.6%)
  draw PrecomputedText Styled WithoutCache     :    829,958 ->    841,749: (+1.4%)
  draw RandomText NoStyled                     :    537,079 ->    545,428: (+1.6%)
  draw RandomText NoStyled WithoutCache        :  6,473,166 ->  6,445,194: (-0.4%)
  draw RandomText Styled                       :    995,033 ->  1,015,913: (+2.1%)
  draw RandomText Styled WithoutCache          :  2,725,313 ->  2,770,604: (+1.7%)

android.widget.TextViewPrecomputedTextPerfTest:
  newLayout PrecomputedText                    :    754,311 ->    718,130: (-4.8%)
  newLayout PrecomputedText Selectable         : 17,716,239 -> 17,484,046: (-1.3%)
  newLayout RandomText                         : 16,657,952 -> 16,511,625: (-0.9%)
  newLayout RandomText Selectable              : 17,675,222 -> 17,520,653: (-0.9%)
  onDraw PrecomputedText                       :  1,307,123 ->  1,280,009: (-2.1%)
  onDraw PrecomputedText Selectable            : 17,613,031 -> 17,404,379: (-1.2%)
  onDraw RandomText                            : 17,369,256 -> 17,295,363: (-0.4%)
  onDraw RandomText Selectable                 : 18,207,392 -> 18,077,660: (-0.7%)
  onMeasure PrecomputedText                    :    748,537 ->    739,128: (-1.3%)
  onMeasure PrecomputedText Selectable         : 17,842,953 -> 17,784,459: (-0.3%)
  onMeasure RandomText                         : 16,633,454 -> 16,549,182: (-0.5%)
  onMeasure RandomText Selectable              : 18,022,286 -> 17,873,919: (-0.8%)
  setText PrecomputedText                      :    120,769 ->    119,496: (-1.1%)
  setText PrecomputedText Selectable           :    162,411 ->    150,809: (-7.1%)
  setText RandomText                           :     11,096 ->     10,956: (-1.3%)
  setText RandomText Selectable                :     48,852 ->     48,593: (-0.5%)

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

Change-Id: I3af758ecc5a15975c4e59c6378faf7c14c3bd65b
2018-03-20 18:57:38 -07:00
Seigo Nonaka
3483bc7d64 Introduce new constructor for not copying NoCopySpan
To hold the original text in PrecomputedText, need to create
SpannableString, but copying NoCopySpan causes some side effect.
This CL introduces a way of copying SpannableString/SpannedString
with all spans other than NoCopySpan.

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

Change-Id: I20dea2114ccaa54b16ff679c97682a5003f9a4c1
2018-03-20 14:33:35 -07:00
Seigo Nonaka
8d2084e84c Merge "Revert "Make PrecomputedText Spannable for supporting selection"" into pi-dev am: b3aec698e8
am: efd7a037d0

Change-Id: I4abfd9ade6928106f21a598dd33ab5be5e86d1b8
2018-03-19 22:28:28 +00:00
Seigo Nonaka
e887f4d2c1 Revert "Make PrecomputedText Spannable for supporting selection"
Crash on Sheets APp
This reverts commit 80ed5a35a9.

Bug: 75652829
Change-Id: I40ddd1b9754e74fbd90d7a029cce9c6a7ede0777
Test: Manual
2018-03-19 17:04:30 +00:00
Seigo Nonaka
35570276db Merge "Make PrecomputedText Spannable for supporting selection" into pi-dev am: 71ed54f377
am: b8293dee84

Change-Id: Id9e287da1a41e2088f2cdd91ac4305b910789a84
2018-03-16 16:35:55 +00:00
Seigo Nonaka
80ed5a35a9 Make PrecomputedText Spannable for supporting selection
To support selectable TextView, make PrecomputedText spannable.
By this change, TextView start using DynamicLayout instead of
StaticLayout. DynamicLayout requires boundary rectangle of the
text, so this CL also adds getBounds method to PrecomputedText
which retrieves measured boundary box from native.

By this change, the selectable TextView performance for the
precomputed text 10x faster. On the other hand, the performacne
for the non-selectable text gets 2.5x slower. However, we concluded
that we accept this performance regression since it still 10 times
faster than non precomputed text.

Here is a precomputed text performance result of TextView.
android.widget.TextViewPrecomputedTextPerfTest:
  newLayout_PrecomputedText                             :    736,130 ->  1,648,694: (+124.0%)
  newLayout_PrecomputedText_Selectable                  : 17,379,765 ->  1,700,146: (-90.2%)
  onDraw_PrecomputedText                                :  1,274,921 ->  1,848,076: (+45.0%)
  onDraw_PrecomputedText_Selectable                     : 17,367,238 ->  1,399,169: (-91.9%)
  onMeasure_PrecomputedText                             :    752,875 ->  1,766,606: (+134.6%)
  onMeasure_PrecomputedText_Selectable                  : 17,647,842 ->  1,810,704: (-89.7%)
  setText_PrecomputedText                               :     92,894 ->    135,471: (+45.8%)
  setText_PrecomputedText_Selectable                    :    145,134 ->    215,757: (+48.7%)

Verified no effects for other performance metrics:
android.widget.TextViewPrecomputedTextPerfTest:
  newLayout_RandomText                                  : 16,495,200 -> 16,450,483: (-0.3%)
  newLayout_RandomText_Selectable                       : 17,482,439 -> 17,534,207: (+0.3%)
  onDraw_RandomText                                     : 17,224,949 -> 17,228,072: (+0.0%)
  onDraw_RandomText_Selectable                          : 18,067,397 -> 17,958,235: (-0.6%)
  onMeasure_RandomText                                  : 16,435,649 -> 16,516,352: (+0.5%)
  onMeasure_RandomText_Selectable                       : 17,724,819 -> 17,879,508: (+0.9%)
  setText_RandomText                                    :     11,130 ->     11,259: (+1.2%)
  setText_RandomText_Selectable                         :     48,900 ->     48,607: (-0.6%)

android.text.PrecomputedTextPerfTest:
  create_NoStyled_Hyphenation                           : 17,695,377 -> 17,660,233: (-0.2%)
  create_NoStyled_Hyphenation_WidthOnly                 : 17,677,423 -> 17,541,823: (-0.8%)
  create_NoStyled_NoHyphenation                         :  7,021,486 ->  7,030,069: (+0.1%)
  create_NoStyled_NoHyphenation_WidthOnly               :  7,045,453 ->  7,067,021: (+0.3%)
  create_Styled_Hyphenation                             : 12,090,933 -> 12,267,730: (+1.5%)
  create_Styled_Hyphenation_WidthOnly                   : 12,105,491 -> 12,277,272: (+1.4%)
  create_Styled_NoHyphenation                           : 11,835,249 -> 11,960,278: (+1.1%)
  create_Styled_NoHyphenation_WidthOnly                 : 11,871,765 -> 11,912,444: (+0.3%)

android.text.StaticLayoutPerfTest:
  create_PrecomputedText_NoStyled_Balanced_Hyphenation  :    709,839 ->    697,134: (-1.8%)
  create_PrecomputedText_NoStyled_Balanced_NoHyphenation:    527,671 ->    528,928: (+0.2%)
  create_PrecomputedText_NoStyled_Greedy_Hyphenation    :    477,259 ->    481,966: (+1.0%)
  create_PrecomputedText_NoStyled_Greedy_NoHyphenation  :    479,772 ->    482,278: (+0.5%)
  create_PrecomputedText_Styled_Greedy_NoHyphenation    :    639,322 ->    637,790: (-0.2%)
  create_RandomText_NoStyled_Balanced_Hyphenation       : 17,123,681 -> 16,989,227: (-0.8%)
  create_RandomText_NoStyled_Balanced_NoHyphenation     :  7,040,572 ->  7,064,175: (+0.3%)
  create_RandomText_NoStyled_Greedy_Hyphenation         :  7,000,681 ->  7,002,322: (+0.0%)
  create_RandomText_NoStyled_Greedy_NoHyphenation       :  6,997,115 ->  6,996,953: (-0.0%)
  create_RandomText_Styled_Greedy_NoHyphenation         : 11,948,744 -> 12,052,791: (+0.9%)
  draw_PrecomputedText_NoStyled                         :    543,623 ->    513,741: (-5.5%)
  draw_PrecomputedText_NoStyled_WithoutCache            :    564,742 ->    541,795: (-4.1%)
  draw_PrecomputedText_Styled                           :    838,581 ->    837,438: (-0.1%)
  draw_PrecomputedText_Styled_WithoutCache              :    826,775 ->    850,586: (+2.9%)
  draw_RandomText_NoStyled                              :    538,162 ->    533,603: (-0.8%)
  draw_RandomText_NoStyled_WithoutCache                 :  6,401,486 ->  6,424,604: (+0.4%)
  draw_RandomText_Styled                                :  1,024,683 ->  1,011,575: (-1.3%)
  draw_RandomText_Styled_WithoutCache                   :  2,733,204 ->  2,722,828: (-0.4%)

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

Change-Id: I072dfd70b9a687d9c47e310d8cdb34f988fbb32e
2018-03-15 14:09:08 -07:00
Siyamed Sinir
70ffd28d57 Fix StaticLayout maxLineHeight warning
Test: atest cts/tests/tests/widget/src/android/widget/cts/TextViewTest.java
Test: atest cts/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
Test: atest frameworks/base/core/tests/coretests/src/android/text/StaticLayoutTest.java
Test: Visual inspection on apk’s provided in b/28988744#3

Bug: 67678695
Change-Id: Ia2de14bc06022fd963b6cc677404906efbe8b70a
2018-03-08 17:20:58 -08:00
Seigo Nonaka
e1ffb54167 Throw an exception in case of parameter mismatch of precomputed text
If the given precomputed text is not compatible with the TextView,
reject the text by throwing IllegalArgumentException.

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

Change-Id: I4fbf89a5f1409e8eefdeb9f208f9a3758220fe1a
(cherry picked from commit 3a0787af5e)
2018-03-07 18:30:27 +00:00