From 40d7bf3c77021218ac48cd1cfbecc7e12020885f Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Wed, 2 Apr 2014 21:41:43 +0200 Subject: [PATCH] No time for comments --- res/drawable-hdpi/ic_action_import_export.png | Bin 0 -> 457 bytes res/drawable-hdpi/ic_action_settings.png | Bin 0 -> 807 bytes res/drawable-mdpi/ic_action_import_export.png | Bin 0 -> 325 bytes res/drawable-mdpi/ic_action_settings.png | Bin 0 -> 550 bytes res/drawable-xhdpi/ic_action_import_export.png | Bin 0 -> 580 bytes res/drawable-xhdpi/ic_action_settings.png | Bin 0 -> 1124 bytes res/drawable-xxhdpi/ic_action_import_export.png | Bin 0 -> 758 bytes res/drawable-xxhdpi/ic_action_settings.png | Bin 0 -> 1661 bytes res/menu/weather_main_menu.xml | 16 +++- res/values/strings.xml | 5 +- .../exampletdd/WeatherInformationActivity.java | 12 +-- .../activityinterface/OnClickButtons.java | 3 +- .../fragment/WeatherInformationDataFragment.java | 93 ++++++++++++++++----- .../WeatherInformationDataFragmentDeprecated.java | 2 +- 14 files changed, 99 insertions(+), 32 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_import_export.png create mode 100644 res/drawable-hdpi/ic_action_settings.png create mode 100644 res/drawable-mdpi/ic_action_import_export.png create mode 100644 res/drawable-mdpi/ic_action_settings.png create mode 100644 res/drawable-xhdpi/ic_action_import_export.png create mode 100644 res/drawable-xhdpi/ic_action_settings.png create mode 100644 res/drawable-xxhdpi/ic_action_import_export.png create mode 100644 res/drawable-xxhdpi/ic_action_settings.png diff --git a/res/drawable-hdpi/ic_action_import_export.png b/res/drawable-hdpi/ic_action_import_export.png new file mode 100644 index 0000000000000000000000000000000000000000..18c0fe7d63774763dd23a014a5bafb6aa2798b95 GIT binary patch literal 457 zcmV;)0XF`LP)L<49_M` zTZp}W_|W8mn8Qvt=e_{@KKas&+H7345D^@v+y~N{mFNnxOJDYZzrlL}16zkY+MO%ablgb15WwU^v5*K50U|&IhyW2_ zXeTZj*10J_$C*avfUi)x2dv4`wYhRGVaMXHUx4qt>keJBw&aaj2t=+#s703x`W&6G zP=m{U6?a73HCtg?z!=5;%Y2BtSjWmL#5vKeZr@v7MnUj`qR!uxH_Cn<-`08!J00FK z6GpOhrUeB2`zbe-C$%9Wvi0XiAP{(hrvL*0bYz4`Hhrth00000NkvXXu0mjf#6iL8 literal 0 HcmV?d00001 diff --git a/res/drawable-hdpi/ic_action_settings.png b/res/drawable-hdpi/ic_action_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..54eecded35495a5d6e6bf2ea5f68003aec682bd0 GIT binary patch literal 807 zcmV+?1K9kDP)(RCwC#S<7+TFc77D4hvukUH5EY;Tl!fNOv$F$$;0UCBz|LUcA)v)R>>tju zM2Qk5O7s9NreJ!z-Ik7}^J1~MerW(Cd`Z)rV|h;i4l&Prnm_?d&)SdJhs_P(=a&XR z=9AO3@@&aH{_(j0NU-lTZ3DJ8*gL-y)4>f*YZ~t~dKyYc6?|`OQ3rErS?lPx9n;(r z+WTj|M+GntT@2|Ec>uTz6I=r+AYhHZGwiuq0B#6`iVfh+ag!f6O5+3#t(cG*6IKH| zV!iS3x)6Xmnh%ih^?>lN5b!Sm6qY>&)>_>92D6O{oEb+0#O&x0$_TIRw;JhxCupO6 zL<>)W(dCbvrX+da zHAFmiQ%0c!1Zaft8&|=GaM=nFMvLpQ!jDR1xY1Ykskda^y|3EDniOmWU-;k~D*Wh7 zOpK50ZzXQ>91^>65!}2AVQ$?RnMMKNPGu}1B}lM3^Zxn&f4+FfWwuLclP*n9vm91Qcygpv^2f?Be9hDs(@gfd%)C*N;nPkPzMUo+FD@KobU0kw zIE9}vb?+4q{v$4~Qb9^fy!;ZRUKF)le_=44$rjF6*2UngF<6c)tJu literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_action_settings.png b/res/drawable-mdpi/ic_action_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..25c36db42c6128d7038fc7c684b299be7c66dee2 GIT binary patch literal 550 zcmV+>0@?kEP)q{gd6P_X zX7OEux~{vX%Li$IrIs}FeZL;N*M%eS8Atv`8jP zU!`JLwub=lbF6Q{5P;YWk$9tIfTATmy8}=>!1kA5yq6yTQ~)Rh&^Ox&u$}@0ND>Os zOEU{I_>`h5k?8%mAS(9f;e6oJwJ#C9lRh4uhy?L?s;8WMg(O;v9Ce7<_aJHGq&RX4vc53+DiCGD1UqCU$Uhby1%a>C3-s5A5l5L of+qpc$SHRPFv%ommtO$}002SWC@^W*^#A|>07*qoM6N<$g24Xmxc~qF literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_import_export.png b/res/drawable-xhdpi/ic_action_import_export.png new file mode 100644 index 0000000000000000000000000000000000000000..b247edafa412fa6e2059817b7f93e625239cec55 GIT binary patch literal 580 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+7@v8%IEGZ*dNb=_;9&y+*IfQ^t_G$%4pIe-0S%f8JCome zzH4DB@~=_9Q^>f45hxeb@KfsBffS*~Hzw(L*Qc9U7v{MCUKG1_iSMEVs)`Iu3LwNC zbp31Y28M(huC0ypSS-&Z{1AJ~oZDU|dxfLnAZv)0eEx-J2N@bZN`};xSRVd*N0edX z!v)(Nt<9gvKeG7urIO{0bWixE0!2BMwts&$uha|1A8kEk&0uuZH~L;(`|tOA85Nv= z{XBGBuH9#n(CNB*uU!ts{0%<2k;jh*pA{j{D~Rn;}!R$8Gw2`FWGxzu11_k-;oMg}Jd=Rk0VZ|8R_9n7eMlsd?)oUuvzF zRAF22`IXMb)r_L^^h>{{o>2I4MN#t7OQ*w32loG9{aU1HB3t+Vj0s0_SwOySe*A0; z-!eu13}OCn26b;!l~kOo5--1>dzvNH%Q`%D)0B#b literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_settings.png b/res/drawable-xhdpi/ic_action_settings.png new file mode 100644 index 0000000000000000000000000000000000000000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vNhWABQ%F<)pM^_2_bg*w z(W1v0b8_>Fv)lokxkfKGdED1^b(k%3Ovh<%m%sv{J6$XC_%h8lrXA%7;4Ga~alLBm zZbt_R&h||!Hg|2)2|N(L_Vt@XvE9N8gvz$AJ9|tzdaA*t_lny8cAwak8=CR({?{(a lpfl{ZELkB5s6pq4Py$222c{COsdvGt%G1@)Wt~$(699!TKx_a2 literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/ic_action_settings.png b/res/drawable-xxhdpi/ic_action_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..fe5fec471f17c23c4f274d2594361d5db6922869 GIT binary patch literal 1661 zcmV-@27>vCP)|sA)KjZ*#03Tp{faCz4eV)Z@O%#u9HB!sSNq<#TswhjA`fK%% z)FMJK7z_r3!C){L3$HDGAt^ z#-WWzCUdvt^T*y10E2(5eEkAKkP~{hS5rPe2eM3%eLRc*_j^?P2r}OYnE}^sQS z2A+hE)#f(H$?id03q*4EQa<-wLq-Z?89I*VsqB9pJOP$Fmw%ZEaGHhI=Lm#p@(;?y zofIKJ#FRiO7SxX12LW3LCn`Rc zKx3DLNt9d>-?YB(9Y~e^96}}FU}pAZOt z0xO7G_$pN0!aD>wRGZLpsQL(M1z2kTpYRSQb>C3}dNw0qjF6~ zV@eTDEhcm4LrC5T0F7EU?9T|pR=_1T8S4|;qNAiTw(9=R+LxTXo(b1!u=ZVB@^kXA z_kJ`H0IQ|?-jz=ob$uwW6B1hr%Lf5b!x&BD44VMRaI2=}Qlh9C@p5Kt2ZVFgR>_)Ipw#YYsqB>=Kr9Ydt8O+5@J zMXuD?6iWBW1U+;*>>O-vEvCMRLgvF5+CyXE9p&>o|yDqK8)&CV;epQ@~U zEbs^XGcZ3(BmqK;;1(1+wp0Yz7UZ7m?xFn;fj<x8e zJ{RqGz1kq_lXhCPlz`2*b@pLj(9neD8qplVQR-o43Snm3Wjb{WGlMX<(Ara6`1neF zS{L#qy}vZLhUlSYmz$m$LyYel;_iIZ23_NtY5`6*6K{8YCkE}5&mF)7m@a$A;{9FU zMsouFs^?KjTb~GswJ zeK`+p(rU($g7ZK5s0rlvvz3l_j=eh1P!lm9CL@GCJ}m)9$M$)M zW~Vm + + + + android:icon="@drawable/ic_action_settings" + android:showAsAction="ifRoom|withText"> diff --git a/res/values/strings.xml b/res/values/strings.xml index d0c9b0c..45d1148 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4,6 +4,7 @@ Weather Information Settings City,country + Get weather Get weather http://api.openweathermap.org/data/{0}/weather?lat={1}&lon={2} http://api.openweathermap.org/data/{0}/weather?q={1} @@ -19,7 +20,7 @@ Temperature: Min temperature: Max temperature: - Cloudiness: + Cloudiness in %: Rain time: Rain amount: Wind speed: @@ -28,7 +29,7 @@ Connection error timeout Impossible to receive weather data. Icon weather - Weather Information + City,country weather_preferences_units Fahrenheit Celsius diff --git a/src/de/example/exampletdd/WeatherInformationActivity.java b/src/de/example/exampletdd/WeatherInformationActivity.java index ae260ee..e693053 100644 --- a/src/de/example/exampletdd/WeatherInformationActivity.java +++ b/src/de/example/exampletdd/WeatherInformationActivity.java @@ -9,7 +9,6 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuItem; -import android.view.View; import de.example.exampletdd.activityinterface.ErrorMessage; import de.example.exampletdd.activityinterface.OnClickButtons; import de.example.exampletdd.fragment.ErrorDialogFragment; @@ -28,8 +27,8 @@ public class WeatherInformationActivity extends Activity implements ErrorMessage final ActionBar actionBar = this.getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO, ActionBar.DISPLAY_USE_LOGO); - // actionBar.setTitle(this.getResources().getString(R.string.header_action_bar)); + actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); + actionBar.setTitle(this.getString(R.string.header_action_bar)); actionBar.setDisplayHomeAsUpEnabled(true); // Better using xml files? How to deal with savedInstanceState with xml files? @@ -67,6 +66,9 @@ public class WeatherInformationActivity extends Activity implements ErrorMessage "de.example.exampletdd.WeatherInformationPreferencesActivity")); this.startActivity(intent); return true; + case R.id.weather_menu_get: + this.onClickGetWeather(); + return true; default: break; } @@ -81,8 +83,8 @@ public class WeatherInformationActivity extends Activity implements ErrorMessage newFragment.show(this.getFragmentManager(), "errorDialog"); } - public void onClickGetWeather(final View v) { - this.onclickButtons.onClickGetWeather(v); + public void onClickGetWeather() { + this.onclickButtons.onClickGetWeather(); } } diff --git a/src/de/example/exampletdd/activityinterface/OnClickButtons.java b/src/de/example/exampletdd/activityinterface/OnClickButtons.java index 0400afe..2206cc5 100644 --- a/src/de/example/exampletdd/activityinterface/OnClickButtons.java +++ b/src/de/example/exampletdd/activityinterface/OnClickButtons.java @@ -1,9 +1,8 @@ package de.example.exampletdd.activityinterface; -import android.view.View; public interface OnClickButtons { - public void onClickGetWeather(final View v); + public void onClickGetWeather(); } diff --git a/src/de/example/exampletdd/fragment/WeatherInformationDataFragment.java b/src/de/example/exampletdd/fragment/WeatherInformationDataFragment.java index 0dcf6db..502a807 100644 --- a/src/de/example/exampletdd/fragment/WeatherInformationDataFragment.java +++ b/src/de/example/exampletdd/fragment/WeatherInformationDataFragment.java @@ -8,12 +8,16 @@ import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; +import java.util.List; import org.apache.http.client.ClientProtocolException; import org.json.JSONException; import android.app.Fragment; import android.content.SharedPreferences; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.net.http.AndroidHttpClient; import android.os.AsyncTask; import android.os.Bundle; @@ -22,6 +26,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.ListView; import de.example.exampletdd.R; import de.example.exampletdd.activityinterface.ErrorMessage; @@ -33,7 +38,6 @@ import de.example.exampletdd.parser.JPOSWeatherParser; import de.example.exampletdd.service.WeatherService; public class WeatherInformationDataFragment extends Fragment implements OnClickButtons { - private WeatherDataAdapter mAdapter; private boolean isFahrenheit; @@ -53,28 +57,17 @@ public class WeatherInformationDataFragment extends Fragment implements OnClickB final ListView listWeatherView = (ListView) this.getActivity().findViewById( R.id.weather_data_list_view); - this.mAdapter = new WeatherDataAdapter(this.getActivity(), + final WeatherDataAdapter adapter = new WeatherDataAdapter(this.getActivity(), R.layout.weather_data_entry_list); - final Collection entries = new ArrayList(); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_description), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_tem), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_tem_max), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_tem_min), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_sun_rise), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_sun_set), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_cloudiness), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_rain_time), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_rain_amount), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_wind_speed), "")); - entries.add(new WeatherDataEntry(this.getString(R.string.text_field_humidity), "")); - - this.mAdapter.addAll(entries); - listWeatherView.setAdapter(this.mAdapter); + final Collection entries = createEmptyEntriesList(); + + adapter.addAll(entries); + listWeatherView.setAdapter(adapter); } @Override - public void onClickGetWeather(final View v) { + public void onClickGetWeather() { final IJPOSWeatherParser JPOSWeatherParser = new JPOSWeatherParser(); final WeatherService weatherService = new WeatherService( @@ -87,7 +80,7 @@ public class WeatherInformationDataFragment extends Fragment implements OnClickB final WeatherTask weatherTask = new WeatherTask(HTTPweatherClient, weatherService); - weatherTask.execute("London,uk"); + weatherTask.execute("Candeleda,spain"); } public void updateWeatherData(final WeatherData weatherData) { @@ -95,17 +88,58 @@ public class WeatherInformationDataFragment extends Fragment implements OnClickB final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss Z"); final double tempUnits = this.isFahrenheit ? 0 : 273.15; - if (weatherData.getWeather() != null) { + final List entries = createEmptyEntriesList(); + + final ListView listWeatherView = (ListView) this.getActivity().findViewById( + R.id.weather_data_list_view); + + final WeatherDataAdapter adapter = new WeatherDataAdapter(this.getActivity(), + R.layout.weather_data_entry_list); + if (weatherData.getWeather() != null) { + entries.set(0, new WeatherDataEntry(this.getString(R.string.text_field_description), weatherData.getWeather() + .getDescription())); + double conversion = weatherData.getMain().getTemp(); + conversion = conversion - tempUnits; + entries.set(1, new WeatherDataEntry(this.getString(R.string.text_field_tem), tempFormatter.format(conversion))); + conversion = weatherData.getMain().getMaxTemp(); + conversion = conversion - tempUnits; + entries.set(2, new WeatherDataEntry(this.getString(R.string.text_field_tem_max), tempFormatter.format(conversion))); + conversion = weatherData.getMain().getMinTemp(); + conversion = conversion - tempUnits; + entries.set(3, new WeatherDataEntry(this.getString(R.string.text_field_tem_min), tempFormatter.format(conversion))); } if (weatherData.getSystem() != null) { + long unixTime = weatherData.getSystem().getSunRiseTime(); + Date unixDate = new Date(unixTime * 1000L); + String dateFormatUnix = dateFormat.format(unixDate); + entries.set(4, new WeatherDataEntry(this.getString(R.string.text_field_sun_rise), dateFormatUnix)); + + unixTime = weatherData.getSystem().getSunSetTime(); + unixDate = new Date(unixTime * 1000L); + dateFormatUnix = dateFormat.format(unixDate); + entries.set(5, new WeatherDataEntry(this.getString(R.string.text_field_sun_set), dateFormatUnix)); + } + if (weatherData.getClouds() != null) { + final double cloudiness = weatherData.getClouds().getCloudiness(); + entries.set(6, new WeatherDataEntry(this.getString(R.string.text_field_cloudiness), tempFormatter.format(cloudiness))); } if (weatherData.getIconData() != null) { - + final Bitmap icon = BitmapFactory.decodeByteArray( + weatherData.getIconData(), 0, + weatherData.getIconData().length); + final ImageView imageIcon = (ImageView) getActivity().findViewById(R.id.weather_picture); + imageIcon.setImageBitmap(icon); } + + + + listWeatherView.setAdapter(null); + adapter.addAll(entries); + listWeatherView.setAdapter(adapter); } @Override @@ -212,4 +246,21 @@ public class WeatherInformationDataFragment extends Fragment implements OnClickB return weatherData; } } + + private List createEmptyEntriesList() { + final List entries = new ArrayList(); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_description), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_tem), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_tem_max), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_tem_min), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_sun_rise), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_sun_set), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_cloudiness), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_rain_time), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_rain_amount), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_wind_speed), null)); + entries.add(new WeatherDataEntry(this.getString(R.string.text_field_humidity), null)); + + return entries; + } } diff --git a/src/de/example/exampletdd/fragment/WeatherInformationDataFragmentDeprecated.java b/src/de/example/exampletdd/fragment/WeatherInformationDataFragmentDeprecated.java index 939ec12..8322661 100644 --- a/src/de/example/exampletdd/fragment/WeatherInformationDataFragmentDeprecated.java +++ b/src/de/example/exampletdd/fragment/WeatherInformationDataFragmentDeprecated.java @@ -64,7 +64,7 @@ public class WeatherInformationDataFragmentDeprecated extends Fragment implement } @Override - public void onClickGetWeather(final View v) { + public void onClickGetWeather() { final IJPOSWeatherParser JPOSWeatherParser = new JPOSWeatherParser(); final WeatherService weatherService = new WeatherService( -- 2.1.4