Implementing gradual image fade for the media template
Test: play music
Merged-In: I525513ce1da1237c4edad32c0ed31e79d5eacd32
Change-Id: I525513ce1da1237c4edad32c0ed31e79d5eacd32
Fixes: 36561228
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index d64ffa9..07e4a8f 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -4959,6 +4959,22 @@
return false;
}
+
+ /**
+ * @return true if this is a media notification
+ *
+ * @hide
+ */
+ public boolean isMediaNotification() {
+ Class<? extends Style> style = getNotificationStyle();
+ if (MediaStyle.class.equals(style)) {
+ return true;
+ } else if (DecoratedMediaCustomViewStyle.class.equals(style)) {
+ return true;
+ }
+ return false;
+ }
+
private boolean hasLargeIcon() {
return mLargeIcon != null || largeIcon != null;
}
diff --git a/core/java/com/android/internal/widget/MediaNotificationView.java b/core/java/com/android/internal/widget/MediaNotificationView.java
index afb2a5e..bbebcc2 100644
--- a/core/java/com/android/internal/widget/MediaNotificationView.java
+++ b/core/java/com/android/internal/widget/MediaNotificationView.java
@@ -23,7 +23,6 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
-import android.widget.RelativeLayout;
import android.widget.RemoteViews;
/**
@@ -34,8 +33,7 @@
@RemoteViews.RemoteView
public class MediaNotificationView extends FrameLayout {
- private final int mMaxImageSize;
- private final int mImageMinTopMargin;
+ private final int mSmallImageSize;
private final int mNotificationContentMarginEnd;
private final int mNotificationContentImageMarginEnd;
private ImageView mRightIcon;
@@ -57,72 +55,68 @@
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int mode = MeasureSpec.getMode(widthMeasureSpec);
boolean hasIcon = mRightIcon.getVisibility() != GONE;
+ if (!hasIcon) {
+ resetHeaderIndention();
+ }
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ int mode = MeasureSpec.getMode(widthMeasureSpec);
+ boolean reMeasure = false;
if (hasIcon && mode != MeasureSpec.UNSPECIFIED) {
- measureChild(mActions, widthMeasureSpec, heightMeasureSpec);
int size = MeasureSpec.getSize(widthMeasureSpec);
size = size - mActions.getMeasuredWidth();
ViewGroup.MarginLayoutParams layoutParams =
(MarginLayoutParams) mRightIcon.getLayoutParams();
int imageEndMargin = layoutParams.getMarginEnd();
size -= imageEndMargin;
- size = Math.min(size, mMaxImageSize);
- size = Math.max(size, mRightIcon.getMinimumWidth());
- layoutParams.width = size;
- layoutParams.height = size;
- mRightIcon.setLayoutParams(layoutParams);
-
- // lets ensure that the main column doesn't run into the image
- ViewGroup.MarginLayoutParams mainParams
- = (MarginLayoutParams) mMainColumn.getLayoutParams();
- int marginEnd = size + imageEndMargin + mNotificationContentMarginEnd;
- if (marginEnd != mainParams.getMarginEnd()) {
- mainParams.setMarginEnd(marginEnd);
- mMainColumn.setLayoutParams(mainParams);
+ int fullHeight = getMeasuredHeight();
+ if (size < fullHeight) {
+ size = mSmallImageSize;
+ } else {
+ size = fullHeight;
}
-
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- ViewGroup.MarginLayoutParams iconParams =
- (MarginLayoutParams) mRightIcon.getLayoutParams();
- int topMargin = getMeasuredHeight() - mRightIcon.getMeasuredHeight()
- - iconParams.bottomMargin;
- // If the topMargin is high enough we can also remove the header constraint!
- boolean reMeasure = false;
- if (!hasIcon || topMargin >= mImageMinTopMargin) {
- reMeasure = resetHeaderIndention();
- } else {
- int paddingEnd = mNotificationContentImageMarginEnd;
- ViewGroup.MarginLayoutParams headerParams =
- (MarginLayoutParams) mHeader.getLayoutParams();
- int newMarginEnd = mRightIcon.getMeasuredWidth() + iconParams.getMarginEnd();
- if (headerParams.getMarginEnd() != newMarginEnd) {
- headerParams.setMarginEnd(newMarginEnd);
- mHeader.setLayoutParams(headerParams);
+ if (layoutParams.width != size || layoutParams.height != size) {
+ layoutParams.width = size;
+ layoutParams.height = size;
+ mRightIcon.setLayoutParams(layoutParams);
reMeasure = true;
}
- if (mHeader.getPaddingEnd() != paddingEnd) {
+
+ // lets ensure that the main column doesn't run into the image
+ ViewGroup.MarginLayoutParams params
+ = (MarginLayoutParams) mMainColumn.getLayoutParams();
+ int marginEnd = size + imageEndMargin + mNotificationContentMarginEnd;
+ if (marginEnd != params.getMarginEnd()) {
+ params.setMarginEnd(marginEnd);
+ mMainColumn.setLayoutParams(params);
+ reMeasure = true;
+ }
+ int headerMarginEnd = size + imageEndMargin;
+ params = (MarginLayoutParams) mHeader.getLayoutParams();
+ if (params.getMarginEnd() != headerMarginEnd) {
+ params.setMarginEnd(headerMarginEnd);
+ mHeader.setLayoutParams(params);
+ reMeasure = true;
+ }
+ if (mHeader.getPaddingEnd() != mNotificationContentImageMarginEnd) {
mHeader.setPaddingRelative(mHeader.getPaddingStart(),
mHeader.getPaddingTop(),
- paddingEnd,
+ mNotificationContentImageMarginEnd,
mHeader.getPaddingBottom());
reMeasure = true;
}
}
if (reMeasure) {
- measureChildWithMargins(mHeader, widthMeasureSpec, 0, heightMeasureSpec, 0);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
- private boolean resetHeaderIndention() {
- boolean remeasure = false;
+ private void resetHeaderIndention() {
if (mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
mHeader.setPaddingRelative(mHeader.getPaddingStart(),
mHeader.getPaddingTop(),
mNotificationContentMarginEnd,
mHeader.getPaddingBottom());
- remeasure = true;
}
ViewGroup.MarginLayoutParams headerParams =
(MarginLayoutParams) mHeader.getLayoutParams();
@@ -130,19 +124,14 @@
if (headerParams.getMarginEnd() != 0) {
headerParams.setMarginEnd(0);
mHeader.setLayoutParams(headerParams);
- remeasure = true;
}
- return remeasure;
}
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);
- mImageMinTopMargin = (int) (context.getResources().getDimensionPixelSize(
- com.android.internal.R.dimen.notification_content_margin_top)
- + getResources().getDisplayMetrics().density * 2);
+ mSmallImageSize = context.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.media_notification_expanded_image_small_size);
mNotificationContentMarginEnd = context.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.notification_content_margin_end);
mNotificationContentImageMarginEnd = context.getResources().getDimensionPixelSize(
diff --git a/core/res/res/layout/notification_template_material_big_media.xml b/core/res/res/layout/notification_template_material_big_media.xml
index 04ea12d..532f28e 100644
--- a/core/res/res/layout/notification_template_material_big_media.xml
+++ b/core/res/res/layout/notification_template_material_big_media.xml
@@ -23,6 +23,13 @@
android:background="#00000000"
android:tag="bigMediaNarrow"
>
+ <!-- The size will actually be determined at runtime -->
+ <ImageView android:id="@+id/right_icon"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_gravity="top|end"
+ android:scaleType="centerCrop"
+ />
<include layout="@layout/notification_template_header"
android:layout_width="match_parent"
android:layout_height="53dp"
@@ -60,14 +67,4 @@
<!-- media buttons will be added here -->
</LinearLayout>
</LinearLayout>
-
- <ImageView android:id="@+id/right_icon"
- android:layout_width="@dimen/media_notification_expanded_image_max_size"
- android:layout_height="@dimen/media_notification_expanded_image_max_size"
- android:minWidth="40dp"
- android:layout_marginEnd="16dp"
- android:layout_marginBottom="20dp"
- android:layout_gravity="bottom|end"
- android:scaleType="centerCrop"
- />
</com.android.internal.widget.MediaNotificationView>
diff --git a/core/res/res/layout/notification_template_material_media.xml b/core/res/res/layout/notification_template_material_media.xml
index 4c64207..4be53e0 100644
--- a/core/res/res/layout/notification_template_material_media.xml
+++ b/core/res/res/layout/notification_template_material_media.xml
@@ -23,6 +23,13 @@
android:background="#00000000"
android:tag="media"
>
+ <ImageView android:id="@+id/right_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:adjustViewBounds="true"
+ android:layout_gravity="top|end"
+ android:scaleType="centerCrop"
+ />
<include layout="@layout/notification_template_header"
android:layout_width="fill_parent"
android:layout_height="53dp" />
@@ -61,5 +68,4 @@
<!-- media buttons will be added here -->
</LinearLayout>
</LinearLayout>
- <include layout="@layout/notification_template_right_icon" />
</FrameLayout>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index c5316c6..ef6c21f 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -208,8 +208,8 @@
<!-- The minimum height of the content if there are at least two lines or a picture-->
<dimen name="notification_min_content_height">41dp</dimen>
- <!-- The maximum size of the image in the expanded media notification -->
- <dimen name="media_notification_expanded_image_max_size">94dp</dimen>
+ <!-- The small size of the image if the height drawing doesn't work anymore -->
+ <dimen name="media_notification_expanded_image_small_size">72dp</dimen>
<!-- The maximum size of the image in the expanded media notification -->
<dimen name="media_notification_expanded_image_margin_bottom">20dp</dimen>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 63a5cfd7..9a31a39 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2616,7 +2616,7 @@
<java-symbol type="string" name="new_sms_notification_title" />
<java-symbol type="string" name="new_sms_notification_content" />
- <java-symbol type="dimen" name="media_notification_expanded_image_max_size" />
+ <java-symbol type="dimen" name="media_notification_expanded_image_small_size" />
<java-symbol type="dimen" name="media_notification_expanded_image_margin_bottom" />
<java-symbol type="dimen" name="notification_content_image_margin_end" />