Merge pull request #197 from Progern/AD_fix_landscape_years_view

Fixed tablet bug and current day bug
This commit is contained in:
Tibor Kaputa 2017-08-24 14:44:03 +02:00 committed by GitHub
commit 2c422d716d
5 changed files with 373 additions and 30 deletions

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.calendar.views
import android.content.Context
import android.content.res.Configuration
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
@ -61,7 +62,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = mTextColor
textSize = resources.getDimensionPixelSize(R.dimen.tiny_text_size).toFloat()
textSize = resources.getDimensionPixelSize(R.dimen.year_view_day_text_size).toFloat()
textAlign = Paint.Align.RIGHT
}
@ -72,17 +73,19 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (mDayWidth == 0f) {
mDayWidth = (canvas.width / 7).toFloat()
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
mDayWidth = (canvas.width / 9.2).toFloat()
} else mDayWidth = (canvas.width / 8).toFloat()
}
var curId = 1 - mFirstDay
for (y in 1..6) {
for (x in 1..7) {
if (curId > 0 && curId <= mDays) {
if (curId in 1..mDays) {
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, getPaint(curId))
if (curId == mTodaysId) {
canvas.drawCircle(x * mDayWidth - mDayWidth / 4, y * mDayWidth - mDayWidth / 4, mDayWidth * 0.41f, mColoredPaint)
canvas.drawCircle(x * mDayWidth - mDayWidth / 7, y * mDayWidth - mDayWidth / 6, mDayWidth * 0.41f, mColoredPaint)
}
}
curId++

View File

@ -0,0 +1,331 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendar_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/yearly_padding_side">
<TableRow android:layout_weight="1">
<RelativeLayout
android:id="@+id/month_1_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/yearly_padding_full"
android:layout_marginRight="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_1_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/january"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month_1_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_2_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_half"
android:layout_marginRight="@dimen/yearly_padding_half"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_2_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/february"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month_2_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_3_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_3_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/march"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month_3_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_4_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_4_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/april"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_4_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding"
app:days="30" />
</RelativeLayout>
</TableRow>
<TableRow android:layout_weight="1">
<RelativeLayout
android:id="@+id/month_5_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_half"
android:layout_marginRight="@dimen/yearly_padding_half"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_5_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/may"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_5_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_6_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_6_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/june"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_6_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding"
app:days="30" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_7_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_7_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/july"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_7_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_8_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_half"
android:layout_marginRight="@dimen/yearly_padding_half"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_8_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/august"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_8_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
</TableRow>
<TableRow android:layout_weight="1">
<RelativeLayout
android:id="@+id/month_9_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_9_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/september"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_9_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding"
app:days="30" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_10_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_10_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/october"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_10_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_11_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_half"
android:layout_marginRight="@dimen/yearly_padding_half"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_11_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/november"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_11_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding"
app:days="30" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/month_12_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/yearly_padding_full"
android:layout_weight="1">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_12_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/december"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_12_label"
android:layout_marginLeft="@dimen/yearly_month_left_padding"
android:layout_marginStart="@dimen/yearly_month_left_padding" />
</RelativeLayout>
</TableRow>
</TableLayout>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendar_holder"
android:layout_width="match_parent"
@ -23,13 +22,13 @@
android:gravity="center_horizontal"
android:text="@string/january"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month_1_label"/>
android:layout_below="@+id/month_1_label" />
</RelativeLayout>
@ -48,13 +47,13 @@
android:gravity="center_horizontal"
android:text="@string/february"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month_2_label"/>
android:layout_below="@+id/month_2_label" />
</RelativeLayout>
@ -72,13 +71,13 @@
android:gravity="center_horizontal"
android:text="@string/march"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/month_3_label"/>
android:layout_below="@+id/month_3_label" />
</RelativeLayout>
</TableRow>
@ -98,14 +97,14 @@
android:gravity="center_horizontal"
android:text="@string/april"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_4_label"
app:days="30"/>
app:days="30" />
</RelativeLayout>
<RelativeLayout
@ -123,13 +122,13 @@
android:gravity="center_horizontal"
android:text="@string/may"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_5_label"/>
android:layout_below="@+id/month_5_label" />
</RelativeLayout>
@ -147,14 +146,14 @@
android:gravity="center_horizontal"
android:text="@string/june"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_6_label"
app:days="30"/>
app:days="30" />
</RelativeLayout>
</TableRow>
@ -174,13 +173,13 @@
android:gravity="center_horizontal"
android:text="@string/july"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_7_label"/>
android:layout_below="@+id/month_7_label" />
</RelativeLayout>
<RelativeLayout
@ -198,13 +197,13 @@
android:gravity="center_horizontal"
android:text="@string/august"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_8_label"/>
android:layout_below="@+id/month_8_label" />
</RelativeLayout>
<RelativeLayout
@ -221,14 +220,14 @@
android:gravity="center_horizontal"
android:text="@string/september"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_9_label"
app:days="30"/>
app:days="30" />
</RelativeLayout>
</TableRow>
@ -248,13 +247,13 @@
android:gravity="center_horizontal"
android:text="@string/october"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_10_label"/>
android:layout_below="@+id/month_10_label" />
</RelativeLayout>
<RelativeLayout
@ -272,14 +271,14 @@
android:gravity="center_horizontal"
android:text="@string/november"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_11_label"
app:days="30"/>
app:days="30" />
</RelativeLayout>
<RelativeLayout
@ -296,13 +295,13 @@
android:gravity="center_horizontal"
android:text="@string/december"
android:textAllCaps="true"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size" />
<com.simplemobiletools.calendar.views.SmallMonthView
android:id="@+id/month_12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_12_label"/>
android:layout_below="@+id/month_12_label" />
</RelativeLayout>
</TableRow>
</TableLayout>

View File

@ -9,7 +9,12 @@
<dimen name="weekly_view_events_height">2160dp</dimen> <!-- weekly_view_row_height * 24 hours -->
<dimen name="weekly_view_minimal_event_height">15dp</dimen>
<dimen name="yearly_month_left_padding">40dp</dimen>
<dimen name="yearly_month_right_padding">40dp</dimen>
<dimen name="meta_text_size">20sp</dimen>
<dimen name="day_text_size">22sp</dimen>
<dimen name="month_text_size">26sp</dimen>
<dimen name="year_view_day_text_size">12sp</dimen>
</resources>

View File

@ -15,7 +15,12 @@
<dimen name="repeat_type_margin_start">40dp</dimen>
<dimen name="yearly_month_left_padding">40dp</dimen>
<dimen name="yearly_month_right_padding">40dp</dimen>
<dimen name="meta_text_size">14sp</dimen>
<dimen name="day_text_size">17sp</dimen>
<dimen name="month_text_size">22sp</dimen>
<dimen name="year_view_day_text_size">8sp</dimen>
</resources>