further beautification

This commit is contained in:
Ronald Schaten 2011-06-13 12:45:54 +02:00
parent 654534eb04
commit bc3383b42e

View File

@ -1,7 +1,13 @@
package de.schatenseite.android.waldemar;
import static de.schatenseite.android.waldemar.WaldemarPreferences.PREFERENCES_UPDATED;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import android.app.AlarmManager;
import android.app.PendingIntent;
@ -18,7 +24,10 @@ import de.schatenseite.android.datepreference.DatePreference;
public class WaldemarWidget extends AppWidgetProvider {
public static final String MIDNIGHTLY_WIDGET_UPDATE = "MIDNIGHTLY_WIDGET_UPDATE";
public static final String PREFERENCES_UPDATED = "PREFERENCES_UPDATED";
private static final double SECONDS_PER_DAY = 24 * 60 * 60;
private static final double MILLISECONDS_PER_DAY = SECONDS_PER_DAY * 1000;
private static final int CURRENTLY_NOT_USED_REQUEST_CODE = 0;
private static final int SUSPICIOUS_FLAGS = 0;
static AlarmManager myAlarmManager;
static PendingIntent myPendingIntent;
@ -33,14 +42,16 @@ public class WaldemarWidget extends AppWidgetProvider {
@Override
public void onEnabled(Context context) {
Intent intent = new Intent(WaldemarWidget.MIDNIGHTLY_WIDGET_UPDATE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, 0);
Intent intent = new Intent(MIDNIGHTLY_WIDGET_UPDATE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
CURRENTLY_NOT_USED_REQUEST_CODE, intent, SUSPICIOUS_FLAGS);
AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
long midnightInMillis = getMidnightInMillis();
//alarmManager.setRepeating(AlarmManager.RTC, midnightInMillis,
// AlarmManager.INTERVAL_DAY, pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC, midnightInMillis,
AlarmManager.INTERVAL_DAY, pendingIntent);
AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent);
}
@ -82,7 +93,8 @@ public class WaldemarWidget extends AppWidgetProvider {
// Create an Intent to launch PreferenceActivity
Intent intent = new Intent(context, WaldemarPreferences.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
CURRENTLY_NOT_USED_REQUEST_CODE, intent, SUSPICIOUS_FLAGS);
remoteViews.setOnClickPendingIntent(R.id.LinearLayout01, pendingIntent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -107,16 +119,16 @@ public class WaldemarWidget extends AppWidgetProvider {
//remoteViews.setViewVisibility(R.id.progress, View.GONE);
break;
case 2: // timeStart and timeThen
duration = (int)Math.round((double)(timeThen - timeStart) / 86400000d);
duration = (int)Math.round((double)(timeThen - timeStart) / MILLISECONDS_PER_DAY);
break;
case 3: // duration and timeThen
break;
case 4: // timeStart and duration
timeThen = timeStart + duration * 86400000;
timeThen = timeStart + duration * (long)MILLISECONDS_PER_DAY;
break;
}
Integer days = (int)Math.round((double)(timeThen - timeNow) / 86400000d);
Integer days = (int)Math.round((double)(timeThen - timeNow) / MILLISECONDS_PER_DAY);
remoteViews.setTextViewText(R.id.daycount, String.valueOf(days));
Integer percent = (int)(((double)(duration - days) / (double)duration)*100);
@ -127,6 +139,10 @@ public class WaldemarWidget extends AppWidgetProvider {
duration = days;
status = "";
}
DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());
status = status + "\n" + format.format(new Date());
remoteViews.setProgressBar(R.id.progress, duration, duration - days, false);
remoteViews.setTextViewText(R.id.status, status);