From 57da7dc6b41fb3f46d5ea86bdd3b8428e16de8ba Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Thu, 18 Jan 2024 11:57:23 +0600 Subject: [PATCH 1/2] 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. Fix gradle build error caused by presence of package name in AndroidManifest.xml file. --- app/src/main/AndroidManifest.xml | 1 - .../calendar/month/MonthWeekEventsView.java | 46 ++++++++++----- .../res/layout-sw600dp/full_month_header.xml | 50 +++++++++------- app/src/main/res/layout/full_month_header.xml | 58 +++++++++++-------- app/src/main/res/layout/mini_month_header.xml | 8 +++ .../main/res/values-w600dp-h879dp/dimens.xml | 3 +- .../main/res/values-w960dp-h527dp/dimens.xml | 3 +- app/src/main/res/values/dimens.xml | 6 +- app/src/main/res/values/styles.xml | 2 +- 9 files changed, 111 insertions(+), 66 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cd29ea970..896618f92 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,6 @@ --> diff --git a/app/src/main/java/com/android/calendar/month/MonthWeekEventsView.java b/app/src/main/java/com/android/calendar/month/MonthWeekEventsView.java index 42a9da93f..61b761a89 100644 --- a/app/src/main/java/com/android/calendar/month/MonthWeekEventsView.java +++ b/app/src/main/java/com/android/calendar/month/MonthWeekEventsView.java @@ -44,8 +44,6 @@ import android.view.MotionEvent; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; -import androidx.core.content.ContextCompat; - import com.android.calendar.DynamicTheme; import com.android.calendar.Event; import com.android.calendar.LunarUtils; @@ -626,12 +624,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) { @@ -640,28 +640,30 @@ 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); } @@ -724,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; diff --git a/app/src/main/res/layout-sw600dp/full_month_header.xml b/app/src/main/res/layout-sw600dp/full_month_header.xml index fb6cee51f..31985a34e 100644 --- a/app/src/main/res/layout-sw600dp/full_month_header.xml +++ b/app/src/main/res/layout-sw600dp/full_month_header.xml @@ -15,6 +15,7 @@ --> - - - - - - - diff --git a/app/src/main/res/layout/full_month_header.xml b/app/src/main/res/layout/full_month_header.xml index 1c47db985..ceae21629 100644 --- a/app/src/main/res/layout/full_month_header.xml +++ b/app/src/main/res/layout/full_month_header.xml @@ -15,70 +15,80 @@ --> - - - - - - - - diff --git a/app/src/main/res/layout/mini_month_header.xml b/app/src/main/res/layout/mini_month_header.xml index 9c3099550..2f9c74f9d 100644 --- a/app/src/main/res/layout/mini_month_header.xml +++ b/app/src/main/res/layout/mini_month_header.xml @@ -15,6 +15,7 @@ --> diff --git a/app/src/main/res/values-w600dp-h879dp/dimens.xml b/app/src/main/res/values-w600dp-h879dp/dimens.xml index d84c8075f..60d8985c8 100644 --- a/app/src/main/res/values-w600dp-h879dp/dimens.xml +++ b/app/src/main/res/values-w600dp-h879dp/dimens.xml @@ -15,7 +15,8 @@ --> - 14sp + 16sp + 16sp 10dip 0dip 6dip diff --git a/app/src/main/res/values-w960dp-h527dp/dimens.xml b/app/src/main/res/values-w960dp-h527dp/dimens.xml index e2774773b..94f73f8d3 100644 --- a/app/src/main/res/values-w960dp-h527dp/dimens.xml +++ b/app/src/main/res/values-w960dp-h527dp/dimens.xml @@ -15,7 +15,8 @@ --> - 14sp + 16sp + 16sp 10dip 0dip 6dip diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 68e8f6195..7d8f93edb 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/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/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index e0469620e..7ec02b0df 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -78,8 +78,8 @@