1 /*
2  * Copyright (C) 2016 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.systemui.tv.pip;
18 
19 import android.animation.Animator;
20 import android.animation.AnimatorInflater;
21 import android.animation.AnimatorListenerAdapter;
22 import android.animation.AnimatorSet;
23 import android.app.Activity;
24 import android.graphics.drawable.AnimationDrawable;
25 import android.os.Bundle;
26 import android.view.View;
27 import android.view.KeyEvent;
28 import android.widget.ImageView;
29 
30 import com.android.systemui.R;
31 
32 /**
33  * Activity to show an overlay on top of PIP activity to show how to pop up PIP menu.
34  */
35 public class PipOnboardingActivity extends Activity implements PipManager.Listener {
36     private final PipManager mPipManager = PipManager.getInstance();
37     private AnimatorSet mEnterAnimator;
38 
39     @Override
onCreate(Bundle bundle)40     protected void onCreate(Bundle bundle) {
41         super.onCreate(bundle);
42         setContentView(R.layout.tv_pip_onboarding);
43         findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
44             @Override
45             public void onClick(View v) {
46                 finish();
47             }
48         });
49 
50         mPipManager.addListener(this);
51     }
52 
53     @Override
onResume()54     public void onResume() {
55         super.onResume();
56         mEnterAnimator = new AnimatorSet();
57         mEnterAnimator.playTogether(
58                 loadAnimator(R.id.background, R.anim.tv_pip_onboarding_background_enter_animation),
59                 loadAnimator(R.id.remote, R.anim.tv_pip_onboarding_image_enter_animation),
60                 loadAnimator(R.id.remote_button, R.anim.tv_pip_onboarding_image_enter_animation),
61                 loadAnimator(R.id.title, R.anim.tv_pip_onboarding_title_enter_animation),
62                 loadAnimator(R.id.description,
63                         R.anim.tv_pip_onboarding_description_enter_animation),
64                 loadAnimator(R.id.button, R.anim.tv_pip_onboarding_button_enter_animation));
65         mEnterAnimator.addListener(new AnimatorListenerAdapter() {
66             @Override
67             public void onAnimationStart(Animator animation) {
68                 ImageView button = (ImageView) findViewById(R.id.remote_button);
69                 ((AnimationDrawable) button.getDrawable()).start();
70             }
71         });
72         int delay = getResources().getInteger(R.integer.tv_pip_onboarding_anim_start_delay);
73         mEnterAnimator.setStartDelay(delay);
74         mEnterAnimator.start();
75     }
76 
loadAnimator(int viewResId, int animResId)77     private Animator loadAnimator(int viewResId, int animResId) {
78         Animator animator = AnimatorInflater.loadAnimator(this, animResId);
79         animator.setTarget(findViewById(viewResId));
80         return animator;
81     }
82 
83     @Override
onKeyUp(int keyCode, KeyEvent event)84     public boolean onKeyUp(int keyCode, KeyEvent event) {
85         if (mEnterAnimator.isStarted()) {
86             return true;
87         }
88         return super.onKeyUp(keyCode, event);
89     }
90 
91     @Override
onKeyDown(int keyCode, KeyEvent event)92     public boolean onKeyDown(int keyCode, KeyEvent event) {
93         if (mEnterAnimator.isStarted()) {
94             return true;
95         }
96         return super.onKeyDown(keyCode, event);
97     }
98 
99     @Override
onPause()100     public void onPause() {
101         super.onPause();
102         finish();
103     }
104 
105     @Override
onDestroy()106     protected void onDestroy() {
107         super.onDestroy();
108         mPipManager.removeListener(this);
109     }
110 
111     @Override
onPipEntered()112     public void onPipEntered() { }
113 
114     @Override
onPipActivityClosed()115     public void onPipActivityClosed() {
116         finish();
117     }
118 
119     @Override
onShowPipMenu()120     public void onShowPipMenu() {
121         finish();
122     }
123 
124     @Override
onMoveToFullscreen()125     public void onMoveToFullscreen() {
126         finish();
127     }
128 
129     @Override
onPipResizeAboutToStart()130     public void onPipResizeAboutToStart() { }
131 }
132