2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 package com.android.test.assist;
19 import android.animation.Animator;
20 import android.animation.ValueAnimator;
21 import android.app.VoiceInteractor;
22 import android.content.Context;
23 import android.graphics.Color;
24 import android.os.Bundle;
25 import android.os.Handler;
26 import android.service.voice.VoiceInteractionSession;
27 import android.util.Log;
28 import android.view.View;
29 import android.view.ViewAnimationUtils;
30 import android.view.ViewTreeObserver;
31 import android.view.animation.AnimationUtils;
32 import android.view.animation.Interpolator;
35 * Sample session to show test assist transition.
37 public class AssistInteractionSession extends VoiceInteractionSession {
40 private View mBackground;
41 private View mNavbarScrim;
45 private float mDensity;
47 public AssistInteractionSession(Context context) {
51 public AssistInteractionSession(Context context, Handler handler) {
52 super(context, handler);
56 public void onRequestConfirmation(ConfirmationRequest request) {
60 public void onRequestPickOption(PickOptionRequest request) {
64 public void onRequestCommand(CommandRequest request) {
68 public void onCancelRequest(Request request) {
72 public void onCreate() {
74 // Simulate slowness of Assist app
77 } catch (InterruptedException e) {
81 getWindow().getWindow().getDecorView().setSystemUiVisibility(
82 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
86 public View onCreateContentView() {
87 View v = getLayoutInflater().inflate(R.layout.assist, null);
88 mScrim = v.findViewById(R.id.scrim);
89 mBackground = v.findViewById(R.id.background);
90 mDensity = mScrim.getResources().getDisplayMetrics().density;
91 mCard1 = v.findViewById(R.id.card1);
92 mCard2 = v.findViewById(R.id.card2);
93 mNavbarScrim = v.findViewById(R.id.navbar_scrim);
98 public void onShow(Bundle args, int showFlags) {
99 super.onShow(args, showFlags);
100 if ((showFlags & SHOW_SOURCE_ASSIST_GESTURE) != 0) {
101 mBackground.getViewTreeObserver().addOnPreDrawListener(
102 new ViewTreeObserver.OnPreDrawListener() {
104 public boolean onPreDraw() {
105 mBackground.getViewTreeObserver().removeOnPreDrawListener(this);
106 playAssistAnimation();
114 public void onLockscreenShown() {
115 super.onLockscreenShown();
116 Log.i("Assistant", "Lockscreen was shown");
119 private void playAssistAnimation() {
120 Interpolator linearOutSlowIn = AnimationUtils.loadInterpolator(mBackground.getContext(),
121 android.R.interpolator.linear_out_slow_in);
122 Interpolator fastOutSlowIn = AnimationUtils.loadInterpolator(mBackground.getContext(),
123 android.R.interpolator.fast_out_slow_in);
129 mBackground.setTranslationY(50 * mDensity);
130 mBackground.animate()
133 .setInterpolator(linearOutSlowIn);
134 int centerX = mBackground.getWidth()/2;
135 int centerY = (int) (mBackground.getHeight()/5*3.8f);
136 int radius = (int) Math.sqrt(centerX*centerX + centerY*centerY) + 1;
137 Animator animator = ViewAnimationUtils.createCircularReveal(mBackground, centerX, centerY,
139 animator.setDuration(300);
140 animator.setInterpolator(fastOutSlowIn);
143 ValueAnimator colorAnim = ValueAnimator.ofArgb(Color.WHITE, 0xffe0e0e0);
144 colorAnim.setDuration(300);
145 colorAnim.setInterpolator(fastOutSlowIn);
146 colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
148 public void onAnimationUpdate(ValueAnimator animation) {
149 mBackground.setBackgroundColor((Integer) animation.getAnimatedValue());
155 mCard1.setY(mBackground.getHeight());
156 mCard2.setTranslationY(mCard1.getTranslationY());
160 .setInterpolator(linearOutSlowIn)
164 .setInterpolator(linearOutSlowIn)
168 mNavbarScrim.setAlpha(0f);
169 mNavbarScrim.animate()
176 public void onHide() {