Search in sources :

Example 21 with Event

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()));
}
Also used : ArrayList(java.util.ArrayList) Event(com.github.sundeepk.compactcalendarview.domain.Event) Date(java.util.Date)

Example 22 with Event

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;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) View(android.view.View) ListView(android.widget.ListView) CompactCalendarView(com.github.sundeepk.compactcalendarview.CompactCalendarView) CompactCalendarView(com.github.sundeepk.compactcalendarview.CompactCalendarView) Date(java.util.Date) TimeZone(java.util.TimeZone) ListView(android.widget.ListView) Button(android.widget.Button) Event(com.github.sundeepk.compactcalendarview.domain.Event) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) ArrayAdapter(android.widget.ArrayAdapter)

Example 23 with Event

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);
    }
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Date(java.util.Date)

Aggregations

Event (com.github.sundeepk.compactcalendarview.domain.Event)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 MotionEvent (android.view.MotionEvent)5 Calendar (java.util.Calendar)5 Date (java.util.Date)3 List (java.util.List)3 Paint (android.graphics.Paint)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 CompactCalendarHelper.getMultipleEventsForEachDayAsMap (com.github.sundeepk.compactcalendarview.CompactCalendarHelper.getMultipleEventsForEachDayAsMap)1 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Random (java.util.Random)1 TimeZone (java.util.TimeZone)1