diff options
author | Chet Haase <chet@google.com> | 2013-07-10 11:27:54 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2013-07-10 12:14:54 -0700 |
commit | dc57d9dda559aaf06237b9124dc9ef27513bab31 (patch) | |
tree | 887177b3a22c8e087637a04daefa7cec6b83179a | |
parent | 0d21c220ddb1873133c24449404f82c28b19b8b4 (diff) | |
download | frameworks_base-dc57d9dda559aaf06237b9124dc9ef27513bab31.zip frameworks_base-dc57d9dda559aaf06237b9124dc9ef27513bab31.tar.gz frameworks_base-dc57d9dda559aaf06237b9124dc9ef27513bab31.tar.bz2 |
Fix minor transition bugs
TransitionGroup.setDuration() was not propagating the new duration to
future child transitions correctly.
Also, Fade should restore a fully-opaque value when a transition ends, to prevent
the problem of mid-stream canceled transitions causing vie3ws to get stuck with partially
faded-in alpha values.
Issue #9755995 Transitions: TransitionGroup.setDuration() not handled correctly
Issue #9756655 Transitions: handle fading cancelation better
Change-Id: Id44569c6f4152a26ee382d04c30a2f035a1ebcf3
5 files changed, 114 insertions, 4 deletions
diff --git a/core/java/android/view/transition/Fade.java b/core/java/android/view/transition/Fade.java index 3c5b6fa..c2aa90b 100644 --- a/core/java/android/view/transition/Fade.java +++ b/core/java/android/view/transition/Fade.java @@ -96,12 +96,19 @@ public class Fade extends Visibility { protected Animator appear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility) { - View endView = (endValues != null) ? endValues.view : null; - if ((mFadingMode & IN) != IN) { + if ((mFadingMode & IN) != IN || endValues == null) { return null; } + final View endView = endValues.view; endView.setAlpha(0); - return runAnimation(endView, 0, 1, null); + final Animator.AnimatorListener endListener = new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + // Always end animation with full alpha, in case it's canceled mid-stream + endView.setAlpha(1); + } + }; + return runAnimation(endView, 0, 1, endListener); } @Override diff --git a/core/java/android/view/transition/TransitionGroup.java b/core/java/android/view/transition/TransitionGroup.java index d0e61ea..313e33e 100644 --- a/core/java/android/view/transition/TransitionGroup.java +++ b/core/java/android/view/transition/TransitionGroup.java @@ -104,7 +104,7 @@ public class TransitionGroup extends Transition { mTransitions.add(transitions[i]); transitions[i].mParent = this; if (mDuration >= 0) { - transitions[0].setDuration(mDuration); + transitions[i].setDuration(mDuration); } } } diff --git a/tests/TransitionTests/AndroidManifest.xml b/tests/TransitionTests/AndroidManifest.xml index 5483f64..9a399d0 100644 --- a/tests/TransitionTests/AndroidManifest.xml +++ b/tests/TransitionTests/AndroidManifest.xml @@ -233,6 +233,13 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + <activity android:label="CrossfadeImage" + android:name=".CrossfadeImage"> + <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/crossfade_image.xml b/tests/TransitionTests/res/layout/crossfade_image.xml new file mode 100644 index 0000000..c46327a --- /dev/null +++ b/tests/TransitionTests/res/layout/crossfade_image.xml @@ -0,0 +1,28 @@ +<?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"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/self_portrait_square_100" + android:onClick="sendMessage" + android:id="@+id/contact_picture"/> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/self_portrait_square_100" + android:onClick="sendMessage" + android:id="@+id/contact_picture1"/> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/self_portrait_square_100" + android:onClick="sendMessage" + android:id="@+id/contact_picture2"/> + +</LinearLayout>
\ No newline at end of file diff --git a/tests/TransitionTests/src/com/android/transitiontests/CrossfadeImage.java b/tests/TransitionTests/src/com/android/transitiontests/CrossfadeImage.java new file mode 100644 index 0000000..28e055f --- /dev/null +++ b/tests/TransitionTests/src/com/android/transitiontests/CrossfadeImage.java @@ -0,0 +1,68 @@ +/* + * 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.Crossfade; +import android.view.transition.Move; +import android.view.transition.Scene; +import android.view.transition.Transition; +import android.view.transition.TransitionGroup; +import android.view.transition.TransitionManager; +import android.widget.ImageView; + +public class CrossfadeImage extends Activity { + ViewGroup mSceneRoot; + static int mCurrentScene; + Scene mScene1, mScene2; + TransitionManager mTransitionManager; + boolean mExpanded = false; + Transition mTransition; + ImageView mImageView; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.crossfade_image); + + ViewGroup container = (ViewGroup) findViewById(R.id.container); + mSceneRoot = container; + + mImageView = (ImageView) findViewById(R.id.contact_picture); + mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); + + Crossfade mCrossfade = new Crossfade(); + mCrossfade.setTargetIds(R.id.contact_picture); + + TransitionGroup group = new TransitionGroup(); + group.setDuration(1500); + group.addTransitions(mCrossfade, new Move()); + mTransition = group; + } + + public void sendMessage(View view) { + TransitionManager.beginDelayedTransition(mSceneRoot, mTransition); + if (mExpanded) { + mImageView.setImageResource(R.drawable.self_portrait_square_100); + } else { + mImageView.setImageResource(R.drawable.self_portrait_square_200); + } + mExpanded = !mExpanded; + } +} |