WeatherInformation: latest changes for tabs
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 22 Apr 2014 01:58:43 +0000 (03:58 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 22 Apr 2014 01:58:43 +0000 (03:58 +0200)
Android/WeatherInformation/res/layout/fragment_pager_list.xml [deleted file]
Android/WeatherInformation/res/layout/weather_current_data_entry_fourth.xml
Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationActivity.java
Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationMapActivity.java
Android/WeatherInformation/src/de/example/exampletdd/WeatherInformationSpecificDataActivity.java
Android/WeatherInformation/src/de/example/exampletdd/WeatherTabsActivity.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/ErrorDialogFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/ProgressDialogFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/current/WeatherInformationCurrentDataFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/overview/WeatherInformationOverviewFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/WeatherInformationSpecificDataFragment.java

diff --git a/Android/WeatherInformation/res/layout/fragment_pager_list.xml b/Android/WeatherInformation/res/layout/fragment_pager_list.xml
deleted file mode 100644 (file)
index e4a1c55..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:background="@android:drawable/gallery_thumb">
-
-    <TextView android:id="@+id/text"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="center_vertical|center_horizontal"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:text="HOLA GUS TABS"/>
-
-    <!-- The frame layout is here since we will be showing either
-    the empty view or the list view.  -->
-    <FrameLayout
-        android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1" >
-        <!-- Here is the list. Since we are using a ListActivity, we
-             have to call it "@android:id/list" so ListActivity will
-             find it -->
-        <ListView android:id="@android:id/list"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:drawSelectorOnTop="false"/>
-
-        <!-- Here is the view to show if the list is emtpy -->
-        <TextView android:id="@android:id/empty"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:text="No items."/>
-
-    </FrameLayout>
-
-</LinearLayout>
index d5a3207..da2d94e 100644 (file)
@@ -2,7 +2,7 @@
 <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_gravity="center"
-    android:layout_height="80dp" >
+    android:layout_height="140dp" >
     
     <LinearLayout
         android:layout_width="wrap_content"
index b8491d3..86c6c0b 100644 (file)
@@ -75,12 +75,6 @@ public class WeatherInformationActivity extends Activity {
                     "de.example.exampletdd.WeatherInformationMapActivity"));
             this.startActivity(intent);
             return true;
-            //        } else if (itemId == R.id.weather_menu_current) {
-            //            intent = new Intent("de.example.exampletdd.WEATHERINFO")
-            //            .setComponent(new ComponentName("de.example.exampletdd",
-            //                    "de.example.exampletdd.WeatherInformationCurrentDataActivity"));
-            //            this.startActivity(intent);
-            //            return true;
         } else {
         }
 
index bc77aa9..ae1bbd6 100644 (file)
@@ -6,12 +6,12 @@ import java.util.List;
 import java.util.Locale;
 
 import android.app.ActionBar;
-import android.app.Activity;
-import android.app.DialogFragment;
 import android.location.Address;
 import android.location.Geocoder;
 import android.os.AsyncTask;
 import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.FragmentActivity;
 import android.util.Log;
 import android.widget.TextView;
 
@@ -28,7 +28,7 @@ import de.example.exampletdd.fragment.ProgressDialogFragment;
 import de.example.exampletdd.model.GeocodingData;
 import de.example.exampletdd.service.WeatherServicePersistenceFile;
 
