diff options
| author | Mady Mellor <madym@google.com> | 2016-04-30 17:31:02 -0700 |
|---|---|---|
| committer | Mady Mellor <madym@google.com> | 2016-05-24 11:39:12 -0700 |
| commit | b0a824687f56b6950338aad169d8d837f8ed657b (patch) | |
| tree | 22a9a1a83e3cfb93f86d89f47c2a52c08ff76242 /core/java/android/view/NotificationHeaderView.java | |
| parent | a3ec065a43069a19dc42f023a40d54a3178f1b44 (diff) | |
Children should have backgrounds
To add a background to children of a group, a couple of things
are changed when a group is in the expanded state:
- The parent's shadow + background is removed
- The group header is given a background and elevation
- The children are elevated to cast a shadow and have backgrounds
- When it's fully expanded the dividers won't be shown
- There's extra height added to the parent so that the child
may cast the bottom shadow of the group
- As the children move into the bottom stack the last visible
one alters its height and the ones below it are hidden
to achieve the clipping effect
Fixes: 27591195
Fixes: 28655641
Change-Id: I0484308843e9b8bc10391387e54de07973a48f7d
Diffstat (limited to 'core/java/android/view/NotificationHeaderView.java')
| -rw-r--r-- | core/java/android/view/NotificationHeaderView.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 37da8695a1ad..6e6baeadd45d 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -18,7 +18,11 @@ package android.view; import android.annotation.Nullable; import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Outline; import android.graphics.Rect; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; import android.widget.RemoteViews; @@ -47,6 +51,18 @@ public class NotificationHeaderView extends ViewGroup { private int mOriginalNotificationColor; private boolean mExpanded; private boolean mShowWorkBadgeAtEnd; + private Drawable mBackground; + private int mHeaderBackgroundHeight; + + ViewOutlineProvider mProvider = new ViewOutlineProvider() { + @Override + public void getOutline(View view, Outline outline) { + if (mBackground != null) { + outline.setRect(0, 0, getWidth(), mHeaderBackgroundHeight); + outline.setAlpha(1f); + } + } + }; public NotificationHeaderView(Context context) { this(context, null); @@ -66,6 +82,8 @@ public class NotificationHeaderView extends ViewGroup { com.android.internal.R.dimen.notification_header_shrink_min_width); mContentEndMargin = getResources().getDimensionPixelSize( com.android.internal.R.dimen.notification_content_margin_end); + mHeaderBackgroundHeight = getResources().getDimensionPixelSize( + com.android.internal.R.dimen.notification_header_background_height); } @Override @@ -165,6 +183,43 @@ public class NotificationHeaderView extends ViewGroup { return new ViewGroup.MarginLayoutParams(getContext(), attrs); } + /** + * Set a {@link Drawable} to be displayed as a background on the header. + */ + public void setHeaderBackgroundDrawable(Drawable drawable) { + if (drawable != null) { + setWillNotDraw(false); + mBackground = drawable; + mBackground.setCallback(this); + setOutlineProvider(mProvider); + } else { + setWillNotDraw(true); + mBackground = null; + setOutlineProvider(null); + } + invalidate(); + } + + @Override + protected void onDraw(Canvas canvas) { + if (mBackground != null) { + mBackground.setBounds(0, 0, getWidth(), mHeaderBackgroundHeight); + mBackground.draw(canvas); + } + } + + @Override + protected boolean verifyDrawable(Drawable who) { + return super.verifyDrawable(who) || who == mBackground; + } + + @Override + protected void drawableStateChanged() { + if (mBackground != null && mBackground.isStateful()) { + mBackground.setState(getDrawableState()); + } + } + private void updateTouchListener() { if (mExpandClickListener != null) { mTouchListener.bindTouchRects(); |
