-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCalendarWeekView.java
More file actions
93 lines (73 loc) · 2.82 KB
/
Copy pathCalendarWeekView.java
File metadata and controls
93 lines (73 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.androidcalendar.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.GridLayout;
import android.widget.TextView;
import com.androidcalendar.R;
import com.androidcalendar.objects.CalendarDate;
import com.androidcalendar.objects.CalendarWeek;
import com.androidcalendar.utils.Utils;
public class CalendarWeekView extends FrameLayout {
private GridLayout mGridLayout;
private ViewGroup mLayoutDays;
public CalendarWeekView(Context context) {
super(context);
init();
}
public CalendarWeekView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CalendarWeekView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
inflate(getContext(), R.layout.view_calendar_month, this);
mGridLayout = (GridLayout) findViewById(R.id.view_calendar_month_grid);
mLayoutDays = (ViewGroup) findViewById(R.id.view_calendar_month_layout_days);
}
public void buildView(CalendarWeek calendarWeek) {
buildDaysLayout();
buildGridView(calendarWeek);
}
private void buildDaysLayout() {
String[] days;
days = getResources().getStringArray(R.array.days_sunday_array);
for (int i = 0; i < mLayoutDays.getChildCount(); i++) {
TextView textView = (TextView) mLayoutDays.getChildAt(i);
textView.setText(days[i]);
}
}
private void buildGridView(CalendarWeek calendarWeek) {
int row = CalendarWeek.NUMBER_OF_WEEKS_IN_WEEK;
int col = CalendarWeek.NUMBER_OF_DAYS_IN_WEEK;
mGridLayout.setRowCount(row);
mGridLayout.setColumnCount(col);
int screenWidth = Utils.getScreenWidth(getContext());
int width = screenWidth / col;
for (CalendarDate day : calendarWeek.getDays()) {
CalendarDayView dayView = new CalendarDayView(getContext(), day);
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.width = width;
params.height = LayoutParams.WRAP_CONTENT;
dayView.setLayoutParams(params);
dayView.setTextDay("" + day.getDay());
decorateDayView(dayView, day, calendarWeek.getMonth());
mGridLayout.addView(dayView);
}
}
protected void decorateDayView(CalendarDayView dayView, CalendarDate day, int month) {
// if (day.getMonth() != month) {
// dayView.setOtherMothTextColor();
// } else {
// dayView.setThisMothTextColor();
// }
dayView.setThisMothTextColor();
if (day.isToday()) {
dayView.setPurpleSolidOvalBackground();
}
}
}