Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 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.view.View; |
| 21 | import android.view.ViewGroup; |
| 22 | import android.view.transition.Crossfade; |
| 23 | import android.view.transition.Move; |
| 24 | import android.view.transition.Scene; |
| 25 | import android.view.transition.TransitionGroup; |
| 26 | import android.view.transition.TransitionManager; |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 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 |
| 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 = new Scene(mSceneRoot, R.layout.crossfade, this); |
| 45 | mScene2 = new Scene(mSceneRoot, R.layout.crossfade_1, this); |
| 46 | |
| 47 | Crossfade crossfade = new Crossfade(); |
Chet Haase | 4f0c467 | 2013-06-05 17:49:01 -0700 | [diff] [blame^] | 48 | crossfade.setFadeBehavior(Crossfade.FADE_BEHAVIOR_CROSSFADE); |
| 49 | crossfade.setResizeBehavior(Crossfade.RESIZE_BEHAVIOR_NONE); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 50 | crossfade.setTargetIds(R.id.textview, R.id.textview1, R.id.textview2); |
| 51 | mTransitionManager = new TransitionManager(); |
| 52 | TransitionGroup moveCrossFade = new TransitionGroup(); |
| 53 | moveCrossFade.addTransitions(crossfade, new Move()); |
| 54 | mTransitionManager.setTransition(mScene1, moveCrossFade); |
| 55 | mTransitionManager.setTransition(mScene2, moveCrossFade); |
| 56 | mCurrentScene = 1; |
| 57 | } |
| 58 | |
| 59 | public void sendMessage(View view) { |
| 60 | if (mCurrentScene == 1) { |
| 61 | mTransitionManager.transitionTo(mScene2); |
| 62 | mCurrentScene = 2; |
| 63 | } else { |
| 64 | mTransitionManager.transitionTo(mScene1); |
| 65 | mCurrentScene = 1; |
| 66 | } |
| 67 | } |
| 68 | } |