Commit Graph

1325 Commits

Author SHA1 Message Date
Jeff Sharkey
ad357d1839 Pass in the user defined by Context.
The majority of Manager-style classes already use Context.getUserId()
when making calls into the OS, so clean up the remaining callers to
unify behind this strategy.

This gives @SystemApi developers a nice clean interface to interact
across user boundaries, instead of manually adding "AsUser" or
"ForUser" method variants, which would quickly become unsustainable.

Test: builds, boots
Bug: 72863821
Exempt-From-Owner-Approval: trivial changes
Change-Id: Ib772ec4438e57a2ad4950821b9432f9842998451
2018-02-03 02:11:45 +00:00
TreeHugger Robot
85d8a99310 Merge "Updating more spans" 2018-02-02 00:26:48 +00:00
Florina Muntenescu
139e1b5c01 Updating more spans
Test: N/A
Bug: 72092996
Change-Id: Iecd3595a03cde2a1d58e4be00b7cf9b6783d4e2a
2018-01-31 18:25:02 +00:00
Abodunrinwa Toki
fe20cdd910 Smart Linkify API
Uses the TextClassifier to generate links on a background thread.
The links are applied on the calling thread.

Test: see topic
Bug: 67629726
Change-Id: I0f1940a2ffbf19f4436c0a20b0c62e6bbc03cd7a
2018-01-31 09:42:36 +00:00
David Ogutu
321ef3a5af Merge "Fix TimePicker separator l10n issue." 2018-01-30 20:57:58 +00:00
David Ogutu
628bb61c30 Fix TimePicker separator l10n issue.
This was surfacing in the android clock with certain locales e.g. fr_CA.
Fixed for all unqiue locale patterns.

Bug: 71572309
Test: manual - changed locale to Fr_CA and made sure clock seperator WAI
Test: atest CtsWidgetTestCases:TextViewTest CtsWidgetTestCases:EditTextTest CtsWidgetTestCases:TextViewFadingEdgeTest FrameworksCoreTests:TextViewFallbackLineSpacingTest FrameworksCoreTests:TextViewTest

Change-Id: Ie43bf9428e8c5ef2fe2e9545cb5a6dada25d6e52
2018-01-30 12:44:45 -05:00
TreeHugger Robot
ea3ca9d720 Merge "Introduce MeasuredText related perf tests" 2018-01-29 19:30:42 +00:00
Florina Muntenescu
8ec69a628b Merge "Making QuoteSpan more flexible." 2018-01-26 03:19:11 +00:00
Florina Muntenescu
ea27314e38 Merge "Update JavaDocs for Alignment, Clickable, Editable and MetricAffecting spans." 2018-01-26 03:18:46 +00:00
Seigo Nonaka
49ca0244c9 Introduce MeasuredText related perf tests
This CL adds two perf test for MeasuredText: the memory usage and
construction time of MeasuredText.

Here is an example output on walleye-userdebug:

Memory Usage (in bytes)
Hyphenation            :    28,448
Hyphenation WidthOnly  :     8,856
NoHyphenation          :    27,592
NoHyphenation WidthOnly:     8,000

MeasuredText creation time
NoStyled Hyphenation            : 18,977,877
NoStyled Hyphenation WidthOnly  : 18,510,041
NoStyled NoHyphenation          :  7,771,936
NoStyled NoHyphenation WidthOnly:  7,332,537
Styled Hyphenation              : 13,514,428
Styled Hyphenation WidthOnly    : 12,446,143
Styled NoHyphenation            : 13,370,358
Styled NoHyphenation WidthOnly  : 13,582,435

Bug: 72461923
Bug: 72462192
Test: See above

Change-Id: I7d326a9e70a29c38c940e0085da2bc4edf2a098a
2018-01-25 10:41:26 -08:00
Florina Muntenescu
58414a4867 Update JavaDocs for Alignment, Clickable, Editable and MetricAffecting
spans.

