make use of modes, fill progress bar

This commit is contained in:
Ronald Schaten 2011-06-07 01:03:38 +02:00
parent 2f9b566099
commit 081a3cbdbc

View File

@ -17,6 +17,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.Toast; import android.widget.Toast;
import de.schatenseite.android.datepreference.DatePreference; import de.schatenseite.android.datepreference.DatePreference;
@ -81,6 +82,10 @@ public class WaldemarWidget extends AppWidgetProvider {
AppWidgetManager appWidgetManager, int appWidgetId) { AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
DateFormat format = SimpleDateFormat.getTimeInstance(
SimpleDateFormat.MEDIUM, Locale.getDefault());
remoteViews.setTextViewText(R.id.debug, format.format(new Date()));
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)));
@ -90,6 +95,8 @@ public class WaldemarWidget extends AppWidgetProvider {
calNow.set(Calendar.SECOND, 0); calNow.set(Calendar.SECOND, 0);
long timeNow = calNow.getTimeInMillis(); long timeNow = calNow.getTimeInMillis();
Integer mode = Integer.valueOf(prefs.getString("pref_mode", "1"));
Calendar calStart = DatePreference.getDateFor(PreferenceManager.getDefaultSharedPreferences(context), "pref_dateStart"); Calendar calStart = DatePreference.getDateFor(PreferenceManager.getDefaultSharedPreferences(context), "pref_dateStart");
long timeStart = calStart.getTimeInMillis(); long timeStart = calStart.getTimeInMillis();
@ -98,13 +105,33 @@ public class WaldemarWidget extends AppWidgetProvider {
Calendar calThen = DatePreference.getDateFor(PreferenceManager.getDefaultSharedPreferences(context), "pref_dateThen"); Calendar calThen = DatePreference.getDateFor(PreferenceManager.getDefaultSharedPreferences(context), "pref_dateThen");
long timeThen = calThen.getTimeInMillis(); long timeThen = calThen.getTimeInMillis();
switch (mode) {
case 1: // only timeThen
remoteViews.setTextViewText(R.id.debug, "tT");
// TODO: switch off progressbar
// doesn't work on progressbars: http://stackoverflow.com/questions/2415782/progressbar-in-an-appwidget
//remoteViews.setViewVisibility(R.id.progress, View.GONE);
break;
case 2: // timeStart and timeThen
remoteViews.setTextViewText(R.id.debug, "tS and tT");
duration = (int)Math.round((double)(timeThen - timeStart) / 86400000.);
break;
case 3: // duration and timeThen
remoteViews.setTextViewText(R.id.debug, "d and tT");
break;
case 4: // timeStart and duration
remoteViews.setTextViewText(R.id.debug, "tS and d");
timeThen = timeStart + duration * 86400000;
break;
}
Integer days = (int)Math.round((double)(timeThen - timeNow) / 86400000.); Integer days = (int)Math.round((double)(timeThen - timeNow) / 86400000.);
remoteViews.setTextViewText(R.id.daycount, String.valueOf(days)); remoteViews.setTextViewText(R.id.daycount, String.valueOf(days));
DateFormat format = SimpleDateFormat.getTimeInstance( if (mode == 1) {
SimpleDateFormat.MEDIUM, Locale.getDefault()); // workaround since we cannot make the progressbar invisible (look above)
remoteViews.setTextViewText(R.id.debug, format.format(new Date())); duration = days;
}
remoteViews.setProgressBar(R.id.progress, duration, duration - days, false); remoteViews.setProgressBar(R.id.progress, duration, duration - days, false);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews); appWidgetManager.updateAppWidget(appWidgetId, remoteViews);