package com.example.geo_api16;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.location.Address;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

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.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;


import com.google.android.gms.maps.model.LatLng;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

// [{   "error_message" : "You have exceeded your daily request quota for this API.",   "predictions" : [],   "status" : "OVER_QUERY_LIMIT"}]

//{"status":"OVER_QUERY_LIMIT","routes":[],"error_message":"You have exceeded your daily request quota for this API. We recommend registering for a key at the Google Developers Console: https:\/\/console.developers.google.com\/apis\/credentials?project=_"}


//  https://console.developers.google.com/apis/credentials?project=_

public class MainActivity extends FragmentActivity 
{

	AutoCompleteTextView atvPlaces;
	AutoCompleteTextView arrivalPlaces;
	    
	PlacesTask_departure placesTask_departure;
	ParserTask_departure parserTask_departure;
		
	PlacesTask_destination placesTask_destination;
	ParserTask_destination parserTask_destination;

	static GoogleMap map;
	
	AutoCompleteTextView depart;
	AutoCompleteTextView arrive;
	
	String departure = "";
	String arrival = "";

	static String global_departure = "";
	static String global_arrival = "";
	static String global_data = "";
	
	static ArrayList<LatLng> locations = new ArrayList();
	
	private ProgressDialog progressdialog;
	
	static LinkedList<String[]> html_instructions_list = new LinkedList<>();
	
	static String distance = "";
	static String duration = "";	
	

	ArrayList markerPoints;
	Dialog dialog;
	AlertDialog.Builder alertDialog;
	EditText et_departure, et_destination;
	Button btn_find, btn_cancel, btn_direction, btn_trajet, btn_scale;
	String test_message_address_departure = "";
	String test_message_address_destination = "";
	boolean flag_address_departure = true;
	boolean flag_address_destination = true;
	int test_sequence = 0;
	TextView tvDistanceDuration;
	

	ArrayList<String> names;
    JSONObject json;
    String url;
  
    ArrayAdapter<String> adapter;
    
