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.android.transitiontests; 17 18 import android.app.Activity; 19 import android.os.Bundle; 20 import android.transition.ChangeBounds; 21 import android.view.View; 22 import android.view.ViewGroup; 23 import android.transition.Crossfade; 24 import android.transition.Scene; 25 import android.transition.TransitionSet; 26 import android.transition.TransitionManager; 27 28 29 public class CrossFadeDemo extends Activity { 30 31 ViewGroup mSceneRoot; 32 static int mCurrentScene; 33 Scene mScene1, mScene2; 34 TransitionManager mTransitionManager; 35 36 @Override onCreate(Bundle savedInstanceState)37 public void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setContentView(R.layout.crossfade); 40 41 View container = (View) findViewById(R.id.container); 42 mSceneRoot = (ViewGroup) container.getParent(); 43 44 mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.crossfade, this); 45 mScene2 = Scene.getSceneForLayout(mSceneRoot, R.layout.crossfade_1, this); 46 47 Crossfade crossfade = new Crossfade(); 48 crossfade.setFadeBehavior(Crossfade.FADE_BEHAVIOR_CROSSFADE); 49 crossfade.setResizeBehavior(Crossfade.RESIZE_BEHAVIOR_NONE); 50 crossfade.addTarget(R.id.textview).addTarget(R.id.textview1). 51 addTarget(R.id.textview2); 52 mTransitionManager = new TransitionManager(); 53 TransitionSet moveCrossFade = new TransitionSet(); 54 moveCrossFade.addTransition(crossfade).addTransition(new ChangeBounds()); 55 mTransitionManager.setTransition(mScene1, moveCrossFade); 56 mTransitionManager.setTransition(mScene2, moveCrossFade); 57 mCurrentScene = 1; 58 } 59 sendMessage(View view)60 public void sendMessage(View view) { 61 if (mCurrentScene == 1) { 62 mTransitionManager.transitionTo(mScene2); 63 mCurrentScene = 2; 64 } else { 65 mTransitionManager.transitionTo(mScene1); 66 mCurrentScene = 1; 67 } 68 } 69 } 70