package com.sabirjan.android;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import org.xmlpull.v1.XmlPullParserException;

import com.sabirjan.CaoZuoTXT.ChaXunDianHua;
import com.sabirjan.Dialog.InfoDialog;
import com.sabirjan.DrawUyghurWord.SetUyghurTypeface;
import com.sabirjan.android.R;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class GetMobileNumberInfo_Activity extends Activity {
	private static final String TAG = "MainActivity";
	private EditText mobileEditText = null;  //输入的查询手机号
	private Button addressButton = null;     //查询按钮
	private TextView addressResult1 ,addressResult2,addressResult3,addressResult4,addressResult5,addressResult6;   //显示查询的地址
	String mobile;
	String address;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mobilemain);
        
        mobileEditText = (EditText)findViewById(R.id.mobile);
        addressButton = (Button)findViewById(R.id.btn_mobile_1);
        addressResult1 = (TextView)findViewById(R.id.txt_mobile_address1);
        addressResult1=SetUyghurTypeface.GetTextView(this, addressResult1);
        addressResult2 = (TextView)findViewById(R.id.txt_mobile_address2);
        addressResult2=SetUyghurTypeface.GetTextView(this, addressResult2);
        addressResult3 = (TextView)findViewById(R.id.txt_mobile_address3);
        addressResult3=SetUyghurTypeface.GetTextView(this, addressResult3);
        addressResult4 = (TextView)findViewById(R.id.txt_mobile_address4);
        addressResult4=SetUyghurTypeface.GetTextView(this, addressResult4);
        addressResult5 = (TextView)findViewById(R.id.txt_mobile_address5);
        addressResult5=SetUyghurTypeface.GetTextView(this, addressResult5);
        
        addressResult6= (TextView)findViewById(R.id.txt_mobile_address6);
        addressResult6=SetUyghurTypeface.GetTextView(this, addressResult6);
       
        addressResult2.setTextColor(Color.GREEN);
        addressResult4.setTextColor(Color.GREEN);
        addressResult6.setTextColor(Color.GREEN);
        
        
        
        addressButton=SetUyghurTypeface.GetButton(this, addressButton);
        TextView txtInfo=(TextView)this.findViewById(R.id.txt_mobile_1);
        txtInfo=SetUyghurTypeface.GetTextView(this, txtInfo);
        TextView txtInfo2=(TextView)this.findViewById(R.id.txt_mobile_2);
        txtInfo2=SetUyghurTypeface.GetTextView(this, txtInfo2);
        addressButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v)
			{
				mobile= mobileEditText.getText().toString();
				if(mobile.trim().length()<11|mobile.trim().length()>11)
				{
					InfoDialog errorInfo=new InfoDialog(GetMobileNumberInfo_Activity.this," ﻛﻪﭼﯘﺭﯗﯓ ،   ﻛﯩﺰﮔﯜﺯﮔﻪﻥ ﻧﻮﻣﯘﺭﯨﯖﯩﺰﺩﺍ  ﺧﺎﺗﺎﻟﯩﻖ ﺑﺎﺭ ");
					errorInfo.show();
					return ;
				}
				UIUpdateThread cls=new UIUpdateThread();
				cls.start();
				
			
			}
		});
    }
    class UIUpdateThread extends Thread{
        public void run() {
            try {
         			try {
					ChaXunDianHua cls=new ChaXunDianHua();
					address=cls.GetNumberInfo(GetMobileNumberInfo_Activity.this,mobile);
				
					
				
				} catch(Exception e) {
			//		Log.e(TAG, e.toString());
					
					Toast.makeText(GetMobileNumberInfo_Activity.this, e.getMessage(), Toast.LENGTH_LONG).show();
				}
                mHandler.post(mUpdateResults);
            } catch (Exception e) {
            	
				Toast.makeText(GetMobileNumberInfo_Activity.this, e.getMessage(), Toast.LENGTH_LONG).show();
		
            }
            
        }
        
         final Handler mHandler = new Handler();
            final Runnable mUpdateResults = new Runnable() {
                public void run() {
                //    invalidate(); //更新视图
                	if(address.trim().length()==0)
					{
						address=" ﻣﻪﺯﻛﯘﺭ ﻧﻮﻣﯘﺭ ﺗﯧﭙﯩﻠﻤﯩﺪﻯ  ،  ﻛﻪﭼﯘﺭﯗﯓ";
						addressResult1.setText(address);
						addressResult3.setText("");
						addressResult4.setText("");
						addressResult2.setText("");
						addressResult5.setText("");
						addressResult6.setText("");
						return;
					}
                	try
                	{
                	String []str=SplitString(address+";",";");
                	addressResult1.setText("ﺗﯧﻠﯩﻔﻮﻥ ﻧﻮﻣﯘﺭﻯ");
                	addressResult2.setText(mobile);
					addressResult3.setText("ﺭﺍﻳﻮﻥ ﻧﻮﻣﯘﺭﻯ");
					addressResult4.setText(str[1]);
					addressResult5.setText("ﺭﺍﻳﻮﻥ ﺋﯩﺴﻤﻰ");
					addressResult6.setText(str[2]);
					System.out.println("Len="+str.length);
                	}
                	catch(Exception ex)
                	{System.out.println("Len="+ex.getMessage());
                		
                	}
                }
            };
        
}
    private String[] SplitString(String input,String regex)
	{
		//取字符串的起始位置
		int startindex=0;
		//将结构数据现放入到vector里面
		Vector v=new Vector();
		String []str={""};
		
	try
	{
		int index=0;
		
		startindex=input.indexOf(regex);
		while((startindex<input.length())&startindex!=-1)
		{
			
			String temp=input.substring(index,startindex).trim();
			if(temp.trim().length()>0)
				v.addElement(temp);
			index=startindex+regex.length();
			startindex=input.indexOf(regex,startindex+regex.length());
		}
		str=new String[v.size()];
		for(int i=0;i<v.size();i++)
		{
			str[i]=(String)v.elementAt(i);
		}
	}
	catch(Exception ex)
	{
		str[0]=ex.getMessage();
	}
		return str;
	}

}