removed debug code
implemented status line
This commit is contained in:
		| @@ -22,9 +22,9 @@ | ||||
|  | ||||
| 	<ProgressBar style="@android:style/Widget.ProgressBar.Horizontal" | ||||
| 		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:textColor="@android:color/white" android:text="debug" | ||||
| 		android:textSize="4pt" /> | ||||
|   | ||||
| @@ -1,11 +1,7 @@ | ||||
| package de.schatenseite.android.waldemar; | ||||
|  | ||||
| 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; | ||||
| @@ -17,9 +13,7 @@ import android.content.Intent; | ||||
| import android.content.SharedPreferences; | ||||
| import android.os.Bundle; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.view.View; | ||||
| import android.widget.RemoteViews; | ||||
| import android.widget.Toast; | ||||
| import de.schatenseite.android.datepreference.DatePreference; | ||||
|  | ||||
| public class WaldemarWidget extends AppWidgetProvider { | ||||
| @@ -40,16 +34,14 @@ public class WaldemarWidget extends AppWidgetProvider { | ||||
| 		calendar.set(Calendar.SECOND, 0); | ||||
|  | ||||
| 		alarmManager.setRepeating(AlarmManager.RTC, | ||||
| 				calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent); | ||||
| 				calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); | ||||
| 		 | ||||
| 		WaldemarWidget.SaveAlarmManager(alarmManager, pendingIntent); | ||||
| 		Toast.makeText(context, "onEnabled()", Toast.LENGTH_LONG).show(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onDisabled(Context context) { | ||||
| 		myAlarmManager.cancel(myPendingIntent); | ||||
| 		Toast.makeText(context, "onDisabled()", Toast.LENGTH_LONG).show(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| @@ -87,10 +79,6 @@ public class WaldemarWidget extends AppWidgetProvider { | ||||
|         PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | ||||
|         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); | ||||
| 		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) { | ||||
| 	    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; | ||||
| 	    } | ||||
| @@ -133,11 +117,16 @@ public class WaldemarWidget extends AppWidgetProvider { | ||||
| 		Integer days = (int)Math.round((double)(timeThen - timeNow) / 86400000.); | ||||
| 		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) { | ||||
| 			// workaround since we cannot make the progressbar invisible (look above) | ||||
| 			duration = days; | ||||
| 			status = ""; | ||||
| 		} | ||||
| 		remoteViews.setProgressBar(R.id.progress, duration, duration - days, false); | ||||
| 		remoteViews.setTextViewText(R.id.status, status); | ||||
|  | ||||
| 		appWidgetManager.updateAppWidget(appWidgetId, remoteViews); | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user