summaryrefslogtreecommitdiff
path: root/core/java/android/text/SpannableStringBuilder.java
Commit message (Collapse)AuthorAgeFilesLines
* Add maxTargetSdk restriction to unused APIs.Mathew Inwood2020-10-291-1/+2
| | | | | | | | | | | | | | | | | | | These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. This is a resubmit of ag/12929664 with some APIs excluded that caused test failures; see bugs 171886397, 171888296, 171864568. APIs excluded: Landroid/bluetooth/le/ScanRecord;->parseFromBytes([B)Landroid/bluetooth/le/ScanRecord; Landroid/os/Process;->myPpid()I Landroid/os/SharedMemory;->getFd()I Landroid/hardware/input/InputManager;->INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH:I Bug: 170729553 Test: Treehugger Change-Id: I8285daa8530260251ecad6f3f38f98e263629ca7
* Revert "Add maxTargetSdk restriction to unused APIs."Hongwei Wang2020-10-281-2/+1
| | | | | | | | | This reverts commit 72f07d6a8a32db4a0dedd7682a0b3385be2b9cd6. Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?testMethod=testAppZygotePreload&testClass=android.app.cts.ServiceTest&atpConfigName=suite%2Ftest-mapping-presubmit-retry_cloud-tf&testModule=CtsAppTestCases&fkbb=6936597&lkbb=6936969&lkgb=6936551&testResults=true&branch=git_master&target=cf_x86_phone-userdebug>, bug b/171886397 Bug: 171886397 Change-Id: Ibe0f0430a3451477c1ee8ef56a596e91ea1e7672
* Add maxTargetSdk restriction to unused APIs.Mathew Inwood2020-10-271-1/+2
| | | | | | | | | | These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. Bug: 170729553 Test: Treehugger Change-Id: I4c8fd0006f950de9955242e93968fb0996ceb372
* Add @Nullable annotation to the parameter of Object.equals() methods.Roman Kalukiewicz2020-10-151-1/+1
| | | | | | | | | | | | | | | | | | Those annotations could be inferred by some tools (like Kotlin), but the https://checkerframework.org/ doesn't check inherited annotations complaining about all equals() invocations that get nullable argument. The change was generated by running find . -name \*.java | xargs sed -i 's/public boolean equals(Object /public boolean equals(@Nullable Object /' in the frameworks/base directory and by automatically adding and formatting required imports if needed. No manual edits. Bug: 170883422 Test: Annotation change only. Should have not impact. Exempt-From-Owner-Approval: Mechanical change not specific to any component. Change-Id: I5eedb571c9d78862115dfdc5dae1cf2a35343580
* Use new UnsupportedAppUsage annotation.Artur Satayev2020-01-071-1/+1
| | | | | | | | Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I288969b0c22fa3a63bc2e71bb5009fe4a927e154
* Fix equals not working correctly in SpannableString and SpannableStringBuilderHaoyu Zhang2018-09-201-4/+5
| | | | | | Bug: 73359036 Test: atest SpannableStringTest SpannableStringBuilderTest Change-Id: Idfaf71cde914d5c5325a6c6a3bfcda20ebee62f2
* Unhide getTextRunCursor APIsSeigo Nonaka2018-09-181-4/+11
| | | | | | | | This API is necessary for identifying the cursor locations. Bug: 112327179 Test: atest android.graphics.cts.PaintTest Change-Id: Ief6770bd622a296ae356094fe3ce58e9c4371088
* Add @UnsupportedAppUsage annotationsMathew Inwood2018-08-151-0/+12
| | | | | | | | | | | | | | | | | | | | 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
* Fix crash when modifying SelectionClara Bayarri2018-04-061-4/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Do not enforce paragraph constraint for copy ctrSiyamed Sinir2017-04-111-37/+26
| | | | | | | | | | | | Update SpannableStringBuilder, SpannedString and SpannableString classes so that they don’t enforce paragraph constraint for copy constructors. If a paragraph constraint is not satisfied for a span, that span is not copied. Before this change it would throw an exception. Test: New tests added for SpannableStringBuilder and SpannableString cts-tradefed run cts -m CtsTextTestCases Bug: 36511794 Change-Id: I62abf08a8d4fe7e342ed97b8e8c3a577a9397e39
* Fix SpannableStringBuilder getSpans sort am: 051caedcaaSiyamed Sinir2017-01-241-13/+19
|\ | | | | | | | | | | am: 1764efad93 Change-Id: I33b2f25901330e79bbc166a318f71d5124d0b332
| * Fix SpannableStringBuilder getSpans sortSiyamed Sinir2017-01-191-13/+19
| | | | | | | | | | | | | | | | | | Sort function was broken for odd number of elements. Test: Added new CTS tests. Bug: 33567024 Change-Id: I7457dee6ac279c6aab5b92431b347dc1f16a8fa0
* | Make SpannableStringBuilder.getSpans thread-safeSiyamed Sinir2017-01-231-16/+67
| | | | | | | | | | | | | | | | | | Add cached int buffers for sorting. Test: All CtsTextTestCases Bug: 33609774 Change-Id: Ice0b3c3fffc541b26aca94c93fd01e30e13efe2e
* | The bigger update to CanvasJohn Reck2016-10-171-3/+5
|/ | | | | | | | | | | | | | | | | All draw* calls in Canvas are regular JNI All draw* calls in DisplayListCanvas are FastNative Unifies Canvas JNI on nMethodName naming CanvasPerf results before: INSTRUMENTATION_STATUS: basicViewGroupDraw_min=12492 INSTRUMENTATION_STATUS: recordSimpleBitmapView_min=13912 and after: INSTRUMENTATION_STATUS: basicViewGroupDraw_min=11945 INSTRUMENTATION_STATUS: recordSimpleBitmapView_min=13318 Test: refactor, makes & boots Change-Id: I06000df1d125e17d60c6498865be7a7638a4a13e
* Fix int overflow in SpannableStringBuilder.replaceSiyamed Sinir2016-06-031-3/+4
| | | | | | | | | | During the offset calculation for selection, SpannableStringBuilder had an overflow while multiplying two int values. This CL uses long to calculate the multiplication, and also checks for overflow after casting the final result into int again. Bug: 29108549 Change-Id: I11eff4677916701074b38bc5214730fe704707c4
* SpannableStringBuilder.getSpans returns array with null values.Siyamed Sinir2016-01-251-5/+6
| | | | | | | | | 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
* Sort the result of SpannableStringBuilder.getSpansSiyamed Sinir2016-01-201-23/+181
| | | | | | | | | | | 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
* Fix SpannableStringBuilder.replace() exception.Siyamed Sinir2016-01-071-16/+37
| | | | | | | | | | | | | 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
* Fix unintentional NPE in SpannableStringBuilder.Roozbeh Pournader2015-08-121-2/+4
| | | | | | | | | | Previously, when getSpans() was called with a null parameter, an unintentional NullPointerException would be thrown. Now, we explicitly return an empty array of Objects. Bug: 19805521 Change-Id: I52f3ae08c2bcf62f6a4d0c01f0fe08ad1134abb8
* Improve undo support for text entered with IMEJames Cook2015-03-181-0/+19
| | | | | | | | | | | | | | | | | | | | | Use span properties to detect: * Composing text - don't record undo operations * Completing a composition - record an insert undo operation * Canceling a composition - don't record Save the composition state on parcel/unparcel. Stop using begin/end batch edit to try to detect when a TextWatcher is modifying the text. IMEs trigger multiple InputFilter passes in a single batch edit. Use SpannableStringBuilder to determine when we're in a TextWatcher callback because it is the authority on that state. Fix a bug in undo manager where it doesn't forget undos correctly if there are more than one in the stack. Bug: 19332904 Change-Id: Iaa9b0b2a7bf6683302cc85e7616e5d5fcc9fa202
* Interval tree for SpannableStringBuilderRaph Levien2015-02-121-189/+361
| | | | | | | | This CL greatly improves the speed of SpannableStringBuilder by storing the spans as an interval tree with binary search. Bug: 7404182 Change-Id: I2540b2cfe8aef128337e63829479660ba51e62b5
* New convenience method that takes a CharSequence and an Object as theNiels Egberts2014-07-111-0/+15
| | | | | | span that is applied to the appended text. Change-Id: Ibdc4a71346e5691bcfe6af23f34beff69d642908
* Clean up dirFlags / bidiFlags confusionRaph Levien2014-06-161-15/+15
| | | | | | | | | | | | | | | | | | | The dirFlags and bidiFlags enums are distinct, and have different meanings. The former is a determined direction for a run of text, while the latter is a request for the bidi algorithm. They have been used interchangeably, and this has caused some problems, notably running the bidi algorithm needlessly when the direction for a run is already determined. This patch cleans up the confusion, by always naming each occurrence explicitly "boolean isRtl" or "int bidiFlags" (the previous code often just used "int flags", which added to the confusion), and converts between the meanings when a function takes an isRtl argument but passes it to another function expecting bidiFlags. Fixes b/15089607 Clean up bidi flag mess Change-Id: I410b6604376e853dd12c255e7f5a9d2b9a310dd9
* Fix a CTS testJean Chalard2014-06-111-17/+1
| | | | | | | | | | SpannableStringBuilder should throw an exception when the parameters to #insert and related methods are in the wrong order. We'll have to reopen b/9570771 and deal with it separately. Bug: 14965397 Change-Id: I01847e0010d23f98ad3def8ba030d36570528900
* Uses VMRuntime.newUnpaddedArray for ideal array sizesAdam Lesinski2014-03-271-34/+19
| | | | | | Bug:13028925 Change-Id: I0a9301248b10a339afbdc5e4ffe3310ac4fa1fb7
* Fix a crash where user data was not validated.Jean Chalard2014-02-131-3/+21
| | | | | | | | | | | ExtractedText#partialStartOffset and #partialEndOffset are from the app, that sets it as it sees fit. We need to validate them so that we don't crash. Still emit a warning if this is the case, as this is not expected. Bug: 9570771 Change-Id: Id9d6babd1620da39bf0e454b14d7ce716bd9d9d3
* Fix infinite recursion in hashcode of SpannablesChet Haase2013-10-041-8/+16
| | | | | | | | | | | | | | | An app created a SpannableStringBuilder, one of which's spans was the instance of the string builder itself (that is, the builder contained a span that was the builder). This caused infinite recursion in the hashcode() method because it computes a hash from its fields, including all of its spans. The fix detects the case where a span equals the current instance and noops the computation on that span. A similar adjustment was made to equals() to avoid the same recursion problem. Issue #11051658 StackOverflowError in android.text.SpannableStringBuilder.hashCode Change-Id: I742687ab32d81ac51c4b9135f698cf5e96a1d295
* Add equals() and hashcode() to SpannableStringChet Haase2013-09-191-0/+41
| | | | | | | | | | | | | | | ActionBar uses a transition to animate text changes. This transition depends on testing the equality of start/end text values in CharSequence objects. Without equals(), SpannableString will return false for objects whose references are different, but whose text is exactly the same. This CL adds the equals() method, and the accompanying hashcode method, to ensure that two Spanned implementations will always be equal if their text and span data are equal. Issue #10760075 Wrong unread count in actionbar Change-Id: I5e77d40dd302eca035e8c56d40f3cd0aef8e6424
* Fix bug #8437358 Clean any ICU related code from TextLayout / Paint and ↵Fabrice Di Meglio2013-03-201-29/+0
| | | | | | | | | their dependencies - remove the ICU related methods and update the methods using the "reserved" argument - update to CTS in another CL too Change-Id: I5509736568c342d9d17bfeafc17951117ab5d3cc
* Revert "Clean Paint.mBidiFlags as it is no longer used"Fabrice Di Meglio2013-03-151-21/+42
| | | | This reverts commit 6d9fe5bd22b531bfce69b146254a4791c76acddc.
* Clean Paint.mBidiFlags as it is no longer usedFabrice Di Meglio2013-02-121-42/+21
| | | | | | See bug #7623824 Change-Id: Ie2f9422821f6dcc73c99e8695f448e966b587b1d
* Final fix in SpannableStringBuilder.Gilles Debunne2012-05-041-8/+11
| | | | | | | | | Bug 6448052 The empty EXCLUSIVE removal condition was incorrect. Also changed the unit test the didn't catch this problem. Change-Id: I5576d830cdfa6cc3716c878fb698695a2978b296
* SpannableStringBuilder correctly manages MARK and POINTSGilles Debunne2012-04-261-22/+45
| | | | | | | | | | | | Bug 6343982 Finally deeply understood the meaning of the POINT and MARK flags. Updated the Spanned documentation to reflect this. Updated tests to come. Change-Id: I400d56b7b4929bc1e7eb4f0497d8e081ee23682e
* Do not notify text watchers when replace is a no-opGilles Debunne2012-04-181-0/+20
| | | | | | | | | | | | Bug 6344997 The early exit we used to do when both replaced and replacement strings were empty has been added back. Only this time it correctly also makes sure no spans from the replacement string would get added with a 0-length. Change-Id: Ifc38a7e3619c57aa7647c0a8e63d7627d86f1036
* Fixed SSB. Correct broadcast of removed spans' positionsGilles Debunne2012-04-181-17/+35
| | | | | | | | | | | | Found while tracking bug 6326750 A bug in the SpannableStringBuilderSpanTest JUnit CTS test was hiding this problem. Also removed the instanceof test on SpanWatcher. All spans, including those implementing this interface should be copied. Change-Id: I5233818fb0c08ab56477720db932a5be453e88ee
* SpannableStringBuilder correctly broadcast span changes during replaceGilles Debunne2012-04-121-76/+144
| | | | | | | | | Bug 6331765 A call to replace was previously not sending any span modification to the attached span watchers. Change-Id: Ic9e4a8ac0210e422961adfb18e205d80531889fe
* Removed exception from SpannableStringBuilderGilles Debunne2012-04-101-9/+7
| | | | | | Bug 6312196 Change-Id: I9cece36b40d8948e0e85bd433954818991009ad5
* Faster and simpler replace in SSB, take twoGilles Debunne2012-04-091-84/+63
| | | | | | | | | | | | | | | | This is a new version of CL 179343 which had to be reverted. This problem of the previous CL is that the ComposingSpan that was part of the replacement text was correctly added during the replace but was immediately removed because it had a zero-length size. Swapping the add and remove blocks solves the problem. The new non-zero length enforcement also revealed a bug in the spell checker where we were creating useless range spans. Change-Id: I59cebd4708af3becc7ab625ae41bc36837f1a1cf
* Merge "More minor refactoring in SpannableStringBuilder"Gilles Debunne2012-04-091-32/+29
|\
| * More minor refactoring in SpannableStringBuilderGilles Debunne2012-04-051-32/+29
| | | | | | | | | | | | No change in the functionnalities. Change-Id: I009acc75b4f70e65a810cdc67505bc0b13e627b2
* | Revert "Faster and simpler replace in SSB"Gilles Debunne2012-04-061-21/+46
|/ | | | | | | | | | Bug 6300658 This change reveals a weird race condition where sometimes the text is entered twice. Adding a debugger slows down everything, and the problem is no longer reproducable. Reverting for now. This reverts commit ebd9a23817052c4d2aaa1058efa2b80b08003d4a.
* Faster and simpler replace in SSBGilles Debunne2012-04-041-46/+21
| | | | | | | | | | | | | The original method was adding a suspicious space that was eventually removed with a series of 3 calls to change. This should not be necessary. I have tested this with various gap positions and lengths, for all replace cases I could think of. The test can not be added to the CTS as it would need to expose the internal resizeFor and moveGapTo methods. Change-Id: I194457fbcfd758fa69a7f380665cfd5ae4d3f1d4
* Refactoring SpannableStringBuilderGilles Debunne2012-04-021-80/+52
| | | | | | | | | | | Made TextWatcher notification process clearer by moving it to a single place, with methods renamed. Also reverts CL 177544: we cannot broadcast span chages just yet, the layout has not been reflown. A future CL will change this behavior to make sure span changes are correctly broadcasted. Change-Id: I9ef88dce91dff5f5f45e2845d5b3f18f1c853de3
* Spans added during a text change are broadcastedGilles Debunne2012-03-301-5/+3
| | | | | | More consistent with the SpanWatcher design. Change-Id: I3a1e4d92fb422f4cc689dabcdef1473d93fef5ad
* Limit created string size in Spell CheckerGilles Debunne2011-12-071-0/+11
| | | | Change-Id: I2f4e7a8b0022d76bc30199ff80c2fe637dbe03ef
* Too many SpellCheckSpans are created.Gilles Debunne2011-09-271-6/+5
| | | | | | | | | | | | | | | | | | | | Removed the Runnable in SpellChecker, spell check is triggered at the end of updateSpellCheckSpans instead of when a new SpellCheckSpan is created. Cache the spans in updateSpellCheckSpans to limit the calls to getSpans. When typing, every new letter in a word will create a SpellCheckSpan (this is needed in case the user taps somewhere else on the screen) The SpellCheckSpans are pooled in SpellChecker to limit unnecessary new SpellCheckSpan creation. Minor optimization on test order in getSpans to avoid some calculation. Spell check is not started everytime the selection is changed (would be triggered when the insertion handle is moved). Explicitely do that only on tap. Change-Id: Ibacf80dd4ba098494e0b5ba0e58a362782fc8f71
* Bug 5250788: TextView gets slower as the text length growsGilles Debunne2011-09-231-2/+3
| | | | | | | | | | | | | getSpans was called too many times in handleRun. Pre-compute the subset of intersected spans and iterate over a subset of it instead. Moving the instanceof test in getSpans after the other tests also speeds things up a lot. On a text with ~300 words, all with a span attached, getSpans went down from 78% to 14% of the CPU usage. Change-Id: I59bc44f610e9a548e0dcec68b180934da9e5c559
* Spell checking in TextViewsGilles Debunne2011-08-231-81/+44
| | | | | | | | | | | New UX interactions (the Paste action is no longer displayed after a delay) suggestionEnabled flag replaced by existing input type flag. removeSpans fixed in SpannableStringBuilder to always send notifications SuggestionSpan handled by TextView instead of SpannableStringBuilder New span update algorithm to correctly handle edition around word boundaries. Change-Id: I52c01172f19e595fa512e285a565a3fd97c3c50e
* SuggestionSpans are removed around edited text.Gilles Debunne2011-04-291-20/+35
| | | | | | | | | | | | | | SuggestionSpans do not make sense anymore when the text they refer to is modified. Removed these at the lowest possible common level: In the SpannableStringBuilder that is used to back the Editable. This way, IME do not have to care about removing these when they change text. And they cannot forget to so either. Also fixed a bug in TextView's paste with multi-item paste text (never exercised, since we have no source for such a thing). Change-Id: I08ed921f8c04ffb1a00936a3e554a85ee82f103c
* Clean getTextRunAdvances() APIsFabrice Di Meglio2011-04-211-8/+8
| | | | | | | - remove ICU reference in API names - use a "reserved" int parameter to pass either "0" for Harfbuzz or "1" for "ICU" Change-Id: I88b4f76feafd203a6999cd7349402fa36a9a4b2a