package com.view;

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

import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import viewbg.*;

public class ListView extends ListActivity {
	//Button back;
	//Button map_view;
	//Button list_view;
	//Button last_page;
	//Button next_page;
	public static final int TAG=Menu.FIRST;
	public static final int DETAIL=Menu.FIRST+1;
	
	static final int REQUEST_MAP=0;
	static final int REQUEST_HOME=1;
	
	static final int TIME=Menu.FIRST;
	static final int PLACE=Menu.FIRST+1;
	
	
	List items;
	EventItemAdapter adapter;
	ArrayList<Integer> event_pics;
	String[] event_ids=new String[]{"000001","000002","000003","000004"};
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview);
		
		
		
		
		items=new ArrayList();
		Map i1=new HashMap();
		i1.put("name", "Event 01");
		i1.put("time", "10:00");
		i1.put("addr", "...");
		items.add(i1);
		
		Map i2=new HashMap();
		i2.put("name", "Event 02");
		i2.put("time", "12:00");
		i2.put("addr", "...");
		items.add(i2);
		
		ArrayList<Integer> idres=new ArrayList<Integer>();
		idres.add(new Integer(R.drawable.logo));
		idres.add(new Integer(R.drawable.logo));
		
		adapter=new EventItemAdapter(this, items,R.layout.eventrow,new String[]{"name","time","addr"},new int[]{R.id.event_name_in_erow,R.id.event_time_in_erow,R.id.event_addr_in_erow},R.id.event_pic_in_erow,idres);
		setListAdapter(adapter);
		
//		back=(Button)findViewById(R.id.return_in_list);
//		map_view=(Button)findViewById(R.id.map_in_list);
		
		//back.setOnClickListener(click_back);
		//map_view.setOnClickListener(click_map);
	}
	
	public boolean onCreatOptionsMenu(Menu menu)
	{
		super.onCreateOptionsMenu(menu);
		menu.add(0,TAG,0,R.string.menu_tag);
		menu.add(0, DETAIL, 1, R.string.menu_detail);
		menu.add(0,TIME,2,R.string.menu_time);
		menu.add(0,PLACE,3,R.string.menu_place);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch(item.getItemId())
		{
		case TAG:
		{
			
		}
		break;
		case DETAIL:
		{
			Intent i=new Intent(ListView.this,EventDetail.class);
			startActivity(i);
		}
		break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void initItems(EventItem[] eis)
	{
		Map map;
		for(int i=0;i<eis.length;i++)
		{
			map=new HashMap();
			map.put("name", eis[i].getName());
			map.put("time", eis[i].getTime());
			map.put("addr", eis[i].getAddr());
			items.add(map);
			
			//event_pics.add(new )    add address of event pic
		}
		
	}
	
	OnClickListener click_map=new OnClickListener()
	{
		public void onClick(View view)
		{
			/*
			 * Same as in SearchEvents.click_list
			 */
			Bundle b=new Bundle();
			//b.putString("CentricEvent",event_id)
			Intent i=new Intent(ListView.this,SearchEvents.class);
			i.putExtras(b);
			startActivityForResult(i,REQUEST_MAP);
		}
	};
	
	OnClickListener click_back=new OnClickListener()
	{
		public void onClick(View view)
		{
			setResult(RESULT_OK,getIntent());
			finish();
		}
	};
	
	public void onActivityResult(int request,int result,Intent data)
	{
		if(request==REQUEST_MAP)
			if(result==RESULT_OK)
			{
				
			}
	}
}
