diff options
| author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2014-01-29 15:20:06 +0000 |
|---|---|---|
| committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2014-01-30 10:41:26 +0000 |
| commit | 1ca1d886588ce54ab0c0229eabc49fa8dff40bc5 (patch) | |
| tree | 96cf0a2b1e89966ae53a576395b4d6c44c1092e8 /core | |
| parent | 34b16b854ae8c78554a75b136a1df403c385f2e9 (diff) | |
| download | frameworks_base-1ca1d886588ce54ab0c0229eabc49fa8dff40bc5.zip frameworks_base-1ca1d886588ce54ab0c0229eabc49fa8dff40bc5.tar.gz frameworks_base-1ca1d886588ce54ab0c0229eabc49fa8dff40bc5.tar.bz2 | |
Allow clients to extend the TTS UtteranceId class.
This change allows TTS clients to create (and use) classes derived from the
UtteranceId class. This allows to attach a custom data and methods that
can be reached later in callbacks that take the UtteranceId instance as
parameter.
Also, since we can't depend on the identityHashCode results being unique,
this change adds AtomicInteger to generate unique identifiers for UtteranceId
instances.
Bug: 8259486
Change-Id: Id1e9eabc890ec585a7f8570fd20e287dcda9a11d
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/speech/tts/TextToSpeechClient.java | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/core/java/android/speech/tts/TextToSpeechClient.java b/core/java/android/speech/tts/TextToSpeechClient.java index 0d8d42c..c6a14f2 100644 --- a/core/java/android/speech/tts/TextToSpeechClient.java +++ b/core/java/android/speech/tts/TextToSpeechClient.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; /** * Synthesizes speech from text for immediate playback or to create a sound @@ -292,7 +293,8 @@ public final class TextToSpeechClient { * @param msFromStart * Miliseconds from the start of the synthesis. */ - public void onSynthesisProgress(UtteranceId utteranceId, int charIndex, int msFromStart) {} + public void onSynthesisProgress(UtteranceId utteranceId, int charIndex, + int msFromStart) {} } /** @@ -366,38 +368,28 @@ public final class TextToSpeechClient { } /** Unique synthesis request identifier. */ - public static final class UtteranceId { - private final String mDescription; - /** - * Create new, unique UtteranceId instance. - */ - public UtteranceId() { - mDescription = null; - } + public static class UtteranceId { + /** Unique identifier */ + private final int id; + + /** Unique identifier generator */ + private static final AtomicInteger ID_GENERATOR = new AtomicInteger(); /** * Create new, unique UtteranceId instance. - * - * @param description Additional string, that will be appended to - * {@link #toUniqueString()} output, allowing easier identification of the utterance in - * callbacks. */ - public UtteranceId(String description) { - mDescription = description; + public UtteranceId() { + id = ID_GENERATOR.getAndIncrement(); } /** * Returns a unique string associated with an instance of this object. * - * If you subclass {@link UtteranceId} make sure that output of this method is - * consistent across multiple calls and unique for the instance. - * * This string will be used to identify the synthesis request/utterance inside the * TTS service. */ - public String toUniqueString() { - return mDescription == null ? "UtteranceId" + System.identityHashCode(this) : - "UtteranceId" + System.identityHashCode(this) + ": " + mDescription; + public final String toUniqueString() { + return "UID" + id; } } @@ -680,7 +672,8 @@ public final class TextToSpeechClient { public void onFallback(String utteranceIdStr) { synchronized (mLock) { - Pair<UtteranceId, RequestCallbacks> callbacks = getCallback(utteranceIdStr); + Pair<UtteranceId, RequestCallbacks> callbacks = getCallback( + utteranceIdStr); callbacks.second.onSynthesisFallback(callbacks.first); } }; |
