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

Commit 57f08cc5 authored by Marc K's avatar Marc K Committed by Eamon Powell
Browse files

Fix preview tile in grid option picker

Create GridTileDrawable with cols and rows parameters in correct order
and display also non quadratic configurations correctly.

Change-Id: I6bb64564e86ec002831dc04bf95f51318dc9e6b3
parent db87e153
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public class GridOption implements CustomizationOption<GridOption> {
            Uri previewImageUri, int previewPagesCount, String iconShapePath) {
        mTitle = title;
        mIsCurrent = isCurrent;
        mTileDrawable = new GridTileDrawable(rows, cols, iconShapePath);
        mTileDrawable = new GridTileDrawable(cols, rows, iconShapePath);
        this.name = name;
        this.rows = rows;
        this.cols = cols;
+12 −5
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ public class GridTileDrawable extends Drawable {
    private final Path mTransformedPath;
    private final Matrix mScaleMatrix;
    private float mCellSize = -1f;
    private float mSpaceBetweenIcons;
    private float mMarginTop;
    private float mMarginLeft;

    public GridTileDrawable(int cols, int rows, String path) {
        mCols = cols;
@@ -41,9 +42,15 @@ public class GridTileDrawable extends Drawable {

    @Override
    protected void onBoundsChange(Rect bounds) {
        float spaceBetweenIcons;

        super.onBoundsChange(bounds);
        mCellSize = (float) bounds.height() / mRows;
        mSpaceBetweenIcons = mCellSize * ((1 - ICON_SCALE) / 2);
        mCellSize = Math.min((float) bounds.height() / mRows,  (float) bounds.width() / mCols);

        spaceBetweenIcons = mCellSize * ((1 - ICON_SCALE) / 2);
        mMarginTop = (bounds.height() - mCellSize * mRows) / 2 + spaceBetweenIcons;
        mMarginLeft = (bounds.width() - mCellSize * mCols) / 2 + spaceBetweenIcons;


        float scaleFactor = (mCellSize * ICON_SCALE) / PATH_SIZE;
        mScaleMatrix.setScale(scaleFactor, scaleFactor);
@@ -55,8 +62,8 @@ public class GridTileDrawable extends Drawable {
        for (int r = 0; r < mRows; r++) {
            for (int c = 0; c < mCols; c++) {
                int saveCount = canvas.save();
                float x = (c * mCellSize) + mSpaceBetweenIcons;
                float y = (r * mCellSize) + mSpaceBetweenIcons;
                float x = (c * mCellSize) + mMarginLeft;
                float y = (r * mCellSize) + mMarginTop;
                canvas.translate(x, y);
                canvas.drawPath(mTransformedPath, mPaint);
                canvas.restoreToCount(saveCount);