diff options
author | Chris Craik <ccraik@google.com> | 2014-04-25 18:34:11 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2014-04-28 14:33:33 -0700 |
commit | cc39e16cb98855f35079941b5e7e6eac2b7bc388 (patch) | |
tree | f37cb0ce9da11a018446adfb83c756f5e76e77f1 /core/java/android | |
parent | 802667b20b2170ddce94d70a022b68b64b9a7493 (diff) | |
download | frameworks_base-cc39e16cb98855f35079941b5e7e6eac2b7bc388.zip frameworks_base-cc39e16cb98855f35079941b5e7e6eac2b7bc388.tar.gz frameworks_base-cc39e16cb98855f35079941b5e7e6eac2b7bc388.tar.bz2 |
Add elevation, Z properties to View
Change-Id: I3dd3b683a66e248a0fdf2ca69d1e962615b0daf9
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/view/RenderNode.java | 10 | ||||
-rw-r--r-- | core/java/android/view/View.java | 58 | ||||
-rw-r--r-- | core/java/android/view/ViewPropertyAnimator.java | 36 |
3 files changed, 97 insertions, 7 deletions
diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java index 30e4281..3dc09c4 100644 --- a/core/java/android/view/RenderNode.java +++ b/core/java/android/view/RenderNode.java @@ -443,6 +443,14 @@ public class RenderNode { return nHasOverlappingRendering(mNativeRenderNode); } + public void setElevation(float lift) { + nSetElevation(mNativeRenderNode, lift); + } + + public float getElevation() { + return nGetElevation(mNativeRenderNode); + } + /** * Sets the translation value for the display list on the X axis. * @@ -854,6 +862,7 @@ public class RenderNode { private static native void nSetAlpha(long renderNode, float alpha); private static native void nSetHasOverlappingRendering(long renderNode, boolean hasOverlappingRendering); + private static native void nSetElevation(long renderNode, float lift); private static native void nSetTranslationX(long renderNode, float translationX); private static native void nSetTranslationY(long renderNode, float translationY); private static native void nSetTranslationZ(long renderNode, float translationZ); @@ -874,6 +883,7 @@ public class RenderNode { private static native float nGetCameraDistance(long renderNode); private static native float nGetScaleX(long renderNode); private static native float nGetScaleY(long renderNode); + private static native float nGetElevation(long renderNode); private static native float nGetTranslationX(long renderNode); private static native float nGetTranslationY(long renderNode); private static native float nGetTranslationZ(long renderNode); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index fdf31fa..463a2f7 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -3649,6 +3649,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, float tx = 0; float ty = 0; float tz = 0; + float elevation = 0; float rotation = 0; float rotationX = 0; float rotationY = 0; @@ -3732,6 +3733,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, tz = a.getDimensionPixelOffset(attr, 0); transformSet = true; break; + case com.android.internal.R.styleable.View_elevation: + elevation = a.getDimensionPixelOffset(attr, 0); + transformSet = true; + break; case com.android.internal.R.styleable.View_rotation: rotation = a.getFloat(attr, 0); transformSet = true; @@ -4080,6 +4085,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, setTranslationX(tx); setTranslationY(ty); setTranslationZ(tz); + setElevation(elevation); setRotation(rotation); setRotationX(rotationX); setRotationY(rotationY); @@ -10435,6 +10441,48 @@ public class View implements Drawable.Callback, KeyEvent.Callback, setTranslationY(y - mTop); } + /** + * The visual z position of this view, in pixels. This is equivalent to the + * {@link #setTranslationZ(float) translationZ} property plus the current + * {@link #getElevation() elevation} property. + * + * @return The visual z position of this view, in pixels. + */ + @ViewDebug.ExportedProperty(category = "drawing") + public float getZ() { + return getElevation() + getTranslationZ(); + } + + /** + * Sets the visual z position of this view, in pixels. This is equivalent to setting the + * {@link #setTranslationZ(float) translationZ} property to be the difference between + * the x value passed in and the current {@link #getElevation() elevation} property. + * + * @param z The visual z position of this view, in pixels. + */ + public void setZ(float z) { + setTranslationZ(z - getElevation()); + } + + @ViewDebug.ExportedProperty(category = "drawing") + public float getElevation() { + return mRenderNode.getElevation(); + } + + /** + * Sets the base depth location of this view. + * + * @attr ref android.R.styleable#View_elevation + */ + public void setElevation(float elevation) { + if (elevation != getElevation()) { + invalidateViewProperty(true, false); + mRenderNode.setElevation(elevation); + invalidateViewProperty(false, true); + + invalidateParentIfNeededAndWasQuickRejected(); + } + } /** * The horizontal location of this view relative to its {@link #getLeft() left} position. @@ -10502,9 +10550,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * The depth location of this view relative to its parent. + * The depth location of this view relative to its {@link #getElevation() elevation}. * - * @return The depth of this view relative to its parent. + * @return The depth of this view relative to its elevation. */ @ViewDebug.ExportedProperty(category = "drawing") public float getTranslationZ() { @@ -10512,7 +10560,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Sets the depth location of this view relative to its parent. + * Sets the depth location of this view relative to its {@link #getElevation() elevation}. * * @attr ref android.R.styleable#View_translationZ */ @@ -11184,7 +11232,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } // Damage the entire IsolatedZVolume recieving this view's shadow. - if (isHardwareAccelerated() && getTranslationZ() != 0) { + if (isHardwareAccelerated() && getZ() != 0) { damageShadowReceiver(); } } @@ -11260,7 +11308,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } else { damageInParent(); } - if (isHardwareAccelerated() && invalidateParent && getTranslationZ() != 0) { + if (isHardwareAccelerated() && invalidateParent && getZ() != 0) { damageShadowReceiver(); } } diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java index 6b21451..b1aa7b2 100644 --- a/core/java/android/view/ViewPropertyAnimator.java +++ b/core/java/android/view/ViewPropertyAnimator.java @@ -144,10 +144,11 @@ public class ViewPropertyAnimator { private static final int ROTATION_Y = 0x0080; private static final int X = 0x0100; private static final int Y = 0x0200; - private static final int ALPHA = 0x0400; + private static final int Z = 0x0400; + private static final int ALPHA = 0x0800; private static final int TRANSFORM_MASK = TRANSLATION_X | TRANSLATION_Y | TRANSLATION_Z | - SCALE_X | SCALE_Y | ROTATION | ROTATION_X | ROTATION_Y | X | Y; + SCALE_X | SCALE_Y | ROTATION | ROTATION_X | ROTATION_Y | X | Y | Z; /** * The mechanism by which the user can request several properties that are then animated @@ -470,6 +471,32 @@ public class ViewPropertyAnimator { } /** + * This method will cause the View's <code>z</code> property to be animated to the + * specified value. Animations already running on the property will be canceled. + * + * @param value The value to be animated to. + * @see View#setZ(float) + * @return This object, allowing calls to methods in this class to be chained. + */ + public ViewPropertyAnimator z(float value) { + animateProperty(Z, value); + return this; + } + + /** + * This method will cause the View's <code>z</code> property to be animated by the + * specified value. Animations already running on the property will be canceled. + * + * @param value The amount to be animated by, as an offset from the current value. + * @see View#setZ(float) + * @return This object, allowing calls to methods in this class to be chained. + */ + public ViewPropertyAnimator zBy(float value) { + animatePropertyBy(Z, value); + return this; + } + + /** * This method will cause the View's <code>rotation</code> property to be animated to the * specified value. Animations already running on the property will be canceled. * @@ -957,6 +984,9 @@ public class ViewPropertyAnimator { case Y: renderNode.setTranslationY(value - mView.mTop); break; + case Z: + renderNode.setTranslationZ(value - renderNode.getElevation()); + break; case ALPHA: info.mAlpha = value; renderNode.setAlpha(value); @@ -993,6 +1023,8 @@ public class ViewPropertyAnimator { return mView.mLeft + node.getTranslationX(); case Y: return mView.mTop + node.getTranslationY(); + case Z: + return node.getElevation() + node.getTranslationZ(); case ALPHA: return mView.mTransformationInfo.mAlpha; } |