Commit Graph

1228 Commits

Author SHA1 Message Date
TreeHugger Robot
b186823314 Merge "Improve TextView.onMeasure() for multiline text." 2017-08-04 19:24:01 +00:00
Seigo Nonaka
917748ef50 Improve TextView.onMeasure() for multiline text.
Previously, measures all paragraph for deciding view width.
However, in case AT_MOST measurment, we can stop calculating measure if
the measured paragraph already exceeds the upper limit.

Bug: 64389125
Test: bit CtsWidgetTestCases:*
Test: CorePerfTest. Here is a result before and after this patch.

Before:
INSTRUMENTATION_STATUS: measure_AtMost_median=50332114
INSTRUMENTATION_STATUS: measure_Exactly_median=28276317
INSTRUMENTATION_STATUS: measure_Unspecified_median=50193036

After:
INSTRUMENTATION_STATUS: measure_AtMost_median=28475187
INSTRUMENTATION_STATUS: measure_Exactly_median=26944710
INSTRUMENTATION_STATUS: measure_Unspecified_median=50880088

Change-Id: I2a39eb39817a8f845c4fa2e174a905a2d057096e
2017-08-04 17:21:06 +00:00
Roozbeh Pournader
55fd45b273 Reverse check for multi-character ellipsis
Reverse a recently-introduced incorrect check for multi-character
ellipsis in Layout.java. The check was introduced in
Id1dfdc503f87fabed2447d55ab2107eee0eccd08.

Test: bit CtsTextTestCases:*
Test: bit FrameworksCoreTests:android.text.
Change-Id: I79198be0bd202a303f8db02a235c2af3b76abf32
2017-08-03 14:01:09 -07:00
TreeHugger Robot
8eee5e31fe Merge "Revert "Make ellipsize retry if text doesn't fit"" 2017-08-03 02:22:09 +00:00
Roozbeh Pournader
7f0ebc944d Revert "Make ellipsize retry if text doesn't fit"
This reverts commit 1051bbe325.

Bug: 64312574
Change-Id: I6a3456172e22e94df30dcbe90988db8592886a78
2017-08-02 22:47:14 +00:00
Roozbeh Pournader
b8eccd82e1 Merge "Make InputFilter.AllCaps constructor reject null locales" into oc-mr1-dev am: 6e8e322ea1
am: 6359944a19

Change-Id: Ib5064f4be5fd73c76ad99547746bb1cb6534c2bd
2017-08-02 21:32:44 +00:00
Roozbeh Pournader
4e5e15a6ea Make InputFilter.AllCaps constructor reject null locales
In I021ff2a97a60396fb1b6e4940d91d3cd6ccb6196, new API for
InputFilter.AllCaps was added. It accepted null as input. This CL
changes that so null locales would be rejected.

Test: bit CtsTextTestCases:android.text.cts.InputFilter_AllCapsTest
Fixes: 64261334
Bug: 37222101

Change-Id: Ic87942c3f341f71bc3c1c833b52ea3e751461e47
2017-08-02 10:37:07 -07:00
Roozbeh Pournader
1051bbe325 Make ellipsize retry if text doesn't fit
This fixes the cases where the replacement of parts of text with
ellipsis may result in more-than-expected width of text due to
contextual width changes in the font, such as kerning or Arabic
shaping.

The calculations in TextUtils.ellipsize() and StaticLayout are fixed
to recalculate the new width and reduce it further until the text
actuall fits. BoringLayout and DynamicLayout get fixed too since
they use the other two implementations indirectly.

Also reverse a recently-introduced incorrect check for
multi-character ellipsis in Layout.java.

Fixes: 31537595
Fixes: 64156587
Test: Manual (Arabic edge cases ellipsize correctly)
Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.EditTextTest
Test: bit CtsWidgetTestCases:android.widget.cts.CheckedTextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.AutoCompleteTextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.MultiAutoCompleteTextViewTest
Test: bit FrameworksCoreTests:android.text.
Test: adb shell am instrument -w com.android.documentsui.tests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I74fdaa9bf32dc2064eeb702f7f9b78b2bb856c26
2017-08-01 17:58:30 -07:00
Siyamed Sinir
8b7053dd45 Merge "Fix EditText cursor when line spacing is set" 2017-08-01 22:37:55 +00:00
TreeHugger Robot
1c34ba15b5 Merge "Revert "Implement family fallback." DO NOT MERGE" into oc-mr1-dev 2017-08-01 17:29:35 +00:00
Roozbeh Pournader
200ae37936 Merge "Revert "Make ellipsize retry if text doesn't fit"" 2017-07-31 20:19:32 +00:00
Seigo Nonaka
296fc2e5c9 Merge "Stop font loading with restricted context." into oc-mr1-dev am: 06ba486a74
am: 0494dc5d17

