summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-07-30 18:23:07 -0700
committerChris Craik <ccraik@google.com>2014-07-31 12:29:57 -0700
commit77b5cad3efedd20f2b7cc14d87ccce1b0261960a (patch)
tree5acf378a0aa0477ef585d71a0b9e6c56cfd1d6c9 /graphics/java
parentf660edb25a99282ce86b91804cd0145c1ef54bab (diff)
downloadframeworks_base-77b5cad3efedd20f2b7cc14d87ccce1b0261960a.zip
frameworks_base-77b5cad3efedd20f2b7cc14d87ccce1b0261960a.tar.gz
frameworks_base-77b5cad3efedd20f2b7cc14d87ccce1b0261960a.tar.bz2
Add outline alpha
bug:16140822 bug:16566746 This allows background drawables to alter the opacity of a shadow being cast with their own alpha values. Change-Id: I49698cc7c1bf4b2b55ffe2f82899543ca62bc61c
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/NinePatch.java6
-rw-r--r--graphics/java/android/graphics/Outline.java25
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java8
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java1
-rw-r--r--graphics/java/android/graphics/drawable/LayerDrawable.java5
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java2
-rw-r--r--graphics/java/android/graphics/drawable/RippleDrawable.java4
-rw-r--r--graphics/java/android/graphics/drawable/ShapeDrawable.java1
8 files changed, 21 insertions, 31 deletions
diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java
index 335bce0..3bccf08 100644
--- a/graphics/java/android/graphics/NinePatch.java
+++ b/graphics/java/android/graphics/NinePatch.java
@@ -43,7 +43,7 @@ public class NinePatch {
@SuppressWarnings({"UnusedDeclaration"}) // called from JNI
InsetStruct(int opticalLeft, int opticalTop, int opticalRight, int opticalBottom,
int outlineLeft, int outlineTop, int outlineRight, int outlineBottom,
- float outlineRadius, boolean outlineFilled, float decodeScale) {
+ float outlineRadius, int outlineAlpha, float decodeScale) {
opticalRect = new Rect(opticalLeft, opticalTop, opticalRight, opticalBottom);
outlineRect = new Rect(outlineLeft, outlineTop, outlineRight, outlineBottom);
@@ -55,13 +55,13 @@ public class NinePatch {
outlineRect.scaleRoundIn(decodeScale);
}
this.outlineRadius = outlineRadius * decodeScale;
- this.outlineFilled = outlineFilled;
+ this.outlineAlpha = outlineAlpha / 255.0f;
}
public final Rect opticalRect;
public final Rect outlineRect;
public final float outlineRadius;
- public final boolean outlineFilled;
+ public final float outlineAlpha;
}
private final Bitmap mBitmap;
diff --git a/graphics/java/android/graphics/Outline.java b/graphics/java/android/graphics/Outline.java
index 3a4c2a7..1cf5f37 100644
--- a/graphics/java/android/graphics/Outline.java
+++ b/graphics/java/android/graphics/Outline.java
@@ -37,9 +37,8 @@ public final class Outline {
public Rect mRect;
/** @hide */
public float mRadius;
-
/** @hide */
- public boolean mIsFilled;
+ public float mAlpha;
/**
* Constructs an empty Outline. Call one of the setter methods to make
@@ -63,7 +62,6 @@ public final class Outline {
mPath = null;
mRect = null;
mRadius = 0;
- mIsFilled = true;
}
/**
@@ -92,24 +90,24 @@ public final class Outline {
}
/**
- * Sets whether the outline represents a fully opaque area.
+ * Sets the alpha represented by the Outline.
*
- * A filled outline is assumed, by the drawing system, to fully cover content beneath it,
- * meaning content beneath may be optimized away.
+ * Content producing a fully opaque (alpha = 1.0f) outline is assumed, by the drawing system,
+ * to fully cover content beneath it, meaning content beneath may be optimized away.
*
* @hide
*/
- public void setFilled(boolean isFilled) {
- mIsFilled = isFilled;
+ public void setAlpha(float alpha) {
+ mAlpha = alpha;
}
/**
- * Returns whether the outline represents a fully opaque area.
+ * Sets the alpha represented by the Outline.
*
* @hide
*/
- public boolean isFilled() {
- return !isEmpty() && mIsFilled;
+ public float getAlpha() {
+ return mAlpha;
}
/**
@@ -132,7 +130,7 @@ public final class Outline {
mRect.set(src.mRect);
}
mRadius = src.mRadius;
- mIsFilled = src.mIsFilled;
+ mAlpha = src.mAlpha;
}
/**
@@ -164,7 +162,6 @@ public final class Outline {
mRect.set(left, top, right, bottom);
mRadius = radius;
mPath = null;
- mIsFilled = true;
}
/**
@@ -193,7 +190,6 @@ public final class Outline {
mPath.reset();
mPath.addOval(left, top, right, bottom, Path.Direction.CW);
mRect = null;
- mIsFilled = true;
}
/**
@@ -220,6 +216,5 @@ public final class Outline {
mPath.set(convexPath);
mRect = null;
mRadius = -1.0f;
- mIsFilled = true;
}
}
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index acb34c2..df9f3c3 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -861,16 +861,14 @@ public abstract class Drawable {
* This method is called by the default {@link android.view.ViewOutlineProvider} to define
* the outline of the View.
* <p>
- * The default behavior defines the outline to be the bounding rectangle. Subclasses that wish
- * to convey a different shape must override this method.
- *
- * @return true if this drawable actually has an outline, else false. The outline must be
- * populated by the drawable if true is returned.
+ * The default behavior defines the outline to be the bounding rectangle of 0 alpha.
+ * Subclasses that wish to convey a different shape or alpha value must override this method.
*
* @see android.view.View#setOutlineProvider(android.view.ViewOutlineProvider)
*/
public void getOutline(@NonNull Outline outline) {
outline.setRect(getBounds());
+ outline.setAlpha(getAlpha() / 255.0f);
}
/**
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 4815586..a383aab 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -1413,6 +1413,7 @@ public class GradientDrawable extends Drawable {
public void getOutline(Outline outline) {
final GradientState st = mGradientState;
final Rect bounds = getBounds();
+ outline.setAlpha(mAlpha / 255.0f);
switch (st.mShape) {
case RECTANGLE:
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index 073100a..d094ce4 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -595,12 +595,9 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
}
/**
- * Populates <code>outline</code> with the first available layer outline.
- * Returns <code>true</code> if an outline is available, <code>false</code>
- * otherwise.
+ * Populates <code>outline</code> with the first available (non-empty) layer outline.
*
* @param outline Outline in which to place the first available layer outline
- * @return <code>true</code> if an outline is available
*/
@Override
public void getOutline(@NonNull Outline outline) {
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index 241ec65..eb313ae 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -297,7 +297,7 @@ public class NinePatchDrawable extends Drawable {
bounds.right - outlineInsets.right,
bounds.bottom - outlineInsets.bottom,
insets.outlineRadius);
- outline.setFilled(insets.outlineFilled);
+ outline.setAlpha(insets.outlineAlpha * (getAlpha() / 255.0f));
return;
}
}
diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java
index eb7291c..cf675ed 100644
--- a/graphics/java/android/graphics/drawable/RippleDrawable.java
+++ b/graphics/java/android/graphics/drawable/RippleDrawable.java
@@ -585,11 +585,9 @@ public class RippleDrawable extends LayerDrawable {
/**
* Populates <code>outline</code> with the first available layer outline,
- * excluding the mask layer. Returns <code>true</code> if an outline is
- * available, <code>false</code> otherwise.
+ * excluding the mask layer.
*
* @param outline Outline in which to place the first available layer outline
- * @return <code>true</code> if an outline is available
*/
@Override
public void getOutline(@NonNull Outline outline) {
diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java
index 2bed3b0..394f584 100644
--- a/graphics/java/android/graphics/drawable/ShapeDrawable.java
+++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java
@@ -470,6 +470,7 @@ public class ShapeDrawable extends Drawable {
public void getOutline(Outline outline) {
if (mShapeState.mShape != null) {
mShapeState.mShape.getOutline(outline);
+ outline.setAlpha(getAlpha() / 255.0f);
}
}