blob: e559c7209fc130ec03c0f5a8f9a64ce8c8a5958d [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.os.Bundle;
20import android.view.View;
21import android.view.ViewGroup;
22import android.view.transition.Move;
23import android.view.transition.Scene;
24import android.view.transition.TransitionManager;
25import android.widget.Button;
Chet Haasefaebd8f2012-05-18 14:17:57 -070026
27public class Reparenting extends Activity {
28
29 ViewGroup mSceneRoot;
30 ViewGroup mContainer1, mContainer2;
31
32 @Override
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
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 Move reparent = new Move();
71 reparent.setReparent(true);
72 TransitionManager.go(newScene, reparent);
73 }
74 };
75}