1 /* 2 * Copyright 2019, 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 package com.android.managedprovisioning.transition; 17 18 import android.graphics.drawable.Animatable2.AnimationCallback; 19 import android.graphics.drawable.AnimatedVectorDrawable; 20 import android.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.widget.ImageView; 23 import com.android.managedprovisioning.R; 24 import com.android.managedprovisioning.common.ProvisionLogger; 25 import com.android.managedprovisioning.common.RepeatingVectorAnimation; 26 import com.android.managedprovisioning.common.SetupGlifLayoutActivity; 27 import com.android.managedprovisioning.common.Utils; 28 import com.android.managedprovisioning.model.CustomizationParams; 29 import com.android.managedprovisioning.model.ProvisioningParams; 30 31 import com.google.android.setupdesign.GlifLayout; 32 33 /** 34 * Activity which informs the user that they are about to set up their personal profile. 35 */ 36 public class TransitionActivity extends SetupGlifLayoutActivity { 37 38 private ProvisioningParams mParams; 39 private AnimatedVectorDrawable mIntroAnimation; 40 private RepeatingVectorAnimation mRepeatingVectorAnimation; 41 42 @Override onCreate(Bundle savedInstanceState)43 protected void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 46 mParams = getIntent().getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS); 47 if (mParams == null) { 48 ProvisionLogger.loge("Missing params in TransitionActivity activity"); 49 finish(); 50 return; 51 } 52 initializeUi(); 53 } 54 55 @Override onStart()56 protected void onStart() { 57 super.onStart(); 58 if (mRepeatingVectorAnimation != null) { 59 mRepeatingVectorAnimation.start(); 60 } else { 61 mIntroAnimation.start(); 62 } 63 } 64 65 @Override onStop()66 protected void onStop() { 67 super.onStop(); 68 if (mRepeatingVectorAnimation != null) { 69 mRepeatingVectorAnimation.stop(); 70 } 71 if (mIntroAnimation != null) { 72 mIntroAnimation.stop(); 73 } 74 } 75 initializeUi()76 private void initializeUi() { 77 CustomizationParams customizationParams = 78 CustomizationParams.createInstance(mParams, this, mUtils); 79 initializeLayoutParams( 80 R.layout.transition_screen, R.string.now_lets_set_up_everything_else, 81 customizationParams); 82 setTitle(R.string.set_up_everything_else); 83 84 final GlifLayout layout = findViewById(R.id.setup_wizard_layout); 85 setupAnimation(layout); 86 Utils.addNextButton(layout, v -> finish()); 87 } 88 setupAnimation(GlifLayout layout)89 private void setupAnimation(GlifLayout layout) { 90 final ImageView animationHolder = layout.findViewById(R.id.animation); 91 final Drawable drawable = animationHolder.getDrawable(); 92 mIntroAnimation = (AnimatedVectorDrawable) drawable; 93 mIntroAnimation.registerAnimationCallback(new AnimationCallback() { 94 @Override 95 public void onAnimationEnd(Drawable drawable) { 96 animationHolder.setImageResource(R.drawable.everything_else_animation_repeating); 97 final AnimatedVectorDrawable repeatingAnimation = 98 (AnimatedVectorDrawable) animationHolder.getDrawable(); 99 mRepeatingVectorAnimation = new RepeatingVectorAnimation(repeatingAnimation); 100 mRepeatingVectorAnimation.start(); 101 mIntroAnimation = null; 102 } 103 }); 104 mIntroAnimation.start(); 105 } 106 107 @Override onBackPressed()108 public void onBackPressed() {} 109 } 110