beautification after code review

This commit is contained in:
Ronald Schaten 2011-06-09 23:46:38 +02:00
parent 2a22bfefb1
commit 612c8a6797
2 changed files with 28 additions and 19 deletions

View File

@ -11,6 +11,7 @@ import android.preference.PreferenceManager;
import de.schatenseite.android.datepreference.DatePreference; import de.schatenseite.android.datepreference.DatePreference;
public class WaldemarPreferences extends PreferenceActivity { public class WaldemarPreferences extends PreferenceActivity {
public static final String PREFERENCES_UPDATED = "PREFERENCES_UPDATED";
int widgetId; int widgetId;
public void enableDisablePreferences(String val) { public void enableDisablePreferences(String val) {
EditTextPreference pref_name = (EditTextPreference)findPreference("pref_name"); EditTextPreference pref_name = (EditTextPreference)findPreference("pref_name");
@ -22,7 +23,8 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_name.setSummary(pref_name.getText()); pref_name.setSummary(pref_name.getText());
int index = pref_mode.findIndexOfValue(val); int index = pref_mode.findIndexOfValue(val);
if (index == 0) { switch (index) {
case 0:
pref_mode.setSummary(R.string.mode1); pref_mode.setSummary(R.string.mode1);
pref_duration.setEnabled(false); pref_duration.setEnabled(false);
pref_duration.setSummary(R.string.duration_summary); pref_duration.setSummary(R.string.duration_summary);
@ -30,7 +32,8 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_dateStart.setSummary(R.string.dateStart_summary); pref_dateStart.setSummary(R.string.dateStart_summary);
pref_dateThen.setEnabled(true); pref_dateThen.setEnabled(true);
pref_dateThen.setSummary(pref_dateThen.getSummaryString()); pref_dateThen.setSummary(pref_dateThen.getSummaryString());
} else if (index == 1) { break;
case 1:
pref_mode.setSummary(R.string.mode2); pref_mode.setSummary(R.string.mode2);
pref_duration.setEnabled(false); pref_duration.setEnabled(false);
pref_duration.setSummary(R.string.duration_summary); pref_duration.setSummary(R.string.duration_summary);
@ -38,22 +41,27 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_dateStart.setSummary(pref_dateStart.getSummaryString()); pref_dateStart.setSummary(pref_dateStart.getSummaryString());
pref_dateThen.setEnabled(true); pref_dateThen.setEnabled(true);
pref_dateThen.setSummary(pref_dateThen.getSummaryString()); pref_dateThen.setSummary(pref_dateThen.getSummaryString());
} else if (index == 2) { break;
case 2:
pref_mode.setSummary(R.string.mode3); pref_mode.setSummary(R.string.mode3);
pref_duration.setEnabled(true); pref_duration.setEnabled(true);
pref_duration.setSummary(pref_duration.getText()+" "+getApplicationContext().getString(R.string.days)); pref_duration.setSummary(pref_duration.getText() + " "
+ getApplicationContext().getString(R.string.days));
pref_dateStart.setEnabled(false); pref_dateStart.setEnabled(false);
pref_dateStart.setSummary(R.string.dateStart_summary); pref_dateStart.setSummary(R.string.dateStart_summary);
pref_dateThen.setEnabled(true); pref_dateThen.setEnabled(true);
pref_dateThen.setSummary(pref_dateThen.getSummaryString()); pref_dateThen.setSummary(pref_dateThen.getSummaryString());
} else if (index == 3) { break;
case 3:
pref_mode.setSummary(R.string.mode4); pref_mode.setSummary(R.string.mode4);
pref_duration.setEnabled(true); pref_duration.setEnabled(true);
pref_duration.setSummary(pref_duration.getText()+" "+getApplicationContext().getString(R.string.days)); pref_duration.setSummary(pref_duration.getText() + " "
+ getApplicationContext().getString(R.string.days));
pref_dateStart.setEnabled(true); pref_dateStart.setEnabled(true);
pref_dateStart.setSummary(pref_dateStart.getSummaryString()); pref_dateStart.setSummary(pref_dateStart.getSummaryString());
pref_dateThen.setEnabled(false); pref_dateThen.setEnabled(false);
pref_dateThen.setSummary(R.string.dateThen_summary); pref_dateThen.setSummary(R.string.dateThen_summary);
break;
} }
} }
@ -78,7 +86,7 @@ public class WaldemarPreferences extends PreferenceActivity {
pref_name.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { pref_name.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
pref_name.setSummary((CharSequence)newValue); pref_name.setSummary(newValue.toString());
return true; return true;
} }
}); });
@ -91,7 +99,7 @@ public class WaldemarPreferences extends PreferenceActivity {
}); });
pref_duration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { pref_duration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
pref_duration.setSummary((CharSequence)newValue+" "+getApplicationContext().getString(R.string.days)); pref_duration.setSummary(newValue.toString()+" "+getApplicationContext().getString(R.string.days));
return true; return true;
} }
}); });
@ -101,7 +109,7 @@ public class WaldemarPreferences extends PreferenceActivity {
public void onBackPressed() { public void onBackPressed() {
// this is the intent broadcast/returned to the widget // this is the intent broadcast/returned to the widget
Intent updateIntent = new Intent(this, WaldemarWidget.class); Intent updateIntent = new Intent(this, WaldemarWidget.class);
updateIntent.setAction("PreferencesUpdated"); updateIntent.setAction(PREFERENCES_UPDATED);
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
setResult(RESULT_OK, updateIntent); setResult(RESULT_OK, updateIntent);
sendBroadcast(updateIntent); sendBroadcast(updateIntent);

View File

@ -17,7 +17,8 @@ import android.widget.RemoteViews;
import de.schatenseite.android.datepreference.DatePreference; import de.schatenseite.android.datepreference.DatePreference;
public class WaldemarWidget extends AppWidgetProvider { public class WaldemarWidget extends AppWidgetProvider {
public static 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";
static AlarmManager myAlarmManager; static AlarmManager myAlarmManager;
static PendingIntent myPendingIntent; static PendingIntent myPendingIntent;
@ -36,7 +37,7 @@ public class WaldemarWidget extends AppWidgetProvider {
alarmManager.setRepeating(AlarmManager.RTC, alarmManager.setRepeating(AlarmManager.RTC,
calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
WaldemarWidget.SaveAlarmManager(alarmManager, pendingIntent); WaldemarWidget.saveAlarmManager(alarmManager, pendingIntent);
} }
@Override @Override
@ -46,7 +47,7 @@ public class WaldemarWidget extends AppWidgetProvider {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (MIDNIGHTLY_WIDGET_UPDATE.equals(intent.getAction()) || "PreferencesUpdated".equals(intent.getAction())) { if (MIDNIGHTLY_WIDGET_UPDATE.equals(intent.getAction()) || PREFERENCES_UPDATED.equals(intent.getAction())) {
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
if (extras != null) { if (extras != null) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
@ -105,16 +106,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) / 86400000.); duration = (int)Math.round((double)(timeThen - timeStart) / 86400000d);
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 = (long)(timeStart + duration * 86400000.); timeThen = timeStart + duration * 86400000;
break; break;
} }
Integer days = (int)Math.round((double)(timeThen - timeNow) / 86400000.); Integer days = (int)Math.round((double)(timeThen - timeNow) / 86400000d);
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);
@ -131,9 +132,9 @@ public class WaldemarWidget extends AppWidgetProvider {
appWidgetManager.updateAppWidget(appWidgetId, remoteViews); appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
} }
static void SaveAlarmManager(AlarmManager tAlarmManager, static void saveAlarmManager(AlarmManager alarmManager,
PendingIntent tPendingIntent) { PendingIntent pendingIntent) {
myAlarmManager = tAlarmManager; myAlarmManager = alarmManager;
myPendingIntent = tPendingIntent; myPendingIntent = pendingIntent;
} }
} }