From cc6c7e997cf8c90101383903eb4e76af37d05286 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Tue, 15 Apr 2014 23:08:47 +0200 Subject: [PATCH] Improvements in lists. --- Android/WeatherInformation/lint.xml | 3 ++ .../res/drawable-hdpi/ic_action_refresh.png | Bin 0 -> 663 bytes .../res/drawable-mdpi/ic_action_refresh.png | Bin 0 -> 508 bytes .../res/drawable-xhdpi/ic_action_refresh.png | Bin 0 -> 895 bytes .../res/drawable-xxhdpi/ic_action_refresh.png | Bin 0 -> 1239 bytes .../res/layout/weather_current_data.xml | 18 +++++-- .../WeatherInformation/res/layout/weather_main.xml | 2 +- .../WeatherInformation/res/layout/weather_map.xml | 17 +------ .../res/layout/weather_specific_data.xml | 16 +++++-- .../res/menu/weather_main_menu.xml | 2 +- Android/WeatherInformation/res/values/arrays.xml | 10 ++++ Android/WeatherInformation/res/values/strings.xml | 2 + .../res/xml/weather_preferences.xml | 9 ++++ .../exampletdd/WeatherInformationActivity.java | 28 ++++++++--- .../WeatherInformationCurrentDataActivity.java | 13 +----- .../exampletdd/WeatherInformationMapActivity.java | 10 ++++ .../WeatherInformationSpecificDataActivity.java | 27 ++++------- .../WeatherInformationCurrentDataFragment.java | 52 +++++++-------------- .../WeatherInformationOverviewFragment.java | 39 ++++++---------- .../WeatherInformationPreferencesFragment.java | 33 +++++++++++++ .../WeatherInformationSpecificDataFragment.java | 39 ++++++---------- 21 files changed, 176 insertions(+), 144 deletions(-) create mode 100644 Android/WeatherInformation/lint.xml create mode 100644 Android/WeatherInformation/res/drawable-hdpi/ic_action_refresh.png create mode 100644 Android/WeatherInformation/res/drawable-mdpi/ic_action_refresh.png create mode 100644 Android/WeatherInformation/res/drawable-xhdpi/ic_action_refresh.png create mode 100644 Android/WeatherInformation/res/drawable-xxhdpi/ic_action_refresh.png 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 0000000000000000000000000000000000000000..dae27903e9ba3415808d48e6ac20afd6de64907b GIT binary patch literal 663 zcmV;I0%-k-P)RI}s=BK%nX zlUx%QIv80pc1(T;vVlKX)Vx1|;n|hBVn^gfP_BsCW76<^*ogv|EgstVEbOtsZ1pcL zlxj9#id5*3d^awHe#@2VtpWK|BL5rURme>gU_=6$qQDWzPtV~B!U*IqVR%)hjSibG zF(9lNt2zE$$Ws;Inv@y!NrBNhD?o{X4`u2aT&VO^Bm7vu&Si}ifX%KvRAn3LHwRJA zK{?2bDkKL`Py3=(5PK%CyUdksvyg9$oLazhXCl!YoOz!tFw=B0`k{c-AdqorI&+xC zhq8*yp{t}GfxzBiUv8QKZHjtMT(>kJzo@7;8Z)4c1vZ4bl~k#r+oYOGO%y$Mlq-vk z1)4V963KHUugm)>^}ZE5j>X2Tf#vC}#uZm}Z5bCXG>2hMSei>CC&W*QLGQjMwp73b zImV6gwZ%mY6qrVBdZZ#)*VOKYD+>rW$RzTjz%Q|DH%2!}2ywEbrrE9(_#-z^uNgfEYJ?X0v;e4!2PF!d%e@SmQ!PVe6+gr*@umuEKASwcC)f< z|GWWrF_jO)uwTspfWO^ZxARn*Qddzc&{8(7&^q)l<2?OSBuUZ-8$gO4se3R$x#Vc0 zf!eXo&j9TD2<2QfcDex=pHGFcp8*2+=+0Nutyp`amRUUWKGy>W20re%Az(?_vju$q z5zvlG>PiOwMBqwTTjT6);!MTFVL-=r)DrmFaZI@g;K%^c1Ee%(;8zJ802*px6z zlwg&mXlX(#B5nCr5nu)5G*ZoW6*o6x#QO-Y29R_M_BPg=Ye0`&o~~q2>vvI_8SAE^ yG?c!76r+gfb>ugXi>NOna_8m$aT-&;1Q-A|?2p+^qB;uz0000CckPh%V0R3M2y&0fcAOnyAGC(sxGXNQY0rI3fagVyT<9`H*tvelU4-CJbC0VlE z2Nt+IL;@lKk$^}*Bp?znO}ShyPr=R{fM0=r1!(~QJcrAhkFk;)esl(xN6J>A;2~0ia@Ib@6GAwB|VR1RG@nRSrhnA zj=0q28)rQNFIpg;WKR~v1AYN=j-#;v0FN{N*L7wDA|n&6W_SW<);~ICJPAoWfk)rm zX!tp!Acr$nQ_yS3T5ybvt_y?Lr-Kq82~4~o$Xy%EB=;P+6=O-RbWIk65kO|I0^b7P z0q{mUGXIbGqjv!ncr@=<#f+2FLTJs0&G z3HWij0IkoW=!})yA%q>FN6FuJQ{7lGB|zx=Q=NTZ1WXpZ5dob@{mcJ@AV87z)l(+G zxf*m`hdq|#Dd(a`ot>hD-G>x{__Wn=&)_>lCKhleR?j2!`>b~YsI=XVbRy@H31fHf z0*Xqo4uSwC--SMfLcmG{UbixxdV4&RBxu^%>C`PiwryVBJpr^cwUkt++SzI1=|erm@*+zKXNh0OrE?o zV)}{!ZLjZ{Iri^6;~Aec(Gf4_1i3T2KLQgSXkIe?6CeD_(H@j+`Y@?J2#_9J?6lTZ zfvydZ$G$-KQJGap0-oTWT2<*Q2-XywDi)&L>PTCZ9wh$HP$VD{5DAC`ge?CA7yzOq VDq)Usy-@%F002ovPDHLkV1gKjk--1} literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..44ee117ee91541ed71f27685dde0b03b51b89f7f GIT binary patch literal 1239 zcmV;|1StE7P) z5dr`J0000000000003wMK0iOlU?Cj&OWC$yA{_Z2)WC*+^3#HR9|H6uA>~fK3{<1{ zx9TJMcVE5FWjmGLALzB$>t!`#{^HAzC-VQuuTB6-#z?*lWgC?UZweA&FWb8$^H76) z!mN&nQ463fJ(caDWZAAk*8D0--5QX89Reugr;2!Apm6o7yyK}t@QoB;(@6m&@zm+L zXX5LERe&ULj9)N@8dqSwza)^=FVx@~0|uQDK$1_LS#ozOCiFa$|7_vXxk@E}=lGX$ zb9tSisuhN+*`}~Zd988O0$7lrt4w7tNjO<#STx9wn~EW?eIKm=4av_`_K`WdhrYUp zLE8jKT1Gxu{Fb+Mkv?Z6e-TR| zcH_A714GMutBO%J^{XIKHqUZ+Pi82)Wa2B=Cc9ad>)`Hx-zc06bN9JrtLsAQx;^H{e0&r zy5Iq3)}MiVUIBD7p2&PcdjM$mQwLna5j08F}_ENY*|b4D(*pbw1z z_Z=a7T`}HKqA_b@2$k5EUi_T?zSj zn$Hix1h^9DLeL2U@IqJZH;w{5aBE-d2#eWXcz~Y#k!}FCneBxDdguhOnrwss)z(i1 zm~Nrj9s=+oHTVuZfYJJO0_<#`_CbKlpoM0-IUwuvgph`ww|<&_elf^?tanc)9y;^2 zh#6E^R$o+ahWO`r8jf|QD)cN3zUpM5nU7tPZ^Hd_E>)g0ru_v=gUrX--eDhOfa}S+ z6C?SlFx%g-balESWzp8qF%rjSyd#J{w&Cwng{~| z2mtZ}3D5`m;YApM1poj50000000000fS~v#zyO={=$CR|bEp6S002ovPDHLkV1lVS BMRNcE literal 0 HcmV?d00001 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); } -- 2.1.4