diff options
author | Winson Chung <winsonc@google.com> | 2014-03-19 10:47:20 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2014-03-20 17:39:19 -0700 |
commit | 399f62052a88e5e7628b7312637ae54fbbaa4bec (patch) | |
tree | 53cb216953534987e571f0516208c31bb6507f52 /core/java/android/view/animation | |
parent | ea818400f8e9cd1a182d9565d42571a709c98990 (diff) | |
download | frameworks_base-399f62052a88e5e7628b7312637ae54fbbaa4bec.zip frameworks_base-399f62052a88e5e7628b7312637ae54fbbaa4bec.tar.gz frameworks_base-399f62052a88e5e7628b7312637ae54fbbaa4bec.tar.bz2 |
Adding support for clipping window transition for alternate recents.
Change-Id: Ic7df4e6c0396afc794ffc21694814c0a93f20f31
Diffstat (limited to 'core/java/android/view/animation')
-rw-r--r-- | core/java/android/view/animation/ClipRectAnimation.java | 59 | ||||
-rw-r--r-- | core/java/android/view/animation/Transformation.java | 53 |
2 files changed, 111 insertions, 1 deletions
diff --git a/core/java/android/view/animation/ClipRectAnimation.java b/core/java/android/view/animation/ClipRectAnimation.java new file mode 100644 index 0000000..2361501 --- /dev/null +++ b/core/java/android/view/animation/ClipRectAnimation.java @@ -0,0 +1,59 @@ +/* + * 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.view.animation; + +import android.graphics.Rect; + +/** + * An animation that controls the clip of an object. See the + * {@link android.view.animation full package} description for details and + * sample code. + * + * @hide + */ +public class ClipRectAnimation extends Animation { + private Rect mFromRect = new Rect(); + private Rect mToRect = new Rect(); + + /** + * Constructor to use when building a ClipRectAnimation from code + * + * @param fromClip the clip rect to animate from + * @param toClip the clip rect to animate to + */ + public ClipRectAnimation(Rect fromClip, Rect toClip) { + if (fromClip == null || toClip == null) { + throw new RuntimeException("Expected non-null animation clip rects"); + } + mFromRect.set(fromClip); + mToRect.set(toClip); + } + + @Override + protected void applyTransformation(float it, Transformation tr) { + int l = mFromRect.left + (int) ((mToRect.left - mFromRect.left) * it); + int t = mFromRect.top + (int) ((mToRect.top - mFromRect.top) * it); + int r = mFromRect.right + (int) ((mToRect.right - mFromRect.right) * it); + int b = mFromRect.bottom + (int) ((mToRect.bottom - mFromRect.bottom) * it); + tr.setClipRect(l, t, r, b); + } + + @Override + public boolean willChangeTransformationMatrix() { + return false; + } +} diff --git a/core/java/android/view/animation/Transformation.java b/core/java/android/view/animation/Transformation.java index 890909b..2f4fe73 100644 --- a/core/java/android/view/animation/Transformation.java +++ b/core/java/android/view/animation/Transformation.java @@ -17,6 +17,7 @@ package android.view.animation; import android.graphics.Matrix; +import android.graphics.Rect; import java.io.PrintWriter; @@ -47,6 +48,9 @@ public class Transformation { protected float mAlpha; protected int mTransformationType; + private boolean mHasClipRect; + private Rect mClipRect = new Rect(); + /** * Creates a new transformation with alpha = 1 and the identity matrix. */ @@ -65,6 +69,8 @@ public class Transformation { } else { mMatrix.reset(); } + mClipRect.setEmpty(); + mHasClipRect = false; mAlpha = 1.0f; mTransformationType = TYPE_BOTH; } @@ -98,9 +104,15 @@ public class Transformation { public void set(Transformation t) { mAlpha = t.getAlpha(); mMatrix.set(t.getMatrix()); + if (t.mHasClipRect) { + setClipRect(t.getClipRect()); + } else { + mHasClipRect = false; + mClipRect.setEmpty(); + } mTransformationType = t.getTransformationType(); } - + /** * Apply this Transformation to an existing Transformation, e.g. apply * a scale effect to something that has already been rotated. @@ -109,6 +121,9 @@ public class Transformation { public void compose(Transformation t) { mAlpha *= t.getAlpha(); mMatrix.preConcat(t.getMatrix()); + if (t.mHasClipRect) { + setClipRect(t.getClipRect()); + } } /** @@ -119,6 +134,9 @@ public class Transformation { public void postCompose(Transformation t) { mAlpha *= t.getAlpha(); mMatrix.postConcat(t.getMatrix()); + if (t.mHasClipRect) { + setClipRect(t.getClipRect()); + } } /** @@ -138,6 +156,39 @@ public class Transformation { } /** + * Sets the current Transform's clip rect + * @hide + */ + public void setClipRect(Rect r) { + setClipRect(r.left, r.top, r.right, r.bottom); + } + + /** + * Sets the current Transform's clip rect + * @hide + */ + public void setClipRect(int l, int t, int r, int b) { + mClipRect.set(l, t, r, b); + mHasClipRect = true; + } + + /** + * Returns the current Transform's clip rect + * @hide + */ + public Rect getClipRect() { + return mClipRect; + } + + /** + * Returns whether the current Transform's clip rect is set + * @hide + */ + public boolean hasClipRect() { + return mHasClipRect; + } + + /** * @return The degree of transparency */ public float getAlpha() { |