From 6e9fa1a4b74dc4e35470739cfd64881cb9bcc7b1 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Wed, 1 Apr 2015 13:37:39 -0700 Subject: [PATCH] Add test assist to implement motion study This change introduces another test VoiceInteractionService, Assist, to test the full SystemUI -> assist layer motion when invoking assist. The old assist test project was renamed to LegacyAssist. Change-Id: Iddf8a36a76083625f8aa4faecef1930e9952d05b --- tests/Assist/Android.mk | 10 + tests/Assist/AndroidManifest.xml | 39 ++++ tests/Assist/res/drawable/assistant.xml | 27 +++ tests/Assist/res/drawable/navbar_scrim.xml | 25 +++ tests/Assist/res/drawable/round_rect.xml | 26 +++ tests/Assist/res/layout/assist.xml | 71 +++++++ tests/Assist/res/values/strings.xml | 28 +++ tests/Assist/res/xml/interaction_service.xml | 21 ++ tests/Assist/res/xml/recognition_service.xml | 18 ++ .../test/assist/AssistInteractionService.java | 23 +++ .../test/assist/AssistInteractionSession.java | 181 ++++++++++++++++++ .../AssistInteractionSessionService.java | 28 +++ .../test/assist/AssistRecognitionService.java | 38 ++++ .../com/android/test/assist/ScrimView.java | 42 ++++ .../{Assistant => LegacyAssistant}/Android.mk | 2 +- .../AndroidManifest.xml | 2 +- .../ic_action_assist_activated.png | Bin .../drawable-hdpi/ic_action_assist_normal.png | Bin .../ic_action_assist_activated.png | Bin .../drawable-mdpi/ic_action_assist_normal.png | Bin .../ic_action_assist_activated.png | Bin .../ic_action_assist_normal.png | Bin .../res/drawable/ic_action_assist.xml | 0 .../res/layout/assist_intent_activity.xml | 0 .../res/values/strings.xml | 0 .../test/legacyassistant}/AssistActivity.java | 4 +- 26 files changed, 581 insertions(+), 4 deletions(-) create mode 100644 tests/Assist/Android.mk create mode 100644 tests/Assist/AndroidManifest.xml create mode 100644 tests/Assist/res/drawable/assistant.xml create mode 100644 tests/Assist/res/drawable/navbar_scrim.xml create mode 100644 tests/Assist/res/drawable/round_rect.xml create mode 100644 tests/Assist/res/layout/assist.xml create mode 100644 tests/Assist/res/values/strings.xml create mode 100644 tests/Assist/res/xml/interaction_service.xml create mode 100644 tests/Assist/res/xml/recognition_service.xml create mode 100644 tests/Assist/src/com/android/test/assist/AssistInteractionService.java create mode 100644 tests/Assist/src/com/android/test/assist/AssistInteractionSession.java create mode 100644 tests/Assist/src/com/android/test/assist/AssistInteractionSessionService.java create mode 100644 tests/Assist/src/com/android/test/assist/AssistRecognitionService.java create mode 100644 tests/Assist/src/com/android/test/assist/ScrimView.java rename tests/{Assistant => LegacyAssistant}/Android.mk (82%) rename tests/{Assistant => LegacyAssistant}/AndroidManifest.xml (96%) rename tests/{Assistant => LegacyAssistant}/res/drawable-hdpi/ic_action_assist_activated.png (100%) rename tests/{Assistant => LegacyAssistant}/res/drawable-hdpi/ic_action_assist_normal.png (100%) rename tests/{Assistant => LegacyAssistant}/res/drawable-mdpi/ic_action_assist_activated.png (100%) rename tests/{Assistant => LegacyAssistant}/res/drawable-mdpi/ic_action_assist_normal.png (100%) rename tests/{Assistant => LegacyAssistant}/res/drawable-xhdpi/ic_action_assist_activated.png (100%) rename tests/{Assistant => LegacyAssistant}/res/drawable-xhdpi/ic_action_assist_normal.png (100%) rename tests/{Assistant => LegacyAssistant}/res/drawable/ic_action_assist.xml (100%) rename tests/{Assistant => LegacyAssistant}/res/layout/assist_intent_activity.xml (100%) rename tests/{Assistant => LegacyAssistant}/res/values/strings.xml (100%) rename tests/{Assistant/src/com/google/android/test/assistant => LegacyAssistant/src/com/google/android/test/legacyassistant}/AssistActivity.java (90%) diff --git a/tests/Assist/Android.mk b/tests/Assist/Android.mk new file mode 100644 index 0000000000000..f31c4ddfbca61 --- /dev/null +++ b/tests/Assist/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := Assist + +include $(BUILD_PACKAGE) diff --git a/tests/Assist/AndroidManifest.xml b/tests/Assist/AndroidManifest.xml new file mode 100644 index 0000000000000..4eceed9d848bf --- /dev/null +++ b/tests/Assist/AndroidManifest.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + diff --git a/tests/Assist/res/drawable/assistant.xml b/tests/Assist/res/drawable/assistant.xml new file mode 100644 index 0000000000000..2a89dda949b9e --- /dev/null +++ b/tests/Assist/res/drawable/assistant.xml @@ -0,0 +1,27 @@ + + + + + diff --git a/tests/Assist/res/drawable/navbar_scrim.xml b/tests/Assist/res/drawable/navbar_scrim.xml new file mode 100644 index 0000000000000..52ed76dd236f8 --- /dev/null +++ b/tests/Assist/res/drawable/navbar_scrim.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/tests/Assist/res/drawable/round_rect.xml b/tests/Assist/res/drawable/round_rect.xml new file mode 100644 index 0000000000000..55937a0a8c4a2 --- /dev/null +++ b/tests/Assist/res/drawable/round_rect.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Assist/res/layout/assist.xml b/tests/Assist/res/layout/assist.xml new file mode 100644 index 0000000000000..8c4be2d03b195 --- /dev/null +++ b/tests/Assist/res/layout/assist.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Assist/res/values/strings.xml b/tests/Assist/res/values/strings.xml new file mode 100644 index 0000000000000..5331457e22b1b --- /dev/null +++ b/tests/Assist/res/values/strings.xml @@ -0,0 +1,28 @@ + + + + + + Start + Confirm + Abort + Complete + Abort Voice + Complete Voice + Pick Voice + Cancel + + diff --git a/tests/Assist/res/xml/interaction_service.xml b/tests/Assist/res/xml/interaction_service.xml new file mode 100644 index 0000000000000..2fd50aae105fd --- /dev/null +++ b/tests/Assist/res/xml/interaction_service.xml @@ -0,0 +1,21 @@ + + + + diff --git a/tests/Assist/res/xml/recognition_service.xml b/tests/Assist/res/xml/recognition_service.xml new file mode 100644 index 0000000000000..5b52c3cac604a --- /dev/null +++ b/tests/Assist/res/xml/recognition_service.xml @@ -0,0 +1,18 @@ + + + + diff --git a/tests/Assist/src/com/android/test/assist/AssistInteractionService.java b/tests/Assist/src/com/android/test/assist/AssistInteractionService.java new file mode 100644 index 0000000000000..e6a671335e179 --- /dev/null +++ b/tests/Assist/src/com/android/test/assist/AssistInteractionService.java @@ -0,0 +1,23 @@ +/* + * 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.assist; + +import android.service.voice.VoiceInteractionService; + +public class AssistInteractionService extends VoiceInteractionService { + +} diff --git a/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java b/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java new file mode 100644 index 0000000000000..0b522c0578bbe --- /dev/null +++ b/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java @@ -0,0 +1,181 @@ +/* + * 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.assist; + +import android.animation.Animator; +import android.animation.RevealAnimator; +import android.animation.ValueAnimator; +import android.app.VoiceInteractor; +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; +import android.os.Handler; +import android.service.voice.VoiceInteractionService; +import android.service.voice.VoiceInteractionSession; +import android.util.Log; +import android.view.View; +import android.view.ViewAnimationUtils; +import android.view.ViewTreeObserver; +import android.view.animation.AnimationUtils; +import android.view.animation.Interpolator; + +/** + * Sample session to show test assist transition. + */ +public class AssistInteractionSession extends VoiceInteractionSession { + + private View mScrim; + private View mBackground; + private View mNavbarScrim; + private View mCard1; + private View mCard2; + + private float mDensity; + + public AssistInteractionSession(Context context) { + super(context); + } + + public AssistInteractionSession(Context context, Handler handler) { + super(context, handler); + } + + @Override + public void onConfirm(Caller caller, + Request request, CharSequence prompt, Bundle extras) { + + } + + @Override + public void onPickOption(Caller caller, + Request request, CharSequence prompt, + VoiceInteractor.PickOptionRequest.Option[] options, Bundle extras) { + + } + + @Override + public void onCommand(Caller caller, + Request request, String command, Bundle extras) { + + } + + @Override + public void onCreate(Bundle args) { + super.onCreate(args); + + // Simulate slowness of Assist app + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Override + public void onCancel(Request request) { + + } + + @Override + public View onCreateContentView() { + View v = getLayoutInflater().inflate(R.layout.assist, null); + mScrim = v.findViewById(R.id.scrim); + mBackground = v.findViewById(R.id.background); + mDensity = mScrim.getResources().getDisplayMetrics().density; + mCard1 = v.findViewById(R.id.card1); + mCard2 = v.findViewById(R.id.card2); + mNavbarScrim = v.findViewById(R.id.navbar_scrim); + return v; + } + + @Override + public void onShow(Bundle args, int showFlags) { + super.onShow(args, showFlags); + if ((showFlags & VoiceInteractionService.START_SOURCE_ASSIST_GESTURE) != 0) { + mBackground.getViewTreeObserver().addOnPreDrawListener( + new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + mBackground.getViewTreeObserver().removeOnPreDrawListener(this); + playAssistAnimation(); + return true; + } + }); + } + } + + private void playAssistAnimation() { + Interpolator linearOutSlowIn = AnimationUtils.loadInterpolator(mBackground.getContext(), + android.R.interpolator.linear_out_slow_in); + Interpolator fastOutSlowIn = AnimationUtils.loadInterpolator(mBackground.getContext(), + android.R.interpolator.fast_out_slow_in); + mScrim.setAlpha(0f); + mScrim.animate() + .alpha(1f) + .setStartDelay(100) + .setDuration(500); + mBackground.setTranslationY(50 * mDensity); + mBackground.animate() + .translationY(0) + .setDuration(300) + .setInterpolator(linearOutSlowIn); + int centerX = mBackground.getWidth()/2; + int centerY = (int) (mBackground.getHeight()/5*3.8f); + int radius = (int) Math.sqrt(centerX*centerX + centerY*centerY) + 1; + Animator animator = ViewAnimationUtils.createCircularReveal(mBackground, centerX, centerY, + 0, radius); + animator.setDuration(300); + animator.setInterpolator(fastOutSlowIn); + animator.start(); + + ValueAnimator colorAnim = ValueAnimator.ofArgb(Color.WHITE, 0xffe0e0e0); + colorAnim.setDuration(300); + colorAnim.setInterpolator(fastOutSlowIn); + colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + mBackground.setBackgroundColor((Integer) animation.getAnimatedValue()); + } + }); + colorAnim.start(); + + + mCard1.setY(mBackground.getHeight()); + mCard2.setTranslationY(mCard1.getTranslationY()); + mCard1.animate() + .translationY(0) + .setDuration(500) + .setInterpolator(linearOutSlowIn) + .setStartDelay(100); + mCard2.animate() + .translationY(0) + .setInterpolator(linearOutSlowIn) + .setStartDelay(150) + .setDuration(500); + + mNavbarScrim.setAlpha(0f); + mNavbarScrim.animate() + .alpha(1f) + .setDuration(500) + .setStartDelay(100); + } + + @Override + public void onHide() { + super.onHide(); + } +} diff --git a/tests/Assist/src/com/android/test/assist/AssistInteractionSessionService.java b/tests/Assist/src/com/android/test/assist/AssistInteractionSessionService.java new file mode 100644 index 0000000000000..3c483d6a66c9a --- /dev/null +++ b/tests/Assist/src/com/android/test/assist/AssistInteractionSessionService.java @@ -0,0 +1,28 @@ +/* + * 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.assist; + +import android.os.Bundle; +import android.service.voice.VoiceInteractionSession; +import android.service.voice.VoiceInteractionSessionService; + +public class AssistInteractionSessionService extends VoiceInteractionSessionService { + @Override + public VoiceInteractionSession onNewSession(Bundle args) { + return new AssistInteractionSession(this); + } +} diff --git a/tests/Assist/src/com/android/test/assist/AssistRecognitionService.java b/tests/Assist/src/com/android/test/assist/AssistRecognitionService.java new file mode 100644 index 0000000000000..6e5faa12bc9ce --- /dev/null +++ b/tests/Assist/src/com/android/test/assist/AssistRecognitionService.java @@ -0,0 +1,38 @@ +/* + * 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.assist; + +import android.content.Intent; +import android.speech.RecognitionService; + +/** + * Stub recognition service needed to be a complete voice interactor. + */ +public class AssistRecognitionService extends RecognitionService { + + @Override + protected void onStartListening(Intent recognizerIntent, Callback listener) { + } + + @Override + protected void onCancel(Callback listener) { + } + + @Override + protected void onStopListening(Callback listener) { + } +} diff --git a/tests/Assist/src/com/android/test/assist/ScrimView.java b/tests/Assist/src/com/android/test/assist/ScrimView.java new file mode 100644 index 0000000000000..1b7387b471f4f --- /dev/null +++ b/tests/Assist/src/com/android/test/assist/ScrimView.java @@ -0,0 +1,42 @@ +/* + * 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.assist; + +import android.annotation.Nullable; +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; + +public class ScrimView extends View { + + public ScrimView(Context context) { + super(context); + } + + public ScrimView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public ScrimView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public boolean hasOverlappingRendering() { + return false; + } +} diff --git a/tests/Assistant/Android.mk b/tests/LegacyAssistant/Android.mk similarity index 82% rename from tests/Assistant/Android.mk rename to tests/LegacyAssistant/Android.mk index bf8cc29e11e3c..0ad48d1ccef0f 100644 --- a/tests/Assistant/Android.mk +++ b/tests/LegacyAssistant/Android.mk @@ -3,7 +3,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-subdir-java-files) -LOCAL_PACKAGE_NAME := Assistant +LOCAL_PACKAGE_NAME := LegacyAssistant LOCAL_MODULE_TAGS := tests LOCAL_CERTIFICATE := platform diff --git a/tests/Assistant/AndroidManifest.xml b/tests/LegacyAssistant/AndroidManifest.xml similarity index 96% rename from tests/Assistant/AndroidManifest.xml rename to tests/LegacyAssistant/AndroidManifest.xml index b5d4d51306026..7ae5103799803 100644 --- a/tests/Assistant/AndroidManifest.xml +++ b/tests/LegacyAssistant/AndroidManifest.xml @@ -15,7 +15,7 @@ --> + package="com.google.android.test.legacyassistant"> diff --git a/tests/Assistant/res/drawable-hdpi/ic_action_assist_activated.png b/tests/LegacyAssistant/res/drawable-hdpi/ic_action_assist_activated.png similarity index 100% rename from tests/Assistant/res/drawable-hdpi/ic_action_assist_activated.png rename to tests/LegacyAssistant/res/drawable-hdpi/ic_action_assist_activated.png diff --git a/tests/Assistant/res/drawable-hdpi/ic_action_assist_normal.png b/tests/LegacyAssistant/res/drawable-hdpi/ic_action_assist_normal.png similarity index 100% rename from tests/Assistant/res/drawable-hdpi/ic_action_assist_normal.png rename to tests/LegacyAssistant/res/drawable-hdpi/ic_action_assist_normal.png diff --git a/tests/Assistant/res/drawable-mdpi/ic_action_assist_activated.png b/tests/LegacyAssistant/res/drawable-mdpi/ic_action_assist_activated.png similarity index 100% rename from tests/Assistant/res/drawable-mdpi/ic_action_assist_activated.png rename to tests/LegacyAssistant/res/drawable-mdpi/ic_action_assist_activated.png diff --git a/tests/Assistant/res/drawable-mdpi/ic_action_assist_normal.png b/tests/LegacyAssistant/res/drawable-mdpi/ic_action_assist_normal.png similarity index 100% rename from tests/Assistant/res/drawable-mdpi/ic_action_assist_normal.png rename to tests/LegacyAssistant/res/drawable-mdpi/ic_action_assist_normal.png diff --git a/tests/Assistant/res/drawable-xhdpi/ic_action_assist_activated.png b/tests/LegacyAssistant/res/drawable-xhdpi/ic_action_assist_activated.png similarity index 100% rename from tests/Assistant/res/drawable-xhdpi/ic_action_assist_activated.png rename to tests/LegacyAssistant/res/drawable-xhdpi/ic_action_assist_activated.png diff --git a/tests/Assistant/res/drawable-xhdpi/ic_action_assist_normal.png b/tests/LegacyAssistant/res/drawable-xhdpi/ic_action_assist_normal.png similarity index 100% rename from tests/Assistant/res/drawable-xhdpi/ic_action_assist_normal.png rename to tests/LegacyAssistant/res/drawable-xhdpi/ic_action_assist_normal.png diff --git a/tests/Assistant/res/drawable/ic_action_assist.xml b/tests/LegacyAssistant/res/drawable/ic_action_assist.xml similarity index 100% rename from tests/Assistant/res/drawable/ic_action_assist.xml rename to tests/LegacyAssistant/res/drawable/ic_action_assist.xml diff --git a/tests/Assistant/res/layout/assist_intent_activity.xml b/tests/LegacyAssistant/res/layout/assist_intent_activity.xml similarity index 100% rename from tests/Assistant/res/layout/assist_intent_activity.xml rename to tests/LegacyAssistant/res/layout/assist_intent_activity.xml diff --git a/tests/Assistant/res/values/strings.xml b/tests/LegacyAssistant/res/values/strings.xml similarity index 100% rename from tests/Assistant/res/values/strings.xml rename to tests/LegacyAssistant/res/values/strings.xml diff --git a/tests/Assistant/src/com/google/android/test/assistant/AssistActivity.java b/tests/LegacyAssistant/src/com/google/android/test/legacyassistant/AssistActivity.java similarity index 90% rename from tests/Assistant/src/com/google/android/test/assistant/AssistActivity.java rename to tests/LegacyAssistant/src/com/google/android/test/legacyassistant/AssistActivity.java index 51894a15efd7f..b3dbb15193595 100644 --- a/tests/Assistant/src/com/google/android/test/assistant/AssistActivity.java +++ b/tests/LegacyAssistant/src/com/google/android/test/legacyassistant/AssistActivity.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.google.android.test.assistant; +package com.google.android.test.legacyassistant; import android.app.Activity; import android.os.Bundle; -import com.google.android.test.assistant.R; +import com.google.android.test.legacyassistant.R; public class AssistActivity extends Activity {