Change-Id: I6b4c3c5aa52c0619967fedae5862dbf30bcfca43
2017-07-31 18:46:06 +00:00
Roozbeh Pournader
7f8dcaaac1 Revert "Make ellipsize retry if text doesn't fit"
This reverts commit 287c8d6fe9.

Bug: 64156587
Bug: 31537595
Change-Id: Ifbab89df78e79fe01881e9d203f46e656985518c
2017-07-28 21:59:29 +00:00
Siyamed Sinir
5494361c59 Merge changes from topic 'edit_text_linespacing'
* changes:
  Fix DynamicLayout last line spacing
  Fix EditText line spacing
2017-07-28 17:06:22 +00:00
Siyamed Sinir
fb0b2dc754 Fix DynamicLayout last line spacing
StaticLayout did not work as expected when there is a line ending with
'\n'. For those cases it would calculate 2 lines, but would
discard line spacing for both of them. This CL fixed that issue. Also
DynamicLayout asks StaticLayout not to add line spacing for the last
line of the text.

Test: Manual/Visual test
Test: bit -t FrameworksCoreTests:android.text.StaticLayoutTest
Test: bit -t FrameworksCoreTests:android.text.StaticLayoutTextMeasuringTest
Test: bit -t FrameworksCoreTests:android.text.StaticLayoutLineBreakingTest
Test: bit -t FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit -t FrameworksCoreTests:android.text.DynamicLayoutBlocksTest
Test: bit -t FrameworksCoreTests:android.widget.TextViewTest
Test: bit -t FrameworksCoreTests:android.widget.EditorCursorTest
Test: bit -t CtsTextTestCases:android.text.cts.StaticLayoutTest
Test: bit -t CtsTextTestCases:android.text.cts.DynamicLayoutTest
Test: bit -t CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit -t CtsWidgetTestCases:android.widget.cts.EditTextTest

Bug: 25194907
Change-Id: I0d901ecf768b25faea156b73097541da4b93d6d0
2017-07-27 14:43:25 -07:00
Seigo Nonaka
9b58ad6ce0 Stop font loading with restricted context.
Resources.getFont may load other package's font. Stop loading font
resources unless the developer allowed to do so.

Bug: 64115349
Bug: 35763094
Bug: 62813533
Test: bit CtsTextTestCases:android.text.style.cts.TextAppearanceSpanTest
Change-Id: Ifa1b57a70650ba086b38407c0ed5b4048983e7e5
2017-07-27 13:09:46 -07:00
TreeHugger Robot
f3b382150f Merge "Make ellipsize retry if text doesn't fit" 2017-07-27 03:24:35 +00:00
Roozbeh Pournader
287c8d6fe9 Make ellipsize retry if text doesn't fit
This fixes the cases where the replacement of parts of text with
ellipsis may result in more-than-expected width of text due to
contextual width changes in the font, such as kerning or Arabic
shaping.

The calculations in TextUtils.ellipsize() and StaticLayout are fixed
to recalculate the new width and reduce it further until the text
actuall fits. BoringLayout and DynamicLayout get fixed too since
they use the other two implementations indirectly.

Also reverse a recently-introduced incorrect check for
multi-character ellipsis in Layout.java.

Fixes: 31537595

Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.EditTextTest
Test: bit CtsWidgetTestCases:android.widget.cts.CheckedTextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.AutoCompleteTextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.MultiAutoCompleteTextViewTest
Test: FrameworksCoreTests:android.text.
Change-Id: I3532820e12ac45a46e28fe2f8bb17dcd0a345916
2017-07-26 18:26:01 -07:00
Siyamed Sinir
442c151b8d Fix EditText line spacing
DynamicLayout did not include the line spacing for the newly added
lines. This CL updates StaticLayout with a parameter to force addition
of line spacing to the last line, and updates DynamicLayout to use this
parameter. With this change the last line will have the line spacing
applied, and it will provide a consistent UX.

