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

Commit 9c1b7302 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: reset tile page after inactivity



Reset the quick settings page back to the first page when the user
hasn't expanded their statusbar for 10s.

Ref: CYNGNOS-2132

Change-Id: Ia195f8c85c8e399ab5e4808fe0ccc343853a1577
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent d218a202
Loading
Loading
Loading
Loading
+19 −30
Original line number Diff line number Diff line
@@ -89,6 +89,9 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

    private static final int MAX_ROW_COUNT = 3;

    // how long to wait before resetting the page
    private static final int PAGE_RESET_DELAY = 10000;

    protected final ArrayList<QSPage> mPages = new ArrayList<>();

    protected QSViewPager mViewPager;
@@ -119,6 +122,16 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
    private Point mDisplaySize;
    private int[] mTmpLoc;

    private Runnable mResetPage = new Runnable() {
        @Override
        public void run() {
            if (!mListening) {
                // only reset when the user isn't interacting at all
                mViewPager.setCurrentItem(0);
            }
        }
    };

    public QSDragPanel(Context context) {
        this(context, null);
    }
@@ -369,6 +382,12 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
    public void setListening(boolean listening) {
        if (mListening == listening) return;
        mListening = listening;
        // reset the page when inactive for a while
        if (listening) {
            removeCallbacks(mResetPage);
        } else {
            postDelayed(mResetPage, PAGE_RESET_DELAY);
        }
        for (TileRecord r : mRecords) {
            r.tile.setListening(mListening);
        }
@@ -481,36 +500,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        mDetailRemoveButton.setText(R.string.quick_settings_remove);
    }

    /**
     * @return returns the number of pages that has at least 1 visible tile
     */
    protected int getVisibleTilePageCount() {
        // if all tiles are invisible on the page, do not count it
        int pages = 0;

        int lastPage = -1;
        boolean allTilesInvisible = true;

        for (TileRecord record : mRecords) {
            DragTileRecord dr = (DragTileRecord) record;
            if (dr.destinationPage != lastPage) {
                if (!allTilesInvisible) {
                    pages++;
                }
                lastPage = dr.destinationPage;
                allTilesInvisible = true;
            }
            if (allTilesInvisible && dr.tile.getState().visible) {
                allTilesInvisible = false;
            }
        }
        // last tile may have set this
        if (!allTilesInvisible) {
            pages++;
        }
        return pages;
    }

    public void setTiles(final Collection<QSTile<?>> tilesCollection) {
        final List<QSTile<?>> tiles = new ArrayList<>(tilesCollection);
        if (DEBUG_TILES) {