diff options
author | Chris Craik <ccraik@google.com> | 2014-07-18 13:48:09 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2014-07-19 00:13:59 +0000 |
commit | 31ba192dd201df2cad96a8c503f730130ab0d80f (patch) | |
tree | 6c2be2ad287e826bf2f7f7fc6316b55c2fd36834 | |
parent | 5552cc5c9dd111c5fb1db512240b5daf15866c88 (diff) | |
download | frameworks_base-31ba192dd201df2cad96a8c503f730130ab0d80f.zip frameworks_base-31ba192dd201df2cad96a8c503f730130ab0d80f.tar.gz frameworks_base-31ba192dd201df2cad96a8c503f730130ab0d80f.tar.bz2 |
Tweaks to outline API
b/15283203
b/16142564
Remove boolean return value chaining, as it's redundant with
the data in the Outline itself.
Change-Id: I3116e57cd1b35c98b74e95195117edd7e39fb2df
21 files changed, 72 insertions, 95 deletions
diff --git a/api/current.txt b/api/current.txt index 2ee881d..e9fb3be 100644 --- a/api/current.txt +++ b/api/current.txt @@ -10898,11 +10898,9 @@ package android.graphics { ctor public Outline(android.graphics.Outline); method public boolean canClip(); method public boolean isEmpty(); - method public boolean isFilled(); method public void set(android.graphics.Outline); method public void setConvexPath(android.graphics.Path); method public void setEmpty(); - method public void setFilled(boolean); method public void setOval(int, int, int, int); method public void setOval(android.graphics.Rect); method public void setRect(int, int, int, int); @@ -11648,7 +11646,7 @@ package android.graphics.drawable { method public int getMinimumHeight(); method public int getMinimumWidth(); method public abstract int getOpacity(); - method public boolean getOutline(android.graphics.Outline); + method public void getOutline(android.graphics.Outline); method public boolean getPadding(android.graphics.Rect); method public int[] getState(); method public android.graphics.Region getTransparentRegion(); @@ -11980,7 +11978,7 @@ package android.graphics.drawable.shapes { method public android.graphics.drawable.shapes.Shape clone() throws java.lang.CloneNotSupportedException; method public abstract void draw(android.graphics.Canvas, android.graphics.Paint); method public final float getHeight(); - method public boolean getOutline(android.graphics.Outline); + method public void getOutline(android.graphics.Outline); method public final float getWidth(); method public boolean hasAlpha(); method protected void onResize(float, float); @@ -34135,7 +34133,6 @@ package android.view { method public void setOnLongClickListener(android.view.View.OnLongClickListener); method public void setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener); method public void setOnTouchListener(android.view.View.OnTouchListener); - method public deprecated void setOutline(android.graphics.Outline); method public void setOutlineProvider(android.view.ViewOutlineProvider); method public void setOverScrollMode(int); method public void setPadding(int, int, int, int); @@ -34688,7 +34685,7 @@ package android.view { public abstract class ViewOutlineProvider { ctor public ViewOutlineProvider(); - method public abstract boolean getOutline(android.view.View, android.graphics.Outline); + method public abstract void getOutline(android.view.View, android.graphics.Outline); field public static final android.view.ViewOutlineProvider BACKGROUND; } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 8cb7702..a5899de 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10762,7 +10762,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } - /** Deprecated, pending removal */ + /** + * Deprecated, pending removal + * + * @hide + */ @Deprecated public void setOutline(@Nullable Outline outline) {} @@ -10843,16 +10847,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // no provider, remove outline mRenderNode.setOutline(null); } else { - if (mOutlineProvider.getOutline(this, outline)) { - if (outline.isEmpty()) { - throw new IllegalStateException("Outline provider failed to build outline"); - } - // provider has provided - mRenderNode.setOutline(outline); - } else { - // provider failed to provide - mRenderNode.setOutline(null); - } + mOutlineProvider.getOutline(this, outline); + mRenderNode.setOutline(outline); } notifySubtreeAccessibilityStateChangedIfNeeded(); diff --git a/core/java/android/view/ViewOutlineProvider.java b/core/java/android/view/ViewOutlineProvider.java index 9c154d5..64624ae 100644 --- a/core/java/android/view/ViewOutlineProvider.java +++ b/core/java/android/view/ViewOutlineProvider.java @@ -31,13 +31,11 @@ public abstract class ViewOutlineProvider { */ public static final ViewOutlineProvider BACKGROUND = new ViewOutlineProvider() { @Override - public boolean getOutline(View view, Outline outline) { + public void getOutline(View view, Outline outline) { Drawable background = view.getBackground(); - if (background == null) { - // no background, no outline - return false; + if (background != null) { + background.getOutline(outline); } - return background.getOutline(outline); } }; @@ -50,8 +48,6 @@ public abstract class ViewOutlineProvider { * * @param view The view building the outline. * @param outline The empty outline to be populated. - * @return true if this View should have an outline, else false. The outline must be - * populated by this method, and non-empty if true is returned. */ - public abstract boolean getOutline(View view, Outline outline); + public abstract void getOutline(View view, Outline outline); } diff --git a/graphics/java/android/graphics/Outline.java b/graphics/java/android/graphics/Outline.java index 4bee554..1709558 100644 --- a/graphics/java/android/graphics/Outline.java +++ b/graphics/java/android/graphics/Outline.java @@ -96,6 +96,8 @@ public final class Outline { * * A filled 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; @@ -103,6 +105,8 @@ public final class Outline { /** * Returns whether the outline represents a fully opaque area. + * + * @hide */ public boolean isFilled() { return !isEmpty() && mIsFilled; diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 89236ad..acb34c2 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -869,9 +869,8 @@ public abstract class Drawable { * * @see android.view.View#setOutlineProvider(android.view.ViewOutlineProvider) */ - public boolean getOutline(@NonNull Outline outline) { + public void getOutline(@NonNull Outline outline) { outline.setRect(getBounds()); - return true; } /** diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index 771322d..55bc35e 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -126,11 +126,10 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { } @Override - public boolean getOutline(@NonNull Outline outline) { + public void getOutline(@NonNull Outline outline) { if (mCurrDrawable != null) { - return mCurrDrawable.getOutline(outline); + mCurrDrawable.getOutline(outline); } - return false; } @Override diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 6e9b776..4815586 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -1410,7 +1410,7 @@ public class GradientDrawable extends Drawable { } @Override - public boolean getOutline(Outline outline) { + public void getOutline(Outline outline) { final GradientState st = mGradientState; final Rect bounds = getBounds(); @@ -1419,7 +1419,7 @@ public class GradientDrawable extends Drawable { if (st.mRadiusArray != null) { buildPathIfDirty(); outline.setConvexPath(mPath); - return true; + return; } float rad = 0; @@ -1429,10 +1429,10 @@ public class GradientDrawable extends Drawable { Math.min(bounds.width(), bounds.height()) * 0.5f); } outline.setRoundRect(bounds, rad); - return true; + return; case OVAL: outline.setOval(bounds); - return true; + return; case LINE: // Hairlines (0-width stroke) must have a non-empty outline for // shadows to draw correctly, so we'll use a very small width. @@ -1443,10 +1443,9 @@ public class GradientDrawable extends Drawable { final int bottom = (int) Math.ceil(centerY + halfStrokeWidth); outline.setRect(bounds.left, top, bounds.right, bottom); - return true; + return; default: - // TODO: investigate - return false; + // TODO: support more complex shapes } } diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index 6db96b6..f6ccbf5 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -316,8 +316,8 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { } @Override - public boolean getOutline(@NonNull Outline outline) { - return mInsetState.mDrawable.getOutline(outline); + public void getOutline(@NonNull Outline outline) { + mInsetState.mDrawable.getOutline(outline); } @Override diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 8d83c74..073100a 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -603,16 +603,16 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { * @return <code>true</code> if an outline is available */ @Override - public boolean getOutline(@NonNull Outline outline) { + public void getOutline(@NonNull Outline outline) { final LayerState state = mLayerState; final ChildDrawable[] children = state.mChildren; final int N = state.mNum; for (int i = 0; i < N; i++) { - if (children[i].mDrawable.getOutline(outline)) { - return true; + children[i].mDrawable.getOutline(outline); + if (!outline.isEmpty()) { + return; } } - return false; } @Override diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index c0110c9..241ec65 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -284,9 +284,9 @@ public class NinePatchDrawable extends Drawable { } @Override - public boolean getOutline(@NonNull Outline outline) { + public void getOutline(@NonNull Outline outline) { final Rect bounds = getBounds(); - if (bounds.isEmpty()) return false; + if (bounds.isEmpty()) return; if (mNinePatchState != null) { NinePatch.InsetStruct insets = mNinePatchState.getBitmap().getNinePatchInsets(); @@ -298,10 +298,10 @@ public class NinePatchDrawable extends Drawable { bounds.bottom - outlineInsets.bottom, insets.outlineRadius); outline.setFilled(insets.outlineFilled); - return true; + return; } } - return super.getOutline(outline); + super.getOutline(outline); } /** diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index f955f7c..4a1d640 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -497,16 +497,16 @@ public class RippleDrawable extends LayerDrawable { * @return <code>true</code> if an outline is available */ @Override - public boolean getOutline(@NonNull Outline outline) { + public void getOutline(@NonNull Outline outline) { final LayerState state = mLayerState; final ChildDrawable[] children = state.mChildren; final int N = state.mNum; for (int i = 0; i < N; i++) { - if (children[i].mId != R.id.mask && children[i].mDrawable.getOutline(outline)) { - return true; + if (children[i].mId != R.id.mask) { + children[i].mDrawable.getOutline(outline); + if (!outline.isEmpty()) return; } } - return false; } @Override diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 9802529..2bed3b0 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -467,13 +467,10 @@ public class ShapeDrawable extends Drawable { } @Override - public boolean getOutline(Outline outline) { - if (mShapeState.mShape == null) { - // don't publish outline without a shape - return false; + public void getOutline(Outline outline) { + if (mShapeState.mShape != null) { + mShapeState.mShape.getOutline(outline); } - - return mShapeState.mShape.getOutline(outline); } @Override diff --git a/graphics/java/android/graphics/drawable/shapes/OvalShape.java b/graphics/java/android/graphics/drawable/shapes/OvalShape.java index 198dcc1..c9473f0 100644 --- a/graphics/java/android/graphics/drawable/shapes/OvalShape.java +++ b/graphics/java/android/graphics/drawable/shapes/OvalShape.java @@ -29,22 +29,18 @@ import android.graphics.RectF; */ public class OvalShape extends RectShape { - /** - * OvalShape constructor. - */ public OvalShape() {} - + @Override public void draw(Canvas canvas, Paint paint) { canvas.drawOval(rect(), paint); } @Override - public boolean getOutline(Outline outline) { + public void getOutline(Outline outline) { final RectF rect = rect(); outline.setOval((int) Math.ceil(rect.left), (int) Math.ceil(rect.top), (int) Math.floor(rect.right), (int) Math.floor(rect.bottom)); - return true; } } diff --git a/graphics/java/android/graphics/drawable/shapes/RectShape.java b/graphics/java/android/graphics/drawable/shapes/RectShape.java index 2a0256c..04cf293 100644 --- a/graphics/java/android/graphics/drawable/shapes/RectShape.java +++ b/graphics/java/android/graphics/drawable/shapes/RectShape.java @@ -29,10 +29,7 @@ import android.graphics.RectF; */ public class RectShape extends Shape { private RectF mRect = new RectF(); - - /** - * RectShape constructor. - */ + public RectShape() {} @Override @@ -41,11 +38,10 @@ public class RectShape extends Shape { } @Override - public boolean getOutline(Outline outline) { + public void getOutline(Outline outline) { final RectF rect = rect(); outline.setRect((int) Math.ceil(rect.left), (int) Math.ceil(rect.top), (int) Math.floor(rect.right), (int) Math.floor(rect.bottom)); - return true; } @Override diff --git a/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java b/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java index a6bb1bb..e5253b8 100644 --- a/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java +++ b/graphics/java/android/graphics/drawable/shapes/RoundRectShape.java @@ -80,8 +80,8 @@ public class RoundRectShape extends RectShape { } @Override - public boolean getOutline(Outline outline) { - if (mInnerRect != null) return false; // have a hole, can't produce valid outline + public void getOutline(Outline outline) { + if (mInnerRect != null) return; // have a hole, can't produce valid outline float radius = 0; if (mOuterRadii != null) { @@ -90,7 +90,7 @@ public class RoundRectShape extends RectShape { if (mOuterRadii[i] != radius) { // can't call simple constructors, use path outline.setConvexPath(mPath); - return true; + return; } } } @@ -99,7 +99,6 @@ public class RoundRectShape extends RectShape { outline.setRoundRect((int) Math.ceil(rect.left), (int) Math.ceil(rect.top), (int) Math.floor(rect.right), (int) Math.floor(rect.bottom), radius); - return true; } @Override diff --git a/graphics/java/android/graphics/drawable/shapes/Shape.java b/graphics/java/android/graphics/drawable/shapes/Shape.java index 1a20e8b..589fbaa 100644 --- a/graphics/java/android/graphics/drawable/shapes/Shape.java +++ b/graphics/java/android/graphics/drawable/shapes/Shape.java @@ -96,12 +96,8 @@ public abstract class Shape implements Cloneable { * Compute the Outline of the shape. * * The default implementation does not supply an outline. - * - * @return True if a valid outline has been computed, false otherwise. */ - public boolean getOutline(Outline outline) { - return false; - } + public void getOutline(Outline outline) {} @Override public Shape clone() throws CloneNotSupportedException { diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java index e973717..4757c5f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java @@ -116,13 +116,12 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On setFooterHeight(getFooterHeight()); setOutlineProvider(new ViewOutlineProvider() { @Override - public boolean getOutline(View view, Outline outline) { + public void getOutline(View view, Outline outline) { // The current height is measured with the footer, so account for the footer height // and the current clip (in the stack) int height = getMeasuredHeight() - mClipFromBottom - mMaxFooterHeight + mFooterHeight; outline.setRoundRect(0, 0, getWidth(), height, mConfig.taskViewRoundedCornerRadiusPx); - return true; } }); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java index d9719ea..d882a87 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java @@ -38,7 +38,7 @@ public abstract class ExpandableOutlineView extends ExpandableView { mDensity = getResources().getDisplayMetrics().density; setOutlineProvider(new ViewOutlineProvider() { @Override - public boolean getOutline(View view, Outline outline) { + public void getOutline(View view, Outline outline) { if (!mCustomOutline) { outline.setRect(0, mClipTopAmount, @@ -47,7 +47,6 @@ public abstract class ExpandableOutlineView extends ExpandableView { } else { outline.setRect(mOutlineRect); } - return true; } }); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java index 3012b13..b2709bc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java @@ -148,9 +148,8 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL }); setOutlineProvider(new ViewOutlineProvider() { @Override - public boolean getOutline(View view, Outline outline) { + public void getOutline(View view, Outline outline) { outline.setRect(mClipBounds); - return true; } }); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java index d232bc4..f3ff8ad 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java @@ -163,7 +163,7 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper. private static final ViewOutlineProvider CONTENT_HOLDER_OUTLINE_PROVIDER = new ViewOutlineProvider() { @Override - public boolean getOutline(View view, Outline outline) { + public void getOutline(View view, Outline outline) { int outlineLeft = view.getPaddingLeft(); int outlineTop = view.getPaddingTop(); @@ -171,7 +171,6 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper. outline.setRect(outlineLeft, outlineTop, view.getWidth() - outlineLeft - view.getPaddingRight(), view.getHeight() - outlineTop - view.getPaddingBottom()); - return true; } }; diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ClipOutlineActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ClipOutlineActivity.java index af448e8..23bb6b4 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/ClipOutlineActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ClipOutlineActivity.java @@ -25,6 +25,8 @@ import android.graphics.Outline; import android.graphics.Path; import android.graphics.Rect; import android.os.Bundle; +import android.view.View; +import android.view.ViewOutlineProvider; import android.widget.FrameLayout; import android.widget.TextView; @@ -58,11 +60,23 @@ public class ClipOutlineActivity extends Activity { public static class RegionView extends FrameLayout { private float mClipPosition = 0.0f; - private Outline mOutline = new Outline(); private Rect mRect = new Rect(); public RegionView(Context c) { super(c); + setOutlineProvider(new ViewOutlineProvider() { + + @Override + public void getOutline(View view, Outline outline) { + int w = getWidth() / 2; + int h = getHeight() / 2; + + mRect.set(0, 0, w, h); + mRect.offset((int) (mClipPosition * w), getHeight() / 4); + + outline.setRoundRect(mRect, w / 2); + } + }); setClipToOutline(true); } @@ -72,14 +86,7 @@ public class ClipOutlineActivity extends Activity { public void setClipPosition(float clipPosition) { mClipPosition = clipPosition; - int w = getWidth() / 2; - int h = getHeight() / 2; - - mRect.set(0, 0, w, h); - mRect.offset((int) (clipPosition * w), getHeight() / 4); - mOutline.setRoundRect(mRect, w / 2); - setOutline(mOutline); - invalidate(); + invalidateOutline(); } } |