From 5be284d8450cbeec06875ede228f7ebba39379e9 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Sun, 20 Apr 2014 18:08:14 +0200 Subject: [PATCH] Weather app android: current data information. --- Android/WeatherInformation/gen/.gitignore | 1 + .../res/layout/weather_current_data.xml | 8 - .../layout/weather_current_data_entry_fifth.xml | 456 +++++++++++++++++++++ .../layout/weather_current_data_entry_fourth.xml | 62 +-- .../layout/weather_current_data_entry_third.xml | 261 ++++++------ .../current/WeatherCurrentDataAdapter.java | 204 +++++++++ .../current/WeatherCurrentDataEntryFifth.java | 71 ++++ .../current/WeatherCurrentDataEntryFirst.java | 28 ++ .../current/WeatherCurrentDataEntrySecond.java | 14 + .../WeatherInformationCurrentDataFragment.java | 157 +++---- .../WeatherInformationOverviewFragment.java | 22 +- .../WeatherInformationSpecificDataFragment.java | 4 + 12 files changed, 1022 insertions(+), 266 deletions(-) create mode 100644 Android/WeatherInformation/res/layout/weather_current_data_entry_fifth.xml create mode 100644 Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataAdapter.java create mode 100644 Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFifth.java create mode 100644 Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFirst.java create mode 100644 Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntrySecond.java diff --git a/Android/WeatherInformation/gen/.gitignore b/Android/WeatherInformation/gen/.gitignore index d4ffb9e..b6c80c1 100644 --- a/Android/WeatherInformation/gen/.gitignore +++ b/Android/WeatherInformation/gen/.gitignore @@ -1,2 +1,3 @@ /com /de +/.gitignore diff --git a/Android/WeatherInformation/res/layout/weather_current_data.xml b/Android/WeatherInformation/res/layout/weather_current_data.xml index 0f581a6..f4b3aad 100644 --- a/Android/WeatherInformation/res/layout/weather_current_data.xml +++ b/Android/WeatherInformation/res/layout/weather_current_data.xml @@ -9,14 +9,6 @@ tools:context="de.example.exampletdd.WeatherInformationCurrentDataActivity" tools:ignore="MergeRootFrame" > - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/WeatherInformation/res/layout/weather_current_data_entry_fourth.xml b/Android/WeatherInformation/res/layout/weather_current_data_entry_fourth.xml index 19d3488..d5a3207 100644 --- a/Android/WeatherInformation/res/layout/weather_current_data_entry_fourth.xml +++ b/Android/WeatherInformation/res/layout/weather_current_data_entry_fourth.xml @@ -15,18 +15,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - @@ -51,6 +38,7 @@ android:textAlignment="center" android:gravity="center" android:layout_alignParentTop="true" + android:layout_centerInParent="true" android:textAppearance="?android:attr/textAppearanceMedium" /> @@ -60,17 +48,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - @@ -92,6 +68,7 @@ android:layout_width="140dp" android:layout_height="wrap_content" android:layout_alignParentTop="true" + android:layout_centerInParent="true" android:gravity="center" android:selectAllOnFocus="true" android:text="DAY" @@ -109,17 +86,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - + @@ -143,6 +109,7 @@ android:text="EVENING" android:textColor="@color/weather_time_of_day_color_title" android:textAlignment="center" + android:layout_centerInParent="true" android:gravity="center" android:layout_alignParentTop="true" android:textAppearance="?android:attr/textAppearanceMedium" /> @@ -155,17 +122,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - @@ -191,6 +146,7 @@ android:textAlignment="center" android:gravity="center" android:layout_alignParentTop="true" + android:layout_centerInParent="true" android:textAppearance="?android:attr/textAppearanceMedium" /> diff --git a/Android/WeatherInformation/res/layout/weather_current_data_entry_third.xml b/Android/WeatherInformation/res/layout/weather_current_data_entry_third.xml index 9f7094c..fa78a65 100644 --- a/Android/WeatherInformation/res/layout/weather_current_data_entry_third.xml +++ b/Android/WeatherInformation/res/layout/weather_current_data_entry_third.xml @@ -6,25 +6,40 @@ android:layout_gravity="center" android:orientation="vertical" > - + + + + + + - @@ -35,9 +50,9 @@ android:text="83" android:layout_gravity="left" android:gravity="left" - android:layout_toRightOf="@+id/weather_current_data_humidity" - android:textAlignment="center" + android:textAlignment="textStart" android:layout_marginTop="5dp" + android:layout_marginBottom="5dp" android:textAppearance="?android:attr/textAppearanceSmall" android:textStyle="normal" /> @@ -49,67 +64,20 @@ android:text="%" android:layout_gravity="left" android:gravity="left" - android:textAlignment="center" - android:layout_toRightOf="@+id/weather_current_data_humidity_value" - android:paddingTop="5dp" - android:textAppearance="?android:attr/textAppearanceSmall" - android:textStyle="bold" /> - - - - - - - - - - - - - - - - - - + + + + @@ -134,11 +99,9 @@ android:text="1.24" android:layout_gravity="left" android:gravity="left" - android:textAlignment="center" - android:layout_toRightOf="@+id/weather_current_data_rain" - android:paddingTop="20dp" - android:paddingBottom="20dp" android:layout_marginTop="5dp" + android:layout_marginBottom="5dp" + android:textAlignment="textStart" android:textAppearance="?android:attr/textAppearanceSmall" android:textStyle="normal" /> @@ -150,48 +113,90 @@ android:text=" mm 3h" android:layout_gravity="left" android:gravity="left" - android:textAlignment="center" - android:layout_toRightOf="@+id/weather_current_data_rain_value" - android:paddingTop="20dp" - android:paddingRight="20dp" - android:paddingBottom="20dp" android:layout_marginTop="5dp" + android:layout_marginBottom="5dp" + android:layout_marginRight="5dp" + android:textAlignment="textStart" android:textAppearance="?android:attr/textAppearanceSmall" android:textStyle="bold" /> - - - + + + + + + + - + + + + + + + + + - + + + + + + + + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center_horizontal" + android:paddingBottom="20dp" + android:orientation="horizontal" > @@ -243,10 +262,9 @@ android:text="1036.05" android:layout_gravity="left" android:gravity="left" - android:textAlignment="center" - android:paddingTop="20dp" - android:paddingBottom="20dp" + android:textAlignment="textStart" android:layout_marginTop="5dp" + android:layout_marginBottom="5dp" android:textAppearance="?android:attr/textAppearanceSmall" android:textStyle="normal" /> @@ -258,11 +276,10 @@ android:text=" hpa" android:layout_gravity="left" android:gravity="left" - android:textAlignment="center" - android:paddingTop="20dp" - android:paddingRight="20dp" - android:paddingBottom="20dp" + android:textAlignment="textStart" android:layout_marginTop="5dp" + android:layout_marginBottom="5dp" + android:layout_marginRight="5dp" android:textAppearance="?android:attr/textAppearanceSmall" android:textStyle="bold" /> diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataAdapter.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataAdapter.java new file mode 100644 index 0000000..78301bd --- /dev/null +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataAdapter.java @@ -0,0 +1,204 @@ +package de.example.exampletdd.fragment.current; + +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 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 WeatherCurrentDataEntryFifth entry = (WeatherCurrentDataEntryFifth) 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()); + viewHolder.sunRiseTime.setText(entry.getSunRiseTime()); + viewHolder.sunSetTime.setText(entry.getSunSetTime()); + viewHolder.feelsLike.setText(entry.getFeelsLike()); + viewHolder.snowValue.setText(entry.getSnowValue()); + viewHolder.feelsLikeUnits.setText(entry.getFeelsLikeUnits()); + } + + 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; + } + + return type; + } + + @Override + public int getViewTypeCount() { + return 3; + } + + 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_now_data_humidity_value); + viewHolder.pressureValue = (TextView) workingView + .findViewById(R.id.weather_current_now_data_pressure_value); + viewHolder.rainValue = (TextView) workingView + .findViewById(R.id.weather_current_now_data_rain_value); + viewHolder.cloudsValue = (TextView) workingView + .findViewById(R.id.weather_current_now_data_clouds_value); + viewHolder.windValue = (TextView) workingView + .findViewById(R.id.weather_current_now_data_wind_value); + viewHolder.cloudsValue = (TextView) workingView + .findViewById(R.id.weather_current_now_data_clouds_value); + viewHolder.snowValue = (TextView) workingView + .findViewById(R.id.weather_current_now_data_snow_value); + viewHolder.sunRiseTime = (TextView) workingView + .findViewById(R.id.weather_current_now_data_sunrise_value); + viewHolder.sunSetTime = (TextView) workingView + .findViewById(R.id.weather_current_now_data_sunset_value); + viewHolder.feelsLike = (TextView) workingView + .findViewById(R.id.weather_current_now_data_feelslike_value); + viewHolder.feelsLikeUnits = (TextView) workingView + .findViewById(R.id.weather_current_now_data_feelslike_units); + + workingView.setTag(viewHolder); + + } else { + viewHolder = (ViewThirdHolder) 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; + public TextView snowValue; + public TextView sunRiseTime; + public TextView sunSetTime; + public TextView feelsLike; + public TextView feelsLikeUnits; + } +} diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFifth.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFifth.java new file mode 100644 index 0000000..2909624 --- /dev/null +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFifth.java @@ -0,0 +1,71 @@ +package de.example.exampletdd.fragment.current; + +public class WeatherCurrentDataEntryFifth { + private final String sunRiseTime; + private final String sunSetTime; + private final String humidityValue; + private final String pressureValue; + private final String windValue; + private final String rainValue; + private final String cloudsValue; + private final String feelsLike; + private final String feelsLikeUnits; + private final String snowValue; + + public WeatherCurrentDataEntryFifth(final String sunRiseTime, final String sunSetTime, + final String humidityValue, final String pressureValue, final String windValue, + final String rainValue, final String feelsLike, final String feelsLikeUnits, + final String snowValue, + final String cloudsValue) { + this.sunRiseTime = sunRiseTime; + this.sunSetTime = sunSetTime; + this.humidityValue = humidityValue; + this.pressureValue = pressureValue; + this.windValue = windValue; + this.rainValue = rainValue; + this.feelsLike = feelsLike; + this.feelsLikeUnits = feelsLikeUnits; + this.snowValue = snowValue; + this.cloudsValue = cloudsValue; + } + + public String getSunRiseTime() { + return this.sunRiseTime; + } + + public String getSunSetTime() { + return this.sunSetTime; + } + + public String getFeelsLike() { + return this.feelsLike; + } + + public String getFeelsLikeUnits() { + return this.feelsLikeUnits; + } + + 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; + } + + public String getSnowValue() { + return this.snowValue; + } +} diff --git a/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFirst.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFirst.java new file mode 100644 index 0000000..67d0463 --- /dev/null +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntryFirst.java @@ -0,0 +1,28 @@ +package de.example.exampletdd.fragment.current; + +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/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntrySecond.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntrySecond.java new file mode 100644 index 0000000..1d3222d --- /dev/null +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherCurrentDataEntrySecond.java @@ -0,0 +1,14 @@ +package de.example.exampletdd.fragment.current; + +public class WeatherCurrentDataEntrySecond { + private final String weatherDescription; + + public WeatherCurrentDataEntrySecond(final String weatherDescription) { + this.weatherDescription = weatherDescription; + } + + public String getWeatherDescription() { + return this.weatherDescription; + } + +} 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 0fbe153..7c63d53 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java @@ -8,10 +8,8 @@ import java.net.URL; 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 org.apache.http.client.ClientProtocolException; @@ -26,7 +24,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; -import android.widget.ImageView; import android.widget.ListView; import com.fasterxml.jackson.core.JsonParseException; @@ -34,8 +31,7 @@ import com.fasterxml.jackson.core.JsonParseException; import de.example.exampletdd.R; import de.example.exampletdd.fragment.ErrorDialogFragment; import de.example.exampletdd.fragment.ProgressDialogFragment; -import de.example.exampletdd.fragment.specific.WeatherSpecificDataAdapter; -import de.example.exampletdd.fragment.specific.WeatherSpecificDataEntry; +import de.example.exampletdd.fragment.overview.IconsList; import de.example.exampletdd.httpclient.CustomHTTPClient; import de.example.exampletdd.model.GeocodingData; import de.example.exampletdd.model.currentweather.CurrentWeatherData; @@ -139,72 +135,111 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { Locale.getDefault()); final double tempUnits = this.mIsFahrenheit ? 0 : 273.15; + final String symbol = this.mIsFahrenheit ? "ºF" : "ºC"; - final List entries = this.createEmptyEntriesList(); + final int[] layouts = new int[3]; + 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_fifth; + final WeatherCurrentDataAdapter adapter = new WeatherCurrentDataAdapter(this.getActivity(), + layouts); - final WeatherSpecificDataAdapter adapter = new WeatherSpecificDataAdapter( - this.getActivity(), R.layout.weather_data_entry_list); - - if (currentWeatherData.getWeather().size() > 0) { - entries.set(0, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_description), - currentWeatherData.getWeather().get(0).getDescription())); - } - - if (currentWeatherData.getMain().getTemp() != null) { - double conversion = (Double) currentWeatherData.getMain().getTemp(); - conversion = conversion - tempUnits; - entries.set(1, new WeatherSpecificDataEntry(this.getString(R.string.text_field_tem), - tempFormatter.format(conversion))); - } + String tempMax = ""; if (currentWeatherData.getMain().getTemp_max() != null) { double conversion = (Double) currentWeatherData.getMain().getTemp_max(); conversion = conversion - tempUnits; - entries.set(2, new WeatherSpecificDataEntry( - this.getString(R.string.text_field_tem_max), tempFormatter.format(conversion))); + tempMax = tempFormatter.format(conversion) + symbol; } - - if (currentWeatherData.getMain().getTemp_max() != null) { + String tempMin = ""; + if (currentWeatherData.getMain().getTemp_min() != null) { double conversion = (Double) currentWeatherData.getMain().getTemp_min(); 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 ((currentWeatherData.getWeather().size() > 0) + && (currentWeatherData.getWeather().get(0).getIcon() != null) + && (IconsList.getIcon(currentWeatherData.getWeather().get(0).getIcon()) != null)) { + final String icon = currentWeatherData.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 (currentWeatherData.getWeather().size() > 0) { + description = currentWeatherData.getWeather().get(0).getDescription(); + } + final WeatherCurrentDataEntrySecond entrySecond = new WeatherCurrentDataEntrySecond( + description); + adapter.add(entrySecond); + + String humidityValue = ""; + if ((currentWeatherData.getMain() != null) + && (currentWeatherData.getMain().getHumidity() != null)) { + final double conversion = (Double) currentWeatherData.getMain().getHumidity(); + humidityValue = tempFormatter.format(conversion); + } + String pressureValue = ""; + if ((currentWeatherData.getMain() != null) + && (currentWeatherData.getMain().getPressure() != null)) { + final double conversion = (Double) currentWeatherData.getMain().getPressure(); + pressureValue = tempFormatter.format(conversion); + } + String windValue = ""; + if ((currentWeatherData.getWind() != null) + && (currentWeatherData.getWind().getSpeed() != null)) { + final double conversion = (Double) currentWeatherData.getWind().getSpeed(); + windValue = tempFormatter.format(conversion); + } + String rainValue = ""; + if ((currentWeatherData.getRain() != null) + && (currentWeatherData.getRain().get3h() != null)) { + final double conversion = (Double) currentWeatherData.getRain().get3h(); + rainValue = tempFormatter.format(conversion); + } + String cloudsValue = ""; + if ((currentWeatherData.getClouds() != null) + && (currentWeatherData.getClouds().getAll() != null)) { + final double conversion = (Double) currentWeatherData.getClouds().getAll(); + cloudsValue = tempFormatter.format(conversion); + } + String snowValue = ""; + if ((currentWeatherData.getSnow() != null) + && (currentWeatherData.getSnow().get3h() != null)) { + final double conversion = (Double) currentWeatherData.getSnow().get3h(); + snowValue = tempFormatter.format(conversion); + } + String feelsLike = ""; + if (currentWeatherData.getMain().getTemp() != null) { + double conversion = (Double) currentWeatherData.getMain().getTemp(); + conversion = conversion - tempUnits; + feelsLike = tempFormatter.format(conversion); + } + String sunRiseTime = ""; if (currentWeatherData.getSys().getSunrise() != null) { final long unixTime = (Long) currentWeatherData.getSys().getSunrise(); final Date unixDate = new Date(unixTime * 1000L); - final String dateFormatUnix = dateFormat.format(unixDate); - entries.set(4, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_sun_rise), - dateFormatUnix)); + sunRiseTime = dateFormat.format(unixDate); } - + String sunSetTime = ""; if (currentWeatherData.getSys().getSunset() != null) { final long unixTime = (Long) currentWeatherData.getSys().getSunset(); final Date unixDate = new Date(unixTime * 1000L); - final String dateFormatUnix = dateFormat.format(unixDate); - entries.set(5, new WeatherSpecificDataEntry( - this.getString(R.string.text_field_sun_set), dateFormatUnix)); + sunSetTime = dateFormat.format(unixDate); } + final WeatherCurrentDataEntryFifth entryFifth = new WeatherCurrentDataEntryFifth( + sunRiseTime, sunSetTime, humidityValue, pressureValue, windValue, rainValue, + feelsLike, symbol, snowValue, cloudsValue); + adapter.add(entryFifth); - if (currentWeatherData.getClouds().getAll() != null) { - final double cloudiness = (Double) currentWeatherData.getClouds().getAll(); - entries.set(6, - new WeatherSpecificDataEntry(this.getString(R.string.text_field_cloudiness), - tempFormatter.format(cloudiness))); - } - if (currentWeatherData.getIconData() != null) { - final Bitmap icon = BitmapFactory.decodeByteArray(currentWeatherData.getIconData(), 0, - currentWeatherData.getIconData().length); - final ImageView imageIcon = (ImageView) this.getActivity().findViewById( - R.id.weather_picture); - imageIcon.setImageBitmap(icon); - } - - adapter.addAll(entries); this.setListAdapter(adapter); } @@ -343,26 +378,4 @@ public class WeatherInformationCurrentDataFragment extends ListFragment { weatherTask.execute(geocodingData); } } - - 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/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java index 9d4a579..a9c2e77 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java @@ -26,6 +26,7 @@ import android.graphics.BitmapFactory; import android.net.http.AndroidHttpClient; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Parcelable; import android.preference.PreferenceManager; import android.util.Log; import android.view.View; @@ -50,6 +51,7 @@ public class WeatherInformationOverviewFragment extends ListFragment implements private boolean mIsFahrenheit; private String mDayForecast; private WeatherServicePersistenceFile mWeatherServicePersistenceFile; + private Parcelable mListState; @Override public void onCreate(final Bundle savedInstanceState) { @@ -87,6 +89,8 @@ public class WeatherInformationOverviewFragment extends ListFragment implements newFragment.show(this.getFragmentManager(), "errorDialog"); } } + + this.mListState = savedInstanceState.getParcelable("ListState"); } this.setHasOptionsMenu(false); @@ -130,6 +134,9 @@ public class WeatherInformationOverviewFragment extends ListFragment implements savedInstanceState.putSerializable("ForecastWeatherData", forecastWeatherData); } + this.mListState = this.getListView().onSaveInstanceState(); + savedInstanceState.putParcelable("ListState", this.mListState); + super.onSaveInstanceState(savedInstanceState); } @@ -250,7 +257,10 @@ public class WeatherInformationOverviewFragment extends ListFragment implements // 3. Update forecast weather data on display. final ForecastWeatherData forecastWeatherData = this.mWeatherServicePersistenceFile .getForecastWeatherData(); - if (forecastWeatherData != null) { + if ((this.mListState != null) && (forecastWeatherData != null)) { + this.updateForecastWeatherData(forecastWeatherData); + this.getListView().onRestoreInstanceState(this.mListState); + } else if (forecastWeatherData != null) { this.updateForecastWeatherData(forecastWeatherData); } @@ -336,16 +346,6 @@ public class WeatherInformationOverviewFragment extends ListFragment implements private ForecastWeatherData doInBackgroundThrowable(final Object... params) throws ClientProtocolException, MalformedURLException, URISyntaxException, JsonParseException, IOException { - // final SharedPreferences sharedPreferences = PreferenceManager - // .getDefaultSharedPreferences(WeatherInformationOverviewFragment.this - // .getActivity()); - // - // final String keyPreference = - // WeatherInformationOverviewFragment.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/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java b/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java index 5e34202..3b1ed4b 100644 --- a/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java +++ b/Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java @@ -70,6 +70,8 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme newFragment.show(this.getFragmentManager(), "errorDialog"); } } + + this.mChosenDay = savedInstanceState.getInt("Chosen day"); } } @@ -84,6 +86,8 @@ public class WeatherInformationSpecificDataFragment extends ListFragment impleme savedInstanceState.putSerializable("ForecastWeatherData", forecastWeatherData); } + savedInstanceState.putInt("Chosend day", this.mChosenDay); + super.onSaveInstanceState(savedInstanceState); } -- 2.1.4