Test: N/A
Bug: 72092996
Change-Id: I716ed3841d7ac0b1cc2f75021ae0e02d1bf05524
2018-01-25 09:06:28 +00:00
Florina Muntenescu
f58a0282a9 Making QuoteSpan more flexible.
Test: QuoteSpanTest
Bug: 72410257
Change-Id: Ie0e159b4f645b7935454ad25fd43c5d0e8f3d7c1
2018-01-25 08:50:49 +00:00
TreeHugger Robot
ab802003b9 Merge "Compute full text layout in MeasuredText and use it for drawing" 2018-01-24 22:07:13 +00:00
Siyamed Sinir
1a5648a2cd Revert "Make ellipsize retry if text doesn't fit"
This reverts commit e88b5df5b7.

Test: bit FrameworksCoreTests:android.text.StaticLayoutTest
Test: bit FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit FrameworksCoreTests:android.text.TextUtilsTest
Test: bit CtsTextTestCases:*
Test: atest FilesActivityUiTest

Bug: 71599479
Bug: 31537595
Bug: 64156587

Change-Id: I1afa77a4b90b9b822b409a3f4721c45d0c0a6664
2018-01-23 18:25:36 -08:00
Seigo Nonaka
783f961d2f Compute full text layout in MeasuredText and use it for drawing
The full layout is required for drawing text on UI thread.
To save this work, store the full layout result in MeasuredText and
compose the final layout from stored full layout if possible.

Currently justification/hyphenation is not supported but works normally
as before. Nothing changes on existing non measured text.

StaticLayout creation time for no style text (w/o patch -> w/ patch, N=30)
  MeasuredText Balanced Hyphenation  :    721,297 ->    720,657: (-0.1%)
  MeasuredText Balanced NoHyphenation:    550,588 ->    546,069: (-0.8%)
  MeasuredText Greedy Hyphenation    :    503,582 ->    498,009: (-1.1%)
  MeasuredText Greedy NoHyphenation  :    502,344 ->    498,507: (-0.8%)
  RandomText Balanced Hyphenation    : 19,351,802 -> 19,176,024: (-0.9%)
  RandomText Balanced NoHyphenation  :  8,033,830 ->  7,973,336: (-0.8%)
  RandomText Greedy Hyphenation      :  7,957,335 ->  7,927,316: (-0.4%)
  RandomText Greedy NoHyphenation    :  7,988,884 ->  7,929,717: (-0.7%)

StaticLayout.draw time for no style text (w/o patch -> w/ patch, N=30)
  MeasuredText NoStyled              :    644,453 ->    660,684: (+2.5%)
  MeasuredText NoStyled WithoutCache :  9,251,919 ->    648,992: (-93.0%)
  MeasuredText Styled                :  3,092,353 ->    870,702: (-71.8%)
  MeasuredText Styled WithoutCache   : 12,544,014 ->  1,114,557: (-91.1%)
  RandomText NoStyled                :    582,167 ->    572,092: (-1.7%)
  RandomText NoStyled WithoutCache   :  9,167,670 ->  9,056,447: (-1.2%)
  RandomText Styled                  :  3,064,490 ->  3,029,028: (-1.2%)
  RandomText Styled WithoutCache     : 12,314,863 -> 12,283,026: (-0.3%)

Test: minikin_test
Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit FrameworksCoreTests:android.text.MeasuredParagraphTest
Bug: 63897135

Change-Id: I7e6ec5c953d7d0f767aba4f61f94e62b6f3a3a2b
2018-01-23 17:45:55 -08:00
TreeHugger Robot
414b665f2d Merge "Make BulletSpan more flexible and update JavaDoc." 2018-01-23 13:57:29 +00:00
Florina Muntenescu
987189b936 Make BulletSpan more flexible and update JavaDoc.
Test: BulletSpanTest
Bug: 72217003
Change-Id: I0ba4d93bd5a7bac02410e0edbd4b20f254959d4e
2018-01-23 12:08:39 +00:00
Florina Muntenescu
6d0474944a Updating JavaDocs for more spans.
Test: N/A
Bug:72092996
Change-Id: I2706465d3d61117b0b5b9e6a013f213988c92521
2018-01-22 18:40:50 +00:00
TreeHugger Robot
f74e56af8c Merge "Update JavaDoc for BackgroundColorSpan and ForegroundColorSpan." 2018-01-20 01:00:54 +00:00
Florina Muntenescu
6e6772ff03 Update JavaDoc for BackgroundColorSpan and ForegroundColorSpan.
Test: N/A
Bug: 72092996
Change-Id: Iec7f378557759e2fdd2969f579e1dfd4635b123a
2018-01-19 17:52:31 +00:00
TreeHugger Robot
881a432d08 Merge "Compute hyphenated word pieces in MeasuredText" 2018-01-18 20:32:54 +00:00
Seigo Nonaka
87b1547c92 Compute hyphenated word pieces in MeasuredText
Bug: 67504091
Test: bit CtsTextTestCases:*
Change-Id: Id1ff5abbf6d433a2d8baad364133fca98d1fe450
2018-01-18 18:30:02 +00:00
Neil Fuller
dd704e316b Merge "Javadoc fixes to Time" am: b3c2efc615 am: b51c638a6c
am: 90a56a59d5

