use of dev.hawala.xns.level4.common.Time2.Time in project Etar-Calendar by Etar-Group.
the class CalendarViewAdapter method buildWeekDate.
private String buildWeekDate() {
// Calculate the start of the week, taking into account the "first day of the week"
// setting.
Time t = new Time(mTimeZone);
t.set(mMilliTime);
int firstDayOfWeek = Utils.getFirstDayOfWeek(mContext);
int dayOfWeek = t.getWeekDay();
int diff = dayOfWeek - firstDayOfWeek;
if (diff != 0) {
if (diff < 0) {
diff += 7;
}
t.setDay(t.getDay() - diff);
t.normalize();
}
long weekStartTime = t.toMillis();
// The end of the week is 6 days after the start of the week
long weekEndTime = weekStartTime + DateUtils.WEEK_IN_MILLIS - DateUtils.DAY_IN_MILLIS;
// If week start and end is in 2 different months, use short months names
Time t1 = new Time(mTimeZone);
t1.set(weekEndTime);
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
if (t.getMonth() != t1.getMonth()) {
flags |= DateUtils.FORMAT_ABBREV_MONTH;
}
mStringBuilder.setLength(0);
String date = DateUtils.formatDateRange(mContext, mFormatter, weekStartTime, weekEndTime, flags, mTimeZone).toString();
return date;
}
use of dev.hawala.xns.level4.common.Time2.Time in project Etar-Calendar by Etar-Group.
the class CalendarViewAdapter method buildLunarInfo.
private void buildLunarInfo() {
if (mLunarLoader == null || TextUtils.isEmpty(mTimeZone))
return;
Time time = new Time(mTimeZone);
if (time != null) {
// The the current month.
time.set(mMilliTime);
// As the first day of previous month;
Calendar from = Calendar.getInstance();
from.set(time.getYear(), time.getMonth() - 1, 1);
// Get the last day of next month.
Calendar to = Calendar.getInstance();
to.set(Calendar.YEAR, time.getYear());
to.set(Calendar.MONTH, time.getMonth() + 1);
to.set(Calendar.DAY_OF_MONTH, to.getMaximum(Calendar.DAY_OF_MONTH));
// Call LunarUtils to load the info.
mLunarLoader.load(from.get(Calendar.YEAR), from.get(Calendar.MONTH), from.get(Calendar.DAY_OF_MONTH), to.get(Calendar.YEAR), to.get(Calendar.MONTH), to.get(Calendar.DAY_OF_MONTH));
}
}
use of dev.hawala.xns.level4.common.Time2.Time in project Etar-Calendar by Etar-Group.
the class CalendarViewAdapter method buildDayOfWeek.
// Builds a string with the day of the week and the word yesterday/today/tomorrow
// before it if applicable.
private String buildDayOfWeek() {
Time t = new Time(mTimeZone);
t.set(mMilliTime);
long julianDay = Time.getJulianDay(mMilliTime, t.getGmtOffset());
String dayOfWeek = null;
mStringBuilder.setLength(0);
if (julianDay == mTodayJulianDay) {
dayOfWeek = mContext.getString(R.string.agenda_today, DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
} else if (julianDay == mTodayJulianDay - 1) {
dayOfWeek = mContext.getString(R.string.agenda_yesterday, DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
} else if (julianDay == mTodayJulianDay + 1) {
dayOfWeek = mContext.getString(R.string.agenda_tomorrow, DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
} else {
dayOfWeek = DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString();
}
return dayOfWeek.toUpperCase();
}
use of dev.hawala.xns.level4.common.Time2.Time in project Etar-Calendar by Etar-Group.
the class DayView method init.
private void init(Context context) {
setFocusable(true);
// Allow focus in touch mode so that we can do keyboard shortcuts
// even after we've entered touch mode.
setFocusableInTouchMode(true);
setClickable(true);
setOnCreateContextMenuListener(this);
mFirstDayOfWeek = Utils.getFirstDayOfWeek(context);
mCurrentTime = new Time(Utils.getTimeZone(context, mTZUpdater));
long currentTime = System.currentTimeMillis();
mCurrentTime.set(currentTime);
mTodayJulianDay = Time.getJulianDay(currentTime, mCurrentTime.getGmtOffset());
mWeek_todayColor = DynamicTheme.getColor(mContext, "week_today");
mWeek_saturdayColor = DynamicTheme.getColor(mContext, "week_saturday");
mWeek_sundayColor = DynamicTheme.getColor(mContext, "week_sunday");
mCalendarDateBannerTextColor = DynamicTheme.getColor(mContext, "calendar_date_banner_text_color");
mFutureBgColorRes = DynamicTheme.getColor(mContext, "calendar_future_bg_color");
mBgColor = DynamicTheme.getColor(mContext, "calendar_hour_background");
mCalendarHourLabelColor = DynamicTheme.getColor(mContext, "calendar_hour_label");
mCalendarGridAreaSelected = DynamicTheme.getColor(mContext, "calendar_grid_area_selected");
mCalendarGridLineInnerHorizontalColor = DynamicTheme.getColor(mContext, "calendar_grid_line_inner_horizontal_color");
mCalendarGridLineInnerVerticalColor = DynamicTheme.getColor(mContext, "calendar_grid_line_inner_vertical_color");
mPressedColor = DynamicTheme.getColor(mContext, "pressed");
mClickedColor = DynamicTheme.getColor(mContext, "day_event_clicked_background_color");
mEventTextColor = DynamicTheme.getColor(mContext, "calendar_event_text_color");
mMoreEventsTextColor = DynamicTheme.getColor(mContext, "month_event_other_color");
int gridLineColor = mResources.getColor(R.color.calendar_grid_line_highlight_color);
Paint p = mSelectionPaint;
p.setColor(gridLineColor);
p.setStyle(Style.FILL);
p.setAntiAlias(false);
p = mPaint;
p.setAntiAlias(true);
// Allocate space for 2 weeks worth of weekday names so that we can
// easily start the week display at any week day.
mDayStrs = new String[14];
// Also create an array of 2-letter abbreviations.
mDayStrs2Letter = new String[14];
for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
int index = i - Calendar.SUNDAY;
// e.g. Tue for Tuesday
mDayStrs[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_MEDIUM);
mDayStrs[index + 7] = mDayStrs[index];
// e.g. Tu for Tuesday
mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORT);
// If we don't have 2-letter day strings, fall back to 1-letter.
if (mDayStrs2Letter[index].equals(mDayStrs[index])) {
mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORTEST);
}
mDayStrs2Letter[index + 7] = mDayStrs2Letter[index];
}
// Figure out how much space we need for the 3-letter abbrev names
// in the worst case.
p.setTextSize(DATE_HEADER_FONT_SIZE);
p.setTypeface(mBold);
String[] dateStrs = { " 28", " 30" };
mDateStrWidth = computeMaxStringWidth(0, dateStrs, p);
p.setTextSize(DAY_HEADER_FONT_SIZE);
mDateStrWidth += computeMaxStringWidth(0, mDayStrs, p);
p.setTextSize(HOURS_TEXT_SIZE);
p.setTypeface(null);
handleOnResume();
String[] timeStrs = { "12 AM", "12 PM", "22:00" };
p.setTextSize(HOURS_TEXT_SIZE);
mHoursWidth = HOURS_MARGIN + computeMaxStringWidth(mHoursWidth, timeStrs, p);
GRID_LINE_LEFT_MARGIN = mHoursWidth;
LayoutInflater inflater;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPopupView = inflater.inflate(R.layout.bubble_event, null);
mPopupView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mPopup = new PopupWindow(context);
mPopup.setContentView(mPopupView);
Resources.Theme dialogTheme = getResources().newTheme();
dialogTheme.applyStyle(android.R.style.Theme_Dialog, true);
TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
mPopup.setBackgroundDrawable(ta.getDrawable(0));
ta.recycle();
// Enable touching the popup window
mPopupView.setOnClickListener(this);
// Catch long clicks for creating a new event
setOnLongClickListener(this);
mBaseDate = new Time(Utils.getTimeZone(context, mTZUpdater));
long millis = System.currentTimeMillis();
mBaseDate.set(millis);
mEarliestStartHour = new int[mNumDays];
mHasAllDayEvent = new boolean[mNumDays];
// mLines is the array of points used with Canvas.drawLines() in
// drawGridBackground() and drawAllDayEvents(). Its size depends
// on the max number of lines that can ever be drawn by any single
// drawLines() call in either of those methods.
final int maxGridLines = // max horizontal lines we might draw
(24 + 1) + // max vertical lines we might draw
(mNumDays + 1);
mLines = new float[maxGridLines * 4];
}
use of dev.hawala.xns.level4.common.Time2.Time in project ddf by codice.
the class CertificateSigningRequestTest method testNewCertificateBuilderWithSan.
@Test
public void testNewCertificateBuilderWithSan() throws Exception {
final DateTime start = DateTime.now().minusDays(1);
final DateTime end = start.plusYears(100);
final KeyPair kp = makeKeyPair();
csr.setSerialNumber(1);
csr.setNotBefore(start);
csr.setNotAfter(end);
csr.setCommonName("A");
csr.setSubjectKeyPair(kp);
csr.addSubjectAlternativeNames("IP:1.2.3.4", "DNS:A");
final X509Certificate issuerCert = mock(X509Certificate.class);
doReturn(new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US")).when(issuerCert).getSubjectX500Principal();
final JcaX509v3CertificateBuilder builder = csr.newCertificateBuilder(issuerCert);
final X509CertificateHolder holder = builder.build(new DemoCertificateAuthority().getContentSigner());
assertThat(holder.getSerialNumber(), equalTo(BigInteger.ONE));
assertThat(holder.getNotBefore(), equalTo(new Time(start.toDate()).getDate()));
assertThat(holder.getNotAfter(), equalTo(new Time(end.toDate()).getDate()));
assertThat(holder.getSubject().toString(), equalTo("cn=A"));
assertThat("Unable to validate public key", holder.getSubjectPublicKeyInfo(), equalTo(SubjectPublicKeyInfo.getInstance(kp.getPublic().getEncoded())));
final org.bouncycastle.asn1.x509.Extension csn = holder.getExtension(org.bouncycastle.asn1.x509.Extension.subjectAlternativeName);
assertThat(csn.getParsedValue().toASN1Primitive().getEncoded(ASN1Encoding.DER), equalTo(new GeneralNamesBuilder().addName(new GeneralName(GeneralName.iPAddress, "1.2.3.4")).addName(new GeneralName(GeneralName.dNSName, "A")).build().getEncoded(ASN1Encoding.DER)));
}
Aggregations