Improvements in lists.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 15 Apr 2014 21:08:47 +0000 (23:08 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 15 Apr 2014 21:08:47 +0000 (23:08 +0200)
21 files changed:
lint.xml [new file with mode: 0644]
res/drawable-hdpi/ic_action_refresh.png [new file with mode: 0644]
res/drawable-mdpi/ic_action_refresh.png [new file with mode: 0644]
res/drawable-xhdpi/ic_action_refresh.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_action_refresh.png [new file with mode: 0644]
res/layout/weather_current_data.xml
res/layout/weather_main.xml
res/layout/weather_map.xml
res/layout/weather_specific_data.xml
res/menu/weather_main_menu.xml
res/values/arrays.xml
res/values/strings.xml
res/xml/weather_preferences.xml
src/de/example/exampletdd/WeatherInformationActivity.java
src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java
src/de/example/exampletdd/WeatherInformationMapActivity.java
src/de/example/exampletdd/WeatherInformationSpecificDataActivity.java
src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java
src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java
src/de/example/exampletdd/fragment/preferences/WeatherInformationPreferencesFragment.java
src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java

diff --git a/lint.xml b/lint.xml
new file mode 100644 (file)
index 0000000..ee0eead
--- /dev/null
+++ b/lint.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+</lint>
\ No newline at end of file
diff --git a/res/drawable-hdpi/ic_action_refresh.png b/res/drawable-hdpi/ic_action_refresh.png
new file mode 100644 (file)
index 0000000..dae2790
Binary files /dev/null and b/res/drawable-hdpi/ic_action_refresh.png differ
diff --git a/res/drawable-mdpi/ic_action_refresh.png b/res/drawable-mdpi/ic_action_refresh.png
new file mode 100644 (file)
index 0000000..94ab6f4
Binary files /dev/null and b/res/drawable-mdpi/ic_action_refresh.png differ
diff --git a/res/drawable-xhdpi/ic_action_refresh.png b/res/drawable-xhdpi/ic_action_refresh.png
new file mode 100644 (file)
index 0000000..ab4ab9d
Binary files /dev/null and b/res/drawable-xhdpi/ic_action_refresh.png differ
diff --git a/res/drawable-xxhdpi/ic_action_refresh.png b/res/drawable-xxhdpi/ic_action_refresh.png
new file mode 100644 (file)
index 0000000..44ee117
Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_refresh.png differ
index 9ffb611..0f581a6 100644 (file)
@@ -1,16 +1,26 @@
 <?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/container"
+    android:id="@+id/weather_current_data"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:gravity="center"
+    android:orientation="vertical"
     tools:context="de.example.exampletdd.WeatherInformationCurrentDataActivity"
     tools:ignore="MergeRootFrame" >
 
+    <ImageView
+        android:id="@+id/weather_current_picture"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:contentDescription="@string/icon_weather_description"
+        android:scaleType="fitCenter"
+        android:src="@drawable/ic_launcher" />
+
      <fragment
-        android:id="@+id/weather_specific_data_fragment"
+        android:id="@+id/weather_current_data_fragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         class="de.example.exampletdd.fragment.current.WeatherInformationCurrentDataFragment" />
 
-</FrameLayout>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
index db32dde..215fc01 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/container"
+    android:id="@+id/weather_main"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context="de.example.exampletdd.WeatherInformationActivity"
index e3a4d5b..32586c4 100644 (file)
@@ -4,32 +4,17 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_gravity="bottom"
-    android:paddingBottom="@dimen/activity_vertical_margin"
-    android:paddingLeft="@dimen/activity_horizontal_margin"
-    android:paddingRight="@dimen/activity_horizontal_margin"
-    android:paddingTop="@dimen/activity_vertical_margin"
     tools:context="de.example.exampletdd.WeatherInformationMapActivity" >
 
     <TextView
-        android:id="@+id/weather_map_citycountry_header"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="top"
-        android:text="City,country:"
-        android:textAlignment="textStart"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:textIsSelectable="false"
-        android:textStyle="normal" />
-    
-    <TextView
         android:id="@+id/weather_map_citycountry_data"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_below="@+id/weather_map_citycountry_header"
         android:gravity="top"
         android:text="City,country"
         android:textAlignment="textStart"
         android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textIsSelectable="false"
         android:textStyle="bold|normal" />
 
     <fragment
index c3f0915..e6a25e5 100644 (file)
@@ -1,16 +1,26 @@
 <?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/container"
+    android:id="@+id/weather_specific_data"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:gravity="center"
+    android:orientation="vertical"
     tools:context="de.example.exampletdd.WeatherInformationSpecificDataActivity"
     tools:ignore="MergeRootFrame" >
 
+    <ImageView
+        android:id="@+id/weather_specific_picture"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:contentDescription="@string/icon_weather_description"
+        android:scaleType="fitCenter"
+        android:src="@drawable/ic_launcher" />
+
      <fragment
         android:id="@+id/weather_specific_data_fragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         class="de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment" />
 
-</FrameLayout>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
index f7329cf..f2f40d1 100644 (file)
@@ -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">
     </item>
     <item
index b9aedcf..9eec8c4 100644 (file)
         <item>Ukrainian</item>
         <item>Vietnamese</item>
     </string-array>
+    <string-array name="weather_preferences_day_forecast">
+        <item>5</item>
+        <item>10</item>
+        <item>14</item>
+    </string-array>
+    <string-array name="weather_preferences_day_forecast_human_value">
+        <item>5-Day Forecast</item>
+        <item>10-Day Forecast</item>
+        <item>14-Day Forecast</item>
+    </string-array>
 </resources>
index 2e4725b..e87cdcc 100644 (file)
@@ -41,6 +41,8 @@
     <string name="weather_preferences_units">Unit of measurement for temperature</string>
     <string name="weather_preferences_language_key">weather_preferences_language</string>
     <string name="weather_preferences_language">Language</string>
+    <string name="weather_preferences_day_forecast_key">weather_preferences_day_forecast</string>
+    <string name="weather_preferences_day_forecast">Forecast days number</string>
     <string name="city_not_found">city not found</string>
     <string name="country_not_found">country not found</string>
     <string name="progress_dialog_get_remote_data">Downloading remote data</string>
index 4d5e35c..3490cb6 100644 (file)
         android:persistent="true"
         android:selectable="true"
         android:summary="English"/>
+    <ListPreference
+        android:key="@string/weather_preferences_day_forecast_key"
+        android:title="@string/weather_preferences_day_forecast"
+        android:entries="@array/weather_preferences_day_forecast_human_value"
+        android:entryValues="@array/weather_preferences_day_forecast"
+        android:selectable="true"
+        android:persistent="true"
+        android:defaultValue="14"
+        android:summary="14-Day Forecast" />
 
 </PreferenceScreen>
index 876310b..c58c3a1 100644 (file)
@@ -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);
+
     }
 
 
