Java Code Examples for android.text.format.DateUtils#FORMAT_SHOW_TIME
The following examples show how to use
android.text.format.DateUtils#FORMAT_SHOW_TIME .
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: RadialPickerLayout.java From cathode with Apache License 2.0 | 6 votes |
/** * 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); }
Example 2
Source File: RadialPickerLayout.java From Conquer with Apache License 2.0 | 6 votes |
/** * 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); }
Example 3
Source File: PersianRadialPickerLayout.java From PersianDateRangePicker with Apache License 2.0 | 6 votes |
/** * 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(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); long millis = time.getTimeInMillis(); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourMode) { flags |= DateUtils.FORMAT_24HOUR; } String timeString = LanguageUtils.getPersianNumbers( DateUtils.formatDateTime(getContext(), millis, flags)); //TODO: Changed Here. event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(event); }
Example 4
Source File: RadialPickerLayout.java From AssistantBySDK with Apache License 2.0 | 6 votes |
/** * 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(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); time.set(Calendar.SECOND, getSeconds()); long millis = time.getTimeInMillis(); 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); }
Example 5
Source File: RadialPickerLayout.java From AlarmOn with Apache License 2.0 | 6 votes |
/** * 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(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); time.set(Calendar.SECOND, getSeconds()); long millis = time.getTimeInMillis(); 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); }
Example 6
Source File: TimePickerClockDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24Hour) { flags |= DateUtils.FORMAT_24HOUR; } else { flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getHour()); mTempCalendar.set(Calendar.MINUTE, getMinute()); final String selectedTime = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags); final String selectionMode = mRadialTimePickerView.getCurrentItemShowing() == HOUR_INDEX ? mSelectHours : mSelectMinutes; event.getText().add(selectedTime + " " + selectionMode); }
Example 7
Source File: Utils.java From FireFiles with Apache License 2.0 | 6 votes |
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); }
Example 8
Source File: RadialPickerLayout.java From MaterialDateTimePicker with Apache License 2.0 | 6 votes |
/** * 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(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); time.set(Calendar.SECOND, getSeconds()); long millis = time.getTimeInMillis(); 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); }
Example 9
Source File: SublimeTimePicker.java From SublimePicker with Apache License 2.0 | 6 votes |
@Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { super.onPopulateAccessibilityEvent(event); int flags = DateUtils.FORMAT_SHOW_TIME; // The deprecation status does not show up in the documentation and // source code does not outline the alternative. // Leaving this as is for now. if (mIs24HourView) { //noinspection deprecation flags |= DateUtils.FORMAT_24HOUR; } else { //noinspection deprecation flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour()); mTempCalendar.set(Calendar.MINUTE, getCurrentMinute()); String selectedDate = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags); event.getText().add(selectedDate); }
Example 10
Source File: TimePicker.java From NewXmPluginSDK with Apache License 2.0 | 6 votes |
@Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { super.onPopulateAccessibilityEvent(event); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourView) { flags |= DateUtils.FORMAT_24HOUR; } else { flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour()); mTempCalendar.set(Calendar.MINUTE, getCurrentMinute()); String selectedDateUtterance = DateUtils.formatDateTime(getContext(), mTempCalendar.getTimeInMillis(), flags); event.getText().add(selectedDateUtterance); }
Example 11
Source File: RadialPickerLayout.java From narrate-android with Apache License 2.0 | 6 votes |
/** * 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); }
Example 12
Source File: ListItemUtils.java From mytracks with Apache License 2.0 | 6 votes |
/** * Gets the date and time as an array of two strings. * * @param isRecording true if recording * @param context the context * @param time the start time */ private static String[] getDateTime( boolean isRecording, Context context, long time, boolean useRelativeTime) { if (isRecording || time == 0L) { return new String[] { null, null }; } boolean isToday = DateUtils.isToday(time); int timeFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL; if (isToday) { if (useRelativeTime) { return new String[] { DateUtils.getRelativeTimeSpanString( time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString(), null }; } else { return new String[] { DateUtils.formatDateTime(context, time, timeFlags), null }; } } return new String[] { DateUtils.formatDateTime( context, time, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL), DateUtils.formatDateTime(context, time, timeFlags) }; }
Example 13
Source File: RadialPickerLayout.java From Blackbulb with GNU General Public License v3.0 | 6 votes |
/** * 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(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); time.set(Calendar.SECOND, getSeconds()); long millis = time.getTimeInMillis(); 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); }
Example 14
Source File: RadialPickerLayout.java From date_picker_converter with Apache License 2.0 | 6 votes |
/** * 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(); Calendar time = Calendar.getInstance(); time.set(Calendar.HOUR, getHours()); time.set(Calendar.MINUTE, getMinutes()); time.set(Calendar.SECOND, getSeconds()); long millis = time.getTimeInMillis(); 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); }
Example 15
Source File: RadialPickerLayout.java From Android-SwitchDateTimePicker with Apache License 2.0 | 6 votes |
/** * 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); }
Example 16
Source File: RingerModeAndScreenMonitor.java From talkback with Apache License 2.0 | 5 votes |
/** * Appends the current time announcement to a {@link StringBuilder}. * * @param builder The string to append to. */ @SuppressWarnings("deprecation") private void appendCurrentTimeAnnouncement(SpannableStringBuilder builder) { int timeFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON_MIDNIGHT; if (DateFormat.is24HourFormat(service)) { timeFlags |= DateUtils.FORMAT_24HOUR; } final CharSequence dateTime = DateUtils.formatDateTime(service, System.currentTimeMillis(), timeFlags); StringBuilderUtils.appendWithSeparator(builder, dateTime); }
Example 17
Source File: TimePickerSpinnerDelegate.java From ticdesign with Apache License 2.0 | 5 votes |
@Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourView) { flags |= DateUtils.FORMAT_24HOUR; } else { flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour()); mTempCalendar.set(Calendar.MINUTE, getCurrentMinute()); String selectedDateUtterance = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags); event.getText().add(selectedDateUtterance); }
Example 18
Source File: TimePickerSpinnerDelegate.java From DateTimePicker with Apache License 2.0 | 5 votes |
@Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourView) { flags |= DateUtils.FORMAT_24HOUR; } else { flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getHour()); mTempCalendar.set(Calendar.MINUTE, getMinute()); String selectedDateUtterance = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags); event.getText().add(selectedDateUtterance); }
Example 19
Source File: LocationService.java From trekarta with GNU General Public License v3.0 | 5 votes |
public void tryToSaveTrack() { mLastTrack = getTrack(); if (mLastTrack.points.size() == 0) return; long startTime = mLastTrack.points.get(0).time; long stopTime = mLastTrack.getLastPoint().time; long period = stopTime - startTime; int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT; if (period < DateUtils.WEEK_IN_MILLIS) flags |= DateUtils.FORMAT_SHOW_TIME; if (period < DateUtils.WEEK_IN_MILLIS * 4) flags |= DateUtils.FORMAT_SHOW_WEEKDAY; //TODO Try to 'guess' starting and ending location name mLastTrack.description = DateUtils.formatDateRange(this, startTime, stopTime, flags) + " \u2014 " + StringFormatter.distanceH(mLastTrack.getDistance()); flags |= DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; mLastTrack.name = DateUtils.formatDateRange(this, startTime, stopTime, flags); if (period < TOO_SMALL_PERIOD) { sendBroadcast(new Intent(BROADCAST_TRACK_SAVE) .putExtra("saved", false) .putExtra("reason", "period")); clearTrack(); return; } if (mLastTrack.getDistance() < TOO_SMALL_DISTANCE) { sendBroadcast(new Intent(BROADCAST_TRACK_SAVE) .putExtra("saved", false) .putExtra("reason", "distance")); clearTrack(); return; } saveTrack(); }
Example 20
Source File: MainActivity.java From samples with MIT License | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { final long min; switch (item.getItemId()) { case R.id.min_0: min = 0l; break; case R.id.min_min: min = DateUtils.MINUTE_IN_MILLIS; break; case R.id.min_hour: min = DateUtils.HOUR_IN_MILLIS; break; case R.id.min_day: min = DateUtils.DAY_IN_MILLIS; break; default: min = -1; break; } if (min >= 0) { item.setChecked(true); mAdapter.setMinResolution(min); return true; } item.setChecked(!item.isChecked()); final int flag; switch (item.getItemId()) { case R.id.FORMAT_SHOW_TIME: flag = DateUtils.FORMAT_SHOW_TIME; break; case R.id.FORMAT_SHOW_WEEKDAY: flag = DateUtils.FORMAT_SHOW_WEEKDAY; break; case R.id.FORMAT_SHOW_YEAR: flag = DateUtils.FORMAT_SHOW_YEAR; break; case R.id.FORMAT_NO_YEAR: flag = DateUtils.FORMAT_NO_YEAR; break; case R.id.FORMAT_SHOW_DATE: flag = DateUtils.FORMAT_SHOW_DATE; break; case R.id.FORMAT_NO_MONTH_DAY: flag = DateUtils.FORMAT_NO_MONTH_DAY; break; case R.id.FORMAT_NO_NOON: flag = DateUtils.FORMAT_NO_NOON; break; case R.id.FORMAT_NO_MIDNIGHT: flag = DateUtils.FORMAT_NO_MIDNIGHT; break; case R.id.FORMAT_ABBREV_TIME: flag = DateUtils.FORMAT_ABBREV_TIME; break; case R.id.FORMAT_ABBREV_WEEKDAY: flag = DateUtils.FORMAT_ABBREV_WEEKDAY; break; case R.id.FORMAT_ABBREV_MONTH: flag = DateUtils.FORMAT_ABBREV_MONTH; break; case R.id.FORMAT_NUMERIC_DATE: flag = DateUtils.FORMAT_NUMERIC_DATE; break; case R.id.FORMAT_ABBREV_RELATIVE: flag = DateUtils.FORMAT_ABBREV_RELATIVE; break; case R.id.FORMAT_ABBREV_ALL: flag = DateUtils.FORMAT_ABBREV_ALL; break; default: throw new UnsupportedOperationException("unknown id"); } if (item.isChecked()) { mAdapter.addFlag(flag); } else { mAdapter.removeFlag(flag); } return true; }