-public class WeatherInformationMapActivity extends Activity {
+public class WeatherInformationMapActivity extends FragmentActivity {
     private GoogleMap mMap;
     private Marker mMarker;
     private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@@ -100,7 +100,8 @@ public class WeatherInformationMapActivity extends Activity {
 
         @Override
         protected void onPreExecute() {
-            this.newFragment.show(WeatherInformationMapActivity.this.getFragmentManager(), "progressDialog");
+            this.newFragment.show(WeatherInformationMapActivity.this.getSupportFragmentManager(),
+                    "progressDialog");
         }
 
         @Override
@@ -125,7 +126,8 @@ public class WeatherInformationMapActivity extends Activity {
 
             if (geocodingData == null) {
                 final DialogFragment newFragment = ErrorDialogFragment.newInstance(R.string.error_dialog_location_error);
-                newFragment.show(WeatherInformationMapActivity.this.getFragmentManager(), "errorDialog");
+                newFragment.show(WeatherInformationMapActivity.this.getSupportFragmentManager(),
+                        "errorDialog");
 
                 return;
             }
@@ -135,11 +137,13 @@ public class WeatherInformationMapActivity extends Activity {
             } catch (final FileNotFoundException e) {
                 Log.e(TAG, "GeocoderAsyncTask onPostExecute exception: ", e);
                 final DialogFragment newFragment = ErrorDialogFragment.newInstance(R.string.error_dialog_location_error);
-                newFragment.show(WeatherInformationMapActivity.this.getFragmentManager(), "errorDialog");
+                newFragment.show(WeatherInformationMapActivity.this.getSupportFragmentManager(),
+                        "errorDialog");
             } catch (final IOException e) {
                 Log.e(TAG, "GeocoderAsyncTask onPostExecute exception: ", e);
                 final DialogFragment newFragment = ErrorDialogFragment.newInstance(R.string.error_dialog_location_error);
-                newFragment.show(WeatherInformationMapActivity.this.getFragmentManager(), "errorDialog");
+                newFragment.show(WeatherInformationMapActivity.this.getSupportFragmentManager(),
+                        "errorDialog");
             }
         }
 
index bf56f69..42eff40 100644 (file)
@@ -1,12 +1,12 @@
 package de.example.exampletdd;
 
 import android.app.ActionBar;
-import android.app.Activity;
 import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
 import de.example.exampletdd.model.GeocodingData;
 import de.example.exampletdd.service.WeatherServicePersistenceFile;
 
-public class WeatherInformationSpecificDataActivity extends Activity {
+public class WeatherInformationSpecificDataActivity extends FragmentActivity {
 
     @Override
     protected void onCreate(final Bundle savedInstanceState) {
index 11f54d9..4c137bd 100644 (file)
@@ -12,17 +12,9 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentActivity;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentPagerAdapter;
-import android.support.v4.app.ListFragment;
 import android.support.v4.view.ViewPager;
-import android.util.Log;
-import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
 import de.example.exampletdd.activityinterface.GetWeather;
 import de.example.exampletdd.fragment.current.WeatherInformationCurrentDataFragment;
 import de.example.exampletdd.fragment.overview.WeatherInformationOverviewFragment;
@@ -30,37 +22,32 @@ import de.example.exampletdd.model.GeocodingData;
 import de.example.exampletdd.service.WeatherServicePersistenceFile;
 
 public class WeatherTabsActivity extends FragmentActivity {
-    static final int NUM_ITEMS = 2;
-
-    MyAdapter mAdapter;
-
-    ViewPager mPager;
-
+    private static final int NUM_ITEMS = 2;
+    private MyAdapter mAdapter;
+    private ViewPager mPager;
     private GetWeather mGetWeather;
 
     @Override
     protected void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.fragment_pager);
+        this.setContentView(R.layout.fragment_pager);
 
-        mAdapter = new MyAdapter(getSupportFragmentManager());
+        this.mAdapter = new MyAdapter(this.getSupportFragmentManager());
 
-        mPager = (ViewPager)findViewById(R.id.pager);
-        mPager.setAdapter(mAdapter);
+        this.mPager = (ViewPager)this.findViewById(R.id.pager);
+        this.mPager.setAdapter(this.mAdapter);
 
 
-        mPager.setOnPageChangeListener(
+        this.mPager.setOnPageChangeListener(
                 new ViewPager.SimpleOnPageChangeListener() {
                     @Override
                     public void onPageSelected(final int position) {
-                        // When swiping between pages, select the
-                        // corresponding tab.
-                        getActionBar().setSelectedNavigationItem(position);
+                        WeatherTabsActivity.this.getActionBar().setSelectedNavigationItem(position);
                     }
                 });
 
 
-        final ActionBar actionBar = getActionBar();
+        final ActionBar actionBar = this.getActionBar();
 
         PreferenceManager.setDefaultValues(this, R.xml.weather_preferences, false);
 
@@ -74,21 +61,17 @@ public class WeatherTabsActivity extends FragmentActivity {
 
             @Override
             public void onTabSelected(final Tab tab, final FragmentTransaction ft) {
-                // When the tab is selected, switch to the
-                // corresponding page in the ViewPager.
-                mPager.setCurrentItem(tab.getPosition());
+                WeatherTabsActivity.this.mPager.setCurrentItem(tab.getPosition());
 
             }
 
             @Override
             public void onTabUnselected(final Tab tab, final FragmentTransaction ft) {
-                // TODO Auto-generated method stub
 
             }
 
             @Override
             public void onTabReselected(final Tab tab, final FragmentTransaction ft) {
-                // TODO Auto-generated method stub
 
             }
 
@@ -96,7 +79,6 @@ public class WeatherTabsActivity extends FragmentActivity {
 
         actionBar.addTab(actionBar.newTab().setText("CURRENTLY").setTabListener(tabListener));
         actionBar.addTab(actionBar.newTab().setText("FORECAST").setTabListener(tabListener));
-
     }
 
     @Override
@@ -163,13 +145,13 @@ public class WeatherTabsActivity extends FragmentActivity {
         final String value = sharedPreferences.getString(keyPreference, "");
         String humanValue = "";
         if (value.equals("5")) {
-            humanValue = "5-Day Forecast";
+            humanValue = "5 DAY FORECAST";
         } else if (value.equals("10")) {
-            humanValue = "10-Day Forecast";
+            humanValue = "10 DAY FORECAST";
         } else if (value.equals("14")) {
-            humanValue = "14-Day Forecast";
+            humanValue = "14 DAY FORECAST";
         }
-        actionBar.setSubtitle(humanValue);
+        actionBar.getTabAt(1).setText(humanValue);
 
     }
 
@@ -200,65 +182,4 @@ public class WeatherTabsActivity extends FragmentActivity {
 
         }
     }
-
-    public static class ArrayListFragment extends ListFragment {
-        int mNum;
-
-        /**
-         * Create a new instance of CountingFragment, providing "num"
-         * as an argument.
-         */
-        static ArrayListFragment newInstance(final int num) {
-            final ArrayListFragment f = new ArrayListFragment();
-
-            // Supply num input as an argument.
-            final Bundle args = new Bundle();
-            args.putInt("num", num);
-            f.setArguments(args);
-
-            return f;
-        }
-
-        /**
-         * When creating, retrieve this instance's number from its arguments.
-         */
-        @Override
-        public void onCreate(final Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
-            mNum = getArguments() != null ? getArguments().getInt("num") : 1;
-        }
-
-        /**
-         * The Fragment's UI is just a simple text view showing its
-         * instance number.
-         */
-        @Override
-        public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
-                final Bundle savedInstanceState) {
-            final View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
-            final View tv = v.findViewById(R.id.text);
-            ((TextView)tv).setText("Fragment #" + mNum);
-            return v;
-        }
-
-        @Override
-        public void onActivityCreated(final Bundle savedInstanceState) {
-            super.onActivityCreated(savedInstanceState);
-            final String[] chesses = new String[5];
-            chesses[0] = "cheese 1";
-            chesses[1] = "cheese 2";
-            chesses[2] = "cheese 3";
-            chesses[3] = "cheese 4";
-            chesses[4] = "cheese 5";
-            setListAdapter(new ArrayAdapter<String>(getActivity(),
-                    android.R.layout.simple_list_item_1, chesses));
-        }
-
-        @Override
-        public void onListItemClick(final ListView l, final View v, final int position, final long id) {
-            Log.i("FragmentList", "Item clicked: " + id);
-        }
-    }
-
-
 }
index 76cb89a..33876e2 100644 (file)
@@ -2,9 +2,9 @@ package de.example.exampletdd.fragment;
 
 import android.app.AlertDialog;
 import android.app.Dialog;
-import android.app.DialogFragment;
 import android.content.DialogInterface;
 import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
 import de.example.exampletdd.R;
 
 public class ErrorDialogFragment extends DialogFragment {
index a21f321..7ff9960 100644 (file)
@@ -1,10 +1,10 @@
 package de.example.exampletdd.fragment;
 
 import android.app.Dialog;
-import android.app.DialogFragment;
 import android.app.ProgressDialog;
 import android.content.DialogInterface;
 import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
 import android.view.KeyEvent;
 
 public class ProgressDialogFragment extends DialogFragment {
index 00a03a1..0a04dc0 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Locale;
 
 import org.apache.http.client.ClientProtocolException;
 
-import android.app.DialogFragment;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -22,6 +21,7 @@ import android.net.http.AndroidHttpClient;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
+import android.support.v4.app.DialogFragment;
 import android.support.v4.app.ListFragment;
 import android.util.Log;
 import android.widget.ListView;
@@ -29,6 +29,7 @@ import android.widget.ListView;
 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.overview.IconsList;
 import de.example.exampletdd.httpclient.CustomHTTPClient;
@@ -67,9 +68,9 @@ public class WeatherInformationCurrentDataFragment extends ListFragment {
                 try {
                     this.mWeatherServicePersistenceFile.storeCurrentWeatherData(currentWeatherData);
                 } catch (final IOException e) {
-                    //                    final DialogFragment newFragment = ErrorDialogFragment
-                    //                            .newInstance(R.string.error_dialog_generic_error);
-                    //                    newFragment.show(this.getFragmentManager(), "errorDialog");
+                    final DialogFragment newFragment = ErrorDialogFragment
+                            .newInstance(R.string.error_dialog_generic_error);
+                    newFragment.show(this.getFragmentManager(), "errorDialog");
                 }
             }
         }
@@ -258,8 +259,8 @@ public class WeatherInformationCurrentDataFragment extends ListFragment {
 
         @Override
         protected void onPreExecute() {
-            this.newFragment.show(WeatherInformationCurrentDataFragment.this.getActivity()
-                    .getFragmentManager(), "progressDialog");
+            this.newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(),
+                    "progressDialog");
         }
 
         @Override
@@ -298,18 +299,18 @@ public class WeatherInformationCurrentDataFragment extends ListFragment {
                 } catch (final IOException e) {
                     WeatherInformationCurrentDataFragment.this.setListShown(true);
                     Log.e(TAG, "WeatherTask onPostExecute exception: ", e);
-                    //                    final DialogFragment newFragment = ErrorDialogFragment
-                    //                            .newInstance(R.string.error_dialog_generic_error);
-                    //                    newFragment.show(
-                    //                            WeatherInformationCurrentDataFragment.this.getFragmentManager(),
-                    //                            "errorDialog");
+                    final DialogFragment newFragment = ErrorDialogFragment
+                            .newInstance(R.string.error_dialog_generic_error);
+                    newFragment.show(
+                            WeatherInformationCurrentDataFragment.this.getFragmentManager(),
+                            "errorDialog");
                 }
             } else {
                 WeatherInformationCurrentDataFragment.this.setListShown(true);
-                //                final DialogFragment newFragment = ErrorDialogFragment
-                //                        .newInstance(R.string.error_dialog_generic_error);
-                //                newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(),
-                //                        "errorDialog");
+                final DialogFragment newFragment = ErrorDialogFragment
+                        .newInstance(R.string.error_dialog_generic_error);
+                newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(),
+                        "errorDialog");
             }
         }
 
@@ -317,10 +318,10 @@ public class WeatherInformationCurrentDataFragment extends ListFragment {
         protected void onCancelled(final CurrentWeatherData currentWeatherData) {
             this.weatherHTTPClient.close();
 
-            //            final DialogFragment newFragment = ErrorDialogFragment
-            //                    .newInstance(R.string.error_dialog_connection_tiemout);
-            //            newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(),
-            //                    "errorDialog");
+            final DialogFragment newFragment = ErrorDialogFragment
+                    .newInstance(R.string.error_dialog_connection_tiemout);
+            newFragment.show(WeatherInformationCurrentDataFragment.this.getFragmentManager(),
+                    "errorDialog");
         }
 
         private CurrentWeatherData doInBackgroundThrowable(final Object... params)
index 8168e23..9256c61 100644 (file)
@@ -16,7 +16,8 @@ import java.util.Locale;
 
 import org.apache.http.client.ClientProtocolException;
 
-import android.app.DialogFragment;
+import android.content.ComponentName;
+import android.content.Intent;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -25,6 +26,7 @@ import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Parcelable;
 import android.preference.PreferenceManager;
+import android.support.v4.app.DialogFragment;
 import android.support.v4.app.ListFragment;
 import android.util.Log;
 import android.view.View;
@@ -34,7 +36,9 @@ import com.fasterxml.jackson.core.JsonParseException;
 
 import de.example.exampletdd.R;
 import de.example.exampletdd.activityinterface.GetWeather;
+import de.example.exampletdd.fragment.ErrorDialogFragment;
 import de.example.exampletdd.fragment.ProgressDialogFragment;
+import de.example.exampletdd.fragment.specific.WeatherInformationSpecificDataFragment;
 import de.example.exampletdd.httpclient.CustomHTTPClient;
 import de.example.exampletdd.model.GeocodingData;
 import de.example.exampletdd.model.forecastweather.ForecastWeatherData;
@@ -80,9 +84,9 @@ public class WeatherInformationOverviewFragment extends ListFragment implements
                     this.mWeatherServicePersistenceFile
                     .storeForecastWeatherData(forecastWeatherData);
                 } catch (final IOException e) {
-                    //                    final DialogFragment newFragment = ErrorDialogFragment
-                    //                            .newInstance(R.string.error_dialog_generic_error);
-                    //                    newFragment.show(this.getFragmentManager(), "errorDialog");
+                    final DialogFragment newFragment = ErrorDialogFragment
+                            .newInstance(R.string.error_dialog_generic_error);
+                    newFragment.show(this.getFragmentManager(), "errorDialog");
                 }
             }
 
@@ -104,19 +108,19 @@ public class WeatherInformationOverviewFragment extends ListFragment implements
 
     @Override
     public void onListItemClick(final ListView l, final View v, final int position, final long id) {
-        //        final WeatherInformationSpecificDataFragment fragment = (WeatherInformationSpecificDataFragment) this.getFragmentManager()
-        //                .findFragmentById(R.id.weather_specific_data__fragment);
-        //        if (fragment == null) {
-        //            // handset layout
-        //            final Intent intent = new Intent("de.example.exampletdd.WEATHERINFO").
-        //                    setComponent(new ComponentName("de.example.exampletdd",
-        //                            "de.example.exampletdd.WeatherInformationSpecificDataActivity"));
-        //            intent.putExtra("CHOSEN_DAY", (int) id);
-        //            WeatherInformationOverviewFragment.this.getActivity().startActivity(intent);
-        //        } else {
-        //            // tablet layout
-        //            fragment.getWeatherByDay((int) id);
-        //        }
+        final WeatherInformationSpecificDataFragment fragment = (WeatherInformationSpecificDataFragment) this
+                .getFragmentManager().findFragmentById(R.id.weather_specific_data__fragment);
+        if (fragment == null) {
+            // handset layout
+            final Intent intent = new Intent("de.example.exampletdd.WEATHERINFO")
+            .setComponent(new ComponentName("de.example.exampletdd",
+                    "de.example.exampletdd.WeatherInformationSpecificDataActivity"));
+            intent.putExtra("CHOSEN_DAY", (int) id);
+            WeatherInformationOverviewFragment.this.getActivity().startActivity(intent);
+        } else {
+            // tablet layout
+            fragment.getWeatherByDay((int) id);
+        }
     }
 
     @Override
@@ -279,8 +283,8 @@ public class WeatherInformationOverviewFragment extends ListFragment implements
 
         @Override
         protected void onPreExecute() {
-            this.newFragment.show(WeatherInformationOverviewFragment.this.getActivity()
-                    .getFragmentManager(), "progressDialog");
+            this.newFragment.show(WeatherInformationOverviewFragment.this.getFragmentManager(),
+                    "progressDialog");
         }
 
         @Override
index 089146f..85b4d1e 100644 (file)
@@ -8,13 +8,13 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 
-import android.app.DialogFragment;
-import android.app.ListFragment;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.ListFragment;
 import android.widget.ListView;
 import de.example.exampletdd.R;
 import de.example.exampletdd.activityinterface.GetWeather;