package com.manubet.android.touristAndroid;

import java.io.IOException;
import java.net.HttpURLConnection;




import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
//import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class InfoDialog extends Dialog implements OnClickListener {
	
    private Button infoButton, cancelar;
    private TextView text,mas,fecha;
    private ImageView imagenview;
    private Place place;
    private String url;
    
    public InfoDialog(Context context,Place elemento) {
    	 super(context); 
    	 place=elemento;

    	 setContentView(R.layout.dialog);
    	 this.setTitle(place.getNombre());
    	 infoButton = (Button) findViewById(R.id.info);
    	 infoButton.setOnClickListener(this);
    	 cancelar = (Button) findViewById(R.id.cancel);
    	 cancelar.setOnClickListener(this);
    	 text=(TextView)findViewById(R.id.summary);
    	 text.setText(place.getSummary());
       	 text.setBackgroundColor(Color.DKGRAY);
    	 mas=(TextView)findViewById(R.id.mas);
    	 mas.setText("");
    	 fecha=(TextView)findViewById(R.id.fecha);
    	 fecha.setText("");
    	 imagenview=(ImageView)findViewById(R.id.thb);
    	 //Log.d("summary", place.getSummary());
    	 url=place.getUrl().toString();
    	 
    	   
         try {
             if(place.getImagen()!=null){
             HttpURLConnection img = (HttpURLConnection) place.getImagen().openConnection();
             img.connect();
             Bitmap imagen = BitmapFactory.decodeStream(img.getInputStream());
             imagenview.setImageBitmap(imagen);
             }
         } catch (IOException e) {
             e.printStackTrace();
         }   	  
    }
    
	public InfoDialog(Context context) {
   	 super(context);
   	 place=null;

   	 setContentView(R.layout.dialog);
   	 this.setTitle(R.string.about);
   	 infoButton = (Button) findViewById(R.id.info);
   	 infoButton.setOnClickListener(this);
   	 cancelar = (Button) findViewById(R.id.cancel);
   	 cancelar.setOnClickListener(this);
   	 cancelar.setText("OK");
   	 text=(TextView)findViewById(R.id.summary);
   	 text.setText(R.string.about1);
   	 text.setBackgroundColor(Color.DKGRAY);
   	 imagenview=(ImageView)findViewById(R.id.thb);
   	 url=context.getResources().getString(R.string.homepage);
   	 imagenview.setImageResource(R.drawable.logo);
	 mas=(TextView)findViewById(R.id.mas);
	 mas.setText(R.string.about2);
	 fecha=(TextView)findViewById(R.id.fecha);
	 fecha.setText(R.string.aboutFecha);
   	  
   }
    
    
	@Override
	public void onClick(View arg0) {
		if (arg0==infoButton){
			try {
			InfoWeb.currentUrl=url;
			InfoWeb.load();
			}
			catch   (NullPointerException e) {
				e.printStackTrace(); 
			}
			MainActivity.swichtTab(1);
			}
		this.dismiss();
	}
}
