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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
28
tests/TransitionTests/res/layout/crossfade_image.xml
Normal file
28
tests/TransitionTests/res/layout/crossfade_image.xml
Normal file
@@ -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>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user