From 0b53d77018913fecac1319242b60e57a8ce3cbf0 Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Mon, 22 Jan 2024 19:13:00 +0600 Subject: [PATCH 1/3] fix: Improve Calendar's monthly view UI Position day names in center of each day cell. Center day numbers and today circle in month view. With "Show week numbers" setting turned on, the day numbers are shifted right in the cell. Update text size and circle radius to match with UI. --- res/layout-sw600dp/full_month_header.xml | 50 +++++++++------- res/layout/full_month_header.xml | 57 +++++++++++-------- res/layout/mini_month_header.xml | 8 +++ res/values/dimens.xml | 6 +- res/values/styles.xml | 1 - .../calendar/month/MonthWeekEventsView.java | 45 ++++++++++----- 6 files changed, 104 insertions(+), 63 deletions(-) diff --git a/res/layout-sw600dp/full_month_header.xml b/res/layout-sw600dp/full_month_header.xml index fb6cee51f..31985a34e 100644 --- a/res/layout-sw600dp/full_month_header.xml +++ b/res/layout-sw600dp/full_month_header.xml @@ -15,6 +15,7 @@ --> - - - - - - - diff --git a/res/layout/full_month_header.xml b/res/layout/full_month_header.xml index 1c47db985..e4106b7e1 100644 --- a/res/layout/full_month_header.xml +++ b/res/layout/full_month_header.xml @@ -15,70 +15,79 @@ --> - - - - - - - - diff --git a/res/layout/mini_month_header.xml b/res/layout/mini_month_header.xml index 9c3099550..2f9c74f9d 100644 --- a/res/layout/mini_month_header.xml +++ b/res/layout/mini_month_header.xml @@ -15,6 +15,7 @@ --> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 68e8f6195..7d8f93edb 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -14,7 +14,9 @@ limitations under the License. --> - 11sp + 16sp + 16sp + 8dp 8dip 0dip 4dip @@ -56,7 +58,7 @@ 300dp 16dp - 14dp + 15dp 15dp 12dp 5dp diff --git a/res/values/styles.xml b/res/values/styles.xml index e0469620e..a0431e9e7 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -78,7 +78,6 @@ diff --git a/src/com/android/calendar/month/MonthWeekEventsView.java b/src/com/android/calendar/month/MonthWeekEventsView.java index 97cf6899c..a5f6945f2 100644 --- a/src/com/android/calendar/month/MonthWeekEventsView.java +++ b/src/com/android/calendar/month/MonthWeekEventsView.java @@ -501,7 +501,6 @@ public class MonthWeekEventsView extends SimpleWeekView { lines[i++] = mWidth; lines[i++] = 0; - p.setColor(mDaySeparatorInnerColor); p.setStrokeWidth(mDaySeparatorInnerWidth * 4); canvas.drawLines(lines, 0, lines.length, p); @@ -512,7 +511,6 @@ public class MonthWeekEventsView extends SimpleWeekView { // There are mNumDays - 1 vertical lines and 1 horizontal, so the total is mNumDays float[] lines = new float[mNumDays * coordinatesPerLine]; int i = 0; - int y0 = 0; int y1 = mHeight; @@ -627,12 +625,14 @@ public class MonthWeekEventsView extends SimpleWeekView { Time time = new Time(mTimeZone); time.setJulianDay(julianMonday); - int current_date_text_x=getResources().getDimensionPixelSize(R.dimen.current_date_text_x); - int current_date_text_y=getResources().getDimensionPixelSize(R.dimen.current_date_text_y); - int current_date_event_margin=getResources().getDimensionPixelSize(R.dimen.current_date_text_event_margin); + int todayTextY = getResources().getDimensionPixelSize(R.dimen.current_date_text_y); + int todayEventMargin = getResources().getDimensionPixelSize(R.dimen.current_date_text_event_margin); for (; i < numCount; i++) { x = computeDayLeftPosition(i - offset) - (mSidePaddingMonthNumber); + + final float monthNumberTextX = getMonthNumberTextX(x); + if (mHasToday && todayIndex == i) { mMonthNumPaint.setFakeBoldText(isBold = false); if (i + 1 < numCount) { @@ -641,28 +641,29 @@ public class MonthWeekEventsView extends SimpleWeekView { isFocusMonth = !mFocusDay[i + 1]; } mMonthNumPaint.setColor(getContext().getResources().getColor(R.color.colorAccent)); - int current_date_bg_size=getResources().getDimensionPixelSize(R.dimen.current_date_bg_size); + final int todayCircleRadius = getResources().getDimensionPixelSize(R.dimen.current_date_bg_size); //check text width & height to calculate circle cx and cy values Rect bounds = new Rect(); mMonthNumPaint.getTextBounds(mDayNumbers[i], 0, mDayNumbers[i].length(), bounds); - int text_height = bounds.height(); - int text_width = bounds.width(); + int textHeight = bounds.height(); + final int todayCircleCenterY = y + todayTextY - (textHeight / 2) - todayEventMargin; - canvas.drawCircle(x - current_date_text_x - (text_width / 2), - y + current_date_text_y - (text_height / 2) - current_date_event_margin, - current_date_bg_size, mMonthNumPaint); + canvas.drawCircle(monthNumberTextX, + todayCircleCenterY, + todayCircleRadius, mMonthNumPaint); mMonthNumPaint.setColor(mMonthNumTodayColor); } else if (mFocusDay[i] != isFocusMonth) { isFocusMonth = mFocusDay[i]; mMonthNumPaint.setColor(isFocusMonth ? mMonthNumColor : mMonthNumOtherColor); } - double relation = Math.sqrt(canvas.getWidth() * canvas.getHeight()); - mMonthNumPaint.setTextSize((int)relation / 12); - canvas.drawText(mDayNumbers[i], x-current_date_text_x, - y+current_date_text_y - current_date_event_margin, mMonthNumPaint); + mMonthNumPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.day_number_text_size)); + mMonthNumPaint.setTextAlign(Align.CENTER); + + canvas.drawText(mDayNumbers[i], monthNumberTextX, + y + todayTextY - todayEventMargin, mMonthNumPaint); if (isBold) { mMonthNumPaint.setFakeBoldText(isBold = false); } @@ -725,6 +726,20 @@ public class MonthWeekEventsView extends SimpleWeekView { } } + private float getMonthNumberTextX(int x) { + final float monthNumberMarginEnd; + if (mShowWeekNum) { + monthNumberMarginEnd = getMonthNumberMarginEnd(); + } else { + monthNumberMarginEnd = 0; + } + return x - (((float) mWidth / mNumDays) / 2f) + mSidePaddingMonthNumber + monthNumberMarginEnd; + } + + private float getMonthNumberMarginEnd() { + return getResources().getDimensionPixelSize(R.dimen.day_number_margin_end); + } + protected void drawEvents(Canvas canvas) { if (mEvents == null || mEvents.isEmpty()) { return; -- GitLab From a35765bf81350d4658466bd0b5031fa832202e21 Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Thu, 1 Feb 2024 18:31:49 +0600 Subject: [PATCH 2/3] refactor: Resolve to MR feedback A new line before return statement has been added to maintain convention used in Murena. Dimension value updated for w600dp and w960dp resource folders. --- res/values-w600dp-h879dp/dimens.xml | 1 + res/values-w960dp-h527dp/dimens.xml | 1 + src/com/android/calendar/month/MonthWeekEventsView.java | 1 + 3 files changed, 3 insertions(+) diff --git a/res/values-w600dp-h879dp/dimens.xml b/res/values-w600dp-h879dp/dimens.xml index 26130deaf..7ee6d6712 100644 --- a/res/values-w600dp-h879dp/dimens.xml +++ b/res/values-w600dp-h879dp/dimens.xml @@ -16,6 +16,7 @@ 14sp + 16sp 10dip 0dip 6dip diff --git a/res/values-w960dp-h527dp/dimens.xml b/res/values-w960dp-h527dp/dimens.xml index 74da6a97a..60229d015 100644 --- a/res/values-w960dp-h527dp/dimens.xml +++ b/res/values-w960dp-h527dp/dimens.xml @@ -16,6 +16,7 @@ 14sp + 16sp 10dip 0dip 6dip diff --git a/src/com/android/calendar/month/MonthWeekEventsView.java b/src/com/android/calendar/month/MonthWeekEventsView.java index a5f6945f2..7d4eb9962 100644 --- a/src/com/android/calendar/month/MonthWeekEventsView.java +++ b/src/com/android/calendar/month/MonthWeekEventsView.java @@ -733,6 +733,7 @@ public class MonthWeekEventsView extends SimpleWeekView { } else { monthNumberMarginEnd = 0; } + return x - (((float) mWidth / mNumDays) / 2f) + mSidePaddingMonthNumber + monthNumberMarginEnd; } -- GitLab From 093d2816a3bcb5c9cf63bbb8af0f090e7bed4a6f Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Mon, 22 Jan 2024 19:13:00 +0600 Subject: [PATCH 3/3] refactor: Update text size Calendar's day label (e.g. SAT, SUN etc.) text size is updated to 16sp to match the design. --- res/values-w600dp-h879dp/dimens.xml | 2 +- res/values-w960dp-h527dp/dimens.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/res/values-w600dp-h879dp/dimens.xml b/res/values-w600dp-h879dp/dimens.xml index 7ee6d6712..2786d5ab9 100644 --- a/res/values-w600dp-h879dp/dimens.xml +++ b/res/values-w600dp-h879dp/dimens.xml @@ -15,7 +15,7 @@ --> - 14sp + 16sp 16sp 10dip 0dip diff --git a/res/values-w960dp-h527dp/dimens.xml b/res/values-w960dp-h527dp/dimens.xml index 60229d015..09e4a0f95 100644 --- a/res/values-w960dp-h527dp/dimens.xml +++ b/res/values-w960dp-h527dp/dimens.xml @@ -15,7 +15,7 @@ --> - 14sp + 16sp 16sp 10dip 0dip -- GitLab