UiTranslationStateCallback
interface UiTranslationStateCallback
android.view.translation.UiTranslationStateCallback |
Callback for listening to UI Translation state changes. See android.view.translation.UiTranslationManager#registerUiTranslationStateCallback(java.util.concurrent.Executor,android.view.translation.UiTranslationStateCallback)
.
Prior to Android version android.os.Build.VERSION_CODES#TIRAMISU
:
- Callback methods without
packageName
are invoked. Apps with minSdkVersion lower thanandroid.os.Build.VERSION_CODES#TIRAMISU
must implement those methods if they want to handle the events. - Callback methods for a particular event may be called multiple times consecutively, even when the translation state has not changed (e.g.,
onStarted(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String)
may be called multiple times even after translation has already started).
In Android version android.os.Build.VERSION_CODES#TIRAMISU
and later:
- If both methods with and without
packageName
are implemented (e.g.,onFinished()
andonFinished(java.lang.String)
, only the one withpackageName
will be called. - Callback methods for a particular event will not be called multiple times consecutively. They will only be called when the translation state has actually changed (e.g., from "started" to "paused"). Note: "resumed" is not considered a separate state from "started", so
onResumed(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String)
will never be called afteronStarted(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String)
.<
Summary
Public methods | |
---|---|
abstract Unit |
The UI Translation session has ended. |
open Unit |
onFinished(packageName: String) The UI Translation session has ended. |
abstract Unit |
onPaused() The system is requesting that the application temporarily show the UI contents in their original language. |
open Unit |
The system is requesting that the application temporarily show the UI contents in their original language. |
open Unit |
The system is requesting that the application restore from the temporarily paused state and show the content in the translated language. |
open Unit |
The system is requesting that the application restore from the temporarily paused state and show the content in the translated language. |
open Unit |
The system is requesting translation of the UI from |
open Unit |
The system is requesting translation of the UI from |
Public methods
onFinished
abstract fun onFinished(): Unit
The UI Translation session has ended.
Apps should implement onFinished(java.lang.String)
as well if they need the name of the package that owns the activity being translated.
onFinished
open fun onFinished(packageName: String): Unit
The UI Translation session has ended.
Apps may implement onFinished()
instead if they don't need the name of the package that owns the activity being translated.
Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU
must implement onFinished()
if they want to handle the "finished" event.
Parameters | |
---|---|
packageName |
String: The name of the package that owns the activity being translated. This value cannot be null . |
onPaused
abstract fun onPaused(): Unit
The system is requesting that the application temporarily show the UI contents in their original language.
Apps should implement onPaused(java.lang.String)
as well if they need the name of the package that owns the activity being translated.
onPaused
open fun onPaused(packageName: String): Unit
The system is requesting that the application temporarily show the UI contents in their original language.
Apps may implement onPaused()
instead if they don't need the name of the package that owns the activity being translated.
Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU
must implement onPaused()
if they want to handle the "paused" event.
Parameters | |
---|---|
packageName |
String: This value cannot be null . |
onResumed
open fun onResumed(
sourceLocale: ULocale,
targetLocale: ULocale
): Unit
The system is requesting that the application restore from the temporarily paused state and show the content in the translated language.
Apps should implement onResumed(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String)
instead if they need the name of the package that owns the activity being translated.
Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU
must implement this method if they want to handle the "resumed" event.
Parameters | |
---|---|
sourceLocale |
ULocale: ULocale the UI is being translated from. This value cannot be null . |
targetLocale |
ULocale: ULocale the UI is being translated to. This value cannot be null . |
onResumed
open fun onResumed(
sourceLocale: ULocale,
targetLocale: ULocale,
packageName: String
): Unit
The system is requesting that the application restore from the temporarily paused state and show the content in the translated language.
Apps may implement onResumed(android.icu.util.ULocale,android.icu.util.ULocale)
instead if they don't need the name of the package that owns the activity being translated.
Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU
must implement onResumed(android.icu.util.ULocale,android.icu.util.ULocale)
if they want to handle the "resumed" event.
Parameters | |
---|---|
sourceLocale |
ULocale: ULocale the UI is being translated from. This value cannot be null . |
targetLocale |
ULocale: ULocale the UI is being translated to. This value cannot be null . |
packageName |
String: The name of the package that owns the activity being translated. This value cannot be null . |
onStarted
open fun onStarted(
sourceLocale: ULocale,
targetLocale: ULocale
): Unit
The system is requesting translation of the UI from sourceLocale
to targetLocale
.
This is also called if either the requested sourceLocale
or targetLocale
has changed.
Apps should implement onStarted(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String)
instead if they need the name of the package that owns the activity being translated.
Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU
must implement this method if they want to handle the "started" event.
Parameters | |
---|---|
sourceLocale |
ULocale: ULocale the UI is being translated from. This value cannot be null . |
targetLocale |
ULocale: ULocale the UI is being translated to. This value cannot be null . |
onStarted
open fun onStarted(
sourceLocale: ULocale,
targetLocale: ULocale,
packageName: String
): Unit
The system is requesting translation of the UI from sourceLocale
to targetLocale
.
This is also called if either the requested sourceLocale
or targetLocale
has changed.
Apps may implement onStarted(android.icu.util.ULocale,android.icu.util.ULocale)
instead if they don't need the name of the package that owns the activity being translated.
Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU
must implement onStarted(android.icu.util.ULocale,android.icu.util.ULocale)
if they want to handle the "started" event.
Parameters | |
---|---|
sourceLocale |
ULocale: ULocale the UI is being translated from. This value cannot be null . |
targetLocale |
ULocale: ULocale the UI is being translated to. This value cannot be null . |
packageName |
String: The name of the package that owns the activity being translated. This value cannot be null . |