<commit_before>package adullact.publicrowdfunding.controller.project.details;

import adullact.publicrowdfunding.R;
import adullact.publicrowdfunding.model.local.cache.Cache;
import adullact.publicrowdfunding.model.local.callback.HoldToDo;
import adullact.publicrowdfunding.model.local.ressource.Project;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

/**
 * @author Ferrand and Nelaupe
 */
public class MapFragment extends Fragment {

	private SupportMapFragment fragment;
	private FragmentManager fm;

	private Project projetCurrent;

	View rootView;
	GoogleMap googleMap;
	

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		System.out.println("Load Google Map Fragment");

		try {
			rootView = inflater.inflate(R.layout.activity_maps, container,
					false);
			setMapFocus();
		} catch (Exception e) {
			TextView text = new TextView(getActivity());
			text.setText("Impossible de charger Google Map");
			return text;
		}

		Bundle bundle = this.getArguments();
		if (bundle != null) {
			String idProject = bundle.getString("idProject");
			Cache<Project> projet = new Project().getCache(idProject);
			projet.toResource(new HoldToDo<Project>() {
				@Override
				public void hold(Project project) {

					try {
						fragment = new SupportMapFragment();
						fm = getFragmentManager();

						FragmentTransaction ft = fm.beginTransaction();
						ft.replace(R.id.mapView, fragment, "mapProjectDetail")
								.commit();

						projetCurrent = project;
						final Handler handler = new Handler();
						handler.postDelayed(new Runnable() {

							@Override
							public void run() {

								System.out.println("rortation");
								Fragment fr = fm
										.findFragmentByTag("mapProjectDetail");
								System.out.println("fr : "+fr);
								
								if(fr == null){
									handler.postDelayed(this, 500);
								}else{
								googleMap = ((SupportMapFragment) fr).getMap();
								}
								if (googleMap != null) {
									displayInfo();
									handler.removeCallbacksAndMessages(null);

								} else {
									handler.postDelayed(this, 1000);
								}
							}
						}, 500);

					} catch (Exception e) {
						TextView text = new TextView(getActivity());
						text.setText("Impossible de charger Google Map");
						rootView = text;
					}
				}
			});
		}
		setMapFocus();
		return rootView;
	}

	public void displayInfo() {
		MarkerOptions marker = new MarkerOptions();
		marker.position(projetCurrent.getPosition());
		marker.snippet(projetCurrent.getDescription());
		googleMap.addMarker(marker);

		setMapFocus();

	}
	
	public void setMapFocus(){
		if(googleMap != null){
			CameraPosition camera = googleMap.getCameraPosition();
			LatLng position = camera.target;
			if(position != projetCurrent
					.getPosition()){
				CameraUpdate positionProject = CameraUpdateFactory.newLatLng(projetCurrent
						.getPosition());
				CameraUpdate zoom = CameraUpdateFactory.zoomTo(9);
				googleMap.moveCamera(positionProject);
				googleMap.animateCamera(zoom);
				
			}
		}
	}
	
	public void onPause(){
		super.onPause();
		this.getActivity().getSupportFragmentManager().beginTransaction().detach(fragment).commit();
	}
	
	public void onResume(){
		super.onResume();
		setMapFocus();
	}

}<commit_msg>Fix bug rotation google map mais du coup des fois maps ne s'affiche pas. Je sais pourquoi.<commit_after>package adullact.publicrowdfunding.controller.project.details;

import adullact.publicrowdfunding.R;
import adullact.publicrowdfunding.model.local.cache.Cache;
import adullact.publicrowdfunding.model.local.callback.HoldToDo;
import adullact.publicrowdfunding.model.local.ressource.Project;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

/**
 * @author Ferrand and Nelaupe
 */
public class MapFragment extends Fragment {

	private SupportMapFragment fragment;
	private FragmentManager fm;

	private Project projetCurrent;

	View rootView;
	GoogleMap googleMap;
	

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		System.out.println("Load Google Map Fragment");

		try {
			rootView = inflater.inflate(R.layout.activity_maps, container,
					false);
			setMapFocus();
		} catch (Exception e) {
			TextView text = new TextView(getActivity());
			text.setText("Impossible de charger Google Map");
			return text;
		}

		Bundle bundle = this.getArguments();
		if (bundle != null) {
			String idProject = bundle.getString("idProject");
			Cache<Project> projet = new Project().getCache(idProject);
			projet.toResource(new HoldToDo<Project>() {
				@Override
				public void hold(Project project) {

					try {
						fragment = new SupportMapFragment();
						fm = getFragmentManager();

						FragmentTransaction ft = fm.beginTransaction();
						ft.replace(R.id.mapView, fragment, "mapProjectDetail")
								.commit();

						projetCurrent = project;
						final Handler handler = new Handler();
						handler.postDelayed(new Runnable() {

							@Override
							public void run() {

								System.out.println("rortation");
								Fragment fr = fm
										.findFragmentByTag("mapProjectDetail");
								System.out.println("fr : "+fr);
								
								if(fr == null){
									handler.postDelayed(this, 500);
								}else{
								googleMap = ((SupportMapFragment) fr).getMap();
								}
								if (googleMap != null) {
									displayInfo();
									handler.removeCallbacksAndMessages(null);

								} else {
									handler.postDelayed(this, 1000);
								}
							}
						}, 500);

					} catch (Exception e) {
						TextView text = new TextView(getActivity());
						text.setText("Impossible de charger Google Map");
						rootView = text;
					}
				}
			});
		}
		setMapFocus();
		return rootView;
	}

	public void displayInfo() {
		MarkerOptions marker = new MarkerOptions();
		marker.position(projetCurrent.getPosition());
		marker.snippet(projetCurrent.getDescription());
		googleMap.addMarker(marker);

		setMapFocus();

	}
	
	public void setMapFocus(){
		if(googleMap != null){
			CameraPosition camera = googleMap.getCameraPosition();
			LatLng position = camera.target;
			if(position != projetCurrent
					.getPosition()){
				CameraUpdate positionProject = CameraUpdateFactory.newLatLng(projetCurrent
						.getPosition());
				CameraUpdate zoom = CameraUpdateFactory.zoomTo(9);
				googleMap.moveCamera(positionProject);
				googleMap.animateCamera(zoom);
				
			}
		}
	}
	
	public void onPause(){
		super.onPause();
		this.getActivity().getSupportFragmentManager().beginTransaction().detach(fragment).commit();
		this.getActivity().getSupportFragmentManager().beginTransaction().detach(this).commit();
	}
	
	public void onResume(){
		super.onResume();
		setMapFocus();
	}

}
{'fraction_non_alphanumeric': 0.11514778325123153, 'fraction_numerical': 0.0034482758620689655, 'mean_word_length': 3.718768158047647, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945077', 'n_tokens_mistral': 3043, 'n_tokens_neox': 2363, 'n_words': 477}