Search in sources :

Example 1 with CompactCalendarView

use of com.github.sundeepk.compactcalendarview.CompactCalendarView 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)

Aggregations

View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)1 Event (com.github.sundeepk.compactcalendarview.domain.Event)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Locale (java.util.Locale)1 TimeZone (java.util.TimeZone)1