Commit Graph

1000 Commits

Author SHA1 Message Date
Daniel U
43bb0a0643 Merge "Adopt HTML/CSS color values in fromHtml()" into nyc-dev 2016-02-12 11:24:56 +00:00
Raph Levien
7004c4407f Merge "Allow null string to BidiFormatter#unicodeWrap" into nyc-dev 2016-02-11 18:35:36 +00:00
Daniel U
1eab97ac8e Adopt HTML/CSS color values in fromHtml()
- "green", "gray/grey", "lightgray/lightgrey", and
  "darkgray/darkgrey" have different values in HTML/CSS.

- Adopt HTML/CSS color values according to user specified
  option flag.

- Remove support to "@color" notation as it is not standard
  HTML/CSS.

- Replace SPAN_MARK_MARK with SPAN_INCLUSIVE_EXCLUSIVE
  consistency.

BUG:26950749
Change-Id: I5b33282368042f74f1b4768e096aae3e5bf45de6
2016-02-11 18:32:30 +00:00
Daniel U
4a70f09e39 Tweak toHtml() paragraph conversion behavior
For mode TO_HTML_PARAGRAPH_LINES_INDIVIDUAL:
1) Empty line outputs <br> instead of <p><br></p>

2) A <ul> element is closed if it is followed by a <br>

3) Explicit zero vertical margin is applied to <ul> instead of <li>'s

4) More deterministic way to encode AlignmentSpans: only spans with
   SPAN_PARAGRAPH flag is used. If multiple spans exist, the last one
   (which is added most recently) is used.

BUG: 26224878
Change-Id: I86a2aeced9965ae465daac1ace64e5e41cf45caf
2016-02-11 12:11:44 +00:00
Raph Levien
b68d147b86 Allow null string to BidiFormatter#unicodeWrap
The BidiFormatter#unicodeWrap() methods allow null string, but the
toString() call on the result in the refactored code was crashing.
Also adds @Nullable annotations.

Bug: 27124532
Change-Id: I25922d104587af4a850c3640987af9315c3d3bde
2016-02-10 17:00:22 -08:00
Daniel U
8b36c0bbd1 Handle <span>, <ul>, and <li> tags in fromHtml()
The vertical spacing of <ul> and <li> are determined by the
FROM_HTML_SEPARATOR_* flags. Foreground color, background color,
and text-decoration CSS attributes are parsed and converted into
the corresponding spans.

Change-Id: I93b232de15753ae510392cbacf45e7453d1ae067
2016-02-10 19:18:09 +00:00
Daniel U
cf1fa60331 Allow different paragraph breaks in fromHtml()
- Separate block-level elements with different numbers of newline
  characters according to the user specified option flag.

- Parse the ALIGN attribute and the CSS TEXT-ALIGN property to handle text
  alignment.

- Rename "header" to the correct term "heading"

Change-Id: I446fa97155e761623a1da6632a0d872a5e47e8af
2016-02-10 18:28:07 +00:00
Roozbeh Pournader
fee4484637 Various LocaleList cleanups
- Remove the LocaleList#getPrimary() API. It had become confusing
  after locale negotiation was completely implemented. For example,
  it could create the confusion that calling getPrimary() on the
  default locale list would provide the default locale, etc.
- Use the adjusted locale list from LocaleList.getAdjustedDefault()
  in Paints created with no locale list provided.
- Change LocaleList#get() to treat out of bound indexes from both
  negative indexes and too large indexes the same way.

Bug: 26984092
Bug: 26193251
Bug: 26834387
Change-Id: I75f77aea6b75e38793ed8477e5e5a4420d5e6d85
2016-02-04 15:44:03 -08:00
Roozbeh Pournader
2f35c6405e Add CharSequence interfaces for BidiFormatter
The previous code just supported strings, but there were requests for
using BidiFormatter while keeping the spans.

Bug: 26967041
Change-Id: If2a1eeaf2cf1eedff3a83b79a105ea79ed1b85c1
2016-02-03 18:44:15 -08:00
Daniel U
ca124ab1e2 Encode BulletSpan in toHtml() conversion
Changes in toHtml() conversion with TO_HTML_PARAGRAPH_LINES_INDIVIDUAL:

