Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Overview

Android Week View

Gitter chat

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Features

  • Week view calendar
  • Day view calendar
  • Custom styling
  • Horizontal and vertical scrolling
  • Infinite horizontal scrolling
  • Live preview of custom styling in xml preview window

Who uses it

Usage

  1. Import the library into your project.
  • Grab via maven

    <dependency>
      <groupId>com.github.alamkanak</groupId>
      <artifactId>android-week-view</artifactId>
      <version>1.2.6</version>
      <type>aar</type>
    </dependency>
  • Grab via gradle

    compile 'com.github.alamkanak:android-week-view:1.2.6'
  1. Add WeekView in your xml layout.

    <com.alamkanak.weekview.WeekView
            android:id="@+id/weekView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:eventTextColor="@android:color/white"
            app:textSize="12sp"
            app:hourHeight="60dp"
            app:headerColumnPadding="8dp"
            app:headerColumnTextColor="#8f000000"
            app:headerRowPadding="12dp"
            app:columnGap="8dp"
            app:noOfVisibleDays="3"
            app:headerRowBackgroundColor="#ffefefef"
            app:dayBackgroundColor="#05000000"
            app:todayBackgroundColor="#1848adff"
            app:headerColumnBackground="#ffffffff"/>
  2. Write the following code in your java file.

    // Get a reference for the week view in the layout.
    mWeekView = (WeekView) findViewById(R.id.weekView);
    
    // Set an action when any event is clicked.
    mWeekView.setOnEventClickListener(mEventClickListener);
    
    // The week view has infinite scrolling horizontally. We have to provide the events of a
    // month every time the month changes on the week view.
    mWeekView.setMonthChangeListener(mMonthChangeListener);
    
    // Set long press listener for events.
    mWeekView.setEventLongPressListener(mEventLongPressListener);
  3. Implement WeekView.MonthChangeListener, WeekView.EventClickListener, WeekView.EventLongPressListener according to your need.

  4. Provide the events for the WeekView in WeekView.MonthChangeListener.onMonthChange() callback. Please remember that the calendar pre-loads events of three consecutive months to enable lag-free scrolling.

    MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() {
        @Override
        public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
            // Populate the week view with some events.
            List<WeekViewEvent> events = getEvents(newYear, newMonth);
            return events;
        }
    };

Customization

You can customize the look of the WeekView in xml. Use the following attributes in xml. All these attributes also have getters and setters to enable you to change the style dynamically.

  • allDayEventHeight
  • columnGap
  • dayBackgroundColor
  • dayNameLength
  • eventMarginVertical
  • eventPadding
  • eventTextColor
  • eventTextSize
  • firstDayOfWeek
  • headerColumnBackground
  • headerColumnPadding
  • headerColumnTextColor
  • headerRowBackgroundColor
  • headerRowPadding
  • hourHeight
  • hourSeparatorColor
  • hourSeparatorHeight
  • noOfVisibleDays
  • overlappingEventGap
  • textSize
  • todayBackgroundColor
  • todayHeaderTextColor
  • showDistinctPastFutureColor
  • futureBackgroundColor
  • pastBackgroundColor
  • showDistinctWeekendColor
  • futureWeekendBackgroundColor
  • pastWeekendBackgroundColor
  • showNowLine
  • nowLineColor
  • nowLineThickness
  • scrollDuration

Interfaces

Use the following interfaces according to your need.

  • mWeekView.setWeekViewLoader() to provide events to the calendar
  • mWeekView.setMonthChangeListener() to provide events to the calendar by months
  • mWeekView.setOnEventClickListener() to get a callback when an event is clicked
  • mWeekView.setEventLongPressListener() to get a callback when an event is long pressed
  • mWeekView.setEmptyViewClickListener() to get a callback when any empty space is clicked
  • mWeekView.setEmptyViewLongPressListener() to get a callback when any empty space is long pressed
  • mWeekView.setDateTimeInterpreter() to set your own labels for the calendar header row and header column
  • mWeekView.setScrollListener() to get an event every time the first visible day has changed

Sample

There is also a sample app to get you started.

To do

  • Add event touch feedback selector
  • Show events that expand multiple days properly

Changelog

Version 1.2.6

  • Add empty view click listener
  • Fix padding bug
  • Fix bug when setting colors of different components
  • Add ability to turn off fling gesture
  • Add example of how to load events asynchronously in the sample app

Version 1.2.5

  • Add support for using subclasses of WeekViewEvent
  • Fix scroll animation
  • Add support for semi-transparent header colors

Version 1.2.4

  • NOTE: If you are using WeekView.MonthChangeListener, make sure to change it into MonthLoader.MonthChangeListener
  • Add support to have loaders other than MonthViewLoader
  • Add pinch to zoom support
  • Add support for location
  • Add ability to have different colors for past, future, weekend days
  • Add support for "now" line

Version 1.2.3

  • Get callbacks when scrolling horizontally
  • goToHour and goToDate methods has been fixed
  • Use getFirstVisibleHour method to get the first visible hour in the week view

Version 1.2.1

  • Better scrolling added
  • Get callbacks when empty view is tapped/long pressed
  • Control the speed of scrolling
  • Support for multiple language added
  • Ability to set your own interpreter for header row and column added

Version 1.1.7

  • You can now dynamically scroll to an hour of your preference.

Version 1.1.6

  • Added support for events that expands to multiple days

Version 1.1.5

  • A bug related to overlapping events fixed
  • You can now programmatically get first and last visible day in the week view

