blob: 07186285be2b861c5fc2ad6c04eb36dea9abc969 [file] [log] [blame]
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
15 */
16
17package com.android.test.assist;
18
19import android.animation.Animator;
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070020import android.animation.ValueAnimator;
21import android.app.VoiceInteractor;
22import android.content.Context;
23import android.graphics.Color;
24import android.os.Bundle;
25import android.os.Handler;
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070026import android.service.voice.VoiceInteractionSession;
Jorim Jaggi19695d92015-07-20 15:51:40 -070027import android.util.Log;
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070028import android.view.View;
29import android.view.ViewAnimationUtils;
30import android.view.ViewTreeObserver;
31import android.view.animation.AnimationUtils;
32import android.view.animation.Interpolator;
33
34/**
35 * Sample session to show test assist transition.
36 */
37public class AssistInteractionSession extends VoiceInteractionSession {
38
39 private View mScrim;
40 private View mBackground;
41 private View mNavbarScrim;
42 private View mCard1;
43 private View mCard2;
44
45 private float mDensity;
46
47 public AssistInteractionSession(Context context) {
48 super(context);
49 }
50
51 public AssistInteractionSession(Context context, Handler handler) {
52 super(context, handler);
53 }
54
55 @Override
Dianne Hackborn593334a2015-06-30 14:38:17 -070056 public void onRequestConfirmation(ConfirmationRequest request) {
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070057 }
58
59 @Override
Dianne Hackborn593334a2015-06-30 14:38:17 -070060 public void onRequestPickOption(PickOptionRequest request) {
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070061 }
62
63 @Override
Dianne Hackborn593334a2015-06-30 14:38:17 -070064 public void onRequestCommand(CommandRequest request) {
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070065 }
66
67 @Override
Dianne Hackborn593334a2015-06-30 14:38:17 -070068 public void onCancelRequest(Request request) {
69 }
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070070
Dianne Hackborn593334a2015-06-30 14:38:17 -070071 @Override
72 public void onCreate() {
Jorim Jaggi19695d92015-07-20 15:51:40 -070073 super.onCreate();
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070074 // Simulate slowness of Assist app
75 try {
76 Thread.sleep(1000);
77 } catch (InterruptedException e) {
78 e.printStackTrace();
79 }
Jorim Jaggi90859bc2016-06-28 16:25:23 -070080
81 getWindow().getWindow().getDecorView().setSystemUiVisibility(
82 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070083 }
84
85 @Override
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -070086 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);
94 return v;
95 }
96
97 @Override
98 public void onShow(Bundle args, int showFlags) {
99 super.onShow(args, showFlags);
Dianne Hackborn2ee5c362015-05-29 17:58:53 -0700100 if ((showFlags & SHOW_SOURCE_ASSIST_GESTURE) != 0) {
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -0700101 mBackground.getViewTreeObserver().addOnPreDrawListener(
102 new ViewTreeObserver.OnPreDrawListener() {
103 @Override
104 public boolean onPreDraw() {
105 mBackground.getViewTreeObserver().removeOnPreDrawListener(this);
106 playAssistAnimation();
107 return true;
108 }
109 });
110 }
111 }
112
Jorim Jaggi19695d92015-07-20 15:51:40 -0700113 @Override
114 public void onLockscreenShown() {
115 super.onLockscreenShown();
116 Log.i("Assistant", "Lockscreen was shown");
117 }
118
Jorim Jaggi6e9fa1a2015-04-01 13:37:39 -0700119 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);
124 mScrim.setAlpha(0f);
125 mScrim.animate()
126 .alpha(1f)
127 .setStartDelay(100)
128 .setDuration(500);
129 mBackground.setTranslationY(50 * mDensity);
130 mBackground.animate()
131 .translationY(0)
132 .setDuration(300)
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,
138 0, radius);
139 animator.setDuration(300);
140 animator.setInterpolator(fastOutSlowIn);
141 animator.start();
142
143 ValueAnimator colorAnim = ValueAnimator.ofArgb(Color.WHITE, 0xffe0e0e0);
144 colorAnim.setDuration(300);
145 colorAnim.setInterpolator(fastOutSlowIn);
146 colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
147 @Override
148 public void onAnimationUpdate(ValueAnimator animation) {
149 mBackground.setBackgroundColor((Integer) animation.getAnimatedValue());
150 }
151 });
152 colorAnim.start();
153
154
155 mCard1.setY(mBackground.getHeight());
156 mCard2.setTranslationY(mCard1.getTranslationY());
157 mCard1.animate()
158 .translationY(0)
159 .setDuration(500)
160 .setInterpolator(linearOutSlowIn)
161 .setStartDelay(100);
162 mCard2.animate()
163 .translationY(0)
164 .setInterpolator(linearOutSlowIn)
165 .setStartDelay(150)
166 .setDuration(500);
167
168 mNavbarScrim.setAlpha(0f);
169 mNavbarScrim.animate()
170 .alpha(1f)
171 .setDuration(500)
172 .setStartDelay(100);
173 }
174
175 @Override
176 public void onHide() {
177 super.onHide();
178 }
179}