Skip to content

Commit e1f49e8

Browse files
committed
Use a scrollview for the months in the year view when in horizontal orientation.
1 parent 7165bae commit e1f49e8

File tree

4 files changed

+126
-157
lines changed

4 files changed

+126
-157
lines changed

app/src/main/kotlin/org/fossify/calendar/views/SmallMonthView.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.fossify.calendar.views
22

33
import android.content.Context
4-
import android.content.res.Configuration
54
import android.graphics.Canvas
65
import android.graphics.Paint
76
import android.util.AttributeSet
@@ -24,7 +23,6 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
2423
private var textColor = 0
2524
private var weekendsTextColor = 0
2625
private var days = 31
27-
private var isLandscape = false
2826
private var highlightWeekends = false
2927
private var isPrintVersion = false
3028
private var mEvents: ArrayList<DayYearly>? = null
@@ -71,18 +69,13 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
7169

7270
todayCirclePaint = Paint(paint)
7371
todayCirclePaint.color = context.getProperPrimaryColor().adjustAlpha(MEDIUM_ALPHA)
74-
isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
7572
}
7673

7774
override fun onDraw(canvas: Canvas) {
7875
super.onDraw(canvas)
7976

8077
if (dayWidth == 0f) {
81-
dayWidth = if (isLandscape) {
82-
width / 9f
83-
} else {
84-
width / 7f
85-
}
78+
dayWidth = width / 7f
8679
}
8780

8881
val fm = paint.fontMetrics
@@ -107,6 +100,17 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
107100
}
108101
}
109102

