1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package com.android.tv.settings.name.setup; 15 16 import android.animation.Animator; 17 import android.animation.AnimatorInflater; 18 import android.annotation.Nullable; 19 import android.os.Bundle; 20 21 import androidx.fragment.app.FragmentActivity; 22 import androidx.leanback.app.GuidedStepSupportFragment; 23 24 import com.android.tv.settings.R; 25 import com.android.tv.settings.name.DeviceNameSetFragment; 26 27 /** 28 * Entry point for the device name flow. This will be invoked during the tv setup process. 29 * This activity needs to have transparent background to show the background drawable of the 30 * setup flow. 31 */ 32 public class DeviceNameFlowStartActivity extends FragmentActivity { 33 private static final String EXTRA_MOVING_FORWARD = "movingForward"; 34 private boolean mResultOk = false; 35 36 @Override onCreate(@ullable Bundle savedInstanceState)37 protected void onCreate(@Nullable Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 if (savedInstanceState == null) { 40 GuidedStepSupportFragment.addAsRoot(this, DeviceNameSetFragment.newInstance(), 41 android.R.id.content); 42 43 // Because our fragment transition is added as root, the animation is dependent 44 // on the Activity transition. We must run the animation at runtime in order to 45 // enter from the correct side. 46 boolean movingForward = getIntent().getExtras().getBoolean(EXTRA_MOVING_FORWARD, true); 47 Animator animator = movingForward 48 ? AnimatorInflater.loadAnimator(this, R.anim.setup_fragment_open_in) 49 : AnimatorInflater.loadAnimator(this, R.anim.setup_fragment_close_in); 50 animator.setTarget(getWindow().getDecorView()); 51 animator.start(); 52 } 53 } 54 55 @Override finish()56 public void finish() { 57 Animator animator = mResultOk 58 ? AnimatorInflater.loadAnimator(this, R.anim.setup_fragment_open_out) 59 : AnimatorInflater.loadAnimator(this, R.anim.setup_fragment_close_out); 60 animator.setTarget(getWindow().getDecorView()); 61 animator.addListener(new Animator.AnimatorListener() { 62 63 @Override 64 public void onAnimationStart(Animator animation) {} 65 66 @Override 67 public void onAnimationRepeat(Animator animation) {} 68 69 @Override 70 public void onAnimationEnd(Animator animation) { 71 doFinish(); 72 } 73 74 @Override 75 public void onAnimationCancel(Animator animation) {} 76 }); 77 animator.start(); 78 } 79 doFinish()80 private void doFinish() { 81 super.finish(); 82 } 83 84 /** 85 * Records activity result is OK so we can finish the activity with the correct animation. 86 */ setResultOk(boolean resultOk)87 public void setResultOk(boolean resultOk) { 88 mResultOk = resultOk; 89 } 90 } 91