package com.nestedworld.nestedworld.fragment.mainMenu.tabs;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.nestedworld.nestedworld.R;
import com.nestedworld.nestedworld.fragment.base.BaseFragment;

import butterknife.Bind;

/**
 * A placeholder fragment containing a simple view.
 */
public class MapFragment extends BaseFragment {

    public final static String FRAGMENT_NAME = MapFragment.class.getSimpleName();

    @Bind(R.id.mapView)
    MapView mMapView;

    public static void load(@NonNull final FragmentManager fragmentManager) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(R.anim.fade_out, R.anim.fade_in);
        fragmentTransaction.addToBackStack(FRAGMENT_NAME);
        fragmentTransaction.commit();
    }

    /*
    ** Life cycle
     */
    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_tab_map;
    }

    @Override
    protected void initUI(Bundle savedInstanceState) {
        mMapView.onCreate(savedInstanceState);
        mMapView.onResume();//We display the map immediately

        try {
            MapsInitializer.initialize(getActivity().getApplicationContext());
        } catch (Exception e) {
            e.printStackTrace();
        }

        GoogleMap googleMap = mMapView.getMap();

        // create marker
        MarkerOptions marker = new MarkerOptions().position(new LatLng(-34, 151)).title("Hello Maps");

        // Changing marker icon
        marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));

        // adding marker
        googleMap.addMarker(marker);
        CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(-34, 151)).zoom(12).build();
        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }

    @Override
    protected void initLogic(Bundle savedInstanceState) {

    }

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

    @Override
    public void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mMapView.onLowMemory();
    }
}

@@ -2572,24 +2572,60 @@
 onResume();%0A
+        if (mMapView != null) %7B%0A    
         mMap
@@ -2637,24 +2637,34 @@
 onResume();%0A
+        %7D%0A
     %7D%0A%0A    @
@@ -2721,24 +2721,60 @@
 .onPause();%0A
+        if (mMapView != null) %7B%0A    
         mMap
@@ -2785,24 +2785,34 @@
 .onPause();%0A
+        %7D%0A
     %7D%0A%0A    @
@@ -2873,24 +2873,60 @@
 nDestroy();%0A
+        if (mMapView != null) %7B%0A    
         mMap
@@ -2939,24 +2939,34 @@
 nDestroy();%0A
+        %7D%0A
     %7D%0A%0A    @
@@ -3031,24 +3031,60 @@
 owMemory();%0A
+        if (mMapView != null) %7B%0A    
         mMap
@@ -3099,20 +3099,30 @@
 owMemory();%0A
+        %7D%0A
     %7D%0A%7D%0A

solve crash