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

Commit 0031e6c3 authored by DvTonder's avatar DvTonder
Browse files

SystemUI: Open Quick Settings panel if there are no active notifications

This is ported from AOKP and described as follows:

  If there are no notifications that belong to the current user, then automatically
  open the quick settings menu (like the two-finger open). It only ignores the ADB
  icon for now (which is pretty useless) but could be extended to ignore the usb
  mounting one or maybe another?
  Author: Roman Birg <romanbirg@gmail.com> AOKP
  AOKP Github: commit 2eb664a4bc5f93b705eeeaa0847331343bb017cd

The CM version of the commit respects the Power widget enabled settings and will
only display this behaviour if the Power widget is disabled.

Change-Id: Ie0c22167ebc6fd3152335c4148dbb7c65bfce46f
parent b055725d
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package com.android.systemui.statusbar.phone;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.MotionEvent;
@@ -92,9 +94,17 @@ public class NotificationPanelView extends PanelView {
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
            boolean shouldFlip = false;
            ContentResolver cr = mContext.getContentResolver();

            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                    mOkToFlip = getExpandedHeight() == 0;
                    // If we have no notifications and the Power Widget is disabled, flip to the settings panel
                    if(mStatusBar.skipToSettingsPanel()
                            && Settings.System.getInt(cr, Settings.System.EXPANDED_VIEW_WIDGET, 0) == 0) {
                        shouldFlip = true;
                    }
                    break;
                case MotionEvent.ACTION_POINTER_DOWN:
                    if (mOkToFlip) {
@@ -106,6 +116,12 @@ public class NotificationPanelView extends PanelView {
                            if (y > maxy) maxy = y;
                        }
                        if (maxy - miny < mHandleBarHeight) {
                            shouldFlip = true;
                        }
                    }
                    break;
            }
            if(mOkToFlip && shouldFlip) {
                if (getMeasuredHeight() < mHandleBarHeight) {
                    mStatusBar.switchToSettings();
                } else {
@@ -114,9 +130,6 @@ public class NotificationPanelView extends PanelView {
                mOkToFlip = false;
            }
        }
                    break;
            }
        }
        return mHandleView.dispatchTouchEvent(event);
    }
}
+27 −0
Original line number Diff line number Diff line
@@ -2611,6 +2611,33 @@ public class PhoneStatusBar extends BaseStatusBar {
                || (mDisabled & StatusBarManager.DISABLE_SEARCH) != 0;
    }

    public boolean skipToSettingsPanel() {
        if (mPile == null || mNotificationData == null) {
            return false;
        }

        int N = mNotificationData.size();
        int thisUsersNotifications = 0;
        for (int i=0; i<N; i++) {
            Entry ent = mNotificationData.get(N-i-1);
            if(ent != null
                    && ent.notification != null
                    && notificationIsForCurrentUser(ent.notification)) {
                switch(ent.notification.id) {
                    // ignore adb icon
                    case com.android.internal.R.drawable.stat_sys_adb:
                        continue;
                }
                thisUsersNotifications++;
            }
        }
        if(thisUsersNotifications == 0) {
            return true;
        }

        return false;
    }

    private static class FastColorDrawable extends Drawable {
        private final int mColor;