package example.com.velezguiatour;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class TelefonoAdress extends Activity {
	final String[] addresses = {
			"Taxi Vélez-Málaga: 952 50 28 96",
	"Taxi Torre del Mar: 952 54 00 16",
	"Urgencias Sanitarias 	061",
	"Emergencias 	112",
	"Guardia Civil 	062",
	"Bomberos 	080",
	"Policía Nacional 	091",
	"Policia Local y Movilidad: 952 54 92 38",
	"Ayuntamiento de Vélez-Málaga	952 559 100",
	"Hospital Comarcal - Centralita 	951 067 000",
	"Hospital Comarcal - Urgencias 	951 067 021",
	"Correos	952 540 665",
	"Oficina de turismo e información 952 541 104"

};
	final String[] phones = {
			"952502896",
			"952540016",
			"061",
			"112",
			"062",
			"080",
			"091",
			"952549238",
			"952559100",
			"951067000",
			"951067021",
			"952540665",
			"952541104"
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_telefono_adapter);
		
		int index = getIntent().getExtras().getInt("index");
		 TextView addressView = (TextView) findViewById(R.id.taxitViewAdress);
		addressView.setText(addresses[index]);
		
		Button call = (Button) findViewById(R.id.btncall);
		
		 index = getIntent().getExtras().getInt("index");
		 final TextView phone = (TextView) findViewById(R.id.txtTextPhone);
		 phone.setText(phones[index]);
		

		call.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String sPhone = phone.getText().toString();
				if ("".equals(sPhone)) {
					Toast.makeText(TelefonoAdress.this,
							"Phone number cannot be blank", Toast.LENGTH_LONG)
							.show();
				} else {
					String sCall = "tel:" + sPhone;
					Intent callIntent = new Intent(Intent.ACTION_CALL);
					callIntent.setData(Uri.parse(sCall));
					startActivity(callIntent);
				}
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_main,menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
