From 51d94917c7dc53845701702bfd63f102a3a2dbc8 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Wed, 2 Mar 2016 15:34:28 -0800 Subject: [PATCH] Fixed a bug where the notification content could become empty This was caused by legacy code which set the actual height, which in turn set the contentview to collapsed. If that happend during an animation, the view could become blank. Bug: 27448145 Change-Id: I0b3a2a2aee3052810176c2ff9a23825d83145d69 --- .../statusbar/ExpandableNotificationRow.java | 26 ++------------- .../systemui/statusbar/ExpandableView.java | 21 ------------ .../statusbar/NotificationContentView.java | 28 ++++++++++------ .../statusbar/ViewTransformationHelper.java | 32 +++++++++---------- 4 files changed, 37 insertions(+), 70 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 84b84e2814c6d..12a83fdb6d36b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -105,7 +105,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { private boolean mClearable; private ExpansionLogger mLogger; private String mLoggingKey; - private boolean mWasReset; private NotificationSettingsIconRow mSettingsIconRow; private NotificationGuts mGuts; private NotificationData.Entry mEntry; @@ -615,20 +614,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { mShowingPublicInitialized = false; mIsSystemExpanded = false; mOnKeyguard = false; - mPublicLayout.reset(mIsHeadsUp); - mPrivateLayout.reset(mIsHeadsUp); + mPublicLayout.reset(); + mPrivateLayout.reset(); resetHeight(); resetTranslation(); logExpansionEvent(false, wasExpanded); } public void resetHeight() { - if (mIsHeadsUp) { - resetActualHeight(); - } mMaxExpandHeight = 0; mHeadsUpHeight = 0; - mWasReset = true; onHeightReset(); requestLayout(); } @@ -964,18 +959,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { return mStatusBarNotification != null && mStatusBarNotification.isClearable(); } - /** - * Apply an expansion state to the layout. - */ - public void applyExpansionToLayout() { - boolean expand = isExpanded(); - if (expand && mExpandable) { - setActualHeight(mMaxExpandHeight); - } else { - setActualHeight(getMinHeight()); - } - } - @Override public int getIntrinsicHeight() { if (isUserLocked()) { @@ -1057,12 +1040,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset; updateMaxHeights(); - if (updateExpandHeight) { - applyExpansionToLayout(); - } - mWasReset = false; } private void updateMaxHeights() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java index b2c632b07c99f..c0e434046139c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java @@ -36,7 +36,6 @@ public abstract class ExpandableView extends FrameLayout { protected OnHeightChangedListener mOnHeightChangedListener; private int mActualHeight; protected int mClipTopAmount; - private boolean mActualHeightInitialized; private boolean mDark; private ArrayList mMatchParentViews = new ArrayList(); private int mClipTopOptimization; @@ -99,28 +98,9 @@ public abstract class ExpandableView extends FrameLayout { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - if (!mActualHeightInitialized && mActualHeight == 0) { - int initialHeight = getInitialHeight(); - if (initialHeight != 0) { - setActualHeight(initialHeight); - } - } updateClipping(); } - /** - * Resets the height of the view on the next layout pass - */ - protected void resetActualHeight() { - mActualHeight = 0; - mActualHeightInitialized = false; - requestLayout(); - } - - protected int getInitialHeight() { - return getHeight(); - } - @Override public boolean pointInView(float localX, float localY, float slop) { float top = mClipTopAmount; @@ -137,7 +117,6 @@ public abstract class ExpandableView extends FrameLayout { * @param notifyListeners Whether the listener should be informed about the change. */ public void setActualHeight(int actualHeight, boolean notifyListeners) { - mActualHeightInitialized = true; mActualHeight = actualHeight; updateClipping(); if (notifyListeners) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index 61105f8ea12a2..b94c15b1d191f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -120,7 +120,7 @@ public class NotificationContentView extends FrameLayout { R.dimen.min_notification_layout_height); mNotificationContentMarginEnd = getResources().getDimensionPixelSize( com.android.internal.R.dimen.notification_content_margin_end); - reset(true); + reset(); } public void setHeights(int smallHeight, int headsUpMaxHeight, int maxHeight) { @@ -255,7 +255,7 @@ public class NotificationContentView extends FrameLayout { updateVisibility(); } - public void reset(boolean resetActualHeight) { + public void reset() { if (mContractedChild != null) { mContractedChild.animate().cancel(); removeView(mContractedChild); @@ -271,10 +271,6 @@ public class NotificationContentView extends FrameLayout { mContractedChild = null; mExpandedChild = null; mHeadsUpChild = null; - mVisibleType = VISIBLE_TYPE_CONTRACTED; - if (resetActualHeight) { - mContentHeight = mSmallHeight; - } } public View getContractedChild() { @@ -484,12 +480,18 @@ public class NotificationContentView extends FrameLayout { private void animateToVisibleType(int visibleType) { final TransformableView shownView = getTransformableViewForVisibleType(visibleType); final TransformableView hiddenView = getTransformableViewForVisibleType(mVisibleType); + if (shownView == hiddenView) { + shownView.setVisible(true); + return; + } shownView.transformFrom(hiddenView); getViewForVisibleType(visibleType).setVisibility(View.VISIBLE); hiddenView.transformTo(shownView, new Runnable() { @Override public void run() { - hiddenView.setVisible(false); + if (hiddenView != getTransformableViewForVisibleType(mVisibleType)) { + hiddenView.setVisible(false); + } } }); } @@ -550,6 +552,9 @@ public class NotificationContentView extends FrameLayout { || mContainingNotification.isExpanded() ? mContainingNotification.getMaxContentHeight() : mContainingNotification.getShowingLayout().getMinHeight(); + if (height == 0) { + height = mContentHeight; + } int expandedVisualType = getVisualTypeForHeight(height); int collapsedVisualType = getVisualTypeForHeight( mContainingNotification.getMinExpandHeight()); @@ -557,7 +562,12 @@ public class NotificationContentView extends FrameLayout { ? expandedVisualType : collapsedVisualType; } - int viewHeight = Math.min(mContentHeight, mContainingNotification.getIntrinsicHeight()); + int intrinsicHeight = mContainingNotification.getIntrinsicHeight(); + int viewHeight = mContentHeight; + if (intrinsicHeight != 0) { + // the intrinsicHeight might be 0 because it was just reset. + viewHeight = Math.min(mContentHeight, intrinsicHeight); + } return getVisualTypeForHeight(viewHeight); } @@ -638,7 +648,6 @@ public class NotificationContentView extends FrameLayout { mBeforeN = entry.targetSdk < Build.VERSION_CODES.N; updateSingleLineView(); applyRemoteInput(entry); - selectLayout(false /* animate */, true /* force */); if (mContractedChild != null) { mContractedWrapper.notifyContentUpdated(entry.notification); } @@ -648,6 +657,7 @@ public class NotificationContentView extends FrameLayout { if (mHeadsUpChild != null) { mHeadsUpWrapper.notifyContentUpdated(entry.notification); } + selectLayout(false /* animate */, true /* force */); setDark(mDark, false /* animate */, 0 /* delay */); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java index bf05d1d7d8828..66f945ea83fa4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java @@ -76,26 +76,26 @@ public class ViewTransformationHelper implements TransformableView { }); mViewTransformationAnimation.setInterpolator(Interpolators.LINEAR); mViewTransformationAnimation.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); - if (endRunnable != null) { - mViewTransformationAnimation.addListener(new AnimatorListenerAdapter() { - public boolean mCancelled; + mViewTransformationAnimation.addListener(new AnimatorListenerAdapter() { + public boolean mCancelled; - @Override - public void onAnimationEnd(Animator animation) { - endRunnable.run(); - if (!mCancelled) { - setVisible(false); - } else { - abortTransformations(); + @Override + public void onAnimationEnd(Animator animation) { + if (!mCancelled) { + if (endRunnable != null) { + endRunnable.run(); } + setVisible(false); + } else { + abortTransformations(); } + } - @Override - public void onAnimationCancel(Animator animation) { - mCancelled = true; - } - }); - } + @Override + public void onAnimationCancel(Animator animation) { + mCancelled = true; + } + }); mViewTransformationAnimation.start(); }