package com.lianxin.pubqq.setup;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Editable;
//import android.text.TextUtils;
import android.text.TextWatcher;
//import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lianxin.pubqq.R;
import com.lianxin.panqq.common.BaseActivity;
import com.lianxin.panqq.common.Utils;
//import com.lianxin.panqq.client.entity.RegisterFor;
import com.lianxin.panqq.picker.AddressPickerDialog;
import com.lianxin.panqq.picker.HeadPickerDialog;

//注册
public class ContactWayActivity extends BaseActivity implements OnClickListener {
	private TextView txt_title;
	private ImageView img_back;
	private Button btn_register, btn_send;
	private EditText et_usertel, et_password, et_code;
	
    RadioGroup rag_sex;
    RadioButton rab_sex_male;
    RadioButton rab_sex_female;	
	private MyCount mc;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_contactway);
		super.onCreate(savedInstanceState);
		
		initControl();
		initView();
		initData();
		setListener();	
	}

	protected void initControl() {
		img_back = (ImageView) findViewById(R.id.img_back);
	
	}

	protected void initView() {

	}

	protected void initData() {
	}

	protected void setListener() {

		img_back.setOnClickListener(this);
	
		
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		if (id == R.id.img_back) {
			Utils.finish(ContactWayActivity.this);
		} else if (id == R.id.btn_send) {
			if (mc == null) {
				mc = new MyCount(60000, 1000); // 第一参数是总的时间，第二个是间隔时间
			}
			mc.start();
			//		getCode();
		} else if (id == R.id.btn_register) {
			getRegister();
		} else if (id == R.id.rl_user_image) {//修改头像
			change_image();
		} else if (id == R.id.rl_user_address) {//修改城市
			change_address();
		} else if (id == R.id.tv_user_address) {//修改城市
			change_address();
		}
	}

	private void getRegister() {

	}



	// 手机号 EditText监听器
	class TelTextChange implements TextWatcher {

		@Override
		public void afterTextChanged(Editable arg0) {

		}

		@Override
		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {

		}

		@Override
		public void onTextChanged(CharSequence cs, int start, int before,
				int count) {
			String phone = et_usertel.getText().toString();
			if (phone.length() == 11) {
				if (Utils.isMobileNO(phone)) {
					btn_send.setBackgroundDrawable(getResources().getDrawable(
							R.drawable.btn_bg_green));
					btn_send.setTextColor(0xFFFFFFFF);
					btn_send.setEnabled(true);
					btn_register.setBackgroundDrawable(getResources()
							.getDrawable(R.drawable.btn_bg_green));
					btn_register.setTextColor(0xFFFFFFFF);
					btn_register.setEnabled(true);
				} else {
					et_usertel.requestFocus();
					Utils.showLongToast(context, "请输入正确的手机号码！");
				}
			} else {
				btn_send.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.btn_enable_green));
				btn_send.setTextColor(0xFFD0EFC6);
				btn_send.setEnabled(false);
				btn_register.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.btn_enable_green));
				btn_register.setTextColor(0xFFD0EFC6);
				btn_register.setEnabled(true);
			}
		}
	}
	/**
	 * 更改头像
	 */
	public void change_image(){
 
        Intent intent = new Intent(this, HeadPickerDialog.class);
       // startActivityForResult(intent, REQUEST_CODE);	
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         
       // UserEdit.this.startActivity(intent);
        context.startActivity(intent);
   /*     Intent intent = new Intent(this, LoginActivity.class);	
        //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         
        startActivity(intent);  */      
	}	
	/**
	 * 更改地址
	 */
	public void change_address(){
 
  /*      Intent intent = new Intent(this, CityPickerDialog.class);	
        //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         
        startActivity(intent);  */ 
	       new AddressPickerDialog(this, AlertDialog.THEME_HOLO_LIGHT).show();			
	}
	// EditText监听器
	class TextChange implements TextWatcher {

		@Override
		public void afterTextChanged(Editable arg0) {

		}

		@Override
		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {

		}

		@Override
		public void onTextChanged(CharSequence cs, int start, int before,
				int count) {
			boolean Sign1 = et_code.getText().length() > 0;
			boolean Sign2 = et_usertel.getText().length() > 0;
			boolean Sign3 = et_password.getText().length() > 0;

			if (Sign1 & Sign2 & Sign3) {
				btn_register.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.btn_bg_green));
				btn_register.setTextColor(0xFFFFFFFF);
				btn_register.setEnabled(true);
			} else {
				btn_register.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.btn_enable_green));
				btn_register.setTextColor(0xFFD0EFC6);
				btn_register.setEnabled(false);
			}
		}
	}

	/* 定义一个倒计时的内部类 */
	private class MyCount extends CountDownTimer {
		public MyCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}

		@Override
		public void onFinish() {
			btn_send.setEnabled(true);
			btn_send.setText("发送验证码");
		}

		@Override
		public void onTick(long millisUntilFinished) {
			btn_send.setEnabled(false);
			btn_send.setText("(" + millisUntilFinished / 1000 + ")秒");
		}
	}

	private void initUserList() {
	/*	Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
		startActivity(intent);
		overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
		finish();*/
	}
}