    private MapScaleView scaleView;
    private MapScaleView scaleViewMiles;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	
		SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); 
		
		map = mapFragment.getMap();
		
		map.setMyLocationEnabled(true);		
		map.setIndoorEnabled(true);
		map.getUiSettings().setZoomControlsEnabled(true);
		map.getUiSettings().setMyLocationButtonEnabled(true);
		map.getUiSettings().setCompassEnabled(true);
		map.getUiSettings().setAllGesturesEnabled(true);
		
		fonctions();
		
		// scaleView = (MapScaleView) findViewById(R.id.scaleView);
		// scaleViewMiles = (MapScaleView) findViewById(R.id.scaleViewMiles);
		
		//Add Scale Bar
        //ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
        //myOpenMapView.getOverlays().add(myScaleBarOverlay);
		
		/* RelativeLayout container = (RelativeLayout) findViewById(R.id.ecran);
		    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(800, 800);

		    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
		    params.addRule(RelativeLayout.CENTER_VERTICAL);

		    ScaleBar mScaleBar = new ScaleBar(this, map);
		    mScaleBar.setLayoutParams(params);
		*/
	}
		
	public void fonctions()
	{

			Toast.makeText(getApplicationContext(), "DEBUG 16 + html_descriptions...", Toast.LENGTH_LONG).show();
		
		    depart = (AutoCompleteTextView) findViewById(R.id.departure_places);
	        depart.setThreshold(5);
	        
	        arrive = (AutoCompleteTextView) findViewById(R.id.arrival_places);
	        arrive.setThreshold(5);
	        
	        depart.addTextChangedListener(new TextWatcher()
	        {
	        	 
		            @Override
		            public void onTextChanged(CharSequence s, int start, int before, int count)
		            {
		            	placesTask_departure = new PlacesTask_departure();
		            	placesTask_departure.execute(s.toString());
		            }
		 
		            @Override
		            public void beforeTextChanged(CharSequence s, int start, int count, int after)
		            {
		                
		            }
		 
		            @Override
		            public void afterTextChanged(Editable s) 
		            {
		              
		            }
	        });
	        
	        arrive.addTextChangedListener(new TextWatcher()
	        {
	        	 
		            @Override
		            public void onTextChanged(CharSequence s, int start, int before, int count)
		            {
		            	placesTask_destination = new PlacesTask_destination();
		            	placesTask_destination.execute(s.toString());
		            }
		 
		            @Override
		            public void beforeTextChanged(CharSequence s, int start, int count, int after)
		            {
		                
		            }
		 
		            @Override
		            public void afterTextChanged(Editable s) 
		            {
		              
		            }
	        });
	
			
		btn_direction = (Button) findViewById(R.id.btn_calculation);
    	btn_direction.setOnClickListener(new View.OnClickListener() 
        {
                @Override
                public void onClick(View v) 
                {
                	
                		if (depart.getText().toString().isEmpty() || arrive.getText().toString().isEmpty())
                        {
                            Toast.makeText(getApplicationContext(), "Text fields cannot be empty", Toast.LENGTH_SHORT).show();
                        } 
                        else 
                        {
                        	
                      
                        	departure = depart.getText().toString();
                        	arrival = arrive.getText().toString();
                        	
                        	ArrayList<String> list=new ArrayList<String>();  
                        	
                        	departure = departure.replaceAll(",", " ");
                        	arrival = arrival.replaceAll(",", " ");
                        	
                        	
                        	list.add(departure);  
                        	list.add(arrival);  
                        	
                        	map.clear();
                        	
                        	new GeocoderTask().execute(list);
                        	
                        	//new cocoTask().execute(list);
                        }	
                	
                }
        });
    	
    	
    	btn_trajet = (Button) findViewById(R.id.btn_trajet);
    	
    	btn_trajet.setEnabled(false); 
    	
    	
    	btn_trajet.setOnClickListener(new View.OnClickListener() 
        {
                @Override
                public void onClick(View v) 
                {
                	    Toast.makeText(getApplicationContext(), "Voir les infos", Toast.LENGTH_SHORT).show();
						Intent Intent = new Intent(getApplicationContext(),CustomTrajetListview.class);
						String str_concate = departure + " " + arrival + " " + distance + " " + duration;
						Intent.putExtra("infos_trajet", str_concate);
						startActivity(Intent);
                }
        });
    	
    	
    	btn_scale = (Button) findViewById(R.id.btn_scale);
    	btn_scale.setOnClickListener(new View.OnClickListener() 
        {
                @Override
                public void onClick(View v) 
                {
                	    Toast.makeText(getApplicationContext(), "Scale demo", Toast.LENGTH_SHORT).show();
						Intent Intent = new Intent(getApplicationContext(), demo_scale.class);
						//String str_concate = departure + " " + arrival + " " + distance + " " + duration;
						//Intent.putExtra("infos_trajet", str_concate);
						startActivity(Intent);
                }
        });
    	
    	
    	
    	 map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() 
		 {
	            @Override
	            public void onMapLongClick(LatLng point) 
	            {
	            	//https://stackoverflow.com/questions/12244297/how-to-add-multiple-buttons-on-a-single-alertdialog
	            	// https://android--code.blogspot.fr/2015/08/android-alertdialog-multichoice.html
	            	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
	                builder.setTitle("MAP Type");
	                builder.setItems(new CharSequence[] {"None", "Normale", "Satellite", "Hybrid", "Terrain"}, new DialogInterface.OnClickListener() 
	                {
	                            public void onClick(DialogInterface dialog, int which) 
	                            {
	                                switch (which) 
	                                {
	                                    case 0:
	                                    	map.setMapType(GoogleMap.MAP_TYPE_NONE);         
	                                        break;
	                                    case 1:
	                                    	map.setMapType(GoogleMap.MAP_TYPE_NORMAL);      
	                                        break;
	                                    case 2:
	                                    	map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);   
	                                        break;
	                                    case 3:
	                                    	map.setMapType(GoogleMap.MAP_TYPE_HYBRID);      
	                                        break;
	                                    case 4:
	                                    	map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);      
	                                        break;    
	                                }
	                            }
	                });
	                builder.create().show();
	            }
	     });
    	
		
	}
	
	/************** Asynchron class ******************/
	
	private class GeocoderTask extends AsyncTask< ArrayList<String>, Void, String >
    {
 
		//http://www.androidtrainee.com/driving-distance-and-travel-time-duration-between-two-locations-in-google-map-android-api-v2/
		
		Context mContext;
		String str_departure = "";
	 	String str_destination = "";
		
        @Override
        protected String  doInBackground(ArrayList<String>... passing) 
        {
            	
        		List<Address> addresses_departure = null;
            	List<Address> addresses_destination = null;
            
            	ArrayList<String> tmp_array = passing[0]; 
            	String local_departure = tmp_array.get(0);
            	String local_destination = tmp_array.get(1);
            	
            	find_location_info(local_departure);
            	find_location_info(local_destination);
            	
            	double lat1 = MainActivity.locations.get(0).latitude;
            	double lng1 = MainActivity.locations.get(0).longitude;
            	String str_origin = "origin=" +lat1 + "," + lng1;

    	        double lat2 = MainActivity.locations.get(1).latitude;
            	double lng2 = MainActivity.locations.get(1).longitude;
    	        String str_dest = "destination=" + lat2 + "," + lng2;

    	        String sensor = "sensor=false";

    	        String parameters = str_origin + "&" + str_dest + "&" + sensor + "&language=fr";
    	        String output = "json";
    	        String strUrl = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters;
            	
            	
//            	 String strUrl = "https://maps.googleapis.com/maps/api/directions/json?origin=48.856614,2.3522219&destination=48.390394,-4.486076&sensor=false";
            	
    	        String data = "";
    	        InputStream iStream = null;
    	        HttpURLConnection urlConnection = null;
    	        try 
    	        {
    	            URL _url = new URL(strUrl);
    	            urlConnection = (HttpURLConnection) _url.openConnection();
    	            urlConnection.connect();
    	            iStream = urlConnection.getInputStream();

    	            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
    	            StringBuffer sb = new StringBuffer();

    	            String line = "";
    	            while ((line = br.readLine()) != null) 
    	            {
    	                sb.append(line);
    	            }

    	            data = sb.toString();
    	            
    	            MainActivity.global_data = sb.toString();
    	            
    	            Log.d("downloadUrl", data.toString());
    	            br.close();

    	        } 
    	        catch (Exception e) 
    	        {
    	            Log.d("Exception", e.toString());
    	        } 
    	        finally 
    	        {
    	            try
    	            {
						iStream.close();
					} 
    	            catch (IOException e)
    	            {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
    	            urlConnection.disconnect();
    	        }
 				
				JSONObject jObject;
				List<List<HashMap<String, String>>> routes = null;
	 
				try
				{
					jObject = new JSONObject(data);
					DirectionsJSONParser parser = new DirectionsJSONParser();
				 
					// Starts parsing data
					routes = parser.parse(jObject);
					
					List<HashMap<String, String>> path = routes.get(0);
					HashMap<String,String> point = path.get(0);
					distance = (String)point.get("distance");		
					
					// path = routes.get(0);
					point = path.get(1);
					duration = (String)point.get("duration");	
				}
				catch(Exception e)
				{
					e.printStackTrace();
				}
            	
            	return data;
          
        }
        
        
        @Override
    	protected void onPreExecute() 
        {
        		progressdialog = new ProgressDialog(MainActivity.this);
        		progressdialog.setMessage("Calcul du trajet");
        		progressdialog.setTitle("Please Wait...");
        		progressdialog.show();
    	}
 
        @Override
        protected void onPostExecute(String data)
        {
        		draw_direction(data);
        	    draw_markers();
        	    
        		if(progressdialog.isShowing()) 
        		{
        			progressdialog.dismiss();
        			String str = distance +" " + duration;
                    Toast.makeText(getApplicationContext(), str , Toast.LENGTH_SHORT).show();
        			locations.clear();
                    
        		}
        		
        		
        		/***/
        		JSONObject jObject = null;
	    		
	    		JSONArray jRoutes = null;
	    		JSONObject jRoute;
	    		
	    		JSONArray jLegs = null;
	    		JSONObject jLeg;
	    		
	    		JSONArray jSteps = null;
	    		JSONObject jStep;
	    		
	    		JSONObject jDistance = null;
				JSONObject jDuration = null;
	 
	    		try 
	    		{
	    			
	    			String filenamex = "infos_filename.txt";
	    			File filex = new File(Environment.getExternalStorageDirectory(), filenamex);
	    			FileOutputStream fosx = new FileOutputStream(filex);  
	        		BufferedWriter bwx = new BufferedWriter(new OutputStreamWriter(fosx));
	    			
	    			// https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/blob/master/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/parser/DirectionsJSONParser.java
	    			
	    			jObject = new JSONObject(data);

	    			jRoutes = jObject.getJSONArray("routes");
	    			for (int i = 0; i < jRoutes.length(); i++) 
	    			{
	    				jRoute=(JSONObject) jRoutes.get(i);
	    				jLegs = jRoute.getJSONArray("legs");
	    				for (int j = 0; j < jLegs.length(); j++) 
	    				{
	    					jLeg=(JSONObject) jLegs.get(j);
	    					jSteps = jLeg.getJSONArray("steps");
	    					for (int k = 0; k < jSteps.length(); k++) 
	    					{
	    						jStep = (JSONObject) jSteps.get(k);
	    						String polyline = (String) ((JSONObject) (jStep).get("polyline")).get("points");
	    						
	    						String str_distance = (String) ((JSONObject) (jStep).get("distance")).get("text");
	    						String str_duration = (String) ((JSONObject) (jStep).get("duration")).get("text");
	    						String str_instructions =  (jStep).getString("html_instructions").replaceAll("<(.*?)*>", "");
	    						//String str_travel_mode = (String) ((JSONObject) (jStep).get("travel_mode")).get("text");
	    						//String d =  (jStep).getString("maneuver") ; 
	    						String concate = str_distance + "*" + str_duration + "*" + str_instructions;
	    						bwx.write(concate);
	    		           		bwx.newLine();
	    					}
	    					// close file	
	    					bwx.close();
	    					
	    				}
	    				
	    			}
	    			
		            
		      } 
		      catch (Exception e)
	     	  {
		    	  e.printStackTrace();
		      }
	    		
        		
	    		btn_trajet.setEnabled(true); 
        		
        		
        }
	
        private void find_location_info(String place ) 
        {
		
        		String url = "https://maps.googleapis.com/maps/api/geocode/json?";					
		
        		try 
				{
					place = URLEncoder.encode(place, "utf-8");
				} 
				catch (UnsupportedEncodingException e)
				{
					e.printStackTrace();
				}
		
				String address = "address=" + place;
				String sensor = "sensor=false";
				String strurl = url + address + "&" + sensor;
		
				String data = "";
				InputStream iStream = null;
				HttpURLConnection urlConnection = null;
	        
				try
				{
					URL _url = new URL(strurl);
					urlConnection = (HttpURLConnection) _url.openConnection();
					urlConnection.connect();
					iStream = urlConnection.getInputStream();

					BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

					StringBuffer sb  = new StringBuffer();

					String line = "";
					while( ( line = br.readLine())  != null)
					{
                        sb.append(line);
					}

					data = sb.toString();

					br.close();
	                
					JSONObject jsonObject = new JSONObject(data);
					JSONArray jsonArray = (JSONArray) jsonObject.get("results");
                    
					if (jsonArray.length() > 0) 
					{
						jsonObject = (JSONObject) jsonArray.get(0);
		                jsonObject = (JSONObject) jsonObject.get("geometry");
		                JSONObject location = (JSONObject) jsonObject.get("location");
		                Double lat = (Double) location.get("lat");
		                Double lng = (Double) location.get("lng");
		                System.out.println("lat - " + lat + " , lon - " + lng);
		                locations.add(new LatLng(lat, lng));
					}
				}
	        
				catch(Exception e)
				{
					Log.d("Exception while downloading url", e.toString());
				}
	        
				finally
				{
					try
				    {
						iStream.close();
					} 
				    catch (IOException e) 
				    {
				    	e.printStackTrace();
					}
				    urlConnection.disconnect();
				}
		
		}
	
		private void draw_direction(String data)
		{
    	 		JSONObject jObject;
         		List<List<HashMap<String, String>>> routes = null;

         		try 
         		{
         			jObject = new JSONObject(data);
         			Log.d("ParserTask",data.toString());
         			DataParser parser = new DataParser();
         			Log.d("ParserTask", parser.toString());
		
         			routes = parser.parse(jObject);
         			Log.d("ParserTask","Executing routes");
         			Log.d("ParserTask",routes.toString());

         		} 
         		catch (Exception e)
         		{
             		Log.d("ParserTask",e.toString());
             		e.printStackTrace();
         		}
         
         		ArrayList<LatLng> points;
         		PolylineOptions lineOptions = null;

			    for (int i = 0; i < routes.size(); i++)
			    {
			    	points = new ArrayList<>();
			        lineOptions = new PolylineOptions();
			
			        List<HashMap<String, String>> path = routes.get(i);
			
			        for (int j = 0; j < path.size(); j++)
			        {
			        	HashMap<String, String> point = path.get(j);
			         	double lat = Double.parseDouble(point.get("lat"));
			         	double lng = Double.parseDouble(point.get("lng"));
			         	LatLng position = new LatLng(lat, lng);
			         	points.add(position);
			         }
			
			         lineOptions.addAll(points);
			         lineOptions.width(2); // 10
			         lineOptions.color(Color.RED);
			
			         Log.d("onPostExecute","onPostExecute lineoptions decoded");
			
			    }
        
			    if(lineOptions != null) 
			    {
			       	MainActivity.map.addPolyline(lineOptions);
			    }
			    else 
			    {
			      	Log.d("onPostExecute","without Polylines drawn");
			    }
       
		}
	
		private void draw_markers()
		{
				
				MarkerOptions options = new MarkerOptions();
				
				LatLng position =  MainActivity.locations.get(0);
				options.position(position);
				Double a = position.latitude;
				Double b = position.longitude;
				String str1 = String.valueOf(a);
				String str2 = String.valueOf(b);
				String title = departure + " (départ)";  
				options.title(title);
				String infos = str1 + " " + str2; 
				options.snippet(infos);
				options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
				MainActivity.map.addMarker(options);
					
				position =  MainActivity.locations.get(1);
				options.position(position);
				a = position.latitude;
				b = position.longitude;
				str1 = String.valueOf(a);
				str2 = String.valueOf(b);
				title = arrival + " (arrivée)";
				options.title(title);
				infos = str1 + " " + str2; 
				options.snippet(infos);
				options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
				MainActivity.map.addMarker(options);
					
		}
    
    }
	
	///////////////////// insertion 
	
	private class cocoTask extends AsyncTask< ArrayList<String>, Void, String >
    {
 
		Context mContext;
		String str_departure = "";
	 	String str_destination = "";
		
        @Override
        protected String  doInBackground(ArrayList<String>... passing) 
        {
        	
        	//https://developers.google.com/maps/documentation/directions/intro?hl=fr
            	
            	//String strUrl = "https://maps.googleapis.com/maps/api/directions/json?origin=48.856614,2.3522219&destination=48.390394,-4.486076&sensor=false";
            	
            	String strUrl = "https://maps.googleapis.com/maps/api/directions/json?origin=48.856614,2.3522219&destination=48.390394,-4.486076&sensor=false&language=fr";
            	
            	
    	        String data = "";
    	        InputStream iStream = null;
    	        HttpURLConnection urlConnection = null;
    	        
    	        try 
    	        {
    	            URL _url = new URL(strUrl);
    	            urlConnection = (HttpURLConnection) _url.openConnection();
    	            urlConnection.connect();
    	            iStream = urlConnection.getInputStream();

    	            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
    	            StringBuffer sb = new StringBuffer();

    	            String line = "";
    	            while ((line = br.readLine()) != null) 
    	            {
    	                sb.append(line);
    	            }

    	            data = sb.toString();
    	            
    	            MainActivity.global_data = sb.toString();
    	            
    	            Log.d("downloadUrl", data.toString());
    	            br.close();

    	        } 
    	        catch (Exception e) 
    	        {
    	            Log.d("Exception", e.toString());
    	        } 
    	        finally 
    	        {
    	            try
    	            {
						iStream.close();
					} 
    	            catch (IOException e)
    	            {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
    	            urlConnection.disconnect();
    	        }
            	
            	return data;
          
        }
        
        
        @Override
    	protected void onPreExecute() 
        {
        		progressdialog = new ProgressDialog(MainActivity.this);
        		progressdialog.setMessage("Calcul du trajet");
        		progressdialog.setTitle("Please Wait...");
        		progressdialog.show();
    	}
 
        @Override
        protected void onPostExecute(String data)
        {
        	
        	    
        		if(progressdialog.isShowing()) 
        		{
        			progressdialog.dismiss();
        			String str = distance +" " + duration;
                    Toast.makeText(getApplicationContext(), str , Toast.LENGTH_SHORT).show();
        			locations.clear();
                    
        		}
        		
        		htmlParserTask htmlparserTask = new htmlParserTask();
        	    htmlparserTask.execute(data);
        		
        }

    
    }

	/************** autocomplete departure ******************/
	
	private String downloadUrl_departure(String strUrl) throws IOException
	{
        String data = "";
        InputStream iStream = null;
        HttpURLConnection urlConnection = null;
        
        try
        {
        	URL url = new URL(strUrl);                

            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.connect();

            iStream = urlConnection.getInputStream();

            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

            StringBuffer sb  = new StringBuffer();
            String line = "";

            while( ( line = br.readLine())  != null)
            {
            	sb.append(line);
            }
                
            data = sb.toString();

            br.close();

        }
        catch(Exception e)
        {
        	Log.d("Exception while downloading url", e.toString());
        }
        finally
        {
        	iStream.close();
            urlConnection.disconnect();
        }
        
        return data;
     }	
	
	 private class PlacesTask_departure extends AsyncTask<String, Void, String>
	 {
		@Override
		protected String doInBackground(String... place)
		{
				// For storing data from web service
				String data = "";
				String key = "AIzaSyBXw9vydHGGjBOYSeM9i-Xh8f9Mk0xzg1k";
				String input="";
				
				try 
				{
					input = "input=" + URLEncoder.encode(place[0], "utf-8");
				} 
				catch (UnsupportedEncodingException e1) 
				{
					e1.printStackTrace();
				}		
				
				// 	place type to be searched
				String types = "types=geocode";
				// 	Sensor enabled
				String sensor = "sensor=false";			
				
				String parameters = input+"&"+types+"&"+sensor+"&key="+key;
				parameters = input+"&"+types+"&"+sensor+"&key="+key+"&components=country:FR";

				//Change input+”&”+types+”&”+sensor+”&”+key; ==> input+”&”+types+”&”+sensor+”&key=”+key;
				
				String output = "json";
				String url = "https://maps.googleapis.com/maps/api/place/autocomplete/"+output+"?"+parameters;
				
				//url = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&key=AIzaSyBXw9vydHGGjBOYSeM9i-Xh8f9Mk0xzg1k";
		
				try
				{
					data = downloadUrl_departure(url);
				}
				catch(Exception e)
				{
	                Log.d("Background Task",e.toString());
				}
				
				return data;		
				
				//  "error_message" : "This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/places_backend?project=_",   "predictions" : [],   "status" : "REQUEST_DENIED"}
		}
			
		@Override
		protected void onPostExecute(String result) 
		{			
				super.onPostExecute(result);
				
				// Creating ParserTask
				parserTask_departure = new ParserTask_departure();
				
				// Starting Parsing the JSON string returned by Web Service
				parserTask_departure.execute(result);
		}		
	}
	
	
	private class ParserTask_departure extends AsyncTask<String, Integer, List<HashMap<String,String>>>
	{

	    	JSONObject jObject;
	    	
			@Override
			protected List<HashMap<String, String>> doInBackground(String... jsonData) 
			{			
				
				List<HashMap<String, String>> places = null;
				
	            PlaceJSONParser placeJsonParser = new PlaceJSONParser();
	            
	            try{
	            	jObject = new JSONObject(jsonData[0]);
	            	
	            	// Getting the parsed data as a List construct
	            	places = placeJsonParser.parse(jObject);

	            }catch(Exception e){
	            	Log.d("Exception",e.toString());
	            }
	            return places;
			}
			
			@Override
			protected void onPostExecute(List<HashMap<String, String>> result) 
			{			
				
					String[] from = new String[] { "description"};
					int[] to = new int[] { android.R.id.text1 };
					
					// Creating a SimpleAdapter for the AutoCompleteTextView			
					SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), result, android.R.layout.simple_list_item_1, from, to);				
					
					// Setting the adapter
					depart.setAdapter(adapter);
			}			
	}    
	
		/************** autocomplete destination ******************/
	
	
	    private String downloadUrl_destination(String strUrl) throws IOException
	    {
	        String data = "";
	        InputStream iStream = null;
	        HttpURLConnection urlConnection = null;
	        try{
	                URL url = new URL(strUrl);                

	                // Creating an http connection to communicate with url 
	                urlConnection = (HttpURLConnection) url.openConnection();

	                // Connecting to url 
	                urlConnection.connect();

	                // Reading data from url 
	                iStream = urlConnection.getInputStream();

	                BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

	                StringBuffer sb  = new StringBuffer();

	                String line = "";
	                while( ( line = br.readLine())  != null){
	                        sb.append(line);
	                }
	                
	                data = sb.toString();

	                br.close();

	        }catch(Exception e){
	                Log.d("Exception while downloading url", e.toString());
	        }
	        finally
	        {
	                iStream.close();
	                urlConnection.disconnect();
	        }
	        
	        return data;
	    }	
	
		private class PlacesTask_destination extends AsyncTask<String, Void, String>
		{

			@Override
			protected String doInBackground(String... place) 
			{
				String data = "";
				String key = "AIzaSyBXw9vydHGGjBOYSeM9i-Xh8f9Mk0xzg1k";
				String input="";
				
				try 
				{
					input = "input=" + URLEncoder.encode(place[0], "utf-8");
				} 
				catch (UnsupportedEncodingException e1) 
				{
					e1.printStackTrace();
				}		
				
				
				// place type to be searched
				String types = "types=geocode";
				
				// Sensor enabled
				String sensor = "sensor=false";			
				
				// Building the parameters to the web service
				String parameters = input+"&"+types+"&"+sensor+"&key="+key;
				parameters = input+"&"+types+"&"+sensor+"&key="+key+"&components=country:FR";

				//Change input+”&”+types+”&”+sensor+”&”+key; ==> input+”&”+types+”&”+sensor+”&key=”+key;
				
				// Output format
				String output = "json";
				
				// Building the url to the web service
				String url = "https://maps.googleapis.com/maps/api/place/autocomplete/"+output+"?"+parameters;
				
				//url = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&key=AIzaSyBXw9vydHGGjBOYSeM9i-Xh8f9Mk0xzg1k";
		
				try
				{
					// Fetching the data from web service in background
					data = downloadUrl_destination(url);
				}
				catch(Exception e)
				{
	                Log.d("Background Task",e.toString());
				}
				return data;		
				
				//  "error_message" : "This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/places_backend?project=_",   "predictions" : [],   "status" : "REQUEST_DENIED"}
			}
			
			@Override
			protected void onPostExecute(String result) 
			{			
				super.onPostExecute(result);
				
				// Creating ParserTask
				parserTask_destination = new ParserTask_destination();
				
				// Starting Parsing the JSON string returned by Web Service
				parserTask_destination.execute(result);
			}		
		}
		
	
		/** A class to parse the Google Places in JSON format */
	    private class ParserTask_destination extends AsyncTask<String, Integer, List<HashMap<String,String>>>
	    {

	    	JSONObject jObject;
	    	
			@Override
			protected List<HashMap<String, String>> doInBackground(String... jsonData) 
			{			
				
				List<HashMap<String, String>> places = null;
				
	            PlaceJSONParser placeJsonParser = new PlaceJSONParser();
	            
	            try
	            {
	            	jObject = new JSONObject(jsonData[0]);
	            	// Getting the parsed data as a List construct
	            	places = placeJsonParser.parse(jObject);
	            }
	            catch(Exception e)
	            {
	            	Log.d("Exception",e.toString());
	            }
	            
	            return places;
			}
			
			@Override
			protected void onPostExecute(List<HashMap<String, String>> result)
			{			
				
					String[] from = new String[] { "description"};
					int[] to = new int[] { android.R.id.text1 };
					
					// Creating a SimpleAdapter for the AutoCompleteTextView			
					SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), result, android.R.layout.simple_list_item_1, from, to);				
					
					// Setting the adapter
					arrive.setAdapter(adapter);
			}			
	    }    
	    
	    
	    /***************   essai pour html instructions  ***********************/
	    
	
	    private class htmlParserTask extends AsyncTask<String, Integer, List<List<HashMap<String, String>>>> 
	    {
	   
	    	@Override
	    	protected List<List<HashMap<String, String>>> doInBackground(String... jsonData) 
	    	{
	 
	    		JSONObject jObject = null;
	    		
	    		JSONArray jRoutes = null;
	    		JSONObject jRoute;
	    		
	    		JSONArray jLegs = null;
	    		JSONObject jLeg;
	    		
	    		JSONArray jSteps = null;
	    		JSONObject jStep;
	    		
	    		JSONObject jDistance = null;
				JSONObject jDuration = null;
	    		
	    		List<List<HashMap<String, String>>> routes = null;
	 
	    		try 
	    		{
	    			
	    			String filenamex = "infos_filename.txt";
	    			File filex = new File(Environment.getExternalStorageDirectory(), filenamex);
	    			FileOutputStream fosx = new FileOutputStream(filex);  
	        		BufferedWriter bwx = new BufferedWriter(new OutputStreamWriter(fosx));
	    			
	    			// https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/blob/master/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/parser/DirectionsJSONParser.java
	    			
	    			jObject = new JSONObject(jsonData[0]);

	    			jRoutes = jObject.getJSONArray("routes");
	    			for (int i = 0; i < jRoutes.length(); i++) 
	    			{
	    				jRoute=(JSONObject) jRoutes.get(i);
	    				jLegs = jRoute.getJSONArray("legs");
	    				for (int j = 0; j < jLegs.length(); j++) 
	    				{
	    					jLeg=(JSONObject) jLegs.get(j);
	    					jSteps = jLeg.getJSONArray("steps");
	    					for (int k = 0; k < jSteps.length(); k++) 
	    					{
	    						jStep = (JSONObject) jSteps.get(k);
	    						String polyline = (String) ((JSONObject) (jStep).get("polyline")).get("points");
	    						
	    						String str_distance = (String) ((JSONObject) (jStep).get("distance")).get("text");
	    						String str_duration = (String) ((JSONObject) (jStep).get("duration")).get("text");
	    						String str_instructions =  (jStep).getString("html_instructions").replaceAll("<(.*?)*>", "");
	    						//String str_travel_mode = (String) ((JSONObject) (jStep).get("travel_mode")).get("text");
	    						//String d =  (jStep).getString("maneuver") ; 
	    						String concate = str_distance + "*" + str_duration + "*" + str_instructions;
	    						bwx.write(concate);
	    		           		bwx.newLine();
	    					}
	    					// close file	
	    					bwx.close();
	    					
	    				}
	    				
	    			}
	    			
	    			
/**************************  OK ********************/	    			
	    			
	    			String filename = "filename.txt";
	    			File file = new File(Environment.getExternalStorageDirectory(), filename);
	    			FileOutputStream fos = new FileOutputStream(file);  
	        		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

	    	        jObject = new JSONObject(jsonData[0]);
	        
	    	        JSONArray array = (JSONArray) jObject.get("routes");
	    	        if(array.length() == 0)
	    	        {
	    	        	String error = "nogood";
	    	        }
	        
	    	        JSONObject obj = (JSONObject) array.get(0);
	        
			        JSONArray array1 = (JSONArray) obj.get("legs");
		            JSONObject obj2 = (JSONObject) array1.get(0);
		            String origin = obj2.getString("start_address");
		            String destination = obj2.getString("end_address");
		            String header = origin +" --> "+destination+"\n";
		            JSONArray array2 = (JSONArray) obj2.get("steps");
		            String[] html_instructions = new String[array2.length()+1];
		            html_instructions[0] = header;
		            
		            for(int i = 0; i < array2.length(); i++)
		            {
		                JSONObject obj2a = (JSONObject) array2.get(i);
		                String html = obj2a.getString("html_instructions").replaceAll("<(.*?)*>", "");
		                html_instructions[i+1] = html;
		           		bw.write(html);
		           		bw.newLine();
		            }
		            bw.close();
	        
		            html_instructions_list.addLast(html_instructions);
            
		            //https://codereview.stackexchange.com/questions/167657/google-maps-directions-api     
		            DirectionsJSONParser007 parser = new DirectionsJSONParser007();
	 
		            // Starts parsing data
		            routes = parser.parse_point(jObject);
		      } 
		      catch (Exception e)
	     	  {
		    	  e.printStackTrace();
		      }
	    		
	    		return routes;
	    
	    }
	 
	    // Executes in UI thread, after the parsing process
	    @Override
	    protected void onPostExecute(List<List<HashMap<String, String>>> result) {
	 
	      // point
	      ArrayList<LatLng> points = null;
	      PolylineOptions lineOptions = null;
	      MarkerOptions markerOptions = new MarkerOptions();
	      // point
	 
	      // html
	      ArrayList<String> html_str_array = null;
	      // html
	 
	      // Traversing through all the routes
	      for (int i = 0; i < result.size(); i++) {
	        System.out.println(" main_result.size():" + result.size());
	        if (i == 0) {
	          points = new ArrayList<LatLng>();
	          lineOptions = new PolylineOptions();
	          // Fetching i-th route
	          List<HashMap<String, String>> path = result.get(i);
	 
	          // Fetching all the points in i-th route
	          for (int j = 0; j < path.size(); j++) {
	 
	            HashMap<String, String> point = path.get(j);
	            double lat = Double.parseDouble(point.get("lat"));
	            double lng = Double.parseDouble(point.get("lng"));
	            LatLng position = new LatLng(lat, lng);
	 
	            points.add(position);
	          }
	        }
	 
	    
	        if (i == 1) {
	          html_str_array = new ArrayList<String>();
	          List<HashMap<String, String>> html_list = result.get(i);
	          System.out.println(" main_html.toString():"
	              + html_list.toString());
	 
	          for (int k = 0; k < html_list.size(); k++) {
	            HashMap<String, String> html_map = html_list.get(k);
	            String html_str = html_map.get("html_str");
	            html_str_array.add(html_str);
	          }
	        }
	 
	      }
	     
	     
	      //listView.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_expandable_list_item_1,html_str_array));
	    }
	  }
	    
	
	
	    /**************************************/
}

