refactored getMidnightInMillis(), set milliseconds to 0

This commit is contained in:
Ronald Schaten 2011-06-10 08:38:18 +02:00
parent 612c8a6797
commit 654534eb04

View File

@ -22,21 +22,26 @@ public class WaldemarWidget extends AppWidgetProvider {
static AlarmManager myAlarmManager; static AlarmManager myAlarmManager;
static PendingIntent myPendingIntent; static PendingIntent myPendingIntent;
@Override static long getMidnightInMillis() {
public void onEnabled(Context context) {
Intent intent = new Intent(
WaldemarWidget.MIDNIGHTLY_WIDGET_UPDATE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = new GregorianCalendar(); Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
@Override
public void onEnabled(Context context) {
Intent intent = new Intent(WaldemarWidget.MIDNIGHTLY_WIDGET_UPDATE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, 0);
AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
long midnightInMillis = getMidnightInMillis();
alarmManager.setRepeating(AlarmManager.RTC, midnightInMillis,
AlarmManager.INTERVAL_DAY, pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC,
calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent); WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent);
} }
@ -83,11 +88,7 @@ public class WaldemarWidget extends AppWidgetProvider {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
remoteViews.setTextViewText(R.id.name, prefs.getString("pref_name", context.getString(R.string.title))); remoteViews.setTextViewText(R.id.name, prefs.getString("pref_name", context.getString(R.string.title)));
Calendar calNow = new GregorianCalendar(); long timeNow = getMidnightInMillis();
calNow.set(Calendar.HOUR_OF_DAY, 0);
calNow.set(Calendar.MINUTE, 0);
calNow.set(Calendar.SECOND, 0);
long timeNow = calNow.getTimeInMillis();
Integer mode = Integer.valueOf(prefs.getString("pref_mode", "1")); Integer mode = Integer.valueOf(prefs.getString("pref_mode", "1"));