103+
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
104+
val desiredDaySize = resources.getDimensionPixelSize(R.dimen.year_view_day_text_size) * 2
105+
val desiredWidth = desiredDaySize * 7
106+
val desiredHeight = desiredDaySize * 6
107+
108+
val resolvedWidth = resolveSize(desiredWidth, widthMeasureSpec)
109+
val resolvedHeight = resolveSize(desiredHeight, heightMeasureSpec)
110+
111+
setMeasuredDimension(resolvedWidth, resolvedHeight)
112+
}
113+
110114
private fun getPaint(curId: Int, weekDay: Int, highlightWeekends: Boolean): Paint {
111115
val colors = mEvents?.get(curId)?.eventColors ?: HashSet()
112116
if (colors.isNotEmpty()) {

app/src/main/res/layout-land/fragment_year.xml

Lines changed: 108 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,134 +6,126 @@
66

77
<include layout="@layout/top_navigation" />
88

9-
<GridLayout
10-
android:id="@+id/calendar_wrapper"
9+
<ScrollView
1110
android:layout_width="match_parent"
1211
android:layout_height="match_parent"
13-
android:layout_below="@+id/top_left_arrow"
14-
android:columnCount="4"
15-
android:padding="@dimen/yearly_padding_side"
16-
android:rowCount="3">
12+
android:layout_below="@+id/top_left_arrow">
1713

18-
<include
19-
android:id="@+id/month_1_holder"
20-
layout="@layout/small_month_view_holder"
21-
android:layout_width="0dp"
22-
android:layout_height="0dp"
23-
android:layout_rowWeight="1"
24-
android:layout_columnWeight="1"
25-
android:layout_marginStart="@dimen/yearly_padding_half"
26-
android:layout_marginEnd="@dimen/yearly_padding_half" />
14+
<GridLayout
15+
android:id="@+id/calendar_wrapper"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:columnCount="4"
19+
android:padding="@dimen/yearly_padding_half"
20+
android:rowCount="3">
2721

28-
<include
29-
android:id="@+id/month_2_holder"
30-
layout="@layout/small_month_view_holder"
31-
android:layout_width="0dp"
32-
android:layout_height="0dp"
33-
android:layout_rowWeight="1"
34-
android:layout_columnWeight="1"
35-
android:layout_marginStart="@dimen/yearly_padding_half"
36-
android:layout_marginEnd="@dimen/yearly_padding_half" />
22+
<include
23+
android:id="@+id/month_1_holder"
24+
layout="@layout/small_month_view_holder"
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_rowWeight="1"
28+
android:layout_columnWeight="1"
29+
android:layout_margin="@dimen/yearly_padding_half" />
3730

38-
<include
39-
android:id="@+id/month_3_holder"
40-
layout="@layout/small_month_view_holder"
41-
android:layout_width="0dp"
42-
android:layout_height="0dp"
43-
android:layout_rowWeight="1"
44-
android:layout_columnWeight="1"
45-
android:layout_marginStart="@dimen/yearly_padding_half"
46-
android:layout_marginEnd="@dimen/yearly_padding_half" />
31+
<include
32+
android:id="@+id/month_2_holder"
33+
layout="@layout/small_month_view_holder"
34+
android:layout_width="0dp"
35+
android:layout_height="wrap_content"
36+
android:layout_rowWeight="1"
37+
android:layout_columnWeight="1"
38+
android:layout_margin="@dimen/yearly_padding_half" />
4739

48-
<include
49-
android:id="@+id/month_4_holder"
50-
layout="@layout/small_month_view_holder"
51-
android:layout_width="0dp"
52-
android:layout_height="0dp"
53-
android:layout_rowWeight="1"
54-
android:layout_columnWeight="1"
55-
android:layout_marginStart="@dimen/yearly_padding_half"
56-
android:layout_marginEnd="@dimen/yearly_padding_half" />
40+
<include
41+
android:id="@+id/month_3_holder"
42+
layout="@layout/small_month_view_holder"
43+
android:layout_width="0dp"
44+
android:layout_height="wrap_content"
45+
android:layout_rowWeight="1"
46+
android:layout_columnWeight="1"
47+
android:layout_margin="@dimen/yearly_padding_half" />
5748

58-
<include
59-
android:id="@+id/month_5_holder"
60-
layout="@layout/small_month_view_holder"
61-
android:layout_width="0dp"
62-
android:layout_height="0dp"
63-
android:layout_rowWeight="1"
64-
android:layout_columnWeight="1"
65-
android:layout_marginStart="@dimen/yearly_padding_half"
66-
android:layout_marginEnd="@dimen/yearly_padding_half" />
49+
<include
50+
android:id="@+id/month_4_holder"
51+
layout="@layout/small_month_view_holder"
52+
android:layout_width="0dp"
53+
android:layout_height="wrap_content"
54+
android:layout_rowWeight="1"
55+
android:layout_columnWeight="1"
56+
android:layout_margin="@dimen/yearly_padding_half" />
6757

68-
<include
69-
android:id="@+id/month_6_holder"
70-
layout="@layout/small_month_view_holder"
71-
android:layout_width="0dp"
72-
android:layout_height="0dp"
73-
android:layout_rowWeight="1"
74-
android:layout_columnWeight="1"
75-
android:layout_marginStart="@dimen/yearly_padding_half"
76-
android:layout_marginEnd="@dimen/yearly_padding_half" />
58+
<include
59+
android:id="@+id/month_5_holder"
60+
layout="@layout/small_month_view_holder"
61+
android:layout_width="0dp"
62+
android:layout_height="wrap_content"
63+
android:layout_rowWeight="1"
64+
android:layout_columnWeight="1"
65+
android:layout_margin="@dimen/yearly_padding_half" />
7766

78-
<include
79-
android:id="@+id/month_7_holder"
80-
layout="@layout/small_month_view_holder"
81-
android:layout_width="0dp"
82-
android:layout_height="0dp"
83-
android:layout_rowWeight="1"
84-
android:layout_columnWeight="1"
85-
android:layout_marginStart="@dimen/yearly_padding_half"
86-
android:layout_marginEnd="@dimen/yearly_padding_half" />
67+
<include
68+
android:id="@+id/month_6_holder"
69+
layout="@layout/small_month_view_holder"
70+
android:layout_width="0dp"
71+
android:layout_height="wrap_content"
72+
android:layout_rowWeight="1"
73+
android:layout_columnWeight="1"
74+
android:layout_margin="@dimen/yearly_padding_half" />
8775

88-
<include
89-
android:id="@+id/month_8_holder"
90-
layout="@layout/small_month_view_holder"
91-
android:layout_width="0dp"
92-
android:layout_height="0dp"
93-
android:layout_rowWeight="1"
94-
android:layout_columnWeight="1"
95-
android:layout_marginStart="@dimen/yearly_padding_half"
96-
android:layout_marginEnd="@dimen/yearly_padding_half" />
76+
<include
77+
android:id="@+id/month_7_holder"
78+
layout="@layout/small_month_view_holder"
79+
android:layout_width="0dp"
80+
android:layout_height="wrap_content"
81+
android:layout_rowWeight="1"
82+
android:layout_columnWeight="1"
83+
android:layout_margin="@dimen/yearly_padding_half" />
9784

98-
<include
99-
android:id="@+id/month_9_holder"
100-
layout="@layout/small_month_view_holder"
101-
android:layout_width="0dp"
102-
android:layout_height="0dp"
103-
android:layout_rowWeight="1"
104-
android:layout_columnWeight="1"
105-
android:layout_marginStart="@dimen/yearly_padding_half"
106-
android:layout_marginTop="0dp"
107-
android:layout_marginEnd="@dimen/yearly_padding_half" />
85+
<include
86+
android:id="@+id/month_8_holder"
87+
layout="@layout/small_month_view_holder"
88+
android:layout_width="0dp"
89+
android:layout_height="wrap_content"
90+
android:layout_rowWeight="1"
91+
android:layout_columnWeight="1"
92+
android:layout_margin="@dimen/yearly_padding_half" />
10893

109-
<include
110-
android:id="@+id/month_10_holder"
111-
layout="@layout/small_month_view_holder"
112-
android:layout_width="0dp"
113-
android:layout_height="0dp"
114-
android:layout_rowWeight="1"
115-
android:layout_columnWeight="1"
116-
android:layout_marginStart="@dimen/yearly_padding_half"
117-
android:layout_marginEnd="@dimen/yearly_padding_half" />
94+
<include
95+
android:id="@+id/month_9_holder"
96+
layout="@layout/small_month_view_holder"
97+
android:layout_width="0dp"
98+
android:layout_height="wrap_content"
99+
android:layout_rowWeight="1"
100+
android:layout_columnWeight="1"
101+
android:layout_margin="@dimen/yearly_padding_half" />
118102

119-
<include
120-
android:id="@+id/month_11_holder"
121-
layout="@layout/small_month_view_holder"
122-
android:layout_width="0dp"
123-
android:layout_height="0dp"
124-
android:layout_rowWeight="1"
125-
android:layout_columnWeight="1"
126-
android:layout_marginStart="@dimen/yearly_padding_half"
127-
android:layout_marginEnd="@dimen/yearly_padding_half" />
103+
<include
104+
android:id="@+id/month_10_holder"
105+
layout="@layout/small_month_view_holder"
106+
android:layout_width="0dp"
107+
android:layout_height="wrap_content"
108+
android:layout_rowWeight="1"
109+
android:layout_columnWeight="1"
110+
android:layout_margin="@dimen/yearly_padding_half" />
128111

129-
<include
130-
android:id="@+id/month_12_holder"
131-
layout="@layout/small_month_view_holder"
132-
android:layout_width="0dp"
133-
android:layout_height="0dp"
134-
android:layout_rowWeight="1"
135-
android:layout_columnWeight="1"
136-
android:layout_marginStart="@dimen/yearly_padding_half"
137-
android:layout_marginEnd="@dimen/yearly_padding_half" />
138-
</GridLayout>
112+
<include
113+
android:id="@+id/month_11_holder"
114+
layout="@layout/small_month_view_holder"
115+
android:layout_width="0dp"
116+
android:layout_height="wrap_content"
117+
android:layout_rowWeight="1"
118+
android:layout_columnWeight="1"
119+
android:layout_margin="@dimen/yearly_padding_half" />
120+
121+
<include
122+
android:id="@+id/month_12_holder"
123+
layout="@layout/small_month_view_holder"
124+
android:layout_width="0dp"
125+
android:layout_height="wrap_content"
126+
android:layout_rowWeight="1"
127+
android:layout_columnWeight="1"
128+
android:layout_margin="@dimen/yearly_padding_half" />
129+
</GridLayout>
130+
</ScrollView>
139131
</RelativeLayout>

app/src/main/res/layout-land/small_month_view_holder.xml

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5-
android:layout_marginEnd="@dimen/yearly_padding_full"
6-
android:layout_weight="1">
5+
android:orientation="vertical">
76

87
<TextView
98
android:id="@+id/month_label"
10-
android:layout_width="match_parent"
9+
android:layout_width="wrap_content"
1110
android:layout_height="wrap_content"
12-
android:gravity="center_horizontal"
11+
android:layout_gravity="center_horizontal"
1312
android:text="@string/january"
1413
android:textAllCaps="true"
1514
android:textSize="@dimen/normal_text_size" />
@@ -18,7 +17,5 @@
1817
android:id="@+id/small_month_view"
1918
android:layout_width="wrap_content"
2019
android:layout_height="wrap_content"
21-
android:layout_below="@+id/month_label"
22-
android:layout_centerInParent="true" />
23-
24-
</RelativeLayout>
20+
android:layout_gravity="center_horizontal" />
21+
</LinearLayout>

0 commit comments

Comments
 (0)