code cleanup, talking variables

This commit is contained in:
Ronald Schaten 2011-06-20 23:12:42 +02:00
parent 30052000a4
commit 116485c22b
4 changed files with 30 additions and 23 deletions

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="modes">
<item>@string/mode1</item>
<item>@string/mode2</item>
<item>@string/mode3</item>
<item>@string/mode4</item>
<item>@string/modeTimeThen</item>
<item>@string/modeTimeStartTimeThen</item>
<item>@string/modeDurationTimeThen</item>
<item>@string/modeTimeStartDuration</item>
</string-array>
<string-array name="modes_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
</resources>

View File

@ -13,10 +13,10 @@
<string name="timing">Zeiteinstellung</string>
<string name="mode">Modus</string>
<string name="mode_summary">Welche Daten sind gegeben?</string>
<string name="mode1">Nur Zieldatum</string>
<string name="mode2">Start- und Zieldatum</string>
<string name="mode3">Dauer und Zieldatum</string>
<string name="mode4">Startdatum und Dauer</string>
<string name="modeTimeThen">Nur Zieldatum</string>
<string name="modeTimeStartTimeThen">Start- und Zieldatum</string>
<string name="modeDurationTimeThen">Dauer und Zieldatum</string>
<string name="modeTimeStartDuration">Startdatum und Dauer</string>
<string name="dateStart">Startdatum</string>
<string name="dateStart_summary">Wann beginnt der Countdown?</string>
<string name="duration">Dauer</string>

View File

@ -13,6 +13,10 @@ import de.schatenseite.android.datepreference.DatePreference;
public class WaldemarPreferences extends PreferenceActivity {
private static final String PREFIX = WaldemarPreferences.class.getPackage().getName() + ".";
public static final String PREFERENCES_UPDATED = PREFIX + "PREFERENCES_UPDATED";
public static final int MODE_TIMETHEN = 0;
public static final int MODE_TIMESTART_TIMETHEN = 1;
public static final int MODE_DURATION_TIMETHEN = 2;
public static final int MODE_TIMESTART_DURATION = 3;
int widgetId;
public void enableDisablePreferences(String val) {
EditTextPreference pref_name = (EditTextPreference)findPreference("pref_name");
@ -25,8 +29,8 @@ public class WaldemarPreferences extends PreferenceActivity {
int index = pref_mode.findIndexOfValue(val);
switch (index) {
case 0:
pref_mode.setSummary(R.string.mode1);
case MODE_TIMETHEN:
pref_mode.setSummary(R.string.modeTimeThen);
pref_duration.setEnabled(false);
pref_duration.setSummary(R.string.duration_summary);
pref_dateStart.setEnabled(false);
@ -34,8 +38,8 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_dateThen.setEnabled(true);
pref_dateThen.setSummary(pref_dateThen.getSummaryString());
break;
case 1:
pref_mode.setSummary(R.string.mode2);
case MODE_TIMESTART_TIMETHEN:
pref_mode.setSummary(R.string.modeTimeStartTimeThen);
pref_duration.setEnabled(false);
pref_duration.setSummary(R.string.duration_summary);
pref_dateStart.setEnabled(true);
@ -43,8 +47,8 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_dateThen.setEnabled(true);
pref_dateThen.setSummary(pref_dateThen.getSummaryString());
break;
case 2:
pref_mode.setSummary(R.string.mode3);
case MODE_DURATION_TIMETHEN:
pref_mode.setSummary(R.string.modeDurationTimeThen);
pref_duration.setEnabled(true);
pref_duration.setSummary(pref_duration.getText() + " "
+ getApplicationContext().getString(R.string.days));
@ -53,8 +57,8 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_dateThen.setEnabled(true);
pref_dateThen.setSummary(pref_dateThen.getSummaryString());
break;
case 3:
pref_mode.setSummary(R.string.mode4);
case MODE_TIMESTART_DURATION:
pref_mode.setSummary(R.string.modeTimeStartDuration);
pref_duration.setEnabled(true);
pref_duration.setSummary(pref_duration.getText() + " "
+ getApplicationContext().getString(R.string.days));

View File

@ -1,6 +1,10 @@
package de.schatenseite.android.waldemar;
import static de.schatenseite.android.waldemar.WaldemarPreferences.PREFERENCES_UPDATED;
import static de.schatenseite.android.waldemar.WaldemarPreferences.MODE_TIMETHEN;
import static de.schatenseite.android.waldemar.WaldemarPreferences.MODE_TIMESTART_TIMETHEN;
import static de.schatenseite.android.waldemar.WaldemarPreferences.MODE_DURATION_TIMETHEN;
import static de.schatenseite.android.waldemar.WaldemarPreferences.MODE_TIMESTART_DURATION;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@ -117,17 +121,17 @@ public class WaldemarWidget extends AppWidgetProvider {
long timeThen = calThen.getTimeInMillis();
switch (mode) {
case 1: // only timeThen
case MODE_TIMETHEN:
remoteViews.setViewVisibility(R.id.progressBarFrame, View.GONE);
break;
case 2: // timeStart and timeThen
case MODE_TIMESTART_TIMETHEN:
duration = (int)Math.round((double)(timeThen - timeStart) / MILLISECONDS_PER_DAY);
remoteViews.setViewVisibility(R.id.progressBarFrame, View.VISIBLE);
break;
case 3: // duration and timeThen
case MODE_DURATION_TIMETHEN:
remoteViews.setViewVisibility(R.id.progressBarFrame, View.VISIBLE);
break;
case 4: // timeStart and duration
case MODE_TIMESTART_DURATION:
timeThen = timeStart + duration * (long)MILLISECONDS_PER_DAY;
remoteViews.setViewVisibility(R.id.progressBarFrame, View.VISIBLE);
break;
@ -139,8 +143,7 @@ public class WaldemarWidget extends AppWidgetProvider {
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)
if (mode == MODE_TIMETHEN) {
duration = days;
status = "";
}