FileDocCategorySizeDatePackage
ScoAudioTest.javaAPI DocAndroid 5.1 API28838Thu Mar 12 22:22:30 GMT 2015com.android.scoaudiotest

ScoAudioTest

public class ScoAudioTest extends android.app.Activity

Fields Summary
static final String
TAG
android.media.AudioManager
mAudioManager
android.media.AudioManager
mAudioManager2
boolean
mForceScoOn
android.widget.ToggleButton
mScoButton
android.widget.ToggleButton
mVoiceDialerButton
boolean
mVoiceDialerOn
String
mLastRecordedFile
SimpleMediaController[]
mMediaControllers
private android.speech.tts.TextToSpeech
mTts
private HashMap
mTtsParams
private int
mOriginalVoiceVolume
android.widget.EditText
mSpeakText
boolean
mTtsInited
private android.os.Handler
mHandler
private static final String
UTTERANCE
private static android.content.Intent
sVoiceCommandIntent
private File
mSampleFile
android.widget.ToggleButton
mTtsToFileButton
private boolean
mTtsToFile
private int
mCurrentMode
android.widget.Spinner
mModeSpinner
private android.bluetooth.BluetoothHeadset
mBluetoothHeadset
private android.bluetooth.BluetoothDevice
mBluetoothHeadsetDevice
android.widget.TextView
mScoStateTxt
android.widget.TextView
mVdStateTxt
private final android.content.BroadcastReceiver
mReceiver
private android.widget.CompoundButton.OnCheckedChangeListener
mForceScoChanged
private android.widget.CompoundButton.OnCheckedChangeListener
mVoiceDialerChanged
private android.widget.CompoundButton.OnCheckedChangeListener
mTtsToFileChanged
private View.OnKeyListener
mSpeakKeyListener
private static final String[]
mModeStrings
private Spinner.OnItemSelectedListener
mModeChanged
private BluetoothProfile.ServiceListener
mBluetoothProfileServiceListener
private int
mChangedState
private int
mUpdatedState
private int
mUpdatedPrevState
Constructors Summary
public ScoAudioTest()


      
        Log.e(TAG, "contructor");
    
Methods Summary
public voidonCreate(android.os.Bundle icicle)
Called when the activity is first created.

        super.onCreate(icicle);
        
        setContentView(R.layout.scoaudiotest);

        mScoStateTxt = (TextView) findViewById(R.id.scoStateTxt);
        mVdStateTxt = (TextView) findViewById(R.id.vdStateTxt);

        IntentFilter intentFilter =
            new IntentFilter(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
        intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
        intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
        registerReceiver(mReceiver, intentFilter);

        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        mAudioManager2 = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
        mHandler = new Handler();
        
        mMediaControllers[0] = new SimplePlayerController(this, R.id.playPause1, R.id.stop1,
                R.raw.sine440_mo_16b_16k, AudioManager.STREAM_BLUETOOTH_SCO);
        TextView name = (TextView) findViewById(R.id.playPause1Text);
        name.setText("VOICE_CALL stream");
        
        mScoButton = (ToggleButton)findViewById(R.id.ForceScoButton);
        mScoButton.setOnCheckedChangeListener(mForceScoChanged);
        mForceScoOn = false;
        mScoButton.setChecked(mForceScoOn);

        mVoiceDialerButton = (ToggleButton)findViewById(R.id.VoiceDialerButton);
        mVoiceDialerButton.setOnCheckedChangeListener(mVoiceDialerChanged);
        mVoiceDialerOn = false;
        mVoiceDialerButton.setChecked(mVoiceDialerOn);

        
        mMediaControllers[1] = new SimpleRecordController(this, R.id.recStop1, 0, "Sco_record_");
        mTtsInited = false;
        mTts = new TextToSpeech(this, new TtsInitListener());
        mTtsParams = new HashMap<String, String>();
        mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
                String.valueOf(AudioManager.STREAM_BLUETOOTH_SCO));
        mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
                UTTERANCE);

        mSpeakText = (EditText) findViewById(R.id.speakTextEdit);        
        mSpeakText.setOnKeyListener(mSpeakKeyListener);
        mSpeakText.setText("sco audio test sentence");
        mTtsToFileButton = (ToggleButton)findViewById(R.id.TtsToFileButton);
        mTtsToFileButton.setOnCheckedChangeListener(mTtsToFileChanged);
        mTtsToFile = true;
        mTtsToFileButton.setChecked(mTtsToFile);

        mModeSpinner = (Spinner) findViewById(R.id.modeSpinner);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, mModeStrings);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mModeSpinner.setAdapter(adapter);
        mModeSpinner.setOnItemSelectedListener(mModeChanged);
        mCurrentMode = mAudioManager.getMode();
        mModeSpinner.setSelection(mCurrentMode);

        mBluetoothHeadsetDevice = null;
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        if (btAdapter != null) {
            btAdapter.getProfileProxy(this, mBluetoothProfileServiceListener,
                                    BluetoothProfile.HEADSET);
        }

        sVoiceCommandIntent = new Intent(Intent.ACTION_VOICE_COMMAND);
        sVoiceCommandIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
public voidonDestroy()

        super.onDestroy();
        mTts.shutdown();
        unregisterReceiver(mReceiver);
        if (mBluetoothHeadset != null) {
            BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
            if (btAdapter != null) {
                btAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
            }
        }
    
protected voidonPause()

        super.onPause();
//        mForceScoOn = false;
//        mScoButton.setChecked(mForceScoOn);
        mMediaControllers[0].stop();        
        mMediaControllers[1].stop();
        mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO,
                mOriginalVoiceVolume, 0);
    
protected voidonResume()

        super.onResume();
        mLastRecordedFile = "";
        mMediaControllers[0].mFileName = "";
        mOriginalVoiceVolume = mAudioManager.getStreamVolume(
                AudioManager.STREAM_BLUETOOTH_SCO);
        setVolumeControlStream(AudioManager.STREAM_BLUETOOTH_SCO);
        mCurrentMode = mAudioManager.getMode();
        mModeSpinner.setSelection(mCurrentMode);