Improved the headsup notification for messages
Previously the heads up notifications and also the collapsed versions were not displaying in the new style. They are now displayed in the new style of heads up notifications. Test: add messaging notification in heads up Bug: 63708826 Change-Id: I041584cd6ee740fd8c59f332f727ed83c89e777f
This commit is contained in:
@@ -6084,25 +6084,12 @@ public class Notification implements Parcelable
|
||||
*/
|
||||
@Override
|
||||
public RemoteViews makeContentView(boolean increasedHeight) {
|
||||
if (!increasedHeight) {
|
||||
Message m = findLatestIncomingMessage();
|
||||
CharSequence title = mConversationTitle != null
|
||||
? mConversationTitle
|
||||
: (m == null) ? null : m.mSender;
|
||||
CharSequence text = (m == null)
|
||||
? null
|
||||
: mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText;
|
||||
|
||||
return mBuilder.applyStandardTemplate(mBuilder.getBaseLayoutResource(),
|
||||
mBuilder.mParams.reset().hasProgress(false).title(title).text(text));
|
||||
} else {
|
||||
mBuilder.mOriginalActions = mBuilder.mActions;
|
||||
mBuilder.mActions = new ArrayList<>();
|
||||
RemoteViews remoteViews = makeBigContentView();
|
||||
mBuilder.mActions = mBuilder.mOriginalActions;
|
||||
mBuilder.mOriginalActions = null;
|
||||
return remoteViews;
|
||||
}
|
||||
mBuilder.mOriginalActions = mBuilder.mActions;
|
||||
mBuilder.mActions = new ArrayList<>();
|
||||
RemoteViews remoteViews = makeBigContentView();
|
||||
mBuilder.mActions = mBuilder.mOriginalActions;
|
||||
mBuilder.mOriginalActions = null;
|
||||
return remoteViews;
|
||||
}
|
||||
|
||||
private Message findLatestIncomingMessage() {
|
||||
@@ -6148,10 +6135,6 @@ public class Notification implements Parcelable
|
||||
mBuilder.getMessagingLayoutResource(),
|
||||
mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null)
|
||||
.hideLargeIcon(isOneToOne).alwaysShowReply(true));
|
||||
contentView.setViewLayoutMarginBottomDimen(R.id.line1,
|
||||
hasTitle ? R.dimen.notification_messaging_spacing : 0);
|
||||
contentView.setInt(R.id.notification_messaging, "setNumIndentLines",
|
||||
!mBuilder.mN.hasLargeIcon() ? 0 : (hasTitle ? 1 : 2));
|
||||
addExtras(mBuilder.mN.extras);
|
||||
contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor",
|
||||
mBuilder.resolveContrastColor());
|
||||
@@ -6185,49 +6168,14 @@ public class Notification implements Parcelable
|
||||
return title;
|
||||
}
|
||||
|
||||
private CharSequence makeMessageLine(Message m, Builder builder) {
|
||||
BidiFormatter bidi = BidiFormatter.getInstance();
|
||||
SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
boolean colorize = builder.isColorized();
|
||||
TextAppearanceSpan colorSpan;
|
||||
CharSequence messageName;
|
||||
if (TextUtils.isEmpty(m.mSender)) {
|
||||
CharSequence replyName = mUserDisplayName == null ? "" : mUserDisplayName;
|
||||
sb.append(bidi.unicodeWrap(replyName),
|
||||
makeFontColorSpan(colorize
|
||||
? builder.getPrimaryTextColor()
|
||||
: mBuilder.resolveContrastColor()),
|
||||
0 /* flags */);
|
||||
} else {
|
||||
sb.append(bidi.unicodeWrap(m.mSender),
|
||||
makeFontColorSpan(colorize
|
||||
? builder.getPrimaryTextColor()
|
||||
: Color.BLACK),
|
||||
0 /* flags */);
|
||||
}
|
||||
CharSequence text = m.mText == null ? "" : m.mText;
|
||||
sb.append(" ").append(bidi.unicodeWrap(text));
|
||||
return sb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override
|
||||
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
|
||||
if (increasedHeight) {
|
||||
return makeBigContentView();
|
||||
}
|
||||
Message m = findLatestIncomingMessage();
|
||||
CharSequence title = mConversationTitle != null
|
||||
? mConversationTitle
|
||||
: (m == null) ? null : m.mSender;
|
||||
CharSequence text = (m == null)
|
||||
? null
|
||||
: mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText;
|
||||
|
||||
return mBuilder.applyStandardTemplateWithActions(mBuilder.getBigBaseLayoutResource(),
|
||||
mBuilder.mParams.reset().hasProgress(false).title(title).text(text));
|
||||
RemoteViews remoteViews = makeBigContentView();
|
||||
remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
|
||||
return remoteViews;
|
||||
}
|
||||
|
||||
private static TextAppearanceSpan makeFontColorSpan(int color) {
|
||||
|
||||
@@ -186,7 +186,13 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
|
||||
result += ((MessagingLinearLayout.MessagingChild) child).getConsumedLines();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
// A group is usually taking up quite some space with the padding and the name, let's add 1
|
||||
return result + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxDisplayedLines(int lines) {
|
||||
mMessageContainer.setMaxDisplayedLines(lines);
|
||||
}
|
||||
|
||||
public Icon getAvatarSymbolIfMatching(CharSequence avatarName, String avatarSymbol,
|
||||
|
||||
@@ -42,12 +42,7 @@ public class MessagingLinearLayout extends ViewGroup {
|
||||
*/
|
||||
private int mSpacing;
|
||||
|
||||
/**
|
||||
* The maximum height allowed.
|
||||
*/
|
||||
private int mMaxHeight;
|
||||
|
||||
private int mIndentLines;
|
||||
private int mMaxDisplayedLines = Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Id of the child that's also visible in the contracted layout.
|
||||
@@ -111,6 +106,7 @@ public class MessagingLinearLayout extends ViewGroup {
|
||||
|
||||
totalHeight = mPaddingTop + mPaddingBottom;
|
||||
boolean first = true;
|
||||
int linesRemaining = mMaxDisplayedLines;
|
||||
|
||||
// Starting from the bottom: we measure every view as if it were the only one. If it still
|
||||
|
||||
@@ -121,7 +117,11 @@ public class MessagingLinearLayout extends ViewGroup {
|
||||
}
|
||||
final View child = getChildAt(i);
|
||||
LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams();
|
||||
|
||||
MessagingChild messagingChild = null;
|
||||
if (child instanceof MessagingChild) {
|
||||
messagingChild = (MessagingChild) child;
|
||||
messagingChild.setMaxDisplayedLines(linesRemaining);
|
||||
}
|
||||
int spacing = first ? 0 : mSpacing;
|
||||
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, totalHeight
|
||||
- mPaddingTop - mPaddingBottom + spacing);
|
||||
@@ -131,8 +131,8 @@ public class MessagingLinearLayout extends ViewGroup {
|
||||
lp.bottomMargin + spacing);
|
||||
first = false;
|
||||
int measureType = MessagingChild.MEASURED_NORMAL;
|
||||
if (child instanceof MessagingChild) {
|
||||
measureType = ((MessagingChild) child).getMeasuredType();
|
||||
if (messagingChild != null) {
|
||||
measureType = messagingChild.getMeasuredType();
|
||||
linesRemaining -= messagingChild.getConsumedLines();
|
||||
}
|
||||
boolean isShortened = measureType == MessagingChild.MEASURED_SHORTENED;
|
||||
@@ -143,7 +143,7 @@ public class MessagingLinearLayout extends ViewGroup {
|
||||
child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin
|
||||
+ mPaddingLeft + mPaddingRight);
|
||||
lp.hide = false;
|
||||
if (isShortened) {
|
||||
if (isShortened || linesRemaining <= 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -239,21 +239,21 @@ public class MessagingLinearLayout extends ViewGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets how many lines should be indented to avoid a floating image.
|
||||
* Sets how many lines should be displayed at most
|
||||
*/
|
||||
@RemotableViewMethod
|
||||
public boolean setNumIndentLines(int numberLines) {
|
||||
boolean changed = numberLines != mIndentLines;
|
||||
mIndentLines = numberLines;
|
||||
return changed;
|
||||
public void setMaxDisplayedLines(int numberLines) {
|
||||
mMaxDisplayedLines = numberLines;
|
||||
}
|
||||
|
||||
public interface MessagingChild {
|
||||
int MEASURED_NORMAL = 0;
|
||||
int MEASURED_SHORTENED = 1;
|
||||
int MEASURED_TOO_SMALL = 2;
|
||||
|
||||
int getMeasuredType();
|
||||
int getConsumedLines();
|
||||
void setMaxDisplayedLines(int lines);
|
||||
}
|
||||
|
||||
public static class LayoutParams extends MarginLayoutParams {
|
||||
|
||||
@@ -144,6 +144,11 @@ public class MessagingMessage extends ImageFloatingTextView implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxDisplayedLines(int lines) {
|
||||
setMaxLines(lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConsumedLines() {
|
||||
return getLineCount();
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
android:id="@+id/notification_messaging"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:spacing="@dimen/notification_messaging_spacing" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -95,6 +95,10 @@
|
||||
<!-- Height of a heads up notification in the status bar -->
|
||||
<dimen name="notification_max_heads_up_height_increased">188dp</dimen>
|
||||
|
||||
<!-- Height of a messaging notifications with actions at least. Not that this is an upper bound
|
||||
and the notification won't use this much, but is measured with wrap_content -->
|
||||
<dimen name="notification_messaging_actions_min_height">196dp</dimen>
|
||||
|
||||
<!-- a threshold in dp per second that is considered fast scrolling -->
|
||||
<dimen name="scroll_fast_threshold">1500dp</dimen>
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ import com.android.systemui.statusbar.notification.AboveShelfObserver;
|
||||
import com.android.systemui.statusbar.notification.HybridNotificationView;
|
||||
import com.android.systemui.statusbar.notification.NotificationInflater;
|
||||
import com.android.systemui.statusbar.notification.NotificationUtils;
|
||||
import com.android.systemui.statusbar.notification.NotificationViewWrapper;
|
||||
import com.android.systemui.statusbar.notification.VisualStabilityManager;
|
||||
import com.android.systemui.statusbar.phone.NotificationGroupManager;
|
||||
import com.android.systemui.statusbar.phone.StatusBar;
|
||||
@@ -453,6 +454,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
||||
} else {
|
||||
headsUpheight = mMaxHeadsUpHeight;
|
||||
}
|
||||
NotificationViewWrapper headsUpWrapper = layout.getVisibleWrapper(
|
||||
NotificationContentView.VISIBLE_TYPE_HEADSUP);
|
||||
if (headsUpWrapper != null) {
|
||||
headsUpheight = Math.max(headsUpheight, headsUpWrapper.getMinLayoutHeight());
|
||||
}
|
||||
layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight,
|
||||
mNotificationAmbientHeight);
|
||||
}
|
||||
@@ -1256,16 +1262,21 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
||||
}
|
||||
|
||||
private void initDimens() {
|
||||
mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
|
||||
mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
|
||||
mNotificationMinHeightLarge = getFontScaledHeight(
|
||||
mNotificationMinHeightLegacy = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_min_height_legacy);
|
||||
mNotificationMinHeight = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_min_height);
|
||||
mNotificationMinHeightLarge = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_min_height_increased);
|
||||
mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
|
||||
mNotificationAmbientHeight = getFontScaledHeight(R.dimen.notification_ambient_height);
|
||||
mMaxHeadsUpHeightLegacy = getFontScaledHeight(
|
||||
mNotificationMaxHeight = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_max_height);
|
||||
mNotificationAmbientHeight = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_ambient_height);
|
||||
mMaxHeadsUpHeightLegacy = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_max_heads_up_height_legacy);
|
||||
mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
|
||||
mMaxHeadsUpHeightIncreased = getFontScaledHeight(
|
||||
mMaxHeadsUpHeight = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_max_heads_up_height);
|
||||
mMaxHeadsUpHeightIncreased = NotificationUtils.getFontScaledHeight(mContext,
|
||||
R.dimen.notification_max_heads_up_height_increased);
|
||||
|
||||
Resources res = getResources();
|
||||
@@ -1279,17 +1290,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
||||
res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dimenId the dimen to look up
|
||||
* @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
|
||||
*/
|
||||
private int getFontScaledHeight(int dimenId) {
|
||||
int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
|
||||
float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
|
||||
getResources().getDisplayMetrics().density);
|
||||
return (int) (dimensionPixelSize * factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this view so it can be re-used for an updated notification.
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification;
|
||||
|
||||
import com.android.internal.widget.MessagingLayout;
|
||||
import com.android.internal.widget.MessagingLinearLayout;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.ExpandableNotificationRow;
|
||||
import com.android.systemui.statusbar.TransformableView;
|
||||
|
||||
@@ -33,6 +34,7 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class NotificationMessagingTemplateViewWrapper extends NotificationTemplateViewWrapper {
|
||||
|
||||
private final int mMinHeightWithActions;
|
||||
private MessagingLayout mMessagingLayout;
|
||||
private View mContractedMessage;
|
||||
|
||||
@@ -40,6 +42,8 @@ public class NotificationMessagingTemplateViewWrapper extends NotificationTempla
|
||||
ExpandableNotificationRow row) {
|
||||
super(ctx, view, row);
|
||||
mMessagingLayout = (MessagingLayout) view;
|
||||
mMinHeightWithActions = NotificationUtils.getFontScaledHeight(ctx,
|
||||
R.dimen.notification_messaging_actions_min_height);
|
||||
}
|
||||
|
||||
private void resolveViews() {
|
||||
@@ -69,4 +73,12 @@ public class NotificationMessagingTemplateViewWrapper extends NotificationTempla
|
||||
public void setRemoteInputVisible(boolean visible) {
|
||||
mMessagingLayout.showHistoricMessages(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinLayoutHeight() {
|
||||
if (mActionsContainer != null && mActionsContainer.getVisibility() != View.GONE) {
|
||||
return mMinHeightWithActions;
|
||||
}
|
||||
return super.getMinLayoutHeight();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
|
||||
private ProgressBar mProgressBar;
|
||||
private TextView mTitle;
|
||||
private TextView mText;
|
||||
private View mActionsContainer;
|
||||
protected View mActionsContainer;
|
||||
private View mReplyAction;
|
||||
private Rect mTmpRect = new Rect();
|
||||
|
||||
|
||||
@@ -66,4 +66,14 @@ public class NotificationUtils {
|
||||
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dimenId the dimen to look up
|
||||
* @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
|
||||
*/
|
||||
public static int getFontScaledHeight(Context context, int dimenId) {
|
||||
int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId);
|
||||
float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity /
|
||||
context.getResources().getDisplayMetrics().density);
|
||||
return (int) (dimensionPixelSize * factor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,4 +190,8 @@ public abstract class NotificationViewWrapper implements TransformableView {
|
||||
public boolean disallowSingleClick(float x, float y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getMinLayoutHeight() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user