Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 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.content.Context; |
| 20 | import android.os.Bundle; |
| 21 | import android.view.LayoutInflater; |
| 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
| 24 | import android.view.transition.Move; |
| 25 | import android.view.transition.Scene; |
| 26 | import android.view.transition.TransitionManager; |
| 27 | import android.widget.Button; |
| 28 | import android.widget.RelativeLayout; |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 29 | |
| 30 | import static android.widget.RelativeLayout.ALIGN_PARENT_LEFT; |
| 31 | import static android.widget.RelativeLayout.ALIGN_PARENT_RIGHT; |
| 32 | import static android.widget.RelativeLayout.LayoutParams; |
| 33 | |
| 34 | public class InstanceTargets extends Activity { |
| 35 | |
| 36 | ViewGroup mSceneRoot; |
| 37 | static int mCurrentScene; |
| 38 | |
| 39 | @Override |
| 40 | public void onCreate(Bundle savedInstanceState) { |
| 41 | super.onCreate(savedInstanceState); |
| 42 | setContentView(R.layout.instance_targets); |
| 43 | |
| 44 | View container = (View) findViewById(R.id.container); |
| 45 | mSceneRoot = (ViewGroup) container; |
| 46 | } |
| 47 | |
| 48 | public void sendMessage(final View view) { |
| 49 | TransitionManager.go(mSceneRoot, new Runnable() { |
| 50 | @Override |
| 51 | public void run() { |
| 52 | for (int i = 0; i < mSceneRoot.getChildCount(); ++i) { |
| 53 | Button button = (Button) mSceneRoot.getChildAt(i); |
| 54 | LayoutParams params = (LayoutParams) button.getLayoutParams(); |
| 55 | int rules[] = params.getRules(); |
| 56 | if (rules[ALIGN_PARENT_RIGHT] != 0) { |
| 57 | params.removeRule(ALIGN_PARENT_RIGHT); |
| 58 | params.addRule(ALIGN_PARENT_LEFT); |
| 59 | } else { |
| 60 | params.removeRule(ALIGN_PARENT_LEFT); |
| 61 | params.addRule(ALIGN_PARENT_RIGHT); |
| 62 | } |
| 63 | button.setLayoutParams(params); |
| 64 | } |
| 65 | } |
| 66 | }, new Move().setTargets(view)); |
| 67 | } |
| 68 | } |