summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-04-25 18:34:11 -0700
committerChris Craik <ccraik@google.com>2014-04-28 14:33:33 -0700
commitcc39e16cb98855f35079941b5e7e6eac2b7bc388 (patch)
treef37cb0ce9da11a018446adfb83c756f5e76e77f1 /core
parent802667b20b2170ddce94d70a022b68b64b9a7493 (diff)
downloadframeworks_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')
-rw-r--r--core/java/android/view/RenderNode.java10
-rw-r--r--core/java/android/view/View.java58
-rw-r--r--core/java/android/view/ViewPropertyAnimator.java36
-rw-r--r--core/jni/android_view_RenderNode.cpp14
-rw-r--r--core/res/res/values/attrs.xml5
-rw-r--r--core/res/res/values/public.xml1
6 files changed, 116 insertions, 8 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;
}
diff --git a/core/jni/android_view_RenderNode.cpp b/core/jni/android_view_RenderNode.cpp
index 8dacfeb..3ad2ae5 100644
--- a/core/jni/android_view_RenderNode.cpp
+++ b/core/jni/android_view_RenderNode.cpp
@@ -164,6 +164,12 @@ static void android_view_RenderNode_setHasOverlappingRendering(JNIEnv* env,
renderNode->mutateStagingProperties().setHasOverlappingRendering(hasOverlappingRendering);
}
+static void android_view_RenderNode_setElevation(JNIEnv* env,
+ jobject clazz, jlong renderNodePtr, float elevation) {
+ RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
+ renderNode->mutateStagingProperties().setElevation(elevation);
+}
+
static void android_view_RenderNode_setTranslationX(JNIEnv* env,
jobject clazz, jlong renderNodePtr, float tx) {
RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
@@ -331,6 +337,12 @@ static jfloat android_view_RenderNode_getScaleY(JNIEnv* env,
return renderNode->stagingProperties().getScaleY();
}
+static jfloat android_view_RenderNode_getElevation(JNIEnv* env,
+ jobject clazz, jlong renderNodePtr) {
+ RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
+ return renderNode->stagingProperties().getElevation();
+}
+
static jfloat android_view_RenderNode_getTranslationX(JNIEnv* env,
jobject clazz, jlong renderNodePtr) {
RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
@@ -457,6 +469,7 @@ static JNINativeMethod gMethods[] = {
{ "nSetAlpha", "(JF)V", (void*) android_view_RenderNode_setAlpha },
{ "nSetHasOverlappingRendering", "(JZ)V",
(void*) android_view_RenderNode_setHasOverlappingRendering },
+ { "nSetElevation", "(JF)V", (void*) android_view_RenderNode_setElevation },
{ "nSetTranslationX", "(JF)V", (void*) android_view_RenderNode_setTranslationX },
{ "nSetTranslationY", "(JF)V", (void*) android_view_RenderNode_setTranslationY },
{ "nSetTranslationZ", "(JF)V", (void*) android_view_RenderNode_setTranslationZ },
@@ -485,6 +498,7 @@ static JNINativeMethod gMethods[] = {
{ "nGetCameraDistance", "(J)F", (void*) android_view_RenderNode_getCameraDistance },
{ "nGetScaleX", "(J)F", (void*) android_view_RenderNode_getScaleX },
{ "nGetScaleY", "(J)F", (void*) android_view_RenderNode_getScaleY },
+ { "nGetElevation", "(J)F", (void*) android_view_RenderNode_getElevation },
{ "nGetTranslationX", "(J)F", (void*) android_view_RenderNode_getTranslationX },
{ "nGetTranslationY", "(J)F", (void*) android_view_RenderNode_getTranslationY },
{ "nGetTranslationZ", "(J)F", (void*) android_view_RenderNode_getTranslationZ },
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 69440be..abac60e 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2191,6 +2191,9 @@
(completely opaque). -->
<attr name="alpha" format="float" />
+ <!-- base z depth of the view -->
+ <attr name="elevation" format="dimension" />
+
<!-- translation in x of the view. This value is added post-layout to the left
property of the view, which is set by its layout. -->
<attr name="translationX" format="dimension" />
@@ -2199,7 +2202,7 @@
property of the view, which is set by its layout. -->
<attr name="translationY" format="dimension" />
- <!-- translation in z of the view. This value is added post-layout to its position. -->
+ <!-- translation in z of the view. This value is added to its elevation. -->
<attr name="translationZ" format="dimension" />
<!-- x location of the pivot point around which the view will rotate and scale.
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index f68f759..85ef004 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2163,6 +2163,7 @@
<public type="attr" name="windowAllowEnterTransitionOverlap" />
<public type="attr" name="sessionService" />
<public type="attr" name="switchStyle" />
+ <public type="attr" name="elevation" />
<public-padding type="dimen" name="l_resource_pad" end="0x01050010" />