From 7cc7ce9398ebffce9d2fe88f96b9259cd680730c Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Sun, 20 Apr 2014 05:57:08 +0200 Subject: [PATCH] No time for comments --- AndroidManifest.xml | 5 - res/drawable-hdpi/ic_action_map.png | Bin 0 -> 802 bytes res/drawable-mdpi/ic_action_map.png | Bin 0 -> 604 bytes res/drawable-xhdpi/ic_action_map.png | Bin 0 -> 1022 bytes res/drawable-xxhdpi/ic_action_map.png | Bin 0 -> 1529 bytes res/layout/activity_test_scroll.xml | 331 --------------------- res/layout/fragment_test_scroll.xml | 16 - res/layout/weather_current_data_entry_first.xml | 51 ++++ res/layout/weather_current_data_entry_fourth.xml | 200 +++++++++++++ res/layout/weather_current_data_entry_second.xml | 24 ++ res/layout/weather_current_data_entry_third.xml | 271 +++++++++++++++++ res/layout/weather_main_entry_list.xml | 80 +++-- res/layout/weather_specific_data.xml | 7 - res/menu/test_scroll.xml | 11 - res/menu/weather_main_menu.xml | 2 +- res/values/strings.xml | 1 - src/de/example/exampletdd/TestScrollActivity.java | 122 -------- .../exampletdd/WeatherInformationActivity.java | 2 +- .../WeatherInformationCurrentDataActivity.java | 4 +- .../WeatherInformationCurrentDataFragment.java | 49 +-- .../specific/WeatherCurrentDataAdapter.java | 223 ++++++++++++++ .../specific/WeatherCurrentDataEntryFirst.java | 28 ++ .../specific/WeatherCurrentDataEntryFourth.java | 33 ++ .../specific/WeatherCurrentDataEntrySecond.java | 14 + .../specific/WeatherCurrentDataEntryThird.java | 39 +++ .../WeatherInformationSpecificDataFragment.java | 169 ++++++----- .../specific/WeatherSpecificDataAdapter.java | 1 - 27 files changed, 1036 insertions(+), 647 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_map.png create mode 100644 res/drawable-mdpi/ic_action_map.png create mode 100644 res/drawable-xhdpi/ic_action_map.png create mode 100644 res/drawable-xxhdpi/ic_action_map.png delete mode 100644 res/layout/activity_test_scroll.xml delete mode 100644 res/layout/fragment_test_scroll.xml create mode 100644 res/layout/weather_current_data_entry_first.xml create mode 100644 res/layout/weather_current_data_entry_fourth.xml create mode 100644 res/layout/weather_current_data_entry_second.xml create mode 100644 res/layout/weather_current_data_entry_third.xml delete mode 100644 res/menu/test_scroll.xml delete mode 100644 src/de/example/exampletdd/TestScrollActivity.java create mode 100644 src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java create mode 100644 src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java create mode 100644 src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java create mode 100644 src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java create mode 100644 src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8b5e56e..bcfb02b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -86,11 +86,6 @@ android:value="@integer/google_play_services_version" /> - - diff --git a/res/drawable-hdpi/ic_action_map.png b/res/drawable-hdpi/ic_action_map.png new file mode 100644 index 0000000000000000000000000000000000000000..370cf5c38f3efec6d186a1e65ee9b23efbf0c1cb GIT binary patch literal 802 zcmV+-1Ks?IP)|3eB;0~7!SPyjh)Rx^smmSjcNVBlsnV2tHk-QM2Geu_G7 zPY(bO0Cx^xAii8KmkE80JK}fQ>-Bbj0FVu7q#Xgk#FzffP^bbSyE0$XDu&boAdaoC z$$QGtSrY(lIg!AL7(eZ4p$<4VqK`8jpM6lsx8q#lW)KQtXPlb?6hF78<5HZH?BE0d zE4IJ{>n5v1*M9J8Xz-PN74j!Zbqr9lWf-c>>+WMxA;G(x#wR(ISvsG>k(fa50pt); zg~aM-iZU$#qA)~bBo+Yk2+k+I0q7zSt2`v9Cjeq9c>F(wlCVMRK%^ww79$cR+z`19 z4o{%ZQQ|uToiZP-%fR4xX+am&gwqKe9b&E}pN9a(aD3cq1fb7vO(%qtqbfzA-=knT zz^OnZcdVFW%Sg#OzeL1OzLJHV2&C5|D5W87p*lN~KqwuyAEQSju2Dxq56h>Ej}eyQ{zP-{b{`mPkL z+yH2XYyL!^K3>{t=4PnIZ=#b_Zq8eWy%a?r{*}%4(03&^@pl8oG07^^^g+x-k+uNH z(XiP^GY#FMHUZ2ldUG{l53T^XAn*l1`{5q|!avt3h-I6>G=(g$*#r2YP*tKz$!Ap~ z08*W2C)Ews8h{#(mk!CdQ(6ZBzR(paA2OPFa9$KAu^8`ydYTA(10Y9$SK`9uMsRrP z&>W_^2-(PJEQPv=0va00m5)ly9GbfSI3D9kM&^S;OxmP}a6Gr@pX>qf#tl2H5VmN# z)$Cg);4u(@VH+wG(u$^!Vd?;+Hl1d`q)zLeMGZ9C--)+1H}!_*6kXq28JkBk-L}Vz g?gxN-2k;}n0Dm9>SJ?%Fr~m)}07*qoM6N<$f=nP{CIA2c literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_action_map.png b/res/drawable-mdpi/ic_action_map.png new file mode 100644 index 0000000000000000000000000000000000000000..50a91002ad0cbf33ea70fdeb8dcb560404ae25ca GIT binary patch literal 604 zcmV-i0;BzjP)U01dc+ zPyi`_6aWRJ0N@S<;Ctc%oC0Wo22_AufO02qnN>!k(ONbHCkJ+Bv4y4Gw;w&(N%D|C zmXvoWB@1V4*)9$s_*Q03eD`m2cVIb)jhqV+y`6=3BWZ5 zsecyG8JDt!me6PD7qoV!xBhx17_GTRB{hmLXU6GF7=UH~q-$rY+uUUo01PkK2rZmq zTmeKKz+eFwr?!LTDe#|d5Cg}rLi9AJVW1PQiOmoIQV&q7stZwsqt7@4EzdIyi2mQ* z3gA5X3bLQquR@A z)3*mgLY(j+ooay|*x$kfRluk{y^=uBG#R{@~9K{o@Va={(@Y`@r9P}5TfDCS6tn(cK&rbkNwB0gLBhYu&7l3uXibU>$(2*m17vceF z7hFiAuk#Ma8MErUbXqDQn#$exH^@BpuBkdwYJLHL_K51_Gp7n1M29=R5*B_bRN$O1 qk`YBYL{pCZUC=(h3;%_D3orn$Rk5nL;If_o0000N(we1wFVu9_11PrvDY{boe3 z7c5w?V8Mdjto7y2*Vor0Z63e5&q=@EPl}x%w;lljfLjM(P;q`mExU3bC)8qF05T$s z-8Fkp#2!+>B?T@$T4UPWQ;Vo6acWDE_>60YI5&~y?5Y7Erxf&u(wxqz?VwR2^QHfk7u{w3%Ww){YKy2OsD;3;cfN4i~(G-y`e~&ybip0os4j-;r zbPDusEe4o90)ZWV7S2CW+jmL_kh60!LOqPm8y$Z|PMYSqD)JdX@-q$q;G<$xTOq-y zw9k3>iM)L$Ct{3bT{{58m(sJR*P;X?ayX?nL!QO8XJ7sP9`|iDz+O!mTnmR%+N1{I z&s=gRNbZ39XX03Kdh?Cv;MkMmi!{!g+7<+QxMUT0 zff97J*y5f9a#%*oJ1WTowPopiBLMJA6lAN5{2f``I>(6jgfwRDp_r3EqDi9wpmr}D zNpR?J-&`Z4a?!uFCMA}Q=zxL`7?cb1)fW0=T$Ij|r9v+(Ph4XM0K&JJibgob(ZEa0 z+nNq!7&Y5Sh|uyA!fOqFNK96-1_tD%G;?mA4DEpUz9Nlsy7rgQ`rpBck&w|V=05VTMEHp#a zs4~N^+MEvOhS6|uI!CCuBz2g8c@sh=x%X+&mt92#IWB@aF2z|3p&ZN7b#gVUTZ0V% z*b7ytTH^p#gEdlRVcC~c0OUe}sHXYX1Zn0G9|@T`~jJtpET307*qoM6N<$f=bxXTL1t6 literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/ic_action_map.png b/res/drawable-xxhdpi/ic_action_map.png new file mode 100644 index 0000000000000000000000000000000000000000..ed72ce91c8788fad8b1a8ade10783d10b60f3ae7 GIT binary patch literal 1529 zcmVE2apfI zxBtjKWKRxY_JO_49Iab zo&hT*5C{YUfj}S-2m}JbCE?0;=llD6pl?PJ9#$k*S69cP1U&1TiNuT*u_j=Vz4Kb) z(k_GmAwUQaw1}HBRa_rO30Wabd=PN7RdIn;MgEZ#BsD-F1PrVQ_bm@oD`kp;7~n9m z(=~19IG3J#(vK%XK>5H^(7z)1d5SK{1bku~L|&+mtq@Q=@H2h$ppS6@IsH=~xB8qX z1l)Gc9Aq9$vT_jV8S~aS0s2kOF=7t3Zl9;rLe~t_6ru0iI7WPI(d2agW5LUfajhbt zYn3M8x@ItF#4R!MUMLXyxbw`x2G=ul`r2X=SMV*JHji~x&@A&ejlx$D<74y(#)v)> zjhV1A3DNf*^z$c{;yVl#gq-Wjw-3mlPt0j)mPrrFAmL44GfMM(U)D5kDh8iM-w(&b zRJ86f@+d7i*(j+C%Bh`2}LtOd&Jc+H(T3&aWM2W_u!_9&nnMR){dlc?$&2kM;LX#yf+ zbY_V-)(rgCk!E6CH%48u`GF%IPmjk>oN})SNMPGTkG&I{TaD4riB0Vf>3M!{S>i$F zbSNo^3gWT>2OJqa8oK6->zWxtY%cm~2sMC$u*mzc%yr~!v@pU`pJ7cg*_mi`Mt`V| zZ8*EB7?8IreGi5ryma(t(suJ4&r4HO>XE)d0v$OFM=%`7VHXXkoB7$K{k z5ul75pX8WJTT8{2ilVBL{F1k&OcBt;aMqNXzERW9an9Zm{HIoCK-TPdD#~7!78P54 z{D+kE*}{6n8T{Hl01h+lt&mI{!2})98;Y3-@TIl_tSO{vZVQ#KkbSmbb+BPokw-IS|uQw61q^m7ldT_+dsATia@2{=!6+A_kqfeWc4 zs&Hz=xMQO?1f;d$7xMWg|AS+5Q?hR7gEZp9$b9TDOd8=vdrl&(8>O z?cj@hOF#()QM-R$P+q#y;mOjr_%LKmZ8GyU1Ma&Jd;@z&>iMVRi7oG;Y6)BfOga>N zg;9RY1b@+1$1@K%4G_?D@ITa$PK#s|=brpVcL;!v9_Of?R$9GCH9OUDaHOEXk#84m z_Su^PHX|&%L_iw+_yU4YpZ!_Y*uBS51F{=fJ6Y^J1fS~OM%CQF%e^SSyO7}1LK4ej z64!Uc&WdN?fv08EN5!~BhNA}jHk8NPKm$L*sQ;yy_a||*qbcZXBQFju@Z@1$k#g9- zu)$ITNN(ykdQijr#r2Ky{8cBmA`Ih`3~2NRs)6sB$*(55G3|>J7Ier53<(Dzphdt? zdN-Alf_jvK0{jk}pd|uEO8&8rq#z+cAOr{j0zSEGyHoy^p%)~VuvjG!2m}IwKp+qZ f1Oh=m{t7SvM#&ydtJi}g00000NkvXXu0mjfVK&0o literal 0 HcmV?d00001 diff --git a/res/layout/activity_test_scroll.xml b/res/layout/activity_test_scroll.xml deleted file mode 100644 index 5ad3eba..0000000 --- a/res/layout/activity_test_scroll.xml +++ /dev/null @@ -1,331 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/fragment_test_scroll.xml b/res/layout/fragment_test_scroll.xml deleted file mode 100644 index cccb845..0000000 --- a/res/layout/fragment_test_scroll.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/res/layout/weather_current_data_entry_first.xml b/res/layout/weather_current_data_entry_first.xml new file mode 100644 index 0000000..bbfb715 --- /dev/null +++ b/res/layout/weather_current_data_entry_first.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + diff --git a/res/layout/weather_current_data_entry_fourth.xml b/res/layout/weather_current_data_entry_fourth.xml new file mode 100644 index 0000000..19d3488 --- /dev/null +++ b/res/layout/weather_current_data_entry_fourth.xml @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/weather_current_data_entry_second.xml b/res/layout/weather_current_data_entry_second.xml new file mode 100644 index 0000000..7c2fa49 --- /dev/null +++ b/res/layout/weather_current_data_entry_second.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/res/layout/weather_current_data_entry_third.xml b/res/layout/weather_current_data_entry_third.xml new file mode 100644 index 0000000..9f7094c --- /dev/null +++ b/res/layout/weather_current_data_entry_third.xml @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/weather_main_entry_list.xml b/res/layout/weather_main_entry_list.xml index f11a2ac..017f8d0 100644 --- a/res/layout/weather_main_entry_list.xml +++ b/res/layout/weather_main_entry_list.xml @@ -1,70 +1,96 @@ - + + + + + + - + + + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/res/layout/weather_specific_data.xml b/res/layout/weather_specific_data.xml index e6a25e5..2e0d4fe 100644 --- a/res/layout/weather_specific_data.xml +++ b/res/layout/weather_specific_data.xml @@ -9,13 +9,6 @@ tools:context="de.example.exampletdd.WeatherInformationSpecificDataActivity" tools:ignore="MergeRootFrame" > - - - - - diff --git a/res/menu/weather_main_menu.xml b/res/menu/weather_main_menu.xml index e2c28f0..26ff96f 100644 --- a/res/menu/weather_main_menu.xml +++ b/res/menu/weather_main_menu.xml @@ -28,7 +28,7 @@ country not found Downloading remote data Please wait… - TestScrollActivity Section 1 Section 2 Section 3 diff --git a/src/de/example/exampletdd/TestScrollActivity.java b/src/de/example/exampletdd/TestScrollActivity.java deleted file mode 100644 index b894a94..0000000 --- a/src/de/example/exampletdd/TestScrollActivity.java +++ /dev/null @@ -1,122 +0,0 @@ -package de.example.exampletdd; - -import android.app.ActionBar; -import android.app.Activity; -import android.app.Fragment; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -public class TestScrollActivity extends Activity implements ActionBar.OnNavigationListener { - - /** - * The serialization (saved instance state) Bundle key representing the - * current dropdown position. - */ - private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.setContentView(R.layout.activity_test_scroll); - - // Set up the action bar to show a dropdown list. - final ActionBar actionBar = this.getActionBar(); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - - // Set up the dropdown list navigation in the action bar. - actionBar.setListNavigationCallbacks( - // Specify a SpinnerAdapter to populate the dropdown list. - new ArrayAdapter(actionBar.getThemedContext(), - android.R.layout.simple_list_item_1, android.R.id.text1, new String[] { - this.getString(R.string.title_section1), - this.getString(R.string.title_section2), - this.getString(R.string.title_section3), }), this); - } - - @Override - public void onRestoreInstanceState(final Bundle savedInstanceState) { - // Restore the previously serialized current dropdown position. - if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { - this.getActionBar().setSelectedNavigationItem( - savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); - } - } - - @Override - public void onSaveInstanceState(final Bundle outState) { - // Serialize the current dropdown position. - outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, this.getActionBar().getSelectedNavigationIndex()); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - - // Inflate the menu; this adds items to the action bar if it is present. - this.getMenuInflater().inflate(R.menu.test_scroll, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - final int id = item.getItemId(); - if (id == R.id.action_settings) { - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - public boolean onNavigationItemSelected(final int position, final long id) { - // When the given dropdown item is selected, show its contents in the - // container view. - // getFragmentManager().beginTransaction() - // .replace(R.id.container, PlaceholderFragment.newInstance(position + - // 1)).commit(); - return true; - } - - /** - * A placeholder fragment containing a simple view. - */ - public static class PlaceholderFragment extends Fragment { - /** - * The fragment argument representing the section number for this - * fragment. - */ - private static final String ARG_SECTION_NUMBER = "section_number"; - - /** - * Returns a new instance of this fragment for the given section number. - */ - public static PlaceholderFragment newInstance(final int sectionNumber) { - final PlaceholderFragment fragment = new PlaceholderFragment(); - final Bundle args = new Bundle(); - args.putInt(ARG_SECTION_NUMBER, sectionNumber); - fragment.setArguments(args); - return fragment; - } - - public PlaceholderFragment() { - } - - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - final View rootView = inflater.inflate(R.layout.fragment_test_scroll, container, false); - final TextView textView = (TextView) rootView.findViewById(R.id.section_label); - textView.setText(Integer.toString(this.getArguments().getInt(ARG_SECTION_NUMBER))); - return rootView; - } - } - -} diff --git a/src/de/example/exampletdd/WeatherInformationActivity.java b/src/de/example/exampletdd/WeatherInformationActivity.java index b45a6ff..de41348 100644 --- a/src/de/example/exampletdd/WeatherInformationActivity.java +++ b/src/de/example/exampletdd/WeatherInformationActivity.java @@ -79,7 +79,7 @@ public class WeatherInformationActivity extends Activity { } else if (itemId == R.id.weather_menu_current) { intent = new Intent("de.example.exampletdd.WEATHERINFO") .setComponent(new ComponentName("de.example.exampletdd", - "de.example.exampletdd.TestScrollActivity")); + "de.example.exampletdd.WeatherInformationCurrentDataActivity")); this.startActivity(intent); return true; } else { diff --git a/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java b/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java index 834f705..4fd78f8 100644 --- a/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java +++ b/src/de/example/exampletdd/WeatherInformationCurrentDataActivity.java @@ -37,8 +37,8 @@ public class WeatherInformationCurrentDataActivity extends Activity { .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("Current weather data information"); - actionBar.setSubtitle(city + "," + country); + actionBar.setTitle(city + "," + country); + actionBar.setSubtitle("CURRENTLY"); } } diff --git a/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java b/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java index b122d8f..0fbe153 100644 --- a/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java +++ b/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java @@ -52,13 +52,6 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { 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, ""); - this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this.getActivity()); this.mWeatherServicePersistenceFile.removeCurrentWeatherData(); } @@ -88,16 +81,9 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { this.setHasOptionsMenu(false); - 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); - + this.setListShownNoAnimation(false); } @Override @@ -125,28 +111,9 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { if (currentWeatherData != null) { this.updateCurrentWeatherData(currentWeatherData); } else { - // 2.1 Empty list by default - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( - this.getActivity(), R.layout.weather_data_entry_list); - this.setListAdapter(adapter); - - // 2.2. Try to update weather data on display with remote - // information. + // 3. Try to update weather data on display with remote this.getRemoteCurrentWeatherInformation(); } - - - - // 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(); - // } } @Override @@ -297,6 +264,7 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { try { this.onPostExecuteThrowable(currentWeatherData); } catch (final IOException e) { + WeatherInformationCurrentDataFragment.this.setListShown(true); Log.e(TAG, "WeatherTask onPostExecute exception: ", e); final DialogFragment newFragment = ErrorDialogFragment .newInstance(R.string.error_dialog_generic_error); @@ -305,6 +273,7 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { "errorDialog"); } } else { + WeatherInformationCurrentDataFragment.this.setListShown(true); final DialogFragment newFragment = ErrorDialogFragment .newInstance(R.string.error_dialog_generic_error); newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(), @@ -325,16 +294,6 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { private CurrentWeatherData doInBackgroundThrowable(final Object... params) throws ClientProtocolException, MalformedURLException, URISyntaxException, JsonParseException, IOException { - // final SharedPreferences sharedPreferences = PreferenceManager - // .getDefaultSharedPreferences(WeatherInformationCurrentDataFragment.this - // .getActivity()); - // - // final String keyPreference = - // WeatherInformationCurrentDataFragment.this - // .getActivity().getString( - // R.string.weather_preferences_language_key); - // final String languagePreferenceValue = - // sharedPreferences.getString(keyPreference, ""); // 1. Coordinates final GeocodingData geocodingData = (GeocodingData) params[0]; diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java new file mode 100644 index 0000000..e118a3c --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataAdapter.java @@ -0,0 +1,223 @@ +package de.example.exampletdd.fragment.specific; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; +import de.example.exampletdd.R; + +public class WeatherCurrentDataAdapter extends ArrayAdapter { + private static final int FIRST = 0; + private static final int SECOND = 1; + private static final int THIRD = 2; + private static final int FOURTH = 3; + private final int[] resources; + + public WeatherCurrentDataAdapter(final Context context, final int[] resources) { + super(context, 0); + + this.resources = resources; + } + + + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + + final View view = this.getWorkingView(position, convertView); + final int viewType = this.getItemViewType(position); + + if (viewType == FIRST) { + + final ViewFirstHolder viewHolder = this.getViewFirstHolder(view); + final WeatherCurrentDataEntryFirst entry = (WeatherCurrentDataEntryFirst) this + .getItem(position); + viewHolder.picture.setImageBitmap(entry.getPicture()); + viewHolder.tempMax.setText(entry.getTempMax()); + viewHolder.tempMin.setText(entry.getTempMin()); + } else if (viewType == SECOND) { + final ViewSecondHolder viewHolder = this.getViewSecondHolder(view); + final WeatherCurrentDataEntrySecond entry = (WeatherCurrentDataEntrySecond) this + .getItem(position); + viewHolder.weatherDescription.setText(entry.getWeatherDescription()); + } else if (viewType == THIRD) { + final ViewThirdHolder viewHolder = this.getViewThirdHolder(view); + final WeatherCurrentDataEntryThird entry = (WeatherCurrentDataEntryThird) this + .getItem(position); + viewHolder.humidityValue.setText(entry.getHumidityValue()); + viewHolder.pressureValue.setText(entry.getPressureValue()); + viewHolder.rainValue.setText(entry.getRainValue()); + viewHolder.cloudsValue.setText(entry.getCloudsValue()); + viewHolder.windValue.setText(entry.getWindValue()); + } else if (viewType == FOURTH) { + final ViewFourthHolder viewHolder = this.getViewFourthHolder(view); + final WeatherCurrentDataEntryFourth entry = (WeatherCurrentDataEntryFourth) this + .getItem(position); + viewHolder.dayTemp.setText(entry.getDayTemp()); + viewHolder.morningTemp.setText(entry.getEveTemp()); + viewHolder.eveTemp.setText(entry.getEveTemp()); + viewHolder.nightTemp.setText(entry.getNightTemp()); + } + + return view; + } + + @Override + public int getItemViewType(final int position) { + int type = 0; + + if (position == 0) { + type = FIRST; + } else if (position == 1) { + type = SECOND; + } else if (position == 2) { + type = THIRD; + } else if (position == 3) { + type = FOURTH; + } + + return type; + } + + @Override + public int getViewTypeCount() { + return 4; + } + + private View getWorkingView(final int position, final View convertView) { + View workingView = null; + + if (convertView == null) { + final int viewType = this.getItemViewType(position); + final Context context = this.getContext(); + final LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + workingView = inflater.inflate(this.resources[viewType], null); + } else { + workingView = convertView; + } + + return workingView; + } + + private ViewFirstHolder getViewFirstHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewFirstHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewFirstHolder)) { + viewHolder = new ViewFirstHolder(); + + viewHolder.picture = (ImageView) workingView + .findViewById(R.id.weather_current_data_picture); + viewHolder.tempMax = (TextView) workingView + .findViewById(R.id.weather_current_data_temp_max); + viewHolder.tempMin = (TextView) workingView + .findViewById(R.id.weather_current_data_temp_min); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewFirstHolder) tag; + } + + return viewHolder; + } + + private ViewSecondHolder getViewSecondHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewSecondHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewSecondHolder)) { + viewHolder = new ViewSecondHolder(); + + viewHolder.weatherDescription = (TextView) workingView + .findViewById(R.id.weather_current_data_description); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewSecondHolder) tag; + } + + return viewHolder; + } + + private ViewThirdHolder getViewThirdHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewThirdHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewThirdHolder)) { + viewHolder = new ViewThirdHolder(); + + viewHolder.humidityValue = (TextView) workingView + .findViewById(R.id.weather_current_data_humidity_value); + viewHolder.pressureValue = (TextView) workingView + .findViewById(R.id.weather_current_data_pressure_value); + viewHolder.rainValue = (TextView) workingView + .findViewById(R.id.weather_current_data_rain_value); + viewHolder.cloudsValue = (TextView) workingView + .findViewById(R.id.weather_current_data_clouds_value); + viewHolder.windValue = (TextView) workingView + .findViewById(R.id.weather_current_data_wind_value); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewThirdHolder) tag; + } + + return viewHolder; + } + + private ViewFourthHolder getViewFourthHolder(final View workingView) { + final Object tag = workingView.getTag(); + ViewFourthHolder viewHolder = null; + + if ((null == tag) || !(tag instanceof ViewFourthHolder)) { + viewHolder = new ViewFourthHolder(); + + viewHolder.morningTemp = (TextView) workingView + .findViewById(R.id.weather_morn_temperature); + viewHolder.dayTemp = (TextView) workingView.findViewById(R.id.weather_day_temperature); + viewHolder.eveTemp = (TextView) workingView.findViewById(R.id.weather_eve_temperature); + viewHolder.nightTemp = (TextView) workingView + .findViewById(R.id.weather_night_temperature); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewFourthHolder) tag; + } + + return viewHolder; + } + + + private static class ViewFirstHolder { + public ImageView picture; + public TextView tempMax; + public TextView tempMin; + } + + private static class ViewSecondHolder { + public TextView weatherDescription; + } + + private static class ViewThirdHolder { + public TextView humidityValue; + public TextView pressureValue; + public TextView windValue; + public TextView rainValue; + public TextView cloudsValue; + } + + private static class ViewFourthHolder { + private TextView morningTemp; + private TextView dayTemp; + private TextView eveTemp; + private TextView nightTemp; + } +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java new file mode 100644 index 0000000..732e682 --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFirst.java @@ -0,0 +1,28 @@ +package de.example.exampletdd.fragment.specific; + +import android.graphics.Bitmap; + +public class WeatherCurrentDataEntryFirst { + private final Bitmap picture; + private final String tempMax; + private final String tempMin; + + public WeatherCurrentDataEntryFirst(final String tempMax, final String tempMin, + final Bitmap picture) { + this.tempMax = tempMax; + this.tempMin = tempMin; + this.picture = picture; + } + + public Bitmap getPicture() { + return this.picture; + } + + public String getTempMax() { + return this.tempMax; + } + + public String getTempMin() { + return this.tempMin; + } +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java new file mode 100644 index 0000000..4aa2e8d --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryFourth.java @@ -0,0 +1,33 @@ +package de.example.exampletdd.fragment.specific; + +public class WeatherCurrentDataEntryFourth { + private final String morningTemp; + private final String dayTemp; + private final String eveTemp; + private final String nightTemp; + + public WeatherCurrentDataEntryFourth(final String morningTemp, final String dayTemp, + final String eveTemp, final String nightTemp) { + this.morningTemp = morningTemp; + this.dayTemp = dayTemp; + this.eveTemp = eveTemp; + this.nightTemp = nightTemp; + } + + public String getMorningTemp() { + return this.morningTemp; + } + + public String getDayTemp() { + return this.dayTemp; + } + + public String getEveTemp() { + return this.eveTemp; + } + + public String getNightTemp() { + return this.nightTemp; + } + +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java new file mode 100644 index 0000000..ca6a073 --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntrySecond.java @@ -0,0 +1,14 @@ +package de.example.exampletdd.fragment.specific; + +public class WeatherCurrentDataEntrySecond { + private final String weatherDescription; + + public WeatherCurrentDataEntrySecond(final String weatherDescription) { + this.weatherDescription = weatherDescription; + } + + public String getWeatherDescription() { + return this.weatherDescription; + } + +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java new file mode 100644 index 0000000..62d2f01 --- /dev/null +++ b/src/de/example/exampletdd/fragment/specific/WeatherCurrentDataEntryThird.java @@ -0,0 +1,39 @@ +package de.example.exampletdd.fragment.specific; + +public class WeatherCurrentDataEntryThird { + private final String humidityValue; + private final String pressureValue; + private final String windValue; + private final String rainValue; + private final String cloudsValue; + + public WeatherCurrentDataEntryThird(final String humidityValue, final String pressureValue, + final String windValue, final String rainValue, final String cloudsValue) { + this.humidityValue = humidityValue; + this.pressureValue = pressureValue; + this.windValue = windValue; + this.rainValue = rainValue; + this.cloudsValue = cloudsValue; + } + + public String getHumidityValue() { + return this.humidityValue; + } + + public String getPressureValue() { + return this.pressureValue; + } + + public String getWindValue() { + return this.windValue; + } + + public String getRainValue() { + return this.rainValue; + } + + public String getCloudsValue() { + return this.cloudsValue; + } + +} diff --git a/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java b/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java index aecda8a..5e34202 100644 --- a/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java +++ b/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java @@ -4,21 +4,22 @@ import java.io.IOException; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; import java.util.Locale; import android.app.DialogFragment; import android.app.ListFragment; import android.content.SharedPreferences; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.os.Bundle; import android.preference.PreferenceManager; import android.widget.ListView; import de.example.exampletdd.R; import de.example.exampletdd.activityinterface.GetWeather; import de.example.exampletdd.fragment.ErrorDialogFragment; +import de.example.exampletdd.fragment.overview.IconsList; import de.example.exampletdd.model.forecastweather.ForecastWeatherData; import de.example.exampletdd.service.WeatherServicePersistenceFile; @@ -41,13 +42,6 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile( this.getActivity()); - - // final SharedPreferences sharedPreferences = PreferenceManager - // .getDefaultSharedPreferences(this.getActivity()); - // final String keyPreference = this.getResources().getString( - // R.string.weather_preferences_language_key); - // this.mLanguage = sharedPreferences.getString( - // keyPreference, ""); } @Override @@ -57,14 +51,9 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme final ListView listWeatherView = this.getListView(); listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE); - 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); + this.setListShownNoAnimation(false); if (savedInstanceState != null) { // Restore state @@ -121,11 +110,16 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme .getDefault()); tempFormatter.applyPattern("#####.#####"); final double tempUnits = this.mIsFahrenheit ? 0 : 273.15; + final String symbol = this.mIsFahrenheit ? "ºF" : "ºC"; - final List entries = this.createEmptyEntriesList(); - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( - this.getActivity(), R.layout.weather_data_entry_list); + final int[] layouts = new int[4]; + layouts[0] = R.layout.weather_current_data_entry_first; + layouts[1] = R.layout.weather_current_data_entry_second; + layouts[2] = R.layout.weather_current_data_entry_third; + layouts[3] = R.layout.weather_current_data_entry_fourth; + final WeatherCurrentDataAdapter adapter = new WeatherCurrentDataAdapter(this.getActivity(), + layouts); final de.example.exampletdd.model.forecastweather.List forecast = forecastWeatherData @@ -138,42 +132,99 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme final Date date = calendar.getTime(); this.getActivity().getActionBar().setSubtitle(dayFormatter.format(date).toUpperCase()); - if (forecast.getWeather().size() > 0) { - entries.set(0, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_description), - forecast.getWeather().get(0).getDescription())); - } - - if (forecast.getTemp().getDay() != null) { - double conversion = (Double) forecast.getTemp().getDay(); - conversion = conversion - tempUnits; - entries.set(1, new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem), - tempFormatter.format(conversion))); - } + String tempMax = ""; if (forecast.getTemp().getMax() != null) { double conversion = (Double) forecast.getTemp().getMax(); conversion = conversion - tempUnits; - entries.set(2, new WeatherSpecificDataEntry( - this.getString(R.string.text_field_tem_max), tempFormatter.format(conversion))); + tempMax = tempFormatter.format(conversion) + symbol; } - + String tempMin = ""; if (forecast.getTemp().getMin() != null) { double conversion = (Double) forecast.getTemp().getMin(); conversion = conversion - tempUnits; - entries.set(3, new WeatherSpecificDataEntry( - this.getString(R.string.text_field_tem_min), tempFormatter.format(conversion))); + tempMin = tempFormatter.format(conversion) + symbol; + } + Bitmap picture; + if ((forecast.getWeather().size() > 0) && (forecast.getWeather().get(0).getIcon() != null) + && (IconsList.getIcon(forecast.getWeather().get(0).getIcon()) != null)) { + final String icon = forecast.getWeather().get(0).getIcon(); + picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon) + .getResourceDrawable()); + } else { + picture = BitmapFactory.decodeResource(this.getResources(), + R.drawable.weather_severe_alert); } + final WeatherCurrentDataEntryFirst entryFirst = new WeatherCurrentDataEntryFirst(tempMax, + tempMin, picture); + adapter.add(entryFirst); + String description = "no description available"; + if (forecast.getWeather().size() > 0) { + description = forecast.getWeather().get(0).getDescription(); + } + final WeatherCurrentDataEntrySecond entrySecond = new WeatherCurrentDataEntrySecond( + description); + adapter.add(entrySecond); + + + String humidityValue = ""; + if (forecast.getHumidity() != null) { + final double conversion = (Double) forecast.getHumidity(); + humidityValue = tempFormatter.format(conversion); + } + String pressureValue = ""; + if (forecast.getPressure() != null) { + final double conversion = (Double) forecast.getPressure(); + pressureValue = tempFormatter.format(conversion); + } + String windValue = ""; + if (forecast.getSpeed() != null) { + final double conversion = (Double) forecast.getSpeed(); + windValue = tempFormatter.format(conversion); + } + String rainValue = ""; + if (forecast.getRain() != null) { + final double conversion = (Double) forecast.getRain(); + rainValue = tempFormatter.format(conversion); + } + String cloudsValue = ""; + if (forecast.getRain() != null) { + final double conversion = (Double) forecast.getClouds(); + cloudsValue = tempFormatter.format(conversion); + } + final WeatherCurrentDataEntryThird entryThird = new WeatherCurrentDataEntryThird( + humidityValue, pressureValue, windValue, rainValue, cloudsValue); + adapter.add(entryThird); - if (forecast.getClouds() != null) { - final double cloudiness = (Double) forecast.getClouds(); - entries.set(6, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_cloudiness), - tempFormatter.format(cloudiness))); + String tempDay = ""; + if (forecast.getTemp().getDay() != null) { + double conversion = (Double) forecast.getTemp().getDay(); + conversion = conversion - tempUnits; + tempDay = tempFormatter.format(conversion) + symbol; + } + String tempMorn = ""; + if (forecast.getTemp().getMorn() != null) { + double conversion = (Double) forecast.getTemp().getMorn(); + conversion = conversion - tempUnits; + tempMorn = tempFormatter.format(conversion) + symbol; + } + String tempEve = ""; + if (forecast.getTemp().getEve() != null) { + double conversion = (Double) forecast.getTemp().getEve(); + conversion = conversion - tempUnits; + tempEve = tempFormatter.format(conversion) + symbol; } + String tempNight = ""; + if (forecast.getTemp().getNight() != null) { + double conversion = (Double) forecast.getTemp().getNight(); + conversion = conversion - tempUnits; + tempNight = tempFormatter.format(conversion) + symbol; + } + final WeatherCurrentDataEntryFourth entryFourth = new WeatherCurrentDataEntryFourth( + tempMorn, tempDay, tempEve, tempNight); + adapter.add(entryFourth); - adapter.addAll(entries); this.setListAdapter(adapter); } @@ -198,46 +249,10 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme // 2. Update weather data on display. - final ForecastWeatherData forecastWeatherData = this.mWeatherServicePersistenceFile .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); } - - - - // 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(); - // } - } - - private List createEmptyEntriesList() { - final List entries = new ArrayList(); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_description), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem_max), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem_min), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_sun_rise), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_sun_set), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_cloudiness), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_rain_time), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_rain_amount), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_wind_speed), null)); - entries.add(new WeatherSpecificDataEntry(this.getString(R.string.text_field_humidity), null)); - - return entries; } } diff --git a/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java b/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java index 0b9491d..a354c92 100644 --- a/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java +++ b/src/de/example/exampletdd/fragment/specific/WeatherSpecificDataAdapter.java @@ -7,7 +7,6 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import de.example.exampletdd.R; -import de.example.exampletdd.fragment.specific.WeatherSpecificDataEntry; public class WeatherSpecificDataAdapter extends ArrayAdapter { private final int resource; -- 2.1.4