diff options
author | Chet Haase <chet@google.com> | 2013-06-03 07:30:21 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2013-06-03 16:37:05 -0700 |
commit | 867a86613d4152a93423300f83597300e6ebeebe (patch) | |
tree | 9087a8ca942f453fb2da7555cd04c5aa2083213d | |
parent | d18607980d86f03ffd838321ac3d511fa820b3e0 (diff) |
Various fixes/cleanup in Scenes and Transitions
setDuration() wasn't handled correctly for TransitionGroup; it should
propagate the value to its children.
Also, videos with no ids were not being handled correctly. The transition code was
using the default id on those views (-1) to store start/end data about the view,
causing multiple non-id views to clobber values in the hashmaps. The correct approach
should be to ignore default id values - only store information about the view
instances, not about the unset ids.
Also, added a new test InterruptTest to be used to fix the current behavior of
not handling situations where new transitions start while old ones are still taking place.
Change-Id: I4e880bdbb33cc26d487bceb0d56e463e72f7621f
12 files changed, 225 insertions, 6 deletions
diff --git a/core/java/android/view/transition/Move.java b/core/java/android/view/transition/Move.java index 3bd57bd0d624..96441aade4db 100644 --- a/core/java/android/view/transition/Move.java +++ b/core/java/android/view/transition/Move.java @@ -24,6 +24,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; +import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -42,6 +43,7 @@ public class Move extends Transition { int[] tempLocation = new int[2]; boolean mResizeClip = false; boolean mReparent = false; + private static final String LOG_TAG = "Move"; private static RectEvaluator sRectEvaluator = new RectEvaluator(); @@ -114,6 +116,13 @@ public class Move extends Transition { int endHeight = endBottom - endTop; int numChanges = 0; if (startWidth != 0 && startHeight != 0 && endWidth != 0 && endHeight != 0) { + if (Transition.DBG) { + Log.v(LOG_TAG, "Target = " + endValues.view); + Log.v(LOG_TAG, " start bounds: " + startLeft + ", " + startTop + ", " + + startRight + ", " + startBottom); + Log.v(LOG_TAG, " end bounds: " + endLeft + ", " + endTop + ", " + + endRight + ", " + endBottom); + } if (startLeft != endLeft) ++numChanges; if (startTop != endTop) ++numChanges; if (startRight != endRight) ++numChanges; diff --git a/core/java/android/view/transition/Transition.java b/core/java/android/view/transition/Transition.java index 150c218c366b..2e3cdee26c77 100644 --- a/core/java/android/view/transition/Transition.java +++ b/core/java/android/view/transition/Transition.java @@ -534,10 +534,14 @@ public abstract class Transition { captureValues(values, start); if (start) { mStartValues.put(view, values); - mStartIdValues.put(id, values); + if (id >= 0) { + mStartIdValues.put(id, values); + } } else { mEndValues.put(view, values); - mEndIdValues.put(id, values); + if (id >= 0) { + mEndIdValues.put(id, values); + } } } } @@ -599,14 +603,18 @@ public abstract class Transition { if (start) { if (!isListViewItem) { mStartValues.put(view, values); - mStartIdValues.put((int) id, values); + if (id >= 0) { + mStartIdValues.put((int) id, values); + } } else { mStartItemIdValues.put(id, values); } } else { if (!isListViewItem) { mEndValues.put(view, values); - mEndIdValues.put((int) id, values); + if (id >= 0) { + mEndIdValues.put((int) id, values); + } } else { mEndItemIdValues.put(id, values); } diff --git a/core/java/android/view/transition/TransitionGroup.java b/core/java/android/view/transition/TransitionGroup.java index 363872a1e027..8d222d8a073d 100644 --- a/core/java/android/view/transition/TransitionGroup.java +++ b/core/java/android/view/transition/TransitionGroup.java @@ -106,8 +106,30 @@ public class TransitionGroup extends Transition { int numTransitions = transitions.length; for (int i = 0; i < numTransitions; ++i) { mTransitions.add(transitions[i]); + if (mDuration >= 0) { + transitions[0].setDuration(mDuration); + } + } + } + } + + /** + * Setting a non-negative duration on a TransitionGroup causes all of the child + * transitions (current and future) to inherit this duration. + * + * @param duration The length of the animation, in milliseconds. + * @return This transitionGroup object. + */ + @Override + public Transition setDuration(long duration) { + super.setDuration(duration); + if (mDuration >= 0) { + int numTransitions = mTransitions.size(); + for (int i = 0; i < numTransitions; ++i) { + mTransitions.get(i).setDuration(duration); } } + return this; } /** diff --git a/tests/TransitionTests/AndroidManifest.xml b/tests/TransitionTests/AndroidManifest.xml index 8cd36bf4f429..be6b145e2bc7 100644 --- a/tests/TransitionTests/AndroidManifest.xml +++ b/tests/TransitionTests/AndroidManifest.xml @@ -205,6 +205,13 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + <activity android:label="InterruptionTest" + android:name="InterruptionTest"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> </application> diff --git a/tests/TransitionTests/res/layout/interruption.xml b/tests/TransitionTests/res/layout/interruption.xml new file mode 100644 index 000000000000..9fdb27af86fc --- /dev/null +++ b/tests/TransitionTests/res/layout/interruption.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <RadioGroup android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + <RadioButton android:id="@+id/scene1RB" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/state1" + android:onClick="onRadioButtonClicked"/> + <RadioButton android:id="@+id/scene2RB" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/state2" + android:onClick="onRadioButtonClicked"/> + <RadioButton android:id="@+id/scene3RB" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/state3" + android:onClick="onRadioButtonClicked"/> + <RadioButton android:id="@+id/scene4RB" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/state4" + android:onClick="onRadioButtonClicked"/> + </RadioGroup> + + <LinearLayout + android:orientation="vertical" + android:id="@+id/sceneRoot" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <include layout="@layout/interruption_inner_1"/> + + </LinearLayout> + + +</LinearLayout>
\ No newline at end of file diff --git a/tests/TransitionTests/res/layout/interruption_inner_1.xml b/tests/TransitionTests/res/layout/interruption_inner_1.xml new file mode 100644 index 000000000000..990a7fdb0d31 --- /dev/null +++ b/tests/TransitionTests/res/layout/interruption_inner_1.xml @@ -0,0 +1,13 @@ +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/buttonContainer"> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/button" + android:layout_alignParentTop="true" + android:layout_alignParentLeft="true" + android:text="@string/state1"/> + +</RelativeLayout>
\ No newline at end of file diff --git a/tests/TransitionTests/res/layout/interruption_inner_2.xml b/tests/TransitionTests/res/layout/interruption_inner_2.xml new file mode 100644 index 000000000000..d18b5571be1f --- /dev/null +++ b/tests/TransitionTests/res/layout/interruption_inner_2.xml @@ -0,0 +1,13 @@ +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/buttonContainer"> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentTop="true" + android:id="@+id/button" + android:layout_alignParentRight="true" + android:text="@string/state2"/> + +</RelativeLayout>
\ No newline at end of file diff --git a/tests/TransitionTests/res/layout/interruption_inner_3.xml b/tests/TransitionTests/res/layout/interruption_inner_3.xml new file mode 100644 index 000000000000..70bd02cb53ac --- /dev/null +++ b/tests/TransitionTests/res/layout/interruption_inner_3.xml @@ -0,0 +1,13 @@ +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/buttonContainer"> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/button" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:text="@string/state3"/> + +</RelativeLayout>
\ No newline at end of file diff --git a/tests/TransitionTests/res/layout/interruption_inner_4.xml b/tests/TransitionTests/res/layout/interruption_inner_4.xml new file mode 100644 index 000000000000..85265fcfb6d2 --- /dev/null +++ b/tests/TransitionTests/res/layout/interruption_inner_4.xml @@ -0,0 +1,13 @@ +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/buttonContainer"> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/button" + android:layout_alignParentBottom="true" + android:layout_alignParentRight="true" + android:text="@string/state4"/> + +</RelativeLayout>
\ No newline at end of file diff --git a/tests/TransitionTests/res/values/strings.xml b/tests/TransitionTests/res/values/strings.xml index e251d5c99f34..3be243bbcdd4 100644 --- a/tests/TransitionTests/res/values/strings.xml +++ b/tests/TransitionTests/res/values/strings.xml @@ -39,4 +39,8 @@ <string name="shortText2">Not much text here</string> <string name="longText1">This is the beginning of the Spring of my discontent. In the event of a real emergency, you would be notified by email. Fear not, for death comes swiftly.</string> <string name="longText2">When do we get to eat? I like all things, especially following strong leaders, and mangy cats. Break glass in emergency. The purpose of a framework is to provide the facilities and functionality of a powerful toolkit with the simplicity of a refrigerator.</string> + <string name="state1">State 1</string> + <string name="state2">State 2</string> + <string name="state3">State 3</string> + <string name="state4">State 4</string> </resources> diff --git a/tests/TransitionTests/src/com/android/transitiontests/ChangingText.java b/tests/TransitionTests/src/com/android/transitiontests/ChangingText.java index 3bb710021052..05bed5fc17ad 100644 --- a/tests/TransitionTests/src/com/android/transitiontests/ChangingText.java +++ b/tests/TransitionTests/src/com/android/transitiontests/ChangingText.java @@ -29,10 +29,8 @@ import android.view.transition.TransitionManager; public class ChangingText extends Activity { - Button mRemovingButton, mInvisibleButton, mGoneButton; Scene mScene1, mScene2; ViewGroup mSceneRoot; - Fade fader; TransitionGroup mChanger; @Override diff --git a/tests/TransitionTests/src/com/android/transitiontests/InterruptionTest.java b/tests/TransitionTests/src/com/android/transitiontests/InterruptionTest.java new file mode 100644 index 000000000000..47cf00220a04 --- /dev/null +++ b/tests/TransitionTests/src/com/android/transitiontests/InterruptionTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.transitiontests; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; +import android.view.transition.AutoTransition; +import android.view.transition.Move; +import android.view.transition.Scene; +import android.view.transition.TextChange; +import android.view.transition.Transition; +import android.view.transition.TransitionGroup; +import android.view.transition.TransitionManager; +import android.widget.RadioButton; + +public class InterruptionTest extends Activity { + + RadioButton mScene1RB, mScene2RB, mScene3RB, mScene4RB; + private Scene mScene1; + private Scene mScene2; + private Scene mScene3; + private Scene mScene4; + Transition mAutoTransition = new AutoTransition(); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.interruption); + + View container = (View) findViewById(R.id.container); + ViewGroup sceneRoot = (ViewGroup) findViewById(R.id.sceneRoot); + + mScene1 = new Scene(sceneRoot, R.layout.interruption_inner_1, this); + mScene2 = new Scene(sceneRoot, R.layout.interruption_inner_2, this); + mScene3 = new Scene(sceneRoot, R.layout.interruption_inner_3, this); + mScene4 = new Scene(sceneRoot, R.layout.interruption_inner_4, this); + + mScene1RB = (RadioButton) findViewById(R.id.scene1RB); + mScene2RB = (RadioButton) findViewById(R.id.scene2RB); + mScene3RB = (RadioButton) findViewById(R.id.scene3RB); + mScene4RB = (RadioButton) findViewById(R.id.scene4RB); + + sceneRoot.setCurrentScene(mScene1); + + mAutoTransition.setDuration(1500); + } + + public void onRadioButtonClicked(View clickedButton) { + if (clickedButton == mScene1RB) { + TransitionManager.go(mScene1, mAutoTransition); + } else if (clickedButton == mScene2RB) { + TransitionManager.go(mScene2, mAutoTransition); + } else if (clickedButton == mScene3RB) { + TransitionManager.go(mScene3, mAutoTransition); + } else { + TransitionManager.go(mScene4, mAutoTransition); + } + } +} |