1c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James/* 2c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * Copyright (C) 2014 The Android Open Source Project 3c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * 4c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * Licensed under the Apache License, Version 2.0 (the "License"); 5c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * you may not use this file except in compliance with the License. 6c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * You may obtain a copy of the License at 7c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * 8c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * http://www.apache.org/licenses/LICENSE-2.0 9c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * 10c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * Unless required by applicable law or agreed to in writing, software 11c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * distributed under the License is distributed on an "AS IS" BASIS, 12c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * See the License for the specific language governing permissions and 14c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * limitations under the License. 15c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James */ 16c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 17c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamespackage com.android.settings.utils; 18c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 19c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesimport android.app.Activity; 20f79e2d11f5ada36705bef1deb58f0f42504ef327Barnaby Jamesimport android.app.Fragment; 21c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesimport android.app.VoiceInteractor; 226e042caff2553c8f108936e8b0b6de732fe5407cBarnaby Jamesimport android.app.VoiceInteractor.AbortVoiceRequest; 23c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesimport android.app.VoiceInteractor.CompleteVoiceRequest; 24c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesimport android.content.Intent; 25c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesimport android.os.Bundle; 26f79e2d11f5ada36705bef1deb58f0f42504ef327Barnaby Jamesimport android.view.View; 27f79e2d11f5ada36705bef1deb58f0f42504ef327Barnaby Jamesimport android.widget.TextView; 28c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesimport android.util.Log; 29c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 30c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James/** 31c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * Activity for modifying a setting using the Voice Interaction API. This activity 32c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * will only allow modifying the setting if the intent was sent using 33c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * {@link android.service.voice.VoiceInteractionSession#startVoiceActivity startVoiceActivity} 34c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * by the current Voice Interaction Service. 35c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James */ 36c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby Jamesabstract public class VoiceSettingsActivity extends Activity { 37c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 38c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James private static final String TAG = "VoiceSettingsActivity"; 39c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 40c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James @Override 41c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James public void onCreate(Bundle savedInstanceState) { 42c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James super.onCreate(savedInstanceState); 43c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 442dbeb423a91e63e7ccdb67b11d35a841bd8b8babDianne Hackborn if (isVoiceInteractionRoot()) { 45c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James // Only permit if this is a voice interaction. 46c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James if (onVoiceSettingInteraction(getIntent())) { 47c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James // If it's complete, finish. 48c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James finish(); 49c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } 50c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } else { 51c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James Log.v(TAG, "Cannot modify settings without voice interaction"); 52c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James finish(); 53c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } 54c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } 55c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 56c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James /** 57c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * Modify the setting as a voice interaction. Should return true if the 58c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * voice interaction is complete or false if more interaction is required. 59c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James */ 60c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James abstract protected boolean onVoiceSettingInteraction(Intent intent); 61c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 62c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James /** 632dbeb423a91e63e7ccdb67b11d35a841bd8b8babDianne Hackborn * Send a notification that the interaction was successful. If {@param prompt} is 64c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * not null, then it will be read to the user. 65c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James */ 66c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James protected void notifySuccess(CharSequence prompt) { 67c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James if (getVoiceInteractor() != null) { 68c54782071ad7d595162040c3471e5ed416fb52a3Barnaby James getVoiceInteractor().submitRequest(new CompleteVoiceRequest(prompt, null) { 69c54782071ad7d595162040c3471e5ed416fb52a3Barnaby James @Override 70c54782071ad7d595162040c3471e5ed416fb52a3Barnaby James public void onCompleteResult(Bundle options) { 71c54782071ad7d595162040c3471e5ed416fb52a3Barnaby James finish(); 72c54782071ad7d595162040c3471e5ed416fb52a3Barnaby James } 73c54782071ad7d595162040c3471e5ed416fb52a3Barnaby James }); 74c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } 75c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } 76c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James 77c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James /** 78c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James * Indicates when the setting could not be changed. 79c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James */ 806e042caff2553c8f108936e8b0b6de732fe5407cBarnaby James protected void notifyFailure(CharSequence prompt) { 816e042caff2553c8f108936e8b0b6de732fe5407cBarnaby James if (getVoiceInteractor() != null) { 826e042caff2553c8f108936e8b0b6de732fe5407cBarnaby James getVoiceInteractor().submitRequest(new AbortVoiceRequest(prompt, null)); 836e042caff2553c8f108936e8b0b6de732fe5407cBarnaby James } 84c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James } 85c55ea15bc0d9297417a4f1d886b9c188b6bf19b5Barnaby James} 86