| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.speech.tts; |
| 18 |
|
| 19 |
import android.speech.tts.SynthesisCallback; |
| 20 |
import android.speech.tts.SynthesisRequest; |
| 21 |
import android.speech.tts.TextToSpeechService; |
| 22 |
import android.util.Log; |
| 23 |
|
| 24 |
import java.util.ArrayList; |
| 25 |
import java.util.logging.Logger; |
| 26 |
|
| 27 |
public class MockableTextToSpeechService extends TextToSpeechService { |
| 28 |
|
| 29 |
private static IDelegate sDelegate; |
| 30 |
|
| 31 |
public static void setMocker(IDelegate delegate) { |
| 32 |
sDelegate = delegate; |
| 33 |
} |
| 34 |
|
| 35 |
static IDelegate getMocker() { |
| 36 |
return sDelegate; |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
protected int onIsLanguageAvailable(String lang, String country, String variant) { |
| 41 |
return sDelegate.onIsLanguageAvailable(lang, country, variant); |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
protected String[] onGetLanguage() { |
| 46 |
return sDelegate.onGetLanguage(); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
protected int onLoadLanguage(String lang, String country, String variant) { |
| 51 |
return sDelegate.onLoadLanguage(lang, country, variant); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
protected void onStop() { |
| 56 |
sDelegate.onStop(); |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
protected void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback) { |
| 61 |
sDelegate.onSynthesizeText(request, callback); |
| 62 |
} |
| 63 |
|
| 64 |
public static interface IDelegate { |
| 65 |
int onIsLanguageAvailable(String lang, String country, String variant); |
| 66 |
|
| 67 |
String[] onGetLanguage(); |
| 68 |
|
| 69 |
int onLoadLanguage(String lang, String country, String variant); |
| 70 |
|
| 71 |
void onStop(); |
| 72 |
|
| 73 |
void onSynthesizeText(SynthesisRequest request, SynthesisCallback callback); |
| 74 |
|
| 75 |
ArrayList<String> getAvailableVoices(); |
| 76 |
|
| 77 |
ArrayList<String> getUnavailableVoices(); |
| 78 |
} |
| 79 |
|
| 80 |
} |