Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae441287 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Animate public/private notification layouts

This change move the boolean whether we hide sensitive contents into
AmbientState, which makes it consistent with the other stack states
and allows for a orchestrated transition between public/private
layouts. We need this transition when going into the full shade.

Bug: 16291973
Change-Id: I379a6119b5b73eca900a4a2ba9d5ec95b293e487
parent dbc3dce8
Loading
Loading
Loading
Loading
+59 −7
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
    private boolean mUserLocked;
    /** Are we showing the "public" version */
    private boolean mShowingPublic;
    private boolean mSensitive;
    private boolean mShowingPublicInitialized;
    private boolean mShowingPublicForIntrinsicHeight;

    /**
     * Is this notification expanded by the system. The expansion state can be overridden by the
@@ -78,6 +81,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        mHasUserChangedExpansion = false;
        mUserLocked = false;
        mShowingPublic = false;
        mSensitive = false;
        mShowingPublicInitialized = false;
        mIsSystemExpanded = false;
        mExpansionDisabled = false;
        mPublicLayout.reset();
@@ -222,7 +227,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
            return mRowMinHeight;
        }

        return mShowingPublic ? mRowMinHeight : getMaxExpandHeight();
        return mShowingPublicForIntrinsicHeight ? mRowMinHeight : getMaxExpandHeight();
    }

    /**
@@ -248,17 +253,64 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        }
    }

    public void setShowingPublic(boolean show) {
        mShowingPublic = show;
    public void setSensitive(boolean sensitive) {
        mSensitive = sensitive;
    }

    public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
        mShowingPublicForIntrinsicHeight = mSensitive && hideSensitive;
    }

    public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
            long duration) {
        boolean oldShowingPublic = mShowingPublic;
        mShowingPublic = mSensitive && hideSensitive;
        if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
            return;
        }

        // bail out if no public version
        if (mPublicLayout.getChildCount() == 0) return;

        // TODO: animation?
        mPublicLayout.setVisibility(show ? View.VISIBLE : View.GONE);
        mPrivateLayout.setVisibility(show ? View.GONE : View.VISIBLE);
        if (!animated) {
            mPublicLayout.animate().cancel();
            mPrivateLayout.animate().cancel();
            mPublicLayout.setAlpha(1f);
            mPrivateLayout.setAlpha(1f);
            mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
            mPrivateLayout.setVisibility(mShowingPublic ? View.INVISIBLE : View.VISIBLE);
        } else {
            animateShowingPublic(delay, duration);
        }

        updateVetoButton();
        mShowingPublicInitialized = true;
    }

    private void animateShowingPublic(long delay, long duration) {
        final View source = mShowingPublic ? mPrivateLayout : mPublicLayout;
        View target = mShowingPublic ? mPublicLayout : mPrivateLayout;
        source.setVisibility(View.VISIBLE);
        target.setVisibility(View.VISIBLE);
        target.setAlpha(0f);
        source.animate().cancel();
        target.animate().cancel();
        source.animate()
                .alpha(0f)
                .withLayer()
                .setStartDelay(delay)
                .setDuration(duration)
                .withEndAction(new Runnable() {
                    @Override
                    public void run() {
                        source.setVisibility(View.INVISIBLE);
                    }
                });
        target.animate()
                .alpha(1f)
                .withLayer()
                .setStartDelay(delay)
                .setDuration(duration);
    }

    private void updateVetoButton() {
@@ -267,7 +319,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
    }

    public int getMaxExpandHeight() {
        return mShowingPublic ? mRowMinHeight : mMaxExpandHeight;
        return mShowingPublicForIntrinsicHeight ? mRowMinHeight : mMaxExpandHeight;
    }

    @Override
+17 −0
Original line number Diff line number Diff line
@@ -175,6 +175,23 @@ public abstract class ExpandableView extends FrameLayout {
    public void setDark(boolean dark, boolean fade) {
    }

    /**
     * See {@link #setHideSensitive}. This is a variant which notifies this view in advance about
     * the upcoming state of hiding sensitive notifications. It gets called at the very beginning
     * of a stack scroller update such that the updated intrinsic height (which is dependent on
     * whether private or public layout is showing) gets taken into account into all layout
     * calculations.
     */
    public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
    }

    /**
     * Sets whether the notification should hide its private contents if it is sensitive.
     */
    public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
            long duration) {
    }

    /**
     * @return The desired notification height.
     */
+11 −5
Original line number Diff line number Diff line
@@ -1362,10 +1362,15 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            int vis = ent.notification.getNotification().visibility;

            // Display public version of the notification if we need to redact.
            final boolean hideSensitive = shouldHideSensitiveContents(ent.notification.getUserId());
            boolean showingPublic = vis == Notification.VISIBILITY_PRIVATE && hideSensitive;
            ent.row.setShowingPublic(showingPublic);
            final boolean hideSensitive =
                    !userAllowsPrivateNotificationsInPublic(ent.notification.getUserId());
            boolean sensitive = vis == Notification.VISIBILITY_PRIVATE;
            boolean showingPublic = sensitive && hideSensitive && isLockscreenPublicMode();
            ent.row.setSensitive(sensitive && hideSensitive);
            if (ent.autoRedacted && ent.legacy) {

                // TODO: Also fade this? Or, maybe easier (and better), provide a dark redacted form
                // for legacy auto redacted notifications.
                if (showingPublic) {
                    ent.row.setShowingLegacyBackground(false);
                } else {
@@ -3415,8 +3420,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
        mNotificationPanel.setBarState(mState, mKeyguardFadingAway, goingToFullShade);
        updateDozingState();
        updateStackScrollerState();
        updatePublicMode();
        updateStackScrollerState(goingToFullShade);
        updateNotifications();
        checkBarModes();
        updateCarrierLabelVisibility(false);
@@ -3443,9 +3448,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mScrimController.setDozing(mDozing);
    }

    public void updateStackScrollerState() {
    public void updateStackScrollerState(boolean goingToFullShade) {
        if (mStackScroller == null) return;
        boolean onKeyguard = mState == StatusBarState.KEYGUARD;
        mStackScroller.setHideSensitive(isLockscreenPublicMode(), goingToFullShade);
        mStackScroller.setDimmed(onKeyguard, false /* animate */);
        mStackScroller.setExpandingEnabled(!onKeyguard);
        ActivatableNotificationView activatedChild = mStackScroller.getActivatedChild();
+3 −1
Original line number Diff line number Diff line
@@ -91,7 +91,9 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.

        if (mHeadsUp != null) {
            mHeadsUp.row.setSystemExpanded(true);
            mHeadsUp.row.setShowingPublic(false);
            mHeadsUp.row.setSensitive(false);
            mHeadsUp.row.setHideSensitive(
                    false, false /* animated */, 0 /* delay */, 0 /* duration */);
            if (mContentHolder == null) {
                // too soon!
                return false;
+9 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ public class AmbientState {
    private int mSpeedBumpIndex = -1;
    private float mScrimAmount;
    private boolean mDark;
    private boolean mHideSensitive;

    public int getScrollY() {
        return mScrollY;
@@ -68,6 +69,10 @@ public class AmbientState {
        mDark = dark;
    }

    public void setHideSensitive(boolean hideSensitive) {
        mHideSensitive = hideSensitive;
    }

    /**
     * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
     * interaction. This child is then scaled normally and its background is fully opaque.
@@ -84,6 +89,10 @@ public class AmbientState {
        return mDark;
    }

    public boolean isHideSensitive() {
        return mHideSensitive;
    }

    public ActivatableNotificationView getActivatedChild() {
        return mActivatedChild;
    }
Loading