alamkanak / android-week-view Goto Github PK
View Code? Open in Web Editor NEWAndroid Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
License: Apache License 2.0
Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
License: Apache License 2.0
Hi all,
I am facing the issue to draw the event in central vertical. What's happening now.
Suppose there two event on same day and same hour with different minutes. Then first event little bit -x position and another one is little bit +x position. I tried to change the same width and left value but not success.
// Calculate left and right position for all the events.
int maxRowCount = columns.get(0).size();
for (int i = 0; i < maxRowCount; i++) {
// Set the left and right values of the event.
float j = 0;
for (List<EventRect> column : columns) {
if (column.size() >= i+1) {
EventRect eventRect = column.get(i);
eventRect.width = 1f / columns.size();
eventRect.left = j / columns.size();
Log.e("WeekView","Width : "+eventRect.width);
Log.e("WeekView","left : "+eventRect.left);
eventRect.width = eventRect.left ;
eventRect.top = eventRect.event.getStartTime().get(Calendar.HOUR_OF_DAY) * 60 + eventRect.event.getStartTime().get(Calendar.MINUTE);
eventRect.bottom = eventRect.event.getEndTime().get(Calendar.HOUR_OF_DAY) * 60 + eventRect.event.getEndTime().get(Calendar.MINUTE);;
mEventRects.add(eventRect);
}
j++;
}
}
if anyone have idea about this. Please help me.
Thanks in advance
I know its a dumb question and I'm looking at internet.
But im getting a hard time finding out how to add it in my project with android studio.
If someone could explain, it would be good to put it in one wiki page, for the next ones.
Thanks in advanced.
Is there any easy way to make it display only one week, without the dates.
Like I need the view to show monday - sunday, like I need to make a plan for every week.
I dont know if im very clear.
Thanks
It would be really awesome to have the possibility to set a DateTimeInterpreter (maybe called a DateTimeViewInterpreter) which could return the view to be displayed in the header.
I want that because I want something like the Google Calendar app above my day columns that show me "Wed 7", but on two lines and "7" a lot bigger than "Wed".
I need a listener when scrolling through the calendar and the month changes.
Something like:
mWeekView.setMonthScrolledListener(this);
...
public void onMonthScrolled(int newYear, int newMonth) {
// I would update some parts of my ui like the actionbar title with the current year and month (Google calendar wise)
}
Is it possible to split onMonthChange() method in 2 separate methods? One that works like a simple onMonthChange() listener and it doesn't do anything else (it doesn't manage the events) and another one that manages only the creation of the events. Actually onMonthChange() makes both of these tasks and I can't call this method by myself to do some stuff without creating the events again, nor I can't create the events if I don't call it.
I try to explain better with an example. When onMonthChange() is called, I need to start an asyncTask inside it to get the events those comply with some parameters (nextMonth and nextYear) downloading them from a server. But when asyncTask returns the results (the events) the onMonthChange() has just finished his job and returned no events (because the asyncTask dind't return the events yet).
Hi,
Can we display the calendar from particular hour in week view like from 6:00 AM to 8:00 PM. If anyone have idea please reply.Thanks in advance...
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.
Hi.
First, thank you for the implementation of this library. It's a good job !
I would like to use it to display and add events. To do this, I need to know the day shown by the view to add an new event. But at this moment, I can't find a callback method in the library that lets me know the day displayed. Is this implemented or not?
I tried to make my own implementation of the following way:
private void drawHeaderRowAndEvents(Canvas canvas) {
...
// Iterate through each day.
for (int dayNumber = leftDaysWithGaps + 1;
dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1;
dayNumber++) {
// Check if the day is today.
day = (Calendar) mToday.clone();
day.add(Calendar.DATE, dayNumber - 1);
boolean sameDay = isSameDay(day, mToday);
// Return the current date displayed
if (dayNumber == leftDaysWithGaps + 1 && !mFetchedDate.equals(day)) {
mFetchedDate = (Calendar) day.clone();
// Callback method like "onMonthChange()" to know the current day displayed
mDayChangeListener.onDayChange(mFetchedDate);
}
...
}
In short, my question is : The library implements a way to know the day displayed ? If so, can you explain me how ? If not, my solution is it right ?
Thank's for your help !
Hey. Is there a way where in I can split the hours on the left into minutes? Also, lets say there are two events one starting from 3PM and ends and 3.30PM, the second one starts at 3.30PM and ends at 4.30PM. Now, when the background is highlighted, both events look like this,
Is there a way to put a differentiator between two consecutive events? Also, is there a way to add a new event by clicking on time column?
Thanks for sharing this library,
Here i have Query need help,
2)How i can manage "onMonthChange" ?
-I used AsyncTask for send request to the server, as result how i can add event after getting responce in "onPostExecute"
Here is the code i am trying to modify it and set dynamic event but no luck !!!
@OverRide
public List onMonthChange(int newYear, int newMonth) {
// Populate the week view with some events.
List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
String date1 = "2015-01-12 02:30 am";
SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
java.util.Date d1 = null;
Calendar cal;
try
{
d1 = form.parse(date1);
}
catch (java.text.ParseException e)
{
e.printStackTrace();
}
cal = Calendar.getInstance();
cal.setTime(d1);
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
startTime.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY));
startTime.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));
startTime.set(Calendar.MONTH, cal.get(Calendar.MONTH));
Calendar endTime = (Calendar) startTime.clone();
endTime.set(Calendar.DAY_OF_MONTH,12);
endTime.set(Calendar.HOUR_OF_DAY,4);
endTime.set(Calendar.MINUTE,30);
endTime.set(Calendar.MONTH, 0);
WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime);
event.setColor(getResources().getColor(R.color.event_color_01));
events.add(event);
return events;
}
Please give me solution or idea.
Thanks in advance.
I couldn't get to create weekly event, probably because an onWeekChangeListener is not implemented. My suggestion is to implement a method to scroll from week to week (From monday to monday), an onWeekChangeListener to populate the weekView and a method to start the week from a preferred day, other than today. Thanks a lot
Is there a way to set the list of events in WeekView other than returning List of WeekViewEvents in onMonthChange() ?
Here is my problem:
Whenever month changes on the weekview, I spawn a background task. When this task finishes, I get the callback on a different method. Hence there is no way I can return list of WeekViewEvents in onMonthChange()
Sample code:
@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) {
// Because this call comes from the AsyncTask, we must ensure that the following
// code instead executes on the UI thread.
//need to pass in activity here because sometimes getActivity() could be null if the
// fragment is detached from the activity
if(mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
//TODO - update weekview - how ?
}
});
}
It would be great if you could separate event handling(in this case, onMonthChange) from setting of weekview events.
I really like the presentation of this widget, however the above issue is preventing me from using it . Would be great if you could resolve this somehow please.
I think it would be useful to be able to start drawing the week from the chosen day rather than from today. Thanks.
For the applications where the main view is a day view the week prefetch is enough. 3 months is too big range for this kind of applications and reduce the application responsiveness for on the activity launch. We need to have a way to configure prefetch range.
Hi, I need to modify labels that display the days of the week and the time of the day, so i could choose a different language for the name of the days and a different pattern for day and time (24 hours format without am/pm marker, day before month format, etc). Is it possible to do that?
When
event1.startTime < event2.startTime && event1.endTime > event2.endTime
the day view would paint them together.
/**
* Checks if two events overlap.
* @param event1 The first event.
* @param event2 The second event.
* @return true if the events overlap.
*/
private boolean isEventsCollide(WeekViewEvent event1, WeekViewEvent event2) {
long start1 = event1.getStartTime().getTimeInMillis();
long end1 = event1.getEndTime().getTimeInMillis();
long start2 = event2.getStartTime().getTimeInMillis();
long end2 = event2.getEndTime().getTimeInMillis();
return (start1 >= start2 && start1 <= end2) || (end1 >= start2 && end1 <= end2);
}
this may need to return
return !((start1 >= end2) || (end1 <= start2));
Hello, first of all thank you for this library, it's amazing! but I have a few questions:
I have loaded events of every month of the year. I know that your library only allow you tu load 3 months at a time. But if I'm showing December, January and February, how can I do to show January, February and March when you scroll forward?
This is my code and it doesn't work:
public List onMonthChange(int newYear, int newMonth)
{
// Populate the week view with some events.
List events = new ArrayList<>();
for(Cita c : citas)
{
Calendar startTime = c.getFecha();
Log.d("DEBUG: ","onMonthChanged: newMonth = "+newMonth+", startTime.MONTH = "+String.valueOf(startTime.MONTH));
if(newMonth == startTime.MONTH)
{
Calendar endTime = (Calendar) startTime.clone();
endTime.add(Calendar.MINUTE, c.getIntervalo());
WeekViewEvent event = new WeekViewEvent(1, getEventTitle(c), startTime, endTime);
switch(c.getIdEstado())
{
case 0:event.setColor(getResources().getColor(R.color.event_color_01));break;
case 1:event.setColor(getResources().getColor(R.color.event_color_02));break;
case 3:event.setColor(getResources().getColor(R.color.event_color_03));break;
case 5:event.setColor(getResources().getColor(R.color.event_color_04));break;
case 8:event.setColor(getResources().getColor(R.color.event_color_05));break;
default:event.setColor(getResources().getColor(R.color.event_color_01));break;
}
events.add(event);
}
}
return events;
}
List of citas is loaded with events for the whole year, but if I scroll to march, no event is shown.
Hello,
I have to display a bunch of events that are long. However, those events seem like they're drawn only when the start_time and end_time for the event can be contained within the view.
So, below is a screenshot of the events "before scrolling down" ( my guess: start_time and end_time are visible to the user, so, these events are drawn):
and "after scrolling down" (scrolled a little bit past 11, to 11:30ish, which is after the start_time. at this point, I think WeekView.drawEvents(..) is called, and some of the events are not re-drawn, aside from the lone event which begins around 16:00, and lasts for an hour):
Rather than having the event rectangles disappear, i would like as much of the event as possible to be drawn within the displayed time. Hope the explanation of my issue is clear. Do you know how i can get this to work?
Thank you,
Karthik
It would be nice to have a marker of what time it is (when viewing today's events)
Do you think is possible to add the Month view too? It would be nice to have it as a library, since catching from the android source code is quite a pain... ๐
How to get Calendar header click event.I need to show a datepicker on click header.
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!
I'm maintaining a schedule app and I would love to switch over to Android-Week-View. There's only one thing that bothers me:
In my app, I'm using the DayView the most, but I don't want to load 3 months in advance into the view. (I'm calling an external API and they won't appreciate it if I load so much at once).
So I would love a way to set how many days/weeks/months in advance to load.
Hi,
I'd like to know if there is a way to zoom/pinch on a week view ?
And is it possible to display only days from Monday to Friday ?
Thank you
I loaded the data using Volley. All data is loaded in the list and I called notifyDataSetChanged(). But the data don't show in view. :(
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?
Hello, i am new to android and i want to implement day change listener using your code
can you help me with this? as 3 months data fetching is too heavy and long task, so instead of that if we can implement day change listener that will be more easy.
Hi,
I implement your framwork as a Fragment in iosched SlidingTabLayout. In this szenario the left-right swipe doesn't work correct. If I swipe to fast the SlidingTab will swipe. I only can swipe the Week-View if I swipe on the View a few millimeters. Is there any workaround to get the Swipe work again or can you fix this issue?
Best Regards
R0ns3n
It would be great to have such possiblity.
I did it
Can we create an event on a particular date?
Any help would be appreciated.
Thanks in advance.
I want to use this library, but can't quite yet because I only have one day (at most one week) of event data available. I should be able to supply only days within the context of the view.
I want the current hour to be scrolled to by default, but using the goToHour(..) method does not work. See my code snippet below.
Code snippet:
Calendar calendar = Calendar.getInstance();
mWeekView.goToDate(calendar);
mWeekView.goToHour(calendar.get(Calendar.HOUR_OF_DAY)); // Not working... Also tried with Calendar.HOUR...
Using release 1.1.2
How often does onMonthChange get called ? I have the weekview widget in a fragment, onMonthChange seem to get called quite a bit (I was expecting it to get called just once during fragment creation), every time it gets called I have to fetch events from the server, which is quite an overhead.
Hi,
When i try to use mWeekView.getFirstVisibleDay()
, I've a problem. When I'm in 3 days view, mWeekView.getFirstVisibleDay()
does not always return the correct day. Sometimes it returns the previous day.
I made a sample that returns the first date displayed by the view and this is the result :
mWeekView.getFirstVisibleDay()
returns the good daymWeekView.getFirstVisibleDay()
returns a bad dayDo you have an idea to solve this problem?
Thank's for your help !
Swiping to a date would be a very nice addition
Filtering hours to specific range would be appreciated. Not everyone wants to see the day beginning at 0.00 (AM).
I've got a button wich calls goToDate() and the date is calculated starting from getFirstVisibleDay(). The problem is that getFirstVisibleDay() sometimes returns a Calendar instance off by one day, which causes the calculation to fail.
To easily see you are viewing the past.
In combination with #48 it should probably also divide today's view in partially "history" and partially "future". So the background before the current hour marker should be the background for past days. And after should be the background for today's view / background for future days.
I want to make a table of curriculum,I think the ndroid-Week-View is very good! Would you change it ?
Thanks!
I think i will have to add empty events with a boolean flag, and on tapping them i can get it, if the event is empty, create new, else show details for previous events ??
Currently, the view just restarts on the current day. But it should probably remember which day was being viewed.
In the fork of CodeaciousAU (https://github.com/CodeaciousAU/Android-Week-View) I saw some nice features which would be very nice to have.
The color of the day text and of the hours should be separated coloured.
Swiping to a date would be a very nice addition
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.