Added in API level 31

Translator


public class Translator
extends Object

java.lang.Object
   ↳ android.view.translation.Translator


The Translator for translation, defined by a TranslationContext.

Summary

Public methods

void destroy()

Destroy this Translator.

boolean isDestroyed()

Returns whether or not this Translator has been destroyed.

void translate(TranslationRequest request, CancellationSignal cancellationSignal, Executor executor, Consumer<TranslationResponse> callback)

Requests a translation for the provided TranslationRequest using the Translator's source spec and destination spec.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public methods

destroy

Added in API level 31
public void destroy ()

Destroy this Translator.

isDestroyed

Added in API level 31
public boolean isDestroyed ()

Returns whether or not this Translator has been destroyed.

Returns
boolean

See also:

translate

Added in API level 31
public void translate (TranslationRequest request, 
                CancellationSignal cancellationSignal, 
                Executor executor, 
                Consumer<TranslationResponse> callback)

Requests a translation for the provided TranslationRequest using the Translator's source spec and destination spec.

Parameters
request TranslationRequest: TranslationRequest request to be translate. This value cannot be null.

cancellationSignal CancellationSignal: signal to cancel the operation in progress. This value may be null.

executor Executor: Executor to run callback operations This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

callback Consumer: Consumer to receive the translation response. Multiple responses may be received if TranslationRequest.FLAG_PARTIAL_RESPONSES is set. This value cannot be null.

Returns
void This value may be null.

Throws
IllegalStateException if this Translator session was destroyed when called.