Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ywwynm opened this issue Aug 6, 2015 · 6 comments
Closed

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

ywwynm opened this issue Aug 6, 2015 · 6 comments

Comments

@ywwynm
Copy link

ywwynm commented Aug 6, 2015

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
Copy link
Author

ywwynm commented Aug 6, 2015

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
Copy link
Author

ywwynm commented Aug 6, 2015

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

@vikramkakkar
Copy link
Owner

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
Copy link
Author

ywwynm commented Aug 12, 2015

@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
Copy link

same problem。

@aadhk aadhk mentioned this issue Dec 13, 2015
@vikramkakkar
Copy link
Owner

@ywwynm @caijiangyang

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants