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,20 +22,25 @@ public class WaldemarWidget extends AppWidgetProvider {
static AlarmManager myAlarmManager;
static PendingIntent myPendingIntent;
@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);
static long getMidnightInMillis() {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
alarmManager.setRepeating(AlarmManager.RTC,
calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
@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);
WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent);
}
@ -83,11 +88,7 @@ public class WaldemarWidget extends AppWidgetProvider {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
remoteViews.setTextViewText(R.id.name, prefs.getString("pref_name", context.getString(R.string.title)));
Calendar calNow = new GregorianCalendar();
calNow.set(Calendar.HOUR_OF_DAY, 0);
calNow.set(Calendar.MINUTE, 0);
calNow.set(Calendar.SECOND, 0);
long timeNow = calNow.getTimeInMillis();
long timeNow = getMidnightInMillis();
Integer mode = Integer.valueOf(prefs.getString("pref_mode", "1"));