本文整理汇总了Java中android.text.format.Time类的典型用法代码示例。如果您正苦于以下问题:Java Time类的具体用法?Java Time怎么用?Java Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Time类属于android.text.format包,在下文中一共展示了Time类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchPopulateAccessibilityEvent
import android.text.format.Time; //导入依赖的package包/类
/**
* 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);
}
示例2: formatTime
import android.text.format.Time; //导入依赖的package包/类
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);
}
示例3: getDayName
import android.text.format.Time; //导入依赖的package包/类
/**
* 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);
}
}
示例4: a
import android.text.format.Time; //导入依赖的package包/类
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();
}
示例5: updateTime
import android.text.format.Time; //导入依赖的package包/类
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);
}
示例6: formatTime
import android.text.format.Time; //导入依赖的package包/类
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;
}
示例7: createNdefMessage
import android.text.format.Time; //导入依赖的package包/类
/**
* 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;
}
示例8: a
import android.text.format.Time; //导入依赖的package包/类
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();
}
示例9: parse
import android.text.format.Time; //导入依赖的package包/类
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 */);
}
示例10: formatTime
import android.text.format.Time; //导入依赖的package包/类
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;
}
示例11: getDayName
import android.text.format.Time; //导入依赖的package包/类
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);
}
}
示例12: onCreate
import android.text.format.Time; //导入依赖的package包/类
@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();
}
示例13: onCreate
import android.text.format.Time; //导入依赖的package包/类
@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");
}
示例14: getRotation
import android.text.format.Time; //导入依赖的package包/类
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;
}
示例15: timeDay2Day
import android.text.format.Time; //导入依赖的package包/类
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);
}
}