- Wrap each paragraph inside a block-level element
Each paragraph delimited by '\n' is now wrapped individually inside either
a <p> or a <li> block to allow per-paragraph formatting.

- Wrap paragraphs covered by BulletSpans as <li> instead of <p> blocks

- Encode text alignment at paragraph level
Instead of creating <div> blocks outside of the block quote level.

- Encode AlignmentSpan as CSS style instead of the ALIGN attribute
The ALIGN attribute is obsolete.

Change-Id: I3a8b315224b762af99eda69cb19f5cf6b3f05dac
2016-01-27 16:41:33 +00:00
Daniel U
b138e28778 Enhance support to text size spans in toHtml()
Convert AbsoluteSizeSpan to <span> with CSS font-size property with CSS
px as the unit of measurement. Sizes measured in Android px are converted
to dip, since there is no CSS unit which conveys the idea of a device
pixel.

Add support to RelativeSizeSpan, which converts to <span> with CSS
font-size property with em as the unit of measurement.

Change-Id: I9104cc5f9b00ab1a31929565dc49e0026466cc75
2016-01-27 14:37:44 +00:00
Daniel U
5c02d7374f Support more CharacterStyles in toHtml() conversion
- Add support to convert BackgroundColorSpan
- Convert StrikethroughSpan to <span> with CSS styling instead of <strike>
- Convert ForegroundColorSpan to <span> with CSS styling instead of <font>

Change-Id: I05ff6b97534df9ee586a552c7e6435aabca152ac
2016-01-27 13:43:46 +00:00
Daniel U
2102de9e1f Overload toHtml() & fromHtml() to accept option flags
Overload the methods to take int option flags indicating the conversion
behavior. This guards against large disruptions in legacy applications.

Change-Id: I0f47180bbb78884b67aa200fe5156e903eeaa6f6
2016-01-27 11:24:03 +00:00
Siyamed Sinir
3a789f657b SpannableStringBuilder.getSpans returns array with null values.
This CL fixes the case where SpannableStringBuilder.getSpans call
forgot to check the case where sort is false, and the span priority
is not set.

Bug: 26761571

Change-Id: I3a548b9c01768e6977a0ff15d6ecb8ca9ec3c075
2016-01-25 11:32:37 -08:00
Siyamed Sinir
92b9747f1c Merge "Sort the result of SpannableStringBuilder.getSpans" 2016-01-21 19:12:28 +00:00
Siyamed Sinir
fa05ba0b0d Sort the result of SpannableStringBuilder.getSpans
SpannableStringBuilder used to return the result of getSpans in the
order of start indices because of the interval tree it uses. However,
style spans has to be applied in the order of insertion to get
predictable results. Sorted the results of getSpans ordered first by
priority flag and then by insertion time. Moreover improved the
performance of SpannableStringInternal copy constructor.

Bug: 26240132
Change-Id: I0b0fa7bb30a3bd9ca37dedca66d8993718586027
2016-01-20 16:27:39 -08:00
Yohei Yukawa
c38b519539 Replace Locale with LocaleList in LocaleSpan.
This is a straightforward upgrading of LocaleSpan.

LocaleSpan was designed to be a mechanism to override text locale only
in a certain substring.  Since now text locale supports multiple locales
with LocaleList, it should make sense to let LocaleSpan have the ability
to have multiple locales with LocaleList.

This CL also addresses an existing issue that LocaleSpan maintained only
Language/Country/Variant tags.  Now Locale data associated with a
LocaleSpan is guaranteed to be preserved as long as each of them can be
created from a BCP 47 language tag with Locale#forLanguageTag(String).

Bug: 26567158
Change-Id: Ib754796d399cd00f9d02005df88874a5cd5c7642
2016-01-15 13:14:03 -08:00
Yohei Yukawa
60fbc8e3bb Introduce SuggestionSpan#getLocaleObject().
This is a series of CLs to promote Java Locale object as a primary data
object to represent locale information in Android APIs.

