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

Commit 4372f7c4 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Prevent division by 0 in HeaderTileLayout

If the resolution is really small, only one column fits in QQS. In that
case, set the margin between tiles to half of the white space available
and use it to center that tile.

Test: adb shell wm size 300x450
Fixes: 144093397
Change-Id: I8fdac5b2358bd4b7669ec6667438ae560231e45e
parent 5fdaa0c9
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -319,7 +319,14 @@ public class QuickQSPanel extends QSPanel {
            } else{
                mColumns = mCellWidth == 0 ? 1 :
                        Math.min(maxTiles, availableWidth / mCellWidth );
                mCellMarginHorizontal = (availableWidth - mColumns * mCellWidth) / (mColumns - 1);
                // If we can only fit one column, use mCellMarginHorizontal to center it.
                if (mColumns == 1) {
                    mCellMarginHorizontal = (availableWidth - mCellWidth) / 2;
                } else {
                    mCellMarginHorizontal =
                            (availableWidth - mColumns * mCellWidth) / (mColumns - 1);
                }

            }
            return mColumns != prevNumColumns;
        }
@@ -357,6 +364,10 @@ public class QuickQSPanel extends QSPanel {

        @Override
        protected int getColumnStart(int column) {
            if (mColumns == 1) {
                // Only one column/tile. Use the margin to center the tile.
                return getPaddingStart() + mCellMarginHorizontal;
            }
            return getPaddingStart() + column *  (mCellWidth + mCellMarginHorizontal);
        }
    }