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

Commit 801e0e55 authored by Yash Garg's avatar Yash Garg 💬
Browse files

Merge branch '493-master-clock-icon-fix' into 'master'

fix: resize clock icon to be same size as other icons

See merge request !116
parents d632b44c 061cc9b7
Loading
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -108,9 +108,9 @@ public class CustomAnalogClock extends View {

    public void setFace(Drawable face) {
        mFace = face;
        mSizeChanged = true;
        mDialHeight = mFace.getIntrinsicHeight();
        mDialWidth = mFace.getIntrinsicWidth();
        mSizeChanged = true;
        invalidate();
    }

@@ -155,7 +155,9 @@ public class CustomAnalogClock extends View {
        super.onDraw(canvas);

        final boolean sizeChanged = mSizeChanged;
        if (sizeChanged) {
            mSizeChanged = false;
        }

        final int availW = mRight - mLeft;
        final int availH = mBottom - mTop;
@@ -177,8 +179,11 @@ public class CustomAnalogClock extends View {
        }

        if (sizeChanged) {
            mFace.setBounds(cX - (w / 2), cY - (h / 2), cX + (w / 2), cY
                    + (h / 2));
            // Extend bottom by 1 and top by -1 for proper bounds
            mFace.setBounds(cX - (w / 2),
                    cY - (h / 2) - 1,
                    cX + (w / 2),
                    cY + (h / 2) + 1);
        }


@@ -193,8 +198,26 @@ public class CustomAnalogClock extends View {
    // from AnalogClock.java
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int size = BlissLauncher.getApplication(mContext).getDeviceProfile().iconSizePx;
        setMeasuredDimension(size, size);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        float hScale = 1.0f;
        float vScale = 1.0f;

        if (widthMode != MeasureSpec.UNSPECIFIED && widthSize < mDialWidth) {
            hScale = (float) widthSize / (float) mDialWidth;
        }

        if (heightMode != MeasureSpec.UNSPECIFIED && heightSize < mDialHeight) {
            vScale = (float) heightSize / (float) mDialHeight;
        }

        float scale = Math.min(hScale, vScale);

        setMeasuredDimension(resolveSizeAndState((int) (mDialWidth * scale), widthMeasureSpec, 0),
                resolveSizeAndState((int) (mDialHeight * scale), heightMeasureSpec, 0));
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ public interface DialOverlay {
     * @param h        the height of the canvas
     * @param calendar the desired date/time
     */
    void onDraw(Canvas canvas, int cX, int cY, int w, int h, Calendar calendar,
    void onDraw(Canvas canvas, float cX, float cY, int w, int h, Calendar calendar,
            boolean sizeChanged);

}
+16 −7
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ public class HandsOverlay implements DialOverlay {
    }

    @Override
    public void onDraw(Canvas canvas, int cX, int cY, int w, int h, Calendar calendar,
    public void onDraw(Canvas canvas, float cX, float cY, int w, int h, Calendar calendar,
            boolean sizeChanged) {

        updateHands(calendar);
@@ -89,38 +89,47 @@ public class HandsOverlay implements DialOverlay {
        canvas.restore();
    }

    private void drawMinutes(Canvas canvas, int cX, int cY, int w, int h, Calendar calendar,
    private void drawMinutes(Canvas canvas, float cX, float cY, int w, int h, Calendar calendar,
            boolean sizeChanged) {
        canvas.rotate(mMinRot, cX, cY);

        if (sizeChanged) {
            w = (int) (mMinute.getIntrinsicWidth() * scale);
            h = (int) (mMinute.getIntrinsicHeight() * scale);
            mMinute.setBounds(cX - (w / 2), cY - (h / 2), cX + (w / 2), cY + (h / 2));
            mMinute.setBounds(Math.round(cX - (w / 2f)),
                    Math.round(cY - (h / 2f)),
                    Math.round(cX + (w / 2f)),
                    Math.round(cY + (h / 2f)));
        }
        mMinute.draw(canvas);
    }

    private void drawHours(Canvas canvas, int cX, int cY, int w, int h, Calendar calendar,
    private void drawHours(Canvas canvas, float cX, float cY, int w, int h, Calendar calendar,
            boolean sizeChanged) {
        canvas.rotate(mHourRot, cX, cY);

        if (sizeChanged) {
            w = (int) (mHour.getIntrinsicWidth()* scale);
            h = (int) (mHour.getIntrinsicHeight()* scale);
            mHour.setBounds(cX - (w / 2), cY - (h / 2), cX + (w / 2), cY + (h / 2));
            mHour.setBounds(Math.round(cX - (w / 2f)),
                    Math.round(cY - (h / 2f)),
                    Math.round(cX + (w / 2f)),
                    Math.round(cY + (h / 2f)));
        }
        mHour.draw(canvas);
    }

    private void drawSec(Canvas canvas, int cX, int cY, int w, int h, Calendar calendar,
    private void drawSec(Canvas canvas, float cX, float cY, int w, int h, Calendar calendar,
            boolean sizeChanged) {
        canvas.rotate(mSecRot, cX, cY);

        if (sizeChanged) {
            w = (int) (mSecond.getIntrinsicWidth() * scale);
            h = (int) (mSecond.getIntrinsicHeight() * scale);
            mSecond.setBounds(cX - (w / 2), cY - (h / 2), cX + (w / 2), cY + (h / 2));
            mSecond.setBounds(Math.round(cX - (w / 2f)),
                    Math.round(cY - (h / 2f)),
                    Math.round(cX + (w / 2f)),
                    Math.round(cY + (h / 2f)));
        }
        mSecond.draw(canvas);
    }
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class SquareLinearLayout extends LinearLayout {

        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        int size = width < height ? width : height;
        int size = Math.min(width, height);
        setMeasuredDimension(size, size);
    }
}