package com.example.GPS_DB01;


import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;

public class Display_datas_run extends Activity 
{

	Button btn_maps;
	private DAOtextReport daOtextReport;
	
	static ArrayList<TextReport> objets= new ArrayList<TextReport>();  
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.display_datas_run_layout);
		
		Bundle extras = getIntent().getExtras();
		String run_name = extras.getString("run_name");
		Toast.makeText(Display_datas_run.this, run_name, Toast.LENGTH_LONG).show();	
		
		// chargement des datas
		
		daOtextReport = new DAOtextReport(this);
		
		String requete = "SELECT * FROM table_run_summary"; //  WHERE name = " + run_name ;
 	
		Cursor Cursor = daOtextReport.DB_query(requete);
		int val = Cursor.getCount();
		
		if(val != 0)
		{
				if (Cursor.moveToFirst()) 
				{
 					do 
 					{
 							/*
							sid = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_ID_RUN ));
	 						titre = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_NAME_RUN ));
	 						start_timestamp = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_DATE_RUN ));
	 						end_timestamp = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_START_RUN ));
	 						phone = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_STOP_RUN ));
	 						
	 						
	 						option_delai = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_STEPS_COUNT_RUN ));
	 						option_vibrate = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_MODE_RUN ));
	 						option_ringtone = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_CALORIES_RUN ));

	 						
	 						notes = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_VITESSE_MOYENNE_RUN ));
	 						status = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_DISTANCE_RUN ));
	 						creation = Cursor.getString(Cursor.getColumnIndex(DBHelper.COLUMN_DURATION_RUN ));
	 						*/
	 						
 					} while (Cursor.moveToNext());
 					
				}
		}
		
		// chargement des points 
		requete = "SELECT * FROM textreport WHERE _id =  5" + run_name ;
		
	//	String requete = "SELECT * FROM table_appointment WHERE _id = " + id ;
	 	
		Cursor = daOtextReport.DB_query(requete);
		val = Cursor.getCount();
		
		final int cpt = 0;
		
		if(val != 0)
		{
				if (Cursor.moveToFirst()) 
				{
 					do 
 					{
							double latitude = Cursor.getDouble(Cursor.getColumnIndex(DBtables.TextReport.COLUMN_LATITUDE ));
							double longitude = Cursor.getDouble(Cursor.getColumnIndex(DBtables.TextReport.COLUMN_LONGITUDE ));
							double altitude = Cursor.getDouble(Cursor.getColumnIndex(DBtables.TextReport.COLUMN_ALTITUDE ));
							double speed = Cursor.getDouble(Cursor.getColumnIndex(DBtables.TextReport.COLUMN_SPEED ));
	 						
							TextReport id = new TextReport("not_defined", "empty", latitude , longitude , altitude, speed);
							objets.add(id);
	 						
 					} while (Cursor.moveToNext());
 					
				}
		}
		
	/*	
		   public static final String COLUMN_NUSER_ID = "userid";
	        public static final String COLUMN_REPORT = "report";
	        public static final String COLUMN_ISREPOETED = "isreported";
	        public static final String COLUMN_DATETIME = "datetime";
	        public static final String COLUMN_LATITUDE = "latitude";
	        public static final String COLUMN_LONGITUDE = "longtitude";
	        public static final String COLUMN_ALTITUDE = "altitude";
	        public static final String COLUMN_SPEED = "speed";
		
	*/	
		
		btn_maps = (Button) findViewById(R.id.btn_maps);    
		btn_maps.setOnClickListener(new OnClickListener() 
		{

				@Override
				public void onClick(View arg0) 
				{
					Intent Intent = new Intent(Display_datas_run.this, GPS_tracker_maps02.class);
		  			startActivity(Intent);
				}

		});
		
	}
}