package com.sabirjan.android;

import java.util.ArrayList;
import java.util.List;

import com.sabirjan.CaoZuoTXT.ReadTXT;
import com.sabirjan.Dialog.Custom_WaitDialog;
import com.sabirjan.DrawUyghurWord.ConvertUL;
import com.sabirjan.Kanun.GetUyghursent;
import com.sabirjan.android.R;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnKeyListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;

public class KanunListShowActivity extends Activity {
    /** Called when the activity is first created. */
	
	public static final int MSG_UPDATE_LIST = 18;  
    
    private ListView mApps;  
    private Context mContext;  
    private List<String> mAppList;  
    private Custom_WaitDialog  dialog;  
    private ArrayAdapter mAdapter;  
    private boolean mIsLoaded = false;  
      
    ArrayList<String>  myListItems ;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //
        setContentView(R.layout.kanun_main);
        
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//
        dialog=new Custom_WaitDialog(this);
        dialog.show();
        mApps = (ListView)findViewById(R.id.myListView);
        mContext = this;  
        mAppList = new ArrayList<String>();  
        
   	 int resID = R.layout.todolist_item;
     mAdapter = new ArrayAdapter<String>(KanunListShowActivity.this, resID,
        		mAppList);
	  mApps.setAdapter(mAdapter);
       
        // 设置正在处理窗口  
	  //Thread thread =  new Thread(null, loadMoreListItems);
     // thread.start();
       mApps.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) 
			{
			
					Intent in=new Intent();
					in.setClass(KanunListShowActivity.this, ShowOneKanunContentActivity.class);
					in.putExtra("Url",String.valueOf(arg2));
					startActivity(in);
				}
          });
     
        
       this.runOnUiThread(new Runnable() { 
           @Override 
               public void run() 
           { 
        		GetUyghursent cls=new GetUyghursent();
           	    ConvertUL clsUyghurWord=new ConvertUL();
           	    ReadTXT clsReadtxt=new ReadTXT();
           	    String strMenu=clsReadtxt.readTxt(KanunListShowActivity.this);
           	   String []str=cls.NewsList(strMenu);//{"123","345","345"};
           	   for(int i=0;i<str.length;i++)
           	   {
           		str[i]=clsUyghurWord.GetULUyghurWord(str[i]);
           	   	mAppList.add(str[i]);
                mAdapter.notifyDataSetChanged();
                
           	   }
    
           	dialog.dismiss();
          } 
           });
       

    }
    
   
    @Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
    	if(keyCode==KeyEvent.KEYCODE_BACK)
    	{
    		this.finish();
    		return true;
    	}
		return super.onKeyDown(keyCode, event);
	}



	private Runnable returnRes = new Runnable() 
    {
        
        public void run() {                              
                  mAdapter.notifyDataSetChanged();
                  dialog.dismiss();
        				}
    };
    private Runnable loadMoreListItems = new Runnable() {                        
        
        public void run()
        {
                
            try { 
            	
            
            	
                } catch (Exception e) 
                {
                	
                	
                }
                runOnUiThread(returnRes);
        }
};        

}