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