summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextViewTranslationCallback.java
Commit message (Collapse)AuthorAgeFilesLines
* Translate selectable TextViews by temporarily disabling selectable.Mark Punzalan2022-05-251-7/+69
| | | | | | | | | | | | | | The text is not selectable while translated. Making translated text selectable requires many more changes. This was tested in Nextdoor in the feed/posts activity. When there is a "Read more" link in the post, the link doesn't work while translated, and doesn't behave the same way after translation is paused. Bug: 202966891 Test: atest CtsTranslationTestCases Test: Manually - with Nextdoor on feed and chat activities Change-Id: I6e8f532d427d85ff22df0deb248d8416a15f4821
* Fix the translation not work if the animation is offJoanne Chung2022-03-241-6/+12
| | | | | | | | | | | The system will show translation after the animation is done but it doesn't work if the animation is off. To fix the issue, we will check the animation status before showing translation. Bug: 215386127 Test: atest testUiTranslationWithoutAnimation Change-Id: Id0d02c422100effcf842209971052f4d6e9b0bd2
* Fix translation animation flash for the same translationJoanne Chung2021-12-101-0/+11
| | | | | | | | | | | | | | | | | | The system received the same multiple translation responses in a very short time. We use a isShowingTranslation flag to determine if the duplicated responses to call onShowTranslation. However the isShowingTransation flag is set in a post runnable, this may cause the system allow the duplicate responses can call onShowTranslation because the isShowingTransaltion isn't set true yet. Use multiple flags isShowingTranslation and a new isRunningAnimation to check if the same translation response should skip to call onShowTranslation. Bug: 207457172 Test: manual Test: atest CtsTranslationTestCases Change-Id: I7003b7f49fc0a8ce2e909228bcb89acedee6d3d0
* Fix not show translation if call startTranslation after pauseTranslationJoanne Chung2021-10-071-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | It is possible the developer calls pauseTranslation() to show the original text but it calls startTranslation() to show translated text. Ideally the developer should call resumeTranslation but it also make sense to call startTranslation() to show translated text. When receiving translation response, we avoid showing transaltion if the view already has the response and it's the same. But it is good to also check if the view is showing translated text or not. If the view is not translated text, it is possible developer calls startTranslation() instead if calling pauseTranslation() to show translated again, the fixing can resolve this case. The issue case can be fixed by this change. But there is a deeper problem about it's useless the caller call finishTranslation(). This is planned to be fixed in next release. Bug: 201238016 Test: manual. The issue case is fixed. Test: manual. Test some chat apps, it still works fine. Test: atest CtsTranslationTestCases Change-Id: I699d0fa1d60ac96db094adcc6e17f4203df03214
* Fix the existing translation doesn't update for new translated result.Joanne Chung2021-09-191-1/+6
| | | | | | | | | | | | It is possible the existing text is changed that triggers a new translation. We cache the translation response when onShowTransltion is called. We should keep the translation response is updated if this is a new translation result. Bug: 200232741 Test: atest CtsTranslationTestCases Test: manual. The issue app works fine. Change-Id: Iaf7423cd35d4484e33de84e478256b77a000f390
* Disable log default dumps in debug ROMJoanne Chung2021-06-291-7/+1
| | | | | | | | | | We enable the logs dump in debug rom, we should only dump logs when the debug flag is on. Bug: 182433547 Test: Make sure the flag is disable after test and enable during test. Change-Id: I0a719ee9c545b4e66f3414d7f57f3d959004071e
* Bug fix: Move the implementation out from View.onTranslationResponse.Joanne Chung2021-06-171-45/+24
| | | | | | | | | | | | | | | | | | | Keep onTranslationResponse() only to save TranslationResponse. We can move set TransformationMethod logic to TextViewTranslationCallback. With the current implementation, if the developers overrides onTranslationResponse(), they don't have a chance to use the TextView default ViewTranslationCallback implementation because they don't set the TranslationTransformation, they must implement their solution. If we move logic to TextViewViewTranslationCallback and the developers only overrides onTranslationResponse(), they still have a chance to use the default TextViewViewTranslationCallback if the developers set the TranslationResponse for View. Bug: 178353965 Test: manual to make sure translation still works. Test: atest CtsTranslationTestCases Change-Id: Iada7f3efbbc7705ecf962c78e275ed942816707f
* Translate: Text alpha animation on toggling translated state.Ahaan Ugale2021-05-271-5/+81
| | | | | | | | | | | | | | | | | | | | | | | | Apply a simple text alpha animation when toggling between original and translated text. The text is fully faded out, then swapped to the new text, then the fading is reversed. Quick toggles are handled by ending the previous animation (which resets the alpha value) when starting a new one. If the toggle is extremely fast (<250ms for the currently defined animation duration), the text stays in it's original state instead of swapping back-and-forth. This is arguably not ideal, but anyway not worth the complexity for fixing. There is an unhandled edge case where if the color is changed by the app during the animation, the app's change would get overridden. It should be rare and doesn't seem very important to fix. Bug: 178651829 Test: atest CtsTranslationTestCases Test: manual - across several apps, while scrolling, concurrently interacting with the app, concurrently closing the app, selecting text during the animation (with animation speed slowed down to see the effect). Change-Id: I08a26de2253bb345f01186a6748b2d0ff6c2a419
* Translate TextView content description if existJoanne Chung2021-05-171-0/+17
| | | | | | | | | | | | | | | | Screen reader(Talkback) will read content description first if the developers set. We only translate TextView text, this may cause the screen reader will not read the translated text if the developers set content description. To fix the issue, we also send the content description to translate. When the translated text is shown, we also set content description with translated content description and reset to original content description if show original text. Bug: 187134784 Test: atest CtsTranslationTestCases Change-Id: I6986384260627a0539780b7293d47666c442d852
* API feedback: Translation View API refinement.Joanne Chung2021-04-201-0/+13
| | | | | | | | | Bug: 178046780 Test: manual Test: atest android.translation.cts.UiTranslationManagerTest CTS-Coverage-Bug: 177960696 Change-Id: I557ca4b3b4e7324af12e81dd8b5ac8a04a17b6b8
* AutoTranslate: Pad view text for compatibility reasons.Ahaan Ugale2021-04-161-3/+64
| | | | | | | | | | | | | | | | | | | | | | | | Some apps operate on the view text based on layout calculations made on the transformed text. This can cause issues (even crashes) if the transformed text is longer than the original, as is often the case with Translate. A previous temporary fix, I685ae4a9752c817db81f0d736f1d746b2e4a9839, ellipsized the translated text. This change fixes it properly by instead padding the original text. A followup change will make this controllable by API instead of padding every TextView. The en space character, U+2002, is used for the padding here. It seems to work well in practice for multiple languages. We don't make this configurable through API as it could make debugging harder (issues triggered by server-side changes). Bug: 179693024 Test: atest CtsTranslationTestCases Test: manual - toggling between original and translated, scrolling, new views appearing, multiple apps Change-Id: I9d7db5d2bc200e4042baf3267796f00cfc298f19
* Add debug log to help to debug translation problem.Joanne Chung2021-04-131-1/+5
| | | | | | | | | | | | There are some issues the resume/finish seems not work well. The debug flag should be enabled manually, but in the most time the user may forget to enable it before testing. Try to enable it in the debug rom to help debugging, we use b/182433547 to trace the disable this check before rom release. Bug: 182433547 Test: manual Change-Id: I2f85a0e17f8a2b8a4b93252044cf48d739b4eca2
* Update View translation APIs.Joanne Chung2021-03-251-0/+120
This change doesn't contain the virtual view part and the API dispatchTranslationRequests, it will be done in another change. Bug: 178046780 Test: manual Test: atest CtsTranslationTestCases CTS-Coverage-Bug: 177960696 Change-Id: I65fe1db19c9dff21c0caca425fbb7d08559e730b