From: gu.martinm@gmail.com Date: Tue, 15 Apr 2014 21:08:47 +0000 (+0200) Subject: Improvements in lists. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=cc6c7e997cf8c90101383903eb4e76af37d05286;p=JavaForFun Improvements in lists. --- diff --git a/Android/WeatherInformation/lint.xml b/Android/WeatherInformation/lint.xml new file mode 100644 index 0000000..ee0eead --- /dev/null +++ b/Android/WeatherInformation/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Android/WeatherInformation/res/drawable-hdpi/ic_action_refresh.png b/Android/WeatherInformation/res/drawable-hdpi/ic_action_refresh.png new file mode 100644 index 0000000..dae2790 Binary files /dev/null and b/Android/WeatherInformation/res/drawable-hdpi/ic_action_refresh.png differ diff --git a/Android/WeatherInformation/res/drawable-mdpi/ic_action_refresh.png b/Android/WeatherInformation/res/drawable-mdpi/ic_action_refresh.png new file mode 100644 index 0000000..94ab6f4 Binary files /dev/null and b/Android/WeatherInformation/res/drawable-mdpi/ic_action_refresh.png differ diff --git a/Android/WeatherInformation/res/drawable-xhdpi/ic_action_refresh.png b/Android/WeatherInformation/res/drawable-xhdpi/ic_action_refresh.png new file mode 100644 index 0000000..ab4ab9d Binary files /dev/null and b/Android/WeatherInformation/res/drawable-xhdpi/ic_action_refresh.png differ diff --git a/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_refresh.png b/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_refresh.png new file mode 100644 index 0000000..44ee117 Binary files /dev/null and b/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_refresh.png differ diff --git a/Android/WeatherInformation/res/layout/weather_current_data.xml b/Android/WeatherInformation/res/layout/weather_current_data.xml index 9ffb611..0f581a6 100644 --- a/Android/WeatherInformation/res/layout/weather_current_data.xml +++ b/Android/WeatherInformation/res/layout/weather_current_data.xml @@ -1,16 +1,26 @@ - + + - \ No newline at end of file + \ No newline at end of file diff --git a/Android/WeatherInformation/res/layout/weather_main.xml b/Android/WeatherInformation/res/layout/weather_main.xml index db32dde..215fc01 100644 --- a/Android/WeatherInformation/res/layout/weather_main.xml +++ b/Android/WeatherInformation/res/layout/weather_main.xml @@ -1,7 +1,7 @@ - - - + + - \ No newline at end of file + \ No newline at end of file diff --git a/Android/WeatherInformation/res/menu/weather_main_menu.xml b/Android/WeatherInformation/res/menu/weather_main_menu.xml index f7329cf..f2f40d1 100644 --- a/Android/WeatherInformation/res/menu/weather_main_menu.xml +++ b/Android/WeatherInformation/res/menu/weather_main_menu.xml @@ -11,7 +11,7 @@ android:visible="true" android:checkable="false" android:enabled="true" - android:icon="@drawable/ic_action_import_export" + android:icon="@drawable/ic_action_refresh" android:showAsAction="ifRoom|withText"> Ukrainian Vietnamese + + 5 + 10 + 14 + + + 5-Day Forecast + 10-Day Forecast + 14-Day Forecast + diff --git a/Android/WeatherInformation/res/values/strings.xml b/Android/WeatherInformation/res/values/strings.xml index 2e4725b..e87cdcc 100644 --- a/Android/WeatherInformation/res/values/strings.xml +++ b/Android/WeatherInformation/res/values/strings.xml @@ -41,6 +41,8 @@ Unit of measurement for temperature weather_preferences_language Language + weather_preferences_day_forecast + Forecast days number city not found country not found Downloading remote data diff --git a/Android/WeatherInformation/res/xml/weather_preferences.xml b/Android/WeatherInformation/res/xml/weather_preferences.xml index 4d5e35c..3490cb6 100644 --- a/Android/WeatherInformation/res/xml/weather_preferences.xml +++ b/Android/WeatherInformation/res/xml/weather_preferences.xml @@ -18,5 +18,14 @@ android:persistent="true" android:selectable="true" android:summary="English"/> + diff --git a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationActivity.java b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationActivity.java index 876310b..c58c3a1 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationActivity.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationActivity.java @@ -4,6 +4,7 @@ import android.app.ActionBar; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.Menu; @@ -15,7 +16,6 @@ import de.example.exampletdd.service.WeatherServicePersistenceFile; public class WeatherInformationActivity extends Activity { private GetWeather mGetWeather; - private WeatherServicePersistenceFile mWeatherServicePersistenceFile; @Override protected void onCreate(final Bundle savedInstanceState) { @@ -42,8 +42,6 @@ public class WeatherInformationActivity extends Activity { this.mGetWeather = weatherOverviewFragment; - this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile( - this); } @Override @@ -74,8 +72,8 @@ public class WeatherInformationActivity extends Activity { return true; case R.id.weather_menu_map: intent = new Intent("de.example.exampletdd.WEATHERINFO") - .setComponent(new ComponentName("de.example.exampletdd", - "de.example.exampletdd.WeatherInformationMapActivity")); + .setComponent(new ComponentName("de.example.exampletdd", + "de.example.exampletdd.WeatherInformationMapActivity")); this.startActivity(intent); return true; case R.id.weather_menu_current: @@ -97,8 +95,8 @@ public class WeatherInformationActivity extends Activity { final ActionBar actionBar = this.getActionBar(); - final GeocodingData geocodingData = - this.mWeatherServicePersistenceFile.getGeocodingData(); + final WeatherServicePersistenceFile weatherServicePersistenceFile = new WeatherServicePersistenceFile(this); + final GeocodingData geocodingData = weatherServicePersistenceFile.getGeocodingData(); if (geocodingData != null) { final String city = (geocodingData.getCity() == null) ? this.getString(R.string.city_not_found) @@ -108,6 +106,22 @@ public class WeatherInformationActivity extends Activity { actionBar.setTitle(city + "," + country); } + + final SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(this); + final String keyPreference = this.getResources().getString( + R.string.weather_preferences_day_forecast_key); + final String value = sharedPreferences.getString(keyPreference, ""); + String humanValue = ""; + if (value.equals("5")) { + humanValue = "5-Day Forecast"; + } else if (value.equals("10")) { + humanValue = "10-Day Forecast"; + } else if (value.equals("14")) { + humanValue = "14-Day Forecast"; + } + actionBar.setSubtitle(humanValue); + } diff --git a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java index ff6da3d..834f705 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java @@ -3,13 +3,10 @@ package de.example.exampletdd; import android.app.ActionBar; import android.app.Activity; import android.os.Bundle; -import android.preference.PreferenceManager; -import de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment; import de.example.exampletdd.model.GeocodingData; import de.example.exampletdd.service.WeatherServicePersistenceFile; public class WeatherInformationCurrentDataActivity extends Activity { - private WeatherServicePersistenceFile mWeatherServicePersistenceFile; @Override protected void onCreate(final Bundle savedInstanceState) { @@ -22,13 +19,6 @@ public class WeatherInformationCurrentDataActivity extends Activity { actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayHomeAsUpEnabled(true); - final WeatherInformationSpecificDataFragment fragment = new WeatherInformationSpecificDataFragment(); - - if (savedInstanceState == null) { - this.getFragmentManager().beginTransaction().add(R.id.container, fragment).commit(); - } - - this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this); } @Override @@ -39,7 +29,8 @@ public class WeatherInformationCurrentDataActivity extends Activity { actionBar.setTitle("Current weather information"); - final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData(); + final WeatherServicePersistenceFile weatherServicePersistenceFile = new WeatherServicePersistenceFile(this); + final GeocodingData geocodingData = weatherServicePersistenceFile.getGeocodingData(); if (geocodingData != null) { final String city = (geocodingData.getCity() == null) ? this diff --git a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationMapActivity.java b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationMapActivity.java index d5f6c6c..64f2a80 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationMapActivity.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationMapActivity.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.List; import java.util.Locale; +import android.app.ActionBar; import android.app.Activity; import android.app.DialogFragment; import android.location.Address; @@ -69,6 +70,15 @@ public class WeatherInformationMapActivity extends Activity { } } + @Override + public void onResume() { + super.onResume(); + + final ActionBar actionBar = this.getActionBar(); + + actionBar.setTitle("Mark your location"); + } + private class LongClickListener implements OnMapLongClickListener { @Override diff --git a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationSpecificDataActivity.java b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationSpecificDataActivity.java index 0b8e3fb..549b61b 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationSpecificDataActivity.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationSpecificDataActivity.java @@ -3,12 +3,10 @@ package de.example.exampletdd; import android.app.ActionBar; import android.app.Activity; import android.os.Bundle; -import de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment; import de.example.exampletdd.model.GeocodingData; import de.example.exampletdd.service.WeatherServicePersistenceFile; public class WeatherInformationSpecificDataActivity extends Activity { - private WeatherServicePersistenceFile mWeatherServicePersistenceFile; @Override protected void onCreate(final Bundle savedInstanceState) { @@ -21,15 +19,6 @@ public class WeatherInformationSpecificDataActivity extends Activity { actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayHomeAsUpEnabled(true); - final WeatherInformationSpecificDataFragment fragment = - new WeatherInformationSpecificDataFragment(); - - if (savedInstanceState == null) { - this.getFragmentManager().beginTransaction() - .add(R.id.container, fragment).commit(); - } - - this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this); } @Override @@ -38,15 +27,17 @@ public class WeatherInformationSpecificDataActivity extends Activity { final ActionBar actionBar = this.getActionBar(); - final GeocodingData geocodingData = this.mWeatherServicePersistenceFile.getGeocodingData(); + final WeatherServicePersistenceFile weatherServicePersistenceFile = new WeatherServicePersistenceFile(this); + final GeocodingData geocodingData = weatherServicePersistenceFile.getGeocodingData(); if (geocodingData != null) { - final String city = (geocodingData.getCity() == null) ? this.getString(R.string.city_not_found) - : geocodingData.getCity(); - final String country = (geocodingData.getCountry() == null) ? this.getString(R.string.country_not_found) - : geocodingData.getCountry(); - actionBar.setTitle(city + "," + country); - } + final String city = (geocodingData.getCity() == null) ? this + .getString(R.string.city_not_found) : geocodingData.getCity(); + final String country = (geocodingData.getCountry() == null) ? this + .getString(R.string.country_not_found) : geocodingData.getCountry(); + actionBar.setTitle("Specific weather data information"); + actionBar.setSubtitle(city + "," + country); + } } } diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java index 4f4a2ba..b122d8f 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java @@ -10,7 +10,6 @@ import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; @@ -18,7 +17,7 @@ import java.util.Locale; import org.apache.http.client.ClientProtocolException; import android.app.DialogFragment; -import android.app.Fragment; +import android.app.ListFragment; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -27,9 +26,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ListView; @@ -48,7 +44,7 @@ import de.example.exampletdd.parser.JPOSWeatherParser; import de.example.exampletdd.service.WeatherServiceParser; import de.example.exampletdd.service.WeatherServicePersistenceFile; -public class WeatherInformationCurrentDataFragment extends Fragment { +public class WeatherInformationCurrentDataFragment extends ListFragment { private boolean mIsFahrenheit; private WeatherServicePersistenceFile mWeatherServicePersistenceFile; @@ -68,22 +64,11 @@ public class WeatherInformationCurrentDataFragment extends Fragment { } @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - final View rootView = inflater.inflate(R.layout.weather_data_list, container, false); - - return rootView; - } - - @Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - final ListView listWeatherView = (ListView) this.getActivity().findViewById( - R.id.weather_data_list_view); - - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( - this.getActivity(), R.layout.weather_data_entry_list); + final ListView listWeatherView = this.getListView(); + listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); if (savedInstanceState != null) { // Restore state @@ -101,10 +86,17 @@ public class WeatherInformationCurrentDataFragment extends Fragment { } } - final Collection entries = this.createEmptyEntriesList(); + this.setHasOptionsMenu(false); - adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( + this.getActivity(), R.layout.weather_data_entry_list); + + + this.setEmptyText("No data available"); + + this.setListAdapter(adapter); + this.setListShown(true); + this.setListShownNoAnimation(true); } @@ -134,15 +126,9 @@ public class WeatherInformationCurrentDataFragment extends Fragment { this.updateCurrentWeatherData(currentWeatherData); } else { // 2.1 Empty list by default - final List entries = this.createEmptyEntriesList(); - - final ListView listWeatherView = (ListView) this.getActivity().findViewById( - R.id.weather_data_list_view); - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( this.getActivity(), R.layout.weather_data_entry_list); - adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + this.setListAdapter(adapter); // 2.2. Try to update weather data on display with remote // information. @@ -189,9 +175,6 @@ public class WeatherInformationCurrentDataFragment extends Fragment { final List entries = this.createEmptyEntriesList(); - final ListView listWeatherView = (ListView) this.getActivity().findViewById( - R.id.weather_data_list_view); - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( this.getActivity(), R.layout.weather_data_entry_list); @@ -254,9 +237,8 @@ public class WeatherInformationCurrentDataFragment extends Fragment { imageIcon.setImageBitmap(icon); } - listWeatherView.setAdapter(null); adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + this.setListAdapter(adapter); } public class CurrentWeatherTask extends AsyncTask { @@ -379,7 +361,7 @@ public class WeatherInformationCurrentDataFragment extends Fragment { throws FileNotFoundException, IOException { WeatherInformationCurrentDataFragment.this.mWeatherServicePersistenceFile - .storeCurrentWeatherData(currentWeatherData); + .storeCurrentWeatherData(currentWeatherData); WeatherInformationCurrentDataFragment.this.updateCurrentWeatherData(currentWeatherData); } diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java index c401d64..a3ca249 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java @@ -48,18 +48,18 @@ import de.example.exampletdd.service.WeatherServicePersistenceFile; public class WeatherInformationOverviewFragment extends ListFragment implements GetWeather { private boolean mIsFahrenheit; + private String mDayForecast; private WeatherServicePersistenceFile mWeatherServicePersistenceFile; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // final SharedPreferences sharedPreferences = PreferenceManager - // .getDefaultSharedPreferences(this.getActivity()); - // final String keyPreference = this.getResources().getString( - // R.string.weather_preferences_language_key); - // this.mLanguage = sharedPreferences.getString( - // keyPreference, ""); + final SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(this.getActivity()); + final String keyPreference = this.getResources().getString( + R.string.weather_preferences_day_forecast_key); + this.mDayForecast = sharedPreferences.getString(keyPreference, ""); this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this.getActivity()); this.mWeatherServicePersistenceFile.removeForecastWeatherData(); @@ -69,10 +69,7 @@ public class WeatherInformationOverviewFragment extends ListFragment implements public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - - final ListView listWeatherView = this.getListView(); - listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); if (savedInstanceState != null) { @@ -218,7 +215,7 @@ public class WeatherInformationOverviewFragment extends ListFragment implements .getDefaultSharedPreferences(this.getActivity()); // 1. Update units of measurement. - final String keyPreference = this.getResources().getString( + String keyPreference = this.getResources().getString( R.string.weather_preferences_units_key); final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, ""); final String celsius = this.getResources().getString( @@ -229,25 +226,19 @@ public class WeatherInformationOverviewFragment extends ListFragment implements this.mIsFahrenheit = true; } + // 2. Update number day forecast. + keyPreference = this.getResources().getString( + R.string.weather_preferences_day_forecast_key); + this.mDayForecast = sharedPreferences.getString(keyPreference, ""); + - // 2. Update forecast weather data on display. + // 3. Update forecast weather data on display. final ForecastWeatherData forecastWeatherData = this.mWeatherServicePersistenceFile .getForecastWeatherData(); if (forecastWeatherData != null) { this.updateForecastWeatherData(forecastWeatherData); } - - // 3. If language changed, try to retrieve new data for new language - // (new strings with the chosen language) - // keyPreference = this.getResources().getString( - // R.string.weather_preferences_language_key); - // final String languagePreferenceValue = sharedPreferences.getString( - // keyPreference, ""); - // if (!languagePreferenceValue.equals(this.mLanguage)) { - // this.mLanguage = languagePreferenceValue; - // this.getWeather(); - // } } public class ForecastWeatherTask extends AsyncTask { @@ -351,7 +342,7 @@ public class WeatherInformationOverviewFragment extends ListFragment implements final String urlAPI = WeatherInformationOverviewFragment.this.getResources() .getString(R.string.uri_api_weather_forecast); final String url = this.weatherService.createURIAPIForecastWeather(urlAPI, APIVersion, - geocodingData.getLatitude(), geocodingData.getLongitude(), "14"); + geocodingData.getLatitude(), geocodingData.getLongitude(), WeatherInformationOverviewFragment.this.mDayForecast); final String jsonData = this.weatherHTTPClient.retrieveDataAsString(new URL(url)); final ForecastWeatherData forecastWeatherData = this.weatherService .retrieveForecastWeatherDataFromJPOS(jsonData); @@ -362,7 +353,7 @@ public class WeatherInformationOverviewFragment extends ListFragment implements private void onPostExecuteThrowable(final ForecastWeatherData forecastWeatherData) throws FileNotFoundException, IOException { WeatherInformationOverviewFragment.this.mWeatherServicePersistenceFile - .storeForecastWeatherData(forecastWeatherData); + .storeForecastWeatherData(forecastWeatherData); WeatherInformationOverviewFragment.this.updateForecastWeatherData(forecastWeatherData); } diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/preferences/WeatherInformationPreferencesFragment.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/preferences/WeatherInformationPreferencesFragment.java index 13f77db..4dc70d6 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/preferences/WeatherInformationPreferencesFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/preferences/WeatherInformationPreferencesFragment.java @@ -28,6 +28,20 @@ implements OnSharedPreferenceChangeListener { connectionPref = this.findPreference(keyPreference); connectionPref.setSummary(this.getPreferenceManager() .getSharedPreferences().getString(keyPreference, "")); + + keyPreference = this.getActivity().getString( + R.string.weather_preferences_day_forecast_key); + connectionPref = this.findPreference(keyPreference); + final String value = this.getPreferenceManager().getSharedPreferences().getString(keyPreference, ""); + String humanValue = ""; + if (value.equals("5")) { + humanValue = "5-Day Forecast"; + } else if (value.equals("10")) { + humanValue = "10-Day Forecast"; + } else if (value.equals("14")) { + humanValue = "14-Day Forecast"; + } + connectionPref.setSummary(humanValue); } @Override @@ -54,6 +68,7 @@ implements OnSharedPreferenceChangeListener { if (key.equals(keyValue)) { final Preference connectionPref = this.findPreference(key); connectionPref.setSummary(sharedPreferences.getString(key, "")); + return; } keyValue = this.getActivity().getString( @@ -61,6 +76,24 @@ implements OnSharedPreferenceChangeListener { if (key.equals(keyValue)) { final Preference connectionPref = this.findPreference(key); connectionPref.setSummary(sharedPreferences.getString(key, "")); + return; + } + + keyValue = this.getActivity().getString( + R.string.weather_preferences_day_forecast_key); + if (key.equals(keyValue)) { + final Preference connectionPref = this.findPreference(key); + final String value = sharedPreferences.getString(key, ""); + String humanValue = ""; + if (value.equals("5")) { + humanValue = "5-Day Forecast"; + } else if (value.equals("10")) { + humanValue = "10-Day Forecast"; + } else if (value.equals("14")) { + humanValue = "14-Day Forecast"; + } + connectionPref.setSummary(humanValue); + return; } } diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java index 8de11a0..5501a7f 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java @@ -4,18 +4,14 @@ import java.io.IOException; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Locale; import android.app.DialogFragment; -import android.app.Fragment; +import android.app.ListFragment; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; import android.widget.ListView; import de.example.exampletdd.R; import de.example.exampletdd.activityinterface.GetWeather; @@ -23,7 +19,7 @@ import de.example.exampletdd.fragment.ErrorDialogFragment; import de.example.exampletdd.model.forecastweather.ForecastWeatherData; import de.example.exampletdd.service.WeatherServicePersistenceFile; -public class WeatherInformationSpecificDataFragment extends Fragment implements GetWeather { +public class WeatherInformationSpecificDataFragment extends ListFragment implements GetWeather { private boolean mIsFahrenheit; private int mChosenDay; private WeatherServicePersistenceFile mWeatherServicePersistenceFile; @@ -52,28 +48,20 @@ public class WeatherInformationSpecificDataFragment extends Fragment implements } @Override - public View onCreateView(final LayoutInflater inflater, - final ViewGroup container, final Bundle savedInstanceState) { - final View rootView = inflater.inflate(R.layout.weather_data_list, - container, false); - - return rootView; - } - - @Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - final ListView listWeatherView = (ListView) this.getActivity().findViewById( - R.id.weather_data_list_view); + final ListView listWeatherView = this.getListView(); + listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter(this.getActivity(), R.layout.weather_data_entry_list); - final Collection entries = this.createEmptyEntriesList(); + this.setEmptyText("No data available"); - adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + this.setListAdapter(adapter); + this.setListShown(true); + this.setListShownNoAnimation(true); if (savedInstanceState != null) { // Restore state @@ -132,8 +120,7 @@ public class WeatherInformationSpecificDataFragment extends Fragment implements final double tempUnits = this.mIsFahrenheit ? 0 : 273.15; final List entries = this.createEmptyEntriesList(); - final ListView listWeatherView = (ListView) this.getActivity().findViewById( - R.id.weather_data_list_view); + final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( this.getActivity(), R.layout.weather_data_entry_list); @@ -176,9 +163,8 @@ public class WeatherInformationSpecificDataFragment extends Fragment implements tempFormatter.format(cloudiness))); } - listWeatherView.setAdapter(null); adapter.addAll(entries); - listWeatherView.setAdapter(adapter); + this.setListAdapter(adapter); } @Override @@ -207,6 +193,11 @@ public class WeatherInformationSpecificDataFragment extends Fragment implements .getForecastWeatherData(); if (forecastWeatherData != null) { this.updateForecastWeatherData(forecastWeatherData, this.mChosenDay); + } else { + // 2.1 Empty list by default + final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( + this.getActivity(), R.layout.weather_data_entry_list); + this.setListAdapter(adapter); }