Comments (15)
I was facing the same problem and this code solves it.
@Override
public List<WeekViewEvent> onMonthChange(final int i, final int i2) {
List<WeekViewEvent> newEvents= new ArrayList<WeekViewEvent>();
List<WeekViewEvent> events = Manager.events;
for (WeekViewEvent event : events) {
Calendar dateTime = event .getStartTime();
Calendar dateEndTime = event .getEndTime();
Calendar monCal = getFirstDay(i2 - 1, i, dateTime.get(Calendar.DAY_OF_WEEK));
int hday = dateTime.get(Calendar.HOUR_OF_DAY);
int mday = dateTime.get(Calendar.MINUTE);
int ehday = dateEndTime.get(Calendar.HOUR_OF_DAY);
int emday = dateEndTime.get(Calendar.MINUTE);
for (int k = monCal.get(Calendar.DAY_OF_MONTH); k <= monCal.getActualMaximum(Calendar.DAY_OF_MONTH); k += 7) {
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.MONTH, i2 - 1);
startTime.set(Calendar.DAY_OF_MONTH, k);
startTime.set(Calendar.YEAR, i);
startTime.set(Calendar.HOUR_OF_DAY, hday);
startTime.set(Calendar.MINUTE, mday);
startTime.set(Calendar.SECOND, 0);
startTime.set(Calendar.MILLISECOND, 0);
Calendar endTime = (Calendar) startTime.clone();
endTime.set(Calendar.HOUR_OF_DAY, ehday);
endTime.set(Calendar.MINUTE, emday - 1);
endTime.set(Calendar.MONTH, i2 - 1);
endTime.set(Calendar.SECOND, 59);
endTime.set(Calendar.MILLISECOND, 999);
WeekViewEvent newEvent = new WeekViewEvent(1, event .getName(), startTime, endTime);
newEvent.setColor(event .getColor());
newEvents.add(newEvent);
}
}
return newEvents;
}
from android-week-view.
Currently not. But isn't this easy to implement in your data provider? (for example using the excellent joda time library: http://www.joda.org/joda-time/). That library allows to add one day, one week, ... to a date.
from android-week-view.
@caske33 thanks for your reply, yes i think the workaround will be to get the date(s) of the visible day, 3 days, or week and query the data provider with those dates.
from android-week-view.
You can already do this in your onMonthChangeListener(int newYear, int newMonth):
public List<WeekViewEvent> onMonthChangeListener(int newYear, int newMonth){
List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
event = getFirstOccuenceInRange(newYear, newMonth);
while(event.isInRange(newYear, newMonth)){
events.add(event);
event = event.nextOccurence();
}
return events;
}
from android-week-view.
Can somebody help me modify the onMonthChange as to repeat each event every 7 between two dates ( ex 15 September and 22 May) or as long as the calendar permits?
tried to follow your approach @hellchoseme, yet can't find getFirstDay method
from android-week-view.
The getfirstday is a method you have to write that returns the first event of the series that falls in the certain month.
A way you can implent that method is by getting the first day over all, convert it to milliseconds (a). Get the first day of the month that is requested in milliseconds (b), and convert 7 days to milliseconds (c).
Then you know that a+c*k
are all events that are part of the series of events. (with k an integer). And you know that a+c*k>b
=> k = Math.ceil((b-a)/c)
. From that, you can calculate the first event (in milliseconds) as a+c*Math.ceil((b-a)/c)
I hope that is clear enough for you. Otherwise, just ask for more help ;)
from android-week-view.
@caske33 or @caske33 can one of you post the method here? I'm having little trouble implementing it
particularly, caske33 what do you mean by first day overall? ( a)
from android-week-view.
managed to achieve repeated events rudimentaly
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
List<WeekViewEvent> weekViewEvents = new ArrayList<WeekViewEvent>();
List <WeekViewEvent> repeatevents = new ArrayList<>();
for(WeekViewEvent event : events){
int startHour = event.getStartTime().get(Calendar.HOUR_OF_DAY);
int dayOfWeek = event.getStartTime().get(Calendar.DAY_OF_WEEK);
int endHour = event.getEndTime().get(Calendar.HOUR_OF_DAY);
String eventName = event.getName();
for (int i = -1000; i <= 1000; i = i + 7) {
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.HOUR_OF_DAY, startHour);
startTime.set(Calendar.MINUTE, 0);
startTime.set(Calendar.DAY_OF_WEEK, dayOfWeek);
startTime.add(Calendar.DATE, i);
startTime.add(Calendar.SECOND,1);
Calendar endTime = (Calendar) startTime.clone();
endTime.set(Calendar.HOUR_OF_DAY, endHour);
endTime.add(Calendar.MINUTE, -2);
WeekViewEvent event1 = new WeekViewEvent(id++, eventName, startTime, endTime);
event1.setColor(event.getColor());
repeatevents.add(event1);
}
}
for (WeekViewEvent event : repeatevents) {
if (event.getStartTime().get(Calendar.MONTH)== newMonth && event.getStartTime().get(Calendar.YEAR) == newYear) {
weekViewEvents.add(event);
}
}
return weekViewEvents;
}
Here is the code. Although, I'm looking forward to seeing yours implementation guys.
from android-week-view.
first day overall = the very first day the event took place.
I don't really have repeting events, so I don't have any code. But maybe @EmanueleHB can help you?
from android-week-view.
Here's my getFirstDay() method, I'm really sorry I forgot to post it:
public static Calendar getFirstDay(int i2, int i, int weekday) {
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, i2);
c.set(Calendar.YEAR, i);
c.set(Calendar.DAY_OF_MONTH, 1);
int day = c.get(Calendar.DAY_OF_WEEK);
while (day != weekday) {
c.add(Calendar.DAY_OF_MONTH, 1);
day = c.get(Calendar.DAY_OF_WEEK);
}
return c;
}
from android-week-view.
@EmanueleHB it works like a charm, but i see that events are also being added for the previous months too, how to modify your code so that event is show repeatedly from the event date and future, not past. I hope that you got my point.
from android-week-view.
@EmanueleHB i achieved what i was looking for, now next task on which i am working is to show events that "Never, Every Day, Every Week, Every Month," and "Every Year" repeating.
from android-week-view.
please help me to solve this problem !
i need to show an event every Monday, but i can't do this,,,
@EmanueleHB what is Manager in you code ?
from android-week-view.
@caske33 i recieve your mail, but i can't solve the problem, if you have a lil bit of time please help me
from android-week-view.
In this line of code : List< WeekViewEvent > events = Manager.events;
What is Manager?
Please help... @EmanueleHB @caske33
from android-week-view.
Related Issues (20)
- How to show the event that starts at Today 11PM and ends at Tomorrow morning 5AM HOT 1
- Accessibility/Talkback implementation of WeekView and its Events
- How to navigate to particular date HOT 1
- How can I hide or clear the header area?
- How to use this in Kotlin project? HOT 1
- Unable to display events
- Auto scroll to current hour?
- use firebase with Android-week-View HOT 2
- Events issue
- Name of event is repeated 3 times HOT 1
- Using a deprecated clipRect() in 1.2.6 HOT 2
- How to add new column in Day View?
- AAPT: error: duplicate value for resource 'attr/textStyle' with config ''.
- Is there a recent Kotlin Sample I can see to understand how this code is implemented HOT 2
- How can we change the **todayHeaderText** date format
- Is it possible to add event in normal date format?
- Is it possible to highlight weekends?
- Need to use Android X as its conflicting dependencies with recent android version
- Change X-axis and y-axis, and vertical scrolling to specific range
- Not integrated Lib
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-week-view.