further beautification
This commit is contained in:
		| @@ -1,7 +1,13 @@ | |||||||
| package de.schatenseite.android.waldemar; | 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.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; | ||||||
| @@ -18,7 +24,10 @@ import de.schatenseite.android.datepreference.DatePreference; | |||||||
|  |  | ||||||
| public class WaldemarWidget extends AppWidgetProvider { | public class WaldemarWidget extends AppWidgetProvider { | ||||||
| 	public static final String MIDNIGHTLY_WIDGET_UPDATE = "MIDNIGHTLY_WIDGET_UPDATE"; | 	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 AlarmManager myAlarmManager; | ||||||
| 	static PendingIntent myPendingIntent; | 	static PendingIntent myPendingIntent; | ||||||
| 	 | 	 | ||||||
| @@ -33,14 +42,16 @@ public class WaldemarWidget extends AppWidgetProvider { | |||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void onEnabled(Context context) { | 	public void onEnabled(Context context) { | ||||||
| 		Intent intent = new Intent(WaldemarWidget.MIDNIGHTLY_WIDGET_UPDATE); | 		Intent intent = new Intent(MIDNIGHTLY_WIDGET_UPDATE); | ||||||
| 		PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, | 		PendingIntent pendingIntent = PendingIntent.getBroadcast(context, | ||||||
| 				intent, 0); | 				CURRENTLY_NOT_USED_REQUEST_CODE, intent, SUSPICIOUS_FLAGS); | ||||||
| 		AlarmManager alarmManager = (AlarmManager) context | 		AlarmManager alarmManager = (AlarmManager) context | ||||||
| 				.getSystemService(Context.ALARM_SERVICE); | 				.getSystemService(Context.ALARM_SERVICE); | ||||||
| 		long midnightInMillis = getMidnightInMillis(); | 		long midnightInMillis = getMidnightInMillis(); | ||||||
|  | 		//alarmManager.setRepeating(AlarmManager.RTC, midnightInMillis, | ||||||
|  | 		//		AlarmManager.INTERVAL_DAY, pendingIntent); | ||||||
| 		alarmManager.setRepeating(AlarmManager.RTC, midnightInMillis, | 		alarmManager.setRepeating(AlarmManager.RTC, midnightInMillis, | ||||||
| 				AlarmManager.INTERVAL_DAY, pendingIntent); | 				AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent); | ||||||
|  |  | ||||||
| 		WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent); | 		WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent); | ||||||
| 	} | 	} | ||||||
| @@ -82,7 +93,8 @@ public class WaldemarWidget extends AppWidgetProvider { | |||||||
|  |  | ||||||
| 		// Create an Intent to launch PreferenceActivity | 		// Create an Intent to launch PreferenceActivity | ||||||
|         Intent intent = new Intent(context, WaldemarPreferences.class); |         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); |         remoteViews.setOnClickPendingIntent(R.id.LinearLayout01, pendingIntent); | ||||||
|  |  | ||||||
| 		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | 		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
| @@ -107,16 +119,16 @@ public class WaldemarWidget extends AppWidgetProvider { | |||||||
| 			//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 | ||||||
| 			duration = (int)Math.round((double)(timeThen - timeStart) / 86400000d); | 			duration = (int)Math.round((double)(timeThen - timeStart) / MILLISECONDS_PER_DAY); | ||||||
| 			break; | 			break; | ||||||
| 	    case 3: // duration and timeThen | 	    case 3: // duration and timeThen | ||||||
| 			break; | 			break; | ||||||
| 	    case 4: // timeStart and duration | 	    case 4: // timeStart and duration | ||||||
| 			timeThen = timeStart + duration * 86400000; | 			timeThen = timeStart + duration * (long)MILLISECONDS_PER_DAY; | ||||||
| 			break; | 			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)); | 		remoteViews.setTextViewText(R.id.daycount, String.valueOf(days)); | ||||||
|  |  | ||||||
| 		Integer percent = (int)(((double)(duration - days) / (double)duration)*100); | 		Integer percent = (int)(((double)(duration - days) / (double)duration)*100); | ||||||
| @@ -127,6 +139,10 @@ public class WaldemarWidget extends AppWidgetProvider { | |||||||
| 			duration = days; | 			duration = days; | ||||||
| 			status = ""; | 			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.setProgressBar(R.id.progress, duration, duration - days, false); | ||||||
| 		remoteViews.setTextViewText(R.id.status, status); | 		remoteViews.setTextViewText(R.id.status, status); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user