Java Code Examples for android.text.format.DateUtils#FORMAT_24HOUR

The following examples show how to use android.text.format.DateUtils#FORMAT_24HOUR . 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 vote down vote up
/**
 * 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 MaterialDateRangePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = DateUtils.formatDateTime(getContext(), millis, flags);
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 3
Source File: RadialPickerLayout.java    From MaterialDateTimePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: RadialPickerLayout.java    From DateTimepicker with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: RadialPickerLayout.java    From Conquer with Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source File: SublimeTimePicker.java    From SublimePicker with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: TimePicker.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: RadialPickerLayout.java    From StyleableDateTimePicker with MIT License 6 votes vote down vote up
/**
 * 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 9
Source File: TimePickerClockDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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 10
Source File: RadialPickerLayout.java    From Blackbulb with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 11
Source File: RadialPickerLayout.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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: TimePickerClockDelegate.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
@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 13
Source File: RadialPickerLayout.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
/**
 * 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: PersianRadialPickerLayout.java    From PersianDateRangePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 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 15
Source File: TimePickerSpinnerDelegate.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: TimePickerSpinnerDelegate.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: RingerModeAndScreenMonitor.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * 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 18
Source File: AppCompatTimePickerDelegate.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
@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 selectedDate = DateUtils.formatDateTime(mContext,
            mTempCalendar.getTimeInMillis(), flags);
    event.getText().add(selectedDate);
}
 
Example 19
Source File: TimePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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 20
Source File: AnalogClock.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void updateContentDescription(Time time) {
    final int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR;
    String contentDescription = DateUtils.formatDateTime(mContext,
            time.toMillis(false), flags);
    setContentDescription(contentDescription);
}