public
class
CalendarView
extends
ViewGroup {
private
final
String TAG =
"TIME"
;
private
final
int
mScreenWidth;
private
final
int
mWidthDate;
private
long
mMillis;
private
int
mDateOfWeek;
private
int
mMaxtDateOfMonth;
private
int
mDefaultTextSize =
40
;
public
static
String[] DAY_OF_WEEK;
public
CalendarView(Context context, AttributeSet attrs) {
super
(context, attrs);
mScreenWidth = getResources().getDisplayMetrics().widthPixels;
mWidthDate = mScreenWidth /
7
;
}
@Override
protected
void
onMeasure(
int
widthMeasureSpec,
int
heightMeasureSpec) {
int
count = getChildCount();
int
maxHeight =
0
;
int
maxWidth =
0
;
int
childState =
0
;
int
mLeftWidth =
0
;
int
rowCount =
0
;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mMillis);
Log.d(
"TAG"
,
"setTimeInMillis : "
+ calendar);
for
(
int
i =
0
; i < count; i++) {
final
View child = getChildAt(i);
if
(child.getVisibility() == GONE)
continue
;
measureChild(child, widthMeasureSpec, heightMeasureSpec);
maxWidth += Math.max(maxWidth, child.getMeasuredHeight());
mLeftWidth += child.getMeasuredWidth();
if
((mLeftWidth / mScreenWidth) > rowCount) {
maxHeight += child.getMeasuredHeight();
rowCount++;
}
else
{
maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
}
childState = combineMeasuredStates(childState, child.getMeasuredState());
}
maxHeight = (
int
) (Math.ceil((count + mDateOfWeek -
1
) / 7d) * (mWidthDate *
0.75
));
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
int
expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, expandSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}