Java Code Examples for java.util.Calendar.getMinimum()

The following are Jave code examples for showing how to use getMinimum() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Tasks   File: TaskListFragment.java   View Source Code Vote up 5 votes
private void addRepeatTask(Task task){
    task.setAlreadyRepeating(true);

    Calendar repeatCalender = Calendar.getInstance();
    repeatCalender.setTimeInMillis(dateDialog.getDatePicker().getMaxDate());

    Calendar taskCalender = task.getTaskDate();

    int currentYear = taskCalender.get(Calendar.YEAR);
    int maxYear = repeatCalender.get(Calendar.YEAR);

    switch (task.getRepeatCategory()){
        case 1:
            int currentWeek = taskCalender.get(Calendar.WEEK_OF_YEAR);
            int maxWeek = repeatCalender.getMaximum(Calendar.WEEK_OF_YEAR);
            Log.d(TAG, "Adding weekly repeat task");
            while (currentYear < maxYear){
                if (currentYear > todayCalender.get(Calendar.YEAR)){
                    currentWeek = repeatCalender.getMinimum(Calendar.WEEK_OF_YEAR)- 1;
                }
                taskCalender.set(Calendar.YEAR, currentYear);
                while (currentWeek < maxWeek){
                    taskCalender.set(Calendar.WEEK_OF_YEAR, ++currentWeek);
                    task.setTaskDate(taskCalender);
                    presenter.addTask(task, true);
                    Log.d(TAG, "Adding for week - " + currentWeek);
                }
                currentYear++;
                Log.d(TAG, "Adding for year - " + currentYear);
            }
            break;
        case 2:
            int currentMonth = taskCalender.get(Calendar.MONTH);
            int maxMonth = repeatCalender.getMaximum(Calendar.MONTH);
            Log.d(TAG, "Adding monthly repeat task");
            while (currentYear < maxYear){
                if (currentYear > todayCalender.get(Calendar.YEAR)){
                    currentMonth = repeatCalender.getMinimum(Calendar.MONTH) - 1;
                }
                taskCalender.set(Calendar.YEAR, currentYear);
                while (currentMonth < maxMonth){
                    taskCalender.set(Calendar.MONTH,
                            ++currentMonth);
                    task.setTaskDate(taskCalender);
                    presenter.addTask(task, true);
                }
                currentYear++;
            }
            break;
        case 3:
            while (currentYear < maxYear){
                Log.d(TAG, "Adding yearly repeat task");
                taskCalender.set(Calendar.YEAR,
                        ++currentYear);
                task.setTaskDate(taskCalender);
                presenter.addTask(task, true);
            }
            break;
    }
}