Change-Id: I62545bdd0604ee0911249abd7628c99868093c77
2018-01-18 10:40:42 +00:00
Neil Fuller
3d3d7f1a8d Javadoc fixes to Time
Fixing errors noticed while inspecting the code.

Test: None - docs only
Change-Id: Ib6d427c4339f0b8e56eb72b12e89c1095245d6b4
2018-01-17 21:13:21 +00:00
Seigo Nonaka
9d3bd08eba Rename PremeasuredText to MeasuredText
There is already MeasuredText, so renamed existing MeasuredText to
MeasuredParagraph, then renamed PremeasuredText to MeasuredText.

Bug: 67504091
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit CtsTextTestCases:*
Change-Id: Ie20bea9501b18fabb36f64d388a7851c4643d4c3
2018-01-11 11:33:32 -08:00
Siyamed Sinir
1fb80bbc94 Prevent crash for Span change events
For some spans, SpannableStringBuilder cannot determine the previous
start and previous end values correctly. In some cases, previous end
value is smaller than previous start value, and this causes
DynamicLayout to access negative index values. This CL updates
DynamicLayout to reflow from index 0 if such a case occurs.

Test: Added a CTS test
Test: bit CtsTextTestCases:android.text.cts.DynamicLayoutTest#testReflow_afterSpanChangedShouldNotThrowException

Bug: 67926915
Change-Id: Ibc55edfd5e49a7782cdd807e2465f4f21577b68d
2018-01-08 13:57:59 -08:00
Victor Chang
d990345d8b Revert "Switch file size formatters to use ICU's MeasureFormat"
This reverts commit 4e5b71f084.

Test: cts-tradefed run cts-dev -m CtsTextTestCases
Bug: 70005649
Bug: 36994779
Change-Id: Ie9a2fd786d48e2a6c291e313cbb4072c7306af9f
2018-01-03 14:31:47 +00:00
Victor Chang
3305bce79d Revert "Remove use of MeasureUnit.internalGetInstance"
This reverts commit aa5629e608.

Test: m
Bug: 70005649
Bug: 36994779
Change-Id: I4591870f564567c40fa450866c3050fd5a7a61ae
2018-01-03 14:31:34 +00:00
TreeHugger Robot
df392c9a1d Merge "Deprecate StaticLayout and DynamicLayout constructors" 2017-12-20 11:58:32 +00:00
Siyamed Sinir
f7314652ed Merge "Add OWNERS for text related classes" 2017-12-19 20:08:56 +00:00
Clara Bayarri
81a4f2e89d Deprecate StaticLayout and DynamicLayout constructors
The Builders should be used instead.
Also remove a StaticLayout constructor only used in tests in favor
of the Builder.

Bug: 64985428
Test: adb shell am instrument -w -e class android.text.StaticLayoutTest com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Change-Id: Ief6839d2c6bb0969bdeb30359eae00d38a2bdb09
2017-12-19 16:46:56 +00:00
Siyamed Sinir
50b585e20c Fix DynamicLayout block index calculation after edit
DynamicLayout made wrong adjustments to the block indices set to be
redrawn. Every indice after the first change was being added the
diff count in the blocks. However this meant when there are 2 deletes
and an index as 1, it would become -1 (wrong array index). The change
should be applied to indices outside of [firstBlock, lastBlock].

