package com.sabirjan.android;

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

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

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
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.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class ActiviyTab_1 extends Activity{

	private static final String action="com.sabirjan.Kanun.TextViewDemo";
	@Override
	public void onCreate(Bundle savedInstanceState) {  
	      super.onCreate(savedInstanceState);  
	      setContentView(R.layout.test1);  
	      GridView gridview = (GridView) findViewById(R.id.gridview);  
	        
	      //生成动态数组，并且转入数据  
	      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.item1);//添加图像资源的ID  
	        map.put("ItemText", "ﻪﭼﯗﺰﻧﻪﺧ-ﻪﭼﺭﯘﻐﻳﯘﺋ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item2);//添加图像资源的ID  
	        map.put("ItemText", "ﻪﭼﺭﯘﻐﻳﯘﺋ-ﻪﭼﯗﺰﻧﻪﺧ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item3);//添加图像资源的ID  
	        map.put("ItemText", "ﻪﭼﺰﯩﻠﯩﮕﻨﯩﺋ-ﻪﭼﺭﯘﻐﻳﯘﺋ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item4);//添加图像资源的ID  
	        map.put("ItemText", "ﻪﭼﺭﯘﻐﻳﯘﺋ-ﻪﭼﺰﯩﻠﯩﮕﻨﯩﺋ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item5);//添加图像资源的ID  
	        map.put("ItemText", "ﺕﺍﯞﺎﺳ ﻦﯨﺪﻧﯘﻧﺎﻗ");
	        lstImageItem.add(map);  
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item6);//添加图像资源的ID  
	        map.put("ItemText", "ﺕﺎﮬﺍﺰﯩﺋ ﺎﻏﺭﻻﯘﻐﻟﺎﺗﺎﺋ");
	        lstImageItem.add(map);
	        
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item7);//添加图像资源的ID  
	        map.put("ItemText", "ﻯﺭﯘﺗ ﻥﯘﻳﻮﺋ");
	        lstImageItem.add(map);
	        
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item);//添加图像资源的ID  
	        map.put("ItemText", "ﻖﯩﻠﻣﻼﻏﺎﺳ");
	        lstImageItem.add(map);
	        
	        map = new HashMap<String, Object>();  
	        map.put("ItemImage", R.drawable.item9);//添加图像资源的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());  
	  }  
	    
	  //当AdapterView被单击(触摸屏或者键盘)，则返回的Item单击事件  
	  class  ItemClickListener implements OnItemClickListener  
	  {  
		  @Override
	public void onItemClick(AdapterView<?> arg0,    View arg1, int selindex,long arg3 ) 
		  {  
			  System.out.println("I="+selindex);
			  try
			  {
				  Intent intent=new Intent();
				switch(selindex)
				{
					case 0:intent.setClass(ActiviyTab_1.this, Input_UyWordActivity.class);
					intent.putExtra("type", "1");		
					break;
					case 1:intent.setClass(ActiviyTab_1.this, Ch_Uy_Activity.class);
					intent.putExtra("type", "4");
					break;
					
					case 2:intent.setClass(ActiviyTab_1.this, Input_UyWordActivity.class);
					intent.putExtra("type", "2");
					break;
					case 3:intent.setClass(ActiviyTab_1.this, En_Uy_Activity.class);
					intent.putExtra("type", "7");
					break;
					case 4:intent.setClass(ActiviyTab_1.this, KanunListShowActivity.class);break;
					case 5:intent.setClass(ActiviyTab_1.this, Logo2.class);break;
					case 8:CustomizeDialog clsDialog=new CustomizeDialog(ActiviyTab_1.this);
			      	  clsDialog.show();return;
					default:return;
				}
				ActiviyTab_1.this.startActivity(intent);
			  }
			  catch(Exception ex)
			  {
				 //Show Error Message
			  }
	    
		  }
	
	      
	  }

	@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);
	}
	  

}
