diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/NotificationHeaderView.java | 16 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/MediaNotificationView.java | 136 |
2 files changed, 150 insertions, 2 deletions
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 1c0ea0f9120b..b3d16763d0d7 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -25,8 +25,6 @@ import android.widget.LinearLayout; import android.widget.RemoteViews; import android.widget.TextView; -import com.android.internal.R; - import java.util.ArrayList; /** @@ -39,6 +37,7 @@ public class NotificationHeaderView extends LinearLayout { public static final int NO_COLOR = -1; private final int mHeaderMinWidth; private final int mExpandTopPadding; + private final int mContentEndMargin; private View mAppName; private View mSubTextView; private OnClickListener mExpandClickListener; @@ -51,6 +50,7 @@ public class NotificationHeaderView extends LinearLayout { private int mOriginalNotificationColor; private boolean mGroupHeader; private boolean mExpanded; + private boolean mShowWorkBadgeAtEnd; public NotificationHeaderView(Context context) { this(context, null); @@ -68,6 +68,8 @@ public class NotificationHeaderView extends LinearLayout { super(context, attrs, defStyleAttr, defStyleRes); mHeaderMinWidth = getResources().getDimensionPixelSize( com.android.internal.R.dimen.notification_header_shrink_min_width); + mContentEndMargin = getResources().getDimensionPixelSize( + com.android.internal.R.dimen.notification_content_margin_end); mExpandTopPadding = (int) (1 * getResources().getDisplayMetrics().density); } @@ -135,6 +137,9 @@ public class NotificationHeaderView extends LinearLayout { super.onLayout(changed, l, t, r, b); if (mProfileBadge.getVisibility() != View.GONE) { int paddingEnd = getPaddingEnd(); + if (mShowWorkBadgeAtEnd) { + paddingEnd = mContentEndMargin; + } if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) { mProfileBadge.layout(paddingEnd, mProfileBadge.getTop(), @@ -225,6 +230,13 @@ public class NotificationHeaderView extends LinearLayout { mExpandButton.setPadding(0, paddingTop, 0, 0); } + public void setShowWorkBadgeAtEnd(boolean showWorkBadgeAtEnd) { + if (showWorkBadgeAtEnd != mShowWorkBadgeAtEnd) { + setClipToPadding(!showWorkBadgeAtEnd); + mShowWorkBadgeAtEnd = showWorkBadgeAtEnd; + } + } + public class HeaderTouchListener implements View.OnTouchListener { private final ArrayList<Rect> mTouchRects = new ArrayList<>(); diff --git a/core/java/com/android/internal/widget/MediaNotificationView.java b/core/java/com/android/internal/widget/MediaNotificationView.java new file mode 100644 index 000000000000..b45fd06c8a71 --- /dev/null +++ b/core/java/com/android/internal/widget/MediaNotificationView.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.internal.widget; + +import android.annotation.Nullable; +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.RemoteViews; + +/** + * A TextView that can float around an image on the end. + * + * @hide + */ +@RemoteViews.RemoteView +public class MediaNotificationView extends RelativeLayout { + + private final int mMaxImageSize; + private final int mImageMarginBottom; + private final int mImageMinTopMargin; + private final int mNotificationContentMarginEnd; + private final int mNotificationContentImageMarginEnd; + private ImageView mRightIcon; + private View mActions; + private View mHeader; + + public MediaNotificationView(Context context) { + this(context, null); + } + + public MediaNotificationView(Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public MediaNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int mode = MeasureSpec.getMode(widthMeasureSpec); + boolean hasIcon = mRightIcon.getVisibility() != GONE; + if (hasIcon && mode != MeasureSpec.UNSPECIFIED) { + measureChild(mActions, widthMeasureSpec, heightMeasureSpec); + int size = MeasureSpec.getSize(widthMeasureSpec); + int height = MeasureSpec.getSize(heightMeasureSpec); + size = size - mActions.getMeasuredWidth(); + ViewGroup.MarginLayoutParams layoutParams = + (MarginLayoutParams) mRightIcon.getLayoutParams(); + size -= layoutParams.getMarginEnd(); + size = Math.min(size, mMaxImageSize); + size = Math.max(size, mRightIcon.getMinimumWidth()); + layoutParams.width = size; + layoutParams.height = size; + // because we can't allign it to the bottom with a margin, we add a topmargin to it + layoutParams.topMargin = height - size - mImageMarginBottom; + // If the topMargin is high enough we can also remove the header constraint! + if (layoutParams.topMargin >= mImageMinTopMargin) { + resetHeaderIndention(); + } else { + int paddingEnd = mNotificationContentImageMarginEnd; + ViewGroup.MarginLayoutParams headerParams = + (MarginLayoutParams) mHeader.getLayoutParams(); + headerParams.setMarginEnd(size + layoutParams.getMarginEnd()); + if (mHeader.getPaddingEnd() != paddingEnd) { + mHeader.setPadding( + isLayoutRtl() ? paddingEnd : mHeader.getPaddingLeft(), + mHeader.getPaddingTop(), + isLayoutRtl() ? mHeader.getPaddingLeft() : paddingEnd, + mHeader.getPaddingBottom()); + mHeader.setLayoutParams(headerParams); + } + } + mRightIcon.setLayoutParams(layoutParams); + } else if (!hasIcon && mHeader.getPaddingEnd() != mNotificationContentMarginEnd) { + resetHeaderIndention(); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + + private void resetHeaderIndention() { + if (mHeader.getPaddingEnd() != mNotificationContentMarginEnd) { + ViewGroup.MarginLayoutParams headerParams = + (MarginLayoutParams) mHeader.getLayoutParams(); + headerParams.setMarginEnd(0); + mHeader.setPadding( + isLayoutRtl() ? mNotificationContentMarginEnd : mHeader.getPaddingLeft(), + mHeader.getPaddingTop(), + isLayoutRtl() ? mHeader.getPaddingLeft() : mNotificationContentMarginEnd, + mHeader.getPaddingBottom()); + mHeader.setLayoutParams(headerParams); + } + } + + public MediaNotificationView(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + mMaxImageSize = context.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.media_notification_expanded_image_max_size); + mImageMarginBottom = context.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.media_notification_expanded_image_margin_bottom); + mImageMinTopMargin = (int) (context.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.notification_content_margin_top) + + getResources().getDisplayMetrics().density * 2); + mNotificationContentMarginEnd = context.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.notification_content_margin_end); + mNotificationContentImageMarginEnd = context.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.notification_content_image_margin_end); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mRightIcon = (ImageView) findViewById(com.android.internal.R.id.right_icon); + mActions = findViewById(com.android.internal.R.id.media_actions); + mHeader = findViewById(com.android.internal.R.id.notification_header); + } +} |
