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

Commit 3a116101 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: improve qs tile layout mechanism



Previously we'd have a temp tile array which would hold tiles until we
were ready to do the first layout pass which caused some funky layouts
initially in specific cases. Get rid of the temp tile array and handle
setting tiles in one pass.

Ref: CYNGNOS-1601

Change-Id: Ibfa4994600c55ced80b8292cbefa9aa1f44971ae
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 6fb2c183
Loading
Loading
Loading
Loading
+81 −121
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

    private static final String TAG = "QSDragPanel";

    public static final boolean DEBUG_TILES = false;
    public static final boolean DEBUG_DRAG = false;

    private static final int MAX_ROW_COUNT = 3;
@@ -114,7 +115,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

    List<TileRecord> mCurrentlyAnimating
            = Collections.synchronizedList(new ArrayList<TileRecord>());
    private Collection<QSTile<?>> mTempTiles = null;

    private Point mDisplaySize;
    private int[] mTmpLoc;
@@ -454,9 +454,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

    protected int getCurrentMaxPageCount() {
        int initialSize = mRecords.size();
        if (mTempTiles != null) {
            return getPagesForCount(initialSize + mTempTiles.size());
        }
        return getPagesForCount(initialSize);
    }

@@ -498,14 +495,9 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

    public void setTiles(final Collection<QSTile<?>> tilesCollection) {
        final List<QSTile<?>> tiles = new ArrayList<>(tilesCollection);
        if (isLaidOut()) {
            if (DEBUG_DRAG) {
        if (DEBUG_TILES) {
            Log.i(TAG, "setTiles() called with " + "tiles = ["
                        + tiles + "], mTempTiles: " + mTempTiles);
                if (mTempTiles != null) {
                    Log.e(TAG, "temp tiles being overridden... : " +
                            Arrays.toString(mTempTiles.toArray()));
                }
                    + tiles + "]");
        }

        if (mLastDragRecord != null && mRecords.indexOf(mLastDragRecord) == -1) {
@@ -524,12 +516,12 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
            DragTileRecord dr = (DragTileRecord) iterator.next();

            if (tiles.contains(dr.tile)) {
                    if (DEBUG_DRAG) {
                if (DEBUG_TILES) {
                    Log.i(TAG, "caching tile: " + dr.tile);
                }
                recordMap.put(dr.tile, dr);
            } else {
                    if (DEBUG_DRAG) {
                if (DEBUG_TILES) {
                    Log.i(TAG, "removing tile: " + dr.tile);
                }
                // clean up view
@@ -544,7 +536,7 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On

        // at this point recordMap should have all retained tiles, no new or old tiles
        int delta = tiles.size() - recordMap.size() - recordsRemoved;
            if (DEBUG_DRAG) {
        if (DEBUG_TILES) {
            Log.i(TAG, "record map delta: " + delta);
        }
        mRecords.ensureCapacity(tiles.size());
@@ -555,27 +547,27 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
            QSTile<?> tile = tiles.get(i);
            final int tileDestPage = getPagesForCount(i + 1) - 1;

                if (DEBUG_DRAG) {
            if (DEBUG_TILES) {
                Log.d(TAG, "tile at : " + i + ": " + tile + " to dest page: " + tileDestPage);
            }
            DragTileRecord record;
            if (!recordMap.containsKey(tile)) {
                    DragTileRecord record = makeRecord(tile);
                if (DEBUG_TILES) {
                    Log.d(TAG, "tile at: " + i + " not cached, adding it to records");
                }
                record = makeRecord(tile);
                record.destinationPage = tileDestPage;
                recordMap.put(tile, record);
                mRecords.add(i, record);
                mPagerAdapter.notifyDataSetChanged();

                    // add the view
                    mPages.get(record.destinationPage).addView(record.tileView);
                    record.page = record.destinationPage;
                    if (DEBUG_DRAG) {
                        Log.d(TAG, "added new record " + record);
                    }
            } else {
                    DragTileRecord record = recordMap.get(tile);
                record = recordMap.get(tile);
                if (DEBUG_TILES) {
                    Log.d(TAG, "tile at : " + i + ": cached, restoring: " + record);
                }
                int indexOf = mRecords.indexOf(record);
                if (indexOf != i) {
                        if (DEBUG_DRAG) {
                    if (DEBUG_TILES) {
                        Log.w(TAG, "moving index of " + record + " from "
                                + indexOf + " to " + i);
                    }
@@ -584,16 +576,19 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                    record.destinationPage = tileDestPage;
                    ensureDestinationPage(record);
                }

            }
            if (record.page == -1) {
                // add the view
                mPages.get(record.destinationPage).addView(record.tileView);
                record.page = record.destinationPage;
                if (DEBUG_TILES) {
                    Log.d(TAG, "added view " + record);
                }
            if (isShowingDetail()) {
                mDetail.bringToFront();
            }
        } else if (!isLaidOut()) {
            if (DEBUG_DRAG) {
                Log.w(TAG, "setting temporary tiles to layout");
        }
            mTempTiles = Collections.synchronizedCollection(new ArrayList<QSTile<?>>(tiles));
        if (isShowingDetail()) {
            mDetail.bringToFront();
        }
        mPagerAdapter.notifyDataSetChanged();

@@ -612,7 +607,7 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
    }

    private DragTileRecord makeRecord(final QSTile<?> tile) {
        if (DEBUG_DRAG) {
        if (DEBUG_TILES) {
            Log.d(TAG, "+++ makeRecord() called with " + "tile = [" + tile + "]");
        }
        final DragTileRecord r = new DragTileRecord();
@@ -689,37 +684,12 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        r.tileView.setVisibility(mEditing ? View.VISIBLE : View.GONE);
        callback.onStateChanged(r.tile.getState());

        if (DEBUG_DRAG) {
        if (DEBUG_TILES) {
            Log.d(TAG, "--- makeRecord() called with " + "tile = [" + tile + "]");
        }
        return r;
    }

    private void addTile(final QSTile<?> tile) {
        if (DEBUG_DRAG) {
            Log.d(TAG, "+++ addTile() called with " + "tile = [" + tile + "]");
        }
        DragTileRecord r = makeRecord(tile);
        mRecords.add(r);
        mPagerAdapter.notifyDataSetChanged();

        r.destinationPage = getPagesForCount(mRecords.size()) - 1;

        if (DEBUG_DRAG) {
            Log.d(TAG, "destinationPage: " + r.destinationPage);
        }

        mPages.get(r.destinationPage).addView(r.tileView);
        r.page = r.destinationPage;
        drawTile(r, r.tile.getState());

        ensurePagerState();

        if (DEBUG_DRAG) {
            Log.d(TAG, "--- addTile() called with " + "tile = [" + tile + "]");
        }
    }

    public void ensurePagerState() {
        if (!isShowingDetail()) {
            final boolean pagingEnabled = getVisibleTilePageCount() > 1 || mDragging || mEditing;
@@ -841,16 +811,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                    footer.getMeasuredWidth(), getMeasuredHeight());
        }

        if (mTempTiles != null) {
            final Iterator<QSTile<?>> iterator = mTempTiles.iterator();
            while (iterator.hasNext()) {
                addTile(iterator.next());
                iterator.remove();
            }
            mTempTiles = null;
            mPagerAdapter.notifyDataSetChanged();
            requestLayout();
        }
        ensurePagerState();
    }

+0 −1
Original line number Diff line number Diff line
@@ -1163,7 +1163,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                        mSecurityController);
            }
            mQSPanel.setHost(mQSTileHost);
            mQSPanel.setTiles(mQSTileHost.getTiles());
            if (mBrightnessMirrorController == null) {
                mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindowContent);
            }