diff options
Diffstat (limited to 'tests')
8 files changed, 238 insertions, 27 deletions
diff --git a/tests/VoiceInteraction/AndroidManifest.xml b/tests/VoiceInteraction/AndroidManifest.xml index 06d31a4..adf572c 100644 --- a/tests/VoiceInteraction/AndroidManifest.xml +++ b/tests/VoiceInteraction/AndroidManifest.xml @@ -12,11 +12,19 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> - <activity android:name="SettingsActivity" - android:label="Voice Interaction Settings" + <activity android:name="AssistProxyActivity" + android:label="Test Assist Proxy" + android:theme="@android:style/Theme.NoDisplay" android:excludeFromRecents="true" android:noHistory="true"> <intent-filter> + <action android:name="android.intent.action.ASSIST" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity> + <activity android:name="SettingsActivity" + android:label="Voice Interaction Settings"> + <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> @@ -44,7 +52,7 @@ <meta-data android:name="android.speech" android:resource="@xml/recognition_service" /> </service> <activity android:name="TestInteractionActivity" android:label="Voice Interaction Target" - android:theme="@android:style/Theme.Material.Light.Voice"> + android:theme="@android:style/Theme.Material.Light"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <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 d55736f..c4e280e 100644 --- a/tests/VoiceInteraction/res/layout/test_interaction.xml +++ b/tests/VoiceInteraction/res/layout/test_interaction.xml @@ -32,7 +32,6 @@ android:layout_weight="1" android:layout_marginTop="16dp" android:textAppearance="?android:attr/textAppearanceMedium" - android:textColor="#ffffffff" /> <Button android:id="@+id/complete" diff --git a/tests/VoiceInteraction/res/layout/voice_interaction_session.xml b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml index 002f350..1057176 100644 --- a/tests/VoiceInteraction/res/layout/voice_interaction_session.xml +++ b/tests/VoiceInteraction/res/layout/voice_interaction_session.xml @@ -15,24 +15,46 @@ --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" - android:layout_height="match_parent" - android:fitsSystemWindows="true"> + android:layout_width="match_parent" + android:layout_height="match_parent"> - <FrameLayout android:layout_width="fill_parent" + <com.android.test.voiceinteraction.AssistVisualizer android:id="@+id/assist_visualizer" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="8dp"> + android:fitsSystemWindows="true"> - <LinearLayout android:id="@+id/content" - android:layout_width="fill_parent" - android:layout_height="match_parent" + <FrameLayout android:id="@+id/top_content" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="top" + android:orientation="vertical" + android:background="#ffffffff" + android:elevation="8dp" + > + + <Button android:id="@+id/start" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="top|right" + android:text="@string/start" + /> + + </FrameLayout> + + <LinearLayout android:id="@+id/bottom_content" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" android:orientation="vertical" android:background="#ffffffff" android:elevation="8dp" > <TextView android:id="@+id/text" - android:layout_width="fill_parent" + android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:textAppearance="?android:attr/textAppearanceMedium" @@ -40,11 +62,6 @@ <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> - <Button android:id="@+id/start" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/start" - /> <Button android:id="@+id/confirm" android:layout_width="wrap_content" android:layout_height="wrap_content" 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) { |