/**********  fin de la classe principale *************/

	class DataParser 
	{

		/** Receives a JSONObject and returns a list of lists containing latitude and longitude */
    
		public List<List<HashMap<String,String>>> parse(JSONObject jObject)
		{

			List<List<HashMap<String, String>>> routes = new ArrayList<>() ;
			JSONArray jRoutes;
			JSONArray jLegs;
			JSONArray jSteps;

			try 
			{

				jRoutes = jObject.getJSONArray("routes");

				/** Traversing all routes */
				for(int i=0;i<jRoutes.length();i++)
				{
					jLegs = ( (JSONObject)jRoutes.get(i)).getJSONArray("legs");
					List path = new ArrayList<>();

					/** Traversing all legs */
					for(int j=0;j<jLegs.length();j++)
					{
						jSteps = ( (JSONObject)jLegs.get(j)).getJSONArray("steps");
						/** Traversing all steps */
						for(int k=0;k<jSteps.length();k++)
						{
							String polyline = "";
							polyline = (String)((JSONObject)((JSONObject)jSteps.get(k)).get("polyline")).get("points");
							List<LatLng> list = decodePoly(polyline);

							/** Traversing all points */
							for(int l=0;l<list.size();l++)
							{
								HashMap<String, String> hm = new HashMap<>();
								hm.put("lat", Double.toString((list.get(l)).latitude) );
								hm.put("lng", Double.toString((list.get(l)).longitude) );
								path.add(hm);
							}
						}
						
						routes.add(path);
					}
				}

			} 
			catch (JSONException e) 
			{
				e.printStackTrace();
			}
			catch (Exception e)
			{
			}

			return routes;
		}

  
		private List<LatLng> decodePoly(String encoded) 
		{

			List<LatLng> poly = new ArrayList<>();
			int index = 0, len = encoded.length();
			int lat = 0, lng = 0;

			while (index < len) 
			{
				int b, shift = 0, result = 0;
            
				do 
				{
					b = encoded.charAt(index++) - 63;
					result |= (b & 0x1f) << shift;
					shift += 5;
				} while (b >= 0x20);
				
				int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
				lat += dlat;

				shift = 0;
				result = 0;
            
				do 
				{
					b = encoded.charAt(index++) - 63;
					result |= (b & 0x1f) << shift;
					shift += 5;
				} while (b >= 0x20);
            
				int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
				lng += dlng;

				LatLng p = new LatLng((((double) lat / 1E5)),  (((double) lng / 1E5)));
				poly.add(p);
			}

			return poly;
		}

	}


	/************ traitement *********************/
	
	class DirectionsJSONParser 
	{
		public List<List<HashMap<String,String>>> parse(JSONObject jObject)
		{
			
			List<List<HashMap<String, String>>> routes = new ArrayList<List<HashMap<String,String>>>() ;
			JSONArray jRoutes = null;
			JSONArray jLegs = null;
			JSONArray jSteps = null;	
			JSONObject jDistance = null;
			JSONObject jDuration = null;
			
			try 
			{			
				
				jRoutes = jObject.getJSONArray("routes");
				
				for(int i=0;i<jRoutes.length();i++)
				{			
					jLegs = ( (JSONObject)jRoutes.get(i)).getJSONArray("legs");				
					
					List<HashMap<String, String>> path = new ArrayList<HashMap<String, String>>();				
					
					/** Traversing all legs */
					for(int j=0;j<jLegs.length();j++)
					{
						/** Getting distance from the json data */
						jDistance = ((JSONObject) jLegs.get(j)).getJSONObject("distance");
						HashMap<String, String> hmDistance = new HashMap<String, String>();
						hmDistance.put("distance", jDistance.getString("text"));
						
						/** Getting duration from the json data */
						jDuration = ((JSONObject) jLegs.get(j)).getJSONObject("duration");
						HashMap<String, String> hmDuration = new HashMap<String, String>();
						hmDuration.put("duration", jDuration.getString("text"));
						
						/** Adding distance object to the path */
						path.add(hmDistance);
						
						/** Adding duration object to the path */
						path.add(hmDuration);					
						
						jSteps = ( (JSONObject)jLegs.get(j)).getJSONArray("steps");
						
					}
					routes.add(path);
				}
				
			} 
			catch (JSONException e) 
			{			
				e.printStackTrace();
			}
			catch (Exception e)
			{			
			}
			
			return routes;
		}
		
	}
	
	
	
	// https://tutel.me/c/codereview/questions/167657/google+maps+directions+api
	
	// https://www.javaworld.com.tw/jute/post/view?bid=26&id=316739
	
	
	// https://www.javaworld.com.tw/jute/post/view?bid=26&id=316739
	
	
	class DirectionsJSONParser007
	{
		public List<List<HashMap<String, String>>> parse_point(JSONObject jObject) 
		{
		 
		    List<List<HashMap<String, String>>> routes = new ArrayList<List<HashMap<String, String>>>();
		    JSONArray jRoutes = null;
		    JSONArray jLegs = null;
		    JSONArray jSteps = null;
		    
		 
		    String[] html_instructions = null;
		    
		    try 
		    {
		 
		    	jRoutes = jObject.getJSONArray("routes");
		    	System.out.println("jRoutes:"+jRoutes);
		 
		    	/** Traversing all routes */
		    	for (int i = 0; i < jRoutes.length(); i++) 
		    	{
		    		jLegs = ((JSONObject) jRoutes.get(i)).getJSONArray("legs");
		    		System.out.println("jLegs:"+jLegs);
		    		List path = new ArrayList<HashMap<String, String>>();
		    		List html = new ArrayList<HashMap<String, String>>();
		 
		    		/** Traversing all legs */
		    		for (int j = 0; j < jLegs.length(); j++) 
		    		{
		    			jSteps = ((JSONObject) jLegs.get(j)).getJSONArray("steps");
		    			System.out.println("jSteps:"+jSteps);
		 
		    			/** Traversing all steps */
		    			for (int k = 0; k < jSteps.length(); k++) 
		    			{
		        	  
		    				//String html_str = (String) ((JSONObject) jSteps.get(k)).get("html_instructions");
		        	  
		        	  
		    				//String polyline = "";
		    				//polyline = (String) ((JSONObject) ((JSONObject) jSteps.get(k)).get("polyline")).get("points");
		    				//List<LatLng> list = decodePoly(polyline);
		            
		    				HashMap<String, String> hp = new HashMap<String, String>();
		    				String html_str = "";
		    				html_str = (String) ((JSONObject) jSteps.get(k)).get("html_instructions");
		    				hp.put("html_str",html_str);
		    				html.add(hp);
		 
		    				/** Traversing all points */
		    				/*
		            		for (int l = 0; l < list.size(); l++) 
		            		{
		              			HashMap<String, String> hm = new HashMap<String, String>();
		              			hm.put("lat",Double.toString(((LatLng) list.get(l)).latitude));
		              			hm.put("lng",Double.toString(((LatLng) list.get(l)).longitude));
		              			path.add(hm);
		            		}
		    				 	*/
		            
		    			}
		    			
		    			//routes.add(path); 
		    			//routes.add(html); 
		    		}
		      }
		 
		    } 
		    catch (JSONException e)
		    {
		      e.printStackTrace();
		    } 
		    catch (Exception e) 
		    {
		    }
		 
		    return routes;
		  
		}
		  
		  
		 
		  public List<HashMap<String, String>> parse_html(JSONObject jObject) {
		 
		    List<HashMap<String, String>> routes = new ArrayList<HashMap<String, String>>();
		    JSONArray jRoutes = null;
		    JSONArray jLegs = null;
		    JSONArray jSteps = null;
		 
		    try {
		      jRoutes = jObject.getJSONArray("routes");
		 
		      /** Traversing all routes */
		      for (int i = 0; i < jRoutes.length(); i++) {
		        jLegs = ((JSONObject) jRoutes.get(i)).getJSONArray("legs");
		        List path = new ArrayList<HashMap<String, String>>();
		 
		        /** Traversing all legs */
		        for (int j = 0; j < jLegs.length(); j++) {
		          jSteps = ((JSONObject) jLegs.get(j)).getJSONArray("steps");
		 
		          /** Traversing all steps */
		          for (int k = 0; k < jSteps.length(); k++) {
		             String html_str = "";
		             html_str = (String)((JSONObject)jSteps.get(k)).get("html_instructions");
		            // hm.put("html_str",html_str);
		 
		          }
		          //routes.add(path);
		        }
		      }
		 
		    } catch (JSONException e) {
		      e.printStackTrace();
		    } catch (Exception e) {
		    }
		 
		    return routes;
		 
		  }
		 
		
		  private List<LatLng> decodePoly(String encoded) {
		 
		    List<LatLng> poly = new ArrayList<LatLng>();
		    int index = 0, len = encoded.length();
		    int lat = 0, lng = 0;
		 
		    while (index < len) {
		      int b, shift = 0, result = 0;
		      do {
		        b = encoded.charAt(index++) - 63;
		        result |= (b & 0x1f) << shift;
		        shift += 5;
		      } while (b >= 0x20);
		      int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
		      lat += dlat;
		 
		      shift = 0;
		      result = 0;
		      do {
		        b = encoded.charAt(index++) - 63;
		        result |= (b & 0x1f) << shift;
		        shift += 5;
		      } while (b >= 0x20);
		      int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
		      lng += dlng;
		 
		      LatLng p = new LatLng((((double) lat / 1E5)),
		          (((double) lng / 1E5)));
		      poly.add(p);
		    }
		 
		    return poly;
		  }
		}
	
	
	// &avoid=highways
	
	//alternatives=true 
	
	//https://codepen.io/jasonmayes/pen/DupCH
	
	/*avoid — Indique que les itinéraires calculés doivent éviter les caractéristiques indiquées. Il prend en charge les arguments suivants :

    tolls indique que l'itinéraire calculé doit éviter les autoroutes et ponts à péage.
    highways indique que l'itinéraire calculé doit éviter les autoroutes.
    ferries indique que l'itinéraire calculé doit éviter les ferries.
    indoor indique que l'itinéraire calculé doit éviter les étapes en intérieur lorsqu'il s'agit de trajets à pied ou en transports en commun. Seules les requêtes qui incluent une clé d'API ou un ID client Google Maps APIs Premium Plan reçoivent des étapes en intérieur par défaut.

	 */
	