diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/HeadsUpStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/HeadsUpStatusBarView.java index acfd998ff6e44..8e6cf36f8e74a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/HeadsUpStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/HeadsUpStatusBarView.java @@ -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)); } @@ -185,70 +137,22 @@ public class HeadsUpStatusBarView extends AlphaOptimizedLinearLayout { protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); mIconPlaceholder.getLocationOnScreen(mTmpPosition); - int left = (int) (mTmpPosition[0] - getTranslationX()); + int left = mTmpPosition[0]; int top = mTmpPosition[1]; int right = left + mIconPlaceholder.getWidth(); 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 - * {@link com.android.systemui.statusbar.notification.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) { - setTranslationX(translationX); - updateDrawingRect(); } private void updateDrawingRect() { float oldLeft = mIconDrawingRect.left; mIconDrawingRect.set(mLayoutedIconRect); - mIconDrawingRect.offset((int) getTranslationX(), 0); if (oldLeft != mIconDrawingRect.left && mOnDrawingRectChangedListener != null) { mOnDrawingRectChangedListener.run(); } } - @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 +168,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(); - } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java index f4830fbb0028b..878fbbf39627c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceController.java @@ -18,9 +18,7 @@ package com.android.systemui.statusbar.phone; import android.graphics.Point; import android.graphics.Rect; -import android.view.DisplayCutout; import android.view.View; -import android.view.WindowInsets; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.widget.ViewClippingUtil; @@ -61,7 +59,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, private final NotificationPanelViewController mNotificationPanelViewController; private final Consumer mSetTrackingHeadsUp = this::setTrackingHeadsUp; - private final Runnable mUpdatePanelTranslation = this::updatePanelTranslation; private final BiConsumer mSetExpandedHeight = this::setAppearFraction; private final KeyguardBypassController mBypassController; private final StatusBarStateController mStatusBarStateController; @@ -75,9 +72,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, float mAppearFraction; private ExpandableNotificationRow mTrackedChild; private boolean mShown; - private final View.OnLayoutChangeListener mStackScrollLayoutChangeListener = - (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) - -> updatePanelTranslation(); private final ViewClippingUtil.ClippingParameters mParentClippingParams = new ViewClippingUtil.ClippingParameters() { @Override @@ -134,10 +128,8 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, mStackScrollerController = stackScrollerController; mNotificationPanelViewController = notificationPanelViewController; notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp); - notificationPanelViewController.setVerticalTranslationListener(mUpdatePanelTranslation); notificationPanelViewController.setHeadsUpAppearanceController(this); mStackScrollerController.addOnExpandedHeightChangedListener(mSetExpandedHeight); - mStackScrollerController.addOnLayoutChangeListener(mStackScrollLayoutChangeListener); mStackScrollerController.setHeadsUpAppearanceController(this); mClockView = clockView; mOperatorNameView = operatorNameView; @@ -174,7 +166,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, mNotificationPanelViewController.setVerticalTranslationListener(null); mNotificationPanelViewController.setHeadsUpAppearanceController(null); mStackScrollerController.removeOnExpandedHeightChangedListener(mSetExpandedHeight); - mStackScrollerController.removeOnLayoutChangeListener(mStackScrollLayoutChangeListener); mDarkIconDispatcher.removeDarkReceiver(this); } @@ -189,63 +180,6 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, updateHeader(entry); } - /** To count the distance from the window right boundary to scroller right boundary. The - * distance formula is the following: - * Y = screenSize - (SystemWindow's width + Scroller.getRight()) - * There are four modes MUST to be considered in Cut Out of RTL. - * No Cut Out: - * Scroller + NB - * NB + Scroller - * => SystemWindow = NavigationBar's width - * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) - * Corner Cut Out or Tall Cut Out: - * cut out + Scroller + NB - * NB + Scroller + cut out - * => SystemWindow = NavigationBar's width - * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) - * Double Cut Out: - * cut out left + Scroller + (NB + cut out right) - * SystemWindow = NavigationBar's width + cut out right width - * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) - * (cut out left + NB) + Scroller + cut out right - * SystemWindow = NavigationBar's width + cut out left width - * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) - * @return the translation X value for RTL. In theory, it should be negative. i.e. -Y - */ - private int getRtlTranslation() { - if (mPoint == null) { - mPoint = new Point(); - } - - int realDisplaySize = 0; - if (mStackScrollerController.getDisplay() != null) { - mStackScrollerController.getDisplay().getRealSize(mPoint); - realDisplaySize = mPoint.x; - } - - WindowInsets windowInset = mStackScrollerController.getRootWindowInsets(); - DisplayCutout cutout = (windowInset != null) ? windowInset.getDisplayCutout() : null; - int sysWinLeft = (windowInset != null) ? windowInset.getStableInsetLeft() : 0; - int sysWinRight = (windowInset != null) ? windowInset.getStableInsetRight() : 0; - int cutoutLeft = (cutout != null) ? cutout.getSafeInsetLeft() : 0; - int cutoutRight = (cutout != null) ? cutout.getSafeInsetRight() : 0; - int leftInset = Math.max(sysWinLeft, cutoutLeft); - int rightInset = Math.max(sysWinRight, cutoutRight); - - return leftInset + mStackScrollerController.getRight() + rightInset - realDisplaySize; - } - - public void updatePanelTranslation() { - float newTranslation; - if (mStackScrollerController.isLayoutRtl()) { - newTranslation = getRtlTranslation(); - } else { - newTranslation = mStackScrollerController.getLeft(); - } - newTranslation += mStackScrollerController.getTranslationX(); - mHeadsUpStatusBarView.setPanelTranslation(newTranslation); - } - private void updateTopEntry() { NotificationEntry newEntry = null; if (shouldBeVisible()) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java index 6e0cbd9ecfa39..bca1227b7d35b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java @@ -202,6 +202,5 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase { verify(mPanelView).removeTrackingHeadsUpListener(any()); verify(mPanelView).setHeadsUpAppearanceController(isNull()); verify(mStackScrollerController).removeOnExpandedHeightChangedListener(any()); - verify(mStackScrollerController).removeOnLayoutChangeListener(any()); } }