use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.
the class TimeTest method disableTestSetJulianDay.
@Suppress
public void disableTestSetJulianDay() throws Exception {
Time time = new Time();
// test that we can set the Julian day correctly.
for (int monthDay = 1; monthDay <= 366; monthDay++) {
for (int zoneIndex = 0; zoneIndex < mTimeZones.length; zoneIndex++) {
// We leave the "month" as zero because we are changing the
// "monthDay" from 1 to 366. The call to normalize() will
// then change the "month" (but we don't really care).
time.set(0, 0, 0, monthDay, 0, 2008);
time.timezone = mTimeZones[zoneIndex];
long millis = time.normalize(true);
if (zoneIndex == 0) {
Log.i("TimeTest", time.format("%B %d, %Y"));
}
int julianDay = Time.getJulianDay(millis, time.gmtoff);
time.setJulianDay(julianDay);
// Some places change daylight saving time at 12am and so there
// is no 12am on some days in some timezones. In those cases,
// the time is set to 1am.
// Examples: Africa/Cairo on April 25, 2008
// America/Sao_Paulo on October 12, 2008
// Atlantic/Azores on March 30, 2008
assertTrue(time.hour == 0 || time.hour == 1);
assertEquals(0, time.minute);
assertEquals(0, time.second);
millis = time.toMillis(false);
int day = Time.getJulianDay(millis, time.gmtoff);
if (day != julianDay) {
Log.i("TimeTest", "Error: gmtoff " + (time.gmtoff / 3600.0) + " day " + julianDay + " millis " + millis + " " + time.format("%B %d, %Y") + " " + time.timezone);
}
assertEquals(day, julianDay);
}
}
}
use of android.text.format.Time in project k-9 by k9mail.
the class K9 method isQuietTime.
public static boolean isQuietTime() {
if (!mQuietTimeEnabled) {
return false;
}
Time time = new Time();
time.setToNow();
Integer startHour = Integer.parseInt(mQuietTimeStarts.split(":")[0]);
Integer startMinute = Integer.parseInt(mQuietTimeStarts.split(":")[1]);
Integer endHour = Integer.parseInt(mQuietTimeEnds.split(":")[0]);
Integer endMinute = Integer.parseInt(mQuietTimeEnds.split(":")[1]);
Integer now = (time.hour * 60) + time.minute;
Integer quietStarts = startHour * 60 + startMinute;
Integer quietEnds = endHour * 60 + endMinute;
// If start and end times are the same, we're never quiet
if (quietStarts.equals(quietEnds)) {
return false;
}
// 21:00 - 05:00 means we want to be quiet if it's after 9 or before 5
if (quietStarts > quietEnds) {
// if it's 22:00 or 03:00 but not 8:00
if (now >= quietStarts || now <= quietEnds) {
return true;
}
} else // 01:00 - 05:00
{
// if it' 2:00 or 4:00 but not 8:00 or 0:00
if (now >= quietStarts && now <= quietEnds) {
return true;
}
}
return false;
}
use of android.text.format.Time in project android-betterpickers by code-troopers.
the class SampleRecurrenceForcedOn method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_and_button);
mResultTextView = (TextView) findViewById(R.id.text);
Button button = (Button) findViewById(R.id.button);
mResultTextView.setText(R.string.no_value);
button.setText(R.string.recurrence_picker_set);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
Bundle bundle = new Bundle();
Time time = new Time();
time.setToNow();
bundle.putLong(RecurrencePickerDialogFragment.BUNDLE_START_TIME_MILLIS, time.toMillis(false));
bundle.putString(RecurrencePickerDialogFragment.BUNDLE_TIME_ZONE, time.timezone);
bundle.putBoolean(RecurrencePickerDialogFragment.BUNDLE_HIDE_SWITCH_BUTTON, true);
// may be more efficient to serialize and pass in EventRecurrence
bundle.putString(RecurrencePickerDialogFragment.BUNDLE_RRULE, mRrule);
RecurrencePickerDialogFragment dialogFragment = (RecurrencePickerDialogFragment) fm.findFragmentByTag(FRAG_TAG_RECUR_PICKER);
if (dialogFragment != null) {
dialogFragment.dismiss();
}
dialogFragment = new RecurrencePickerDialogFragment();
dialogFragment.setArguments(bundle);
dialogFragment.setOnRecurrenceSetListener(SampleRecurrenceForcedOn.this);
dialogFragment.show(fm, FRAG_TAG_RECUR_PICKER);
}
});
}
use of android.text.format.Time in project android-betterpickers by code-troopers.
the class MonthView method setMonthParams.
/**
* Sets all the parameters for displaying this week. The only required parameter is the week number. Other
* parameters have a default value and will only update if a new value is included, except for focus month, which
* will always default to no focus month if no value is passed in. See {@link #VIEW_PARAMS_HEIGHT} for more info on
* parameters.
*
* @param params A map of the new parameters, see {@link #VIEW_PARAMS_HEIGHT}
*/
public void setMonthParams(HashMap<String, Integer> params) {
if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
throw new InvalidParameterException("You must specify month and year for this view");
}
setTag(params);
// We keep the current value for any params not present
if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
if (mRowHeight < MIN_HEIGHT) {
mRowHeight = MIN_HEIGHT;
}
}
if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
}
if (params.containsKey(VIEW_PARAMS_RANGE_MIN)) {
mRangeMin = params.get(VIEW_PARAMS_RANGE_MIN);
}
if (params.containsKey(VIEW_PARAMS_RANGE_MAX)) {
mRangeMax = params.get(VIEW_PARAMS_RANGE_MAX);
}
// Allocate space for caching the day numbers and focus values
mMonth = params.get(VIEW_PARAMS_MONTH);
mYear = params.get(VIEW_PARAMS_YEAR);
// Figure out what day today is
final Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
mHasToday = false;
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
}
mNumCells = Utils.getDaysInMonth(mMonth, mYear);
for (int i = 0; i < mNumCells; i++) {
final int day = i + 1;
if (sameDay(day, today)) {
mHasToday = true;
mToday = day;
}
}
mNumRows = calculateNumRows();
// Invalidate cached accessibility information.
mTouchHelper.invalidateRoot();
}
use of android.text.format.Time in project Etar-Calendar by Etar-Group.
the class AgendaWindowAdapter method buildAgendaItemFromCursor.
private AgendaItem buildAgendaItemFromCursor(final Cursor cursor, int cursorPosition, boolean isDayHeader) {
if (cursorPosition == -1) {
cursor.moveToFirst();
} else {
cursor.moveToPosition(cursorPosition);
}
AgendaItem agendaItem = new AgendaItem();
agendaItem.begin = cursor.getLong(AgendaWindowAdapter.INDEX_BEGIN);
agendaItem.end = cursor.getLong(AgendaWindowAdapter.INDEX_END);
agendaItem.startDay = cursor.getInt(AgendaWindowAdapter.INDEX_START_DAY);
agendaItem.allDay = cursor.getInt(AgendaWindowAdapter.INDEX_ALL_DAY) != 0;
if (agendaItem.allDay) {
// UTC to Local time conversion
Time time = new Time(mTimeZone);
time.setJulianDay(Time.getJulianDay(agendaItem.begin, 0));
agendaItem.begin = time.toMillis(false);
} else if (isDayHeader) {
// Trim to midnight.
Time time = new Time(mTimeZone);
time.set(agendaItem.begin);
time.hour = 0;
time.minute = 0;
time.second = 0;
agendaItem.begin = time.toMillis(false);
}
// If this is not a day header, then it's an event.
if (!isDayHeader) {
agendaItem.id = cursor.getLong(AgendaWindowAdapter.INDEX_EVENT_ID);
if (agendaItem.allDay) {
Time time = new Time(mTimeZone);
time.setJulianDay(Time.getJulianDay(agendaItem.end, 0));
agendaItem.end = time.toMillis(false);
}
}
return agendaItem;
}
Aggregations