diff --git a/api/current.txt b/api/current.txt index 8f757857fb0ac..5a82f1d3a75e0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -929,6 +929,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 @@ -34958,6 +34959,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) -->