Test: Added android.text.DynamicLayoutTest#testReflow_afterSpannableEdit
Test: bit FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit FrameworksCoreTests:android.text.DynamicLayoutBlocksTest
Test: bit CtsTextTestCases:android.text.cts.DynamicLayoutTest

Bug: 67405337
Change-Id: Ie5e5658ffca4293f32f7b574d22d307e9e8d52dc
2017-12-18 23:32:50 -08:00
Siyamed Sinir
198e309394 Add OWNERS for text related classes
Test: None
Change-Id: Ieacd6b7e91665c7f17ab7e9308d0533f6dc5663e
2017-12-18 18:04:30 -08:00
Jeff Sharkey
ce8db99114 Add more IntDef prefixes for auto-documenting.
Test: builds, boots
Bug: 70177949
Exempt-From-Owner-Approval: annotation-only changes
Change-Id: I76dde6054e06f52240bd4b1a0f196dcb74623608
2017-12-13 20:05:36 -07:00
Seigo Nonaka
fbe63bddd6 Introduce PremeasuredText
By measuring the character widths beforehand, we can save at least 40%
of the StaticLayout construction time which typically happens on UI
thread.
Also verified this doesn't cause performance regression for not
premeasured text.

Raw performance score (Not premeasured -> premeasured, median, N=100)

No Style,   Greedy, Hyphenation OFF:  7,812,975 ->    503,245 (-93.6%)
No Style, Balanced, Hyphenation OFF:  7,843,254 ->    396,892 (-95.0%)

No Style,   Greedy, Hyphenation ON : 19,134,214 -> 11,658,928 (-39.1%)
No Style, Balanced, Hyphenation ON : 19,348,062 -> 11,634,942 (-39.9%)

Styled,     Greedy, Hyphenation OFF: 14,353,673 ->    572,840 (-96.0%)

Raw performance score (w/o patch -> w/ patch, median, N=100):

No Style,   Greedy, Hyphenation OFF:  7,732,894 ->  7,812,975 (+1.04%)
No Style, Balanced, Hyphenation OFF:  7,884,510 ->  7,843,254 (-0.52%)

No Style,   Greedy, Hyphenation ON : 18,986,958 -> 19,134,214 (+0.78%)
No Style, Balanced, Hyphenation ON : 19,232,791 -> 19,348,062 (+0.60%)

Styled,     Greedy, Hyphenation OFF: 14,319,690 -> 14,353,673 (+0.24%)

Bug: 67504091
Test: bit CtsTextTestCases:*
Test: bit CtsGraphicsTestCases:*
Test: bit CtsWidgetTestCases:*
Test: FrameworksCoreTests:android.text.MeasuredTextTest
Change-Id: I0b46f04b42cc012606a9c722eca0d51147a0dcc7
2017-12-11 18:55:12 -08:00
Seigo Nonaka
4b6bceec36 Fix testCursorIsOnRight test case
This is partial revert of Ie932903845645e50cfa0cb428babb31a44babc47

The root cause is MeasuredText.getParagraphDir respect requsted text
direction even if it is an empty text. Ideally we don't need to create
MeasuredText object for empty string but for safety, reverted to the
original code.

Bug: 70384435
Test: bit FrameworksCoreTests:android.widget.EditorCursorTest
Change-Id: Id24405f476c50fa27743589a640281d96de1c9ce
2017-12-11 12:26:13 -08:00
Seigo Nonaka
6f1868b813 Associate native MeasuredText with Java one.
To measure text beforehand, remove static layout dependency from
MeasuredText. Now MeasuredText can compute native measured text
by itself and StaticLayout use it for line breaking.

This CL introduce one additional JNI method call per paragraph during
line breaking but looks negligible cost.

Here is a raw performance test result on walleye-userdebug.

StaticLayoutPerfTest (median, N=100):
createRandom:          7,879,440 -> 7,964,789 (+1.08%)
createRandom Balanced: 7,835,192 -> 7,848,151 (+0.17%)

TextViewOnMeasurePerfTest (median, N=100):
measure_AtMost:       92,599,175 ->  93,027,121 (+0.47%)
measure_Exactly:      89,949,922 ->  90,439,886 (+0.54%)
measure_Unspecified: 148,645,916 -> 150,047,694 (+0.94%)

