Search in sources :

Example 1 with WeekViewEvent

use of com.alamkanak.weekview.WeekViewEvent in project Android-Week-View by alamkanak.

the class BasicActivity method onMonthChange.

@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    // Populate the week view with some events.
    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
    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.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, getEventTitle(startTime), startTime, endTime);
    event.setColor(getResources().getColor(R.color.event_color_02));
    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.event_color_03));
    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.event_color_02));
    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.event_color_03));
    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.event_color_04));
    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.event_color_01));
    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.event_color_02));
    events.add(event);
    //AllDay event
    startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 0);
    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, 23);
    event = new WeekViewEvent(7, getEventTitle(startTime), null, startTime, endTime, true);
    event.setColor(getResources().getColor(R.color.event_color_04));
    events.add(event);
    events.add(event);
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 8);
    startTime.set(Calendar.HOUR_OF_DAY, 2);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.DAY_OF_MONTH, 10);
    endTime.set(Calendar.HOUR_OF_DAY, 23);
    event = new WeekViewEvent(8, getEventTitle(startTime), null, startTime, endTime, true);
    event.setColor(getResources().getColor(R.color.event_color_03));
    events.add(event);
    // All day event until 00:00 next day
    startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 10);
    startTime.set(Calendar.HOUR_OF_DAY, 0);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.SECOND, 0);
    startTime.set(Calendar.MILLISECOND, 0);
    startTime.set(Calendar.MONTH, newMonth - 1);
    startTime.set(Calendar.YEAR, newYear);
    endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.DAY_OF_MONTH, 11);
    event = new WeekViewEvent(8, getEventTitle(startTime), null, startTime, endTime, true);
    event.setColor(getResources().getColor(R.color.event_color_01));
    events.add(event);
    return events;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) WeekViewEvent(com.alamkanak.weekview.WeekViewEvent)

Example 2 with WeekViewEvent

use of com.alamkanak.weekview.WeekViewEvent in project Android-Week-View by alamkanak.

the class AsynchronousActivity method onMonthChange.

@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    // downloaded using retrofit, visit http://square.github.io/retrofit
    if (!calledNetwork) {
        RestAdapter retrofit = new RestAdapter.Builder().setEndpoint("https://api.myjson.com/bins").build();
        MyJsonService service = retrofit.create(MyJsonService.class);
        service.listEvents(this);
        calledNetwork = true;
    }
    // Return only the events that matches newYear and newMonth.
    List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
    for (WeekViewEvent event : events) {
        if (eventMatches(event, newYear, newMonth)) {
            matchedEvents.add(event);
        }
    }
    return matchedEvents;
}
Also used : MyJsonService(com.alamkanak.weekview.sample.apiclient.MyJsonService) ArrayList(java.util.ArrayList) RestAdapter(retrofit.RestAdapter) WeekViewEvent(com.alamkanak.weekview.WeekViewEvent)

Example 3 with WeekViewEvent

use of com.alamkanak.weekview.WeekViewEvent in project Android-Week-View by alamkanak.

the class Event method toWeekViewEvent.

@SuppressLint("SimpleDateFormat")
public WeekViewEvent toWeekViewEvent() {
    // Parse time.
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    Date start = new Date();
    Date end = new Date();
    try {
        start = sdf.parse(getStartTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    try {
        end = sdf.parse(getEndTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    // Initialize start and end time.
    Calendar now = Calendar.getInstance();
    Calendar startTime = (Calendar) now.clone();
    startTime.setTimeInMillis(start.getTime());
    startTime.set(Calendar.YEAR, now.get(Calendar.YEAR));
    startTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
    startTime.set(Calendar.DAY_OF_MONTH, getDayOfMonth());
    Calendar endTime = (Calendar) startTime.clone();
    endTime.setTimeInMillis(end.getTime());
    endTime.set(Calendar.YEAR, startTime.get(Calendar.YEAR));
    endTime.set(Calendar.MONTH, startTime.get(Calendar.MONTH));
    endTime.set(Calendar.DAY_OF_MONTH, startTime.get(Calendar.DAY_OF_MONTH));
    // Create an week view event.
    WeekViewEvent weekViewEvent = new WeekViewEvent();
    weekViewEvent.setName(getName());
    weekViewEvent.setStartTime(startTime);
    weekViewEvent.setEndTime(endTime);
    weekViewEvent.setColor(Color.parseColor(getColor()));
    return weekViewEvent;
}
Also used : Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) WeekViewEvent(com.alamkanak.weekview.WeekViewEvent) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint)

Aggregations

WeekViewEvent (com.alamkanak.weekview.WeekViewEvent)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 SuppressLint (android.annotation.SuppressLint)1 MyJsonService (com.alamkanak.weekview.sample.apiclient.MyJsonService)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 RestAdapter (retrofit.RestAdapter)1