| 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.view.LayoutInflater; |
| 21 |
import android.view.View; |
| 22 |
import android.view.ViewGroup; |
| 23 |
import android.transition.Scene; |
| 24 |
import android.transition.Transition; |
| 25 |
import android.widget.Button; |
| 26 |
import android.widget.LinearLayout; |
| 27 |
import android.transition.TransitionManager; |
| 28 |
|
| 29 |
|
| 30 |
import java.util.HashMap; |
| 31 |
|
| 32 |
public class UniqueIds extends Activity { |
| 33 |
ViewGroup mSceneRoot; |
| 34 |
static Scene mCurrentScene; |
| 35 |
TransitionManager mTransitionManager = null; |
| 36 |
HashMap<Button, ToggleScene> mSceneMap = new HashMap<Button, ToggleScene>(); |
| 37 |
|
| 38 |
@Override |
| 39 |
public void onCreate(Bundle savedInstanceState) { |
| 40 |
super.onCreate(savedInstanceState); |
| 41 |
setContentView(R.layout.unique_id_test); |
| 42 |
|
| 43 |
LinearLayout container = findViewById(R.id.container); |
| 44 |
LayoutInflater inflater = getLayoutInflater(); |
| 45 |
Button button = (Button) inflater.inflate(R.layout.button_template, null); |
| 46 |
container.addView(button); |
| 47 |
ToggleScene scene = new ToggleScene(container, button); |
| 48 |
mSceneMap.put(button, scene); |
| 49 |
button = (Button) inflater.inflate(R.layout.button_template, null); |
| 50 |
container.addView(button); |
| 51 |
scene = new ToggleScene(container, button); |
| 52 |
mSceneMap.put(button, scene); |
| 53 |
} |
| 54 |
|
| 55 |
public void sendMessage(View view) { |
| 56 |
mSceneMap.get(view).changeToScene(); |
| 57 |
} |
| 58 |
|
| 59 |
class ToggleScene { |
| 60 |
Scene mScene; |
| 61 |
Transition mTransition; |
| 62 |
Button mButton; |
| 63 |
|
| 64 |
ToggleScene(ViewGroup rootView, Button button) { |
| 65 |
mScene = new Scene(rootView); |
| 66 |
mButton = button; |
| 67 |
mScene.setEnterAction(new Runnable() { |
| 68 |
@Override |
| 69 |
public void run() { |
| 70 |
if (mButton.getLeft() == 0) { |
| 71 |
mButton.offsetLeftAndRight(500); |
| 72 |
} else { |
| 73 |
int width = mButton.getWidth(); |
| 74 |
mButton.setLeft(0); |
| 75 |
mButton.setRight(width); |
| 76 |
} |
| 77 |
} |
| 78 |
}); |
| 79 |
} |
| 80 |
|
| 81 |
void changeToScene() { |
| 82 |
TransitionManager.go(mScene); |
| 83 |
} |
| 84 |
} |
| 85 |
} |