Fix text is cut off in corner cut out condition
There is a todo that it needs to handle the corner cut out. In the condition of RTL and Corner Cut out, HeadsUpStatusBarView's padding is wrong because displayCutout.getSafeInsetRight() is 0 but corner cut out actually impact HeadsUpStatusBar's layout. Corner cut out make icon's start more big but mCutOutInset is 0 so the newPadding is a negative number. The handle method is to detect the part of overlaying with corner cut out. i.e. center cut out is exclude. To count the cut out start as cutOutStart and compare cutOutStart with icon's start. The cut out is not corner cut out if cutOutStart < icon's start. icon's minus the width of overlay part to prevent from negative padding. move the get screen size from onLayout to fitSystemWindows and onAttachToWindow because there is a chance to new object in onLayout. To new object in onLayout is not good practice. And, there is an chance to invoke ANR because Display.getRealSize() may do IPC. Fixes: 80271465 Test: atest SystemUITests Change-Id: I36fa5c880f5e624747133e46950c1c1695a5fa58
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@@ -31,6 +32,8 @@ import com.android.keyguard.AlphaOptimizedLinearLayout;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The view in the statusBar that contains part of the heads-up information
|
||||
*/
|
||||
@@ -48,8 +51,9 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
|
||||
private View mRootView;
|
||||
private int mSysWinInset;
|
||||
private int mCutOutInset;
|
||||
private List<Rect> mCutOutBounds;
|
||||
private Rect mIconDrawingRect = new Rect();
|
||||
private Point mPoint;
|
||||
private Point mDisplaySize;
|
||||
private Runnable mOnDrawingRectChangedListener;
|
||||
|
||||
public HeadsUpStatusBarView(Context context) {
|
||||
@@ -141,16 +145,19 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
|
||||
mLayoutedIconRect.set(left, top, right, bottom);
|
||||
updateDrawingRect();
|
||||
int targetPadding = mAbsoluteStartPadding + mSysWinInset + mCutOutInset;
|
||||
if (left != targetPadding) {
|
||||
int start;
|
||||
if (isLayoutRtl()) {
|
||||
if (mPoint == null) {
|
||||
mPoint = new Point();
|
||||
boolean isRtl = isLayoutRtl();
|
||||
int start = isRtl ? (mDisplaySize.x - right) : left;
|
||||
|
||||
if (start != targetPadding) {
|
||||
if (mCutOutBounds != null) {
|
||||
for (Rect cutOutRect : mCutOutBounds) {
|
||||
int cutOutStart = (isRtl)
|
||||
? (mDisplaySize.x - cutOutRect.right) : cutOutRect.left;
|
||||
if (start > cutOutStart) {
|
||||
start -= cutOutRect.width();
|
||||
break;
|
||||
}
|
||||
}
|
||||
getDisplay().getRealSize(mPoint);
|
||||
start = (mPoint.x - right);
|
||||
} else {
|
||||
start = left;
|
||||
}
|
||||
|
||||
int newPadding = targetPadding - start + getPaddingStart();
|
||||
@@ -165,6 +172,11 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/** In order to do UI alignment, this view will be notified by
|
||||
* {@link com.android.systemui.statusbar.stack.NotificationStackScrollLayout}.
|
||||
* After scroller laid out, the scroller will tell this view about scroller's getX()
|
||||
* @param translationX how to translate the horizontal position
|
||||
*/
|
||||
public void setPanelTranslation(float translationX) {
|
||||
if (isLayoutRtl()) {
|
||||
setTranslationX(translationX + mCutOutInset);
|
||||
@@ -191,6 +203,15 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout {
|
||||
mCutOutInset = (displayCutout != null)
|
||||
? (isRtl ? displayCutout.getSafeInsetRight() : displayCutout.getSafeInsetLeft())
|
||||
: 0;
|
||||
|
||||
getDisplaySize();
|
||||
|
||||
mCutOutBounds = null;
|
||||
if (displayCutout != null && displayCutout.getSafeInsetRight() == 0
|
||||
&& displayCutout.getSafeInsetLeft() == 0) {
|
||||
mCutOutBounds = displayCutout.getBoundingRects();
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -222,4 +243,17 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
|
||||
* @return the translation X value for RTL. In theory, it should be negative. i.e. -Y
|
||||
*/
|
||||
private int getRtlTranslation() {
|
||||
// TODO: Corner Cut Out still need to handle.
|
||||
if (mPoint == null) {
|
||||
mPoint = new Point();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user