From: gu.martinm@gmail.com Date: Wed, 2 Apr 2014 19:41:43 +0000 (+0200) Subject: No time for comments X-Git-Tag: weatherinformation-1.0~192 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=40d7bf3c77021218ac48cd1cfbecc7e12020885f;p=AndroidWeatherInformation No time for comments --- 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 0000000..18c0fe7 Binary files /dev/null and b/res/drawable-hdpi/ic_action_import_export.png differ diff --git a/res/drawable-hdpi/ic_action_settings.png b/res/drawable-hdpi/ic_action_settings.png new file mode 100644 index 0000000..54eecde Binary files /dev/null and b/res/drawable-hdpi/ic_action_settings.png differ diff --git a/res/drawable-mdpi/ic_action_import_export.png b/res/drawable-mdpi/ic_action_import_export.png new file mode 100644 index 0000000..95914cc Binary files /dev/null and b/res/drawable-mdpi/ic_action_import_export.png differ diff --git a/res/drawable-mdpi/ic_action_settings.png b/res/drawable-mdpi/ic_action_settings.png new file mode 100644 index 0000000..25c36db Binary files /dev/null and b/res/drawable-mdpi/ic_action_settings.png differ 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 0000000..b247eda Binary files /dev/null and b/res/drawable-xhdpi/ic_action_import_export.png differ diff --git a/res/drawable-xhdpi/ic_action_settings.png b/res/drawable-xhdpi/ic_action_settings.png new file mode 100644 index 0000000..425a8bc Binary files /dev/null and b/res/drawable-xhdpi/ic_action_settings.png differ diff --git a/res/drawable-xxhdpi/ic_action_import_export.png b/res/drawable-xxhdpi/ic_action_import_export.png new file mode 100644 index 0000000..2dccb24 Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_import_export.png differ diff --git a/res/drawable-xxhdpi/ic_action_settings.png b/res/drawable-xxhdpi/ic_action_settings.png new file mode 100644 index 0000000..fe5fec4 Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_settings.png differ diff --git a/res/menu/weather_main_menu.xml b/res/menu/weather_main_menu.xml index 30460b2..6e3221f 100644 --- a/res/menu/weather_main_menu.xml +++ b/res/menu/weather_main_menu.xml @@ -1,6 +1,19 @@ + + + + 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(