FileDocCategorySizeDatePackage
DayOfMonthCursor.javaAPI DocAndroid 1.5 API5349Wed May 06 22:41:56 BST 2009android.util

DayOfMonthCursor

public class DayOfMonthCursor extends MonthDisplayHelper
Helps control and display a month view of a calendar that has a current selected day.
  • Keeps track of current month, day, year
  • Keeps track of current cursor position (row, column)
  • Provides methods to help display the calendar
  • Provides methods to move the cursor up / down / left / right.
This should be used by anyone who presents a month view to users and wishes to behave consistently with other widgets and apps; if we ever change our mind about when to flip the month, we can change it here only.
hide

Fields Summary
private int
mRow
private int
mColumn
Constructors Summary
public DayOfMonthCursor(int year, int month, int dayOfMonth, int weekStartDay)

param
year The initial year.
param
month The initial month.
param
dayOfMonth The initial dayOfMonth.
param
weekStartDay What dayOfMonth of the week the week should start, in terms of {@link java.util.Calendar} constants such as {@link java.util.Calendar#SUNDAY}.

        super(year, month, weekStartDay);
        mRow = getRowOf(dayOfMonth);
        mColumn = getColumnOf(dayOfMonth);
    
Methods Summary
public booleandown()
Move down one box, potentially flipping to the next month.

return
Whether the month was flipped to the next month due to the move.

        if (isWithinCurrentMonth(mRow + 1, mColumn)) {
            // within current month, just move down
            mRow++;
            return false;
        }
        // flip to next month, same column, first position within month
        nextMonth();
        mRow = 0;
        while (!isWithinCurrentMonth(mRow, mColumn)) {
            mRow++;
        }
        return true;
    
public intgetSelectedColumn()

        return mColumn;
    
public intgetSelectedDayOfMonth()

        return getDayAt(mRow, mColumn);
    
public intgetSelectedMonthOffset()

return
0 if the selection is in the current month, otherwise -1 or +1 depending on whether the selection is in the first or last row.

        if (isWithinCurrentMonth(mRow, mColumn)) {
            return 0;
        }
        if (mRow == 0) {
            return -1;
        }
        return 1;
    
public intgetSelectedRow()

        return mRow;
    
public booleanisSelected(int row, int column)

        return (mRow == row) && (mColumn == column);
    
public booleanleft()
Move left one box, potentially flipping to the previous month.

return
Whether the month was flipped to the previous month due to the move.

        if (mColumn == 0) {
            mRow--;
            mColumn = 6;
        } else {
            mColumn--;
        }

        if (isWithinCurrentMonth(mRow, mColumn)) {
            return false;
        }

        // need to flip to last day of previous month
        previousMonth();
        int lastDay = getNumberOfDaysInMonth();
        mRow = getRowOf(lastDay);
        mColumn = getColumnOf(lastDay);
        return true;
    
public booleanright()
Move right one box, potentially flipping to the next month.

return
Whether the month was flipped to the next month due to the move.

        if (mColumn == 6) {
            mRow++;
            mColumn = 0;
        } else {
            mColumn++;
        }

        if (isWithinCurrentMonth(mRow, mColumn)) {
            return false;
        }

        // need to flip to first day of next month
        nextMonth();
        mRow = 0;
        mColumn = 0;
        while (!isWithinCurrentMonth(mRow, mColumn)) {
            mColumn++;
        }
        return true;
    
public voidsetSelectedDayOfMonth(int dayOfMonth)

        mRow = getRowOf(dayOfMonth);
        mColumn = getColumnOf(dayOfMonth);
    
public voidsetSelectedRowColumn(int row, int col)

        mRow = row;
        mColumn = col;
    
public booleanup()
Move up one box, potentially flipping to the previous month.

return
Whether the month was flipped to the previous month due to the move.

        if (isWithinCurrentMonth(mRow - 1, mColumn)) {
            // within current month, just move up
            mRow--;
            return false;
        }
        // flip back to previous month, same column, first position within month
        previousMonth();
        mRow = 5;
        while(!isWithinCurrentMonth(mRow, mColumn)) {
            mRow--;
        }
        return true;