本文整理汇总了Java中android.text.format.DateFormat.is24HourFormat方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.is24HourFormat方法的具体用法?Java DateFormat.is24HourFormat怎么用?Java DateFormat.is24HourFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.DateFormat
的用法示例。
在下文中一共展示了DateFormat.is24HourFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
static Dialog createDialog(
Bundle args, Context activityContext, @Nullable OnTimeSetListener onTimeSetListener
) {
final Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
boolean is24hour = DateFormat.is24HourFormat(activityContext);
if (args != null) {
hour = args.getInt(TimePickerDialogModule.ARG_HOUR, now.get(Calendar.HOUR_OF_DAY));
minute = args.getInt(TimePickerDialogModule.ARG_MINUTE, now.get(Calendar.MINUTE));
is24hour = args.getBoolean(
TimePickerDialogModule.ARG_IS24HOUR,
DateFormat.is24HourFormat(activityContext));
}
return new DismissableTimePickerDialog(
activityContext,
onTimeSetListener,
hour,
minute,
is24hour);
}
示例2: onDeviceConfigurationChange
import android.text.format.DateFormat; //导入方法依赖的package包/类
public void onDeviceConfigurationChange(Configuration newConfig) {
if (changingConfiguration) {
return;
}
is24HourFormat = DateFormat.is24HourFormat(ApplicationLoader.applicationContext);
systemDefaultLocale = newConfig.locale;
if (languageOverride != null) {
LocaleInfo toSet = currentLocaleInfo;
currentLocaleInfo = null;
applyLanguage(toSet, false);
} else {
Locale newLocale = newConfig.locale;
if (newLocale != null) {
String d1 = newLocale.getDisplayName();
String d2 = currentLocale.getDisplayName();
if (d1 != null && d2 != null && !d1.equals(d2)) {
recreateFormatters();
}
currentLocale = newLocale;
currentPluralRules = allRules.get(currentLocale.getLanguage());
if (currentPluralRules == null) {
currentPluralRules = allRules.get("en");
}
}
}
}
示例3: getChangeSummary
import android.text.format.DateFormat; //导入方法依赖的package包/类
/**
* Produce a summary of the Zen mode change to be read aloud as TTS.
*/
private CharSequence getChangeSummary(int mode, int minutes) {
int indefinite = -1;
int byMinute = -1;
int byHour = -1;
int byTime = -1;
switch (mode) {
case Global.ZEN_MODE_ALARMS:
indefinite = R.string.zen_mode_summary_alarms_only_indefinite;
byMinute = R.plurals.zen_mode_summary_alarms_only_by_minute;
byHour = R.plurals.zen_mode_summary_alarms_only_by_hour;
byTime = R.string.zen_mode_summary_alarms_only_by_time;
break;
case Global.ZEN_MODE_OFF:
indefinite = R.string.zen_mode_summary_always;
break;
};
if (minutes < 0 || mode == Global.ZEN_MODE_OFF) {
return getString(indefinite);
}
long time = System.currentTimeMillis() + minutes * MINUTES_MS;
String skeleton = DateFormat.is24HourFormat(this, UserHandle.myUserId()) ? "Hm" : "hma";
String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
CharSequence formattedTime = DateFormat.format(pattern, time);
Resources res = getResources();
if (minutes < 60) {
return res.getQuantityString(byMinute, minutes, minutes, formattedTime);
} else if (minutes % 60 != 0) {
return res.getString(byTime, formattedTime);
} else {
int hours = minutes / 60;
return res.getQuantityString(byHour, hours, hours, formattedTime);
}
}
示例4: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//Get the default time from the arguments:
int hour = getArguments().getInt("hour");
int minute = getArguments().getInt("minute");
//Return a TimePickerDialog which has a default time of what was set in the constructor:
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
示例5: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
//Use the current time as the default values for the time picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
//Create and return a new instance of TimePickerDialog
/*
public constructor.....
TimePickerDialog(Context context, int theme,
TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)
The 'theme' parameter allow us to specify the theme of TimePickerDialog
.......List of Themes.......
THEME_DEVICE_DEFAULT_DARK
THEME_DEVICE_DEFAULT_LIGHT
THEME_HOLO_DARK
THEME_HOLO_LIGHT
THEME_TRADITIONAL
*/
TimePickerDialog tpd = new TimePickerDialog(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_DARK
,this, hour, minute, DateFormat.is24HourFormat(getActivity()));
//You can set a simple text title for TimePickerDialog
//tpd.setTitle("Title Of Time Picker Dialog");
/*.........Set a custom title for picker........*/
TextView tvTitle = new TextView(getActivity());
tvTitle.setText("TimePickerDialog Title");
tvTitle.setBackgroundColor(Color.parseColor("#EEE8AA"));
tvTitle.setPadding(5, 3, 5, 3);
tvTitle.setGravity(Gravity.CENTER_HORIZONTAL);
tpd.setCustomTitle(tvTitle);
/*.........End custom title section........*/
return tpd;
}
示例6: onBindDialogView
import android.text.format.DateFormat; //导入方法依赖的package包/类
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
if (DateFormat.is24HourFormat(context)) {
time_picker.setIs24HourView(true);
}
//retrieving hour and minute
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
time_picker.setCurrentHour(hour);
int minute = c.get(Calendar.MINUTE);
time_picker.setCurrentMinute(minute);
}
示例7: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
示例8: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
/* Use the last time chosen as the time that is selected when the dialog pops up. This is
* stored in the global variables hour_end and minute_end. If it is the first time
* the dialog is being launched, it will default to the current time.
*/
int hour = ((GraphTabbed)getActivity()).hour_end;
int minute = ((GraphTabbed)getActivity()).minute_end;
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
示例9: TimePicker
import android.text.format.DateFormat; //导入方法依赖的package包/类
/**
* Create a new TimePicker component.
*
* @param container the parent container.
*/
public TimePicker(ComponentContainer container) {
super(container);
form = container.$form();
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
time = new TimePickerDialog(this.container.$context(),
timePickerListener, hour, minute, DateFormat.is24HourFormat(this.container.$context()));
instant = Dates.TimeInstant(hour, minute);
androidUIHandler = new Handler();
}
示例10: setDate
import android.text.format.DateFormat; //导入方法依赖的package包/类
public void setDate(int year, int month, int day){
Calendar calendar = Calendar.getInstance();
int hour, minute;
// int currentYear = calendar.get(Calendar.YEAR);
// int currentMonth = calendar.get(Calendar.MONTH);
// int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
Calendar reminderCalendar = Calendar.getInstance();
reminderCalendar.set(year, month, day);
if(reminderCalendar.before(calendar)){
Toast.makeText(this, "My time-machine is a bit rusty", Toast.LENGTH_SHORT).show();
return;
}
if(mUserReminderDate!=null){
calendar.setTime(mUserReminderDate);
}
if(DateFormat.is24HourFormat(this)){
hour = calendar.get(Calendar.HOUR_OF_DAY);
}
else{
hour = calendar.get(Calendar.HOUR);
}
minute = calendar.get(Calendar.MINUTE);
calendar.set(year, month, day, hour, minute);
mUserReminderDate = calendar.getTime();
setReminderTextView();
// setDateAndTimeEditText();
setDateEditText();
}
示例11: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
return new TimePickerDialog(context, timeSetListener, hour, minute,
DateFormat.is24HourFormat(context));
}
示例12: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
示例13: onCreateDialog
import android.text.format.DateFormat; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
示例14: getDetailedDateFormatter
import android.text.format.DateFormat; //导入方法依赖的package包/类
public static SimpleDateFormat getDetailedDateFormatter(Context context, Locale locale) {
String dateFormatPattern;
if (DateFormat.is24HourFormat(context)) {
dateFormatPattern = getLocalizedPattern("MMM d, yyyy HH:mm:ss zzz", locale);
} else {
dateFormatPattern = getLocalizedPattern("MMM d, yyyy hh:mm:ss a zzz", locale);
}
return new SimpleDateFormat(dateFormatPattern, locale);
}
示例15: getDateTimeInterpreter
import android.text.format.DateFormat; //导入方法依赖的package包/类
/**
* Get the interpreter which provides the text to show in the header column and the header row.
* @return The date, time interpreter.
*/
public DateTimeInterpreter getDateTimeInterpreter() {
if (mDateTimeInterpreter == null) {
mDateTimeInterpreter = new DateTimeInterpreter() {
@Override
public String interpretDate(Calendar date) {
try {
SimpleDateFormat sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE M/dd", Locale.getDefault()) : new SimpleDateFormat("EEE M/dd", Locale.getDefault());
return sdf.format(date.getTime()).toUpperCase();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
@Override
public String interpretTime(int hour) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, 0);
try {
SimpleDateFormat sdf = DateFormat.is24HourFormat(getContext()) ? new SimpleDateFormat("HH:mm", Locale.getDefault()) : new SimpleDateFormat("hh a", Locale.getDefault());
return sdf.format(calendar.getTime());
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
};
}
return mDateTimeInterpreter;
}