With this CL, developers can get Locale information from SuggestionSpan
without semantically losing the original data.  Possible use cases would
be:
 - Emoji subtag (CLDR Ticket #9063)
 - Stable and reliable 3-letter country codes handling
 - Custom attributes based on private extensions.

Note that this CL does not change the current behavior of
SuggestionSpan#getLocale() as is, even if it is created with a malformed
Locale object:

  new SuggestionSpan(new Locale(" a ", " b c ", " e"), new String[0], 0)
          .getLocale() -> " a  b c  e".

Bug: 22858221
Change-Id: I96dfd4f819a236ee2e6dbd3e12903d1214223cb0
2016-01-14 12:16:06 -08:00
Raph Levien
e53e428a7e resolve merge conflicts of 957bdc56c5 to master.
Change-Id: I4c8749f92a1fa39bf0d08e10155d9e68c87401c0
2016-01-12 17:45:34 -08:00
Raph Levien
c08d43c4d7 Merge "Fix measurement to respect grapheme and span boundaries" into mnc-dr1.5-dev am: 36c5ab3542 am: 50c22adc25
am: 243efe13a4

* commit '243efe13a44faf3617e2df409fa8f4bd30078a5d':
  Fix measurement to respect grapheme and span boundaries
2016-01-13 00:54:58 +00:00
Raph Levien
9f2c939730 Merge changes from topic 'grapheme-dr1.5' into mnc-dr1.5-dev
* changes:
  Respect grapheme clusters in Layout#getOffsetForHorizontal.
  Fix: Cursor can be at an invalid offset in EditText.
2016-01-12 01:10:52 +00:00
Keisuke Kuroyanagi
5bff01d72f Respect grapheme clusters in Layout#getOffsetForHorizontal.
TextUtils#getOffsetAfter was used for getting the next
offset in Layout#getOffsetForHorizontal. However, this
method doesn't treat grapheme clusters properly.
Changed to use TextLine#getOffsetToLeftRightOf instead of
TextUtils#getOffsetAfter.

Bug: 25375561
Change-Id: I96c9e6e5da65adfb5266446ecab852c52628dbb5
2016-01-11 14:32:55 -08:00
Keisuke Kuroyanagi
720edf95db Fix: Cursor can be at an invalid offset in EditText.
"getLineEnd(line) - 1" is used as the return value when the
"horiz" is beyond the line end for multiple line text.
In this case, the returned value can point an invalid
offset like the middle point of a surrogate pair.

Bug: 23069901
Change-Id: I1afef7205a15079a42bb0018df73f70fe9ada862
(cherry picked from commit 00ad16d1cd)
2016-01-11 22:29:12 +00:00
Raph Levien
909c7bca57 Fix measurement to respect grapheme and span boundaries
When measuring in TextLine (important for cursor positioning), the
substring measured must neither be too short (it can't just be the
substring up to the measure limit, but must include additional
characters if they form a ligature) nor too long (it can't extend
beyond the end of the CharacterStyle span, otherwise the measurement
fails to account for the fact that the CharacterStyle span boundary
breaks the ligature). This patch gets it just right.

Bug: 25375561
Change-Id: I36e1c4bdc66424d3b611cf54031756cf54cf3fec
2016-01-11 21:43:24 +00:00
Siyamed Sinir
3463c04b51 Fix SpannableStringBuilder.replace() exception.
When SpannableStringBuilder.replace is called with a source text that
contains a span with SPAN_PARAGRAPH flag, the code tries to retain the
spans. However when the paragraph boundary constraint is not satisfied,
setSpan method throws an exception. Updated the rule as: if the source
text has a span with SPAN_PARAGRAPH flag check if it can be copied into
the target. If not, discard the span. Also updated the JavaDoc for
Spanned and Editable.

Bug: 22521443
Change-Id: Ie8541e00bfdf5b8b0115ad7b26cb9f83a6a3ee55
2016-01-07 12:56:09 -08:00
Keisuke Kuroyanagi
6f80c44651 Merge "Fix: TextView cannot be scrolled." 2016-01-07 06:59:03 +00:00
Keisuke Kuroyanagi
cb4a2bb5de Fix: TextView cannot be scrolled.
scrollTo in Touch#onTouchEvent was wrongly removed in
I1b29a65be3d321ac while moving mouse text selection logic
added in Iab264bb954b.

Bug: 26409193

Change-Id: Ibb0b13be9492d658785f2ac72be383e634ad96f8
2016-01-06 19:23:43 +09:00
Siyamed Sinir
840385c9f6 New regular expression to autolink URLs
Introduced a new regular expression to autolink URLs. Previous regular
expression used the protocol as an optional rule. The new expression
applies separate rules for strings that do not start with a known
protocol and strings that do start with a known protocol.

- In order to reuse previous regular expression definitions for
different parts of a URL, created constants for different parts of
WEB_URL expression.
- Separated the test cases for WEB_URL in order to remove the suppress
command and make them running again.
- Fixed failing tests for punycode urls, which were causing existing
tests to fail.
- Introduced new a regular expression for URL matching.
- Changed the protocol rule to be case insensitive.
- Updated IANA TLDs.
- Added tests for the new regular expression.
- Added tests for Linkify.
- Bug 9622849 is partially fixed.

Bug: 25727599
Bug: 9622849
Bug: 24500693
Bug: 23189367
Bug: 24543148

Change-Id: Ifd62455d342ca7adb22996246ff652e1d5944bec
2016-01-04 17:59:45 -08:00
Roozbeh Pournader
a1c0a82ba6 Load Portuguese and German hyphenation in Hyphenator
This also extends the fallback locale matching algorithm to consider
language+variant before just the language, so asking for "de-AT-1901"
would result in trying "de-1901" before trying "de".

Bug: 26169902
Change-Id: I55e5a73e7ac730d0bc14204126cbb3cc6ce0e9f1
2015-12-14 21:27:46 +00:00
Roozbeh Pournader
0c5b33eb26 Merge "Switch WordIterator's BreakIterator to ICU4J" 2015-12-11 02:57:56 +00:00
Roozbeh Pournader
108c9604e3 Switch WordIterator's BreakIterator to ICU4J
The java.text results are different from the ICU4J's results when
non-BMP characters are present, and the ICU4J's results appear to be
more correct. See also bug 26144875.

Bug: 25993844
Change-Id: Iec2e48008b2ce2147260ed3874e90a51ecf94a35
2015-12-10 18:14:55 -08:00
Keisuke Kuroyanagi
97af673e1f Move mouse selection handling logic to Editor.
- Remove mouse selection related logic from
ArrowKeyMovementMethod and Touch.
- Extend drag accelerator to support character based
selection by dragging and use it for mouse drag selection.
- Enable word based drag accelerator even if the clicked
position is not on a word.
- Disable y-coordinate adjustment for word based drag
accelerator when the user is using a mouse.

Bug: 19544351

Change-Id: I1b29a65be3d321ac472f8c5b70ab6fee4e895964
2015-12-10 05:13:40 +00:00
Neil Fuller
568f4de11a Merge "Fix @code escapes" 2015-12-03 09:44:01 +00:00
Roozbeh Pournader
c7dcec43d6 Make Hyphenator load Spanish hyphenation patterns
The pattern files themselves are added to the
external/hyphenation-patterns repo.

Change-Id: Icf37191f1217b7869f49f8ea63174341662caacf
2015-12-02 12:25:07 -08:00
Neil Fuller
71fbb81b14 Fix @code escapes
The body of {@code} must not be HTML escaped. This is one of
several changes that fix the source in conjunction with a
doclava fix.

Bug: 25757239
Change-Id: Ib38a0fa2dd2a3d68e467f78a812071e763d7e881
2015-12-02 14:24:11 +00:00
Keisuke Kuroyanagi
ead6ba3a63 Stop making a reversed selection with mice.
Bug: 24889605
Bug: 24475013
Change-Id: I6d39e050656dc28e523fab862c84054169e6300b
2015-10-27 17:26:07 +09:00
Keisuke Kuroyanagi
742bd40328 Merge "Fix: Last char can be excluded from mouse selection." 2015-10-27 05:46:47 +00:00
Roozbeh Pournader
ca9dbf596d am ebdf60e7: am 0221328c: am b3538082: am 5362f273: Merge "Fix line height problem with inline images in StaticLayout." into mnc-dr-dev
* commit 'ebdf60e7c800b2ccda01887a304ddc0edce0361d':
  Fix line height problem with inline images in StaticLayout.
2015-10-16 22:20:01 +00:00
Roozbeh Pournader
431e506b53 Fix line height problem with inline images in StaticLayout.
Previously, paragraphs with ImageSpans in their middle would continue to
carry the height of the image into the line height of next lines. This was
a regression from L.

The bug was due to StaticLayout's out() method almost always
modifying the value of its parameter "fm", although that was only
intended when there were LineHeightSpans in the text. The method
generate() was assuming that it can restore fmTop etc to metrics of
the current span by setting them from "fm" after out() was run, while
"fm" was modified by out() and its original values was lost!

The fix makes sure to set chooseHt back to null if there were no
LineHeightSpans, so out() would not modify "fm" unless necessary.

AOSP bug: https://code.google.com/p/android/issues/detail?id=188042
Bug: 24548073

Change-Id: I0d00af384c35a9d863377972318da9db7668118f
2015-10-16 02:49:13 -07:00
Roozbeh Pournader
63aa02e47f Merge "Load binary hyphen data files" into mnc-dr-dev 2015-10-15 00:18:36 +00:00
Raph Levien
35e026929b Load binary hyphen data files
Support for loading the pre-compiled binary format for hyphenation
patterns.

Bug: 21562869
Bug: 21826930
Bug: 24570591
Change-Id: Iaeaa9c9ac9dac236af6b0d7894c2e2396bc8447d
(cherry picked from commit 091dba2de1)
2015-10-14 19:11:33 +00:00
Roozbeh Pournader
0453112de6 Make Hyphenator#get() return an object.
Previously, a native pointer was returned. After this change, callers
should call getNativePtr() if they want to get the native pointer instead.

Bug: 21492297
Bug: 24570591
Change-Id: I745bd88e6e8c86078fffb07f90f8d8f24215410c
(cherry picked from commit e7eac6f540)
2015-10-14 19:10:44 +00:00
Keisuke Kuroyanagi
45a60d1a43 Fix: Last char can be excluded from mouse selection.
When a mouse is used, isTouchSelecting for ACTION_UP always
returns false with current implementation because all
DragState spans have been removed in Touch#onTouchEvent.

Change-Id: Ie27a2bb860e9ddeb71dafff361c734a7c727102d
2015-10-13 11:02:26 +00:00
John Reck
44e8d60f53 Super-fast getLineWidth for BL
Bug: 24678704
Change-Id: I952964f450d19b1e127753d00833eb7b34473bba
2015-10-05 15:44:04 -07:00
Raph Levien
091dba2de1 Load binary hyphen data files
Support for loading the pre-compiled binary format for hyphenation
patterns.

Bug: 21562869
Bug: 21826930
Change-Id: Iaeaa9c9ac9dac236af6b0d7894c2e2396bc8447d
2015-09-30 17:37:54 -07:00
Keisuke Kuroyanagi
9f18132aae Merge "Fix: Cursor can be at an invalid offset in EditText." 2015-08-28 06:57:22 +00:00
Keisuke Kuroyanagi
00ad16d1cd Fix: Cursor can be at an invalid offset in EditText.
"getLineEnd(line) - 1" is used as the return value when the
"horiz" is beyond the line end for multiple line text.
In this case, the returned value can point an invalid
offset like the middle point of a surrogate pair.

Bug: 23069901
Change-Id: I1afef7205a15079a42bb0018df73f70fe9ada862
2015-08-27 18:15:48 +09:00
Roozbeh Pournader
4bae2038cd Merge "Cleanup android.text.TextUtils a little." 2015-08-21 19:04:29 +00:00
Roozbeh Pournader
4059d7dbfa Update tests and support negative values in formatBytes().
This updates the tests to match the older commit
f723017481 and also adds support for
negative values.

Bug: 23191381
Bug: 11237727
Change-Id: Ib9a1f10031b730ee460658949b388c779cefa041
2015-08-20 17:59:30 -07:00
Roozbeh Pournader
3efda95072 Cleanup android.text.TextUtils a little.
- Clarify that getTrimmedLength() only considers ASCII control
  characters as control characters.

- Deprecate getReverse() instead of trying to fix it, as it's really
  not meaningful for internationalized text.

- Support non-BMP characters in isDigitsOnly().

Change-Id: I947c449b48c252ecc7f7299145f6f8fbad86004f
2015-08-18 14:04:43 -07:00