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.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
onCreate(Bundle savedInstanceState)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 
sendMessage(View view)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 
ToggleScene(ViewGroup rootView, Button button)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 
changeToScene()81         void changeToScene() {
82             TransitionManager.go(mScene);
83         }
84     }
85 }
86