diff --git a/api/current.txt b/api/current.txt index ddcca2721860c..cd07828a03ca7 100644 --- a/api/current.txt +++ b/api/current.txt @@ -28245,6 +28245,18 @@ package android.transition { method public void setResizeClip(boolean); } + public class ChangeClipBounds extends android.transition.Transition { + ctor public ChangeClipBounds(); + method public void captureEndValues(android.transition.TransitionValues); + method public void captureStartValues(android.transition.TransitionValues); + } + + public class ChangeTransform extends android.transition.Transition { + ctor public ChangeTransform(); + method public void captureEndValues(android.transition.TransitionValues); + method public void captureStartValues(android.transition.TransitionValues); + } + public class CircularPropagation extends android.transition.VisibilityPropagation { ctor public CircularPropagation(); method public long getStartDelay(android.view.ViewGroup, android.transition.Transition, android.transition.TransitionValues, android.transition.TransitionValues); diff --git a/core/java/android/transition/ChangeClipBounds.java b/core/java/android/transition/ChangeClipBounds.java new file mode 100644 index 0000000000000..a61b29dbe6ba3 --- /dev/null +++ b/core/java/android/transition/ChangeClipBounds.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2014 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 android.transition; + +import android.animation.Animator; +import android.animation.ObjectAnimator; +import android.animation.RectEvaluator; +import android.graphics.Rect; +import android.view.View; +import android.view.ViewGroup; + +/** + * ChangeClipBounds captures the {@link android.view.View#getClipBounds()} before and after the + * scene change and animates those changes during the transition. + */ +public class ChangeClipBounds extends Transition { + + private static final String TAG = "ChangeTransform"; + + private static final String PROPNAME_CLIP = "android:clipBounds:clip"; + private static final String PROPNAME_BOUNDS = "android:clipBounds:bounds"; + + private static final String[] sTransitionProperties = { + PROPNAME_CLIP, + }; + + @Override + public String[] getTransitionProperties() { + return sTransitionProperties; + } + + private void captureValues(TransitionValues values) { + View view = values.view; + if (view.getVisibility() == View.GONE) { + return; + } + + Rect clip = view.getClipBounds(); + values.values.put(PROPNAME_CLIP, clip); + if (clip == null) { + Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight()); + values.values.put(PROPNAME_BOUNDS, bounds); + } + } + + @Override + public void captureStartValues(TransitionValues transitionValues) { + captureValues(transitionValues); + } + + @Override + public void captureEndValues(TransitionValues transitionValues) { + captureValues(transitionValues); + } + + @Override + public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, + TransitionValues endValues) { + if (startValues == null || endValues == null + || !startValues.values.containsKey(PROPNAME_CLIP) + || !endValues.values.containsKey(PROPNAME_CLIP)) { + return null; + } + Rect start = (Rect) startValues.values.get(PROPNAME_CLIP); + Rect end = (Rect) endValues.values.get(PROPNAME_CLIP); + if (start == null && end == null) { + return null; // No animation required since there is no clip. + } + + if (start == null) { + start = (Rect) startValues.values.get(PROPNAME_BOUNDS); + } else if (end == null) { + end = (Rect) endValues.values.get(PROPNAME_BOUNDS); + } + if (start.equals(end)) { + return null; + } + + endValues.view.setClipBounds(start); + RectEvaluator evaluator = new RectEvaluator(new Rect()); + return ObjectAnimator.ofObject(endValues.view, "clipBounds", evaluator, start, end); + } +} diff --git a/core/java/android/transition/ChangeTransform.java b/core/java/android/transition/ChangeTransform.java new file mode 100644 index 0000000000000..85cb2c7862ea5 --- /dev/null +++ b/core/java/android/transition/ChangeTransform.java @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2014 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 android.transition; + +import android.animation.Animator; +import android.animation.FloatArrayEvaluator; +import android.animation.ObjectAnimator; +import android.util.FloatProperty; +import android.util.Property; +import android.view.View; +import android.view.ViewGroup; + +/** + * This Transition captures scale and rotation for Views before and after the + * scene change and animates those changes during the transition. + * + *
ChangeTransform does not work when the pivot changes between scenes, so either the + * pivot must be set to prevent automatic pivot adjustment or the View's size must be unchanged.
+ */ +public class ChangeTransform extends Transition { + + private static final String TAG = "ChangeTransform"; + + private static final String PROPNAME_SCALE_X = "android:changeTransform:scaleX"; + private static final String PROPNAME_SCALE_Y = "android:changeTransform:scaleY"; + private static final String PROPNAME_ROTATION_X = "android:changeTransform:rotationX"; + private static final String PROPNAME_ROTATION_Y = "android:changeTransform:rotationY"; + private static final String PROPNAME_ROTATION_Z = "android:changeTransform:rotationZ"; + private static final String PROPNAME_PIVOT_X = "android:changeTransform:pivotX"; + private static final String PROPNAME_PIVOT_Y = "android:changeTransform:pivotY"; + + private static final String[] sTransitionProperties = { + PROPNAME_SCALE_X, + PROPNAME_SCALE_Y, + PROPNAME_ROTATION_X, + PROPNAME_ROTATION_Y, + PROPNAME_ROTATION_Z, + }; + + private static final FloatProperty{@link android.transition.Explode} transition:
+ *This TransitionSet contains {@link android.transition.Explode} for visibility,
+ * {@link android.transition.ChangeBounds}, {@link android.transition.ChangeTransform},
+ * and {@link android.transition.ChangeClipBounds} for non-ImageViews and
+ * {@link android.transition.MoveImage} for ImageViews:
{@link android.transition.MoveImage} transition:
- * - * {@sample development/samples/ApiDemos/res/transition/move_image.xml MoveImage} + * {@sample development/samples/ApiDemos/res/transition/explode_move_together.xml MultipleTransform} * *Note that attributes for the transition are not required, just as they are * optional when declared in code; Transitions created from XML resources will use diff --git a/core/java/android/transition/TransitionInflater.java b/core/java/android/transition/TransitionInflater.java index 1aa412a3c4d83..2bdba81f5bf7e 100644 --- a/core/java/android/transition/TransitionInflater.java +++ b/core/java/android/transition/TransitionInflater.java @@ -153,6 +153,12 @@ public class TransitionInflater { } else if ("moveImage".equals(name)) { transition = new MoveImage(); newTransition = true; + } else if ("changeTransform".equals(name)) { + transition = new ChangeTransform(); + newTransition = true; + } else if ("changeClipBounds".equals(name)) { + transition = new ChangeClipBounds(); + newTransition = true; } else if ("autoTransition".equals(name)) { transition = new AutoTransition(); newTransition = true;