vikramkakkar / SublimePicker

A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.
Apache License 2.0
2.31k stars 407 forks source link

SublimeDatePicker displays wrong week name in Chinese in API 19 #15

Closed ywwynm closed 8 years ago

ywwynm commented 9 years ago

In China we call Monday "星期一". The first two characters means "week" and the last character determines which day in a week. When I use SublimeDatePicker, it only displays "星" for all days of a week: screenshot_2015-08-06-14-40-54 This only occurs in API 19(I didn't test Android 4.2 but I did test on 4.3 and above, at those versions it displays correctly). Maybe we should change DateFormat pattern or sth.

ywwynm commented 9 years ago

In datePicker/SimpleMonthView.java, the SimpleDateFormat used to format day of week label was built with pattern "EEEEE". Then in drawWeekDayLabels(Canvas), you used following code to draw them:

    final String dayLabel = mDayFormatter.format(mDayLabelCalendar.getTime());
    final int x = (2 * i + 1) * dayWidthHalf + mPadding;
    canvas.drawText(dayLabel.length() > 1 ? dayLabel.substring(0, 1) : dayLabel,
            x, y, mMonthDayLabelPaint);

And dayLabel.substring(0, 1) is the root reason. Umm, for English context, this is a simple way to show first letter of week days. However, many languages don't show it in that way. So we'd better improve it.

ywwynm commented 9 years ago

And I recommend you to use dayLabel.substring(0, 3) for English instead...

vikramkakkar commented 9 years ago

Thank you opening this issue and following up with the research. I really appreciate this.

I chose dayLabel.substring(0, 1) to have a consistent UI. On smaller screen sizes, the 3 letter day-labels ("MON") were overlapping. Unaware/ignorant of the convention used by other locales, I went with substring(0, 1).

One way forward would be to define the end argument in values-xx folders. values-zh folder could define end as 3 while values-en supplies 1. But that still doesn't address the overlapping problem.

Keeping in mind the 'overlap' issue, can you propose a different solution?

ywwynm commented 9 years ago

@vikramkakkar well, for consistent UI, you're on the right way. However, please tell me with which screen size it will overlap using substring(0, 3). I have a 4.0-inch phone and it displays well with 'substring(0, 3)`. Considering picking date needs to be nearly full-screen and we're in a almost-above-4-inch-screen world, I don't think overlapping is an important problem for this library.

My solution to solve first issue is to judge locale in java code and use different substring(start, end). For example, for Chinese, you can write something like followings:

final String dayLabel = mDayFormatter.format(mDayLabelCalendar.getTime());
final int x = (2 * i + 1) * dayWidthHalf + mPadding;

String finalDayLabel = dayLabel;
int length = dayLabel.length();
if (length > 1) {
     String language = getContext().getResources().getConfiguration().locale.getLanguage();
     if (language.equals(Locale.SIMPLIFIED_CHINESE.getLanguage())
         || language.equals(Locale.TRADITIONAL_CHINESE.getLanguage())) {
             finalDayLabel = dayLabel.substring(length - 1, length);
        } else if (language.equals(Locale.ENGLISH.getLanguage())) {
             finalDayLabel = dayLabel.substring(0, 3);
        } else {
             finalDayLabel = dayLabel.substring(0, 1);
        }
     }
canvas.drawText(finalDayLabel, x, y, mMonthDayLabelPaint);

Anyway, I do it in that way. And it's enough for me at least now because I don't know if substring(0, 1) could cause fine UI result in other languages :(

caijiangyang commented 8 years ago

same problem。

vikramkakkar commented 8 years ago

@ywwynm @caijiangyang

This issue has been addressed in v2.0.0 which was released today.