Bug: 67504091
Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:*
Test: bit CtsGraphicsTestCases:*
Test: bit FrameworksCoreTests:android.text.StaticLayoutTest
Change-Id: Ie932903845645e50cfa0cb428babb31a44babc47
2017-12-05 14:56:06 -08:00
Seigo Nonaka
f1644f735d Refactor MeasuredText
This is 2nd attempt of I58d3020a3fa560d05576e18888fbfe46e2975e8f

The root cause of the crash is passing end offset instead of passing
length. This CL contains that fix and also has a test case for that.

This refactoring contains:
- Add lots of comments.
- Mark private the internal fields and introduce accessors and helper
  methods.
- Factor out the auto grow array implementation to another class.
- Use SynchronizedPool for pool implementation.
- Introduce three build methods for each use case.
- Hide addStyleRun and compute all necessary informations in build method.

Locally verified that this doesn't cause performance regressions.
Here is a raw performance test result on walleye-userdebug.

StaticLayoutPerfTest (median, N=100):
createRandom:          7,846,449 -> 8,003,903 (+2.01%)
createRandom Balanced: 7,810,436 -> 7,919,200 (+1.40%)

TextViewOnMeasurePerfTest (median, N=100):
measure_AtMost:       94,276,376 ->  94,124,658 (-0.16%)
measure_Exactly:      91,629,352 ->  91,617,639 (-0.01%)
measure_Unspecified: 151,006,181 -> 150,957,598 (-0.03%)

Test: bit CtsTextTestCases:*
Test: bit CtsGraphicsTestCases:*
Test: bit CtsWidgetTestCases:*
Test: bit FrameworksCoreTests:android.text.StaticLayoutTest
Bug: 65024629
Bug: 70146381
Change-Id: I772f60444d0fe87f59609977af5ef712cab3eb37
2017-12-05 14:49:53 -08:00
Seigo Nonaka
4674e642a5 Revert "Refactor MeasuredText"
This reverts commit 75492afb1b.

Reason for revert: 70146381

Change-Id: Ibb6433b5e02608326ef51cc16d8d5d8efa86beec
2017-12-04 18:25:03 +00:00
Seigo Nonaka
75492afb1b Refactor MeasuredText
This refactoring contains:
- Add lots of comments.
- Mark private the internal fields and introduce accessors and helper
  methods.
- Factor out the auto grow array implementation to another class.
- Use SynchronizedPool for pool implementation.
- Introduce three build methods for each use case.
- Hide addStyleRun and compute all necessary informations in build method.

Locally verified that this doesn't cause performance regressions.
Here is a raw performance test result on walleye-userdebug.

StaticLayoutPerfTest (median, N=100):
createRandom:          7,846,449 -> 8,003,903 (+2.01%)
createRandom Balanced: 7,810,436 -> 7,919,200 (+1.40%)

TextViewOnMeasurePerfTest (median, N=100):
measure_AtMost:       94,276,376 ->  94,124,658 (-0.16%)
measure_Exactly:      91,629,352 ->  91,617,639 (-0.01%)
measure_Unspecified: 151,006,181 -> 150,957,598 (-0.03%)

Test: bit CtsTextTestCases:*
Test: bit CtsGraphicsTestCases:*
Test: bit CtsWidgetTestCases:*
Test: bit FrameworksCoreTests:android.text.StaticLayoutTest
Bug: 65024629

Change-Id: I58d3020a3fa560d05576e18888fbfe46e2975e8f
2017-11-30 10:46:30 -08:00
Roozbeh Pournader
2e97386d9d Drop the second unit from elapsed time if zero
Previously, we could get formatted strings like "1h 0min" which is
unnecessarily complex for users. Replace such cases with "1 h" if
the second unit is zero.

