Java Code Examples for android.text.format.DateFormat#is24HourFormat()
The following examples show how to use
android.text.format.DateFormat#is24HourFormat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddLogActivity.java From callmeter with GNU General Public License v3.0 | 6 votes |
@Override public void onClick(final View v) { switch (v.getId()) { case R.id.date: DatePickerDialog dpd = new DatePickerDialog(this, this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); dpd.show(); break; case R.id.time: TimePickerDialog dtp = new TimePickerDialog(this, this, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), DateFormat.is24HourFormat(this)); dtp.show(); break; default: break; } }
Example 2
Source File: TimePreferenceDialog.java From openScale with GNU General Public License v3.0 | 6 votes |
@Override protected void onBindDialogView(View view) { super.onBindDialogView(view); timePicker = view.findViewById(R.id.timePicker); calendar = Calendar.getInstance(); Long timeInMillis = null; DialogPreference preference = getPreference(); if (preference instanceof TimePreference) { TimePreference timePreference = (TimePreference) preference; timeInMillis = timePreference.getTimeInMillis(); } if (timeInMillis != null) { calendar.setTimeInMillis(timeInMillis); boolean is24hour = DateFormat.is24HourFormat(getContext()); timePicker.setIs24HourView(is24hour); timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY)); timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE)); } }
Example 3
Source File: DateAndTimeIndicator.java From MaterialScrollBar with Apache License 2.0 | 6 votes |
@Override protected int getIndicatorWidth() { int width = 62; if(includeYear) { if(includeDay) { width += 14; } width += 56; } if(includeMonth) { width += 43; } if(includeDay) { width += 28; } if(includeTime) { if(DateFormat.is24HourFormat(context)) { width += 70; } else { width += 115; } } return width; }
Example 4
Source File: SettingsFragment.java From QuickLyric with GNU General Public License v3.0 | 6 votes |
@Override public void onTimeSet(RadialPickerLayout radialPickerLayout, int h, int min) { if (nightTimeStart[0] >= 25) { nightTimeStart = new int[]{h, min}; boolean twentyFourHourStyle = DateFormat.is24HourFormat(getActivity()); TimePickerDialog tpd = TimePickerDialog .newInstance(this, 6, 0, twentyFourHourStyle); tpd.setOnCancelListener(this); tpd.setTitle(getActivity().getString(R.string.nighttime_end_dialog_title)); tpd.show(getFragmentManager(), NIGHT_END_TIME_DIALOG_TAG); } else { SharedPreferences current = getActivity().getSharedPreferences("night_time", Context.MODE_PRIVATE); current.edit().putInt("startHour", nightTimeStart[0]) .putInt("startMinute", nightTimeStart[1]) .putInt("endHour", h) .putInt("endMinute", min) .apply(); nightTimeStart[0] = 42; } }
Example 5
Source File: EditAlertActivity.java From NightWatch with GNU General Public License v3.0 | 5 votes |
public String timeFormatString(int Hour, int Minute) { SimpleDateFormat timeFormat24 = new SimpleDateFormat("HH:mm"); String selected = Hour+":"+Minute; if (!DateFormat.is24HourFormat(mContext)) { try { Date date = timeFormat24.parse(selected); SimpleDateFormat timeFormat12 = new SimpleDateFormat("hh:mm aa"); return timeFormat12.format(date); } catch (final ParseException e) { e.printStackTrace(); } } return selected; }
Example 6
Source File: TimePickerFragment.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@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())); }
Example 7
Source File: OBSetupMenu.java From GLEXP-Team-onebillion with Apache License 2.0 | 5 votes |
void showPickTimeDialog (final TimePickerDialog.OnTimeSetListener listener) { final DatePickerDialog.OnDateSetListener dateListener = (DatePickerDialog.OnDateSetListener) listener; final Calendar calendar = Calendar.getInstance(); TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, listener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.mainActivity)); // d.setCancelable(false); d.setCanceledOnTouchOutside(false); // d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener() { @Override public void onClick (DialogInterface dialog, int which) { if (screenType == ScreenType.SET_DATE_SCREEN) { showPickDateDialog(dateListener, null); } else { MainActivity.log("OBSetupMenu:showPickTimeDialog:cancelled!"); } } }); // LinearLayout linearLayout = new LinearLayout(MainActivity.mainActivity.getApplicationContext()); d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setCustomTitle(linearLayout); // d.show(); }
Example 8
Source File: DateAndTimeUtil.java From recurrence with GNU General Public License v3.0 | 5 votes |
public static String toStringReadableTime(Calendar calendar, Context context) { if (DateFormat.is24HourFormat(context)) { return READABLE_TIME_24_FORMAT.format(calendar.getTime()); } else { return READABLE_TIME_FORMAT.format(calendar.getTime()); } }
Example 9
Source File: TimeSpinner.java From ReminderDatePicker with Apache License 2.0 | 5 votes |
private boolean is24HourFormat(java.text.DateFormat timeFormat) { String pattern; try { pattern = ((SimpleDateFormat) timeFormat).toLocalizedPattern(); } catch (ClassCastException e) { // we cannot get the pattern, use the default setting for out context: return DateFormat.is24HourFormat(getContext()); } // if pattern does not contain the 12 hour formats, we return true (regardless of any 'a' (am/pm) modifier) return !(pattern.contains("h") || pattern.contains("K")); }
Example 10
Source File: AlarmActivity.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
protected void onResume() { super.onResume(); checkOnceAlarmIfExpired(); new DateFormat(); q = DateFormat.is24HourFormat(this); if (i != null) { i.notifyDataSetChanged(); } UmengAnalytics.startPage("PageAlarm"); UmengAnalytics.startSession(this); }
Example 11
Source File: PrayerListView.java From android with Apache License 2.0 | 5 votes |
public PrayerListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); LayoutInflater.from(context).inflate(R.layout.view_default_prayer, this, true); ButterKnife.bind(this); mDateFormat = DateFormat.is24HourFormat(context) ? FORMAT_24 : FORMAT_12; }
Example 12
Source File: MapboxNavigationNotification.java From graphhopper-navigation-android with MIT License | 5 votes |
private void initialize(Context context, MapboxNavigation mapboxNavigation) { this.mapboxNavigation = mapboxNavigation; etaFormat = context.getString(R.string.eta_format); initializeDistanceFormatter(context, mapboxNavigation); notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); isTwentyFourHourFormat = DateFormat.is24HourFormat(context); createNotificationChannel(context); buildNotification(context); registerReceiver(context); }
Example 13
Source File: EditAlertActivity.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
static public String timeFormatString(Context context, int hour, int minute) { SimpleDateFormat timeFormat24 = new SimpleDateFormat("HH:mm"); String selected = hour+":" + ((minute<10)?"0":"") + minute; if (!DateFormat.is24HourFormat(context)) { try { Date date = timeFormat24.parse(selected); SimpleDateFormat timeFormat12 = new SimpleDateFormat("hh:mm aa"); return timeFormat12.format(date); } catch (final ParseException e) { e.printStackTrace(); } } return selected; }
Example 14
Source File: NumberPadTimePickerDialogTest.java From NumberPadTimePicker with Apache License 2.0 | 4 votes |
@Before public void setup() { mLocaleModel = new LocaleModel(mActivityTestRule.getActivity()); mInitiallyIn24HourMode = DateFormat.is24HourFormat(mActivityTestRule.getActivity()); }
Example 15
Source File: DashClockService.java From android with Apache License 2.0 | 4 votes |
private String getFormattedDate(Date date) { String f = DateFormat.is24HourFormat(this) ? FORMAT_24 : FORMAT_12; return DateFormat.format(f, date).toString(); }
Example 16
Source File: TimePicker.java From react-native-datetime-picker with MIT License | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new RCTTimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity())); }
Example 17
Source File: TimeManager.java From GeometricWeather with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean is12Hour(Context context) { return !DateFormat.is24HourFormat(context); }
Example 18
Source File: SettingsFragment.java From QuickLyric with GNU General Public License v3.0 | 4 votes |
@Override public boolean onPreferenceChange(Preference pref, Object newValue) { switch (pref.getKey()) { case "pref_theme": findPreference("pref_theme").setSummary(themes[Integer.valueOf((String) newValue)]); break; case "pref_notifications": if (newValue.equals("0")) { ((NotificationManager) getActivity() .getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll(); } else broadcast(); break; case "pref_night_mode": if ((Boolean) newValue) { boolean twentyFourHourStyle = DateFormat.is24HourFormat(getActivity()); TimePickerDialog tpd = TimePickerDialog .newInstance(this, 21, 0, twentyFourHourStyle); tpd.setOnCancelListener(this); tpd.setTitle(getActivity().getString(R.string.nighttime_start_dialog_title)); tpd.show(getFragmentManager(), NIGHT_START_TIME_DIALOG_TAG); } else { this.onCancel(null); } break; case "pref_overlay": findPreference("pref_overlay_behavior").setEnabled((Boolean) newValue); findPreference("pref_notifications").setEnabled(!((Boolean) newValue)); findPreference("pref_notifications").setSummary((Boolean) newValue ? R.string.pref_notification_sum_disabled : R.string.pref_notifications_sum); if ((Boolean) newValue) { PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(pref.getKey(), (Boolean) newValue).apply(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(getActivity())) { broadcast(); } else { final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getActivity().getPackageName())); getActivity().startActivity(intent); } PermissionsChecker.displayMIUIPopupPermission(getActivity()); } else { LyricsOverlayService.removeCustomFloatingView(getActivity()); } break; case "pref_overlay_behavior": LyricsOverlayService.removeCustomFloatingView(getActivity()); break; } return true; }
Example 19
Source File: TimeViewUpdater.java From TabletClock with MIT License | 4 votes |
public boolean retrive24Format() { // return true if changed boolean old = is24hours; is24hours = DateFormat.is24HourFormat(mTimeView.getContext()); return old != is24hours; }
Example 20
Source File: TextClock.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Indicates whether the system is currently using the 24-hour mode. * * When the system is in 24-hour mode, this view will use the pattern * returned by {@link #getFormat24Hour()}. In 12-hour mode, the pattern * returned by {@link #getFormat12Hour()} is used instead. * * If either one of the formats is null, the other format is used. If * both formats are null, the default formats for the current locale are used. * * @return true if time should be displayed in 24-hour format, false if it * should be displayed in 12-hour format. * * @see #setFormat12Hour(CharSequence) * @see #getFormat12Hour() * @see #setFormat24Hour(CharSequence) * @see #getFormat24Hour() */ public boolean is24HourModeEnabled() { if (mShowCurrentUserTime) { return DateFormat.is24HourFormat(getContext(), ActivityManager.getCurrentUser()); } else { return DateFormat.is24HourFormat(getContext()); } }