Home | History | Annotate | Download | only in transitiontests
      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.content.Context;
     20 import android.os.Bundle;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.transition.Fade;
     25 import android.transition.ChangeBounds;
     26 import android.transition.Scene;
     27 import android.transition.TransitionSet;
     28 import android.transition.TransitionManager;
     29 
     30 
     31 public 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             TransitionSet transition = new TransitionSet();
     73             transition.addTransition(new Fade().addTarget(R.id.resultsText).
     74                     addTarget(R.id.resultsList)).
     75                     addTransition(new ChangeBounds().addTarget(R.id.searchContainer));
     76             mTransitionManager = new TransitionManager();
     77             mTransitionManager.setTransition(mSearchScreen, transition);
     78             mTransitionManager.setTransition(mResultsScreen, transition);
     79         }
     80         if (mCurrentScene == mResultsScreen) {
     81             mTransitionManager.transitionTo(mSearchScreen);
     82             mCurrentScene = mSearchScreen;
     83         } else {
     84             mTransitionManager.transitionTo(mResultsScreen);
     85             mCurrentScene = mResultsScreen;
     86         }
     87     }
     88 }
     89