blob: ce7f439df8d752e21293ee290006f1053dfe8cf3 [file] [log] [blame]
Chet Haasefaebd8f2012-05-18 14:17:57 -07001/*
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 */
16package com.android.transitiontests;
17
18import android.app.Activity;
19import android.content.Context;
20import android.os.Bundle;
21import android.view.LayoutInflater;
22import android.view.View;
23import android.view.ViewGroup;
24import android.view.transition.Fade;
25import android.view.transition.Move;
26import android.view.transition.Scene;
27import android.view.transition.TransitionGroup;
28import android.view.transition.TransitionManager;
Chet Haasefaebd8f2012-05-18 14:17:57 -070029
30
31public class Demo1 extends Activity {
32 ViewGroup mSceneRoot;
33 static Scene mCurrentScene;
34 boolean mFirstTime = true;
35 Scene mSearchScreen, mResultsScreen;
36 TransitionManager mTransitionManager = null;
37
38 @Override
39 public void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41 setContentView(R.layout.search_screen);
42
43 View container = (View) findViewById(R.id.container);
44 mSceneRoot = (ViewGroup) container.getParent();
45
46// mResultsScreen = new MyScene(mSceneRoot, R.layout.results_screen);
47// mSearchScreen = new MyScene(mSceneRoot, R.layout.search_screen);
48 mResultsScreen = new Scene(mSceneRoot);
49 mResultsScreen.setEnterAction(new Runnable() {
50 @Override
51 public void run() {
52 LayoutInflater inflater = (LayoutInflater)
53 getSystemService(Context.LAYOUT_INFLATER_SERVICE);
54 inflater.inflate(R.layout.results_screen, mSceneRoot);
55 }
56 });
57 mSearchScreen = new Scene(mSceneRoot);
58 mSearchScreen.setEnterAction(new Runnable() {
59 @Override
60 public void run() {
61 LayoutInflater inflater = (LayoutInflater)
62 getSystemService(Context.LAYOUT_INFLATER_SERVICE);
63 inflater.inflate(R.layout.search_screen, mSceneRoot);
64 }
65 });
66
67 }
68
69 public void sendMessage(View view) {
70 if (mFirstTime) {
71 mFirstTime = false;
72 TransitionGroup transition = new TransitionGroup();
73 transition.addTransitions(new Fade().setTargetIds(R.id.resultsText, R.id.resultsList),
74 new Move().setTargetIds(R.id.searchContainer));
75 mTransitionManager = new TransitionManager();
76 mTransitionManager.setTransition(mSearchScreen, transition);
77 mTransitionManager.setTransition(mResultsScreen, transition);
78 }
79 if (mCurrentScene == mResultsScreen) {
80 mTransitionManager.transitionTo(mSearchScreen);
81 mCurrentScene = mSearchScreen;
82 } else {
83 mTransitionManager.transitionTo(mResultsScreen);
84 mCurrentScene = mResultsScreen;
85 }
86 }
87}