package com.sabirjan.android;

import java.util.ArrayList;
import java.util.HashMap;

import com.sabirjan.Dialog.CustomizeDialog;
import com.sabirjan.android.R;
import com.sabirjan.android.ActiviyTab_1.ItemClickListener;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class ActiviyTab_2 extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test2);
		 GridView gridview = (GridView) findViewById(R.id.gridview2);  
	        
	      //生成动态数组，并且转入数据  
	      ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();  
	      //for(int i=0;i<9;i++)  
	      {  
	        HashMap<String, Object> map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item_2_1);//添加图像资源的ID  
	        map.put("ItemText", "ﺵﯗﺭﯘﺘﺷﯗﺭﯘﺳ ﻥﻮﻳﺍﺭ ﻩﯞﻪﺗ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item_2_2);//添加图像资源的ID  
	        map.put("ItemText", "ﺵﻩﺩﺰﯩﺋ ﻯﺭﯘﻣﻮﻧ ﺕﻪﺧ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item_2_3);//添加图像资源的ID  
	        map.put("ItemText", "ﻯﺭﯘﻣﻮﻧ ﺩﻮﻛ ﺕﻪﻠﻠﯩﻣ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item_2_4);//添加图像资源的ID  
	        map.put("ItemText", "ﻯﺮﯩﻟﺭﯘﻣﻮﻧ ﻥﻮﻳﺍﺭ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item_2_5);//添加图像资源的ID  
	        map.put("ItemText", "ﺭﻻﺭﯘﻣﻮﻧ ﺎﻘﺷﺎﺑ");
	        lstImageItem.add(map);  
	      }
	      
	      
	      
	//  	Typeface face=Typeface.createFromAsset(this.getAssets(),"fonts/ALKATIPTorTom.TTF");//
		 
	//      TextView t=(TextView)this.findViewById(R.id.ItemText);
	//      t.setTypeface(face);
	      //生成适配器的ImageItem <====> 动态数组的元素，两者一一对应  
	      SimpleAdapter saImageItems = new SimpleAdapter(this, //没什么解释  
	                                                lstImageItem,//数据来源   
	                                                R.layout.night_item,//night_item的XML实现  
	                                                  
	                                                //动态数组与ImageItem对应的子项          
	                                                new String[] {"ItemImage","ItemText"},   
	                                                  
	                                                //ImageItem的XML文件里面的一个ImageView,两个TextView ID  
	                                                new int[] {R.id.ItemImage,R.id.ItemText});  
	      //添加并且显示  
	      gridview.setAdapter(saImageItems);  
	 
	      //添加消息处理  
	      gridview.setOnItemClickListener(new ItemClickListener());  
	}
	 class  ItemClickListener implements OnItemClickListener  
	  {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int selindex,
				long arg3) {
			// TODO Auto-generated method stub
		
			  try
			  {
				  Intent intent=new Intent();
				switch(selindex)
				{
					case 0:intent.setClass(ActiviyTab_2.this, GetMobileNumberInfo_Activity.class);break;
					case 1:intent.setClass(ActiviyTab_2.this, HanZi_Code_Activity.class);break;
					case 2:intent.setClass(ActiviyTab_2.this, MinZuDaiMa_Activity.class);break;
					case 3:intent.setClass(ActiviyTab_2.this, RayonNomuri_Activity.class);break;
					case 4:intent.setClass(ActiviyTab_2.this, Qita_ListShowActivity.class);break;
					
					case 8:CustomizeDialog clsDialog=new CustomizeDialog(ActiviyTab_2.this);
			      	  clsDialog.show();return;
					default:return;
				}
				ActiviyTab_2.this.startActivity(intent);
			  }
			  catch(Exception ex)
			  {
				  System.out.println("I="+ex);
			  }
		} 
		 
	  }
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode==KeyEvent.KEYCODE_BACK)
		{
			  CustomizeDialog clsDialog=new CustomizeDialog(this);
	      	  clsDialog.show();
	      	  return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	
	

}
