Chet Haase | 4f50723 | 2013-06-10 13:00:06 -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.os.Bundle; |
| 20 | import android.view.View; |
| 21 | import android.view.ViewGroup; |
| 22 | import android.view.transition.TransitionManager; |
| 23 | import android.widget.Button; |
| 24 | import android.widget.LinearLayout; |
| 25 | import static android.widget.LinearLayout.LayoutParams; |
| 26 | |
| 27 | public class DelayedTransition extends Activity { |
| 28 | |
| 29 | private static final int SEARCH_SCREEN = 0; |
| 30 | private static final int RESULTS_SCREEN = 1; |
| 31 | ViewGroup mSceneRoot; |
| 32 | static int mCurrentScene; |
| 33 | |
| 34 | @Override |
| 35 | public void onCreate(Bundle savedInstanceState) { |
| 36 | super.onCreate(savedInstanceState); |
| 37 | setContentView(R.layout.two_buttons); |
| 38 | |
| 39 | final Button button1 = (Button) findViewById(R.id.button1); |
| 40 | final Button button2 = (Button) findViewById(R.id.button2); |
| 41 | final LinearLayout container = (LinearLayout) findViewById(R.id.container); |
| 42 | button1.setOnClickListener(new View.OnClickListener() { |
| 43 | @Override |
| 44 | public void onClick(View v) { |
| 45 | int buttonWidth = button1.getWidth(); |
| 46 | int containerWidth = container.getWidth(); |
| 47 | if (buttonWidth < containerWidth) { |
| 48 | TransitionManager.beginDelayedTransition(container, null); |
| 49 | button1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, |
| 50 | LayoutParams.WRAP_CONTENT)); |
| 51 | TransitionManager.beginDelayedTransition(container, null); |
| 52 | button2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, |
| 53 | LayoutParams.MATCH_PARENT)); |
| 54 | } else { |
| 55 | TransitionManager.beginDelayedTransition(container, null); |
| 56 | button1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, |
| 57 | LayoutParams.WRAP_CONTENT)); |
| 58 | TransitionManager.beginDelayedTransition(container, null); |
| 59 | button2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, |
| 60 | LayoutParams.WRAP_CONTENT)); |
| 61 | } |
| 62 | } |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | } |