Merge "Add color setting for Saturday and Sunday in month view"
diff --git a/res/values-ja/colors.xml b/res/values-ja/colors.xml
index 25b9091..1ce51c6 100644
--- a/res/values-ja/colors.xml
+++ b/res/values-ja/colors.xml
@@ -18,7 +18,12 @@
*/
-->
<resources>
- <color name="week_saturday">#ff4444aa</color>
- <color name="week_sunday">#ffaa2222</color>
- <color name="calendar_date_banner_text_color">#ffffffff</color>
+ <color name="week_saturday">#ff2222cc</color>
+ <color name="week_sunday">#ffcc2222</color>
+ <color name="calendar_date_banner_text_color">#ff000000</color>
+ <color name="saturday_text_color">#ff2222cc</color>
+ <color name="sunday_text_color">#ffcc2222</color>
+ <color name="daynames_text_color">#ff000000</color>
+ <color name="month_saturday">#ff2222cc</color>
+ <color name="month_sunday">#ffcc2222</color>
</resources>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 3d38ca8..556418c 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -22,6 +22,8 @@
<color name="panel_text_foreground">#ffffffff</color>
<color name="daynames_background">#ffc3d9ff</color>
<color name="daynames_text_color">#ff112abb</color>
+ <color name="sunday_text_color">#ff112abb</color>
+ <color name="saturday_text_color">#ff112abb</color>
<color name="calendar_event_selected_text_color">#ff000000</color>
<color name="calendar_event_text_color">#ffffffff</color>
@@ -44,6 +46,8 @@
<color name="pressed">#fffab400</color>
<color name="month_day_number">#ff404040</color>
+ <color name="month_saturday">#ff404040</color>
+ <color name="month_sunday">#ff404040</color>
<color name="month_today_number">#ffffffff</color>
<color name="month_other_month">#ff595959</color>
<color name="month_other_month_day_number">#ffa0a0a0</color>
diff --git a/src/com/android/calendar/CalendarView.java b/src/com/android/calendar/CalendarView.java
index 63b724d..84744a1 100644
--- a/src/com/android/calendar/CalendarView.java
+++ b/src/com/android/calendar/CalendarView.java
@@ -42,10 +42,10 @@
import android.provider.Calendar.Attendees;
import android.provider.Calendar.Calendars;
import android.provider.Calendar.Events;
+import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.text.format.Time;
-import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Gravity;
@@ -356,14 +356,7 @@
setClickable(true);
setOnCreateContextMenuListener(this);
- mStartDay = Calendar.getInstance().getFirstDayOfWeek();
- if (mStartDay == Calendar.SATURDAY) {
- mStartDay = Time.SATURDAY;
- } else if (mStartDay == Calendar.MONDAY) {
- mStartDay = Time.MONDAY;
- } else {
- mStartDay = Time.SUNDAY;
- }
+ mStartDay = Utils.getFirstDayOfWeek();
mWeek_saturdayColor = mResources.getColor(R.color.week_saturday);
mWeek_sundayColor = mResources.getColor(R.color.week_sunday);
@@ -1445,30 +1438,9 @@
private void drawDayHeader(String dateStr, int day, int cell, int x, Canvas canvas, Paint p) {
float xCenter = x + mCellWidth / 2.0f;
- boolean isSaturday = false;
- boolean isSunday = false;
- if (mStartDay == Time.SUNDAY) {
- if (day == 6) {
- isSaturday = true;
- } else if (day == 0) {
- isSunday = true;
- }
- } else if (mStartDay == Time.MONDAY) {
- if (day == 5) {
- isSaturday = true;
- } else if (day == 6) {
- isSunday = true;
- }
- } else if (mStartDay == Time.SATURDAY) {
- if (day == 0) {
- isSaturday = true;
- } else if (day == 1) {
- isSunday = true;
- }
- }
- if (isSaturday) {
+ if (Utils.isSaturday(day, mStartDay)) {
p.setColor(mWeek_saturdayColor);
- } else if (isSunday) {
+ } else if (Utils.isSunday(day, mStartDay)) {
p.setColor(mWeek_sundayColor);
} else {
p.setColor(mCalendarDateBannerTextColor);
diff --git a/src/com/android/calendar/MonthActivity.java b/src/com/android/calendar/MonthActivity.java
index 5c7e978..ed9bee3 100644
--- a/src/com/android/calendar/MonthActivity.java
+++ b/src/com/android/calendar/MonthActivity.java
@@ -17,6 +17,7 @@
package com.android.calendar;
import static android.provider.Calendar.EVENT_BEGIN_TIME;
+import dalvik.system.VMRuntime;
import android.app.Activity;
import android.content.BroadcastReceiver;
@@ -43,8 +44,6 @@
import android.widget.ViewSwitcher;
import android.widget.Gallery.LayoutParams;
-import dalvik.system.VMRuntime;
-
import java.util.Calendar;
public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory,
@@ -63,6 +62,14 @@
private ProgressBar mProgressBar;
+ private static final int DAY_OF_WEEK_LABEL_IDS[] = {
+ R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6
+ };
+ private static final int DAY_OF_WEEK_KINDS[] = {
+ Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY,
+ Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY
+ };
+
protected void startProgressSpinner() {
// start the progress spinner
mProgressBar.setVisibility(View.VISIBLE);
@@ -219,28 +226,21 @@
// Get first day of week based on locale and populate the day headers
mStartDay = Calendar.getInstance().getFirstDayOfWeek();
int diff = mStartDay - Calendar.SUNDAY - 1;
+ final int startDay = Utils.getFirstDayOfWeek();
+ final int sundayColor = getResources().getColor(R.color.sunday_text_color);
+ final int saturdayColor = getResources().getColor(R.color.saturday_text_color);
- String dayString = DateUtils.getDayOfWeekString((Calendar.SUNDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day0)).setText(dayString);
- dayString = DateUtils.getDayOfWeekString((Calendar.MONDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day1)).setText(dayString);
- dayString = DateUtils.getDayOfWeekString((Calendar.TUESDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day2)).setText(dayString);
- dayString = DateUtils.getDayOfWeekString((Calendar.WEDNESDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day3)).setText(dayString);
- dayString = DateUtils.getDayOfWeekString((Calendar.THURSDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day4)).setText(dayString);
- dayString = DateUtils.getDayOfWeekString((Calendar.FRIDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day5)).setText(dayString);
- dayString = DateUtils.getDayOfWeekString((Calendar.SATURDAY + diff) % 7 + 1,
- DateUtils.LENGTH_MEDIUM);
- ((TextView) findViewById(R.id.day6)).setText(dayString);
+ for (int day = 0; day < 7; day++) {
+ final String dayString = DateUtils.getDayOfWeekString(
+ (DAY_OF_WEEK_KINDS[day] + diff) % 7 +1, DateUtils.LENGTH_MEDIUM);
+ final TextView label = (TextView) findViewById(DAY_OF_WEEK_LABEL_IDS[day]);
+ label.setText(dayString);
+ if (Utils.isSunday(day, startDay)) {
+ label.setTextColor(sundayColor);
+ } else if (Utils.isSaturday(day, startDay)) {
+ label.setTextColor(saturdayColor);
+ }
+ }
// Set the initial title
TextView title = (TextView) findViewById(R.id.title);
diff --git a/src/com/android/calendar/MonthView.java b/src/com/android/calendar/MonthView.java
index 989e255..c8f435f 100644
--- a/src/com/android/calendar/MonthView.java
+++ b/src/com/android/calendar/MonthView.java
@@ -156,6 +156,8 @@
*/
private int mFirstJulianDay;
+ private int mStartDay;
+
private final EventLoader mEventLoader;
private ArrayList<Event> mEvents = new ArrayList<Event>();
@@ -170,6 +172,8 @@
private int mMonthOtherMonthDayNumberColor;
private int mMonthDayNumberColor;
private int mMonthTodayNumberColor;
+ private int mMonthSaturdayColor;
+ private int mMonthSundayColor;
public MonthView(MonthActivity activity, Navigator navigator) {
super(activity);
@@ -211,6 +215,7 @@
mViewCalendar.monthDay = 1;
long millis = mViewCalendar.normalize(true /* ignore DST */);
mFirstJulianDay = Time.getJulianDay(millis, mViewCalendar.gmtoff);
+ mStartDay = Utils.getFirstDayOfWeek();
mViewCalendar.set(now);
mCursor = new DayOfMonthCursor(mViewCalendar.year, mViewCalendar.month,
@@ -235,6 +240,8 @@
mMonthOtherMonthDayNumberColor = res.getColor(R.color.month_other_month_day_number);
mMonthDayNumberColor = res.getColor(R.color.month_day_number);
mMonthTodayNumberColor = res.getColor(R.color.month_today_number);
+ mMonthSaturdayColor = res.getColor(R.color.month_saturday);
+ mMonthSundayColor = res.getColor(R.color.month_sunday);
if (mShowToast) {
LayoutInflater inflater;
@@ -784,10 +791,14 @@
if (!withinCurrentMonth) {
p.setColor(mMonthOtherMonthDayNumberColor);
} else {
- if (drawSelection || !isToday) {
- p.setColor(mMonthDayNumberColor);
- } else {
+ if (isToday && !drawSelection) {
p.setColor(mMonthTodayNumberColor);
+ } else if (Utils.isSunday(column, mStartDay)) {
+ p.setColor(mMonthSundayColor);
+ } else if (Utils.isSaturday(column, mStartDay)) {
+ p.setColor(mMonthSaturdayColor);
+ } else {
+ p.setColor(mMonthDayNumberColor);
}
//bolds the day if there's an event that day
p.setFakeBoldText(eventDay[day-mFirstJulianDay]);
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index c282798..f8c69f6 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -27,6 +27,8 @@
import android.view.animation.AlphaAnimation;
import android.widget.ViewFlipper;
+import java.util.Calendar;
+
public class Utils {
public static void startActivity(Context context, String className, long time) {
Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -121,4 +123,43 @@
time.minute = 0;
time.hour = 0;
}
+
+ /**
+ * Get first day of week as android.text.format.Time constant.
+ * @return the first day of week in android.text.format.Time
+ */
+ public static int getFirstDayOfWeek() {
+ int startDay = Calendar.getInstance().getFirstDayOfWeek();
+ if (startDay == Calendar.SATURDAY) {
+ return Time.SATURDAY;
+ } else if (startDay == Calendar.MONDAY) {
+ return Time.MONDAY;
+ } else {
+ return Time.SUNDAY;
+ }
+ }
+
+ /**
+ * Determine whether the column position is Saturday or not.
+ * @param column the column position
+ * @param firstDayOfWeek the first day of week in android.text.format.Time
+ * @return true if the column is Saturday position
+ */
+ public static boolean isSaturday(int column, int firstDayOfWeek) {
+ return (firstDayOfWeek == Time.SUNDAY && column == 6)
+ || (firstDayOfWeek == Time.MONDAY && column == 5)
+ || (firstDayOfWeek == Time.SATURDAY && column == 0);
+ }
+
+ /**
+ * Determine whether the column position is Sunday or not.
+ * @param column the column position
+ * @param firstDayOfWeek the first day of week in android.text.format.Time
+ * @return true if the column is Sunday position
+ */
+ public static boolean isSunday(int column, int firstDayOfWeek) {
+ return (firstDayOfWeek == Time.SUNDAY && column == 0)
+ || (firstDayOfWeek == Time.MONDAY && column == 6)
+ || (firstDayOfWeek == Time.SATURDAY && column == 1);
+ }
}