New overview list. WIP: implementation for tabs and phones.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Thu, 10 Apr 2014 07:41:30 +0000 (09:41 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Thu, 10 Apr 2014 07:41:30 +0000 (09:41 +0200)
res/drawable-hdpi/ic_02d.png [new file with mode: 0644]
res/drawable-mdpi/ic_02d.png [new file with mode: 0644]
res/drawable-xhdpi/ic_02d.png [new file with mode: 0644]
res/drawable-xxhdpi/ic_02d.png [new file with mode: 0644]
res/layout/weather_main.xml
res/layout/weather_main_entry_list.xml
res/layout/weather_main_list.xml [deleted file]
src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java
src/de/example/exampletdd/fragment/overview/WeatherOverviewAdapter.java
src/de/example/exampletdd/fragment/overview/WeatherOverviewEntry.java

diff --git a/res/drawable-hdpi/ic_02d.png b/res/drawable-hdpi/ic_02d.png
new file mode 100644 (file)
index 0000000..3451b4a
Binary files /dev/null and b/res/drawable-hdpi/ic_02d.png differ
diff --git a/res/drawable-mdpi/ic_02d.png b/res/drawable-mdpi/ic_02d.png
new file mode 100644 (file)
index 0000000..482afa3
Binary files /dev/null and b/res/drawable-mdpi/ic_02d.png differ
diff --git a/res/drawable-xhdpi/ic_02d.png b/res/drawable-xhdpi/ic_02d.png
new file mode 100644 (file)
index 0000000..775ee02
Binary files /dev/null and b/res/drawable-xhdpi/ic_02d.png differ
diff --git a/res/drawable-xxhdpi/ic_02d.png b/res/drawable-xxhdpi/ic_02d.png
new file mode 100644 (file)
index 0000000..54649c6
Binary files /dev/null and b/res/drawable-xxhdpi/ic_02d.png differ
index 8ce309b..db32dde 100644 (file)
@@ -11,7 +11,6 @@
         android:id="@+id/weather_overview_fragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        class="de.example.exampletdd.fragment.overview.WeatherInformationOverviewFragment"
-        tools:layout="@layout/weather_main_list" />
+        class="de.example.exampletdd.fragment.overview.WeatherInformationOverviewFragment" />
 
 </FrameLayout>
\ No newline at end of file
index 56ea95e..6802af1 100644 (file)
@@ -4,20 +4,18 @@
     android:layout_height="match_parent"
     android:orientation="vertical" >
 
-    
-
     <TextView
         android:id="@+id/weather_main_entry_date"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_alignBottom="@+id/weather_main_entry_temperature"
         android:layout_alignParentLeft="true"
         android:layout_alignTop="@+id/weather_main_entry_temperature"
-        android:layout_alignBottom="@+id/weather_main_entry_temperature"
-        android:textAppearance="?android:attr/textAppearanceLarge"
-        android:textStyle="bold"
-        android:textSize="14sp"
+        android:text="Date"
         android:textAlignment="center"
-        android:text="Date" />
+        android:textAllCaps="true"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+        android:textStyle="bold" />
 
     <TextView
         android:id="@+id/weather_main_entry_temperature"
         android:layout_height="wrap_content"
         android:layout_alignBottom="@+id/weather_main_entry_image"
         android:layout_alignTop="@+id/weather_main_entry_image"
-        android:layout_toRightOf="@+id/weather_main_entry_date"
+        android:layout_centerHorizontal="true"
         android:text="Temperature"
         android:textAlignment="center"
-        android:textAppearance="?android:attr/textAppearanceLarge"
-        android:textSize="14sp"
+        android:textAllCaps="true"
+        android:textAppearance="?android:attr/textAppearanceMedium"
         android:textStyle="normal" />
     
-    
     <ImageView
         android:id="@+id/weather_main_entry_image"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_toRightOf="@+id/weather_main_entry_temperature"
         android:layout_alignParentRight="true"
         android:contentDescription="@string/icon_weather_description"
         android:orientation="vertical"
diff --git a/res/layout/weather_main_list.xml b/res/layout/weather_main_list.xml
deleted file mode 100644 (file)
index 1537e10..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:gravity="center"
-    android:orientation="vertical" >
-    
-
-    <ListView
-        android:id="@+id/weather_main_list_view"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent" >
-    </ListView>
-    
-</RelativeLayout>
index 82945a8..2c973d9 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.http.client.ClientProtocolException;
 import org.json.JSONException;
 
 import android.app.DialogFragment;
-import android.app.Fragment;
+import android.app.ListFragment;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
@@ -34,9 +34,10 @@ import android.os.AsyncTask;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
+import android.view.ActionMode;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.AbsListView.MultiChoiceModeListener;
 import android.widget.ListView;
 import de.example.exampletdd.R;
 import de.example.exampletdd.activityinterface.ErrorMessage;
@@ -49,7 +50,8 @@ import de.example.exampletdd.parser.IJPOSWeatherParser;
 import de.example.exampletdd.parser.JPOSWeatherParser;
 import de.example.exampletdd.service.WeatherService;
 
-public class WeatherInformationOverviewFragment extends Fragment implements GetWeather {
+public class WeatherInformationOverviewFragment extends ListFragment implements
+GetWeather {
     private static final String WEATHER_DATA_FILE = "weatherdata.file";
     private static final String WEATHER_GEOCODING_FILE = "weathergeocoding.file";
     private static final String TAG = "WeatherInformationOverviewFragment";
@@ -71,31 +73,42 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW
     }
 
     @Override
-    public View onCreateView(final LayoutInflater inflater,
-            final ViewGroup container, final Bundle savedInstanceState) {
-        // TODO: In activity_main.xml you can see: tools:layout="@layout/weather_data_list"
-        // So, probably this line is not required. I guess you can do the same
-        // by xml or by means of this code. Test it!!!
-        final View rootView = inflater.inflate(R.layout.weather_main_list,
-                container, false);
-
-        return rootView;
-    }
-
-    @Override
     public void onActivityCreated(final Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
-        final ListView listWeatherView = (ListView) this.getActivity().findViewById(
-                R.id.weather_main_list_view);
+        final ListView listWeatherView = this.getListView();
 
-        final WeatherOverviewAdapter adapter = new WeatherOverviewAdapter(this.getActivity(),
-                R.layout.weather_main_entry_list);
+        listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE);
+        listWeatherView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
 
-        final Collection<WeatherOverviewEntry> entries = this.createEmptyEntriesList();
+            @Override
+            public boolean onCreateActionMode(final ActionMode mode,
+                    final Menu menu) {
+                return false;
+            }
 
-        adapter.addAll(entries);
-        listWeatherView.setAdapter(adapter);
+            @Override
+            public boolean onPrepareActionMode(final ActionMode mode,
+                    final Menu menu) {
+                return false;
+            }
+
+            @Override
+            public boolean onActionItemClicked(final ActionMode mode,
+                    final MenuItem item) {
+                return false;
+            }
+
+            @Override
+            public void onDestroyActionMode(final ActionMode mode) {
+            }
+
+            @Override
+            public void onItemCheckedStateChanged(
+                    final ActionMode mode, final int position,
+                    final long id, final boolean checked) {
+            }
+        });
 
         if (savedInstanceState != null) {
             // Restore state
@@ -109,6 +122,20 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW
                         .createErrorDialog(R.string.error_dialog_generic_error);
             }
         }
