package jp.frdevel.letitflow;

import android.location.Location;
import android.util.Log;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlayOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


/**
 * Some important variables...
 * protected GoogleMap mMap;
 * protected Location mCurrentLocation;
 * protected String mLastUpdateTime;
 *
 * Some important callbacks...
 * public void onLocationChanged(Location location)
 * public void checkLocationSettings()
 * protected void initializeMap()
 * protected List<MapsDrawerItem> getSliderItem()
 * public void onItemClick(AdapterView<?> parent, View view, int pos, long id)
 * public boolean onOptionsItemSelected(MenuItem item)
 */
public class MapsActivity extends MapsActivityBase {

    protected final String TAG = "FireRubyDev MapGPSample";

    private Marker mMarker;
    private GroundOverlayOptions mOverlay;

    @Override
    public void onResume() {
        super.onResume();
        checkLocationSettings();
    }

    @Override
    public void initializeMap() {
        mMap.moveCamera(CameraUpdateFactory.zoomTo(15.0f));
        mMarker = mMap.addMarker(new MarkerOptions()
                .position(new LatLng(0, 0)).visible(false));
        mMarker.setTitle("your position");
        // TODO Retrieve image from server: This is local
        LatLngBounds bounds = new LatLngBounds(
                new LatLng(  33.88480983,  134.6542902),
                new LatLng(  33.91108717,  134.6806122)
        );
        mOverlay = new GroundOverlayOptions()
                .image(BitmapDescriptorFactory.fromResource(R.mipmap.hazard))
                .positionFromBounds(bounds);
        mMap.addGroundOverlay(mOverlay);
    }

    @Override
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
        Log.i(TAG, location.toString());

        if(!mMarker.isVisible())
            mMarker.setVisible(true);
        mMarker.setPosition(new LatLng(
                location.getLatitude(), location.getLongitude()));

        mMap.animateCamera(CameraUpdateFactory.newLatLng(
                new LatLng(location.getLatitude(), location.getLongitude())
        ));
    }

}

@@ -82,16 +82,106 @@
 til.Log;
+%0Aimport android.view.View;%0Aimport android.widget.AdapterView;%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -568,16 +568,177 @@
 ptions;%0A
+import com.google.android.gms.maps.model.Polyline;%0Aimport com.google.android.gms.maps.model.PolylineOptions;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A
 %0A%0A/**%0A *
@@ -2131,16 +2131,17 @@
 p.hazard
+3
 ))%0A     
@@ -2691,24 +2691,24 @@
 ongitude())%0A
-
         ));%0A
@@ -2714,10 +2714,1147 @@
 %0A    %7D%0A%0A
+    @Override%0A    protected List%3CMapsDrawerItem%3E getSliderItem() %7B%0A        ArrayList%3CMapsDrawerItem%3E ret = new ArrayList%3CMapsDrawerItem%3E();%0A        ret.add(new MapsDrawerItem(%22Map%22, R.mipmap.icon_map));%0A        ret.add(new MapsDrawerItem(%22Config%22, R.mipmap.icon_config));%0A        ret.add(new MapsDrawerItem(%22About%22, R.mipmap.ic_launcher));%0A        return ret;%0A    %7D%0A%0A    @Override%0A    public void onItemClick(AdapterView%3C?%3E parent, View view, int pos, long id) %7B%0A        if(pos == 0) %7B // open map%0A%0A        %7D else if(pos == 1) %7B // open config%0A%0A        %7D else if(pos == 2) %7B // about%0A            Toast.makeText(this,%0A                    %22Let it Flow version alpha%22,%0A                    Toast.LENGTH_LONG).show();%0A        %7D%0A    %7D%0A%0A    // TODO need test%0A    private void drawPath(List%3CLatLng%3E path) %7B%0A        // Instantiates a new Polyline object and adds points to define a rectangle%0A        PolylineOptions pathOptions = new PolylineOptions();%0A        for(LatLng p: path) %7B%0A            pathOptions = pathOptions.add(p);%0A        %7D%0A        // Get back the mutable Polyline%0A        Polyline polyline = mMap.addPolyline(pathOptions);%0A    %7D%0A%0A
 %7D%0A

update hazard map overlay(from image)