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