use of java.text.DateFormatSymbols in project onebusaway-application-modules by camsys.
the class ResourceServiceImpl method getDateLibraryMessagesResourceAsSourceUrl.
private URL getDateLibraryMessagesResourceAsSourceUrl(LocaleProvider localeProvider) {
String messagesPrefix = PREFIX_MESSAGES_DATE_LIBRARY;
DateFormatSymbols symbols = DateFormatSymbols.getInstance(localeProvider.getLocale());
Map<String, Object> resourceMapping = new HashMap<String, Object>();
resourceMapping.put("amPm", Arrays.asList(symbols.getAmPmStrings()));
resourceMapping.put("eras", Arrays.asList(symbols.getEras()));
resourceMapping.put("months", Arrays.asList(symbols.getMonths()));
resourceMapping.put("shortMonths", Arrays.asList(symbols.getShortMonths()));
resourceMapping.put("weekdays", Arrays.asList(symbols.getWeekdays()));
resourceMapping.put("shortWeekdays", Arrays.asList(symbols.getShortWeekdays()));
try {
File file = getOutputFile(PREFIX_MESSAGES + messagesPrefix + ".js");
PrintWriter out = new PrintWriter(file);
JSONObject obj = new JSONObject(resourceMapping);
out.println("var OBA = window.OBA || {};");
out.println("if(!OBA.Resources) { OBA.Resources = {}; }");
out.println("OBA.Resources." + messagesPrefix + " = " + obj.toString() + ";");
out.close();
return getFileAsUrl(file);
} catch (IOException ex) {
throw new IllegalStateException("error loading resources", ex);
}
}
use of java.text.DateFormatSymbols in project Memento-Calendar by alexstyl.
the class MonthLabels method forLocale.
public static MonthLabels forLocale(Locale locale) {
DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(locale);
String[] labels = dateFormatSymbols.getMonths();
return new MonthLabels(labels);
}
use of java.text.DateFormatSymbols in project freeplane by freeplane.
the class JDayChooser method drawDayNames.
/**
* Draws the day names of the day columnes.
*/
private void drawDayNames() {
final int firstDayOfWeek = calendar.getFirstDayOfWeek();
final DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
dayNames = dateFormatSymbols.getShortWeekdays();
int day = firstDayOfWeek;
for (int i = 0; i < 7; i++) {
if (maxDayCharacters > 0 && maxDayCharacters < 5) {
if (dayNames[day].length() >= maxDayCharacters) {
dayNames[day] = dayNames[day].substring(0, maxDayCharacters);
}
}
days[i].setText(dayNames[day]);
if (day == 1) {
days[i].setForeground(sundayForeground);
} else {
days[i].setForeground(weekdayForeground);
}
if (day < 7) {
day++;
} else {
day -= 6;
}
}
}
use of java.text.DateFormatSymbols in project freeplane by freeplane.
the class JMonthChooser method initNames.
/**
* Initializes the locale specific month names.
*/
public void initNames() {
localInitialize = true;
final DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
final String[] monthNames = dateFormatSymbols.getMonths();
if (comboBox.getItemCount() == 12) {
comboBox.removeAllItems();
}
for (int i = 0; i < 12; i++) {
comboBox.addItem(monthNames[i]);
}
localInitialize = false;
comboBox.setSelectedIndex(month);
}
use of java.text.DateFormatSymbols in project MaterialDateTimePicker by wdullaer.
the class TimePickerDialog method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int viewRes = mVersion == Version.VERSION_1 ? R.layout.mdtp_time_picker_dialog : R.layout.mdtp_time_picker_dialog_v2;
View view = inflater.inflate(viewRes, container, false);
KeyboardListener keyboardListener = new KeyboardListener();
view.findViewById(R.id.mdtp_time_picker_dialog).setOnKeyListener(keyboardListener);
// If an accent color has not been set manually, get it from the context
if (mAccentColor == null) {
mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
}
// if theme mode has not been set by java code, check if it is specified in Style.xml
if (!mThemeDarkChanged) {
mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
}
Resources res = getResources();
Context context = requireActivity();
mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
mSelectHours = res.getString(R.string.mdtp_select_hours);
mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);
mHourView = view.findViewById(R.id.mdtp_hours);
mHourView.setOnKeyListener(keyboardListener);
mHourSpaceView = view.findViewById(R.id.mdtp_hour_space);
mMinuteSpaceView = view.findViewById(R.id.mdtp_minutes_space);
mMinuteView = view.findViewById(R.id.mdtp_minutes);
mMinuteView.setOnKeyListener(keyboardListener);
mSecondSpaceView = view.findViewById(R.id.mdtp_seconds_space);
mSecondView = view.findViewById(R.id.mdtp_seconds);
mSecondView.setOnKeyListener(keyboardListener);
mAmTextView = view.findViewById(R.id.mdtp_am_label);
mAmTextView.setOnKeyListener(keyboardListener);
mPmTextView = view.findViewById(R.id.mdtp_pm_label);
mPmTextView.setOnKeyListener(keyboardListener);
mAmPmLayout = view.findViewById(R.id.mdtp_ampm_layout);
String[] amPmTexts = new DateFormatSymbols(mLocale).getAmPmStrings();
mAmText = amPmTexts[0];
mPmText = amPmTexts[1];
mHapticFeedbackController = new HapticFeedbackController(getActivity());
if (mTimePicker != null) {
mInitialTime = new Timepoint(mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
}
mInitialTime = roundToNearest(mInitialTime);
mTimePicker = view.findViewById(R.id.mdtp_time_picker);
mTimePicker.setOnValueSelectedListener(this);
mTimePicker.setOnKeyListener(keyboardListener);
mTimePicker.initialize(getActivity(), mLocale, this, mInitialTime, mIs24HourMode);
int currentItemShowing = HOUR_INDEX;
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
}
setCurrentItemShowing(currentItemShowing, false, true, true);
mTimePicker.invalidate();
mHourView.setOnClickListener(v -> {
setCurrentItemShowing(HOUR_INDEX, true, false, true);
tryVibrate();
});
mMinuteView.setOnClickListener(v -> {
setCurrentItemShowing(MINUTE_INDEX, true, false, true);
tryVibrate();
});
mSecondView.setOnClickListener(view1 -> {
setCurrentItemShowing(SECOND_INDEX, true, false, true);
tryVibrate();
});
mOkButton = view.findViewById(R.id.mdtp_ok);
mOkButton.setOnClickListener(v -> {
if (mInKbMode && isTypedTimeFullyLegal()) {
finishKbMode(false);
} else {
tryVibrate();
}
notifyOnDateListener();
dismiss();
});
mOkButton.setOnKeyListener(keyboardListener);
mOkButton.setTypeface(ResourcesCompat.getFont(context, R.font.robotomedium));
if (mOkString != null)
mOkButton.setText(mOkString);
else
mOkButton.setText(mOkResid);
mCancelButton = view.findViewById(R.id.mdtp_cancel);
mCancelButton.setOnClickListener(v -> {
tryVibrate();
if (getDialog() != null)
getDialog().cancel();
});
mCancelButton.setTypeface(ResourcesCompat.getFont(context, R.font.robotomedium));
if (mCancelString != null)
mCancelButton.setText(mCancelString);
else
mCancelButton.setText(mCancelResid);
mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);
// Enable or disable the AM/PM view.
if (mIs24HourMode) {
mAmPmLayout.setVisibility(View.GONE);
} else {
OnClickListener listener = v -> {
// Don't do anything if either AM or PM are disabled
if (isAmDisabled() || isPmDisabled())
return;
tryVibrate();
int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
if (amOrPm == AM) {
amOrPm = PM;
} else if (amOrPm == PM) {
amOrPm = AM;
}
mTimePicker.setAmOrPm(amOrPm);
};
mAmTextView.setVisibility(View.GONE);
mPmTextView.setVisibility(View.VISIBLE);
mAmPmLayout.setOnClickListener(listener);
if (mVersion == Version.VERSION_2) {
mAmTextView.setText(mAmText);
mPmTextView.setText(mPmText);
mAmTextView.setVisibility(View.VISIBLE);
}
updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
}
// Disable seconds picker
if (!mEnableSeconds) {
mSecondView.setVisibility(View.GONE);
view.findViewById(R.id.mdtp_separator_seconds).setVisibility(View.GONE);
}
// Disable minutes picker
if (!mEnableMinutes) {
mMinuteSpaceView.setVisibility(View.GONE);
view.findViewById(R.id.mdtp_separator).setVisibility(View.GONE);
}
// Center stuff depending on what's visible
boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
// Landscape layout is radically different
if (isLandscape) {
if (!mEnableMinutes && !mEnableSeconds) {
// Just the hour
// Put the hour above the center
RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsHour.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
paramsHour.addRule(RelativeLayout.CENTER_HORIZONTAL);
mHourSpaceView.setLayoutParams(paramsHour);
if (mIs24HourMode) {
// Hour + Am/Pm indicator
// Put the am / pm indicator next to the hour
RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
mAmPmLayout.setLayoutParams(paramsAmPm);
}
} else if (!mEnableSeconds && mIs24HourMode) {
// Hour + Minutes
// Put the separator above the center
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
TextView separatorView = view.findViewById(R.id.mdtp_separator);
separatorView.setLayoutParams(paramsSeparator);
} else if (!mEnableSeconds) {
// Hour + Minutes + Am/Pm indicator
// Put separator above the center
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
TextView separatorView = view.findViewById(R.id.mdtp_separator);
separatorView.setLayoutParams(paramsSeparator);
// Put the am/pm indicator below the separator
RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsAmPm.addRule(RelativeLayout.CENTER_IN_PARENT);
paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_center_view);
mAmPmLayout.setLayoutParams(paramsAmPm);
} else if (mIs24HourMode) {
// Hour + Minutes + Seconds
// Put the separator above the center
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
TextView separatorView = view.findViewById(R.id.mdtp_separator);
separatorView.setLayoutParams(paramsSeparator);
// Center the seconds
RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
mSecondSpaceView.setLayoutParams(paramsSeconds);
} else {
// Hour + Minutes + Seconds + Am/Pm Indicator
// Put the seconds on the center
RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
mSecondSpaceView.setLayoutParams(paramsSeconds);
// Put the separator above the seconds
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
TextView separatorView = view.findViewById(R.id.mdtp_separator);
separatorView.setLayoutParams(paramsSeparator);
// Put the Am/Pm indicator below the seconds
RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsAmPm.addRule(RelativeLayout.CENTER_HORIZONTAL);
paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_seconds_space);
mAmPmLayout.setLayoutParams(paramsAmPm);
}
} else if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) {
// center first separator
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
TextView separatorView = view.findViewById(R.id.mdtp_separator);
separatorView.setLayoutParams(paramsSeparator);
} else if (!mEnableMinutes && !mEnableSeconds) {
// center the hour
RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT);
mHourSpaceView.setLayoutParams(paramsHour);
if (!mIs24HourMode) {
RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.mdtp_hour_space);
mAmPmLayout.setLayoutParams(paramsAmPm);
}
} else if (mEnableSeconds) {
// link separator to minutes
final View separator = view.findViewById(R.id.mdtp_separator);
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.mdtp_minutes_space);
paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
separator.setLayoutParams(paramsSeparator);
if (!mIs24HourMode) {
// center minutes
RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
mMinuteSpaceView.setLayoutParams(paramsMinutes);
} else {
// move minutes to right of center
RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_center_view);
mMinuteSpaceView.setLayoutParams(paramsMinutes);
}
}
mAllowAutoAdvance = true;
setHour(mInitialTime.getHour(), true);
setMinute(mInitialTime.getMinute());
setSecond(mInitialTime.getSecond());
// Set up for keyboard mode.
mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
mPlaceholderText = mDoublePlaceholderText.charAt(0);
mAmKeyCode = mPmKeyCode = -1;
generateLegalTimesTree();
if (mInKbMode && savedInstanceState != null) {
mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
tryStartingKbMode(-1);
mHourView.invalidate();
} else if (mTypedTimes == null) {
mTypedTimes = new ArrayList<>();
}
// Set the title (if any)
TextView timePickerHeader = view.findViewById(R.id.mdtp_time_picker_header);
if (!mTitle.isEmpty()) {
timePickerHeader.setVisibility(TextView.VISIBLE);
timePickerHeader.setText(mTitle);
}
// Set the theme at the end so that the initialize()s above don't counteract the theme.
timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
view.findViewById(R.id.mdtp_time_display_background).setBackgroundColor(mAccentColor);
view.findViewById(R.id.mdtp_time_display).setBackgroundColor(mAccentColor);
// Button text can have a different color
if (mOkColor == null)
mOkColor = mAccentColor;
mOkButton.setTextColor(mOkColor);
if (mCancelColor == null)
mCancelColor = mAccentColor;
mCancelButton.setTextColor(mCancelColor);
if (getDialog() == null) {
view.findViewById(R.id.mdtp_done_background).setVisibility(View.GONE);
}
int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);
mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
view.findViewById(R.id.mdtp_time_picker_dialog).setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
return view;
}
Aggregations