Test: Manual/Visual test
Test: bit -t FrameworksCoreTests:android.text.StaticLayoutTest
Test: bit -t FrameworksCoreTests:android.text.StaticLayoutTextMeasuringTest
Test: bit -t FrameworksCoreTests:android.text.StaticLayoutLineBreakingTest
Test: bit -t FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit -t FrameworksCoreTests:android.text.DynamicLayoutBlocksTest
Test: bit -t CtsTextTestCases:android.text.cts.StaticLayoutTest
Test: bit -t CtsTextTestCases:android.text.cts.DynamicLayoutTest

Bug: 25194907
Change-Id: I52497fbd108538729758e842072f3ce87c6bbfdd
2017-07-26 15:32:04 -07:00
Seigo Nonaka
065c59beaf Revert "Implement family fallback." DO NOT MERGE
This reverts commit 0d253e46aa.

The original CL changed Typeface internal methods and broke
TypefaceCompatApi26Impl in support library which uses reflections.
Ideally, TypefaceCompatApi26Impl must fall back to public API
implementation but due to lack of method availability check, it ended up
crashing the application.

The original patch didn't change any behaviors in MR1, so reverting
that change is the best solution for MR1.

Bug: 64033594
Change-Id: Ie86afeb1b809e57915d62c1db5a70c8d210d2354
Test: N/A
2017-07-26 22:21:14 +00:00
Siyamed Sinir
337d92e06e Fix bullet span vertical positioning
Test: bit CtsTextTestCases:android.text.style.cts.BulletSpanTest
Bug: 33138492
Change-Id: I2fd787190d7125591fb0fc823f6ead532c859829
2017-07-26 11:26:21 -07:00
Siyamed Sinir
a60b59d1cc Fix EditText cursor when line spacing is set
Test: bit FrameworksCoreTests:android.widget.TextViewTest
Test: bit FrameworksCoreTests:android.widget.EditorCursorTest
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.EditTextTest

Bug: 30870806
Change-Id: I54f014b06af328c3e9a9c4ddb5a3348a26e290c2
2017-07-26 11:12:53 -07:00
Siyamed Sinir
c94801f816 Merge "Store line extra in layouts" 2017-07-26 18:09:50 +00:00
Siyamed Sinir
d25760c660 Merge "Fix StaticLayout.mDirections array size" 2017-07-26 16:14:24 +00:00
Siyamed Sinir
af39851b2a Fix StaticLayout.mDirections array size
mLineDirections variable needs to keep a Directions object for each line
of text. Therefore at any time array of line count is required. However
currently mLineDirections is initialized and grown in the size of mLines
array, which makes the size around mColumns*line count.

This CL removes that extra allocation.

Test: Manual test to check if device boots and displays
Test: bit -t CtsTextTestCases:*
Test: bit -t FrameworksCoreTests:android.text.
Test: bit -t FrameworksCoreTests:android.widget.TextViewTest
Test: bit -t FrameworksCoreTests:android.widget.EditorCursorTest
Test: bit -t CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit -t CtsWidgetTestCases:android.widget.cts.EditTextTest

Bug: 64038460
Bug: 62889232
Change-Id: If9bda040b98efcf16c3cdcba5bc27667775ce1fc
2017-07-25 19:09:53 -07:00
Siyamed Sinir
0fa89d6f62 Store line extra in layouts
StaticLayout and Dynamic layout changes the values of line bottom and
descent according to linespacing modification attributes. This loses
information of the real line descent and bottom, which causes some
utilities not to be able to draw themselves in correct positions.
Examples are cursor drawing to the empty space, BulletSpan not being
able to vertically center itself in the line, and DynamicLayout not
being able to calculate the last line height properly.

This CL stores the extra added to bottom and descent values so that it
can be used later.

Test: bit CtsTextTestCases:android.text.cts.LayoutTest
Test: bit CtsTextTestCases:android.text.cts.StaticLayoutTest
Test: bit CtsTextTestCases:android.text.cts.DynamicLayoutTest
Test: bit FrameworksCoreTests:android.text.LayoutTest
Test: bit FrameworksCoreTests:android.text.StaticLayoutTest
Test: bit FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit FrameworksCoreTests:android.text.DynamicLayoutBlocksTest

