Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.test.assist; |
| 18 | |
| 19 | import android.animation.Animator; |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 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; |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 26 | import android.service.voice.VoiceInteractionSession; |
Jorim Jaggi | 19695d9 | 2015-07-20 15:51:40 -0700 | [diff] [blame] | 27 | import android.util.Log; |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 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; |
| 33 | |
| 34 | /** |
| 35 | * Sample session to show test assist transition. |
| 36 | */ |
| 37 | public 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 Hackborn | 593334a | 2015-06-30 14:38:17 -0700 | [diff] [blame] | 56 | public void onRequestConfirmation(ConfirmationRequest request) { |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
Dianne Hackborn | 593334a | 2015-06-30 14:38:17 -0700 | [diff] [blame] | 60 | public void onRequestPickOption(PickOptionRequest request) { |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
Dianne Hackborn | 593334a | 2015-06-30 14:38:17 -0700 | [diff] [blame] | 64 | public void onRequestCommand(CommandRequest request) { |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Dianne Hackborn | 593334a | 2015-06-30 14:38:17 -0700 | [diff] [blame] | 68 | public void onCancelRequest(Request request) { |
| 69 | } |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 70 | |
Dianne Hackborn | 593334a | 2015-06-30 14:38:17 -0700 | [diff] [blame] | 71 | @Override |
| 72 | public void onCreate() { |
Jorim Jaggi | 19695d9 | 2015-07-20 15:51:40 -0700 | [diff] [blame] | 73 | super.onCreate(); |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 74 | // Simulate slowness of Assist app |
| 75 | try { |
| 76 | Thread.sleep(1000); |
| 77 | } catch (InterruptedException e) { |
| 78 | e.printStackTrace(); |
| 79 | } |
Jorim Jaggi | 90859bc | 2016-06-28 16:25:23 -0700 | [diff] [blame] | 80 | |
| 81 | getWindow().getWindow().getDecorView().setSystemUiVisibility( |
| 82 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 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); |
| 94 | return v; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void onShow(Bundle args, int showFlags) { |
| 99 | super.onShow(args, showFlags); |
Dianne Hackborn | 2ee5c36 | 2015-05-29 17:58:53 -0700 | [diff] [blame] | 100 | if ((showFlags & SHOW_SOURCE_ASSIST_GESTURE) != 0) { |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 101 | 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 Jaggi | 19695d9 | 2015-07-20 15:51:40 -0700 | [diff] [blame] | 113 | @Override |
| 114 | public void onLockscreenShown() { |
| 115 | super.onLockscreenShown(); |
| 116 | Log.i("Assistant", "Lockscreen was shown"); |
| 117 | } |
| 118 | |
Jorim Jaggi | 6e9fa1a | 2015-04-01 13:37:39 -0700 | [diff] [blame] | 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); |
| 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 | } |