Merge "Add outlineProvider attribute" into lmp-dev

This commit is contained in:
Chris Craik
2014-08-20 17:38:57 +00:00
committed by Android (Google) Code Review
5 changed files with 72 additions and 8 deletions

View File

@@ -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 {

View File

@@ -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.
* <p>
@@ -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.

View File

@@ -43,6 +43,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.
*

View File

@@ -2513,6 +2513,19 @@
result to valid color values. Saturate(S + D) -->
<enum name="add" value="16" />
</attr>
<!-- ViewOutlineProvider used to determine the View's Outline. -->
<attr name="outlineProvider">
<!-- Default, background drawable-driven outline. -->
<enum name="background" value="0" />
<!-- No outline provider. -->
<enum name="none" value="1" />
<!-- Generates an opaque outline for the bounds of the view. -->
<enum name="bounds" value="2" />
<!-- Generates an opaque outline for the padded bounds of the view. -->
<enum name="paddedBounds" value="3" />
</attr>
</declare-styleable>
<!-- Attributes that can be assigned to a tag for a particular View. -->

View File

@@ -2272,6 +2272,7 @@
<public type="attr" name="inset" />
<public type="attr" name="letterSpacing" />
<public type="attr" name="fontFeatureSettings" />
<public type="attr" name="outlineProvider" />
<public-padding type="dimen" name="l_resource_pad" end="0x01050010" />