summaryrefslogtreecommitdiffstats
path: root/tests/VoiceInteraction
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-02-25 11:08:11 -0800
committerDianne Hackborn <hackbod@google.com>2015-02-25 17:36:17 -0800
commitffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655 (patch)
tree79ce65f76cff29d67abc6b867f0f79795be7a38b /tests/VoiceInteraction
parent6e53931f49f49245deef8622eb8e7dc6ccf04536 (diff)
downloadframeworks_base-ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655.zip
frameworks_base-ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655.tar.gz
frameworks_base-ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655.tar.bz2
Rework voice interaction session lifecycle.
We now have a formal concept of the session being shown and hidden, with it being able to continue running while hidden as long as there is enough RAM. This changes the flow that a VoiceInteractionSession will see: onCreate() is when it is first created, onCreateContentView() is when its UI first needs to be built, onShow() is called each time it needs to be shown and has the arguments given when the show request was made (which has been renamed from startSession to showSession), and then onHide() will be called when the UI is no longer shown. The methods show() and hide() now allow a VoiceInteractionSession subclass to control when it is shown and hidden, working with the shown state being maintained by the system. Change-Id: Ic4a430ec7e8bf76a5441fd0425e2932806170fcc
Diffstat (limited to 'tests/VoiceInteraction')
-rw-r--r--tests/VoiceInteraction/AndroidManifest.xml3
-rw-r--r--tests/VoiceInteraction/res/layout/test_interaction.xml7
-rw-r--r--tests/VoiceInteraction/res/values/strings.xml1
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java2
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java5
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java52
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java11
7 files changed, 61 insertions, 20 deletions
diff --git a/tests/VoiceInteraction/AndroidManifest.xml b/tests/VoiceInteraction/AndroidManifest.xml
index adf572c..36d5d98 100644
--- a/tests/VoiceInteraction/AndroidManifest.xml
+++ b/tests/VoiceInteraction/AndroidManifest.xml
@@ -16,7 +16,8 @@
android:label="Test Assist Proxy"
android:theme="@android:style/Theme.NoDisplay"
android:excludeFromRecents="true"
- android:noHistory="true">
+ android:noHistory="true"
+ android:taskAffinity="">
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT" />
diff --git a/tests/VoiceInteraction/res/layout/test_interaction.xml b/tests/VoiceInteraction/res/layout/test_interaction.xml
index c4e280e..f4648b5 100644
--- a/tests/VoiceInteraction/res/layout/test_interaction.xml
+++ b/tests/VoiceInteraction/res/layout/test_interaction.xml
@@ -48,4 +48,11 @@
android:text="@string/abortVoice"
/>
+ <Button android:id="@+id/cancel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:text="@string/cancelVoice"
+ />
+
</LinearLayout>
diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml
index 7eec90c..9f99c97 100644
--- a/tests/VoiceInteraction/res/values/strings.xml
+++ b/tests/VoiceInteraction/res/values/strings.xml
@@ -22,6 +22,7 @@
<string name="complete">Complete</string>
<string name="abortVoice">Abort Voice</string>
<string name="completeVoice">Complete Voice</string>
+ <string name="cancelVoice">Cancel</string>
</resources>
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java
index fc04ff5..6a99351 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java
@@ -29,6 +29,6 @@ public class AssistProxyActivity extends Activity {
Intent intent = new Intent(this, MainInteractionService.class);
intent.setAction(Intent.ACTION_ASSIST);
intent.putExtras(getIntent());
- startService(new Intent(this, MainInteractionService.class));
+ startService(intent);
}
}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
index 5d5ae2f..d35bc5c 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
@@ -57,6 +57,11 @@ public class AssistVisualizer extends View {
}
}
+ public void clearAssistData() {
+ mAssistData = null;
+ mTextRects.clear();
+ }
+
void buildTextRects(AssistData.ViewNode root, int parentLeft, int parentTop) {
if (root.getVisibility() != View.VISIBLE) {
return;
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
index 1aeb98a..1e30aff 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
@@ -49,6 +49,7 @@ public class MainInteractionSession extends VoiceInteractionSession
static final int STATE_COMMAND = 3;
static final int STATE_ABORT_VOICE = 4;
static final int STATE_COMPLETE_VOICE = 5;
+ static final int STATE_DONE=6;
int mState = STATE_IDLE;
Request mPendingRequest;
@@ -60,12 +61,26 @@ public class MainInteractionSession extends VoiceInteractionSession
@Override
public void onCreate(Bundle args, int startFlags) {
super.onCreate(args);
- showWindow();
+ }
+
+ @Override
+ public void onShow(Bundle args, int showFlags) {
+ super.onShow(args, showFlags);
+ mState = STATE_IDLE;
mStartIntent = args.getParcelable("intent");
Bundle assist = args.getBundle("assist");
- if (assist != null) {
- parseAssistData(assist);
+ parseAssistData(assist);
+ updateState();
+ }
+
+ @Override
+ public void onHide() {
+ super.onHide();
+ if (mAssistVisualizer != null) {
+ mAssistVisualizer.clearAssistData();
}
+ mState = STATE_DONE;
+ updateState();
}
@Override
@@ -86,7 +101,6 @@ public class MainInteractionSession extends VoiceInteractionSession
mCompleteButton.setOnClickListener(this);
mAbortButton = (Button)mContentView.findViewById(R.id.abort);
mAbortButton.setOnClickListener(this);
- updateState();
return mContentView;
}
@@ -100,23 +114,35 @@ public class MainInteractionSession extends VoiceInteractionSession
}
void parseAssistData(Bundle assistBundle) {
- Bundle assistContext = assistBundle.getBundle(Intent.EXTRA_ASSIST_CONTEXT);
- if (assistContext != null) {
- mAssistData = AssistData.getAssistData(assistContext);
- mAssistData.dump();
- if (mAssistVisualizer != null) {
- mAssistVisualizer.setAssistData(mAssistData);
+ if (assistBundle != null) {
+ Bundle assistContext = assistBundle.getBundle(Intent.EXTRA_ASSIST_CONTEXT);
+ if (assistContext != null) {
+ mAssistData = AssistData.getAssistData(assistContext);
+ mAssistData.dump();
+ if (mAssistVisualizer != null) {
+ mAssistVisualizer.setAssistData(mAssistData);
+ }
+ return;
}
}
+ if (mAssistVisualizer != null) {
+ mAssistVisualizer.clearAssistData();
+ }
}
void updateState() {
if (mState == STATE_IDLE) {
mTopContent.setVisibility(View.VISIBLE);
mBottomContent.setVisibility(View.GONE);
+ mAssistVisualizer.setVisibility(View.VISIBLE);
+ } else if (mState == STATE_DONE) {
+ mTopContent.setVisibility(View.GONE);
+ mBottomContent.setVisibility(View.GONE);
+ mAssistVisualizer.setVisibility(View.GONE);
} else {
mTopContent.setVisibility(View.GONE);
mBottomContent.setVisibility(View.VISIBLE);
+ mAssistVisualizer.setVisibility(View.GONE);
}
mStartButton.setEnabled(mState == STATE_IDLE);
mConfirmButton.setEnabled(mState == STATE_CONFIRM || mState == STATE_COMMAND);
@@ -136,18 +162,12 @@ public class MainInteractionSession extends VoiceInteractionSession
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();
}
}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
index 8522cdc..023e0ec 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
@@ -31,8 +31,10 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
static final String TAG = "TestInteractionActivity";
VoiceInteractor mInteractor;
+ VoiceInteractor.Request mCurrentRequest = null;
Button mAbortButton;
Button mCompleteButton;
+ Button mCancelButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -56,9 +58,11 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
mAbortButton.setOnClickListener(this);
mCompleteButton = (Button)findViewById(R.id.complete);
mCompleteButton.setOnClickListener(this);
+ mCancelButton = (Button)findViewById(R.id.cancel);
+ mCancelButton.setOnClickListener(this);
mInteractor = getVoiceInteractor();
- VoiceInteractor.ConfirmationRequest req = new VoiceInteractor.ConfirmationRequest(
+ mCurrentRequest = new VoiceInteractor.ConfirmationRequest(
"This is a confirmation", null) {
@Override
public void onCancel() {
@@ -72,7 +76,7 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
getActivity().finish();
}
};
- mInteractor.submitRequest(req);
+ mInteractor.submitRequest(mCurrentRequest);
}
@Override
@@ -112,6 +116,9 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
}
};
mInteractor.submitRequest(req);
+ } else if (v == mCancelButton && mCurrentRequest != null) {
+ Log.i(TAG, "Cancel request");
+ mCurrentRequest.cancel();
}
}