index ff6da3d..834f705 100644 (file)
@@ -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
index d5f6c6c..64f2a80 100644 (file)
@@ -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
index 0b8e3fb..549b61b 100644 (file)
@@ -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);
 
+        }
     }
 }
index 4f4a2ba..b122d8f 100644 (file)
@@ -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<WeatherSpecificDataEntry> 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<WeatherSpecificDataEntry> 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<WeatherSpecificDataEntry> 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<Object, Void, CurrentWeatherData> {
@@ -379,7 +361,7 @@ public class WeatherInformationCurrentDataFragment extends Fragment {
                 throws FileNotFoundException, IOException {
 
             WeatherInformationCurrentDataFragment.this.mWeatherServicePersistenceFile
-                    .storeCurrentWeatherData(currentWeatherData);
+            .storeCurrentWeatherData(currentWeatherData);
 
             WeatherInformationCurrentDataFragment.this.updateCurrentWeatherData(currentWeatherData);
         }
index c401d64..a3ca249 100644 (file)
@@ -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<Object, Void, ForecastWeatherData> {
@@ -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);
         }
index 13f77db..4dc70d6 100644 (file)
@@ -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;
         }
 
     }
index 8de11a0..5501a7f 100644 (file)
@@ -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<WeatherSpecificDataEntry> 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<WeatherSpecificDataEntry> 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);
         }