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

Commit 31aada4e authored by Selim Cinek's avatar Selim Cinek
Browse files

Enabled usage of expand button in heads up notifications

Heads up notifications can now be expanded with the expand
button. The notification stays there until the user dismisses it
or collapses it again.

Change-Id: I0f1b729915317bbbd6f13c3d968c933ffbe6feeb
parent 6959f9b0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1276,7 +1276,7 @@ public abstract class BaseStatusBar extends SystemUI implements
    }

    @Override
    public void onExpandClicked(View clickedView, boolean nowExpanded) {
    public void onExpandClicked(Entry clickedEntry, boolean nowExpanded) {
    }

    protected class H extends Handler {
@@ -1359,6 +1359,7 @@ public abstract class BaseStatusBar extends SystemUI implements
                    parent, false);
            row.setExpansionLogger(this, entry.notification.getKey());
            row.setGroupManager(mGroupManager);
            row.setHeadsUpManager(mHeadsUpManager);
            row.setRemoteInputController(mRemoteInputController);
            row.setOnExpandClickListener(this);
        }
+50 −12
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.widget.RemoteViews;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
import com.android.systemui.statusbar.stack.StackScrollState;
import com.android.systemui.statusbar.stack.StackStateAnimator;
@@ -59,6 +60,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
    private boolean mHasUserChangedExpansion;
    /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
    private boolean mUserExpanded;

    /**
     * Has this notification been expanded while it was pinned
     */
    private boolean mExpandedWhenPinned;
    /** Is the user touching this row */
    private boolean mUserLocked;
    /** Are we showing the "public" version */
@@ -103,6 +109,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
    private boolean mIsSystemChildExpanded;
    private boolean mIsPinned;
    private FalsingManager mFalsingManager;
    private HeadsUpManager mHeadsUpManager;
    private NotificationHeaderUtil mHeaderUtil = new NotificationHeaderUtil(this);

    private boolean mJustClicked;
@@ -115,14 +122,19 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        public void onClick(View v) {
            if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
                mGroupManager.toggleGroupExpansion(mStatusBarNotification);
                mOnExpandClickListener.onExpandClicked(ExpandableNotificationRow.this,
                mOnExpandClickListener.onExpandClicked(mEntry,
                        mGroupManager.isGroupExpanded(mStatusBarNotification));
            } else {
                boolean nowExpanded = !isExpanded();
                boolean nowExpanded;
                if (isPinned()) {
                    nowExpanded = !mExpandedWhenPinned;
                    mExpandedWhenPinned = nowExpanded;
                } else {
                    nowExpanded = !isExpanded();
                    setUserExpanded(nowExpanded);
                }
                notifyHeightChanged(true);
                mOnExpandClickListener.onExpandClicked(ExpandableNotificationRow.this,
                        nowExpanded);
                mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
            }
        }
    };
@@ -386,6 +398,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
     */
    public void setPinned(boolean pinned) {
        mIsPinned = pinned;
        if (pinned) {
            setIconAnimationRunning(true);
            mExpandedWhenPinned = false;
        } else if (mExpandedWhenPinned) {
            setUserExpanded(true);
        }
        setChronometerRunning(mLastChronometerRunning);
    }

@@ -393,12 +411,23 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        return mIsPinned;
    }

    public int getHeadsUpHeight() {
    /**
     * @param atLeastMinHeight should the value returned be at least the minimum height.
     *                         Used to avoid cyclic calls
     * @return the height of the heads up notification when pinned
     */
    public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
        if (mIsSummaryWithChildren) {
            return mChildrenContainer.getIntrinsicHeight();
        }
        if(mExpandedWhenPinned) {
            return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
        } else if (atLeastMinHeight) {
            return Math.max(getMinHeight(), mHeadsUpHeight);
        } else {
            return mHeadsUpHeight;
        }
    }

    /**
     * Mark whether this notification was just clicked, i.e. the user has just clicked this
@@ -461,6 +490,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        mOnExpandClickListener = onExpandClickListener;
    }

    public void setHeadsUpManager(HeadsUpManager headsUpManager) {
        mHeadsUpManager = headsUpManager;
    }

    public interface ExpansionLogger {
        public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
    }
@@ -718,7 +751,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        if (isUserLocked()) {
            return getActualHeight();
        }
        boolean inExpansionState = isExpanded();
        if (mGuts != null && mGuts.areGutsExposed()) {
            return mGuts.getHeight();
        } else if ((isChildInGroup() && !isGroupExpanded())) {
@@ -728,12 +760,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        } else if (mIsSummaryWithChildren && !mOnKeyguard) {
            return mChildrenContainer.getIntrinsicHeight();
        } else if (mIsHeadsUp) {
            if (inExpansionState) {
            if (isPinned()) {
                return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
            } else if (isExpanded()) {
                return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
            } else {
                return Math.max(getMinHeight(), mHeadsUpHeight);
            }
        } else if (inExpansionState) {
        } else if (isExpanded()) {
            return getMaxExpandHeight();
        } else {
            return getMinHeight();
@@ -961,8 +995,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {

    @Override
    public int getMinHeight() {
        if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
        if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
                return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
        } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
            return mChildrenContainer.getMinHeight();
        } else if (mIsHeadsUp) {
            return mHeadsUpHeight;
        }
        NotificationContentView showingLayout = getShowingLayout();
        return showingLayout.getMinHeight();
@@ -1067,6 +1105,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
    }

    public interface OnExpandClickListener {
        void onExpandClicked(View clickedView, boolean nowExpanded);
        void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -110,12 +110,12 @@ public class HeadsUpTouchHelper implements Gefingerpoken {
                    mInitialTouchX = x;
                    mInitialTouchY = y;
                    int expandedHeight = mPickedChild.getActualHeight();
                    mHeadsUpManager.unpinAll();
                    mPanel.setPanelScrimMinFraction((float) expandedHeight
                            / mPanel.getMaxPanelHeight());
                    mPanel.startExpandMotion(x, y, true /* startTracking */, expandedHeight
                            + mNotificationsTopPadding);
                    mPanel.clearNotificattonEffects();
                    mHeadsUpManager.unpinAll();
                    return true;
                }
                break;
