summaryrefslogtreecommitdiffstats
path: root/tests/VoiceInteraction/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'tests/VoiceInteraction/src/com')
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java34
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java95
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java17
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java54
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java5
5 files changed, 196 insertions, 9 deletions
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java
new file mode 100644
index 0000000..fc04ff5
--- /dev/null
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistProxyActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.voiceinteraction;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class AssistProxyActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ finish();
+ Intent intent = new Intent(this, MainInteractionService.class);
+ intent.setAction(Intent.ACTION_ASSIST);
+ intent.putExtras(getIntent());
+ startService(new Intent(this, MainInteractionService.class));
+ }
+}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
new file mode 100644
index 0000000..5d5ae2f
--- /dev/null
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/AssistVisualizer.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.voiceinteraction;
+
+import android.annotation.Nullable;
+import android.app.AssistData;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+
+import java.util.ArrayList;
+
+public class AssistVisualizer extends View {
+ static final String TAG = "AssistVisualizer";
+
+ AssistData mAssistData;
+ final Paint mFramePaint = new Paint();
+ final ArrayList<Rect> mTextRects = new ArrayList<>();
+ final int[] mTmpLocation = new int[2];
+
+ public AssistVisualizer(Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ setWillNotDraw(false);
+ mFramePaint.setColor(0xffff0000);
+ mFramePaint.setStyle(Paint.Style.STROKE);
+ mFramePaint.setStrokeWidth(0);
+ }
+
+ public void setAssistData(AssistData ad) {
+ mAssistData = ad;
+ mTextRects.clear();
+ final int N = ad.getWindowCount();
+ if (N > 0) {
+ AssistData.ViewNode window = new AssistData.ViewNode();
+ for (int i=0; i<N; i++) {
+ ad.getWindowAt(i, window);
+ buildTextRects(window, 0, 0);
+ }
+ }
+ }
+
+ void buildTextRects(AssistData.ViewNode root, int parentLeft, int parentTop) {
+ if (root.getVisibility() != View.VISIBLE) {
+ return;
+ }
+ int left = parentLeft+root.getLeft();
+ int top = parentTop+root.getTop();
+ Log.d(TAG, "View " + root.getClassName() + ": " + left + ", " + top);
+ if (root.getText() != null) {
+ Rect r = new Rect(left, top, left+root.getWidth(), top+root.getHeight());
+ Log.d(TAG, "Text Rect " + r.toShortString() + ": " + root.getText());
+ mTextRects.add(r);
+ }
+ final int N = root.getChildCount();
+ if (N > 0) {
+ left -= root.getScrollX();
+ top -= root.getScrollY();
+ AssistData.ViewNode child = new AssistData.ViewNode();
+ for (int i=0; i<N; i++) {
+ root.getChildAt(i, child);
+ buildTextRects(child, left, top);
+ }
+ }
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ getLocationOnScreen(mTmpLocation);
+ final int N = mTextRects.size();
+ for (int i=0; i<N; i++) {
+ Rect r = mTextRects.get(i);
+ canvas.drawRect(r.left-mTmpLocation[0], r.top-mTmpLocation[1],
+ r.right-mTmpLocation[0], r.bottom-mTmpLocation[1], mFramePaint);
+ }
+ }
+}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java
index 4639114..2cab3ea 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java
@@ -16,6 +16,7 @@
package com.android.test.voiceinteraction;
+import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.service.voice.AlwaysOnHotwordDetector;
@@ -74,9 +75,19 @@ public class MainInteractionService extends VoiceInteractionService {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- Bundle args = new Bundle();
- args.putParcelable("intent", new Intent(this, TestInteractionActivity.class));
- startSession(args);
+ if (isActiveService(this, new ComponentName(this, getClass()))) {
+ Bundle args = new Bundle();
+ args.putParcelable("intent", new Intent(this, TestInteractionActivity.class));
+ args.putBundle("assist", intent.getExtras());
+ Bundle assistContext = intent.getBundleExtra(Intent.EXTRA_ASSIST_CONTEXT);
+ int startFlags = 0;
+ if (assistContext == null) {
+ startFlags |= START_WITH_ASSIST;
+ }
+ startSession(args, startFlags);
+ } else {
+ Log.w(TAG, "Not starting -- not current voice interaction service");
+ }
stopSelf(startId);
return START_NOT_STICKY;
}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
index d20906e..1aeb98a 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java
@@ -16,6 +16,7 @@
package com.android.test.voiceinteraction;
+import android.app.AssistData;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -31,12 +32,17 @@ public class MainInteractionSession extends VoiceInteractionSession
Intent mStartIntent;
View mContentView;
+ AssistVisualizer mAssistVisualizer;
+ View mTopContent;
+ View mBottomContent;
TextView mText;
Button mStartButton;
Button mConfirmButton;
Button mCompleteButton;
Button mAbortButton;
+ AssistData mAssistData;
+
static final int STATE_IDLE = 0;
static final int STATE_LAUNCHING = 1;
static final int STATE_CONFIRM = 2;
@@ -52,15 +58,25 @@ public class MainInteractionSession extends VoiceInteractionSession
}
@Override
- public void onCreate(Bundle args) {
+ public void onCreate(Bundle args, int startFlags) {
super.onCreate(args);
showWindow();
mStartIntent = args.getParcelable("intent");
+ Bundle assist = args.getBundle("assist");
+ if (assist != null) {
+ parseAssistData(assist);
+ }
}
@Override
public View onCreateContentView() {
mContentView = getLayoutInflater().inflate(R.layout.voice_interaction_session, null);
+ mAssistVisualizer = (AssistVisualizer)mContentView.findViewById(R.id.assist_visualizer);
+ if (mAssistData != null) {
+ mAssistVisualizer.setAssistData(mAssistData);
+ }
+ mTopContent = mContentView.findViewById(R.id.top_content);
+ mBottomContent = mContentView.findViewById(R.id.bottom_content);
mText = (TextView)mContentView.findViewById(R.id.text);
mStartButton = (Button)mContentView.findViewById(R.id.start);
mStartButton.setOnClickListener(this);
@@ -74,7 +90,34 @@ public class MainInteractionSession extends VoiceInteractionSession
return mContentView;
}
+ @Override
+ public void onHandleAssist(Bundle assistBundle) {
+ if (assistBundle != null) {
+ parseAssistData(assistBundle);
+ } else {
+ Log.i(TAG, "onHandleAssist: NO ASSIST BUNDLE");
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+
void updateState() {
+ if (mState == STATE_IDLE) {
+ mTopContent.setVisibility(View.VISIBLE);
+ mBottomContent.setVisibility(View.GONE);
+ } else {
+ mTopContent.setVisibility(View.GONE);
+ mBottomContent.setVisibility(View.VISIBLE);
+ }
mStartButton.setEnabled(mState == STATE_IDLE);
mConfirmButton.setEnabled(mState == STATE_CONFIRM || mState == STATE_COMMAND);
mAbortButton.setEnabled(mState == STATE_ABORT_VOICE);
@@ -109,6 +152,15 @@ public class MainInteractionSession extends VoiceInteractionSession
}
@Override
+ public void onComputeInsets(Insets outInsets) {
+ super.onComputeInsets(outInsets);
+ if (mState != STATE_IDLE) {
+ outInsets.contentInsets.top = mBottomContent.getTop();
+ outInsets.touchableInsets = Insets.TOUCHABLE_INSETS_CONTENT;
+ }
+ }
+
+ @Override
public boolean[] onGetSupportedCommands(Caller caller, String[] commands) {
return new boolean[commands.length];
}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
index 783c78e..8522cdc 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java
@@ -57,11 +57,6 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis
mCompleteButton = (Button)findViewById(R.id.complete);
mCompleteButton.setOnClickListener(this);
- // Framework should take care of these.
- getWindow().setGravity(Gravity.TOP);
- getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
-
mInteractor = getVoiceInteractor();
VoiceInteractor.ConfirmationRequest req = new VoiceInteractor.ConfirmationRequest(
"This is a confirmation", null) {