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.Dialog.TorDinIzDax;
import com.sabirjan.Dialog.TordinEzdaxDialog;
import com.sabirjan.DrawUyghurWord.ConvertUL;
import com.sabirjan.Tor.UyghurDic_TordinEzdax;
import com.sabirjan.android.R.id;
import com.sabirjan.wangluo.fangwenService;


import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.Selection;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class Input_UyWordActivity extends Activity implements OnCheckedChangeListener,OnClickListener{
    /** Called when the activity is first created. */
    private static final List<String> list = new ArrayList<String>();
    RadioGroup row1;
    RadioGroup row2;
    RadioGroup row3;
    RadioGroup row4;
    EditText inputText;
    String strText="";
    Button boxorun;
    Button kaytix;
    Button izdax;
    Button oqurux;
	ConvertUL cls;
	Button auto_btn1;
	Button auto_btn2;
	Button auto_btn3;
	LinearLayout auto_layout;
	TextView txt_natija;
	String type;
	Custom_WaitDialog cwait;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uy_keyboard);
        setFont();
        Intent inten=this.getIntent();
        type=inten.getStringExtra("type");
        cls=new ConvertUL();
        cwait=new Custom_WaitDialog(this);
    }
    
    
    private void setFont()
    {
    	
    	
     txt_natija=(TextView)this.findViewById(R.id.txt_key_natija);
  	  row1=(RadioGroup)this.findViewById(R.id.main_radio);
      row1.setOnCheckedChangeListener(this);//End setOnCheckedChangeListener
      row2=(RadioGroup)this.findViewById(R.id.main_radio2);
      row2.setOnCheckedChangeListener(this);//End setOnCheckedChangeListener
      row3=(RadioGroup)this.findViewById(R.id.main_radio3);
      row3.setOnCheckedChangeListener(this);//End setOnCheckedChangeListener
      row4=(RadioGroup)this.findViewById(R.id.main_radio4);
      row4.setOnCheckedChangeListener(this);//End setOnCheckedChangeListener
		Typeface typeface=Typeface.createFromAsset(this.getAssets(),"fonts/ALKATIPTorTom.TTF");
	
		TextView t=(TextView)this.findViewById(R.id.txtTop);
		t.setTypeface(typeface);
		txt_natija.setTypeface(typeface);
		inputText=(EditText)this.findViewById(R.id.edit);
		inputText.setSingleLine(true);
		inputText.setTypeface(typeface);

        RadioButton r0=(RadioButton)this.findViewById(R.id.button_0);
        RadioButton r1=(RadioButton)this.findViewById(R.id.button_1);
        RadioButton r2=(RadioButton)this.findViewById(R.id.button_2);
        RadioButton r3=(RadioButton)this.findViewById(R.id.button_3);
        RadioButton r4=(RadioButton)this.findViewById(R.id.button_4);
        RadioButton r5=(RadioButton)this.findViewById(R.id.button_5);
        RadioButton r6=(RadioButton)this.findViewById(R.id.button_6);
        RadioButton r7=(RadioButton)this.findViewById(R.id.button_7);
        RadioButton r8=(RadioButton)this.findViewById(R.id.button_8);
        RadioButton r9=(RadioButton)this.findViewById(R.id.button_9);
    	r0.setTypeface(typeface);
		r1.setTypeface(typeface);
		r2.setTypeface(typeface);
		r3.setTypeface(typeface);
		r4.setTypeface(typeface);
		r5.setTypeface(typeface);
		r6.setTypeface(typeface);
		r7.setTypeface(typeface);
		r8.setTypeface(typeface);
		r9.setTypeface(typeface);
        //第二行
        RadioButton r11=(RadioButton)this.findViewById(R.id.button_19);
        RadioButton r12=(RadioButton)this.findViewById(R.id.button_11);
        RadioButton r13=(RadioButton)this.findViewById(R.id.button_12);
        RadioButton r14=(RadioButton)this.findViewById(R.id.button_13);
        RadioButton r15=(RadioButton)this.findViewById(R.id.button_14);
        RadioButton r16=(RadioButton)this.findViewById(R.id.button_15);
        RadioButton r17=(RadioButton)this.findViewById(R.id.button_16);
        RadioButton r18=(RadioButton)this.findViewById(R.id.button_17);
        RadioButton r19=(RadioButton)this.findViewById(R.id.button_18);
		r11.setTypeface(typeface);
		r12.setTypeface(typeface);
		r13.setTypeface(typeface);
		r14.setTypeface(typeface);
		r15.setTypeface(typeface);
		r16.setTypeface(typeface);
		r17.setTypeface(typeface);
		r18.setTypeface(typeface);
		r19.setTypeface(typeface);
		
		//第三行
		  	RadioButton r20=(RadioButton)this.findViewById(R.id.button_20);
	        RadioButton r21=(RadioButton)this.findViewById(R.id.button_21);
	        RadioButton r22=(RadioButton)this.findViewById(R.id.button_22);
	        RadioButton r23=(RadioButton)this.findViewById(R.id.button_23);
	        RadioButton r24=(RadioButton)this.findViewById(R.id.button_24);
	        RadioButton r25=(RadioButton)this.findViewById(R.id.button_25);
	        RadioButton r26=(RadioButton)this.findViewById(R.id.button_26);
	        RadioButton r27=(RadioButton)this.findViewById(R.id.button_27);
	        r20.setTypeface(typeface);
			r21.setTypeface(typeface);
			r22.setTypeface(typeface);
			r23.setTypeface(typeface);
			r24.setTypeface(typeface);
			r25.setTypeface(typeface);
			r26.setTypeface(typeface);
			r27.setTypeface(typeface);
			r27.setTextColor(Color.RED);
			
			//////////////
			//第四行
		  	RadioButton r30=(RadioButton)this.findViewById(R.id.button_30);
	        RadioButton r31=(RadioButton)this.findViewById(R.id.button_31);
	        RadioButton r32=(RadioButton)this.findViewById(R.id.button_32);
	        RadioButton r33=(RadioButton)this.findViewById(R.id.button_33);
	        RadioButton r34=(RadioButton)this.findViewById(R.id.button_34);
	        RadioButton r35=(RadioButton)this.findViewById(R.id.button_35);
	        RadioButton r36=(RadioButton)this.findViewById(R.id.button_36);
	        RadioButton r37=(RadioButton)this.findViewById(R.id.button_37);
	        r30.setTypeface(typeface);
			r31.setTypeface(typeface);
			r32.setTypeface(typeface);
			r33.setTypeface(typeface);
			r34.setTypeface(typeface);
			r35.setTypeface(typeface);
			r36.setTypeface(typeface);
			r37.setTypeface(typeface);
			
			/////////////////Button/////
			  boxorun=(Button)this.findViewById(R.id.boxorun);
			  kaytix=(Button)this.findViewById(R.id.kaytix);
			  izdax=(Button)this.findViewById(R.id.izdax);
			  oqurux=(Button)this.findViewById(R.id.oqurux);
			  
			  
			  boxorun.setTypeface(typeface);
			  kaytix.setTypeface(typeface);
			  izdax.setTypeface(typeface);
			  oqurux.setTypeface(typeface);
			  
			  
			  boxorun.setOnClickListener(this);
			  kaytix.setOnClickListener(this);
			  izdax.setOnClickListener(this);
			  oqurux.setOnClickListener(this);
			  
			  
			  
		
			  
			  
    }



	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		/*
		 if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
  //横向 
  setContentView(R.layout.file_list_landscape); 
}else{
  //竖向 
   setContentView(R.layout.file_list); 

		 */
		super.onConfigurationChanged(newConfig);
	}


	@Override
	public void onCheckedChanged(RadioGroup arg0, int id) {
		// TODO Auto-generated method stub
		RadioButton r=(RadioButton)this.findViewById(id);
		if(r!=null)
		{
			strText=strText+r.getText().toString();

			r.setChecked(false);
			inputText.setText(cls.getShape(strText));
			inputText.setSelection(strText.length());
		}
	}
	
	@Override
	public void onClick(View btn) {
		
		if(btn==boxorun)
		{
			strText=strText+" ";
			inputText.setText(cls.getShape(strText));
		}
		else if(btn==oqurux&strText.length()>0) 
		{
			strText=strText.substring(0,strText.length()-1);
			inputText.setText(cls.getShape(strText));
		}
		else if(btn==kaytix)
		{
			this.finish();
		}
		else if(btn==izdax)
		{
			cwait.show();
			new Thread( new Runnable() {     
			    public void run() {     
			    	
			    	mHandler.sendEmptyMessage(2);
			    }
			}).start();
			/*
			fangwenService cls=new fangwenService();
			txt_natija.setText(cls.callChaXunWeiHan(strText));
			*/
		
		}
	}
	
	 private Handler mHandler = new Handler(){  
         
	        public void handleMessage(Message msg) {  
	        	try
				{
	        	
				fangwenService cls=new fangwenService();
				String result=cls.callChaXunWeiHan(strText.trim());
				String []str=result.split("；");
				ConvertUL cls2=new ConvertUL();
				result="";
				for(String strOne:str)
				{
					result+=strOne.trim()+"\n";
				}
		
			//	result=cls2.GetULUyghurWord(result);
				txt_natija.setText(result);
				}
				catch(Exception ex)
				{
					
					Toast toast;
					toast = Toast.makeText(getApplicationContext(),
						     ex.getMessage(), Toast.LENGTH_LONG);
						   toast.setGravity(Gravity.CENTER, 0, 0);
						   toast.show();
					
					/*
				
					LayoutInflater inflater = getLayoutInflater();
					   View layout = inflater.inflate(R.layout.custom_toast,
					     (ViewGroup) findViewById(R.id.llToast));
					   ImageView image = (ImageView) layout
					     .findViewById(R.id.tvImageToast);
					   image.setImageResource(R.drawable.icon);
					   TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
					   title.setText("Attention");
					   TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
					   text.setText();
					   toast = new Toast(getApplicationContext());
					   toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);
					   toast.setDuration(Toast.LENGTH_LONG);
					   toast.setView(layout);
					   toast.show();
					   */
					
				}
				cwait.dismiss();
	        }
	        }; 
	
	
}