/** * Announce the currently-selected time when launched. */ @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { // Clear the event's current text so that only the current time will be spoken. event.getText().clear(); Time time = new Time(); time.hour = getHours(); time.minute = getMinutes(); long millis = time.normalize(true); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourMode) { flags |= DateUtils.FORMAT_24HOUR; } String timeString = DateUtils.formatDateTime(getContext(), millis, flags); event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(event); }
public static String formatTime(Context context, long when) { // TODO: DateUtils should make this easier Time then = new Time(); then.set(when); Time now = new Time(); now.setToNow(); int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL; if (then.year != now.year) { flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { flags |= DateUtils.FORMAT_SHOW_DATE; } else { flags |= DateUtils.FORMAT_SHOW_TIME; } return DateUtils.formatDateTime(context, when, flags); }
/** * Given a day, returns just the name to use for that day. * E.g "today", "tomorrow", "wednesday". * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return */ public static String getDayName(Context context, long dateInMillis) { // If the date is today, return the localized version of "Today" instead of the actual // day name. Time t = new Time(); t.setToNow(); int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff); int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff); if (julianDay == currentJulianDay) { return context.getString(R.string.today); } else if ( julianDay == currentJulianDay +1 ) { return context.getString(R.string.tomorrow); } else { Time time = new Time(); time.setToNow(); // Otherwise, the format is just the day of the week (e.g "Wednesday". SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE"); return dayFormat.format(dateInMillis); } }
public String a(int i, Thread thread, long j, String str, String str2, Throwable th) { long j2 = j % 1000; Time time = new Time(); time.set(j); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(a(i)).append(LetvUtils.CHARACTER_BACKSLASH).append(time.format("%Y-%m-%d %H:%M:%S")).append('.'); if (j2 < 10) { stringBuilder.append("00"); } else if (j2 < 100) { stringBuilder.append('0'); } stringBuilder.append(j2).append(' ').append('['); if (thread == null) { stringBuilder.append("N/A"); } else { stringBuilder.append(thread.getName()); } stringBuilder.append(']').append('[').append(str).append(']').append(' ').append(str2).append('\n'); if (th != null) { stringBuilder.append("* Exception : \n").append(Log.getStackTraceString(th)).append('\n'); } return stringBuilder.toString(); }
private void updateTime() { // TODO KIO Is this really necessary to creat a calendar? // Calendar calendar = Calendar.getInstance(); // calendar.setTime(mTest.getDate()); Log.d(TAG_KIO, "Inside updateTime() mDate time is: " + mTest.getDate().getTime()); Log.d(TAG_KIO, "Inside updateTime() mDate is: " + mTest.getDate()); Time time = new Time(); time.set(mTest.getDate().getTime()); String timeFormat = time.format("%I:%M"); Log.d(TAG_KIO, "timeFormat is: " + timeFormat); mTimeButton.setText(timeFormat); }
static public String formatTime(int ms) { String res; if (ms <= 0) { res = EMPTY_STRING; } else { Time t = new Time(); t.set(ms); t.switchTimezone(Time.TIMEZONE_UTC); if (ms >= 3600000) { res = t.format(TIME_HOUR); } else if (ms < 60000) res = t.format(TIME_SECOND); else res = t.format(TIME_MINUTE); if (res.charAt(0) == '0') { res = res.substring(1); } } return res; }
/** * Implementation for the CreateNdefMessageCallback interface */ @Override public NdefMessage createNdefMessage(NfcEvent event) { Time time = new Time(); time.setToNow(); String text = ("Beam me up!\n\n" + "Beam Time: " + time.format("%H:%M:%S")); NdefMessage msg = new NdefMessage(NdefRecord.createMime( "application/com.example.android.beam", text.getBytes()) /** * The Android Application Record (AAR) is commented out. When a device * receives a push with an AAR in it, the application specified in the AAR * is guaranteed to run. The AAR overrides the tag dispatch system. * You can add it back in to guarantee that this * activity starts when receiving a beamed message. For now, this code * uses the tag dispatch system. */ //,NdefRecord.createApplicationRecord("com.example.android.beam") ); return msg; }
public String a(int i, Thread thread, long j, String str, String str2, Throwable th) { long j2 = j % 1000; Time time = new Time(); time.set(j); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(a(i)).append('/').append(time.format("%Y-%m-%d %H:%M:%S")).append('.'); if (j2 < 10) { stringBuilder.append("00"); } else if (j2 < 100) { stringBuilder.append('0'); } stringBuilder.append(j2).append(' ').append('['); if (thread == null) { stringBuilder.append("N/A"); } else { stringBuilder.append(thread.getName()); } stringBuilder.append(']').append('[').append(str).append(']').append(' ').append(str2) .append('\n'); if (th != null) { stringBuilder.append("* Exception : \n").append(Log.getStackTraceString(th)).append ('\n'); } return stringBuilder.toString(); }
public static long parse(String timeString) throws IllegalArgumentException { int date = 1; int month = Calendar.JANUARY; int year = 1970; TimeOfDay timeOfDay; Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString); if (rfcMatcher.find()) { date = getDate(rfcMatcher.group(1)); month = getMonth(rfcMatcher.group(2)); year = getYear(rfcMatcher.group(3)); timeOfDay = getTime(rfcMatcher.group(4)); } else { Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString); if (ansicMatcher.find()) { month = getMonth(ansicMatcher.group(1)); date = getDate(ansicMatcher.group(2)); timeOfDay = getTime(ansicMatcher.group(3)); year = getYear(ansicMatcher.group(4)); } else { throw new IllegalArgumentException(); } } // FIXME: Y2038 BUG! if (year >= 2038) { year = 2038; month = Calendar.JANUARY; date = 1; } Time time = new Time(Time.TIMEZONE_UTC); time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date, month, year); return time.toMillis(false /* use isDst */); }
public String formatTime(long ms) { String res; if (ms == 0) { res = ""; } else { Time t = new Time(); t.set(ms); t.switchTimezone(Time.TIMEZONE_UTC); if (ms >= 3600000) { res = t.format("%kh%M'"); } else if (ms < 60000) res = t.format("%S''"); else res = t.format("%M'%S''"); if (res.charAt(0) == '0') { res = res.substring(1); } } return res; }
public String getDayName(long dateInMillis) { // If the date is today, return the localized version of "Today" instead of the actual // day name. Time t = new Time(); t.setToNow(); int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff); int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff); if (julianDay == currentJulianDay) { return mContext.getString(R.string.today); } else if (julianDay == currentJulianDay + 1) { return mContext.getString(R.string.tomorrow); } else if (julianDay == currentJulianDay - 1) { return mContext.getString(R.string.yesterday); } else { Time time = new Time(); time.setToNow(); // Otherwise, the format is just the day of the week (e.g "Wednesday". SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE"); return dayFormat.format(dateInMillis); } }
@Override public void onCreate(SurfaceHolder holder){ super.onCreate(holder); setWatchFaceStyle(new WatchFaceStyle.Builder(IOWatchFace.this) .setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT) .setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE) .setHotwordIndicatorGravity(Gravity.TOP | Gravity.RIGHT) .setShowSystemUiTime(false) .setAcceptsTapEvents(true) .build()); Resources resources=IOWatchFace.this.getResources(); mBackgroundPaint=new Paint(); //mBackgroundPaint.setColor(0xFFFFFFFF); mBackgroundPaint.setColor(0xFF000000); paint=new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1f*getResources().getDisplayMetrics().density); paint.setColor(0xFFFFFFFF); //paint.setStrokeCap(Paint.Cap.ROUND); time=new Time(); }
@Override public void onCreate() { super.onCreate(); Log.d("server",String.valueOf(walk_count)); gClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); gClient.connect(); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); registerSensor(); walk_count = 0; today = new Time(Time.getCurrentTimezone()); today.setToNow(); Log.d("server","service on"); }
private HandRotation getRotation(Time time) { HandRotation rotation = new HandRotation(); float minRotationUnit = 360 / 60; int min = time.minute; float hourH = time.hour < 12 ? (float) time.hour + time.minute / 60f : (float) (time.hour - 12) + time.minute / 60f; rotation.setSecondHand(time.second * minRotationUnit); rotation.setMinuteHand(min * minRotationUnit); rotation.setHourHand(hourH * 5f * minRotationUnit); if (BuildConfig.DEBUG) { String tag = this.getClass().getSimpleName(); Log.d(tag, "時間回転角 = " + String.valueOf(rotation.getHourHand())); Log.d(tag, "分回転角 = " + String.valueOf(rotation.getMinuteHand())); Log.d(tag, "秒回転角 = " + String.valueOf(rotation.getSecondHand())); } return rotation; }
public static int timeDay2Day(int day) { switch (day) { case Time.SUNDAY: return SU; case Time.MONDAY: return MO; case Time.TUESDAY: return TU; case Time.WEDNESDAY: return WE; case Time.THURSDAY: return TH; case Time.FRIDAY: return FR; case Time.SATURDAY: return SA; default: throw new RuntimeException("bad day of week: " + day); } }
/** * Converts the day of the week from android.text.format.Time to java.util.Calendar */ public static int convertDayOfWeekFromTimeToCalendar(int timeDayOfWeek) { switch (timeDayOfWeek) { case Time.MONDAY: return Calendar.MONDAY; case Time.TUESDAY: return Calendar.TUESDAY; case Time.WEDNESDAY: return Calendar.WEDNESDAY; case Time.THURSDAY: return Calendar.THURSDAY; case Time.FRIDAY: return Calendar.FRIDAY; case Time.SATURDAY: return Calendar.SATURDAY; case Time.SUNDAY: return Calendar.SUNDAY; default: throw new IllegalArgumentException("Argument must be between Time.SUNDAY and " + "Time.SATURDAY"); } }
/** * 获取当前时间是否大于12:30 */ public static boolean isRightTime() { // or Time t=new Time("GMT+8"); 加上Time Zone资料。 Time t = new Time(); t.setToNow(); // 取得系统时间。 int hour = t.hour; // 0-23 int minute = t.minute; return hour > 12 || (hour == 12 && minute >= 30); }
public Day(Context context,int day, int year, int month){ this.day = day; this.year = year; this.month = month; this.context = context; Calendar cal = Calendar.getInstance(); cal.set(year, month-1, day); int end = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(year, month, end); TimeZone tz = TimeZone.getDefault(); monthEndDay = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis()))); }
/** * 获取当前时间是否大于12:30 */ public static boolean isRightTime() { Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。 t.setToNow(); // 取得系统时间。 int hour = t.hour; // 0-23 int minute = t.minute; return hour > 12 || (hour == 12 && minute >= 30); }
private Uri generateTimeStampPhotoFileUri() { Uri photoFileUri = null; File outputDir = getPhotoDirectory(); if (outputDir != null) { Time t = new Time(); t.setToNow(); File photoFile = new File(outputDir, System.currentTimeMillis() + ".jpg"); //photoFileUri = Uri.fromFile(photoFile); photoFileUri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", photoFile); } return photoFileUri; }
/** * 将UTC-0时区时间字符串转换成用户时区时间距离1970-01-01的毫秒数. * * @param strUtcTime UTC-0时区的时间字符串 * @param strInFmt 时间格式 * @return 用户时区时间距离1970-01-01的毫秒数. * @throws ParseException 时间转换异常 */ public static long getUserZoneMillis(final String strUtcTime, final String strInFmt) throws ParseException { if (StringUtils.isNull(strUtcTime)) { throw new NullPointerException("参数strUtcTime不能为空"); } else if (StringUtils.isNull(strInFmt)) { throw new NullPointerException("参数strInFmt不能为空"); } long lUtcMillis = parseMillis(strUtcTime, strInFmt); Time time = new Time(); time.setToNow(); long lOffset = time.gmtoff * DateUtils.SECOND_IN_MILLIS; long lUserZoneMillis = lUtcMillis + lOffset; return lUserZoneMillis; }
public static long normalizeDate(long startDate) { // normalize the start date to the beginning of the (UTC) day Time time = new Time(); time.set(startDate); int julianDay = Time.getJulianDay(startDate, time.gmtoff); return time.setJulianDay(julianDay); }
/** * Helper method to convert the database representation of the date into something to display * to users. As classy and polished a user experience as "20140102" is, we can do better. * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return a user-friendly representation of the date. */ public static String getFriendlyDayString(Context context, long dateInMillis, boolean displayLongToday) { // The day string for forecast uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday" (just the day name) // For all days after that: "Mon Jun 8" Time time = new Time(); time.setToNow(); long currentTime = System.currentTimeMillis(); int julianDay = Time.getJulianDay(dateInMillis, time.gmtoff); int currentJulianDay = Time.getJulianDay(currentTime, time.gmtoff); // If the date we're building the String for is today's date, the format // is "Today, June 24" if (displayLongToday && julianDay == currentJulianDay) { String today = context.getString(R.string.today); int formatId = R.string.format_full_friendly_date; return String.format(context.getString( formatId, today, getFormattedMonthDay(context, dateInMillis))); } else if ( julianDay < currentJulianDay + 7 ) { // If the input date is less than a week in the future, just return the day name. return getDayName(context, dateInMillis); } else { // Otherwise, use the form "Mon Jun 3" SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("EEE MMM dd"); return shortenedDateFormat.format(dateInMillis); } }
/** * Converts db date format to the format "Month day", e.g "June 24". * @param context Context to use for resource localization * @param dateInMillis The db formatted date string, expected to be of the form specified * in Utility.DATE_FORMAT * @return The day in the form of a string formatted "December 6" */ public static String getFormattedMonthDay(Context context, long dateInMillis ) { Time time = new Time(); time.setToNow(); SimpleDateFormat dbDateFormat = new SimpleDateFormat(Utility.DATE_FORMAT); SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd"); String monthDayString = monthDayFormat.format(dateInMillis); return monthDayString; }