+
+        this.setHasOptionsMenu(false);
+
+        final WeatherOverviewAdapter adapter = new WeatherOverviewAdapter(
+                this.getActivity(), R.layout.weather_main_entry_list);
+
+        final Collection<WeatherOverviewEntry> entries = this
+                .createEmptyEntriesList();
+
+        this.setListAdapter(null);
+        adapter.addAll(entries);
+        this.setListAdapter(adapter);
+        this.setListShown(true);
+        this.setListShownNoAnimation(true);
     }
 
     @Override
@@ -170,40 +197,45 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW
     @Override
     public void updateWeatherData(final WeatherData weatherData) {
         final List<WeatherOverviewEntry> entries = this.createEmptyEntriesList();
-        final ListView listWeatherView = (ListView) this.getActivity().findViewById(
-                R.id.weather_main_list_view);
         final WeatherOverviewAdapter adapter = new WeatherOverviewAdapter(this.getActivity(),
                 R.layout.weather_main_entry_list);
 
-        Bitmap picture = null;
-
-        if (weatherData.getWeather().getIcon() != null) {
-            picture= BitmapFactory.decodeByteArray(
-                    weatherData.getIconData(), 0,
-                    weatherData.getIconData().length);
-        }
+        // Bitmap picture = null;
+        //
+        // if (weatherData.getWeather().getIcon() != null) {
+        // picture= BitmapFactory.decodeByteArray(
+        // weatherData.getIconData(), 0,
+        // weatherData.getIconData().length);
+        // }
 
+        final Bitmap picture = BitmapFactory.decodeResource(
+                this.getResources(), R.drawable.ic_02d);
         final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.getDefault());
