Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
7 AndroidManifest.xml
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.josegd.monthcalwidget" android:versionCode="1" android:versionName="1.0">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.josegd.monthcalwidget"
+ android:versionCode="2" android:versionName="1.1.0">
<application android:icon="@drawable/monthcal" android:label="@string/app_name">
<receiver android:name=".MonthCalWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.DATE_CHANGED"/>
+ </intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/monthcal_widget_provider" />
</receiver>
+ <service android:name=".MCWUpdateService" />
</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
</manifest>
View
116 gen/com/josegd/monthcalwidget/R.java
@@ -28,58 +28,61 @@
public static final int widget_bg=0x7f020007;
}
public static final class id {
- public static final int date00=0x7f080004;
- public static final int date01=0x7f08000b;
- public static final int date02=0x7f080012;
- public static final int date03=0x7f080019;
- public static final int date04=0x7f080020;
- public static final int date05=0x7f080027;
- public static final int date06=0x7f08002e;
- public static final int date10=0x7f080005;
- public static final int date11=0x7f08000c;
- public static final int date12=0x7f080013;
- public static final int date13=0x7f08001a;
- public static final int date14=0x7f080021;
- public static final int date15=0x7f080028;
- public static final int date16=0x7f08002f;
- public static final int date20=0x7f080006;
- public static final int date21=0x7f08000d;
- public static final int date22=0x7f080014;
- public static final int date23=0x7f08001b;
- public static final int date24=0x7f080022;
- public static final int date25=0x7f080029;
- public static final int date26=0x7f080030;
- public static final int date30=0x7f080007;
- public static final int date31=0x7f08000e;
- public static final int date32=0x7f080015;
- public static final int date33=0x7f08001c;
- public static final int date34=0x7f080023;
- public static final int date35=0x7f08002a;
- public static final int date36=0x7f080031;
- public static final int date40=0x7f080008;
- public static final int date41=0x7f08000f;
- public static final int date42=0x7f080016;
- public static final int date43=0x7f08001d;
- public static final int date44=0x7f080024;
- public static final int date45=0x7f08002b;
- public static final int date46=0x7f080032;
- public static final int date50=0x7f080009;
- public static final int date51=0x7f080010;
- public static final int date52=0x7f080017;
- public static final int date53=0x7f08001e;
- public static final int date54=0x7f080025;
- public static final int date55=0x7f08002c;
- public static final int date56=0x7f080033;
- public static final int day1=0x7f080003;
- public static final int day2=0x7f08000a;
- public static final int day3=0x7f080011;
- public static final int day4=0x7f080018;
- public static final int day5=0x7f08001f;
- public static final int day6=0x7f080026;
- public static final int day7=0x7f08002d;
- public static final int monthyear=0x7f080001;
- public static final int nextmonth=0x7f080002;
- public static final int prevmonth=0x7f080000;
+ public static final int date00=0x7f080007;
+ public static final int date01=0x7f08000e;
+ public static final int date02=0x7f080015;
+ public static final int date03=0x7f08001c;
+ public static final int date04=0x7f080023;
+ public static final int date05=0x7f08002a;
+ public static final int date06=0x7f080031;
+ public static final int date10=0x7f080008;
+ public static final int date11=0x7f08000f;
+ public static final int date12=0x7f080016;
+ public static final int date13=0x7f08001d;
+ public static final int date14=0x7f080024;
+ public static final int date15=0x7f08002b;
+ public static final int date16=0x7f080032;
+ public static final int date20=0x7f080009;
+ public static final int date21=0x7f080010;
+ public static final int date22=0x7f080017;
+ public static final int date23=0x7f08001e;
+ public static final int date24=0x7f080025;
+ public static final int date25=0x7f08002c;
+ public static final int date26=0x7f080033;
+ public static final int date30=0x7f08000a;
+ public static final int date31=0x7f080011;
+ public static final int date32=0x7f080018;
+ public static final int date33=0x7f08001f;
+ public static final int date34=0x7f080026;
+ public static final int date35=0x7f08002d;
+ public static final int date36=0x7f080034;
+ public static final int date40=0x7f08000b;
+ public static final int date41=0x7f080012;
+ public static final int date42=0x7f080019;
+ public static final int date43=0x7f080020;
+ public static final int date44=0x7f080027;
+ public static final int date45=0x7f08002e;
+ public static final int date46=0x7f080035;
+ public static final int date50=0x7f08000c;
+ public static final int date51=0x7f080013;
+ public static final int date52=0x7f08001a;
+ public static final int date53=0x7f080021;
+ public static final int date54=0x7f080028;
+ public static final int date55=0x7f08002f;
+ public static final int date56=0x7f080036;
+ public static final int datesll=0x7f080005;
+ public static final int day1=0x7f080006;
+ public static final int day2=0x7f08000d;
+ public static final int day3=0x7f080014;
+ public static final int day4=0x7f08001b;
+ public static final int day5=0x7f080022;
+ public static final int day6=0x7f080029;
+ public static final int day7=0x7f080030;
+ public static final int mainll=0x7f080000;
+ public static final int monthyear=0x7f080003;
+ public static final int navll=0x7f080001;
+ public static final int nextmonth=0x7f080004;
+ public static final int prevmonth=0x7f080002;
}
public static final class layout {
public static final int main=0x7f030000;
@@ -88,9 +91,14 @@
public static final int app_name=0x7f060000;
}
public static final class style {
+ /** <item name="android:focusableInTouchMode">true</item>
+ */
public static final int Img_Arrows=0x7f070000;
- public static final int Text_DatesColumn=0x7f070003;
- public static final int Text_DaysOfWeek=0x7f070002;
+ public static final int LL_DatesColumn=0x7f070002;
+ public static final int Text_DatesColumn=0x7f070004;
+ public static final int Text_DaysOfWeek=0x7f070003;
+ /** <item name="android:focusableInTouchMode">true</item>
+ */
public static final int Text_MonthYear=0x7f070001;
}
public static final class xml {
View
2  res/drawable/selector_next.xml
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_window_focused="false" android:drawable="@drawable/next_normal" />
+ <item android:state_focused="true" android:drawable="@drawable/next_pressed" />
<item android:state_pressed="true" android:drawable="@drawable/next_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/next_normal" /> <!-- default -->
</selector>
View
2  res/drawable/selector_prev.xml
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_window_focused="false" android:drawable="@drawable/previous_normal" />
+ <item android:state_focused="true" android:drawable="@drawable/previous_pressed" />
<item android:state_pressed="true" android:drawable="@drawable/previous_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/previous_normal" /> <!-- default -->
</selector>
View
23 res/layout/main.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/mainll"
android:orientation="vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
@@ -8,19 +9,21 @@
android:layout_height="wrap_content"
android:background="@drawable/widget_bg">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/navll"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
- <ImageButton android:id="@+id/prevmonth" android:src="@drawable/selector_prev" style="@style/Img_Arrows"/>
- <TextView android:id="@+id/monthyear" style="@style/Text_MonthYear"/>
- <ImageButton android:id="@+id/nextmonth" android:src="@drawable/selector_next" style="@style/Img_Arrows"/>
+ <ImageButton android:id="@+id/prevmonth" android:src="@drawable/selector_prev" style="@style/Img_Arrows" android:focusable="true"/>
+ <TextView android:id="@+id/monthyear" style="@style/Text_MonthYear" android:focusable="true"/>
+ <ImageButton android:id="@+id/nextmonth" android:src="@drawable/selector_next" style="@style/Img_Arrows" android:focusable="true"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/datesll"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">"
<TextView android:id="@+id/day1" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date00" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date10" style="@style/Text_DatesColumn"/>
@@ -30,7 +33,7 @@
<TextView android:id="@+id/date50" style="@style/Text_DatesColumn"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">
<TextView android:id="@+id/day2" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date01" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date11" style="@style/Text_DatesColumn"/>
@@ -40,7 +43,7 @@
<TextView android:id="@+id/date51" style="@style/Text_DatesColumn"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">
<TextView android:id="@+id/day3" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date02" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date12" style="@style/Text_DatesColumn"/>
@@ -50,7 +53,7 @@
<TextView android:id="@+id/date52" style="@style/Text_DatesColumn"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">
<TextView android:id="@+id/day4" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date03" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date13" style="@style/Text_DatesColumn"/>
@@ -60,7 +63,7 @@
<TextView android:id="@+id/date53" style="@style/Text_DatesColumn"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">
<TextView android:id="@+id/day5" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date04" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date14" style="@style/Text_DatesColumn"/>
@@ -70,7 +73,7 @@
<TextView android:id="@+id/date54" style="@style/Text_DatesColumn"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">
<TextView android:id="@+id/day6" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date05" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date15" style="@style/Text_DatesColumn"/>
@@ -80,7 +83,7 @@
<TextView android:id="@+id/date55" style="@style/Text_DatesColumn"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="25dip" android:layout_height="wrap_content">
+ android:orientation="vertical" style="@style/LL_DatesColumn">
<TextView android:id="@+id/day7" style="@style/Text_DaysOfWeek"/>
<TextView android:id="@+id/date06" style="@style/Text_DatesColumn"/>
<TextView android:id="@+id/date16" style="@style/Text_DatesColumn"/>
View
20 res/values/styles.xml
@@ -4,33 +4,35 @@
<item name="android:background">@null</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
- <item name="android:focusable">true</item>
+<!-- <item name="android:focusableInTouchMode">true</item> -->
</style>
<style name="Text_MonthYear">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:paddingTop">4dip</item>
- <item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1.0</item>
<item name="android:gravity">center</item>
- <item name="android:focusable">true</item>
+<!-- <item name="android:focusableInTouchMode">true</item> -->
+ </style>
+ <style name="LL_DatesColumn">
+ <item name="android:layout_width">25dip</item>
+ <item name="android:layout_height">wrap_content</item>
</style>
<style name="Text_DaysOfWeek">
<item name="android:textSize">10sp</item>
<item name="android:textColor">@color/lightgray</item>
- <item name="android:padding">2dip</item>
+ <item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
- <item name="android:layout_width">wrap_content</item>
- <item name="android:layout_gravity">center</item>
+ <item name="android:gravity">center</item>
</style>
<style name="Text_DatesColumn">
<item name="android:textSize">12sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:paddingTop">4dip</item>
- <item name="android:layout_height">wrap_content</item>
- <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">fill_parent</item>
<item name="android:gravity">right</item>
- <item name="android:layout_gravity">right</item>
</style>
</resources>
View
4 res/xml/monthcal_widget_provider.xml
@@ -3,5 +3,5 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/main"
android:minWidth="220dip"
- android:minHeight="220dip"
- android:updatePeriodMillis="86400000"/>
+ android:minHeight="146dip"
+ android:updatePeriodMillis="0"/>
View
132 src/com/josegd/monthcalwidget/MCWUpdateService.java
@@ -0,0 +1,132 @@
+package com.josegd.monthcalwidget;
+
+import java.text.DateFormatSymbols;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+import android.app.IntentService;
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.text.Spannable;
+import android.text.SpannableStringBuilder;
+import android.text.style.BackgroundColorSpan;
+import android.widget.RemoteViews;
+
+public class MCWUpdateService extends IntentService {
+
+ private static int yearNow;
+ private static int monthNow;
+ private static int today;
+ private static MonthDisplayHelper mdh;
+
+ public MCWUpdateService() {
+ super("MCWUpdateService");
+ }
+
+ @Override
+ public void onHandleIntent(Intent intent) {
+ initMonthDisplayHelper();
+ updateCalendar(this);
+ }
+
+ public static void initMonthDisplayHelper() {
+ Calendar cal = Calendar.getInstance();
+ yearNow = cal.get(Calendar.YEAR);
+ monthNow = cal.get(Calendar.MONTH);
+ today = cal.get(Calendar.DATE);
+ mdh = new MonthDisplayHelper(yearNow, monthNow);
+ }
+
+ public static void nextMonth() {
+ mdh.nextMonth();
+ }
+
+ public static void previousMonth() {
+ mdh.previousMonth();
+ }
+
+ public static void updateCalendar(Context context) {
+ ComponentName widget = new ComponentName(context, MonthCalWidget.class);
+ AppWidgetManager mgr = AppWidgetManager.getInstance(context);
+ RemoteViews remViews = buildUpdate(context);
+ mgr.updateAppWidget(widget, remViews);
+ }
+
+ private static RemoteViews buildUpdate(Context context) {
+ RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
+ setViewAction(context, views, MonthCalWidget.WIDGET_CLICK_NEXT, R.id.nextmonth);
+ setViewAction(context, views, MonthCalWidget.WIDGET_CLICK_PREV, R.id.prevmonth);
+ setViewAction(context, views, MonthCalWidget.WIDGET_CLICK_MYTV, R.id.monthyear);
+ fillCalendar(context, views);
+ return views;
+ }
+
+ private static void setViewAction(Context cont, RemoteViews rv, String action, int idView) {
+ Intent intent = new Intent(cont, MonthCalWidget.class);
+ intent.setAction(action);
+ rv.setOnClickPendingIntent(idView, PendingIntent.getBroadcast(cont, 0, intent, 0));
+ }
+
+ private static void fillCalendar(Context cont, RemoteViews rv) {
+ // Month and year (title)
+ SimpleDateFormat sdfDate = new SimpleDateFormat("MMMM yyyy");
+ Calendar cal = Calendar.getInstance();
+ cal.set(mdh.getYear(), mdh.getMonth(), 1);
+ rv.setTextViewText( R.id.monthyear, sdfDate.format(cal.getTime()) );
+ // Dates (grid)
+ setWeekDays(cont, rv);
+ clearDatesGrid(cont, rv);
+ refillDatesGrid(cont, rv);
+ }
+
+ private static void setWeekDays(Context cont, RemoteViews rv) {
+ int identifier;
+ DateFormatSymbols weekDays = new DateFormatSymbols();
+ for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
+ identifier = cont.getResources().getIdentifier("day" + i, "id", cont.getPackageName());
+ rv.setTextViewText(identifier, weekDays.getShortWeekdays()[i]);
+ }
+ }
+
+ private static void clearDatesGrid(Context cont, RemoteViews rv) {
+ int identifier;
+ for (int j = 0; j < 7; j++) {
+ for (int i = 0; i < 6; i++) {
+ identifier = cont.getResources().getIdentifier("date" + i + j, "id", cont.getPackageName());
+ rv.setTextViewText(identifier, "");
+ }
+ }
+ }
+
+ private static void refillDatesGrid(Context cont, RemoteViews rv) {
+ int dateNumber, nextDateNumber;
+ int i, identifier;
+ String dateNumberStr;
+ for (int j = 0; j < 7; j++) {
+ i = 0;
+ nextDateNumber = 0;
+ do {
+ dateNumber = mdh.isWithinCurrentMonth(i, j) ? mdh.getDayAt(i, j) : 0;
+ if (dateNumber > 0) {
+ identifier = cont.getResources().getIdentifier("date" + i + j, "id", cont.getPackageName());
+ dateNumberStr = dateNumber < 10 ? " " : " ";
+ dateNumberStr += dateNumber + " ";
+ if (mdh.getYear() == yearNow && mdh.getMonth() == monthNow && dateNumber == today) {
+ SpannableStringBuilder ssb = new SpannableStringBuilder();
+ ssb.append(dateNumberStr);
+ ssb.setSpan(new BackgroundColorSpan(cont.getResources().getColor(R.color.today)), 1, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ rv.setTextViewText(identifier, ssb);
+ } else {
+ rv.setTextViewText(identifier, dateNumberStr);
+ }
+ nextDateNumber = dateNumber + 7;
+ }
+ i++;
+ } while (nextDateNumber <= mdh.getNumberOfDaysInMonth());
+ }
+ }
+
+}
View
147 src/com/josegd/monthcalwidget/MonthCalWidget.java
@@ -1,118 +1,85 @@
package com.josegd.monthcalwidget;
-import java.text.DateFormatSymbols;
-import java.text.SimpleDateFormat;
import java.util.Calendar;
+
+import android.app.AlarmManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.text.Spannable;
-import android.text.SpannableStringBuilder;
-import android.text.style.BackgroundColorSpan;
-import android.widget.RemoteViews;
public class MonthCalWidget extends AppWidgetProvider {
- public static String WIDGET_CLICK_NEXT = "com.josegd.monthcalwidget.ACTION_NEXT_MONTH";
- public static String WIDGET_CLICK_PREV = "com.josegd.monthcalwidget.ACTION_PREV_MONTH";
- public static String WIDGET_CLICK_MYTV = "com.josegd.monthcalwidget.ACTION_CURRENT_MONTH";
+ public static String WIDGET_CLICK_NEXT = "com.josegd.monthcalwidget.ACTION_NEXT_MONTH";
+ public static String WIDGET_CLICK_PREV = "com.josegd.monthcalwidget.ACTION_PREV_MONTH";
+ public static String WIDGET_CLICK_MYTV = "com.josegd.monthcalwidget.ACTION_CURRENT_MONTH";
+ public static String WIDGET_NEWDAY_ALARM = "com.josegd.monthcalwidget.ACTION_NEW_DAY";
+ public static String WIDGET_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
+
+ @Override
+ public void onEnabled(Context context) {
+ super.onEnabled(context);
+ setNewDayAlarm(context);
+ }
- private static Calendar cal = Calendar.getInstance();
- private static int yearNow = cal.get(Calendar.YEAR);
- private static int monthNow = cal.get(Calendar.MONTH);
- private static int today = cal.get(Calendar.DATE);
- private static MonthDisplayHelper mdh = new MonthDisplayHelper(yearNow, monthNow);
- private SimpleDateFormat cmyDate = new SimpleDateFormat("MMMM yyyy");
- private DateFormatSymbols weekDays = new DateFormatSymbols();
+ @Override
+ public void onDisabled(Context context) {
+ cancelNewDayAlarm(context);
+ super.onDisabled(context);
+ }
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- RemoteViews remViews = new RemoteViews(context.getPackageName(), R.layout.main);
- setViewAction(context, remViews, WIDGET_CLICK_NEXT, R.id.nextmonth);
- setViewAction(context, remViews, WIDGET_CLICK_PREV, R.id.prevmonth);
- setViewAction(context, remViews, WIDGET_CLICK_MYTV, R.id.monthyear);
- updateCalendar(context, remViews, new ComponentName(context, MonthCalWidget.class));
super.onUpdate(context, appWidgetManager, appWidgetIds);
+ initService(context);
}
-
+
@Override
public void onReceive(Context context, Intent intent) {
- RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.main);
- ComponentName me = new ComponentName(context, MonthCalWidget.class);
- String action = intent.getAction();
- if (action.equals(WIDGET_CLICK_NEXT)) {
- mdh.nextMonth();
- } else
- if (action.equals(WIDGET_CLICK_PREV)) {
- mdh.previousMonth();
+ try {
+ String action = intent.getAction();
+ if (action.equals(WIDGET_CLICK_NEXT)) {
+ MCWUpdateService.nextMonth();
} else
- if (action.equals(WIDGET_CLICK_MYTV)) {
- mdh = new MonthDisplayHelper(yearNow, monthNow);
- } else {
- super.onReceive(context, intent);
- return;
- }
- updateCalendar(context, rv, me);
- }
-
- private void setViewAction(Context cont, RemoteViews rv, String action, int idView) {
- Intent intent = new Intent(cont, MonthCalWidget.class);
- intent.setAction(action);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(cont, 0, intent, 0);
- rv.setOnClickPendingIntent(idView, pendingIntent);
+ if (action.equals(WIDGET_CLICK_PREV)) {
+ MCWUpdateService.previousMonth();
+ } else
+ if (action.equals(WIDGET_CLICK_MYTV) || action.equals(WIDGET_NEWDAY_ALARM) || action.equals(WIDGET_DATE_CHANGED)) {
+ MCWUpdateService.initMonthDisplayHelper();
+ } else {
+ super.onReceive(context, intent);
+ return;
+ }
+ MCWUpdateService.updateCalendar(context);
+ } catch (NullPointerException e) {
+ initService(context);
+ }
}
- private void updateCalendar(Context cont, RemoteViews rv, ComponentName cn) {
- rv.setTextViewText(R.id.monthyear, cmyDate.format(mdh.getTime())); // Month and year (title)
- setWeekDays(cont, rv);
- refillDatesGrid(cont, rv); // Dates (grid)
- AppWidgetManager.getInstance(cont).updateAppWidget(cn, rv);
+ private void setNewDayAlarm(Context context) {
+ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ Calendar alarmCal = Calendar.getInstance();
+ alarmCal.set(Calendar.HOUR_OF_DAY, 0);
+ alarmCal.set(Calendar.MINUTE, 0);
+ alarmCal.set(Calendar.SECOND, 0);
+ alarmManager.setRepeating(AlarmManager.RTC, alarmCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, createNewDayIntent(context));
}
-
- private void setWeekDays(Context cont, RemoteViews rv) {
- int identifier;
- for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
- identifier = cont.getResources().getIdentifier("day" + i, "id", cont.getPackageName());
- rv.setTextViewText(identifier, weekDays.getShortWeekdays()[i]);
- }
+
+ private void cancelNewDayAlarm(Context context) {
+ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ alarmManager.cancel(createNewDayIntent(context));
}
-
- private void refillDatesGrid(Context cont, RemoteViews rv) {
- int dateNumber, nextDateNumber;
- int i, j, identifier;
- String dateNumberStr;
- for (j = 0; j < 7; j++) {
- for (i = 0; i < 6; i++) {
- identifier = cont.getResources().getIdentifier("date" + i + j, "id", cont.getPackageName());
- rv.setTextViewText(identifier, "");
- }
- }
- for (j = 0; j < 7; j++) {
- i = 0;
- nextDateNumber = 0;
- do {
- dateNumber = mdh.isWithinCurrentMonth(i, j) ? mdh.getDayAt(i, j) : 0;
- if (dateNumber > 0) {
- identifier = cont.getResources().getIdentifier("date" + i + j, "id", cont.getPackageName());
- dateNumberStr = dateNumber < 10 ? " " : " ";
- dateNumberStr += dateNumber + " ";
- if (mdh.getYear() == yearNow && mdh.getMonth() == monthNow && dateNumber == today) {
- SpannableStringBuilder ssb = new SpannableStringBuilder();
- ssb.append(dateNumberStr);
- ssb.setSpan(new BackgroundColorSpan(cont.getResources().getColor(R.color.today)), 1, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- rv.setTextViewText(identifier, ssb);
- } else {
- rv.setTextViewText(identifier, dateNumberStr);
- }
- nextDateNumber = dateNumber + 7;
- }
- i++;
- } while (nextDateNumber <= mdh.getNumberOfDaysInMonth());
- }
+
+ private PendingIntent createNewDayIntent(Context context) {
+ Intent intent = new Intent(context, MonthCalWidget.class);
+ intent.setAction(WIDGET_NEWDAY_ALARM);
+ return PendingIntent.getBroadcast(context, 0, intent, 0);
}
+ private void initService(Context context) {
+ context.startService(new Intent(context, MCWUpdateService.class));
+ }
+
}
View
6 src/com/josegd/monthcalwidget/MonthDisplayHelper.java
@@ -17,7 +17,6 @@
package com.josegd.monthcalwidget;
import java.util.Calendar;
-import java.util.Date;
/**
* Helps answer common questions that come up when displaying a month in a
@@ -77,11 +76,6 @@ public int getMonth() {
return mCalendar.get(Calendar.MONTH);
}
- // Return calendar's current date/time - Jose
- public Date getTime() {
- return mCalendar.getTime();
- }
-
public int getWeekStartDay() {
return mWeekStartDay;
}

No commit comments for this range

Something went wrong with that request. Please try again.