Merge "Media notifications now properly respect font size changes" into nyc-dev
am: 24ffe236b1
* commit '24ffe236b1ca89b6088a5488c591ea836ee59e1c':
Media notifications now properly respect font size changes
This commit is contained in:
@@ -21,6 +21,7 @@ import android.content.Context;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
@@ -31,16 +32,16 @@ import android.widget.RemoteViews;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@RemoteViews.RemoteView
|
@RemoteViews.RemoteView
|
||||||
public class MediaNotificationView extends RelativeLayout {
|
public class MediaNotificationView extends FrameLayout {
|
||||||
|
|
||||||
private final int mMaxImageSize;
|
private final int mMaxImageSize;
|
||||||
private final int mImageMarginBottom;
|
|
||||||
private final int mImageMinTopMargin;
|
private final int mImageMinTopMargin;
|
||||||
private final int mNotificationContentMarginEnd;
|
private final int mNotificationContentMarginEnd;
|
||||||
private final int mNotificationContentImageMarginEnd;
|
private final int mNotificationContentImageMarginEnd;
|
||||||
private ImageView mRightIcon;
|
private ImageView mRightIcon;
|
||||||
private View mActions;
|
private View mActions;
|
||||||
private View mHeader;
|
private View mHeader;
|
||||||
|
private View mMainColumn;
|
||||||
|
|
||||||
public MediaNotificationView(Context context) {
|
public MediaNotificationView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -61,39 +62,49 @@ public class MediaNotificationView extends RelativeLayout {
|
|||||||
if (hasIcon && mode != MeasureSpec.UNSPECIFIED) {
|
if (hasIcon && mode != MeasureSpec.UNSPECIFIED) {
|
||||||
measureChild(mActions, widthMeasureSpec, heightMeasureSpec);
|
measureChild(mActions, widthMeasureSpec, heightMeasureSpec);
|
||||||
int size = MeasureSpec.getSize(widthMeasureSpec);
|
int size = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
||||||
size = size - mActions.getMeasuredWidth();
|
size = size - mActions.getMeasuredWidth();
|
||||||
ViewGroup.MarginLayoutParams layoutParams =
|
ViewGroup.MarginLayoutParams layoutParams =
|
||||||
(MarginLayoutParams) mRightIcon.getLayoutParams();
|
(MarginLayoutParams) mRightIcon.getLayoutParams();
|
||||||
size -= layoutParams.getMarginEnd();
|
int imageEndMargin = layoutParams.getMarginEnd();
|
||||||
|
size -= imageEndMargin;
|
||||||
size = Math.min(size, mMaxImageSize);
|
size = Math.min(size, mMaxImageSize);
|
||||||
size = Math.max(size, mRightIcon.getMinimumWidth());
|
size = Math.max(size, mRightIcon.getMinimumWidth());
|
||||||
layoutParams.width = size;
|
layoutParams.width = size;
|
||||||
layoutParams.height = 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);
|
mRightIcon.setLayoutParams(layoutParams);
|
||||||
} else if (!hasIcon && mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
|
|
||||||
resetHeaderIndention();
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
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!
|
||||||
|
if (!hasIcon || topMargin >= mImageMinTopMargin) {
|
||||||
|
resetHeaderIndention();
|
||||||
|
} else {
|
||||||
|
int paddingEnd = mNotificationContentImageMarginEnd;
|
||||||
|
ViewGroup.MarginLayoutParams headerParams =
|
||||||
|
(MarginLayoutParams) mHeader.getLayoutParams();
|
||||||
|
headerParams.setMarginEnd(mRightIcon.getMeasuredWidth() + iconParams.getMarginEnd());
|
||||||
|
if (mHeader.getPaddingEnd() != paddingEnd) {
|
||||||
|
mHeader.setPadding(
|
||||||
|
isLayoutRtl() ? paddingEnd : mHeader.getPaddingLeft(),
|
||||||
|
mHeader.getPaddingTop(),
|
||||||
|
isLayoutRtl() ? mHeader.getPaddingLeft() : paddingEnd,
|
||||||
|
mHeader.getPaddingBottom());
|
||||||
|
mHeader.setLayoutParams(headerParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetHeaderIndention() {
|
private void resetHeaderIndention() {
|
||||||
@@ -115,8 +126,6 @@ public class MediaNotificationView extends RelativeLayout {
|
|||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
mMaxImageSize = context.getResources().getDimensionPixelSize(
|
mMaxImageSize = context.getResources().getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.media_notification_expanded_image_max_size);
|
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(
|
mImageMinTopMargin = (int) (context.getResources().getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.notification_content_margin_top)
|
com.android.internal.R.dimen.notification_content_margin_top)
|
||||||
+ getResources().getDisplayMetrics().density * 2);
|
+ getResources().getDisplayMetrics().density * 2);
|
||||||
@@ -132,5 +141,6 @@ public class MediaNotificationView extends RelativeLayout {
|
|||||||
mRightIcon = (ImageView) findViewById(com.android.internal.R.id.right_icon);
|
mRightIcon = (ImageView) findViewById(com.android.internal.R.id.right_icon);
|
||||||
mActions = findViewById(com.android.internal.R.id.media_actions);
|
mActions = findViewById(com.android.internal.R.id.media_actions);
|
||||||
mHeader = findViewById(com.android.internal.R.id.notification_header);
|
mHeader = findViewById(com.android.internal.R.id.notification_header);
|
||||||
|
mMainColumn = findViewById(com.android.internal.R.id.notification_main_column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,41 +19,45 @@
|
|||||||
<com.android.internal.widget.MediaNotificationView xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.android.internal.widget.MediaNotificationView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/status_bar_latest_event_content"
|
android:id="@+id/status_bar_latest_event_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="126dp"
|
android:layout_height="wrap_content"
|
||||||
android:background="#00000000"
|
android:background="#00000000"
|
||||||
android:tag="bigMediaNarrow"
|
android:tag="bigMediaNarrow"
|
||||||
>
|
>
|
||||||
<include layout="@layout/notification_template_header"
|
<include layout="@layout/notification_template_header"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_alignParentStart="true"/>
|
android:layout_gravity="start"/>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/notification_main_column"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/notification_content_margin_top"
|
|
||||||
android:layout_marginStart="@dimen/notification_content_margin_start"
|
|
||||||
android:layout_marginBottom="@dimen/notification_content_margin_bottom"
|
|
||||||
android:layout_marginEnd="@dimen/notification_content_margin_end"
|
|
||||||
android:layout_toStartOf="@id/right_icon"
|
|
||||||
android:minHeight="@dimen/notification_min_content_height"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
>
|
>
|
||||||
<include layout="@layout/notification_template_part_line1" />
|
<LinearLayout
|
||||||
<include layout="@layout/notification_template_text" />
|
android:id="@+id/notification_main_column"
|
||||||
</LinearLayout>
|
android:layout_width="match_parent"
|
||||||
<LinearLayout
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/media_actions"
|
android:layout_marginTop="@dimen/notification_content_margin_top"
|
||||||
android:layout_width="wrap_content"
|
android:layout_marginStart="@dimen/notification_content_margin_start"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginBottom="@dimen/notification_content_margin_bottom"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_marginEnd="@dimen/notification_content_margin_end"
|
||||||
android:layout_alignParentStart="true"
|
android:minHeight="@dimen/notification_min_content_height"
|
||||||
android:paddingStart="8dp"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="8dp"
|
>
|
||||||
android:orientation="horizontal"
|
<include layout="@layout/notification_template_part_line1" />
|
||||||
android:layoutDirection="ltr"
|
<include layout="@layout/notification_template_text" />
|
||||||
>
|
</LinearLayout>
|
||||||
<!-- media buttons will be added here -->
|
<LinearLayout
|
||||||
|
android:id="@+id/media_actions"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="-15dp"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layoutDirection="ltr"
|
||||||
|
>
|
||||||
|
<!-- media buttons will be added here -->
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView android:id="@+id/right_icon"
|
<ImageView android:id="@+id/right_icon"
|
||||||
@@ -61,9 +65,8 @@
|
|||||||
android:layout_height="@dimen/media_notification_expanded_image_max_size"
|
android:layout_height="@dimen/media_notification_expanded_image_max_size"
|
||||||
android:minWidth="40dp"
|
android:minWidth="40dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_gravity="bottom|end"
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
/>
|
/>
|
||||||
</com.android.internal.widget.MediaNotificationView>
|
</com.android.internal.widget.MediaNotificationView>
|
||||||
|
|||||||
Reference in New Issue
Block a user