From f56885d413b9910a414716c4652c26f888dac316 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Fri, 8 Aug 2014 10:46:03 -0700 Subject: [PATCH] Add outlineProvider attribute bug:16871683 Change-Id: Iae9326c41872ac03d40ebeec6257522a34cbe1ff --- api/current.txt | 3 ++ core/java/android/view/View.java | 34 ++++++++++++++----- .../android/view/ViewOutlineProvider.java | 29 ++++++++++++++++ core/res/res/values/attrs.xml | 13 +++++++ core/res/res/values/public.xml | 1 + 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/api/current.txt b/api/current.txt index b2106d24b4b39..3faf5b91041bc 100644 --- a/api/current.txt +++ b/api/current.txt @@ -930,6 +930,7 @@ package android { field public static final int orderingFromXml = 16843239; // 0x10101e7 field public static final int orientation = 16842948; // 0x10100c4 field public static final int outAnimation = 16843128; // 0x1010178 + field public static final int outlineProvider = 16843961; // 0x10104b9 field public static final int overScrollFooter = 16843459; // 0x10102c3 field public static final int overScrollHeader = 16843458; // 0x10102c2 field public static final int overScrollMode = 16843457; // 0x10102c1 @@ -35193,6 +35194,8 @@ package android.view { ctor public ViewOutlineProvider(); method public abstract void getOutline(android.view.View, android.graphics.Outline); field public static final android.view.ViewOutlineProvider BACKGROUND; + field public static final android.view.ViewOutlineProvider BOUNDS; + field public static final android.view.ViewOutlineProvider PADDED_BOUNDS; } public class ViewOverlay { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 3adc41a0e86d5..f17daafca6078 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4047,6 +4047,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mBackgroundTintMode = Drawable.parseTintMode(a.getInt( R.styleable.View_backgroundTintMode, -1), mBackgroundTintMode); break; + case R.styleable.View_outlineProvider: + setOutlineProviderFromAttribute(a.getInt(R.styleable.View_outlineProvider, + PROVIDER_BACKGROUND)); + break; } } @@ -10823,14 +10827,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } - /** - * Deprecated, pending removal - * - * @hide - */ - @Deprecated - public void setOutline(@Nullable Outline outline) {} - /** * Returns whether the Outline should be used to clip the contents of the View. *

@@ -10860,6 +10856,28 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } + // correspond to the enum values of View_outlineProvider + private static final int PROVIDER_BACKGROUND = 0; + private static final int PROVIDER_NONE = 1; + private static final int PROVIDER_BOUNDS = 2; + private static final int PROVIDER_PADDED_BOUNDS = 3; + private void setOutlineProviderFromAttribute(int providerInt) { + switch (providerInt) { + case PROVIDER_BACKGROUND: + setOutlineProvider(ViewOutlineProvider.BACKGROUND); + break; + case PROVIDER_NONE: + setOutlineProvider(null); + break; + case PROVIDER_BOUNDS: + setOutlineProvider(ViewOutlineProvider.BOUNDS); + break; + case PROVIDER_PADDED_BOUNDS: + setOutlineProvider(ViewOutlineProvider.PADDED_BOUNDS); + break; + } + } + /** * Sets the {@link ViewOutlineProvider} of the view, which generates the Outline that defines * the shape of the shadow it casts, and enables outline clipping. diff --git a/core/java/android/view/ViewOutlineProvider.java b/core/java/android/view/ViewOutlineProvider.java index 170c5d8149cc1..a1a02f67ff5bc 100644 --- a/core/java/android/view/ViewOutlineProvider.java +++ b/core/java/android/view/ViewOutlineProvider.java @@ -43,6 +43,35 @@ public abstract class ViewOutlineProvider { } }; + /** + * Maintains the outline of the View to match its rectangular bounds, + * at 1.0f alpha. + * + * This can be used to enable Views that are opaque but lacking a background cast a shadow. + */ + public static final ViewOutlineProvider BOUNDS = new ViewOutlineProvider() { + @Override + public void getOutline(View view, Outline outline) { + outline.setRect(0, 0, view.getWidth(), view.getHeight()); + } + }; + + /** + * Maintains the outline of the View to match its rectangular padded bounds, + * at 1.0f alpha. + * + * This can be used to enable Views that are opaque but lacking a background cast a shadow. + */ + public static final ViewOutlineProvider PADDED_BOUNDS = new ViewOutlineProvider() { + @Override + public void getOutline(View view, Outline outline) { + outline.setRect(view.getPaddingLeft(), + view.getPaddingTop(), + view.getWidth() - view.getPaddingRight(), + view.getHeight() - view.getPaddingBottom()); + } + }; + /** * Called to get the provider to populate the Outline. * diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index f9ea5d8a0cfbf..08aaa6aee8212 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2513,6 +2513,19 @@ result to valid color values. Saturate(S + D) --> + + + + + + + + + + + + + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 7ade51d9c1ad2..ed66c652bb742 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2272,6 +2272,7 @@ +