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

Consider firstDayOfWeek of the current locale #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ private void drawWidget(Context context, int appWidgetId) {
if (!mini) {
cal.set(Calendar.DAY_OF_MONTH, 1);
int monthStartDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, 1 - monthStartDayOfWeek);
cal.add(Calendar.DAY_OF_MONTH, - dayToDayId(monthStartDayOfWeek, cal));
} else {
int todayDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, 1 - todayDayOfWeek);
cal.add(Calendar.DAY_OF_MONTH, - dayToDayId(todayDayOfWeek, cal));
}

rv.removeAllViews(R.id.calendar);
Expand All @@ -166,7 +166,8 @@ private void drawWidget(Context context, int appWidgetId) {
R.layout.row_header);
DateFormatSymbols dfs = DateFormatSymbols.getInstance();
String[] weekdays = dfs.getShortWeekdays();
for (int day = Calendar.SUNDAY; day <= Calendar.SATURDAY; day++) {
for (int dayId = 0; dayId < 7; dayId++) {
int day = dayIdToDay(dayId, cal);
RemoteViews dayRv = new RemoteViews(context.getPackageName(), R.layout.cell_header);
dayRv.setTextViewText(android.R.id.text1, weekdays[day]);
headerRowRv.addView(R.id.row_container, dayRv);
Expand Down Expand Up @@ -219,4 +220,15 @@ private void drawWidget(Context context, int appWidgetId) {
rv.setViewVisibility(R.id.month_bar, numWeeks <= 1 ? View.GONE : View.VISIBLE);
appWidgetManager.updateAppWidget(appWidgetId, rv);
}

static private int dayIdToDay(int dayId, Calendar cal)
{
return (cal.getFirstDayOfWeek() - 1 + dayId) % 7 + 1;
}

static private int dayToDayId(int day, Calendar cal)
{
return (7 - cal.getFirstDayOfWeek() + day) % 7;
}

}