package fr.tvbarthel.apps.sayitfromthesky;


import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.UiSettings;

public class SayItFragment extends Fragment implements SayItMapFragment.ISayItMapFragment {

    private SayItMapFragment mMapFragment;
    private GoogleMap mGoogleMap;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_say_it, container, false);
        mMapFragment = new SayItMapFragment(this);
        getFragmentManager().beginTransaction().add(R.id.fragment_say_it_map_container, mMapFragment, "fragmentTagMap").commit();
        return view;
    }

    @Override
    public void onMapReady() {
        Log.d("argonne", "map ready !");
        if (mGoogleMap == null) {
            mGoogleMap = mMapFragment.getMap();
            if (mGoogleMap != null) {
                Log.d("argonne", "map is active !");
                mGoogleMap.setMyLocationEnabled(true);
                final UiSettings uiSettings = mGoogleMap.getUiSettings();
                uiSettings.setCompassEnabled(false);
                uiSettings.setZoomControlsEnabled(false);
            }
        }
    }

}

@@ -86,17 +86,25 @@
 oid.
-os.Bundle
+location.Location
 ;%0Aim
@@ -120,16 +120,17 @@
 oid.
-util.Log
+os.Bundle
 ;%0Aim
@@ -221,16 +221,72 @@
 Group;%0A%0A
+import com.google.android.gms.maps.CameraUpdateFactory;%0A
 import c
@@ -369,16 +369,65 @@
 ettings;
+%0Aimport com.google.android.gms.maps.model.LatLng;
 %0A%0Apublic
@@ -513,16 +513,230 @@
 ment %7B%0A%0A
+    private static float DEFAULT_VALUE_ZOOM = 15f;%0A    private static String BUNDLE_KEY_LOCATION = %22SayItFragment.Bundle.Key.Location%22;%0A    private static String BUNDLE_KEY_ZOOM = %22SayItFragment.Bundle.Key.Zoom%22;%0A%0A
     priv
@@ -803,16 +803,91 @@
 ogleMap;
+%0A    private Location mLastKnownLocation;%0A    private float mLastKnownZoom;
 %0A%0A    @O
@@ -1271,121 +1271,686 @@
 ();%0A
-        return view;%0A    %7D%0A%0A    @Override%0A    public void onMapReady() %7B%0A        Log.d(%22argonne%22, %22map ready !%22);
+%0A        mLastKnownZoom = DEFAULT_VALUE_ZOOM;%0A%0A        if (savedInstanceState != null) %7B%0A            mLastKnownLocation = savedInstanceState.getParcelable(BUNDLE_KEY_LOCATION);%0A            mLastKnownZoom = savedInstanceState.getFloat(BUNDLE_KEY_ZOOM, DEFAULT_VALUE_ZOOM);%0A        %7D%0A%0A        return view;%0A    %7D%0A%0A    @Override%0A    public void onSaveInstanceState(Bundle outState) %7B%0A        super.onSaveInstanceState(outState);%0A        outState.putParcelable(BUNDLE_KEY_LOCATION, mLastKnownLocation);%0A        if (mGoogleMap != null) %7B%0A            outState.putFloat(BUNDLE_KEY_ZOOM, mGoogleMap.getCameraPosition().zoom);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onMapReady() %7B
 %0A   
@@ -2086,44 +2086,54 @@
     
-Log.d(%22argonne%22, %22
+//the 
 map is 
+now 
 active 
-!%22);
+and can be manipulated
 %0A   
@@ -2373,31 +2373,897 @@
 e);%0A
-            %7D%0A        %7D
+%0A                //try to restore last known location%0A                if (mLastKnownLocation != null) %7B%0A                    initMapLocation();%0A                %7D%0A%0A                mGoogleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() %7B%0A                    @Override%0A                    public void onMyLocationChange(Location location) %7B%0A                        //first location%0A                        if (mLastKnownLocation == null) %7B%0A                            mLastKnownLocation = location;%0A                            initMapLocation();%0A                        %7D%0A                    %7D%0A                %7D);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void initMapLocation() %7B%0A        mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(%0A                new LatLng(mLastKnownLocation.getLatitude(), mLastKnownLocation.getLongitude()), mLastKnownZoom));
 %0A   

Initialize the map and the location