Back to project page android-times-square.
The source code is released under:
Apache License
If you think the Android project android-times-square listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
// Copyright 2012 Square, Inc. package com.squareup.timessquare; /*from w ww . j a v a 2s . c om*/ import android.content.Context; import android.graphics.Typeface; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import java.text.DateFormat; import java.util.Calendar; import java.util.List; public class MonthView extends LinearLayout { TextView title; CalendarGridView grid; private Listener listener; public static MonthView create(ViewGroup parent, LayoutInflater inflater, DateFormat weekdayNameFormat, Listener listener, Calendar today, int dividerColor, int dayBackgroundResId, int dayTextColorResId, int titleTextColor, boolean displayHeader, int headerTextColor) { final MonthView view = (MonthView) inflater.inflate(R.layout.month, parent, false); view.setDividerColor(dividerColor); view.setDayTextColor(dayTextColorResId); view.setTitleTextColor(titleTextColor); view.setDisplayHeader(displayHeader); view.setHeaderTextColor(headerTextColor); if (dayBackgroundResId != 0) { view.setDayBackground(dayBackgroundResId); } final int originalDayOfWeek = today.get(Calendar.DAY_OF_WEEK); int firstDayOfWeek = today.getFirstDayOfWeek(); final CalendarRowView headerRow = (CalendarRowView) view.grid.getChildAt(0); for (int offset = 0; offset < 7; offset++) { today.set(Calendar.DAY_OF_WEEK, firstDayOfWeek + offset); final TextView textView = (TextView) headerRow.getChildAt(offset); textView.setText(weekdayNameFormat.format(today.getTime())); } today.set(Calendar.DAY_OF_WEEK, originalDayOfWeek); view.listener = listener; return view; } public MonthView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onFinishInflate() { super.onFinishInflate(); title = (TextView) findViewById(R.id.title); grid = (CalendarGridView) findViewById(R.id.calendar_grid); } public void init(MonthDescriptor month, List<List<MonthCellDescriptor>> cells, boolean displayOnly, Typeface titleTypeface, Typeface dateTypeface) { Logr.d("Initializing MonthView (%d) for %s", System.identityHashCode(this), month); long start = System.currentTimeMillis(); title.setText(month.getLabel()); final int numRows = cells.size(); grid.setNumRows(numRows); for (int i = 0; i < 6; i++) { CalendarRowView weekRow = (CalendarRowView) grid.getChildAt(i + 1); weekRow.setListener(listener); if (i < numRows) { weekRow.setVisibility(VISIBLE); List<MonthCellDescriptor> week = cells.get(i); for (int c = 0; c < week.size(); c++) { MonthCellDescriptor cell = week.get(c); CalendarCellView cellView = (CalendarCellView) weekRow.getChildAt(c); String cellDate = Integer.toString(cell.getValue()); if (!cellView.getText().equals(cellDate)) { cellView.setText(cellDate); } cellView.setEnabled(cell.isCurrentMonth()); cellView.setClickable(!displayOnly); cellView.setSelectable(cell.isSelectable()); cellView.setSelected(cell.isSelected()); cellView.setCurrentMonth(cell.isCurrentMonth()); cellView.setToday(cell.isToday()); cellView.setRangeState(cell.getRangeState()); cellView.setHighlighted(cell.isHighlighted()); cellView.setTag(cell); } } else { weekRow.setVisibility(GONE); } } if (titleTypeface != null) { title.setTypeface(titleTypeface); } if (dateTypeface != null) { grid.setTypeface(dateTypeface); } Logr.d("MonthView.init took %d ms", System.currentTimeMillis() - start); } public void setDividerColor(int color) { grid.setDividerColor(color); } public void setDayBackground(int resId) { grid.setDayBackground(resId); } public void setDayTextColor(int resId) { grid.setDayTextColor(resId); } public void setTitleTextColor(int color) { title.setTextColor(color); } public void setDisplayHeader(boolean displayHeader) { grid.setDisplayHeader(displayHeader); } public void setHeaderTextColor(int color) { grid.setHeaderTextColor(color); } public interface Listener { void handleClick(MonthCellDescriptor cell); } }