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

Commit 5f71bee3 authored by Selim Cinek's avatar Selim Cinek
Browse files

Determining the number of keyguard notifications dynamically

Instead of having a fixed number, we are now calculating the number
dynamically based on the available notifications.
This is necessary since notifications might have different sizes now.

Change-Id: I0cbe9b1c5fd731a89c242202846f42bec3fc57eb
parent 177fd432
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -1289,6 +1289,17 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
    }

    /**
     * Called when the panel was layouted expanded for the first time after being collapsed.
     */
    public void onPanelExpandedAndLayouted() {
        if (mState == StatusBarState.KEYGUARD) {
            // Since the number of notifications is determined based on the height of the view, we
            // need to update them.
            updateRowStates();
        }
    }

    protected class H extends Handler {
        public void handleMessage(Message m) {
            switch (m.what) {
@@ -1955,15 +1966,15 @@ public abstract class BaseStatusBar extends SystemUI implements
    }

    /**
     * @param recompute wheter the number should be recomputed
     * @return The number of notifications we show on Keyguard.
     */
    protected abstract int getMaxKeyguardNotifications();
    protected abstract int getMaxKeyguardNotifications(boolean recompute);

    /**
     * Updates expanded, dimmed and locked states of notification rows.
     */
    protected void updateRowStates() {
        int maxKeyguardNotifications = getMaxKeyguardNotifications();
        mKeyguardIconOverflowContainer.getIconsView().removeAllViews();

        ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
@@ -1971,6 +1982,10 @@ public abstract class BaseStatusBar extends SystemUI implements

        int visibleNotifications = 0;
        boolean onKeyguard = mState == StatusBarState.KEYGUARD;
        int maxNotifications = 0;
        if (onKeyguard) {
            maxNotifications = getMaxKeyguardNotifications(true /* recompute */);
        }
        for (int i = 0; i < N; i++) {
            NotificationData.Entry entry = activeNotifications.get(i);
            if (onKeyguard) {
@@ -1986,7 +2001,7 @@ public abstract class BaseStatusBar extends SystemUI implements
                    == View.VISIBLE;
            boolean showOnKeyguard = shouldShowOnKeyguard(entry.notification);
            if ((isLockscreenPublicMode() && !mShowLockscreenNotifications) ||
                    (onKeyguard && (visibleNotifications >= maxKeyguardNotifications
                    (onKeyguard && (visibleNotifications >= maxNotifications
                            && !childWithVisibleSummary
                            || !showOnKeyguard))) {
                entry.row.setVisibility(View.GONE);
+5 −0
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ public class KeyguardClockPositionAlgorithm {
        mEmptyDragAmount = emptyDragAmount;
    }

    public float getMinStackScrollerPadding(int height, int keyguardStatusHeight) {
        return mClockYFractionMin * height + keyguardStatusHeight / 2
                + mClockNotificationsMarginMin;
    }

    public void run(Result result) {
        int y = getClockY() - mKeyguardStatusHeight / 2;
        float clockAdjustment = getClockYExpansionAdjustment();
+31 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.android.internal.logging.MetricsLogger;
import com.android.keyguard.KeyguardStatusView;
import com.android.systemui.DejankUtils;
@@ -448,6 +449,36 @@ public class NotificationPanelView extends PanelView implements
        requestScrollerTopPaddingUpdate(animate);
    }

    /**
     * @param maximum the maximum to return at most
     * @return the maximum keyguard notifications that can fit on the screen
     */
    public int computeMaxKeyguardNotifications(int maximum) {
        float minPadding = mClockPositionAlgorithm.getMinStackScrollerPadding(getHeight(),
                mKeyguardStatusView.getHeight());
        int keyguardPadding = getResources().getDimensionPixelSize(
                R.dimen.notification_padding_dimmed);
        final int overflowheight = getResources().getDimensionPixelSize(
                R.dimen.notification_summary_height);
        float bottomStackSize = mNotificationStackScroller.getKeyguardBottomStackSize();
        float availableSpace = mNotificationStackScroller.getHeight() - minPadding - overflowheight
                - bottomStackSize;
        int count = 0;
        for (int i = 0; i < mNotificationStackScroller.getChildCount(); i++) {
            ExpandableView child = (ExpandableView) mNotificationStackScroller.getChildAt(i);
            if (!(child instanceof ExpandableNotificationRow)) {
                continue;
            }
            availableSpace -= child.getMinHeight() + keyguardPadding;
            if (availableSpace >= 0 && count < maximum) {
                count++;
            } else {
                return count;
            }
        }
        return count;
    }

    private void startClockAnimation(int y) {
        if (mClockAnimationTarget == y) {
            return;
+1 −2
Original line number Diff line number Diff line
@@ -36,9 +36,7 @@ import android.widget.FrameLayout;
import com.android.systemui.EventLogConstants;
import com.android.systemui.EventLogTags;
import com.android.systemui.R;
import com.android.systemui.classifier.Classifier;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.classifier.HumanInteractionClassifier;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.statusbar.StatusBarState;
@@ -891,6 +889,7 @@ public abstract class PanelView extends FrameLayout {
                        if (mStatusBar.getStatusBarWindow().getHeight()
                                != mStatusBar.getStatusBarHeight()) {
                            getViewTreeObserver().removeOnGlobalLayoutListener(this);
                            mStatusBar.onPanelExpandedAndLayouted();
                            if (animate) {
                                mBar.startOpeningPanel(PanelView.this);
                                notifyExpandingStarted();
+16 −6
Original line number Diff line number Diff line
@@ -110,8 +110,8 @@ import com.android.systemui.EventLogConstants;
import com.android.systemui.EventLogTags;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.keyguard.KeyguardViewMediator;
@@ -171,7 +171,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
@@ -338,7 +337,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    private long mKeyguardFadingAwayDelay;
    private long mKeyguardFadingAwayDuration;

    int mKeyguardMaxNotificationCount;
    int mMaxAllowedKeyguardNotifications;

    boolean mExpandedVisible;

@@ -428,6 +427,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    private boolean mAutohideSuspended;
    private int mStatusBarMode;
    private int mNavigationBarMode;
    private int mMaxKeyguardNotifications;

    private ViewMediatorCallback mKeyguardViewMediatorCallback;
    private ScrimController mScrimController;
@@ -3132,7 +3132,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mRowMinHeight =  res.getDimensionPixelSize(R.dimen.notification_min_height);
        mRowMaxHeight =  res.getDimensionPixelSize(R.dimen.notification_max_height);

        mKeyguardMaxNotificationCount = res.getInteger(R.integer.keyguard_max_notification_count);
        mMaxAllowedKeyguardNotifications = res.getInteger(R.integer.keyguard_max_notification_count);

        if (DEBUG) Log.v(TAG, "updateResources");
    }
@@ -3913,8 +3913,18 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    }

    @Override
    protected int getMaxKeyguardNotifications() {
        return mKeyguardMaxNotificationCount;
    protected int getMaxKeyguardNotifications(boolean recompute) {
        if (recompute) {
            mMaxKeyguardNotifications = Math.max(1,
                    mNotificationPanel.computeMaxKeyguardNotifications(
                            mMaxAllowedKeyguardNotifications));
            return mMaxKeyguardNotifications;
        }
        return mMaxKeyguardNotifications;
    }

    public int getMaxKeyguardNotifications() {
        return getMaxKeyguardNotifications(false /* recompute */);
    }

    public NavigationBarView getNavigationBarView() {
Loading