-        tempFormatter.applyPattern("#####.#####");
-        final SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd", Locale.getDefault());
+        tempFormatter.applyPattern("#####.##");
+        final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d", Locale.getDefault());
         final double tempUnits = this.mIsFahrenheit ? 0 : 273.15;
-        double conversion = weatherData.getMain().getTemp();
-        conversion = conversion - tempUnits;
+        double temp = weatherData.getMain().getTemp();
+        temp = temp - tempUnits;
+        double maxTemp = weatherData.getMain().getMaxTemp();
+        maxTemp = maxTemp - tempUnits;
+        double minTemp = weatherData.getMain().getMinTemp();
+        minTemp = minTemp - tempUnits;
 
         final Calendar now = Calendar.getInstance();
         if (weatherData.getWeather() != null) {
             for (int i = 0; i<15; i++) {
                 final Date day = now.getTime();
-                entries.set(i, new WeatherOverviewEntry(
-                        "DATE: " + dateFormat.format(day),
-                        tempFormatter.format(conversion), picture));
-                now.add(Calendar.DAY_OF_MONTH, -1);
+                entries.set(i, new WeatherOverviewEntry(dateFormat.format(day),
+                        tempFormatter.format(temp), tempFormatter
+                        .format(maxTemp), tempFormatter
+                        .format(minTemp), picture));
+                now.add(Calendar.DAY_OF_MONTH, 1);
             }
         }
 
-        listWeatherView.setAdapter(null);
+        this.setListAdapter(null);
         adapter.addAll(entries);
-        listWeatherView.setAdapter(adapter);
+        this.setListAdapter(adapter);
     }
 
     @Override
@@ -381,14 +413,14 @@ public class WeatherInformationOverviewFragment extends Fragment implements GetW
 
     private List<WeatherOverviewEntry> createEmptyEntriesList() {
         final List<WeatherOverviewEntry> entries = new ArrayList<WeatherOverviewEntry>();
-        final SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd", Locale.getDefault());
+        final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d", Locale.getDefault());
 
         final Calendar now = Calendar.getInstance();
         for (int i = 0; i<15; i++) {
             final Date day = now.getTime();
-            entries.add(i, new WeatherOverviewEntry(
-                    "DATE: " + dateFormat.format(day), null, null));
-            now.add(Calendar.DAY_OF_MONTH, -1);
+            entries.add(i, new WeatherOverviewEntry(dateFormat.format(day),
+                    null, null, null, null));
+            now.add(Calendar.DAY_OF_MONTH, 1);
         }
 
         return entries;
index 43fae28..7f101d5 100644 (file)
@@ -32,7 +32,15 @@ public class WeatherOverviewAdapter extends ArrayAdapter<WeatherOverviewEntry> {
 
         // Setting the text view
         viewHolder.dateView.setText(entry.getDate());
-        viewHolder.temperatureView.setText(entry.getTemperature());
+        String maxTemp = "";
+        if (entry.getMaxTemp() != null) {
+            maxTemp = entry.getMaxTemp() + "º";
+        }
+        String minTemp = "";
+        if (entry.getMinTemp() != null) {
+            minTemp = "/" + entry.getMinTemp() + "º";
+        }
+        viewHolder.temperatureView.setText(maxTemp + minTemp);
         // Set image view
         viewHolder.pictureView.setImageBitmap(entry.getPicture());
 
index f56fce6..2d2c710 100644 (file)
@@ -5,12 +5,16 @@ import android.graphics.Bitmap;
 public class WeatherOverviewEntry {
     private final String date;
     private final String temperature;
+    private final String maxTemp;
+    private final String minTemp;
     private final Bitmap picture;
 
     public WeatherOverviewEntry(final String date, final String temperature,
-            final Bitmap picture) {
+            final String maxTemp, final String minTemp, final Bitmap picture) {
         this.date = date;
         this.temperature = temperature;
+        this.maxTemp = maxTemp;
+        this.minTemp = minTemp;
         this.picture = picture;
     }
 
@@ -22,6 +26,14 @@ public class WeatherOverviewEntry {
         return this.temperature;
     }
 
+    public String getMaxTemp() {
+        return this.maxTemp;
+    }
+
+    public String getMinTemp() {
+        return this.minTemp;
+    }
+
     public Bitmap getPicture() {
         return this.picture;
     }