• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Scene;
24 import android.transition.TransitionManager;
25 import android.widget.Button;
26 
27 public class Reparenting extends Activity {
28 
29     ViewGroup mSceneRoot;
30     ViewGroup mContainer1, mContainer2;
31 
32     @Override
onCreate(Bundle savedInstanceState)33     public void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35         setContentView(R.layout.reparenting);
36 
37         ViewGroup container = (ViewGroup) findViewById(R.id.container);
38         mContainer1 = (ViewGroup) findViewById(R.id.container1);
39         mContainer2 = (ViewGroup) findViewById(R.id.container2);
40         System.out.println("container 1 and 2 " + mContainer1 + ", " + mContainer2);
41 
42         setupButtons(0, mContainer1);
43         setupButtons(3, mContainer2);
44 
45         mSceneRoot = container;
46     }
47 
setupButtons(int startIndex, ViewGroup parent)48     private void setupButtons(int startIndex, ViewGroup parent) {
49         for (int i = startIndex; i < (startIndex + 3); ++i) {
50             Button button = new Button(this);
51             button.setText(Integer.toString(i));
52             button.setOnClickListener(mButtonListener);
53             parent.addView(button);
54         }
55     }
56 
57     private View.OnClickListener mButtonListener = new View.OnClickListener() {
58         @Override
59         public void onClick(final View v) {
60             Scene newScene = new Scene(mSceneRoot);
61             newScene.setEnterAction(new Runnable() {
62                 @Override
63                 public void run() {
64                     ViewGroup oldParent = (ViewGroup) v.getParent();
65                     ViewGroup newParent = oldParent == mContainer1 ? mContainer2 : mContainer1;
66                     oldParent.removeView(v);
67                     newParent.addView(v);
68                 }
69             });
70             ChangeBounds reparent = new ChangeBounds();
71             reparent.setReparent(true);
72             TransitionManager.go(newScene, reparent);
73         }
74     };
75 }
76