summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryingying <yingying@codeaurora.org>2014-07-21 21:23:20 +0800
committerSteve Kondik <steve@cyngn.com>2015-10-18 13:52:41 -0700
commit515ade24eaaff7e898392dc7a2784e64f0193723 (patch)
tree06f15a883de9b1454f32ba32bbf024e2571bf560 /src
parent84fcda3e2462e754188ebad62a21a655d47d1954 (diff)
downloadandroid_packages_apps_Calendar-515ade24eaaff7e898392dc7a2784e64f0193723.tar.gz
android_packages_apps_Calendar-515ade24eaaff7e898392dc7a2784e64f0193723.tar.bz2
android_packages_apps_Calendar-515ade24eaaff7e898392dc7a2784e64f0193723.zip
Calendar: Display the lunar and festival if the language is Chinese.
If the current language is Chinese, it will display the lunar and festival for month, week and day view Change-Id: Ib948e2aef30d9129f2d0eeeade41b31f432e7de4
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calendar/CalendarViewAdapter.java70
-rw-r--r--src/com/android/calendar/DayView.java36
-rw-r--r--src/com/android/calendar/LunarUtils.java306
-rw-r--r--src/com/android/calendar/month/MonthWeekEventsView.java68
4 files changed, 474 insertions, 6 deletions
diff --git a/src/com/android/calendar/CalendarViewAdapter.java b/src/com/android/calendar/CalendarViewAdapter.java
index 3928e44a..a2aaae0a 100644
--- a/src/com/android/calendar/CalendarViewAdapter.java
+++ b/src/com/android/calendar/CalendarViewAdapter.java
@@ -17,9 +17,13 @@
package com.android.calendar;
import com.android.calendar.CalendarController.ViewType;
+import com.android.calendar.LunarUtils.LunarInfoLoader;
import android.content.Context;
+import android.content.Loader;
+import android.content.Loader.OnLoadCompleteListener;
import android.os.Handler;
+import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.format.Time;
import android.view.LayoutInflater;
@@ -28,6 +32,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
+import java.util.Calendar;
import java.util.Formatter;
import java.util.Locale;
@@ -75,6 +80,8 @@ public class CalendarViewAdapter extends BaseAdapter {
private Handler mMidnightHandler = null; // Used to run a time update every midnight
private final boolean mShowDate; // Spinner mode indicator (view name or view name with date)
+ private LunarInfoLoader mLunarLoader = null;
+
// Updates time specific variables (time-zone, today's Julian day).
private final Runnable mTimeUpdater = new Runnable() {
@Override
@@ -83,6 +90,13 @@ public class CalendarViewAdapter extends BaseAdapter {
}
};
+ private OnLoadCompleteListener<Void> mLunarLoaderListener = new OnLoadCompleteListener<Void>() {
+ @Override
+ public void onLoadComplete(Loader<Void> loader, Void data) {
+ notifyDataSetChanged();
+ }
+ };
+
public CalendarViewAdapter(Context context, int viewType, boolean showDate) {
super();
@@ -101,8 +115,19 @@ public class CalendarViewAdapter extends BaseAdapter {
if (showDate) {
refresh(context);
}
+
+ mLunarLoader = new LunarInfoLoader(mContext);
+ mLunarLoader.registerListener(0, mLunarLoaderListener);
}
+ @Override
+ protected void finalize() throws Throwable {
+ LunarUtils.clearInfo();
+ if (mLunarLoader != null && mLunarLoaderListener != null) {
+ mLunarLoader.unregisterListener(mLunarLoaderListener);
+ }
+ super.finalize();
+ }
// Sets the time zone and today's Julian day to be used by the adapter.
// Also, notify listener on the change and resets the midnight update thread.
@@ -177,15 +202,30 @@ public class CalendarViewAdapter extends BaseAdapter {
v = convertView;
}
TextView weekDay = (TextView) v.findViewById(R.id.top_button_weekday);
+ TextView lunarInfo = (TextView) v.findViewById(R.id.top_button_lunar);
TextView date = (TextView) v.findViewById(R.id.top_button_date);
switch (mCurrentMainView) {
case ViewType.DAY:
weekDay.setVisibility(View.VISIBLE);
weekDay.setText(buildDayOfWeek());
+ if (LunarUtils.showLunar(mContext)) {
+ lunarInfo.setVisibility(View.VISIBLE);
+ Time time = new Time(mTimeZone);
+ time.set(mMilliTime);
+ int flag = LunarUtils.FORMAT_LUNAR_LONG | LunarUtils.FORMAT_MULTI_FESTIVAL;
+ String lunar = LunarUtils.get(mContext, time.year, time.month,
+ time.monthDay, flag, false, null);
+ if (!TextUtils.isEmpty(lunar)) {
+ lunarInfo.setText(lunar);
+ }
+ } else {
+ lunarInfo.setVisibility(View.GONE);
+ }
date.setText(buildFullDate());
break;
case ViewType.WEEK:
+ lunarInfo.setVisibility(View.GONE);
if (Utils.getShowWeekNumber(mContext)) {
weekDay.setVisibility(View.VISIBLE);
weekDay.setText(buildWeekNum());
@@ -196,10 +236,12 @@ public class CalendarViewAdapter extends BaseAdapter {
break;
case ViewType.MONTH:
weekDay.setVisibility(View.GONE);
+ lunarInfo.setVisibility(View.GONE);
date.setText(buildMonthYearDate());
break;
case ViewType.AGENDA:
weekDay.setVisibility(View.VISIBLE);
+ lunarInfo.setVisibility(View.GONE);
weekDay.setText(buildDayOfWeek());
date.setText(buildFullDate());
break;
@@ -304,6 +346,9 @@ public class CalendarViewAdapter extends BaseAdapter {
// Used when the user selects a new day/week/month to watch
public void setTime(long time) {
mMilliTime = time;
+ if (LunarUtils.showLunar(mContext)) {
+ buildLunarInfo();
+ }
notifyDataSetChanged();
}
@@ -421,5 +466,30 @@ public class CalendarViewAdapter extends BaseAdapter {
return mContext.getResources().getQuantityString(R.plurals.weekN, week, week);
}
+ private void buildLunarInfo() {
+ if (mLunarLoader == null || TextUtils.isEmpty(mTimeZone)) return;
+
+ Time time = new Time(mTimeZone);
+ if (time != null) {
+ // The the current month.
+ time.set(mMilliTime);
+
+ // As the first day of previous month;
+ Calendar from = Calendar.getInstance();
+ from.set(time.year, time.month - 1, 1);
+
+ // Get the last day of next month.
+ Calendar to = Calendar.getInstance();
+ to.set(Calendar.YEAR, time.year);
+ to.set(Calendar.MONTH, time.month + 1);
+ to.set(Calendar.DAY_OF_MONTH, to.getMaximum(Calendar.DAY_OF_MONTH));
+
+ // Call LunarUtils to load the info.
+ mLunarLoader.load(from.get(Calendar.YEAR), from.get(Calendar.MONTH),
+ from.get(Calendar.DAY_OF_MONTH), to.get(Calendar.YEAR), to.get(Calendar.MONTH),
+ to.get(Calendar.DAY_OF_MONTH));
+ }
+ }
+
}
diff --git a/src/com/android/calendar/DayView.java b/src/com/android/calendar/DayView.java
index 68ae6a46..35cafbcb 100644
--- a/src/com/android/calendar/DayView.java
+++ b/src/com/android/calendar/DayView.java
@@ -734,6 +734,9 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
}
HOURS_MARGIN = HOURS_LEFT_MARGIN + HOURS_RIGHT_MARGIN;
DAY_HEADER_HEIGHT = mNumDays == 1 ? ONE_DAY_HEADER_HEIGHT : MULTI_DAY_HEADER_HEIGHT;
+ if (LunarUtils.showLunar(mContext) && mNumDays != 1) {
+ DAY_HEADER_HEIGHT = (int) (DAY_HEADER_HEIGHT + DAY_HEADER_FONT_SIZE + 2);
+ }
mCurrentTimeLine = mResources.getDrawable(R.drawable.timeline_indicator_holo_light);
mCurrentTimeAnimateLine = mResources
@@ -2560,8 +2563,12 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
// Draw day of the month
String dateNumStr = String.valueOf(dateNum);
if (mNumDays > 1) {
- float y = DAY_HEADER_HEIGHT - DAY_HEADER_BOTTOM_MARGIN;
-
+ float y = -1;
+ if (LunarUtils.showLunar(mContext)) {
+ y = DAY_HEADER_HEIGHT - DAY_HEADER_BOTTOM_MARGIN - DATE_HEADER_FONT_SIZE - 2;
+ } else {
+ y = DAY_HEADER_HEIGHT - DAY_HEADER_BOTTOM_MARGIN;
+ }
// Draw day of the month
x = computeDayLeftPosition(day + 1) - DAY_HEADER_RIGHT_MARGIN;
p.setTextAlign(Align.RIGHT);
@@ -2571,10 +2578,31 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
canvas.drawText(dateNumStr, x, y, p);
// Draw day of the week
- x -= p.measureText(" " + dateNumStr);
+ int dateX = (int) (x - p.measureText(" " + dateNumStr));
p.setTextSize(DAY_HEADER_FONT_SIZE);
p.setTypeface(Typeface.DEFAULT);
- canvas.drawText(dayStr, x, y, p);
+ canvas.drawText(dayStr, dateX, y, p);
+
+ // To show the lunar info.
+ if (LunarUtils.showLunar(mContext)) {
+ // adjust the year and month
+ int month = mBaseDate.month;
+ int year = mBaseDate.year;
+ if (dateNum > mMonthLength || dateNum < mFirstVisibleDate) {
+ month = month + 1;
+ if (month > 11) {
+ month = 0;
+ year = year + 1;
+ }
+ }
+
+ String lunarInfo = LunarUtils.get(mContext, year, month, dateNum,
+ LunarUtils.FORMAT_LUNAR_SHORT | LunarUtils.FORMAT_ONE_FESTIVAL,
+ false, null);
+ if (!TextUtils.isEmpty(lunarInfo)) {
+ canvas.drawText(lunarInfo, x, y + DAY_HEADER_FONT_SIZE + 2, p);
+ }
+ }
} else {
float y = ONE_DAY_HEADER_HEIGHT - DAY_HEADER_ONE_DAY_BOTTOM_MARGIN;
p.setTextAlign(Align.LEFT);
diff --git a/src/com/android/calendar/LunarUtils.java b/src/com/android/calendar/LunarUtils.java
new file mode 100644
index 00000000..2c7515d9
--- /dev/null
+++ b/src/com/android/calendar/LunarUtils.java
@@ -0,0 +1,306 @@
+/*
+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.android.calendar;
+
+import android.content.AsyncTaskLoader;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Locale;
+
+public class LunarUtils {
+ private static final String TAG = "LunarUtils";
+
+ // The flags used for get the lunar info.
+ public static final int FORMAT_LUNAR_LONG = 0x00001;
+ public static final int FORMAT_LUNAR_SHORT = 0x00002;
+ public static final int FORMAT_ONE_FESTIVAL = 0x00004;
+ public static final int FORMAT_MULTI_FESTIVAL = 0x00008;
+ public static final int FORMAT_ANIMAL = 0x00010;
+
+ private static final String INFO_SEPARATE = " ";
+ private static final String MORE_FESTIVAL_SUFFIX = "*";
+
+ private static HashMap<String, LunarInfo> sLunarInfos = new HashMap<String, LunarInfo>();
+
+ /**
+ * If need show the lunar info now. As default, it will need shown if the current
+ * language is zh-cn.
+ */
+ public static boolean showLunar(Context context) {
+ Locale locale = Locale.getDefault();
+ String language = locale.getLanguage().toLowerCase();
+ String country = locale.getCountry().toLowerCase();
+ return ("zh".equals(language) && "cn".equals(country));
+ }
+
+ /**
+ * Used to clear the saved info.
+ */
+ public static void clearInfo() {
+ Log.i(TAG, "Clear all the saved info.");
+ sLunarInfos.clear();
+ }
+
+ /**
+ * Used to get the lunar, festival and animal info of the date. Before you call this
+ * function to get the info, you need make sure already load the info by calling
+ * {@link LunarInfoLoader#load} to pre-load them.
+ * @param format Format which info need append to the result.
+ * The format {@link #FORMAT_LUNAR_LONG} and {@link #FORMAT_LUNAR_SHORT},
+ * {@link #FORMAT_ONE_FESTIVAL} and {@link #FORMAT_MULTI_FESTIVAL} could not
+ * selected at once.
+ * @param showLunarBeforeFestival If the festival is exist for the date, if need append the
+ * lunar info before the festival info.
+ * @param result [out] The result will be saved in this list as your given format.
+ * @return The result as string for your given format.
+ */
+ public static String get(Context context, int year, int month, int day, int format,
+ boolean showLunarBeforeFestival, ArrayList<String> result) {
+ if (context == null || format < FORMAT_LUNAR_LONG) return null;
+
+ String res = null;
+
+ // Try to find the matched lunar info from the hash map.
+ String key = getKey(year, month, day);
+ LunarInfo info = sLunarInfos.get(key);
+ if (info != null) {
+ res = buildInfo(info, format, showLunarBeforeFestival, result);
+ } else {
+ Log.d(TAG, "Couldn't get the lunar info for " + key);
+ }
+
+ return res;
+ }
+
+ private static String getKey(int year, int month, int day) {
+ return year + "-" + month + "-" + day;
+ }
+
+ private static String buildInfo(LunarInfo info, int format, boolean showLunarBeforeFestival,
+ ArrayList<String> list) {
+ if (info == null || format < FORMAT_LUNAR_LONG) return null;
+
+ StringBuilder result = new StringBuilder();
+
+ if (showLunarBeforeFestival || TextUtils.isEmpty(info._festival1)) {
+ // The format should not support long and short at one time.
+ if ((format & FORMAT_LUNAR_LONG) == FORMAT_LUNAR_LONG) {
+ appendInfo(result, info._label_long, list);
+ } else if ((format & FORMAT_LUNAR_SHORT) == FORMAT_LUNAR_SHORT) {
+ appendInfo(result, info._label_short, list);
+ }
+ }
+
+ // The format should not support only one festival and multiple festivals.
+ if ((format & FORMAT_ONE_FESTIVAL) == FORMAT_ONE_FESTIVAL) {
+ String festival = info._festival1;
+ if (!TextUtils.isEmpty(info._festival2)) {
+ festival = festival + MORE_FESTIVAL_SUFFIX;
+ }
+ appendInfo(result, festival, list);
+ } else if ((format & FORMAT_MULTI_FESTIVAL) == FORMAT_MULTI_FESTIVAL) {
+ appendInfo(result, info._festival1, list);
+ appendInfo(result, info._festival2, list);
+ appendInfo(result, info._festival3, list);
+ appendInfo(result, info._festival4, list);
+ }
+
+ if ((format & FORMAT_ANIMAL) == FORMAT_ANIMAL) {
+ appendInfo(result, info._animal, list);
+ }
+
+ return result.toString();
+ }
+
+ private static void appendInfo(StringBuilder builder, String info, ArrayList<String> list) {
+ if (builder == null || TextUtils.isEmpty(info)) return;
+
+ String prefix = builder.length() > 0 ? INFO_SEPARATE : "";
+ builder.append(prefix).append(info);
+
+ if (list != null) list.add(info);
+ }
+
+ public static class LunarInfoLoader extends AsyncTaskLoader<Void> {
+ private static final Uri CONTENT_URI_GET_ONE_DAY =
+ Uri.parse("content://com.qualcomm.qti.lunarinfo/one_day");
+ private static final Uri CONTENT_URI_GET_ONE_MONTH =
+ Uri.parse("content://com.qualcomm.qti.lunarinfo/one_month");
+ private static final Uri CONTENT_URI_GET_FROM_TO =
+ Uri.parse("content://com.qualcomm.qti.lunarinfo/from_to");
+
+ // The query parameters used to get lunar info.
+ private static final String PARAM_YEAR = "year";
+ private static final String PARAM_MONTH = "month";
+ private static final String PARAM_DAY = "day";
+ private static final String PARAM_FROM_YEAR = "from_year";
+ private static final String PARAM_FROM_MONTH = "from_month";
+ private static final String PARAM_FROM_DAY = "from_day";
+ private static final String PARAM_TO_YEAR = "to_year";
+ private static final String PARAM_TO_MONTH = "to_month";
+ private static final String PARAM_TO_DAY = "to_day";
+
+ // The columns for result.
+ private static final String COL_ID = "_id";
+ private static final String COL_YEAR = "year";
+ private static final String COL_MONTH = "month";
+ private static final String COL_DAY = "day";
+ private static final String COL_LUNAR_LABEL_LONG = "lunar_label_long";
+ private static final String COL_LUNAR_LABEL_SHORT = "lunar_label_short";
+ private static final String COL_ANIMAL = "animal";
+ private static final String COL_FESTIVAL_1 = "festival_1";
+ private static final String COL_FESTIVAL_2 = "festival_2";
+ private static final String COL_FESTIVAL_3 = "festival_3";
+ private static final String COL_FESTIVAL_4 = "festival_4";
+
+ private static int sIndexId = -1;
+ private static int sIndexYear = -1;
+ private static int sIndexMonth = -1;
+ private static int sIndexDay = -1;
+ private static int sIndexLunarLabelLong = -1;
+ private static int sIndexLunarLabelShort = -1;
+ private static int sIndexAnimal = -1;
+ private static int sIndexFestival1 = -1;
+ private static int sIndexFestival2 = -1;
+ private static int sIndexFestival3 = -1;
+ private static int sIndexFestival4 = -1;
+
+ private Uri mUri;
+
+ public LunarInfoLoader(Context context) {
+ super(context);
+ }
+
+ public void load(int year, int month, int day) {
+ reset();
+ // Build the query uri.
+ mUri = CONTENT_URI_GET_ONE_DAY.buildUpon()
+ .appendQueryParameter(PARAM_YEAR, String.valueOf(year))
+ .appendQueryParameter(PARAM_MONTH, String.valueOf(month))
+ .appendQueryParameter(PARAM_DAY, String.valueOf(day))
+ .build();
+ startLoading();
+ forceLoad();
+ }
+
+ public void load(int year, int month) {
+ reset();
+ // Build the query uri.
+ mUri = CONTENT_URI_GET_ONE_MONTH.buildUpon()
+ .appendQueryParameter(PARAM_YEAR, String.valueOf(year))
+ .appendQueryParameter(PARAM_MONTH, String.valueOf(month))
+ .build();
+ startLoading();
+ forceLoad();
+ }
+
+ public void load(int from_year, int from_month, int from_day,
+ int to_year, int to_month, int to_day) {
+ reset();
+ // Build the query uri.
+ mUri = CONTENT_URI_GET_FROM_TO.buildUpon()
+ .appendQueryParameter(PARAM_FROM_YEAR, String.valueOf(from_year))
+ .appendQueryParameter(PARAM_FROM_MONTH, String.valueOf(from_month))
+ .appendQueryParameter(PARAM_FROM_DAY, String.valueOf(from_day))
+ .appendQueryParameter(PARAM_TO_YEAR, String.valueOf(to_year))
+ .appendQueryParameter(PARAM_TO_MONTH, String.valueOf(to_month))
+ .appendQueryParameter(PARAM_TO_DAY, String.valueOf(to_day))
+ .build();
+ startLoading();
+ forceLoad();
+ }
+
+ @Override
+ public Void loadInBackground() {
+ Cursor cursor = getContext().getContentResolver().query(mUri, null, null, null, null);
+ try {
+ if (cursor == null || cursor.getCount() < 1) return null;
+
+ if (sIndexId < 0) getIndexValue(cursor);
+ while (cursor.moveToNext()) {
+ int year = cursor.getInt(sIndexYear);
+ int month = cursor.getInt(sIndexMonth);
+ int day = cursor.getInt(sIndexDay);
+
+ LunarInfo info = new LunarInfo();
+ info._label_long = cursor.getString(sIndexLunarLabelLong);
+ info._label_short = cursor.getString(sIndexLunarLabelShort);
+ info._animal = cursor.getString(sIndexAnimal);
+ info._festival1 = cursor.getString(sIndexFestival1);
+ info._festival2 = cursor.getString(sIndexFestival2);
+ info._festival3 = cursor.getString(sIndexFestival3);
+ info._festival4 = cursor.getString(sIndexFestival4);
+
+ sLunarInfos.put(getKey(year, month, day), info);
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ cursor = null;
+ }
+ }
+
+ return null;
+ }
+
+ private void getIndexValue(Cursor cursor) {
+ if (cursor == null) return;
+
+ sIndexId = cursor.getColumnIndexOrThrow(COL_ID);
+ sIndexYear = cursor.getColumnIndexOrThrow(COL_YEAR);
+ sIndexMonth = cursor.getColumnIndexOrThrow(COL_MONTH);
+ sIndexDay = cursor.getColumnIndexOrThrow(COL_DAY);
+ sIndexLunarLabelLong = cursor.getColumnIndexOrThrow(COL_LUNAR_LABEL_LONG);
+ sIndexLunarLabelShort = cursor.getColumnIndexOrThrow(COL_LUNAR_LABEL_SHORT);
+ sIndexAnimal = cursor.getColumnIndexOrThrow(COL_ANIMAL);
+ sIndexFestival1 = cursor.getColumnIndexOrThrow(COL_FESTIVAL_1);
+ sIndexFestival2 = cursor.getColumnIndexOrThrow(COL_FESTIVAL_2);
+ sIndexFestival3 = cursor.getColumnIndexOrThrow(COL_FESTIVAL_3);
+ sIndexFestival4 = cursor.getColumnIndexOrThrow(COL_FESTIVAL_4);
+ }
+
+ }
+
+ private static class LunarInfo {
+ public String _label_long;
+ public String _label_short;
+ public String _animal;
+ public String _festival1;
+ public String _festival2;
+ public String _festival3;
+ public String _festival4;
+ }
+}
diff --git a/src/com/android/calendar/month/MonthWeekEventsView.java b/src/com/android/calendar/month/MonthWeekEventsView.java
index e1c78c67..6ffc254d 100644
--- a/src/com/android/calendar/month/MonthWeekEventsView.java
+++ b/src/com/android/calendar/month/MonthWeekEventsView.java
@@ -17,6 +17,7 @@
package com.android.calendar.month;
import com.android.calendar.Event;
+import com.android.calendar.LunarUtils;
import com.android.calendar.R;
import com.android.calendar.Utils;
@@ -64,6 +65,7 @@ public class MonthWeekEventsView extends SimpleWeekView {
/* NOTE: these are not constants, and may be multiplied by a scale factor */
private static int TEXT_SIZE_MONTH_NUMBER = 32;
+ private static int TEXT_SIZE_LUNAR = 10;
private static int TEXT_SIZE_EVENT = 12;
private static int TEXT_SIZE_EVENT_TITLE = 14;
private static int TEXT_SIZE_MORE_EVENTS = 12;
@@ -89,6 +91,7 @@ public class MonthWeekEventsView extends SimpleWeekView {
private static int DAY_SEPARATOR_VERTICAL_LENGTH = 53;
private static int DAY_SEPARATOR_VERTICAL_LENGHT_PORTRAIT = 64;
private static int MIN_WEEK_WIDTH = 50;
+ private static int LUNAR_PADDING_LUNAR = 2;
private static int EVENT_X_OFFSET_LANDSCAPE = 38;
private static int EVENT_Y_OFFSET_LANDSCAPE = 8;
@@ -116,8 +119,6 @@ public class MonthWeekEventsView extends SimpleWeekView {
// events being drawn on each day. The code will expand this if necessary.
protected FloatRef mEventOutlines = new FloatRef(10 * 4 * 4 * 7);
-
-
protected static StringBuilder mStringBuilder = new StringBuilder(50);
// TODO recreate formatter when locale changes
protected static Formatter mFormatter = new Formatter(mStringBuilder, Locale.getDefault());
@@ -360,6 +361,7 @@ public class MonthWeekEventsView extends SimpleWeekView {
SIDE_PADDING_WEEK_NUMBER *= mScale;
SPACING_WEEK_NUMBER *= mScale;
TEXT_SIZE_MONTH_NUMBER *= mScale;
+ TEXT_SIZE_LUNAR *= mScale;
TEXT_SIZE_EVENT *= mScale;
TEXT_SIZE_EVENT_TITLE *= mScale;
TEXT_SIZE_MORE_EVENTS *= mScale;
@@ -696,6 +698,12 @@ public class MonthWeekEventsView extends SimpleWeekView {
boolean isFocusMonth = mFocusDay[i];
boolean isBold = false;
mMonthNumPaint.setColor(isFocusMonth ? mMonthNumColor : mMonthNumOtherColor);
+
+ // Get the julian monday used to show the lunar info.
+ int julianMonday = Utils.getJulianMondayFromWeeksSinceEpoch(mWeek);
+ Time time = new Time(mTimeZone);
+ time.setJulianDay(julianMonday);
+
for (; i < numCount; i++) {
if (mHasToday && todayIndex == i) {
mMonthNumPaint.setColor(mMonthNumTodayColor);
@@ -714,6 +722,62 @@ public class MonthWeekEventsView extends SimpleWeekView {
if (isBold) {
mMonthNumPaint.setFakeBoldText(isBold = false);
}
+
+ if (LunarUtils.showLunar(getContext())) {
+ // adjust the year and month
+ int year = time.year;
+ int month = time.month;
+ int julianMondayDay = time.monthDay;
+ int monthDay = Integer.parseInt(mDayNumbers[i]);
+ if (monthDay != julianMondayDay) {
+ int offsetDay = monthDay - julianMondayDay;
+ if (offsetDay > 0 && offsetDay > 6) {
+ month = month - 1;
+ if (month < 0) {
+ month = 11;
+ year = year - 1;
+ }
+ } else if (offsetDay < 0 && offsetDay < -6) {
+ month = month + 1;
+ if (month > 11) {
+ month = 0;
+ year = year + 1;
+ }
+ }
+ }
+
+ ArrayList<String> infos = new ArrayList<String>();
+ LunarUtils.get(getContext(), year, month, monthDay,
+ LunarUtils.FORMAT_LUNAR_SHORT | LunarUtils.FORMAT_MULTI_FESTIVAL, false,
+ infos);
+ if (infos.size() > 0) {
+ float originalTextSize = mMonthNumPaint.getTextSize();
+ mMonthNumPaint.setTextSize(TEXT_SIZE_LUNAR);
+ Resources res = getResources();
+ int mOrientation = res.getConfiguration().orientation;
+
+ int num = 0;
+ for (int index = 0; index < infos.size(); index++) {
+ String info = infos.get(index);
+ if (TextUtils.isEmpty(info)) continue;
+
+ int infoX = 0;
+ int infoY = 0;
+ if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
+ infoX = x - mMonthNumHeight - TOP_PADDING_MONTH_NUMBER;
+ infoY = y + (mMonthNumHeight + LUNAR_PADDING_LUNAR) * num;
+ } else {
+ infoX = x;
+ infoY = y + (mMonthNumHeight + LUNAR_PADDING_LUNAR) * (num + 1);
+ }
+ canvas.drawText(info, infoX, infoY, mMonthNumPaint);
+ num = num + 1;
+ }
+
+ // restore the text size.
+ mMonthNumPaint.setTextSize(originalTextSize);
+ }
+ }
}
}