package com.view;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import com.app.downloadstream1.*;

public class EventDetail extends Activity {
	TextView tv_name;
	TextView tv_time;
	TextView tv_place;
	TextView tv_publisher;
	Button bt_how;
	Button bt_contact;
	TextView tv_des;
	ImageView iv_pic;
	Button bt_return;
//	Button bt_tag;
	Button bt_reply;
//	Button bt_next;
	Button bt_video;
	
	boolean isOnline=true;
	boolean permitSMS=false;
	
	String name="";
	String stime="";
	String etime="";
	String place="";
	String des="";
	String image_path="";
	String publisher="";
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.eventdetail);
		tv_name=(TextView)findViewById(R.id.name_in_detail);
		tv_time=(TextView)findViewById(R.id.time_in_detail);
		tv_place=(TextView)findViewById(R.id.place_in_detail);
		tv_publisher=(TextView)findViewById(R.id.publisher_in_detail);
		bt_how=(Button)findViewById(R.id.how_in_detail);
		bt_contact=(Button)findViewById(R.id.contact_in_detail);
		tv_des=(TextView)findViewById(R.id.descri_in_detail);
		iv_pic=(ImageView)findViewById(R.id.pic_in_detail);
		bt_return=(Button)findViewById(R.id.return_in_detail);
//		bt_tag=(Button)findViewById(R.id.tag_in_detail);
		bt_reply=(Button)findViewById(R.id.reply_in_detail);
//		bt_next=(Button)findViewById(R.id.next_in_detail);
		bt_video=(Button)findViewById(R.id.video_in_detail);
		bt_video.setOnClickListener(click_video);
		tv_name.setText(name);
		String time;
		if(etime==null) time=stime;
		else time=stime+" ~ "+etime;
		tv_time.setText(time);
		tv_place.setText(place);
		tv_publisher.setText(publisher);
		tv_des.setText(des);
		
		bt_contact.setOnClickListener(click_contact);
		
	}
	
	/*
	 * To set Event information before detail page is called
	 */
	public void setName(String name)
	{
		this.name=name;
	}
	public void setStartTime(String time)
	{
		this.stime=time;
	}
	public void setEndTime(String time)
	{
		this.etime=time;
	}
	public void setPlace(String place)
	{
		this.place=place;
	}
	public void setDes(String des)
	{
		this.des=des;
	}
	public void setEventImage(String path)
	{
		this.image_path=path;
	}
	
	/*
	 * user部分可改成：
	 * 先获取user id，再连接服务器获取资料。
	 */
	public void setPublisher(String pub)
	{
		this.publisher=pub;
	}
	public void setOnline(boolean isOl)
	{
		isOnline=isOl;
		this.setContactText();
	}
	public void setPermitSMS(boolean sms)
	{
		permitSMS=sms;
		this.setContactText();
	}
	
	
	public void setContactText()
	{
		if(isOnline==true)
		{
			this.bt_contact.setText("Msg to me");
		}
		else
		{
			if(permitSMS==true)
				this.bt_contact.setText("SMS to me");
			else
				this.bt_contact.setText("Leave a msg");
		}
	}
	
	OnClickListener click_contact=new OnClickListener()
	{
		public void onClick(View view)
		{
			/*
			 * need overriding: 将10086改为获取对方号码
			 */
			Uri smsToUri = Uri.parse("smsto://10086");
			Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
			startActivity( mIntent );
		}
	};
	OnClickListener click_video=new OnClickListener()
	{
		public void onClick(View view)
		{
			Intent intent=new Intent(EventDetail.this,DownloadStream.class);
			startActivity(intent);
		}
	};
}
