removed debug code

implemented status line
This commit is contained in:
Ronald Schaten 2011-06-08 14:25:11 +02:00
parent 40d738a2fa
commit c0d227629a
2 changed files with 8 additions and 19 deletions

View File

@ -22,9 +22,9 @@
<ProgressBar style="@android:style/Widget.ProgressBar.Horizontal" <ProgressBar style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/progress" android:layout_width="wrap_content" android:id="@+id/progress" android:layout_width="wrap_content"
android:layout_height="6dp" android:paddingTop="2dp" /> android:layout_height="10dp" android:paddingTop="6dp" />
<TextView android:id="@+id/debug" android:layout_width="fill_parent" <TextView android:id="@+id/status" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center" android:layout_height="wrap_content" android:gravity="center"
android:textColor="@android:color/white" android:text="debug" android:textColor="@android:color/white" android:text="debug"
android:textSize="4pt" /> android:textSize="4pt" />

View File

@ -1,11 +1,7 @@
package de.schatenseite.android.waldemar; package de.schatenseite.android.waldemar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Locale;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -17,9 +13,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 de.schatenseite.android.datepreference.DatePreference; import de.schatenseite.android.datepreference.DatePreference;
public class WaldemarWidget extends AppWidgetProvider { public class WaldemarWidget extends AppWidgetProvider {
@ -40,16 +34,14 @@ public class WaldemarWidget extends AppWidgetProvider {
calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.SECOND, 0);
alarmManager.setRepeating(AlarmManager.RTC, alarmManager.setRepeating(AlarmManager.RTC,
calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent); calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
WaldemarWidget.SaveAlarmManager(alarmManager, pendingIntent); WaldemarWidget.SaveAlarmManager(alarmManager, pendingIntent);
Toast.makeText(context, "onEnabled()", Toast.LENGTH_LONG).show();
} }
@Override @Override
public void onDisabled(Context context) { public void onDisabled(Context context) {
myAlarmManager.cancel(myPendingIntent); myAlarmManager.cancel(myPendingIntent);
Toast.makeText(context, "onDisabled()", Toast.LENGTH_LONG).show();
} }
@Override @Override
@ -87,10 +79,6 @@ public class WaldemarWidget extends AppWidgetProvider {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.daycount, pendingIntent); remoteViews.setOnClickPendingIntent(R.id.daycount, pendingIntent);
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)));
@ -112,20 +100,16 @@ public class WaldemarWidget extends AppWidgetProvider {
switch (mode) { switch (mode) {
case 1: // only timeThen case 1: // only timeThen
remoteViews.setTextViewText(R.id.debug, "tT");
// TODO: switch off progressbar // TODO: switch off progressbar
// doesn't work on progressbars: http://stackoverflow.com/questions/2415782/progressbar-in-an-appwidget // doesn't work on progressbars: http://stackoverflow.com/questions/2415782/progressbar-in-an-appwidget
//remoteViews.setViewVisibility(R.id.progress, View.GONE); //remoteViews.setViewVisibility(R.id.progress, View.GONE);
break; break;
case 2: // timeStart and timeThen case 2: // timeStart and timeThen
remoteViews.setTextViewText(R.id.debug, "tS and tT");
duration = (int)Math.round((double)(timeThen - timeStart) / 86400000.); duration = (int)Math.round((double)(timeThen - timeStart) / 86400000.);
break; break;
case 3: // duration and timeThen case 3: // duration and timeThen
remoteViews.setTextViewText(R.id.debug, "d and tT");
break; break;
case 4: // timeStart and duration case 4: // timeStart and duration
remoteViews.setTextViewText(R.id.debug, "tS and d");
timeThen = timeStart + duration * 86400000; timeThen = timeStart + duration * 86400000;
break; break;
} }
@ -133,11 +117,16 @@ public class WaldemarWidget extends AppWidgetProvider {
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));
Integer percent = (int)(((double)(duration - days) / (double)duration)*100);
String status = String.valueOf(duration - days)+"/"+String.valueOf(duration)+", "+String.valueOf(percent)+"%";
if (mode == 1) { if (mode == 1) {
// workaround since we cannot make the progressbar invisible (look above) // workaround since we cannot make the progressbar invisible (look above)
duration = days; duration = days;
status = "";
} }
remoteViews.setProgressBar(R.id.progress, duration, duration - days, false); remoteViews.setProgressBar(R.id.progress, duration, duration - days, false);
remoteViews.setTextViewText(R.id.status, status);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews); appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
} }