diff options
| author | Chris Craik <ccraik@google.com> | 2014-08-20 17:38:57 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-19 22:53:25 +0000 |
| commit | e2527bc206011ad02f208bdb590b7010366f5926 (patch) | |
| tree | f24899799dcd238035265e481075b90169560574 /core/java/android | |
| parent | aba9715ae77dcc9c100677a0b3e822aaf919f3ff (diff) | |
| parent | f56885d413b9910a414716c4652c26f888dac316 (diff) | |
Merge "Add outlineProvider attribute" into lmp-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/View.java | 34 | ||||
| -rw-r--r-- | core/java/android/view/ViewOutlineProvider.java | 29 |
2 files changed, 55 insertions, 8 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 3adc41a0e86d..f17daafca607 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; } } @@ -10824,14 +10828,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. * <p> * Note that this flag will only be respected if the View's Outline returns true from @@ -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 170c5d8149cc..a1a02f67ff5b 100644 --- a/core/java/android/view/ViewOutlineProvider.java +++ b/core/java/android/view/ViewOutlineProvider.java @@ -44,6 +44,35 @@ public abstract class ViewOutlineProvider { }; /** + * Maintains the outline of the View to match its rectangular bounds, + * at <code>1.0f</code> 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 <code>1.0f</code> 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. * * This method will be called by a View when its owned Drawables are invalidated, when the |