Fixes: 65426298
Test: bit FrameworksCoreTests:android.text.format.FormatterTest
Change-Id: I1d9828ec97f2cbfb7ce27c266a04d4c02b090d6d
2017-11-15 16:19:35 -08:00
TreeHugger Robot
0e364f64da Merge "Fix space counting for justified text" 2017-10-25 02:30:54 +00:00
Seigo Nonaka
b90e08f92e Reorganize JNI in StaticLayout
This CL reorganize the JNI strategy as follows:
- Remove nNewBuilder/nFreeBuilder.
- Make addStyleRun/addReplacementRun CriticalNative.
- Remove nSetupParagraph and pass necessary arguments to
  nComputeLineBreaks instead.

Here is a performance scores: (w/o patch -> w/ patch)

StaticLayoutPerfTest (median):
createRandom:           3,755,090 -> 3,781,394 (+0.70%)
createRandom Balanced:  3,702,837 -> 3,730,435 (+0.74%)

TextViewOnMeasurePerfTest (median):
measure_AtMost:        39,172,360 -> 35,883,014 (-8.4%)
measure_Exactly:       38,005,066 -> 34,585,052 (-9.0%)
measure_Unspecified:   67,191,780 -> 63,100,545 (-6.1%)

Bug: 65024629
Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:*
Change-Id: If9db1fdd2b03a1cf240f87322c1e852cf8085fff
2017-10-24 17:31:17 -07:00
Roozbeh Pournader
3630d0861b Fix space counting for justified text
Previously, the number of stretchable spaces in a line were
miscounted, always returning one more than the actual number. We now
count them correctly.

Also, disable NBSP as an stretchable space, since in some use cases
it should not stretch and the implementation in Minikin was broken
anyway.

Test: Manual (justified text is now properly aligned on right side)
Test: bit FrameworksCoreTests:android.text.TextLineTest
Fixes: 68009059
Bug: 68204709
Change-Id: I473415a2a51eec75377d6ffc4a9adddc2033d360
2017-10-24 16:21:51 -07:00
Roozbeh Pournader
a5511eb648 Merge "Replace JNI portion of AndroidBidi with calls to ICU4J" 2017-10-19 22:55:57 +00:00
Roozbeh Pournader
a15fd848cb Replace JNI portion of AndroidBidi with calls to ICU4J
We no longer need the native calls to ICU since we have ICU4J.

Fixes: 67786879
Test: bit FrameworksCoreTests:android.text.
Change-Id: Ib2ec93017000b4f0343756814ca388bd31457849
2017-10-19 11:20:46 -07:00
Seigo Nonaka
f90c9b6437 Move hyphenator mapping to native code.
This CL contains the following changes:
- Replace Hyphenator mapping in Java with minikin::HyphenatorMap.
- Remove locale tracking code from StaticLayout.java
- Stop creating Hyphenator pointer array in StaticLayout.

Bug: 65024629
Bug: 67319341
Test: bit CtsTextTestCases:*
Test: bit FrameworksCoreTests:android.text.
Test: bit FrameworksCoreTests:android.widget.TextViewTest
Change-Id: Ib88c8e816c70959057abe296cc434ddb70bc397a
2017-10-13 15:57:48 -07:00
Seigo Nonaka
898a319db3 Fix Catalan and Polish hyphenation.
After I7e2ece979181d12ac1adbede14995ec9b7b87d21, the special hyphenation
logic for Catalan and Policy was not working.

Bug: 65024629
Bug: 67702053
Test: N/A
Change-Id: I985253e24cf0ce4e537c01074e75054381a7816a
2017-10-11 23:21:12 +00:00
Siyamed Sinir
2d729d55aa Merge "Removed unused variables from text layout code" 2017-10-11 02:20:27 +00:00
Seigo Nonaka
2dd1a55b41 Remove nGetWidths and pass the jfloat[] as nComputeLineBreaks argument.
nGetWidths was always called just before nComputeLineBreaks. It would be
an improvement to pass the result array as the argument of
nComputeLineBreaks.

Bug: 65024629
Test: bit FrameworksCoreTests:android.text.StaticLayoutLineBreakingTest
Test: bit CtsTextTestCase:*
Test: Manually checked no regression in TextViewOnMeasurePerfTest
Test: Manually checked no regression in StaticLayoutPerfTest result
Change-Id: I566be66558a22b3a3ff79d502bebbbfec75dd065
2017-10-10 20:44:47 +00:00