List of usage examples for org.joda.time DateTimeUtils fromJulianDay
public static final long fromJulianDay(double julianDay)
From source file:com.android.calendar.DayView.java
License:Apache License
/** * Returns the start of the selected time in milliseconds since the epoch. * * @return selected time in UTC milliseconds since the epoch. *///ww w . j a v a 2s .com long getSelectedTimeInMillis() { Time time = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(mSelectionDay); time.set(milis); time.hour = mSelectionHour; // We ignore the "isDst" field because we want normalize() to figure // out the correct DST value and not adjust the selected time based // on the current setting of DST. return time.normalize(true /* ignore isDst */); }
From source file:com.android.calendar.DayView.java
License:Apache License
Time getSelectedTime() { Time time = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(mSelectionDay); time.set(milis);/*w ww .j a va2 s. c o m*/ time.hour = mSelectionHour; // We ignore the "isDst" field because we want normalize() to figure // out the correct DST value and not adjust the selected time based // on the current setting of DST. time.normalize(true /* ignore isDst */); return time; }
From source file:com.android.calendar.DayView.java
License:Apache License
Time getSelectedTimeForAccessibility() { Time time = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(mSelectionDayForAccessibility); time.set(milis);//from w ww . jav a 2 s.c o m time.hour = mSelectionHourForAccessibility; // We ignore the "isDst" field because we want normalize() to figure // out the correct DST value and not adjust the selected time based // on the current setting of DST. time.normalize(true /* ignore isDst */); return time; }
From source file:com.android.calendar.DayView.java
License:Apache License
public Time getSelectedDay() { Time time = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(mSelectionDay); time.set(milis);//w ww. ja v a2 s.co m time.hour = mSelectionHour; // We ignore the "isDst" field because we want normalize() to figure // out the correct DST value and not adjust the selected time based // on the current setting of DST. time.normalize(true /* ignore isDst */); return time; }
From source file:com.android.calendar.DayView.java
License:Apache License
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mSelectionMode == SELECTION_HIDDEN) { if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { // Display the selection box but don't move or select it // on this key press. mSelectionMode = SELECTION_SELECTED; invalidate();// ww w .j av a 2 s.c o m return true; } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { // Display the selection box but don't select it // on this key press. mSelectionMode = SELECTION_PRESSED; invalidate(); return true; } } mSelectionMode = SELECTION_SELECTED; mScrolling = false; boolean redraw; int selectionDay = mSelectionDay; switch (keyCode) { case KeyEvent.KEYCODE_DEL: // Delete the selected event, if any Event selectedEvent = mSelectedEvent; if (selectedEvent == null) { return false; } mPopup.dismiss(); mLastPopupEventID = INVALID_EVENT_ID; long begin = selectedEvent.startMillis; long end = selectedEvent.endMillis; long id = selectedEvent.id; mDeleteEventHelper.delete(begin, end, id, -1); return true; case KeyEvent.KEYCODE_ENTER: switchViews(true /* trackball or keyboard */); return true; case KeyEvent.KEYCODE_BACK: if (event.getRepeatCount() == 0) { event.startTracking(); return true; } return super.onKeyDown(keyCode, event); case KeyEvent.KEYCODE_DPAD_LEFT: if (mSelectedEvent != null) { setSelectedEvent(mSelectedEvent.nextLeft); } if (mSelectedEvent == null) { mLastPopupEventID = INVALID_EVENT_ID; selectionDay -= 1; } redraw = true; break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (mSelectedEvent != null) { setSelectedEvent(mSelectedEvent.nextRight); } if (mSelectedEvent == null) { mLastPopupEventID = INVALID_EVENT_ID; selectionDay += 1; } redraw = true; break; case KeyEvent.KEYCODE_DPAD_UP: if (mSelectedEvent != null) { setSelectedEvent(mSelectedEvent.nextUp); } if (mSelectedEvent == null) { mLastPopupEventID = INVALID_EVENT_ID; if (!mSelectionAllday) { setSelectedHour(mSelectionHour - 1); adjustHourSelection(); mSelectedEvents.clear(); mComputeSelectedEvents = true; } } redraw = true; break; case KeyEvent.KEYCODE_DPAD_DOWN: if (mSelectedEvent != null) { setSelectedEvent(mSelectedEvent.nextDown); } if (mSelectedEvent == null) { mLastPopupEventID = INVALID_EVENT_ID; if (mSelectionAllday) { mSelectionAllday = false; } else { setSelectedHour(mSelectionHour + 1); adjustHourSelection(); mSelectedEvents.clear(); mComputeSelectedEvents = true; } } redraw = true; break; default: return super.onKeyDown(keyCode, event); } if ((selectionDay < mFirstJulianDay) || (selectionDay > mLastJulianDay)) { DayView view = (DayView) mViewSwitcher.getNextView(); Time date = view.mBaseDate; date.set(mBaseDate); if (selectionDay < mFirstJulianDay) { date.monthDay -= mNumDays; } else { date.monthDay += mNumDays; } date.normalize(true /* ignore isDst */); view.setSelectedDay(selectionDay); initView(view); Time end = new Time(date); end.monthDay += mNumDays - 1; mController.sendEvent(this, EventType.GO_TO, date, end, -1, ViewType.CURRENT); return true; } if (mSelectionDay != selectionDay) { Time date = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(selectionDay); date.set(milis); date.hour = mSelectionHour; mController.sendEvent(this, EventType.GO_TO, date, date, -1, ViewType.CURRENT); } setSelectedDay(selectionDay); mSelectedEvents.clear(); mComputeSelectedEvents = true; mUpdateToast = true; if (redraw) { invalidate(); return true; } return super.onKeyDown(keyCode, event); }
From source file:com.android.calendar.DayView.java
License:Apache License
private void drawDayHeaderLoop(Rect r, Canvas canvas, Paint p) { // Draw the horizontal day background banner // p.setColor(mCalendarDateBannerBackground); // r.top = 0; // r.bottom = DAY_HEADER_HEIGHT; // r.left = 0; // r.right = mHoursWidth + mNumDays * (mCellWidth + DAY_GAP); // canvas.drawRect(r, p); ///*w w w. ja v a 2 s. c o m*/ // Fill the extra space on the right side with the default background // r.left = r.right; // r.right = mViewWidth; // p.setColor(mCalendarGridAreaBackground); // canvas.drawRect(r, p); if (mNumDays == 1 && ONE_DAY_HEADER_HEIGHT == 0) { return; } p.setTypeface(mBold); p.setTextAlign(Paint.Align.RIGHT); int cell = mFirstJulianDay; String[] dayNames; if (mDateStrWidth < mCellWidth) { dayNames = mDayStrs; } else { dayNames = mDayStrs2Letter; } p.setAntiAlias(true); for (int day = 0; day < mNumDays; day++, cell++) { int dayOfWeek = day + mFirstVisibleDayOfWeek; if (dayOfWeek >= 14) { dayOfWeek -= 14; } int color = mCalendarDateBannerTextColor; if (mNumDays == 1) { // if (dayOfWeek == Time.SATURDAY) { // color = mWeek_saturdayColor; // } else if (dayOfWeek == Time.SUNDAY) { // color = mWeek_sundayColor; // } } else { long millis = DateTimeUtils.fromJulianDay(mFirstJulianDay + day); if (OccasionHelper.isHolliday(millis)) { color = mWeek_hollidayColor; } // final int column = day % 7; // if (Utils.isFriday(column, mFirstDayOfWeek)) { // color = mWeek_hollidayColor; // } // if (Utils.isSaturday(column, mFirstDayOfWeek)) { // color = mWeek_saturdayColor; // } else if (Utils.isSunday(column, mFirstDayOfWeek)) { // color = mWeek_sundayColor; // } } p.setColor(color); drawDayHeader(dayNames[dayOfWeek], day, cell, canvas, p); } p.setTypeface(null); }
From source file:com.android.calendar.DayView.java
License:Apache License
private void drawDayHeader(String dayStr, int day, int cell, Canvas canvas, Paint p) { int julianDay = mFirstJulianDay + day; Time time = new Time(); long milis = DateTimeUtils.fromJulianDay(julianDay); time.set(milis);//w ww.j a v a 2 s .co m int dateNum = Jalali.gregorianToJalali(time).day; int x; // if (dateNum > mMonthLength) { // dateNum -= mMonthLength; // } p.setAntiAlias(true); int todayIndex = mTodayJulianDay - mFirstJulianDay; // Draw day of the month String dateNumStr = Jalali.persianDigits(String.valueOf(dateNum)); if (mNumDays > 1) { float y = -1; if (LunarUtils.showLunar(mContext)) { y = DAY_HEADER_HEIGHT - DAY_HEADER_BOTTOM_MARGIN - DATE_HEADER_FONT_SIZE - 2; } else { y = DAY_HEADER_HEIGHT - DAY_HEADER_BOTTOM_MARGIN; } // Draw day of the month x = computeDayRightPosition(day) - DAY_HEADER_RIGHT_MARGIN; p.setTextAlign(Align.RIGHT); p.setTextSize(DATE_HEADER_FONT_SIZE); p.setTypeface(todayIndex == day ? mBold : Typeface.DEFAULT); canvas.drawText(dateNumStr, x, y, p); // Draw day of the week int dateX = (int) (x - p.measureText(" " + dateNumStr)); p.setTextSize(DAY_HEADER_FONT_SIZE); p.setTypeface(Typeface.DEFAULT); canvas.drawText(dayStr, dateX, y, p); // To show the lunar info. if (LunarUtils.showLunar(mContext)) { // adjust the year and month int month = mBaseDate.month; int year = mBaseDate.year; if (dateNum > mMonthLength || dateNum < mFirstVisibleDate) { month = month + 1; if (month > 11) { month = 0; year = year + 1; } } String lunarInfo = LunarUtils.get(mContext, year, month, dateNum, LunarUtils.FORMAT_LUNAR_SHORT | LunarUtils.FORMAT_ONE_FESTIVAL, false, null); if (!TextUtils.isEmpty(lunarInfo)) { canvas.drawText(lunarInfo, x, y + DAY_HEADER_FONT_SIZE + 2, p); } } } else { float y = ONE_DAY_HEADER_HEIGHT - DAY_HEADER_ONE_DAY_BOTTOM_MARGIN; p.setTextAlign(Align.LEFT); // Draw day of the week x = computeDayRightPosition(day) + DAY_HEADER_ONE_DAY_LEFT_MARGIN; p.setTextSize(DAY_HEADER_FONT_SIZE); p.setTypeface(Typeface.DEFAULT); canvas.drawText(dayStr, x, y, p); // Draw day of the month x += p.measureText(dayStr) + DAY_HEADER_ONE_DAY_RIGHT_MARGIN; p.setTextSize(DATE_HEADER_FONT_SIZE); p.setTypeface(todayIndex == day ? mBold : Typeface.DEFAULT); canvas.drawText(dateNumStr, x, y, p); } }
From source file:com.android.calendar.DayView.java
License:Apache License
private void doSingleTapUp(MotionEvent ev) { if (!mHandleActionUp || mScrolling) { return;//w w w.j ava 2 s . c o m } int x = (int) ev.getX(); int y = (int) ev.getY(); int selectedDay = mSelectionDay; int selectedHour = mSelectionHour; if (mMaxAlldayEvents > mMaxUnexpandedAlldayEventCount) { // check if the tap was in the allday expansion area int bottom = mFirstCell; if ((x < mHoursWidth && y > DAY_HEADER_HEIGHT && y < DAY_HEADER_HEIGHT + mAlldayHeight) || (!mShowAllAllDayEvents && mAnimateDayHeight == 0 && y < bottom && y >= bottom - MIN_UNEXPANDED_ALLDAY_EVENT_HEIGHT)) { doExpandAllDayClick(); return; } } boolean validPosition = setSelectionFromPosition(x, y, false); if (!validPosition) { if (y < DAY_HEADER_HEIGHT) { Time selectedTime = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(mSelectionDay); selectedTime.set(milis); selectedTime.hour = mSelectionHour; selectedTime.normalize(true /* ignore isDst */); mController.sendEvent(this, EventType.GO_TO, null, null, selectedTime, -1, ViewType.DAY, CalendarController.EXTRA_GOTO_DATE, null, null); } return; } boolean hasSelection = mSelectionMode != SELECTION_HIDDEN; boolean pressedSelected = (hasSelection || mTouchExplorationEnabled) && selectedDay == mSelectionDay && selectedHour == mSelectionHour; if (pressedSelected && mSavedClickedEvent == null) { // If the tap is on an already selected hour slot, then create a new // event long extraLong = 0; if (mSelectionAllday) { extraLong = CalendarController.EXTRA_CREATE_ALL_DAY; } mSelectionMode = SELECTION_SELECTED; mController.sendEventRelatedEventWithExtra(this, EventType.CREATE_EVENT, -1, getSelectedTimeInMillis(), 0, (int) ev.getRawX(), (int) ev.getRawY(), extraLong, -1); } else if (mSelectedEvent != null) { // If the tap is on an event, launch the "View event" view if (mIsAccessibilityEnabled) { mAccessibilityMgr.interrupt(); } mSelectionMode = SELECTION_HIDDEN; int yLocation = (int) ((mSelectedEvent.top + mSelectedEvent.bottom) / 2); // Y location is affected by the position of the event in the // scrolling // view (mViewStartY) and the presence of all day events // (mFirstCell) if (!mSelectedEvent.allDay) { yLocation += (mFirstCell - mViewStartY); } mClickedYLocation = yLocation; long clearDelay = (CLICK_DISPLAY_DURATION + mOnDownDelay) - (System.currentTimeMillis() - mDownTouchTime); if (clearDelay > 0) { this.postDelayed(mClearClick, clearDelay); } else { this.post(mClearClick); } } else { // Select time Time startTime = new Time(mBaseDate); long milis = DateTimeUtils.fromJulianDay(mSelectionDay); startTime.set(milis); startTime.hour = mSelectionHour; startTime.normalize(true /* ignore isDst */); Time endTime = new Time(startTime); endTime.hour++; mSelectionMode = SELECTION_SELECTED; mController.sendEvent(this, EventType.GO_TO, startTime, endTime, -1, ViewType.CURRENT, CalendarController.EXTRA_GOTO_TIME, null, null); } invalidate(); }
From source file:com.android.calendar.month.MonthByWeekFragment.java
License:Apache License
/** * Updates the uri used by the loader according to the current position of * the listview./* w w w. j a v a2s.c om*/ * * @return The new Uri to use */ private Uri updateUri() { SimpleWeekView child = (SimpleWeekView) mListView.getChildAt(0); if (child != null) { int julianDay = child.getFirstJulianDay(); mFirstLoadedJulianDay = julianDay; } // -1 to ensure we get all day events from any time zone long milis = DateTimeUtils.fromJulianDay(mFirstLoadedJulianDay - 1); mTempTime.set(milis); long start = mTempTime.toMillis(true); mLastLoadedJulianDay = mFirstLoadedJulianDay + (mNumWeeks + 2 * WEEKS_BUFFER) * 7; // +1 to ensure we get all day events from any time zone milis = DateTimeUtils.fromJulianDay(mLastLoadedJulianDay + 1); mTempTime.set(milis); long end = mTempTime.toMillis(true); // Create a new uri with the updated times Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, start); ContentUris.appendId(builder, end); return builder.build(); }
From source file:com.android.calendar.month.MonthListView.java
License:Apache License
private void doFling(float velocityY) { // Stop the list-view movement and take over MotionEvent cancelEvent = MotionEvent.obtain(mDownActionTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0); onTouchEvent(cancelEvent);//from ww w . j av a 2 s .c o m // Below the threshold, fling one month. Above the threshold , fling // according to the speed of the fling. int monthsToJump; if (Math.abs(velocityY) < MULTIPLE_MONTH_VELOCITY_THRESHOLD) { if (velocityY < 0) { monthsToJump = 1; } else { // value here is zero and not -1 since by the time the fling is // detected the list moved back one month. monthsToJump = 0; } } else { if (velocityY < 0) { monthsToJump = 1 - (int) ((velocityY + MULTIPLE_MONTH_VELOCITY_THRESHOLD) / FLING_VELOCITY_DIVIDER); } else { monthsToJump = -(int) ((velocityY - MULTIPLE_MONTH_VELOCITY_THRESHOLD) / FLING_VELOCITY_DIVIDER); } } // Get the day at the top right corner int day = getUpperRightJulianDay(); // Get the day of the first day of the next/previous month // (according to scroll direction) long milis = DateTimeUtils.fromJulianDay(day); mTempTime.set(milis); mTempTime.monthDay = 1; mTempTime.month += monthsToJump; long timeInMillis = mTempTime.normalize(false); // Since each view is 7 days, round the target day up to make sure the // scroll will be at least one view. int scrollToDay = Time.getJulianDay(timeInMillis, mTempTime.gmtoff) + ((monthsToJump > 0) ? 6 : 0); // Since all views have the same height, scroll by pixels instead of // "to position". // Compensate for the top view offset from the top. View firstView = getChildAt(0); int firstViewHeight = firstView.getHeight(); // Get visible part length firstView.getLocalVisibleRect(mFirstViewRect); int topViewVisiblePart = mFirstViewRect.bottom - mFirstViewRect.top; int viewsToFling = (scrollToDay - day) / 7 - ((monthsToJump <= 0) ? 1 : 0); int offset = (viewsToFling > 0) ? -(firstViewHeight - topViewVisiblePart + SimpleDayPickerFragment.LIST_TOP_OFFSET) : (topViewVisiblePart - SimpleDayPickerFragment.LIST_TOP_OFFSET); // Fling smoothScrollBy(viewsToFling * firstViewHeight + offset, FLING_TIME); }