Version 1.1.4

  • Small bug fixed

Version 1.1.3

  • Margins support added for overlapping events

Version 1.1.2

  • Small bugs fixed
  • Hour separator inconsistency fixed

Version 1.1.1

  • Overlapping event bug fixed

Version 1.1.0

  • Added support for overlapping events

License

Copyright 2014 Raquib-ul-Alam

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Problem with set event

    Problem with set event

    Hello, I have 2 dates: 15-01-2015 14:00, timestamp: 1421330400 15-01-2015 15:00, timestamp: 1421334000 and I want to set Event like this: @Override public List onMonthChange(int newYear, int newMonth) {

        List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
    
        GregorianCalendar startTime = new GregorianCalendar();
        startTime.setTimeInMillis(1421330400*1000);
        GregorianCalendar endTime = new GregorianCalendar();
        endTime.setTimeInMillis(1421334000*1000);
    
        WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime.get(Calendar.YEAR) , startTime.get(Calendar.MONTH), startTime.get(Calendar.DAY_OF_MONTH), startTime.get(Calendar.HOUR_OF_DAY), startTime.get(Calendar.MINUTE), endTime.get(Calendar.YEAR) , endTime.get(Calendar.MONTH), endTime.get(Calendar.DAY_OF_MONTH), endTime.get(Calendar.HOUR_OF_DAY), endTime.get(Calendar.MINUTE));
        event.setColor(getResources().getColor(R.color.event_color_01));
        events.add(event);
    
        return events;
    }
    

    but event don't show on calendar, how to do this?

    opened by wojtkuju 31
  • Re: Question about setting weekview event

    Re: Question about setting weekview event

    Hello,

    This is with reference to the issue I opened earlier, with the same title. I cannot reopen the issue, because it was not closed by me. Hence opening a new issue:

    Question : Is there a way to set the list of events in WeekView other than returning List of WeekViewEvents in onMonthChange() ?

    Your solution:

    Currently the week view does not provide a ready-made solution for async event loading. But there is a simple hack. Use the following code to achieve what you want.

    @Override public List onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List events = new ArrayList();

    // Fetch events for the date user selected.
    fetchEventsinBackground();
    

    }

    // Callback when fetchEvents finishes. public void setEventList(Activity activity, final List eventModels) {

    // Hide the progress dialog.
    if(mProgressDialog != null && mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();
    }
    
    // Refresh the week view.
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Store the returned events in a global variable for later use.
            mEventModels = eventModels;
    
            // This line will trigger the method 'onMonthChange()' again.
            mWeekView.notifyDatasetChanged();
        }
    });
    

    }

    @Override public List onMonthChange(int year, int month) { // TODO Be sure to check if the variables year and month equals the year and month of the events of mEventModels. return getWeekViewEventsFromEventModels(mEventModels); }

    Thank you for the response, however it did not work for me.

    Java doesn't support 2 methods with same signature, so I can't have something like this in the same class:

    @Override public List onMonthChange(int year, int month) { // TODO Be sure to check if the variables year and month equals the year and month of the events of mEventModels. return getWeekViewEventsFromEventModels(mEventModels); } @Override public List onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List events = new ArrayList();

    // Fetch events for the date user selected.
    fetchEventsinBackground();
    

    } If mWeekView.notifyDatasetChanged(); triggers onMonthChange() again, then it results in an infinite loop with fetchEventsinBackground() being called again & again!

    Is there a better way out ? Thanks for all the help!

    opened by shalinipk 23
  • Navigating between days very jerky in version 1.2.4 compared to before

    Navigating between days very jerky in version 1.2.4 compared to before

    This is an excellent library that I am trying to incorporate into a demo app and have noticed a degradation in experience between after upgrading from version 1.2.3 to 1.2.4.

    I am attaching two videos with this issue. First video is showing how navigating between days is very jerky. Sliding left and sliding right results in 'oversliding' or 'undersliding', which is then compensated by the app by automatically jumping to the nearest day. It might have been a desired behavior, but as you can see in the video, for the most common use case of user going from day to day, it makes for a very jerky and unsettling experience.

    Now compare this to the experience in the older version, which can be seen in the second video. As soon as you slide to left or right, the view smoothly scrolls to that day. If we flick very fast, it may scroll to a few days back and forth, but the experience is very smooth, very predictable.

    Is there a way to get the old behavior back, or is this on purpose? If it's on purpose, would anyone mind pointing out the relevant change that is causing this, so I can consider overriding it?

    Thank you, and many kudos for an excellent job done.

    Videos:

    Old Version: (Smooth Behavior) : http://gfycat.com/WelllitWideeyedGenet

    New Version:(Jerky Behavior) http://gfycat.com/ElasticExhaustedArchaeocete

    opened by wwahmed 20
  • why Events are repeating every months

    why Events are repeating every months

    I need to show events weekly basis. But If how can I create a event on a particulate date month time? and why events are repeating every months.

    What I tried to add a event on a particulate date and time -

    Calendar startTime = Calendar.getInstance(); startTime.set(Calendar.HOUR_OF_DAY, 3); startTime.set(Calendar.MINUTE, 0); startTime.set(Calendar.MONTH, 6); startTime.set(Calendar.YEAR, 2015); Calendar endTime = (Calendar) startTime.clone(); endTime.add(Calendar.HOUR, 2); endTime.set(Calendar.MONTH, 06); WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime); event.setColor(getResources().getColor(R.color.event_color_01)); event.setName("Meeting with John"); events.add(event);

    But nothing happening.

    opened by anirbansAndroidDev 20
  • goToDate

    goToDate

    Using the goToDate function doesn't seem to work as intended. For example: Calendar myDate = Calendar.getInstace(); myDate.set(Calendar.DATE, 5); myDate.set(Calendar.MONTH, 1); mWeekView.goToDate(myDate); Results in the equivalent of calling goToToday(). I've gotten some success from doing the following: myDate.add(Calendar.Date, x) However this doesn't seem to work for anything beyond the current month.

    bug 
    opened by Harrison-Miller 17
  • Same Event name is apprearing 3 times in single row

    Same Event name is apprearing 3 times in single row

    Hi, I am adding events on weekly calendar by your reference code below. But the name of event is appearing three time also when I click on that event it returns me same event id so there is no duplicate events added . Please check my code below also attaching a screen shot screenshot_1490074131

    events = new ArrayList();

        Calendar startTime = Calendar.getInstance();
        startTime.set(Calendar.HOUR_OF_DAY, 3);
        startTime.set(Calendar.MINUTE, 0);
        startTime.set(Calendar.MONTH, newMonth - 1);
        startTime.set(Calendar.YEAR, newYear);
        Calendar endTime = (Calendar) startTime.clone();
        endTime.add(Calendar.HOUR, 1);
        endTime.set(Calendar.MONTH, newMonth - 1);
        WeekViewEvent event = new WeekViewEvent(1, "ABC", startTime, endTime);
        //event.setColor(getResources().getColor(R.color.event_color_01));
        events.add(event);
    
        startTime = Calendar.getInstance();
        startTime.set(Calendar.HOUR_OF_DAY, 3);
        startTime.set(Calendar.MINUTE, 30);
        startTime.set(Calendar.MONTH, newMonth-1);
        startTime.set(Calendar.YEAR, newYear);
        endTime = (Calendar) startTime.clone();
        endTime.set(Calendar.HOUR_OF_DAY, 4);
        endTime.set(Calendar.MINUTE, 30);
        endTime.set(Calendar.MONTH, newMonth-1);
        event = new WeekViewEvent(10, "XYZ", startTime, endTime);
        //event.setColor(getResources().getColor(R.color.event_color_02));
        events.add(event);
    
        startTime = Calendar.getInstance();
        startTime.set(Calendar.HOUR_OF_DAY, 3);
        startTime.set(Calendar.MINUTE, 30);
        startTime.set(Calendar.MONTH, newMonth-1);
        startTime.set(Calendar.YEAR, newYear);
        startTime.set(Calendar.DATE,startTime.get(Calendar.DATE)+1);
        endTime = (Calendar) startTime.clone();
        endTime.set(Calendar.HOUR_OF_DAY, 4);
        endTime.set(Calendar.MINUTE, 30);
        endTime.set(Calendar.MONTH, newMonth-1);
        event = new WeekViewEvent(10, "YYM", startTime, endTime);
        //event.setColor(getResources().getColor(R.color.event_color_02));
        events.add(event);
    
    opened by rishabhbsdei 16
  • error :

    error : "You must provide a MonthChangeListener" however I provide this

    Hello. I have this error when i want to implement a Fragment with a WeekView : "java.lang.IllegalStateException: You must provide a MonthChangeListener". I really don't understand because I have a MonthChangeListener ! I looked for the reason of this error on internet but I didn't find... It works when I made an activity with WeekView but I don't manage to make a fragment with it, always this error.

    I paste my code, if you know why this error occured, please let me know !

    public class Cal extends Fragment implements MonthLoader.MonthChangeListener,WeekView.EventClickListener, WeekView.EventLongPressListener,
            WeekView.EmptyViewLongPressListener{
        // TODO: Rename parameter arguments, choose names that match
        // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
        private static final String ARG_PARAM1 = "param1";
        private static final String ARG_PARAM2 = "param2";
    
        // TODO: Rename and change types of parameters
        private String mParam1;
        private String mParam2;
    
        private OnFragmentInteractionListener mListener;
    
        public Intent impor;
        public Intent settings;
        public Intent compte;
        View v;
        LayoutInflater inflater;
    
        private int index;
        private static WeekView mWeekView;
        private static WeekViewEvent e;
        private static ArrayList<WeekViewEvent> mNewEvents;
    
        public Cal() {
            // Required empty public constructor
        }
    
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment Cal.
         */
        // TODO: Rename and change types and number of parameters
        public static Cal newInstance(String param1, String param2) {
            Cal fragment = new Cal();
            Bundle args = new Bundle();
            args.putString(ARG_PARAM1, param1);
            args.putString(ARG_PARAM2, param2);
            fragment.setArguments(args);
            return fragment;
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (getArguments() != null) {
                mParam1 = getArguments().getString(ARG_PARAM1);
                mParam2 = getArguments().getString(ARG_PARAM2);
            }
    
            inflater=getActivity().getLayoutInflater();
            v=inflater.inflate(R.layout.weekview, null);
    
            // Get a reference for the week view in the layout.
            mWeekView = (WeekView) v.findViewById(R.id.weekView);
    
            // The week view has infinite scrolling horizontally. We have to provide the events of a
            // month every time the month changes on the week view.
            mWeekView.setMonthChangeListener(this);
    
            // Show a toast message about the touched event.
            mWeekView.setOnEventClickListener(this);
    
            // Set up empty view click listener.
            mWeekView.setEmptyViewLongPressListener(this);
    
            mWeekView.setEventLongPressListener(this);
    
    
            // Set up a date time interpreter to interpret how the date and time will be formatted in
            // the week view. This is optional.
            setupDateTimeInterpreter(false);
    
            // Initially, there will be no events on the week view because the user has not tapped on
            // it yet.
            mNewEvents = new ArrayList<WeekViewEvent>();
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.weekview, container, false);
        }
    
        // TODO: Rename method, update argument and hook method into UI event
        public void onButtonPressed(Uri uri) {
            if (mListener != null) {
                mListener.onFragmentInteraction(uri);
            }
        }
    
        @Override
        public void onAttach(Context context) {
            super.onAttach(context);
            if (context instanceof OnFragmentInteractionListener) {
                mListener = (OnFragmentInteractionListener) context;
            } else {
                throw new RuntimeException(context.toString()
                        + " must implement OnFragmentInteractionListener");
            }
        }
    
        @Override
        public void onDetach() {
            super.onDetach();
            mListener = null;
        }
    
    
        @Override
        public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
            // Populate the week view with the events that was added by tapping on empty view.
            List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
            ArrayList<WeekViewEvent> newEvents = getNewEvents(newYear, newMonth);
            events.addAll(newEvents);
    
            Calendar startTime = Calendar.getInstance();
            startTime.set(Calendar.HOUR_OF_DAY, 3);
            startTime.set(Calendar.MINUTE, 0);
            startTime.set(Calendar.MONTH, newMonth - 1);
            startTime.set(Calendar.YEAR, newYear);
            Calendar endTime = (Calendar) startTime.clone();
            endTime.add(Calendar.HOUR, 1);
            endTime.set(Calendar.MONTH, newMonth - 1);
            WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.red));
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.HOUR_OF_DAY, 3);
            startTime.set(Calendar.MINUTE, 30);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            endTime = (Calendar) startTime.clone();
            endTime.set(Calendar.HOUR_OF_DAY, 4);
            endTime.set(Calendar.MINUTE, 30);
            endTime.set(Calendar.MONTH, newMonth-1);
            event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.red));
            event.setName("match foot");
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.HOUR_OF_DAY, 4);
            startTime.set(Calendar.MINUTE, 20);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            endTime = (Calendar) startTime.clone();
            endTime.set(Calendar.HOUR_OF_DAY, 5);
            endTime.set(Calendar.MINUTE, 0);
            event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.green));
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.HOUR_OF_DAY, 5);
            startTime.set(Calendar.MINUTE, 30);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            endTime = (Calendar) startTime.clone();
            endTime.add(Calendar.HOUR_OF_DAY, 2);
            endTime.set(Calendar.MONTH, newMonth-1);
            event = new WeekViewEvent(2, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.green));
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.HOUR_OF_DAY, 5);
            startTime.set(Calendar.MINUTE, 0);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            startTime.add(Calendar.DATE, 1);
            endTime = (Calendar) startTime.clone();
            endTime.add(Calendar.HOUR_OF_DAY, 3);
            endTime.set(Calendar.MONTH, newMonth - 1);
            event = new WeekViewEvent(3, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.blue));
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.DAY_OF_MONTH, 15);
            startTime.set(Calendar.HOUR_OF_DAY, 3);
            startTime.set(Calendar.MINUTE, 0);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            endTime = (Calendar) startTime.clone();
            endTime.add(Calendar.HOUR_OF_DAY, 3);
            event = new WeekViewEvent(4, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.yellow));
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.DAY_OF_MONTH, 1);
            startTime.set(Calendar.HOUR_OF_DAY, 3);
            startTime.set(Calendar.MINUTE, 0);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            endTime = (Calendar) startTime.clone();
            endTime.add(Calendar.HOUR_OF_DAY, 3);
            event = new WeekViewEvent(5, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.red));
            events.add(event);
    
            startTime = Calendar.getInstance();
            startTime.set(Calendar.DAY_OF_MONTH, startTime.getActualMaximum(Calendar.DAY_OF_MONTH));
            startTime.set(Calendar.HOUR_OF_DAY, 15);
            startTime.set(Calendar.MINUTE, 0);
            startTime.set(Calendar.MONTH, newMonth-1);
            startTime.set(Calendar.YEAR, newYear);
            endTime = (Calendar) startTime.clone();
            endTime.add(Calendar.HOUR_OF_DAY, 3);
            event = new WeekViewEvent(5, getEventTitle(startTime), startTime, endTime);
            event.setColor(getResources().getColor(R.color.green));
            events.add(event);
    
            return events;
        }
    
        protected String getEventTitle(Calendar time) {
            return String.format("Event of %02d:%02d %s/%d", time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), time.get(Calendar.MONTH)+1, time.get(Calendar.DAY_OF_MONTH));
        }
    
    
        private void setupDateTimeInterpreter(final boolean shortDate) {
            mWeekView.setDateTimeInterpreter(new DateTimeInterpreter() {
                @Override
                public String interpretDate(Calendar date) {
                    SimpleDateFormat weekdayNameFormat = new SimpleDateFormat("EEE", Locale.getDefault());
                    String weekday = weekdayNameFormat.format(date.getTime());
                    SimpleDateFormat format = new SimpleDateFormat(" M/d", Locale.getDefault());
    
                    // All android api level do not have a standard way of getting the first letter of
                    // the week day name. Hence we get the first char programmatically.
                    // Details: http://stackoverflow.com/questions/16959502/get-one-letter-abbreviation-of-week-day-of-a-date-in-java#answer-16959657
                    if (shortDate)
                        weekday = String.valueOf(weekday.charAt(0));
                    return weekday.toUpperCase() + format.format(date.getTime());
                }
    
                @Override
                public String interpretTime(int hour) {
                    return hour > 11 ? (hour - 12) + " PM" : (hour == 0 ? "12 AM" : hour + " AM");
                }
            });
        }
        /**
         * Get events that were added by tapping on empty view.
         * @param year The year currently visible on the week view.
         * @param month The month currently visible on the week view.
         * @return The events of the given year and month.
         */
        private ArrayList<WeekViewEvent> getNewEvents(int year, int month) {
    
            // Get the starting point and ending point of the given month. We need this to find the
            // events of the given month.
            Calendar startOfMonth = Calendar.getInstance();
            startOfMonth.set(Calendar.YEAR, year);
            startOfMonth.set(Calendar.MONTH, month - 1);
            startOfMonth.set(Calendar.DAY_OF_MONTH, 1);
            startOfMonth.set(Calendar.HOUR_OF_DAY, 0);
            startOfMonth.set(Calendar.MINUTE, 0);
            startOfMonth.set(Calendar.SECOND, 0);
            startOfMonth.set(Calendar.MILLISECOND, 0);
            Calendar endOfMonth = (Calendar) startOfMonth.clone();
            endOfMonth.set(Calendar.DAY_OF_MONTH, endOfMonth.getMaximum(Calendar.DAY_OF_MONTH));
            endOfMonth.set(Calendar.HOUR_OF_DAY, 23);
            endOfMonth.set(Calendar.MINUTE, 59);
            endOfMonth.set(Calendar.SECOND, 59);
    
            // Find the events that were added by tapping on empty view and that occurs in the given
            // time frame.
            ArrayList<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
            for (WeekViewEvent event : mNewEvents) {
                if (event.getEndTime().getTimeInMillis() > startOfMonth.getTimeInMillis() &&
                        event.getStartTime().getTimeInMillis() < endOfMonth.getTimeInMillis()) {
                    events.add(event);
                }
            }
            return events;
        }
    
    
        @Override
        public void onEventClick(WeekViewEvent event, RectF eventRect) {
            Toast.makeText(getActivity(), "Clicked " + event.getName(), Toast.LENGTH_SHORT).show();
            e=event;
            /*this.getmNewEvents().remove(e);
            this.getmWeekView().notifyDatasetChanged();*/
           /* eventName.setText("Match");
            eventPlace.setText("parc");
            eventSchedule.setText("20h-22h");*/
            EventFragment eventFragment= new EventFragment();
            eventFragment.show(getFragmentManager(), "EventFragment");
        }
        @Override
        public void onEventLongPress(WeekViewEvent event, RectF eventRect) {
            Toast.makeText(getActivity(), "Long pressed event: " + event.getName(), Toast.LENGTH_SHORT).show();
    
        }
    
        @Override
        public void onEmptyViewLongPress(Calendar time) {
            // Set the new event with duration one hour.
            Calendar endTime = (Calendar) time.clone();
            // nombre random pour l'id de l'évènement
            Random r = new Random();
            int i1 = r.nextInt(200);
            endTime.add(Calendar.HOUR, 1);
    
            // Create a new event.
            e = new WeekViewEvent(i1, "New event", time, endTime);
            // appelle la fonction qui lance le dialogView pour récupérer les informations sur l'event
            e=addEvent(e);
        }
    
        public WeekViewEvent addEvent(WeekViewEvent e){
    
    
            Calendar_dialog dialog= new Calendar_dialog();
            dialog.show(getFragmentManager(), "Calendar_dialog");
    
    
            return e;
        }
    
        public static WeekViewEvent getE() {
            return e;
        }
    
        public static WeekView getmWeekView() {
    
            return mWeekView;
        }
        public static ArrayList<WeekViewEvent> getmNewEvents() {
            return mNewEvents;
        }
    
        public static void setmWeekView(WeekView mWeekView) {
            Cal.mWeekView = mWeekView;
        }
    
        public static void setE(WeekViewEvent e) {
            Cal.e = e;
        }
    
        public static void setmNewEvents(ArrayList<WeekViewEvent> mNewEvents) {
            Cal.mNewEvents = mNewEvents;
        }
    
        public int getIndex() {
            return index;
        }
    
    
        /**
         * This interface must be implemented by activities that contain this
         * fragment to allow an interaction in this fragment to be communicated
         * to the activity and potentially other fragments contained in that
         * activity.
         * <p/>
         * See the Android Training lesson <a href=
         * "http://developer.android.com/training/basics/fragments/communicating.html"
         * >Communicating with Other Fragments</a> for more information.
         */
        public interface OnFragmentInteractionListener {
            // TODO: Update argument type and name
            void onFragmentInteraction(Uri uri);
        }
    
    
    }
    

    Thank you for reading me ! Guillaume

    opened by GuillaumeBuc 16
  • Show only the days of the week (Sunday to Saturday)

    Show only the days of the week (Sunday to Saturday)

    Is there other way to show only ONE WEEK, featuring the days (Sunday - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday), as the header columns, and no specified dates?

    opened by anobilisgorse 16
  • All Day Events

    All Day Events

    Is there a way to represent events as being All Day Events.

    We have a lot of events that have a Start Date but no End Date time. These are typically All Day events. They have no start times just a start date. Right now if I include these events they all show up at the same hour, and overlap each other.

    I tried setting overlapping attribute but that didn't affect anything.

    enhancement 
    opened by kingargyle 16
  • Rendering bug in version 1.2.6

    Rendering bug in version 1.2.6

    Hello, great job, i am pleased to use and look at your library live and improve.

    More precisely, i use your library until last 3 updates. And find one annoying bug(with drawing, look at screenshots) after last update (in version 1.2.6) Bug constantly reproduced in samsung galaxy tab s (android 4.4.2), it`s my target device. Also i tried to reproduce him on another devices (Sony Xperia z3 android 5.0 and Sony Xperia z Android 4.4.4), but on this devices all work correctly.

    I tried to use previous version of library (using Gradle) :

    • add compile 'com.github.alamkanak:android-week-view:1.2.4'. All work correctly, bug doesn`t appear.
    • add compile 'com.github.alamkanak:android-week-view:1.2.5'. Can`t compile because of : "Could not find com.github.alamkanak:android-week-view:1.2.5"

    Steps to reproduce the bug.

    1. Device - samsung galaxy tab s (android 4.4.2);
    2. Create new project with navigation drawer activity (minsdk 14);
    3. add compile 'com.github.alamkanak:android-week-view:1.2.6'
    4. create layout
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context=".CategoryActivity$PlaceholderFragment">
    
    <com.alamkanak.weekview.WeekView
        android:id="@+id/weekView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:eventTextColor="@android:color/black"
        app:textSize="12sp"
        app:hourHeight="60dp"
        app:headerColumnPadding="8dp"
        app:headerColumnTextColor="#8f000000"
        app:headerRowPadding="12dp"
        app:hourSeparatorColor="#808080"
        app:columnGap="8dp"
        app:noOfVisibleDays="7"
        app:showDistinctPastFutureColor = "true"
        app:futureBackgroundColor = "#1500FF00"
        app:pastBackgroundColor = "#0800ff00"
        app:showDistinctWeekendColor ="true"
        app:futureWeekendBackgroundColor = "#15ff0000"
        app:pastWeekendBackgroundColor = "#15ff0000"
        app:headerRowBackgroundColor="#ffefefef"
        app:showNowLine = "true"
        app:nowLineColor = "#aa0000ff"
        app:headerColumnBackground="#ffffffff"/> 
    
    5. add monthlistener. 6. All work as expected until to slide navigation drawer (look at screenshots);

    I appreciate any suggestion on resolving this problem.

    // Normal state normal state

    // Buggy state after slide navigation drawer bug state

    opened by dukerok 15
  • Support for setting min and max dates

    Support for setting min and max dates

    In case you are interested, I've implemented a feature for limiting the WeekView to a defined date range. This allows you to disable the infinite horizontal scrolling in one or both directions.

    I think this makes the component more flexible, and useful in a range of situations. For example you could show a schedule of sessions that occur over a fixed period at a conference.

    This feature has involved a few changes to the codebase, which can be broken down as follows:

    1. Add members mMinDate and mMaxDate which default to null (providing unrestricted scrolling by default)
    2. Add public methods getMinDate(), getMaxDate(), setMinDate(), setMaxDate()
    3. Eliminate mToday and replace it with mHomeDate, which is recalculated by a private method resetHomeDate() whenever certain properties change.
      • When the horizontal scroll offset is zero, the home date will be the leftmost day visible in the view.
      • The home date won't always be 'today', because today's date might not be within the the restricted date range.
    4. Centralise the logic that calculates min/max scroll offsets into private methods getXMinLimit(), getXMaxLimit(), getYMinLimit() and getYMaxLimit()
    5. Centralise the logic that calculates the x-offset for a date into private method getXOriginForDate()
    6. Enforce the scroll limits in onScroll(), onFling() and goToDate()
    opened by glennschmidt 15
  • Is it possible to add event in normal date format?

    Is it possible to add event in normal date format?

    Is it possible to add event in normal date format? For example - SimpleDateFormat("dd/MM/yyyy hh:mm a")

    Difficult to add event in GregorianCalendar format. GregorianCalendar[time=1666827017762,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=libcore.util.ZoneInfo[id="Asia/Calcutta",mRawOffset=19800000,mEarliestRawOffset=21208000,mUseDst=false,mDstSavings=0,transitions=7],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2022,MONTH=9,WEEK_OF_YEAR=44,WEEK_OF_MONTH=5,DAY_OF_MONTH=27,DAY_OF_YEAR=300,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=5,HOUR_OF_DAY=5,MINUTE=0,SECOND=17,MILLISECOND=762,ZONE_OFFSET=19800000,DST_OFFSET=0]

    opened by ujj922059 0
  • Is there a recent Kotlin Sample I can see to understand how this code is implemented

    Is there a recent Kotlin Sample I can see to understand how this code is implemented

    I tried to use the Java code by converting to Kotlin and I am seeing these error messages: image image

    It tells me that the WeekView is deprecated and to use Event. Does this mean that the Event Class is already implemented? Sorry, I am new to Android and I am practicing by creating an app.

    opened by rohanafsan 1
  •  AAPT: error: duplicate value for resource 'attr/textStyle' with config ''.

    AAPT: error: duplicate value for resource 'attr/textStyle' with config ''.

    .gradle/caches/transforms-2/files-2.1/717a955ea77a238245f5bda828ae15c0/core-5.2.4/res/values/values.xml:3:5 AAPT: error: duplicate value for resource 'attr/textStyle' with config ''.

        <!-- Calendar configuration -->
        <attr format="integer" name="numberOfVisibleDays"/>
        <attr format="boolean" name="restoreNumberOfVisibleDays"/>
        <attr format="boolean" name="showFirstDayOfWeekFirst"/>
        <attr format="boolean" name="showCurrentTimeFirst"/>
        <attr format="boolean" name="arrangeAllDayEventsVertically"/>
    
        <!-- Header bottom line -->
        <attr format="boolean" name="showHeaderBottomLine"/>
        <attr format="color" name="headerBottomLineColor"/>
        <attr format="dimension" name="headerBottomLineWidth"/>
    
        <!-- Header bottom shadow -->
        <attr format="boolean" name="showHeaderBottomShadow"/>
        <attr format="color" name="headerBottomShadowColor"/>
        <attr format="dimension" name="headerBottomShadowRadius"/>
    
        <!-- Time column -->
        <attr format="color" name="timeColumnTextColor"/>
        <attr format="color" name="timeColumnBackgroundColor"/>
        <attr format="dimension" name="timeColumnPadding"/>
        <attr format="dimension" name="timeColumnTextSize"/>
        <attr format="boolean" name="showMidnightHour"/>
        <attr format="boolean" name="showTimeColumnHourSeparator"/>
        <attr format="integer" name="timeColumnHoursInterval"/>
    
        <!-- Time column separator -->
        <attr format="boolean" name="showTimeColumnSeparator"/>
        <attr format="color" name="timeColumnSeparatorColor"/>
        <attr format="dimension" name="timeColumnSeparatorStrokeWidth"/>
    
        <!-- Time range -->
        <attr format="integer" name="minHour"/>
        <attr format="integer" name="maxHour"/>
    
        <!-- Header row -->
        <attr format="color" name="headerBackgroundColor"/>
        <attr format="dimension" name="headerPadding"/>
        <attr format="dimension" name="headerTextSize"/>
        <attr format="color" name="headerTextColor"/>
        <attr format="color" name="todayHeaderTextColor"/>
        <attr format="color" name="weekendHeaderTextColor"/>
    
        <!-- Week number -->
        <attr format="boolean" name="showWeekNumber"/>
        <attr format="color" name="weekNumberTextColor"/>
        <attr format="dimension" name="weekNumberTextSize"/>
        <attr format="color" name="weekNumberBackgroundColor"/>
        <attr format="dimension" name="weekNumberBackgroundCornerRadius"/>
    
        <!-- Event chips -->
        <attr format="dimension" name="eventCornerRadius"/>
        <attr format="dimension" name="eventTextSize"/>
        <attr format="boolean" name="adaptiveEventTextSize"/>
        <attr format="color" name="eventTextColor"/>
        <attr format="dimension" name="eventPaddingHorizontal"/>
        <attr format="dimension" name="eventPaddingVertical"/>
        <attr format="color" name="defaultEventColor"/>
        <attr format="dimension" name="allDayEventTextSize"/>
    
        <!-- Event margins -->
        <attr format="dimension" name="columnGap"/>
        <attr format="dimension" name="overlappingEventGap"/>
        <attr format="dimension" name="eventMarginVertical"/>
        <attr format="dimension" name="singleDayHorizontalPadding"/>
    
        <!-- Colors -->
        <attr format="color" name="dayBackgroundColor"/>
        <attr format="color" name="todayBackgroundColor"/>
        <attr format="color" name="pastBackgroundColor"/>
        <attr format="color" name="futureBackgroundColor"/>
        <attr format="color" name="pastWeekendBackgroundColor"/>
        <attr format="color" name="futureWeekendBackgroundColor"/>
    
        <!-- Hour height -->
        <attr format="dimension" name="hourHeight"/>
        <attr format="dimension" name="minHourHeight"/>
        <attr format="dimension" name="maxHourHeight"/>
        <attr format="boolean" name="showCompleteDay"/>
    
        <!-- Now line -->
        <attr format="boolean" name="showNowLine"/>
        <attr format="color" name="nowLineColor"/>
        <attr format="dimension" name="nowLineStrokeWidth"/>
    
        <!-- Now line dot -->
        <attr format="boolean" name="showNowLineDot"/>
        <attr format="color" name="nowLineDotColor"/>
        <attr format="dimension" name="nowLineDotRadius"/>
    
        <!-- Hour separators -->
        <attr format="boolean" name="showHourSeparator"/>
        <attr format="color" name="hourSeparatorColor"/>
        <attr format="dimension" name="hourSeparatorStrokeWidth"/>
    
        <!-- Day separators -->
        <attr format="boolean" name="showDaySeparator"/>
        <attr format="color" name="daySeparatorColor"/>
        <attr format="dimension" name="daySeparatorStrokeWidth"/>
    
        <!-- Scrolling -->
        <attr format="boolean" name="horizontalScrollingEnabled"/>
    
        <attr format="float" name="xScrollingSpeed"/>
        <attr format="boolean" name="verticalFlingEnabled"/>
        <attr format="boolean" name="horizontalFlingEnabled"/>
        <attr format="integer" name="scrollDuration"/>
    
        <!-- Font -->
        <attr format="string" name="fontFamily"/>
        <attr name="typeface">
            <enum name="normal" value="0"/>
            <enum name="sans" value="1"/>
            <enum name="serif" value="2"/>
            <enum name="monospace" value="3"/>
        </attr>
        <attr name="textStyle">
            <flag name="normal" value="0"/>
            <flag name="bold" value="1"/>
            <flag name="italic" value="2"/>
        </attr>
    
    </declare-styleable>
    
    opened by ten-skv 0
  • How to add new column in Day View?

    How to add new column in Day View?

    Hi all, In my project, I want to add a few columns to divide the work into each column like each column will be a meeting room. I don't know how to customize it.

    opened by BaoDat 0
  • Using a deprecated clipRect() in 1.2.6

    Using a deprecated clipRect() in 1.2.6

    In the following code in WeekView.java, this line number 591

    canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2, getWidth(), getHeight(), Region.Op.REPLACE);

    must be replaced by canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2, getWidth(), getHeight());

    since the usage of Region.Op.REPLACE is no longer supported.

    opened by GoldDiggerRu 2
Releases(parent-1.2.6)
  • parent-1.2.6(Jan 4, 2016)

  • parent-1.2.5(Jan 2, 2016)

  • parent-1.2.4(Dec 12, 2015)

    NOTE: If you are using WeekView.MonthChangeListener, make sure to change it into MonthLoader.MonthChangeListener.

    • New: Add support to have loaders other than MonthViewLoader
    • New: Add pinch to zoom support
    • New: Add support for location
    • New: Add ability to have different colors for past, future, weekend days
    • New: Add support for "now" line
    Source code(tar.gz)
    Source code(zip)
  • parent-1.2.3(May 9, 2015)

    • New: Use getFirstVisibleHour method to get the first visible hour in the week view
    • New: Get callbacks when scrolling horizontally
    • Fix: goToHour and goToDate methods has been fixed
    Source code(tar.gz)
    Source code(zip)
Owner
Raquib-ul Alam (Kanak)
Hybrid of two realms: android/kotlin and machine learning
Raquib-ul Alam (Kanak)
Kalendar - A calendar to integrate Calendar with Custom design in your jetpack compose project

Kalendar - An Elementary Compose Calendar. This is a calendar to integrate Calen

Himanshu Singh 494 Jan 2, 2023
Color-My-View-App - Layouts - ColorMyViews app

Layouts - ColorMyViews app This is the second toy app for lesson 2 of the Androi

null 0 Jan 7, 2022
An android library which provides a compact calendar view much like the one used in google calenders.

CompactCalendarView CompactCalendarView is a simple calendar view which provides scrolling between months. It's based on Java's Date and Calendar clas

SundeepK 1.5k Dec 9, 2022
Jetlime - A simple library for TimeLine view in Android

JetLime ⏱️ A simple yet highly customizable library for showing a TimeLine view

Pushpal Roy 107 Dec 6, 2022
Standalone Android widget for picking a single date from a calendar view.

TimesSquare for Android Standalone Android widget for picking a single date from a calendar view. Usage Include CalendarPickerView in your layout XML.

Square 4.4k Dec 20, 2022
Android calendar view (like card)

android-calendar-card (Google Play Demo) Android calendar view (like card) Simple and easy to modify Author: Michał Szwarc #CalendarCardPager License

Michał Szwarc 473 Nov 10, 2022
Android calendar view inspired by Sunrise calendar and iOS7 stock calendar

SilkCal Android calendar view inspired by Sunrise calendar and iOS7 stock calendar. Usage Add compile 'me.nlmartian.silkcal:library:0.1.1' to your dep

JunGuan Zhu 385 Nov 25, 2022
A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.

SublimePicker A customizable view that provisions picking of a date, time & recurrence option, all from a single user-interface. You can also view 'Su

Vikram 2.3k Jan 4, 2023
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Code-Troopers 2.7k Dec 29, 2022
FlipTimerView library for Android

FlipTimerView Preview FlipTimerView library for Android Getting started Add it in your root build.gradle at the end of repositories: allprojects { re

Anu S Pillai 314 Dec 28, 2022
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Code-Troopers 2.7k Dec 29, 2022
A customizable, easy-to-use, and functional circular time range picker library for Android

A customizable, easy-to-use, and functional circular time range picker library for Android. Use this library to mimic Apple's iOS or Samsung's bedtime picker.

Joery Droppers 251 Dec 30, 2022
Appleader707 1 Aug 9, 2022
Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal.

About Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal. Gradle Sample Default Item size Unfocused count

null 6 Dec 22, 2022
Nepali Date Picker library in Jetpack compose for android with Date conversion from BS to AD and vice-versa

Nepali Date picker Converter - Re in Compose This is a re-work of Nepali Date Picker Converter in jetpack compose and kotlin. English Locale Nepali Lo

Kiran Gyawali 4 Dec 23, 2022
Alwan 🎨 is an Android Jetpack Compose color picker library.

Alwan Alwan is an Android Jetpack Compose color picker library. Preview Recording.mp4 Download Gradle: dependencies { implementation 'com.raedapps:a

Raed Mughaus 6 Sep 16, 2022
JetCalendarView - A calendar library for Jetpack Compose

JetCalendar WIP 2022 Hit Refresh! Calendar view ❤️ Jetpack Compose License Copyr

Anmol Verma 8 Aug 17, 2022
Android interval timer app using compose + compose navigation, dagger hilt, room, kotlin coroutines + flow and mvvm design pattern.

What's InTime? ⏳ InTime is an interval timer application using android jetpack components and a long running service. The purpose of this project is t

P. 46 Oct 10, 2022
Gallery: an Android app developed for displaying images from unsplash website

Gallery App Gallery is an Android app developed for displaying images from unspl

Mohab Ezzat 0 Dec 30, 2021