InstanceTargets.java revision d82c8ac4db7091d2e976af4c89a1734465d20cd2
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 */
16package com.android.transitiontests;
17
18import android.app.Activity;
19import android.os.Bundle;
20import android.view.View;
21import android.view.ViewGroup;
22import android.transition.ChangeBounds;
23import android.transition.TransitionManager;
24import android.widget.Button;
25
26import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT;
27import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT;
28import static android.widget.RelativeLayout.LayoutParams;
29
30public class InstanceTargets extends Activity {
31
32    ViewGroup mSceneRoot;
33    static int mCurrentScene;
34
35    @Override
36    public void onCreate(Bundle savedInstanceState) {
37        super.onCreate(savedInstanceState);
38        setContentView(R.layout.instance_targets);
39
40        View container = (View) findViewById(R.id.container);
41        mSceneRoot = (ViewGroup) container;
42    }
43
44    public void sendMessage(final View view) {
45        TransitionManager.beginDelayedTransition(mSceneRoot, new ChangeBounds().addTarget(view));
46        for (int i = 0; i < mSceneRoot.getChildCount(); ++i) {
47            Button button = (Button) mSceneRoot.getChildAt(i);
48            LayoutParams params = (LayoutParams) button.getLayoutParams();
49            int rules[] = params.getRules();
50            if (rules[ALIGN_PARENT_RIGHT] != 0) {
51                params.removeRule(ALIGN_PARENT_RIGHT);
52                params.addRule(ALIGN_PARENT_LEFT);
53            } else {
54                params.removeRule(ALIGN_PARENT_LEFT);
55                params.addRule(ALIGN_PARENT_RIGHT);
56            }
57            button.setLayoutParams(params);
58        }
59    }
60}
61