+3 −2
Original line number Diff line number Diff line
@@ -4035,9 +4035,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    }

    @Override
    public void onExpandClicked(View clickedView, boolean nowExpanded) {
    public void onExpandClicked(Entry clickedEntry, boolean nowExpanded) {
        mHeadsUpManager.setExpanded(clickedEntry, nowExpanded);
        if (mState == StatusBarState.KEYGUARD && nowExpanded) {
            goToLockedShade(clickedView);
            goToLockedShade(clickedEntry.row);
        }
    }

+41 −4
Original line number Diff line number Diff line
@@ -387,7 +387,7 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
                    row.getLocationOnScreen(mTmpTwoArray);
                    minX = mTmpTwoArray[0];
                    maxX = mTmpTwoArray[0] + row.getWidth();
                    maxY = row.getHeadsUpHeight();
                    maxY = row.getIntrinsicHeight();
                    break;
                }
            }
@@ -448,6 +448,8 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        for (String key : mHeadsUpEntries.keySet()) {
            HeadsUpEntry entry = mHeadsUpEntries.get(key);
            setEntryPinned(entry, false /* isPinned */);
            // maybe it got un sticky
            entry.updateEntry(false /* updatePostTime */);
        }
    }

@@ -470,6 +472,10 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        mTrackingHeadsUp = trackingHeadsUp;
    }

    public boolean isTrackingHeadsUp() {
        return mTrackingHeadsUp;
    }

    public void setIsExpanded(boolean isExpanded) {
        if (isExpanded != mIsExpanded) {
            mIsExpanded = isExpanded;
@@ -482,9 +488,16 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        }
    }

    public int getTopHeadsUpHeight() {
    /**
     * @return the height of the top heads up notification when pinned. This is different from the
     *         intrinsic height, which also includes whether the notification is system expanded and
     *         is mainly used when dragging down from a heads up notification.
     */
    public int getTopHeadsUpPinnedHeight() {
        HeadsUpEntry topEntry = getTopEntry();
        return topEntry != null ? topEntry.entry.row.getHeadsUpHeight() : 0;
        return topEntry != null && topEntry.entry != null
                ? topEntry.entry.row.getPinnedHeadsUpHeight(true /* atLeastMinHeight */)
                : 0;
    }

    /**
@@ -557,6 +570,22 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        }
    }

    /**
     * Set an entry to be expanded and therefore stick in the heads up area if it's pinned
     * until it's collapsed again.
     */
    public void setExpanded(NotificationData.Entry entry, boolean expanded) {
        HeadsUpEntry headsUpEntry = mHeadsUpEntries.get(entry.key);
        if (headsUpEntry != null && headsUpEntry.expanded != expanded) {
            headsUpEntry.expanded = expanded;
            if (expanded) {
                headsUpEntry.removeAutoRemovalCallbacks();
            } else {
                headsUpEntry.updateEntry(false /* updatePostTime */);
            }
        }
    }

    /**
     * This represents a notification and how long it is in a heads up mode. It also manages its
     * lifecycle automatically when created.
@@ -567,6 +596,7 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        public long earliestRemovaltime;
        private Runnable mRemoveHeadsUpRunnable;
        public boolean remoteInputActive;
        public boolean expanded;

        public void setEntry(final NotificationData.Entry entry) {
            this.entry = entry;
@@ -601,7 +631,7 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
            if (mEntriesToRemoveAfterExpand.contains(entry)) {
                mEntriesToRemoveAfterExpand.remove(entry);
            }
            if (!hasFullScreenIntent(entry) && !mRemoteInputActive) {
            if (!isSticky()) {
                long finishTime = postTime + mHeadsUpNotificationDecay;
                long removeDelay = Math.max(finishTime - currentTime, mMinimumDisplayTime);
                mHandler.postDelayed(mRemoveHeadsUpRunnable, removeDelay);
@@ -609,6 +639,11 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
            mSortedEntries.add(HeadsUpEntry.this);
        }

        private boolean isSticky() {
            return (entry.row.isPinned() && expanded)
                    || remoteInputActive || hasFullScreenIntent(entry);
        }

        @Override
        public int compareTo(HeadsUpEntry o) {
            boolean selfFullscreen = hasFullScreenIntent(entry);
@@ -641,6 +676,8 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
            removeAutoRemovalCallbacks();
            entry = null;
            mRemoveHeadsUpRunnable = null;
            expanded = false;
            remoteInputActive = false;
        }
    }

Loading