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.tts; 18 19 import android.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.speech.tts.TextToSpeech; 23 import android.speech.tts.TtsEngines; 24 25 import com.android.car.settings.common.ButtonPreference; 26 import com.android.car.settings.common.FragmentController; 27 import com.android.car.settings.common.Logger; 28 import com.android.car.settings.common.PreferenceController; 29 30 /** Business logic to set the summary for the preferred engine entry setting. */ 31 public class PreferredEngineEntryPreferenceController extends 32 PreferenceController<ButtonPreference> { 33 34 private static final Logger LOG = new Logger(PreferredEngineEntryPreferenceController.class); 35 private TtsEngines mEnginesHelper; 36 PreferredEngineEntryPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)37 public PreferredEngineEntryPreferenceController(Context context, String preferenceKey, 38 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 39 super(context, preferenceKey, fragmentController, uxRestrictions); 40 mEnginesHelper = new TtsEngines(context); 41 } 42 43 @Override getPreferenceType()44 protected Class<ButtonPreference> getPreferenceType() { 45 return ButtonPreference.class; 46 } 47 48 @Override onCreateInternal()49 protected void onCreateInternal() { 50 getPreference().setOnButtonClickListener(preference -> { 51 TextToSpeech.EngineInfo info = mEnginesHelper.getEngineInfo( 52 mEnginesHelper.getDefaultEngine()); 53 Intent subSettingsIntent = mEnginesHelper.getSettingsIntent(info.name); 54 if (subSettingsIntent != null) { 55 getContext().startActivity(subSettingsIntent); 56 } else { 57 LOG.e("subSettingsIntent is null"); 58 } 59 }); 60 } 61 62 @Override updateState(ButtonPreference preference)63 protected void updateState(ButtonPreference preference) { 64 TextToSpeech.EngineInfo info = mEnginesHelper.getEngineInfo( 65 mEnginesHelper.getDefaultEngine()); 66 preference.setSummary(info.label); 67 } 68 } 69