summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryingying <yingying@codeaurora.org>2013-12-30 03:53:21 -0500
committerSteve Kondik <steve@cyngn.com>2015-10-18 13:52:39 -0700
commite0978b2e507b21692d70886dd6437ad8762d0221 (patch)
tree58a44d7f7b892f3781927ef9718c3dde96fd732d /src
parent52463f36899c9051c42ac784077e514864e52373 (diff)
downloadandroid_packages_apps_Calendar-e0978b2e507b21692d70886dd6437ad8762d0221.tar.gz
android_packages_apps_Calendar-e0978b2e507b21692d70886dd6437ad8762d0221.tar.bz2
android_packages_apps_Calendar-e0978b2e507b21692d70886dd6437ad8762d0221.zip
Calendar: Support display the lunar info.
- It will show the lunar info on the Month, Week and Day view. - If the current displayed language is not Chinese, it will not show the lunar info for on these views. Change-Id: I1aeb4bc27dbdd127e69ceb0bf50abc1509cf4bb2
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calendar/AllInOneActivity.java34
-rw-r--r--src/com/android/calendar/CalendarViewAdapter.java96
-rw-r--r--src/com/android/calendar/DayView.java61
-rw-r--r--src/com/android/calendar/month/MonthWeekEventsView.java57
-rw-r--r--src/com/android/lunar/ILunarService.aidl50
-rw-r--r--src/com/android/lunar/LunarUtils.java80
6 files changed, 374 insertions, 4 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java
index 0e1feb49..9b623e4f 100644
--- a/src/com/android/calendar/AllInOneActivity.java
+++ b/src/com/android/calendar/AllInOneActivity.java
@@ -31,9 +31,12 @@ import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.AsyncQueryHandler;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentUris;
+import android.content.Context;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration;
@@ -44,6 +47,7 @@ import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
+import android.os.IBinder;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
@@ -71,6 +75,8 @@ import com.android.calendar.CalendarController.ViewType;
import com.android.calendar.agenda.AgendaFragment;
import com.android.calendar.month.MonthByWeekFragment;
import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
+import com.android.lunar.ILunarService;
+import com.android.lunar.LunarUtils;
import java.io.IOException;
import java.util.List;
@@ -167,6 +173,23 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
private AllInOneMenuExtensionsInterface mExtensions = ExtensionsFactory
.getAllInOneMenuExtensions();
+ // To connect the lunar service
+ private ILunarService mLunarService = null;
+ private ServiceConnection mLunarConnection = new ServiceConnection() {
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mLunarService = null;
+ LunarUtils.setService(null);
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mLunarService = ILunarService.Stub.asInterface(service);
+ LunarUtils.setService(mLunarService);
+ }
+ };
+
private final AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
@Override
@@ -307,6 +330,12 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
}
super.onCreate(icicle);
+ // Bind the lunar service
+ if (LunarUtils.showLunar() && mLunarService == null) {
+ bindService(new Intent(ILunarService.class.getName()), mLunarConnection,
+ Context.BIND_AUTO_CREATE);
+ }
+
if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
}
@@ -610,6 +639,11 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
protected void onDestroy() {
super.onDestroy();
+ // Unbind the lunar service
+ if (mLunarService != null && mLunarConnection != null) {
+ unbindService(mLunarConnection);
+ }
+
SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
prefs.unregisterOnSharedPreferenceChangeListener(this);
diff --git a/src/com/android/calendar/CalendarViewAdapter.java b/src/com/android/calendar/CalendarViewAdapter.java
index f07d4d8a..6b986d08 100644
--- a/src/com/android/calendar/CalendarViewAdapter.java
+++ b/src/com/android/calendar/CalendarViewAdapter.java
@@ -17,11 +17,17 @@
package com.android.calendar;
import com.android.calendar.CalendarController.ViewType;
+import com.android.lunar.ILunarService;
+import com.android.lunar.LunarUtils;
+import com.android.lunar.LunarUtils.LunarServiceConnListener;
import android.content.Context;
import android.os.Handler;
+import android.os.RemoteException;
+import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.format.Time;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -29,6 +35,7 @@ import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.Formatter;
+import java.util.HashMap;
import java.util.Locale;
@@ -75,6 +82,24 @@ 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)
+ // Create the connect listener for lunar service.
+ private HashMap<String, String> mLunarInfoMap = new HashMap<String, String>();
+ private LunarServiceConnListener mLunarServiceConnListener = new LunarServiceConnListener() {
+
+ @Override
+ public void onLunarServiceDisconnected() {
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public void onLunarServiceConnected(ILunarService service) {
+ if (service != null && LunarUtils.getService() != null && LunarUtils.showLunar()) {
+ buildLunarInfo();
+ notifyDataSetChanged();
+ }
+ }
+ };
+
// Updates time specific variables (time-zone, today's Julian day).
private final Runnable mTimeUpdater = new Runnable() {
@Override
@@ -97,6 +122,8 @@ public class CalendarViewAdapter extends BaseAdapter {
mStringBuilder = new StringBuilder(50);
mFormatter = new Formatter(mStringBuilder, Locale.getDefault());
+ LunarUtils.setListener(mLunarServiceConnListener);
+
// Sets time specific variables and starts a thread for midnight updates
if (showDate) {
refresh(context);
@@ -177,15 +204,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.getService() != null && LunarUtils.showLunar()) {
+ lunarInfo.setVisibility(View.VISIBLE);
+ String dateStr = Utils.formatDateRange(mContext, mMilliTime, mMilliTime,
+ DateUtils.FORMAT_SHOW_DATE);
+ if (mLunarInfoMap.containsKey(dateStr)) {
+ lunarInfo.setText(mLunarInfoMap.get(dateStr));
+ } else {
+ buildLunarInfo();
+ notifyDataSetChanged();
+ }
+ } 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 +238,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 +348,14 @@ 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.getService() != null && LunarUtils.showLunar()) {
+ new Thread (new Runnable() {
+ @Override
+ public void run() {
+ buildLunarInfo();
+ }
+ }).start();
+ }
notifyDataSetChanged();
}
@@ -421,5 +473,49 @@ public class CalendarViewAdapter extends BaseAdapter {
return mContext.getResources().getQuantityString(R.plurals.weekN, week, week);
}
+ private void buildLunarInfo() {
+ if (TextUtils.isEmpty(mTimeZone)) return;
+
+ Time time = new Time(mTimeZone);
+ try {
+ ILunarService service = LunarUtils.getService();
+ if (service != null && time != null) {
+ // put the current time lunar string into map
+ time.set(mMilliTime);
+ String date = Utils.formatDateRange(mContext, mMilliTime, mMilliTime,
+ DateUtils.FORMAT_SHOW_DATE);
+ if (!mLunarInfoMap.containsKey(date)) {
+ String lunarInfo = service.getLunarStringForDayView(
+ time.year, time.month, time.monthDay);
+ mLunarInfoMap.put(date, lunarInfo);
+ }
+
+ // put the pre time lunar string into map
+ long preMilliTime = mMilliTime - 24 * 3600 * 1000;
+ time.set(preMilliTime);
+ date = Utils.formatDateRange(mContext, preMilliTime, preMilliTime,
+ DateUtils.FORMAT_SHOW_DATE);
+ if (!mLunarInfoMap.containsKey(date)) {
+ String lunarInfo = service.getLunarStringForDayView(
+ time.year, time.month, time.monthDay);
+ mLunarInfoMap.put(date, lunarInfo);
+ }
+
+ // put the next time lunar string into map
+ long nextMilliTime = mMilliTime + 24 * 3600 * 1000;
+ time.set(nextMilliTime);
+ date = Utils.formatDateRange(mContext, nextMilliTime, nextMilliTime,
+ DateUtils.FORMAT_SHOW_DATE);
+ if (!mLunarInfoMap.containsKey(date)) {
+ String lunarInfo = service.getLunarStringForDayView(
+ time.year, time.month, time.monthDay);
+ mLunarInfoMap.put(date, lunarInfo);
+ }
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "build lunar info, catch the RemoteException:");
+ e.printStackTrace();
+ }
+ }
}
diff --git a/src/com/android/calendar/DayView.java b/src/com/android/calendar/DayView.java
index 68ae6a46..7f6cbce6 100644
--- a/src/com/android/calendar/DayView.java
+++ b/src/com/android/calendar/DayView.java
@@ -38,6 +38,7 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
+import android.os.RemoteException;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
@@ -79,6 +80,9 @@ import android.widget.ViewSwitcher;
import com.android.calendar.CalendarController.EventType;
import com.android.calendar.CalendarController.ViewType;
+import com.android.lunar.ILunarService;
+import com.android.lunar.LunarUtils;
+import com.android.lunar.LunarUtils.LunarServiceConnListener;
import java.util.ArrayList;
import java.util.Arrays;
@@ -196,6 +200,24 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
// TODO recreate formatter when locale changes
protected static Formatter mFormatter = new Formatter(mStringBuilder, Locale.getDefault());
+ private LunarServiceConnListener mLunarServiceConnListener = new LunarServiceConnListener() {
+
+ @Override
+ public void onLunarServiceDisconnected() {
+ DAY_HEADER_HEIGHT = mNumDays == 1 ? ONE_DAY_HEADER_HEIGHT : MULTI_DAY_HEADER_HEIGHT;
+ }
+
+ @Override
+ public void onLunarServiceConnected(ILunarService service) {
+ if (service != null) {
+ DAY_HEADER_HEIGHT = mNumDays == 1 ? ONE_DAY_HEADER_HEIGHT : MULTI_DAY_HEADER_HEIGHT;
+ if (LunarUtils.showLunar() && mNumDays != 1) {
+ DAY_HEADER_HEIGHT = (int) (DAY_HEADER_HEIGHT + DAY_HEADER_FONT_SIZE + 2);
+ }
+ }
+ }
+ };
+
private final Runnable mTZUpdater = new Runnable() {
@Override
public void run() {
@@ -773,6 +795,8 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
mOnDownDelay = ViewConfiguration.getTapTimeout();
OVERFLING_DISTANCE = vc.getScaledOverflingDistance();
+ LunarUtils.setListener(mLunarServiceConnListener);
+
init(context);
}
@@ -2560,8 +2584,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() && LunarUtils.getService() != null) {
+ 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 +2599,35 @@ 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.
+ ILunarService service = LunarUtils.getService();
+ if (LunarUtils.showLunar() && service != null) {
+ // 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;
+ }
+ }
+
+ try {
+ String display = service.getLunarDay(year, month, dateNum);
+ if (!TextUtils.isEmpty(display)) {
+ canvas.drawText(display, x, y + DAY_HEADER_FONT_SIZE + 2, p);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException e:" + e.toString());
+ e.printStackTrace();
+ }
+ }
} else {
float y = ONE_DAY_HEADER_HEIGHT - DAY_HEADER_ONE_DAY_BOTTOM_MARGIN;
p.setTextAlign(Align.LEFT);
diff --git a/src/com/android/calendar/month/MonthWeekEventsView.java b/src/com/android/calendar/month/MonthWeekEventsView.java
index e1c78c67..a5dd5dae 100644
--- a/src/com/android/calendar/month/MonthWeekEventsView.java
+++ b/src/com/android/calendar/month/MonthWeekEventsView.java
@@ -19,6 +19,8 @@ package com.android.calendar.month;
import com.android.calendar.Event;
import com.android.calendar.R;
import com.android.calendar.Utils;
+import com.android.lunar.ILunarService;
+import com.android.lunar.LunarUtils;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -34,6 +36,7 @@ import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
+import android.os.RemoteException;
import android.provider.CalendarContract.Attendees;
import android.text.TextPaint;
import android.text.TextUtils;
@@ -64,6 +67,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 = 18;
private static int TEXT_SIZE_EVENT = 12;
private static int TEXT_SIZE_EVENT_TITLE = 14;
private static int TEXT_SIZE_MORE_EVENTS = 12;
@@ -696,6 +700,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 +724,53 @@ public class MonthWeekEventsView extends SimpleWeekView {
if (isBold) {
mMonthNumPaint.setFakeBoldText(isBold = false);
}
+
+ ILunarService service = LunarUtils.getService();
+ if (LunarUtils.showLunar() && service != null) {
+ // 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;
+ }
+ }
+ }
+
+ try {
+ String display = service.getLunarDay(year, month, monthDay);
+ if (!TextUtils.isEmpty(display)) {
+ float originalTextSize = mMonthNumPaint.getTextSize();
+ mMonthNumPaint.setTextSize(TEXT_SIZE_LUNAR);
+ Resources res = getResources();
+ int mOrientation = res.getConfiguration().orientation;
+ if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
+ canvas.drawText(display, x - mMonthNumHeight - TOP_PADDING_MONTH_NUMBER,
+ y , mMonthNumPaint);
+ } else {
+ canvas.drawText(display, x, y + mMonthNumHeight
+ + TOP_PADDING_MONTH_NUMBER, mMonthNumPaint);
+ }
+ // restore the text size.
+ mMonthNumPaint.setTextSize(originalTextSize);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException e:" + e.toString());
+ e.printStackTrace();
+ }
+ }
}
}
diff --git a/src/com/android/lunar/ILunarService.aidl b/src/com/android/lunar/ILunarService.aidl
new file mode 100644
index 00000000..f5a24f32
--- /dev/null
+++ b/src/com/android/lunar/ILunarService.aidl
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2013, 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.lunar;
+
+interface ILunarService {
+ String getTraditionalFestivalSimple();
+ String getTraditionalFestival(int lunarYear, int lunarMonth, int lunarDay);
+ String getFestivalSimple();
+ String getFestival(int year, int month, int day);
+ String getLunarSolarTerms(int year);
+ String getAnimalsYearSimple();
+ String getAnimalsYear(int lunarYear);
+ String getChinaMonthStringSimple();
+ String getChinaMonthString(int lunarMonth, boolean isLeapMonth);
+ String getChinaDayStringSimple(boolean isDisplayLunarMonthForFirstDay);
+ String getChinaDayString(int lunarMonth, int lunarDay, boolean isLeapMonth,
+ boolean isDisplayLunarMonthForFirstDay);
+ String getChinaYearStringSimple();
+ String getChinaYearString(int lunarYear);
+ String getLunarCalendarInfo();
+ String getLunarStringForDayView(int year, int month, int monthDay);
+ String getLunarDay(int year, int month, int monthDay);
+}
diff --git a/src/com/android/lunar/LunarUtils.java b/src/com/android/lunar/LunarUtils.java
new file mode 100644
index 00000000..b9721ed9
--- /dev/null
+++ b/src/com/android/lunar/LunarUtils.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2013, 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.lunar;
+
+import java.util.Locale;
+
+public class LunarUtils {
+
+ private static ILunarService sService = null;
+ private static LunarServiceConnListener sListener = null;
+
+ public static void setService(ILunarService service) {
+ sService = service;
+ if (sListener != null) {
+ if (sService != null) {
+ sListener.onLunarServiceConnected(sService);
+ } else {
+ sListener.onLunarServiceDisconnected();
+ }
+ }
+ }
+
+ public static ILunarService getService() {
+ return sService;
+ }
+
+ public static void setListener(LunarServiceConnListener l) {
+ sListener = l;
+ if (l != null && sService != null) {
+ l.onLunarServiceConnected(sService);
+ }
+ }
+
+ public static LunarServiceConnListener getListener() {
+ return sListener;
+ }
+
+ public static boolean showLunar() {
+ Locale locale = Locale.getDefault();
+ String language = locale.getLanguage();
+ String country = locale.getCountry().toLowerCase();
+ if ("zh".equals(language) && "cn".equals(country)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public interface LunarServiceConnListener {
+ public void onLunarServiceConnected(ILunarService service);
+ public void onLunarServiceDisconnected();
+ }
+}