blob: 433a91c4e55fcca64a955c736cf779f8bc46340b [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.LayoutInflater;
21import android.view.View;
22import android.view.ViewGroup;
23import android.view.transition.Scene;
24import android.view.transition.Transition;
25import android.widget.Button;
26import android.widget.LinearLayout;
27import android.view.transition.TransitionManager;
Chet Haasefaebd8f2012-05-18 14:17:57 -070028
29
30import java.util.HashMap;
31
32public 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 = (LinearLayout) 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}