Left align the HeadsUp content in the StatusBar.

Fixes: 185679234
Test: post Heads Up notification from an app with a long name using each cutout configuration, in LTR and RTL, portrait and landscape.
Change-Id: Iccd924ca8103f66af6e732787ba634643acfae1c
This commit is contained in:
Jeff DeCew
2021-08-05 15:36:58 -04:00
parent 2458c8f8c6
commit 8d6022e778

View File

@@ -17,14 +17,10 @@
package com.android.systemui.statusbar;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.DisplayCutout;
import android.view.View;
import android.widget.TextView;
@@ -42,22 +38,14 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry.
public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
private static final String HEADS_UP_STATUS_BAR_VIEW_SUPER_PARCELABLE =
"heads_up_status_bar_view_super_parcelable";
private static final String FIRST_LAYOUT = "first_layout";
private static final String VISIBILITY = "visibility";
private static final String ALPHA = "alpha";
private int mAbsoluteStartPadding;
private int mEndMargin;
private final Rect mLayoutedIconRect = new Rect();
private final int[] mTmpPosition = new int[2];
private final Rect mIconDrawingRect = new Rect();
private View mIconPlaceholder;
private TextView mTextView;
private NotificationEntry mShowingEntry;
private Rect mLayoutedIconRect = new Rect();
private int[] mTmpPosition = new int[2];
private boolean mFirstLayout = true;
private int mMaxWidth;
private int mSysWinInset;
private int mCutOutInset;
private Rect mIconDrawingRect = new Rect();
private Point mDisplaySize;
private Runnable mOnDrawingRectChangedListener;
public HeadsUpStatusBarView(Context context) {
@@ -75,40 +63,6 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
public HeadsUpStatusBarView(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Resources res = getResources();
mAbsoluteStartPadding = res.getDimensionPixelSize(R.dimen.notification_side_paddings)
+ res.getDimensionPixelSize(
com.android.internal.R.dimen.notification_content_margin_start);
mEndMargin = res.getDimensionPixelSize(
com.android.internal.R.dimen.notification_content_margin_end);
setPaddingRelative(mAbsoluteStartPadding, 0, mEndMargin, 0);
updateMaxWidth();
}
private void updateMaxWidth() {
int maxWidth = getResources().getDimensionPixelSize(R.dimen.qs_panel_width);
if (maxWidth != mMaxWidth) {
// maxWidth doesn't work with fill_parent, let's manually make it at most as big as the
// notification panel
mMaxWidth = maxWidth;
requestLayout();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mMaxWidth > 0) {
int newSize = Math.min(MeasureSpec.getSize(widthMeasureSpec), mMaxWidth);
widthMeasureSpec = MeasureSpec.makeMeasureSpec(newSize,
MeasureSpec.getMode(widthMeasureSpec));
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateMaxWidth();
}
@Override
@@ -116,7 +70,6 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
Bundle bundle = new Bundle();
bundle.putParcelable(HEADS_UP_STATUS_BAR_VIEW_SUPER_PARCELABLE,
super.onSaveInstanceState());
bundle.putBoolean(FIRST_LAYOUT, mFirstLayout);
bundle.putInt(VISIBILITY, getVisibility());
bundle.putFloat(ALPHA, getAlpha());
@@ -125,7 +78,7 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state == null || !(state instanceof Bundle)) {
if (!(state instanceof Bundle)) {
super.onRestoreInstanceState(state);
return;
}
@@ -133,7 +86,6 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
Bundle bundle = (Bundle) state;
Parcelable superState = bundle.getParcelable(HEADS_UP_STATUS_BAR_VIEW_SUPER_PARCELABLE);
super.onRestoreInstanceState(superState);
mFirstLayout = bundle.getBoolean(FIRST_LAYOUT, true);
if (bundle.containsKey(VISIBILITY)) {
setVisibility(bundle.getInt(VISIBILITY));
}
@@ -191,20 +143,6 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
int bottom = top + mIconPlaceholder.getHeight();
mLayoutedIconRect.set(left, top, right, bottom);
updateDrawingRect();
int targetPadding = mAbsoluteStartPadding + mSysWinInset + mCutOutInset;
boolean isRtl = isLayoutRtl();
int start = isRtl ? (mDisplaySize.x - right) : left;
if (start != targetPadding) {
int newPadding = targetPadding - start + getPaddingStart();
setPaddingRelative(newPadding, 0, mEndMargin, 0);
}
if (mFirstLayout) {
// we need to do the padding calculation in the first frame, so the layout specified
// our visibility to be INVISIBLE in the beginning. let's correct that and set it
// to GONE.
setVisibility(GONE);
mFirstLayout = false;
}
}
/** In order to do UI alignment, this view will be notified by
@@ -226,29 +164,6 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
}
}
@Override
protected boolean fitSystemWindows(Rect insets) {
boolean isRtl = isLayoutRtl();
mSysWinInset = isRtl ? insets.right : insets.left;
DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout();
mCutOutInset = (displayCutout != null)
? (isRtl ? displayCutout.getSafeInsetRight() : displayCutout.getSafeInsetLeft())
: 0;
getDisplaySize();
// For Double Cut Out mode, the System window navigation bar is at the right
// side of the left cut out. In this condition, mSysWinInset include the left cut
// out width so we set mCutOutInset to be 0. For RTL, the condition is the same.
// The navigation bar is at the left side of the right cut out and include the
// right cut out width.
if (mSysWinInset != 0) {
mCutOutInset = 0;
}
return super.fitSystemWindows(insets);
}
public NotificationEntry getShowingEntry() {
return mShowingEntry;
}
@@ -264,17 +179,4 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
public void setOnDrawingRectChangedListener(Runnable onDrawingRectChangedListener) {
mOnDrawingRectChangedListener = onDrawingRectChangedListener;
}
private void getDisplaySize() {
if (mDisplaySize == null) {
mDisplaySize = new Point();
}
getDisplay().getRealSize(mDisplaySize);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
getDisplaySize();
}
}