| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
| 33 |
public void onCreate(Bundle savedInstanceState) { |
| 34 |
super.onCreate(savedInstanceState); |
| 35 |
setContentView(R.layout.reparenting); |
| 36 |
|
| 37 |
ViewGroup container = findViewById(R.id.container); |
| 38 |
mContainer1 = findViewById(R.id.container1); |
| 39 |
mContainer2 = 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 |
ChangeBounds reparent = new ChangeBounds(); |
| 71 |
reparent.setReparent(true); |
| 72 |
TransitionManager.go(newScene, reparent); |
| 73 |
} |
| 74 |
}; |
| 75 |
} |