1 /* 2 * Copyright (C) 2013 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.example.android.apis.animation; 17 18 import android.app.Activity; 19 import android.os.Bundle; 20 import android.view.View; 21 import android.view.ViewGroup; 22 import android.transition.Scene; 23 import android.transition.TransitionInflater; 24 import android.transition.TransitionManager; 25 import com.example.android.apis.R; 26 27 /** 28 * This application demonstrates some of the capabilities and uses of the 29 * {@link android.transition transitions} APIs. Scenes and a TransitionManager 30 * are loaded from resource files and transitions are run between those scenes 31 * as well as a dynamically-configured scene. 32 */ 33 public class Transitions extends Activity { 34 35 Scene mScene1, mScene2, mScene3; 36 ViewGroup mSceneRoot; 37 TransitionManager mTransitionManager; 38 39 @Override 40 protected void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 setContentView(R.layout.transition); 43 44 mSceneRoot = (ViewGroup) findViewById(R.id.sceneRoot); 45 46 TransitionInflater inflater = TransitionInflater.from(this); 47 48 // Note that this is not the only way to create a Scene object, but that 49 // loading them from layout resources cooperates with the 50 // TransitionManager that we are also loading from resources, and which 51 // uses the same layout resource files to determine the scenes to transition 52 // from/to. 53 mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.transition_scene1, this); 54 mScene2 = Scene.getSceneForLayout(mSceneRoot, R.layout.transition_scene2, this); 55 mScene3 = Scene.getSceneForLayout(mSceneRoot, R.layout.transition_scene3, this); 56 mTransitionManager = inflater.inflateTransitionManager(R.transition.transitions_mgr, 57 mSceneRoot); 58 } 59 60 public void selectScene(View view) { 61 switch (view.getId()) { 62 case R.id.scene1: 63 mTransitionManager.transitionTo(mScene1); 64 break; 65 case R.id.scene2: 66 mTransitionManager.transitionTo(mScene2); 67 break; 68 case R.id.scene3: 69 mTransitionManager.transitionTo(mScene3); 70 break; 71 case R.id.scene4: 72 // scene4 is not an actual 'Scene', but rather a dynamic change in the UI, 73 // transitioned to using beginDelayedTransition() to tell the TransitionManager 74 // to get ready to run a transition at the next frame 75 TransitionManager.beginDelayedTransition(mSceneRoot); 76 setNewSize(R.id.view1, 150, 25); 77 setNewSize(R.id.view2, 150, 25); 78 setNewSize(R.id.view3, 150, 25); 79 setNewSize(R.id.view4, 150, 25); 80 break; 81 } 82 } 83 84 private void setNewSize(int id, int width, int height) { 85 View view = findViewById(id); 86 ViewGroup.LayoutParams params = view.getLayoutParams(); 87 params.width = width; 88 params.height = height; 89 view.setLayoutParams(params); 90 } 91 } 92