Bug: 30870806
Bug: 33138492
Bug: 25194907
Change-Id: I7a1039e71e4999c75b5f26122fe6239e3ee24868
2017-07-25 18:31:47 -07:00
Roozbeh Pournader
6ba82998e2 Merge "Refactor ellipsis attributes and methods" 2017-07-26 00:14:06 +00:00
Roozbeh Pournader
9ea756fa70 Refactor ellipsis attributes and methods
Mostly changed to avoid repetition of code and remove the assumptions
about ellipsis being one code unit. The code for multi-code unit
ellipsis is not triggered yet, but is done in preparation for
potential future locale-dependent cases.

Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.EditTextTest
Test: bit CtsWidgetTestCases:android.widget.cts.CheckedTextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.AutoCompleteTextViewTest
Test: bit CtsWidgetTestCases:android.widget.cts.MultiAutoCompleteTextViewTest
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner

Change-Id: Id1dfdc503f87fabed2447d55ab2107eee0eccd08
2017-07-25 14:50:18 -07:00
Siyamed Sinir
1e0f03da5f Merge "Make BulletSpan work with lineSpacing" 2017-07-21 18:08:46 +00:00
Siyamed Sinir
967805ca47 Merge "Handle long text for share/cut/copy operations." 2017-07-21 18:07:07 +00:00
Siyamed Sinir
b097553b78 Merge "Add BoringLayout constructor API docs" 2017-07-21 18:03:25 +00:00
TreeHugger Robot
89e4c1ce17 Merge "Refactor TextUtils.join() and add documentation" 2017-07-21 08:08:31 +00:00
TreeHugger Robot
c71c832a9e Merge "Use the Context's locale in DateFormat" 2017-07-21 01:01:41 +00:00
Roozbeh Pournader
42673c33ee Refactor TextUtils.join() and add documentation
Added documentation to clarify what happens in the case of null or
empty arguments.

Change-Id: I694dc0f6a6d95ab6ca7ed95b51d81938618eb75f
Fixes: 36861796
Test: bit CtsTextTestCases:*
Test: bit CtsGraphicsTestCases:android.graphics.cts.FontVariationAxisTest
2017-07-20 17:22:30 -07:00
Seigo Nonaka
298bb2995b Support font resource in TextAppearanceSpan
To be able to parcel/unparcel Typeface, keep it in static context.

Bug: 62850669
Test: Manually done
Test: bit CtsTextTestCases:android.text.style.cts.TextAppearanceSpanTest
Change-Id: I408cd33b98d8bb13776560231d1eeaac0a7c6bf8
(cherry picked from commit c49ee3bde9)
2017-07-20 23:40:44 +00:00
Siyamed Sinir
e827a0910e Make BulletSpan work with lineSpacing
Test: bit FrameworksCoreTests:android.widget.BulletSpanTest
Test: Manual sample app test

Bug: 33138492
Change-Id: I311ceab156c03c8b3174b2b4e875e172f01cd6c5
2017-07-20 15:16:28 -07:00
Siyamed Sinir
08fac62bc9 Add BoringLayout constructor API docs
Test: none
Bug: 30508784
Change-Id: Id9d739c2e09cebfd5482d83e4481dfaec5e178eb
2017-07-20 15:04:49 -07:00
Siyamed Sinir
ce3b05abc0 Handle long text for share/cut/copy operations.
When TextView or EditText contains text that is larger than the
total parcelable limit, some of the FloatingToolbar operations would
crash.

This CL changes the behavior as follows:
- Show a toast message if cut or copy operation fails because it cannot
  set the primary clip.
- Trim the text for share and process_text actions
- A simple app with an EditText and a long text in it, would not open
since Autofill value was being sent over IPC. Trimmed the text that is
sent for Autofill feature.
- Trim the value send to accessibility services

Test: bit CtsWidgetTestCases:.TextViewTest
Test: bit FrameworksCoreTests:android.widget.TextViewTest
Test: bit FrameworksCoreTests:android.text.TextUtilsTest
Test: Manual sample app test

Bug: 8013261
Change-Id: Ia0df6b4eb4c13071a1bf75cedac7241c7239663c
2017-07-20 15:01:18 -07:00
Roozbeh Pournader
3150434f49 Use the Context's locale in DateFormat
Previously, a mix and match of the default locale and the context's
locale were used in DateFormat methods that took a Context as a
parameter. Now we consistently use the Context's locale.

Also refactored the methods is24HourFormat() and hasDesignator() for
simpler and more readable code.

Change-Id: I418c1dcb710cdf2daf14684b258b97bfabe61d8c
Fixes: 62871956
Test: bit CtsTextTestCases:android.text.format.cts.DateFormatTest
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
2017-07-20 12:34:06 -07:00
Seigo Nonaka
c49ee3bde9 Support font resource in TextAppearanceSpan
To be able to parcel/unparcel Typeface, keep it in static context.

