package com.sabirjan.android;

import com.sabirjan.CaoZuoTXT.ChaXunDianHua;
import com.sabirjan.CaoZuoTXT.ChaXun_Rayon;
import com.sabirjan.Dialog.InfoDialog;
import com.sabirjan.DrawUyghurWord.SetUyghurTypeface;
import com.sabirjan.HanziCode.HuoquPinYin;
import com.sabirjan.android.GetMobileNumberInfo_Activity.UIUpdateThread;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RayonNomuri_Activity extends Activity{

	EditText edit1,edit2;
	String text,name;
	TextView txt;
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rayon_numuri);
		
		TextView txt1=(TextView)this.findViewById(R.id.txt_rayon1);
		txt1=SetUyghurTypeface.GetTextView(this, txt1);
		TextView txt2=(TextView)this.findViewById(R.id.txt_rayon2);
		txt2=SetUyghurTypeface.GetTextView(this, txt2);
		
		 txt=(TextView)this.findViewById(R.id.txt_rayon3);
		 txt=SetUyghurTypeface.GetTextView(this, txt);
		 
		 TextView txt4=(TextView)this.findViewById(R.id.txt_rayon4);
		 txt4=SetUyghurTypeface.GetTextView(this, txt4);
		
		edit1=(EditText)this.findViewById(R.id.edit_rayon1);
		edit2=(EditText)this.findViewById(R.id.edit_rayon2);
		Button btn1=(Button)this.findViewById(R.id.btn_rayon1);
		btn1=SetUyghurTypeface.GetButton(this, btn1);
		btn1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(edit1.getText().toString().length()==0)
				{
				InfoDialog errorInfo=new InfoDialog(RayonNomuri_Activity.this," ﻛﻪﭼﯘﺭﯗﯓ ،  ﻣﻪﺯﻣﯘﻥ ﻛﯩﺮﮔﯜﺯﯛﯓ ");
				errorInfo.show();
				return ;
				}
				InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(edit1.getWindowToken(), 0);
				text=edit1.getText().toString();
				name="";
				UIUpdateThread2 cls=new UIUpdateThread2();
				cls.start();
			}
		});
		
		
		
		Button btn2=(Button)this.findViewById(R.id.btn_rayon2);
		btn2=SetUyghurTypeface.GetButton(this, btn2);
		btn2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(edit2.getText().toString().length()==0)
				{
				InfoDialog errorInfo=new InfoDialog(RayonNomuri_Activity.this," ﻛﻪﭼﯘﺭﯗﯓ ،  ﻣﻪﺯﻣﯘﻥ ﻛﯩﺮﮔﯜﺯﯛﯓ ");
				errorInfo.show();
				return ;
				}
				InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
				inputMethodManager.hideSoftInputFromWindow(edit2.getWindowToken(), 0);
				text=edit2.getText().toString();
				name="";
				UIUpdateThread cls=new UIUpdateThread();
				cls.start();
			}
		});
		
		
		
		Button btn3=(Button)this.findViewById(R.id.btn_rayon3);
		btn3=SetUyghurTypeface.GetButton(this, btn3);
		btn3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent=new Intent();
				intent.setClass(RayonNomuri_Activity.this, Show_AllRayon_Activity.class);
				RayonNomuri_Activity.this.startActivity(intent);
			}
		});
		
		
	}


	 class UIUpdateThread extends Thread{
	        public void run() {
	            try 
	            {
	            	ChaXun_Rayon cls=new ChaXun_Rayon();
	            	name=cls.GetNumber(RayonNomuri_Activity.this,text);
	                mHandler.post(mUpdateResults);
	            } 
	            catch (Exception e)
	            {
	            	
					Toast.makeText(RayonNomuri_Activity.this, e.getMessage(), Toast.LENGTH_LONG).show();
			
	            }
	            
	        }
	        
	         final Handler mHandler = new Handler();
	            final Runnable mUpdateResults = new Runnable() {
	                public void run() {
	                //    invalidate(); //更新视图
	                try{
	                	if(name.trim().length()==0)
	                	{
	                		name=" ﺳﯩﺰ ﺋﯩﺰﺩﯨﮕﻪﻥ ﻣﻪﺯﻣﯘﻥ ﺗﯧﭙﯩﻠﻤﯩﺪﻯ ";
	                	}
	                	txt.setText(name);
	                	}
	                	catch(Exception ex)
	                	{System.out.println("Len="+ex.getMessage());
	                		
	                	}
	                }
	            };
	        
	}
	 class UIUpdateThread2 extends Thread{
	        public void run() {
	            try 
	            {
	            	ChaXun_Rayon cls=new ChaXun_Rayon();
	            	name=cls.GetName(RayonNomuri_Activity.this,text);
	            	if(name.length()>0)
	            	{
	            		HuoquPinYin cls2=new HuoquPinYin();
	            		String str=cls2.GetCH_PinYinKong(name);
	            		name=name+"\n"+str;
	            	}
	                mHandler.post(mUpdateResults);
	            } 
	            catch (Exception e)
	            {
	            	
					Toast.makeText(RayonNomuri_Activity.this, e.getMessage(), Toast.LENGTH_LONG).show();
			
	            }
	            
	        }
	        
	         final Handler mHandler = new Handler();
	            final Runnable mUpdateResults = new Runnable() {
	                public void run() {
	                //    invalidate(); //更新视图
	                try{
	                	if(name.trim().length()==0)
	                	{
	                		name=" ﺳﯩﺰ ﺋﯩﺰﺩﯨﮕﻪﻥ ﻣﻪﺯﻣﯘﻥ ﺗﯧﭙﯩﻠﻤﯩﺪﻯ ";
	                	}
	                	txt.setText(name);
	                	}
	                	catch(Exception ex)
	                	{System.out.println("Len="+ex.getMessage());
	                		
	                	}
	                }
	            };
	        
	}
	

}
