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.tv.ui; 18 19 import android.animation.TimeInterpolator; 20 import android.content.Context; 21 import android.graphics.drawable.AnimationDrawable; 22 import android.util.AttributeSet; 23 import android.view.KeyEvent; 24 import android.view.View; 25 26 import com.android.tv.R; 27 import com.android.tv.menu.Menu; 28 29 public class IntroView extends FullscreenDialogView { 30 private AnimationDrawable mRippleDrawable; 31 private boolean mOpenMenu; 32 33 public IntroView(Context context) { 34 this(context, null, 0); 35 } 36 37 public IntroView(Context context, AttributeSet attrs) { 38 this(context, attrs, 0); 39 } 40 41 public IntroView(Context context, AttributeSet attrs, int defStyle) { 42 super(context, attrs, defStyle); 43 } 44 45 @Override 46 public boolean dispatchKeyEvent(KeyEvent event) { 47 if (event.getAction() == KeyEvent.ACTION_UP) { 48 switch (event.getKeyCode()) { 49 case KeyEvent.KEYCODE_DPAD_CENTER: 50 case KeyEvent.KEYCODE_ENTER: 51 dismiss(); 52 mOpenMenu = true; 53 return true; 54 } 55 } 56 return super.dispatchKeyEvent(event); 57 } 58 59 @Override 60 public void onBackPressed() { 61 dismiss(); 62 } 63 64 @Override 65 protected void onAttachedToWindow() { 66 super.onAttachedToWindow(); 67 View v = findViewById(R.id.welcome_ripple); 68 mRippleDrawable = (AnimationDrawable) v.getBackground(); 69 mRippleDrawable.start(); 70 } 71 72 @Override 73 protected void onDetachedFromWindow() { 74 mRippleDrawable.stop(); 75 super.onDetachedFromWindow(); 76 } 77 78 @Override 79 public void onDestroy() { 80 if (mOpenMenu) { 81 getActivity().getOverlayManager().showMenu(Menu.REASON_GUIDE); 82 } 83 } 84 85 @Override 86 protected void onStartEnterAnimation(TimeInterpolator interpolator, long duration) { 87 View v = findViewById(R.id.container); 88 v.setAlpha(0); 89 v.animate() 90 .alpha(1.0f) 91 .setInterpolator(interpolator) 92 .setDuration(duration) 93 .withLayer() 94 .start(); 95 } 96 97 @Override 98 protected void onStartExitAnimation(TimeInterpolator interpolator, long duration, 99 final Runnable onAnimationEnded) { 100 View v = findViewById(R.id.container); 101 v.animate() 102 .alpha(0.0f) 103 .setInterpolator(interpolator) 104 .setDuration(duration) 105 .withLayer() 106 .withEndAction(new Runnable() { 107 @Override 108 public void run() { 109 onAnimationEnded.run(); 110 } 111 }) 112 .start(); 113 } 114 } 115