make use of modes, fill progress bar
This commit is contained in:
parent
2f9b566099
commit
081a3cbdbc
@ -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,21 +95,43 @@ 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();
|
||||||
|
|
||||||
Integer duration = Integer.parseInt(prefs.getString("pref_duration", context.getString(R.string.duration_default)));
|
Integer duration = Integer.parseInt(prefs.getString("pref_duration", context.getString(R.string.duration_default)));
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user