use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.
the class CompactCalendarTab method logEventsByMonth.
private void logEventsByMonth(CompactCalendarView compactCalendarView) {
currentCalender.setTime(new Date());
currentCalender.set(Calendar.DAY_OF_MONTH, 1);
currentCalender.set(Calendar.MONTH, Calendar.AUGUST);
List<String> dates = new ArrayList<>();
for (Event e : compactCalendarView.getEventsForMonth(new Date())) {
dates.add(dateFormatForDisplaying.format(e.getTimeInMillis()));
}
Log.d(TAG, "Events for Aug with simple date formatter: " + dates);
Log.d(TAG, "Events for Aug month using default local and timezone: " + compactCalendarView.getEventsForMonth(currentCalender.getTime()));
}
use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.
the class CompactCalendarTab method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.main_tab, container, false);
final List<String> mutableBookings = new ArrayList<>();
final ListView bookingsListView = (ListView) v.findViewById(R.id.bookings_listview);
final Button showPreviousMonthBut = (Button) v.findViewById(R.id.prev_button);
final Button showNextMonthBut = (Button) v.findViewById(R.id.next_button);
final Button slideCalendarBut = (Button) v.findViewById(R.id.slide_calendar);
final Button showCalendarWithAnimationBut = (Button) v.findViewById(R.id.show_with_animation_calendar);
final Button setLocaleBut = (Button) v.findViewById(R.id.set_locale);
final Button removeAllEventsBut = (Button) v.findViewById(R.id.remove_all_events);
final ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, mutableBookings);
bookingsListView.setAdapter(adapter);
compactCalendarView = (CompactCalendarView) v.findViewById(R.id.compactcalendar_view);
// below allows you to configure color for the current day in the month
// compactCalendarView.setCurrentDayBackgroundColor(getResources().getColor(R.color.black));
// below allows you to configure colors for the current day the user has selected
// compactCalendarView.setCurrentSelectedDayBackgroundColor(getResources().getColor(R.color.dark_red));
compactCalendarView.setUseThreeLetterAbbreviation(false);
compactCalendarView.setFirstDayOfWeek(Calendar.MONDAY);
loadEvents();
loadEventsForYear(2017);
compactCalendarView.invalidate();
logEventsByMonth(compactCalendarView);
// below line will display Sunday as the first day of the week
// compactCalendarView.setShouldShowMondayAsFirstDay(false);
// disable scrolling calendar
// compactCalendarView.shouldScrollMonth(false);
// show days from other months as greyed out days
// compactCalendarView.displayOtherMonthDays(true);
// show Sunday as first day of month
// compactCalendarView.setShouldShowMondayAsFirstDay(false);
//set initial title
toolbar = ((ActionBarActivity) getActivity()).getSupportActionBar();
toolbar.setTitle(dateFormatForMonth.format(compactCalendarView.getFirstDayOfCurrentMonth()));
//set title on calendar scroll
compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
toolbar.setTitle(dateFormatForMonth.format(dateClicked));
List<Event> bookingsFromMap = compactCalendarView.getEvents(dateClicked);
Log.d(TAG, "inside onclick " + dateFormatForDisplaying.format(dateClicked));
if (bookingsFromMap != null) {
Log.d(TAG, bookingsFromMap.toString());
mutableBookings.clear();
for (Event booking : bookingsFromMap) {
mutableBookings.add((String) booking.getData());
}
adapter.notifyDataSetChanged();
}
}
@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
toolbar.setTitle(dateFormatForMonth.format(firstDayOfNewMonth));
}
});
showPreviousMonthBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
compactCalendarView.showPreviousMonth();
}
});
showNextMonthBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
compactCalendarView.showNextMonth();
}
});
final View.OnClickListener showCalendarOnClickLis = getCalendarShowLis();
slideCalendarBut.setOnClickListener(showCalendarOnClickLis);
final View.OnClickListener exposeCalendarListener = getCalendarExposeLis();
showCalendarWithAnimationBut.setOnClickListener(exposeCalendarListener);
compactCalendarView.setAnimationListener(new CompactCalendarView.CompactCalendarAnimationListener() {
@Override
public void onOpened() {
}
@Override
public void onClosed() {
}
});
setLocaleBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Locale locale = Locale.FRANCE;
dateFormatForDisplaying = new SimpleDateFormat("dd-M-yyyy hh:mm:ss a", locale);
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
dateFormatForDisplaying.setTimeZone(timeZone);
dateFormatForMonth.setTimeZone(timeZone);
compactCalendarView.setLocale(timeZone, locale);
compactCalendarView.setUseThreeLetterAbbreviation(false);
loadEvents();
loadEventsForYear(2017);
logEventsByMonth(compactCalendarView);
}
});
removeAllEventsBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
compactCalendarView.removeAllEvents();
}
});
return v;
}
use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.
the class CompactCalendarTab method addEvents.
private void addEvents(int month, int year) {
currentCalender.setTime(new Date());
currentCalender.set(Calendar.DAY_OF_MONTH, 1);
Date firstDayOfMonth = currentCalender.getTime();
for (int i = 0; i < 6; i++) {
currentCalender.setTime(firstDayOfMonth);
if (month > -1) {
currentCalender.set(Calendar.MONTH, month);
}
if (year > -1) {
currentCalender.set(Calendar.ERA, GregorianCalendar.AD);
currentCalender.set(Calendar.YEAR, year);
}
currentCalender.add(Calendar.DATE, i);
setToMidnight(currentCalender);
long timeInMillis = currentCalender.getTimeInMillis();
List<Event> events = getEvents(timeInMillis, i);
compactCalendarView.addEvents(events);
}
}
Aggregations