Bug: 62850669
Test: Manually done
Test: bit CtsTextTestCases:android.text.style.cts.TextAppearanceSpanTest
Change-Id: I408cd33b98d8bb13776560231d1eeaac0a7c6bf8
2017-07-20 12:01:05 -07:00
Clara Bayarri
6c66f86778 Make up/down movement of multilength lines remember position
Test: Separate CTS CL being submitted along this one, see topic
Bug: 25486843
Change-Id: I463c126b07db05b1c4a26e870cde5c5567471da0
2017-07-18 15:59:28 +01:00
Roozbeh Pournader
e2393ae726 Merge "Make strike-through respect kerning at boundaries" 2017-07-14 02:17:43 +00:00
TreeHugger Robot
b4dfcca0ab Merge "Switch file size formatters to use ICU's MeasureFormat" 2017-07-13 23:11:47 +00:00
Roozbeh Pournader
1378a9d72c Make strike-through respect kerning at boundaries
Also clean up lower-level drawing of strike-through in Cavas.cpp.

We still cannot use the strike-through information from the font
since Skia doesn't provide it, so we are going with the default
values.

Test: Manual
Test: bit CtsTextTestCases:*
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Bug: 32907446
Change-Id: Iee6f8102a35eba0ff4127dbbef189529ab573e6d
2017-07-13 13:21:00 -07:00
Roozbeh Pournader
4e5b71f084 Switch file size formatters to use ICU's MeasureFormat
Use ICU's MeasureFormat to the degree possible for formatting file
sizes.

Bug: 36994779
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Test: bit CtsTextTestCases:*
Change-Id: I4ad3b568ae7585b6ff56fddb79ded7c5b2118176
2017-07-13 11:11:55 -07:00
Seigo Nonaka
0d253e46aa Implement family fallback.
Introduce new attribute "fallbackFor" to font element.
By specifying name of the family to this attribute, that font is used
when the developer specifies the font family.
For example, if fonts.xml has the following family entry,
  <family lang="ja">
    <font fallbackFor="serif">NotoSerifJP-Regular.ttf</font>
    <font>NotoSansJP-Regular.ttf</font>
  </family>
the Japanese text is rendered by NotoSansJP-Regular.ttf by default.
Then, if developer specifies fontFamily="serif" in TextView, the Japanese
text is rendered by NotoSerifJP-Regular.ttf.

Bug: 37328609
Bug: 31491668
Test: bit FrameworksCoreTests:android.graphics.TypefaceSystemFallbackTest

Change-Id: I2744db7384c8056795e841c88b387545434131f4
2017-07-13 10:47:48 -07:00
TreeHugger Robot
ec8c01d767 Merge "Switch formatElapsedTime to use ICU's MeasureFormat" 2017-06-23 21:51:31 +00:00
Roozbeh Pournader
2ee9075462 Switch formatElapsedTime to use ICU's MeasureFormat
Previously, localizable strings were used instead, causing various
difficulties and inconsistencies. The formatting code also
hard-coded the pluralization rules for English and used it for all
locales.

Now we use ICU's MeasureFormat. There are some small formatting
differences with the previous code, but they are not important,
especially since the old strings were not necessarily well-thought.

Bug: 36994779
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Change-Id: Ie8cb119a76e89e2ee971353761fbd54e0d9a556c
2017-06-20 16:50:01 -07:00
Roozbeh Pournader
ef7cfa17e7 Pass all locale information down to Minikin
Previously, locale lists and LocaleSpans were ignored in deciding line
breaking and hyphenation in layouts.

Now, we pass both changing locale information and the whole locale
list to Minikin.

Fixes: 21571721
Bug: 25122192
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Change-Id: Ia93b0b7cbe54de65bb0ec4937e65cc7993559a6f
2017-06-20 14:19:24 -07:00
Roozbeh Pournader
dc8f3ef561 Make Linkify use the SIM card's country for phone numbers
Previously, it was using the locale's country code, which doesn't
make sense, since the locale's country code means which dialect of
the language the system should function in.  We should use the SIM
card's country code instead.

Change-Id: Ib942f92f3218c943669fc6150d6cc6b4e340b451
Fixes: 30000652
Test: cts-tradefed run cts-dev --module CtsTextTestCases
Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Test: Manual
2017-06-13 16:39:10 -07:00