No time for comments
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Wed, 2 Apr 2014 19:41:43 +0000 (21:41 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Wed, 2 Apr 2014 19:41:43 +0000 (21:41 +0200)
14 files changed:
Android/WeatherInformation/res/drawable-hdpi/ic_action_import_export.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-hdpi/ic_action_settings.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-mdpi/ic_action_import_export.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-mdpi/ic_action_settings.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-xhdpi/ic_action_import_export.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-xhdpi/ic_action_settings.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-xxhdpi/ic_action_import_export.png [new file with mode: 0644]
Android/WeatherInformation/res/drawable-xxhdpi/ic_action_settings.png [new file with mode: 0644]
Android/WeatherInformation/res/menu/weather_main_menu.xml
Android/WeatherInformation/res/values/strings.xml
Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationActivity.java
Android/WeatherInformation/src/de/example/exampletdd/activityinterface/OnClickButtons.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/WeatherInformationDataFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/WeatherInformationDataFragmentDeprecated.java

diff --git a/Android/WeatherInformation/res/drawable-hdpi/ic_action_import_export.png b/Android/WeatherInformation/res/drawable-hdpi/ic_action_import_export.png
new file mode 100644 (file)
index 0000000..18c0fe7
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-hdpi/ic_action_import_export.png differ
diff --git a/Android/WeatherInformation/res/drawable-hdpi/ic_action_settings.png b/Android/WeatherInformation/res/drawable-hdpi/ic_action_settings.png
new file mode 100644 (file)
index 0000000..54eecde
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-hdpi/ic_action_settings.png differ
diff --git a/Android/WeatherInformation/res/drawable-mdpi/ic_action_import_export.png b/Android/WeatherInformation/res/drawable-mdpi/ic_action_import_export.png
new file mode 100644 (file)
index 0000000..95914cc
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-mdpi/ic_action_import_export.png differ
diff --git a/Android/WeatherInformation/res/drawable-mdpi/ic_action_settings.png b/Android/WeatherInformation/res/drawable-mdpi/ic_action_settings.png
new file mode 100644 (file)
index 0000000..25c36db
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-mdpi/ic_action_settings.png differ
diff --git a/Android/WeatherInformation/res/drawable-xhdpi/ic_action_import_export.png b/Android/WeatherInformation/res/drawable-xhdpi/ic_action_import_export.png
new file mode 100644 (file)
index 0000000..b247eda
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-xhdpi/ic_action_import_export.png differ
diff --git a/Android/WeatherInformation/res/drawable-xhdpi/ic_action_settings.png b/Android/WeatherInformation/res/drawable-xhdpi/ic_action_settings.png
new file mode 100644 (file)
index 0000000..425a8bc
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-xhdpi/ic_action_settings.png differ
diff --git a/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_import_export.png b/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_import_export.png
new file mode 100644 (file)
index 0000000..2dccb24
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_import_export.png differ
diff --git a/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_settings.png b/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_settings.png
new file mode 100644 (file)
index 0000000..fe5fec4
Binary files /dev/null and b/Android/WeatherInformation/res/drawable-xxhdpi/ic_action_settings.png differ
index 30460b2..6e3221f 100644 (file)
@@ -1,6 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
     
+    
+    <item
+        android:id="@+id/weather_menu_get"
+        android:menuCategory="system"
+        android:title="@string/action_get_weather"
+        android:titleCondensed="@string/action_get_weather"
+        android:checked="false"
+        android:visible="true"
+        android:checkable="false"
+        android:enabled="true"
+        android:icon="@drawable/ic_action_import_export"
+        android:showAsAction="ifRoom|withText">
+    </item>
     <item
         android:id="@+id/weather_menu_settings"
         android:menuCategory="system"
@@ -10,7 +23,8 @@
         android:visible="true"
         android:checkable="false"
         android:enabled="true"
-        android:showAsAction="never">
+        android:icon="@drawable/ic_action_settings"
+        android:showAsAction="ifRoom|withText">
     </item>
     
     
index d0c9b0c..45d1148 100644 (file)
@@ -4,6 +4,7 @@
     <string name="app_name">Weather Information</string>
     <string name="action_settings">Settings</string>
     <string name="action_search">City,country</string>
+    <string name="action_get_weather">Get weather</string>
     <string name="button_weather">Get weather</string>
     <string name="uri_api_coord">http://api.openweathermap.org/data/{0}/weather?lat={1}&amp;lon={2}</string>
     <string name="uri_api_city">http://api.openweathermap.org/data/{0}/weather?q={1}</string>
@@ -19,7 +20,7 @@
     <string name="text_field_tem">Temperature:</string>
     <string name="text_field_tem_min">Min temperature:</string>
     <string name="text_field_tem_max">Max temperature:</string>
-    <string name="text_field_cloudiness">Cloudiness:</string>
+    <string name="text_field_cloudiness">Cloudiness in %:</string>
     <string name="text_field_rain_time">Rain time:</string>
     <string name="text_field_rain_amount">Rain amount:</string>
     <string name="text_field_wind_speed">Wind speed:</string>
@@ -28,7 +29,7 @@
     <string name="error_dialog_connection_tiemout">Connection error timeout</string>
     <string name="error_dialog_generic_error">Impossible to receive weather data.</string>
     <string name="icon_weather_description">Icon weather</string>
-    <string name="header_action_bar">Weather Information</string>
+    <string name="header_action_bar">City,country</string>
     <string name="weather_preferences_units_key">weather_preferences_units</string>
     <string name="weather_preferences_units_fahrenheit">Fahrenheit</string>
     <string name="weather_preferences_units_celsius">Celsius</string>
index ae260ee..e693053 100644 (file)
@@ -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();
     }
 
 }
index 0400afe..2206cc5 100644 (file)
@@ -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();
 
 }
index 0dcf6db..502a807 100644 (file)
@@ -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<WeatherDataEntry> entries = new ArrayList<WeatherDataEntry>();
-        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<WeatherDataEntry> 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<WeatherDataEntry> 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<WeatherDataEntry> createEmptyEntriesList() {
+        final List<WeatherDataEntry> entries = new ArrayList<WeatherDataEntry>();
+        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;
+    }
 }
index 939ec12..8322661 100644 (file)
@@ -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(