FileDocCategorySizeDatePackage
MainInteractionSession.javaAPI DocAndroid 5.1 API5462Thu Mar 12 22:22:44 GMT 2015com.android.test.voiceinteraction

MainInteractionSession

public class MainInteractionSession extends android.service.voice.VoiceInteractionSession implements View.OnClickListener

Fields Summary
static final String
TAG
android.content.Intent
mStartIntent
android.view.View
mContentView
android.widget.TextView
mText
android.widget.Button
mStartButton
android.widget.Button
mConfirmButton
android.widget.Button
mCompleteButton
android.widget.Button
mAbortButton
static final int
STATE_IDLE
static final int
STATE_LAUNCHING
static final int
STATE_CONFIRM
static final int
STATE_COMMAND
static final int
STATE_ABORT_VOICE
static final int
STATE_COMPLETE_VOICE
int
mState
Request
mPendingRequest
Constructors Summary
MainInteractionSession(android.content.Context context)


      
        super(context);
    
Methods Summary
public voidonAbortVoice(Caller caller, Request request, java.lang.CharSequence message, android.os.Bundle extras)

        Log.i(TAG, "onAbortVoice: message=" + message + " extras=" + extras);
        mText.setText(message);
        mPendingRequest = request;
        mState = STATE_ABORT_VOICE;
        updateState();
    
public voidonCancel(Request request)

        Log.i(TAG, "onCancel");
        request.sendCancelResult();
    
public voidonClick(android.view.View v)

        if (v == mStartButton) {
            mState = STATE_LAUNCHING;
            updateState();
            startVoiceActivity(mStartIntent);
        } else if (v == mConfirmButton) {
            if (mState == STATE_CONFIRM) {
                mPendingRequest.sendConfirmResult(true, null);
            } else {
                mPendingRequest.sendCommandResult(true, null);
            }
            mPendingRequest = null;
            mState = STATE_IDLE;
            updateState();
        } else if (v == mAbortButton) {
            mPendingRequest.sendAbortVoiceResult(null);
            mPendingRequest = null;
            mState = STATE_IDLE;
            updateState();
        } else if (v== mCompleteButton) {
            mPendingRequest.sendCompleteVoiceResult(null);
            mPendingRequest = null;
            mState = STATE_IDLE;
            updateState();
        }
    
public voidonCommand(Caller caller, Request request, java.lang.String command, android.os.Bundle extras)

        Log.i(TAG, "onCommand: command=" + command + " extras=" + extras);
        mText.setText("Command: " + command);
        mStartButton.setText("Finish Command");
        mPendingRequest = request;
        mState = STATE_COMMAND;
        updateState();
    
public voidonCompleteVoice(Caller caller, Request request, java.lang.CharSequence message, android.os.Bundle extras)

        Log.i(TAG, "onCompleteVoice: message=" + message + " extras=" + extras);
        mText.setText(message);
        mPendingRequest = request;
        mState = STATE_COMPLETE_VOICE;
        updateState();
    
public voidonConfirm(Caller caller, Request request, java.lang.CharSequence prompt, android.os.Bundle extras)

        Log.i(TAG, "onConfirm: prompt=" + prompt + " extras=" + extras);
        mText.setText(prompt);
        mStartButton.setText("Confirm");
        mPendingRequest = request;
        mState = STATE_CONFIRM;
        updateState();
    
public voidonCreate(android.os.Bundle args)

        super.onCreate(args);
        showWindow();
        mStartIntent = args.getParcelable("intent");
    
public android.view.ViewonCreateContentView()

        mContentView = getLayoutInflater().inflate(R.layout.voice_interaction_session, null);
        mText = (TextView)mContentView.findViewById(R.id.text);
        mStartButton = (Button)mContentView.findViewById(R.id.start);
        mStartButton.setOnClickListener(this);
        mConfirmButton = (Button)mContentView.findViewById(R.id.confirm);
        mConfirmButton.setOnClickListener(this);
        mCompleteButton = (Button)mContentView.findViewById(R.id.complete);
        mCompleteButton.setOnClickListener(this);
        mAbortButton = (Button)mContentView.findViewById(R.id.abort);
        mAbortButton.setOnClickListener(this);
        updateState();
        return mContentView;
    
public boolean[]onGetSupportedCommands(Caller caller, java.lang.String[] commands)

        return new boolean[commands.length];
    
voidupdateState()

        mStartButton.setEnabled(mState == STATE_IDLE);
        mConfirmButton.setEnabled(mState == STATE_CONFIRM || mState == STATE_COMMAND);
        mAbortButton.setEnabled(mState == STATE_ABORT_VOICE);
        mCompleteButton.setEnabled(mState == STATE_COMPLETE_VOICE);