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; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 20 | import android.transition.ChangeBounds; |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 21 | import android.view.View; |
| 22 | import android.view.ViewGroup; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 23 | import android.transition.Crossfade; |
| 24 | import android.transition.Scene; |
| 25 | import android.transition.TransitionSet; |
| 26 | import android.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 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 41 | View container = findViewById(R.id.container); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 42 | mSceneRoot = (ViewGroup) container.getParent(); |
| 43 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 44 | mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.crossfade, this); |
| 45 | mScene2 = Scene.getSceneForLayout(mSceneRoot, R.layout.crossfade_1, this); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 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 | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 50 | crossfade.addTarget(R.id.textview).addTarget(R.id.textview1). |
| 51 | addTarget(R.id.textview2); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 52 | mTransitionManager = new TransitionManager(); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 53 | TransitionSet moveCrossFade = new TransitionSet(); |
| 54 | moveCrossFade.addTransition(crossfade).addTransition(new ChangeBounds()); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 55 | mTransitionManager.setTransition(mScene1, moveCrossFade); |
| 56 | mTransitionManager.setTransition(mScene2, moveCrossFade); |
| 57 | mCurrentScene = 1; |
| 58 | } |
| 59 | |
| 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 | } |