1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.settings.testutils; 18 19 import android.content.Intent; 20 import android.speech.tts.TextToSpeech; 21 import android.speech.tts.TtsEngines; 22 23 import org.robolectric.annotation.Implementation; 24 import org.robolectric.annotation.Implements; 25 import org.robolectric.annotation.Resetter; 26 27 import java.util.List; 28 import java.util.Locale; 29 30 @Implements(TtsEngines.class) 31 public class ShadowTtsEngines { 32 private static TtsEngines sInstance; 33 setInstance(TtsEngines ttsEngines)34 public static void setInstance(TtsEngines ttsEngines) { 35 sInstance = ttsEngines; 36 } 37 38 @Resetter reset()39 public static void reset() { 40 sInstance = null; 41 } 42 43 @Implementation getEngines()44 protected List<TextToSpeech.EngineInfo> getEngines() { 45 return sInstance.getEngines(); 46 } 47 48 @Implementation getEngineInfo(String packageName)49 protected TextToSpeech.EngineInfo getEngineInfo(String packageName) { 50 return sInstance.getEngineInfo(packageName); 51 } 52 53 @Implementation getDefaultEngine()54 protected String getDefaultEngine() { 55 return sInstance.getDefaultEngine(); 56 } 57 58 @Implementation getSettingsIntent(String engine)59 protected Intent getSettingsIntent(String engine) { 60 return sInstance.getSettingsIntent(engine); 61 } 62 63 @Implementation isLocaleSetToDefaultForEngine(String engineName)64 protected boolean isLocaleSetToDefaultForEngine(String engineName) { 65 return sInstance.isLocaleSetToDefaultForEngine(engineName); 66 } 67 68 @Implementation getLocalePrefForEngine(String engineName)69 protected Locale getLocalePrefForEngine(String engineName) { 70 return sInstance.getLocalePrefForEngine(engineName); 71 } 72 73 @Implementation updateLocalePrefForEngine(String engineName, Locale newLocale)74 protected synchronized void updateLocalePrefForEngine(String engineName, Locale newLocale) { 75 sInstance.updateLocalePrefForEngine(engineName, newLocale); 76 } 77 78 @Implementation parseLocaleString(String localeString)79 protected Locale parseLocaleString(String localeString) { 80 return sInstance.parseLocaleString(localeString); 81 } 82 } 83