diff --git a/iFish7/src/main/java/com/ifish/activity/RegisteredActivity.java b/iFish7/src/main/java/com/ifish/activity/RegisteredActivity.java index cafe462b1..fa779b0c1 100644 --- a/iFish7/src/main/java/com/ifish/activity/RegisteredActivity.java +++ b/iFish7/src/main/java/com/ifish/activity/RegisteredActivity.java @@ -1,7 +1,9 @@ package com.ifish.activity; +import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; import android.text.TextUtils; @@ -63,58 +65,64 @@ import cn.smssdk.SMSSDK; import de.greenrobot.event.EventBus; /** - * -* @ClassName: RegisteredActivity -* @Description: 注册界面 -* @author Jacky dada -* @date 2015-9-2 下午6:45:16 + * @author Jacky dada + * @ClassName: RegisteredActivity + * @Description: 注册界面 + * @date 2015-9-2 下午6:45:16 */ -public class RegisteredActivity extends BaseActivityNotAnim{ - long waitTime = 2000;//2秒退出时间 - long touchTime = 0; - private ImageView title_img; - private TextView title_text,title_text_right,tv_country; - private CheckBox ct_check; - private Toast toast; - private EditText et_phone,et_messge,et_psw; - private TextView tv_code; - private HttpManager hm=HttpManager.getInstance(); - private int CURRENTDELAYTIME; - private final int DELAYTIME = 60;//60S倒数 - private int disableColor = drawable.tvcode_press_noright_shape; - private int ebleColor = drawable.login_bt_noright_shape; - private Timer timer;// 定时器,用于更新下载进度 - private TimerTask task;// 定时器执行的任务 - private int doRegisteredResult; - private int result; - private User loginUser; - private SPUtil sp; - private ConfigUtil cp; - private LocationClient mLocationClient; - EventHandler eh=null; - private final String UnknownHostException="UnknownHostException"; - private CountryCode countryCode; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.registered_activity); - initTitle("注册","登录"); - initView(); - init(); - initListener(); - initLocation();//百度定位 - } - private void test(){ - findViewById(R.id.iv_test).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showProgressDialog(); - doRegistered(); - } - }); +public class RegisteredActivity extends BaseActivityNotAnim { + long waitTime = 2000;//2秒退出时间 + long touchTime = 0; + private ImageView title_img; + private TextView title_text, title_text_right, tv_country, tv_changesmscode; + private CheckBox ct_check; + private Toast toast; + private EditText et_phone, et_messge, et_psw; + private TextView tv_code, tv_msgcode; + private HttpManager hm = HttpManager.getInstance(); + private int CURRENTDELAYTIME; + private final int DELAYTIME = 60;//60S倒数 + private int disableColor = drawable.tvcode_press_noright_shape; + private int ebleColor = drawable.login_bt_noright_shape; + private Timer timer;// 定时器,用于更新下载进度 + private TimerTask task;// 定时器执行的任务 + private int doRegisteredResult; + private int result; + private User loginUser; + private SPUtil sp; + private ConfigUtil cp; + private LocationClient mLocationClient; + EventHandler eh = null; + private final String UnknownHostException = "UnknownHostException"; + private CountryCode countryCode; + private TimeCount time; + private String smsCode; + private Activity act; + private boolean isShowSmsCode = false; - } - private void initLocation(){ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.registered_activity); + initTitle("注册", "登录"); + initView(); + init(); + initListener(); + initLocation();//百度定位 + } + + private void test() { + findViewById(R.id.iv_test).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showProgressDialog(); + doRegistered(); + } + }); + + } + + private void initLocation() { LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationMode.Hight_Accuracy);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 option.setCoorType("gcj02");//可选,默认gcj02,设置返回的定位结果坐标系, @@ -125,124 +133,126 @@ public class RegisteredActivity extends BaseActivityNotAnim{ option.setIgnoreKillProcess(false);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死 mLocationClient.setLocOption(option); } - private void initView() { - ct_check = (CheckBox) findViewById(R.id.ct_check); - tv_code = (TextView) findViewById(R.id.tv_code); - et_phone = (EditText) findViewById(R.id.et_phone); - et_messge = (EditText) findViewById(R.id.et_messge); - et_psw = (EditText) findViewById(R.id.et_psw); - tv_country=findMyViewById(R.id.tv_country); -} - private void initTitle(String title,String right) { - title_img = (ImageView) findViewById(R.id.title_img); - title_img.setVisibility(View.GONE); - title_text = (TextView) findViewById(R.id.title_text); - title_text_right = (TextView) findViewById(R.id.title_text_right); - title_text.setText(title); - title_text_right.setText(right); - title_text_right.setOnClickListener(this); - } - public void init() { - cp=ConfigUtil.getInstance(RegisteredActivity.this); - toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); - timer = new Timer(); - mLocationClient = ((BaseApplication)getApplication()).mLocationClient;//定位 - eh=new EventHandler() { - @Override - public void afterEvent(int event, int result, Object data) { - Message msg = new Message(); - msg.arg1 = event; - msg.arg2 = result; - msg.obj = data; - mHandler.sendMessage(msg); - } - }; - SMSSDK.registerEventHandler(eh); - EventBus.getDefault().register(this); - } - - - Handler mHandler = new Handler(){ - public void handleMessage(Message msg) { - super.handleMessage(msg); - int event = msg.arg1; - int result = msg.arg2; - Object data = msg.obj; - if (result == SMSSDK.RESULT_COMPLETE) { - if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {//提交验证码成功 - //提交验证码成功 - 去注册 - doRegistered(); - }else if (event ==SMSSDK.EVENT_GET_VOICE_VERIFICATION_CODE){ - ToastUtil.show(getApplicationContext(), "语音验证码已发送 注意接听手机来电"); - } - } else { - dismissProgressDialog(); - if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) { - //提交验证码失败 - if (data!=null) { - if (data.toString().contains(UnknownHostException)) {//没有网络 - ToastUtil.show(getApplicationContext(), Text.ERROR); - return; - } - } - int status = 0; - try { - ((Throwable) data).printStackTrace(); - Throwable throwable = (Throwable) data; - JSONObject object = new JSONObject(throwable.getMessage()); - String des = object.optString("detail"); - status = object.optInt("status"); - if (!TextUtils.isEmpty(des)) { - ToastUtil.show(getApplicationContext(), des); - return; - } - } catch (Exception e) { - ToastUtil.show(getApplicationContext(), "获取失败"); - } - }else { - //获取验证码失败 - if (data!=null) { - if (data.toString().contains(UnknownHostException)) {//没有网络 - ToastUtil.show(getApplicationContext(), Text.ERROR); - //获取验证码失败 - task.cancel(); - tv_code.setClickable(true); - tv_code.setText(getResources().getString(R.string.voice_code)); - tv_code.setBackgroundDrawable(tv_code - .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); - return; - } - } - int status = 0; - try { - ((Throwable) data).printStackTrace(); - Throwable throwable = (Throwable) data; - JSONObject object = new JSONObject(throwable.getMessage()); - String des = object.optString("detail"); - status = object.optInt("status"); - if (!TextUtils.isEmpty(des)) { - ToastUtil.show(getApplicationContext(), des); - //获取验证码失败 - task.cancel(); - tv_code.setClickable(true); - tv_code.setText(getResources().getString(R.string.voice_code)); - tv_code.setBackgroundDrawable(tv_code - .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); - return; - } - } catch (Exception e) { - ToastUtil.show(getApplicationContext(), "获取失败"); - } - } - - } - } - }; + private void initView() { + act = this; + ct_check = (CheckBox) findViewById(R.id.ct_check); + tv_code = (TextView) findViewById(R.id.tv_code); + tv_msgcode = (TextView) findViewById(R.id.tv_msgcode); + et_phone = (EditText) findViewById(R.id.et_phone); + et_messge = (EditText) findViewById(R.id.et_messge); + et_psw = (EditText) findViewById(R.id.et_psw); + tv_changesmscode = (TextView) findViewById(R.id.tv_changesmscode); + tv_country = findMyViewById(R.id.tv_country); + time = new TimeCount(60000, 1000); + } + private void initTitle(String title, String right) { + title_img = (ImageView) findViewById(R.id.title_img); + title_img.setVisibility(View.GONE); + title_text = (TextView) findViewById(R.id.title_text); + title_text_right = (TextView) findViewById(R.id.title_text_right); + title_text.setText(title); + title_text_right.setText(right); + title_text_right.setOnClickListener(this); + } + public void init() { + cp = ConfigUtil.getInstance(RegisteredActivity.this); + toast = Toast.makeText(this, "", Toast.LENGTH_SHORT); + timer = new Timer(); + mLocationClient = ((BaseApplication) getApplication()).mLocationClient;//定位 + eh = new EventHandler() { + @Override + public void afterEvent(int event, int result, Object data) { + Message msg = new Message(); + msg.arg1 = event; + msg.arg2 = result; + msg.obj = data; + mHandler.sendMessage(msg); + } + }; + SMSSDK.registerEventHandler(eh); + EventBus.getDefault().register(this); + showSmsCode(); + } + Handler mHandler = new Handler() { + public void handleMessage(Message msg) { + super.handleMessage(msg); + int event = msg.arg1; + int result = msg.arg2; + Object data = msg.obj; + if (result == SMSSDK.RESULT_COMPLETE) { + if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {//提交验证码成功 + //提交验证码成功 - 去注册 + doRegistered(); + } else if (event == SMSSDK.EVENT_GET_VOICE_VERIFICATION_CODE) { + ToastUtil.show(getApplicationContext(), "语音验证码已发送 注意接听手机来电"); + } + } else { + dismissProgressDialog(); + if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) { + //提交验证码失败 + if (data != null) { + if (data.toString().contains(UnknownHostException)) {//没有网络 + ToastUtil.show(getApplicationContext(), Text.ERROR); + return; + } + } + int status = 0; + try { + ((Throwable) data).printStackTrace(); + Throwable throwable = (Throwable) data; + JSONObject object = new JSONObject(throwable.getMessage()); + String des = object.optString("detail"); + status = object.optInt("status"); + if (!TextUtils.isEmpty(des)) { + ToastUtil.show(getApplicationContext(), des); + return; + } + } catch (Exception e) { + ToastUtil.show(getApplicationContext(), "获取失败"); + } + } else { + //获取验证码失败 + if (data != null) { + if (data.toString().contains(UnknownHostException)) {//没有网络 + ToastUtil.show(getApplicationContext(), Text.ERROR); + //获取验证码失败 + task.cancel(); + tv_code.setClickable(true); + tv_code.setText(getResources().getString(R.string.voice_code)); + tv_code.setBackgroundDrawable(tv_code + .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); + return; + } + } + int status = 0; + try { + ((Throwable) data).printStackTrace(); + Throwable throwable = (Throwable) data; + JSONObject object = new JSONObject(throwable.getMessage()); + String des = object.optString("detail"); + status = object.optInt("status"); + if (!TextUtils.isEmpty(des)) { + ToastUtil.show(getApplicationContext(), des); + //获取验证码失败 + task.cancel(); + tv_code.setClickable(true); + tv_code.setText(getResources().getString(R.string.voice_code)); + tv_code.setBackgroundDrawable(tv_code + .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); + return; + } + } catch (Exception e) { + ToastUtil.show(getApplicationContext(), "获取失败"); + } + } + } + } + }; @Override @@ -250,361 +260,460 @@ public class RegisteredActivity extends BaseActivityNotAnim{ mLocationClient.stop(); super.onStop(); } - public void initListener() { - findViewById(R.id.tv_code).setOnClickListener(this); - findViewById(R.id.bt_submit).setOnClickListener(this); - findViewById(R.id.tv_check).setOnClickListener(this); - findViewById(R.id.rl_bg).setOnClickListener(this); - findViewById(R.id.rl_country).setOnClickListener(this); - } - /** - * - * @Description: 60S短信倒数 - * @author Jacky dada - * @param - * @date 2015-9-6 下午8:15:45 - */ - private void startTime() { - CURRENTDELAYTIME = DELAYTIME; - task = new TimerTask() { - @Override - public void run() { - UIHandler.sendEmptyMessage(7); - } - }; - timer.schedule(task,0,1000); - } - Handler UIHandler = new Handler(){ - public void handleMessage(android.os.Message msg) { - switch (msg.what) { - case 7: - if(CURRENTDELAYTIME<=0){ + public void initListener() { + findViewById(R.id.tv_code).setOnClickListener(this); + findViewById(R.id.tv_msgcode).setOnClickListener(this); + findViewById(R.id.bt_submit).setOnClickListener(this); + findViewById(R.id.tv_check).setOnClickListener(this); + findViewById(R.id.rl_bg).setOnClickListener(this); + findViewById(R.id.rl_country).setOnClickListener(this); + tv_changesmscode.setOnClickListener(this); + } - task.cancel(); - tv_code.setClickable(true); - tv_code.setText(getResources().getString(R.string.voice_code)); - tv_code.setBackgroundDrawable(tv_code - .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); - }else{ - CURRENTDELAYTIME--; - tv_code.setText(CURRENTDELAYTIME+"\""); - } - break; - - default: - break; - } - }; - }; - Handler loginHandler = new Handler(){ - public void handleMessage(android.os.Message msg) { - /** - * 注册后登录成功到主界面 否则则去登录界面 手机号已存SP 自动读取 - */ - if(NetWork.Success==msg.what){ - saveInfo(); - ToastUtil.show(getApplicationContext(), "注册成功"); - dismissProgressDialog(); - startActivity(MainTabActivity.class); - finish(); - }else{ - dismissProgressDialog(); - ToastUtil.show(getApplicationContext(), "注册成功 请登录"); - startActivity(LoginActivity.class); - AnimationUtil.startAnimation(RegisteredActivity.this); - finish(); - } - } - }; - private void saveInfo(){ - //登录成功保存个人信息 - Commons.USER=loginUser; - Commons.PHONE_NUM=et_phone.getText().toString(); - Commons.CODE=MD5Util.GetMD5(et_psw.getText().toString()); - sp=SPUtil.getInstance(getApplicationContext()); - sp.putBoolean(LoginSPKey.IS_LOGIN, true); - sp.putBoolean(LoginSPKey.IS_CAMERA, Commons.IS_CAMERA); - sp.putString(LoginSPKey.PHONE_NUM, et_phone.getText().toString()); - sp.putString(LoginSPKey.PASSWORD, Commons.CODE); - sp.putString(LoginSPKey.USER_ID, loginUser.getUserId()); - sp.putString(LoginSPKey.NICKNAME, loginUser.getNickName()); - sp.putString(LoginSPKey.USERIMG, loginUser.getUserImg()); - sp.putString(LoginSPKey.UPDATETIME, loginUser.getUpdateTime()); - sp.putString(LoginSPKey.P2PVerifyCode1, loginUser.P2PVerifyCode1); - sp.putString(LoginSPKey.P2PVerifyCode2, loginUser.P2PVerifyCode2); - sp.putString(LoginSPKey.GeeWeUserId, loginUser.gwellUserID); - } - Handler regeditHandler = new Handler(){ - public void handleMessage(android.os.Message msg) { - /** - * 1:注册成功 - 0:注册失败 - */ - switch (msg.what) { - case NetWork.Success: - cp.putBoolean(LoginSPKey.IS_LOGIN, true); - cp.putString(LoginSPKey.PHONE_NUM, et_phone.getText().toString()); - userLogin();//注册成功就登录请求 - break; - case NetWork.Fail: - ToastUtil.show(getApplicationContext(),"注册失败"); - dismissProgressDialog(); - break; - case NetWork.ERROR: - ToastUtil.show(getApplicationContext(), Text.ERROR); - dismissProgressDialog(); - break; - case NetWork.RepeatMobile: - ToastUtil.show(getApplicationContext(), "手机号已被注册 请直接登录"); - cp.putBoolean(LoginSPKey.IS_LOGIN, true); - cp.putString(LoginSPKey.PHONE_NUM, et_phone.getText().toString()); - dismissProgressDialog(); - startActivity(LoginActivity.class); - AnimationUtil.startAnimation(RegisteredActivity.this); - finish(); - break; - - default: - ToastUtil.show(getApplicationContext(), Text.ServerException); - dismissProgressDialog(); - break; - } - } - }; - @Override - protected void onDestroy() { - SMSSDK.unregisterEventHandler(eh); - if(task != null){ - task.cancel(); - timer.cancel(); - timer = null; - task = null; - } - EventBus.getDefault().unregister(this); - super.onDestroy(); - } - @Override - public void onBackPressed() { - long currentTime = System.currentTimeMillis(); - if ((currentTime - touchTime) >= waitTime) { - showToast("再按一次退出程序"); - touchTime = currentTime; - } else { - ActivityManager.getInstance().exit(); - } - } - @Override - public void onClick(View v) { - // 点击事件 - Intent i=new Intent(); - switch (v.getId()) { - case R.id.rl_bg: - hideKeyboard(); - break; - case R.id.tv_check: - i.setClass(this, WebViewActivity.class);//注册协议 - i.putExtra(WebViewActivity.URL, HttpManager.REGISTERAGREEMENT_URL); - i.putExtra(WebViewActivity.WEBVIEWTITLE, Text.REGISTERAGREEMENT); - startActivity(i); - AnimationUtil.startAnimation(this); - break; - case R.id.title_text_right://跳转登录 - i.setClass(this, LoginActivity.class); - startActivity(i); - AnimationUtil.startAnimation(this); - finish(); - break; - case R.id.bt_submit: {//注册 - if(et_phone.getText().toString().replaceAll(" ","").length()==0){ - ToastUtil.show(getApplicationContext(), "请输入手机号"); - return; - } - if (et_messge.getText().toString().replaceAll(" ","").length() == 0) { - ToastUtil.show(getApplicationContext(), "请输入短信验证码"); - return; - } - if (et_psw.getText().toString().length() < 6) { - ToastUtil.show(getApplicationContext(), "密码不能短于六位"); - return; - } - if (!ct_check.isChecked()) { - ToastUtil.show(getApplicationContext(), "您必须同意爱鱼奇服务"); - return; - } - hideKeyboard(); - showProgressDialog(); - if (countryCode == null) { - countryCode=new CountryCode("86","中国"); - } - SMSSDK.submitVerificationCode(countryCode.countryCode, et_phone.getText().toString(), et_messge.getText().toString()); - break; - } - case R.id.tv_code: {//注册验证码 - if(et_phone.getText().toString().replaceAll(" ","").length()==0){ - ToastUtil.show(getApplicationContext(),"请输入手机号"); - return; - } - if (countryCode == null) { - countryCode=new CountryCode("86","中国"); - } - SMSSDK.getVoiceVerifyCode(countryCode.countryCode, et_phone.getText().toString()); - mLocationClient.start();//定位SDK start之后会默认发起一次定位请求,开发者无须判断isstart并主动调用request - mLocationClient.requestLocation(); - tv_code.setClickable(false); - tv_code.setBackgroundDrawable(tv_code - .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); - tv_code.setText("60\""); - startTime(); - break; - } - case R.id.rl_country: {//国家代码 - startActivity(CountryListActivity.class); - AnimationUtil.startAnimation(RegisteredActivity.this); - break; - } - - default: - break; - } - } - - - /** - * 国家/地区发生改变 - * @param event + /** + * @param + * @Description: 60S短信倒数 + * @author Jacky dada + * @date 2015-9-6 下午8:15:45 */ - public void onEventMainThread(CountryCode event) { - if (tv_country != null) { - tv_country.setText(event.country+" +"+event.countryCode); - } - countryCode=event; - } - /** - * - * @Description: 注册成功就接着发登录的请求 - * @author Jacky dada - * @param - * @date 2015-9-6 下午7:20:42 - */ - private void doRegistered() { - hm.register(new HttpListener>() { - @Override - public void success(BaseBean baseBean) { - doRegisteredResult = baseBean.result; - } + private void startTime() { + CURRENTDELAYTIME = DELAYTIME; + task = new TimerTask() { - @Override - public void finish() { - regeditHandler.sendEmptyMessage(doRegisteredResult); - } + @Override + public void run() { + UIHandler.sendEmptyMessage(7); + } + }; + timer.schedule(task, 0, 1000); + } - @Override - public void error(Exception e, String msg) { - doRegisteredResult=NetWork.ERROR; - } - }, et_phone.getText().toString(),et_psw.getText().toString()); - } - /** - * - * @Description: 登录 - * @author Jacky dada - * @param - * @date 2015-9-8 下午2:33:05 - */ - private void userLogin() { - hm.userLogin(new HttpListener>() { - @Override - public void success(BaseBean baseBean) { - if(baseBean==null){ - result=NetWork.ERROR; - return; - } - result=baseBean.result; - if (result==NetWork.Success) { - loginUser=baseBean.data.getUser(); - Commons.USER=loginUser; - List device = baseBean.data.getDevice(); - List camera = baseBean.data.camera; - List deviceCamera = baseBean.data.deviceCamera; - Commons.DEVICE=device; - Commons.CAMERA=camera; - Commons.INFO=baseBean.data.information; - Commons.DeviceCamera=deviceCamera; - Commons.SHOP=baseBean.data.shopsInfo; - Commons.SHOP2=baseBean.data.shopsInfo2; - Commons.USERASSET=baseBean.data.userAsset; - Commons.GOLDTASKS=baseBean.data.goldTasks; - if (device.size()==0) { - Commons.HAVE_DEVICE=false; - }else{ - Commons.HAVE_DEVICE=true; - Commons.IS_EventBus=true; - } - if (camera.size()==0) { - Commons.HAVE_CAMERA=false; - }else{ - Commons.HAVE_CAMERA=true; - } - if (!Commons.HAVE_DEVICE&&Commons.HAVE_CAMERA) {//用户没有鱼缸,只有摄像头则默认展示摄像头界面 - Commons.IS_CAMERA=true; - }else{ - Commons.IS_CAMERA=false; - } - /** - * 登录云信 - */ - AbortableFuture login = NIMClient.getService(AuthService.class).login(new LoginInfo(Commons.USER.getUserId(), Commons.USER.neteaseToken)); - login.setCallback(new RequestCallback() { + Handler UIHandler = new Handler() { + public void handleMessage(android.os.Message msg) { + switch (msg.what) { + case 7: + if (CURRENTDELAYTIME <= 0) { - @Override - public void onException(Throwable arg0) { - arg0.printStackTrace(); - L.d("yunxin onException"); - } + task.cancel(); + tv_code.setClickable(true); + tv_code.setText(getResources().getString(R.string.voice_code)); + tv_code.setBackgroundDrawable(tv_code + .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); + } else { + CURRENTDELAYTIME--; + tv_code.setText(CURRENTDELAYTIME + "\""); + } + break; - @Override - public void onFailed(int arg0) { - // TODO Auto-generated method stub - L.d("yunxin onFailed code="+arg0+" Account="+Commons.USER.getUserId()+" token="+Commons.USER.neteaseToken); + default: + break; + } + } - } + ; + }; + Handler loginHandler = new Handler() { + public void handleMessage(android.os.Message msg) { + /** + * 注册后登录成功到主界面 否则则去登录界面 手机号已存SP 自动读取 + */ + if (NetWork.Success == msg.what) { + saveInfo(); + ToastUtil.show(getApplicationContext(), "注册成功"); + dismissProgressDialog(); + startActivity(MainTabActivity.class); + finish(); + } else { + dismissProgressDialog(); + ToastUtil.show(getApplicationContext(), "注册成功 请登录"); + startActivity(LoginActivity.class); + AnimationUtil.startAnimation(RegisteredActivity.this); + finish(); + } + } + }; - @Override - public void onSuccess(LoginInfo arg0) { - DemoCache.setAccount(Commons.USER.getUserId()); - DataCacheManager.buildDataCacheAsync(); - } - }); - /** - * 登录友盟微社区 - */ - LoginSDKManager.getInstance().addAndUse(new UmengLoginImpl()); - CommunitySDK commSDK = CommunityFactory.getCommSDK(RegisteredActivity.this); - commSDK.login(RegisteredActivity.this, new LoginListener() { - @Override - public void onStart() { + private void saveInfo() { + //登录成功保存个人信息 + Commons.USER = loginUser; + Commons.PHONE_NUM = et_phone.getText().toString(); + Commons.CODE = MD5Util.GetMD5(et_psw.getText().toString()); + sp = SPUtil.getInstance(getApplicationContext()); + sp.putBoolean(LoginSPKey.IS_LOGIN, true); + sp.putBoolean(LoginSPKey.IS_CAMERA, Commons.IS_CAMERA); + sp.putString(LoginSPKey.PHONE_NUM, et_phone.getText().toString()); + sp.putString(LoginSPKey.PASSWORD, Commons.CODE); + sp.putString(LoginSPKey.USER_ID, loginUser.getUserId()); + sp.putString(LoginSPKey.NICKNAME, loginUser.getNickName()); + sp.putString(LoginSPKey.USERIMG, loginUser.getUserImg()); + sp.putString(LoginSPKey.UPDATETIME, loginUser.getUpdateTime()); + sp.putString(LoginSPKey.P2PVerifyCode1, loginUser.P2PVerifyCode1); + sp.putString(LoginSPKey.P2PVerifyCode2, loginUser.P2PVerifyCode2); + sp.putString(LoginSPKey.GeeWeUserId, loginUser.gwellUserID); + } - } + Handler regeditHandler = new Handler() { + public void handleMessage(android.os.Message msg) { + /** + * 1:注册成功 + 0:注册失败 + */ + switch (msg.what) { + case NetWork.Success: + cp.putBoolean(LoginSPKey.IS_LOGIN, true); + cp.putString(LoginSPKey.PHONE_NUM, et_phone.getText().toString()); + userLogin();//注册成功就登录请求 + break; + case NetWork.Fail: + ToastUtil.show(getApplicationContext(), "注册失败"); + dismissProgressDialog(); + break; + case NetWork.ERROR: + ToastUtil.show(getApplicationContext(), Text.ERROR); + dismissProgressDialog(); + break; + case NetWork.RepeatMobile: + ToastUtil.show(getApplicationContext(), "手机号已被注册 请直接登录"); + cp.putBoolean(LoginSPKey.IS_LOGIN, true); + cp.putString(LoginSPKey.PHONE_NUM, et_phone.getText().toString()); + dismissProgressDialog(); + startActivity(LoginActivity.class); + AnimationUtil.startAnimation(RegisteredActivity.this); + finish(); + break; - @Override - public void onComplete(int arg0, CommUser arg1) { - L.i("state"+arg0); - } - }); - } - } + default: + ToastUtil.show(getApplicationContext(), Text.ServerException); + dismissProgressDialog(); + break; + } + } + }; - @Override - public void finish() { - loginHandler.sendEmptyMessage(result); - } + @Override + protected void onDestroy() { + SMSSDK.unregisterEventHandler(eh); + if (task != null) { + task.cancel(); + timer.cancel(); + timer = null; + task = null; + } + EventBus.getDefault().unregister(this); + super.onDestroy(); + } - @Override - public void error(Exception e, String msg) { - result=NetWork.ERROR; - } - }, et_phone.getText().toString(),MD5Util.GetMD5(et_psw.getText().toString())); - } + @Override + public void onBackPressed() { + long currentTime = System.currentTimeMillis(); + if ((currentTime - touchTime) >= waitTime) { + showToast("再按一次退出程序"); + touchTime = currentTime; + } else { + ActivityManager.getInstance().exit(); + } + } + + @Override + public void onClick(View v) { + // 点击事件 + Intent i = new Intent(); + switch (v.getId()) { + case R.id.rl_bg: + hideKeyboard(); + break; + case R.id.tv_check: + i.setClass(this, WebViewActivity.class);//注册协议 + i.putExtra(WebViewActivity.URL, HttpManager.REGISTERAGREEMENT_URL); + i.putExtra(WebViewActivity.WEBVIEWTITLE, Text.REGISTERAGREEMENT); + startActivity(i); + AnimationUtil.startAnimation(this); + break; + case R.id.title_text_right://跳转登录 + i.setClass(this, LoginActivity.class); + startActivity(i); + AnimationUtil.startAnimation(this); + finish(); + break; + case R.id.bt_submit: {//注册 + if (et_phone.getText().toString().replaceAll(" ", "").length() == 0) { + ToastUtil.show(getApplicationContext(), "请输入手机号"); + return; + } + if (et_messge.getText().toString().replaceAll(" ", "").length() == 0) { + ToastUtil.show(getApplicationContext(), "请输入短信验证码"); + return; + } + if (et_psw.getText().toString().length() < 6) { + ToastUtil.show(getApplicationContext(), "密码不能短于六位"); + return; + } + if (!ct_check.isChecked()) { + ToastUtil.show(getApplicationContext(), "您必须同意爱鱼奇服务"); + return; + } + hideKeyboard(); + if (isShowSmsCode) { + if (smsCode == null) { + ToastUtil.show(getApplicationContext(), "请先获取短信码"); + return; + } + if (et_messge.getText().toString().equals(smsCode)) { + showProgressDialog(); + doRegistered(); + } else { + ToastUtil.show(getApplicationContext(), "请输入正确的短信验证码"); + } + } else { + showProgressDialog(); + if (countryCode == null) { + countryCode = new CountryCode("86", "中国"); + } + SMSSDK.submitVerificationCode(countryCode.countryCode, et_phone.getText().toString(), et_messge.getText().toString()); + } + break; + } + case R.id.tv_code: {//注册验证码 + if (et_phone.getText().toString().replaceAll(" ", "").length() == 0) { + ToastUtil.show(getApplicationContext(), "请输入手机号"); + return; + } + if (countryCode == null) { + countryCode = new CountryCode("86", "中国"); + } + SMSSDK.getVoiceVerifyCode(countryCode.countryCode, et_phone.getText().toString()); + mLocationClient.start();//定位SDK start之后会默认发起一次定位请求,开发者无须判断isstart并主动调用request + mLocationClient.requestLocation(); + tv_code.setClickable(false); + tv_code.setBackgroundDrawable(tv_code + .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); + tv_code.setText("60\""); + startTime(); + break; + } + case R.id.tv_msgcode: { + hm.getSecurityCode(new HttpListener>() { + @Override + public void success(BaseBean baseBean) { + if (baseBean.result == 201) { + act.runOnUiThread(new Runnable() { + @Override + public void run() { + ToastUtil.show(getApplicationContext(), "手机号已被注册 请直接登录"); + } + }); + } else if (baseBean.result == 100) { + smsCode = baseBean.data; + time.start(); + } else { + act.runOnUiThread(new Runnable() { + @Override + public void run() { + ToastUtil.show(getApplicationContext(), "发送短信失败 请重新获取"); + } + }); + } + } + + @Override + public void error(Exception e, String msg) { + + } + + @Override + public void finish() { + + } + }, et_phone.getText().toString()); + break; + } + case R.id.rl_country: {//国家代码 + startActivity(CountryListActivity.class); + AnimationUtil.startAnimation(RegisteredActivity.this); + break; + } + case R.id.tv_changesmscode: { + isShowSmsCode = !isShowSmsCode; + showSmsCode(); + break; + } + default: + break; + } + } + + /** + * 国家/地区发生改变 + * + * @param event + */ + public void onEventMainThread(CountryCode event) { + if (tv_country != null) { + tv_country.setText(event.country + " +" + event.countryCode); + } + countryCode = event; + } + + /** + * @param + * @Description: 注册成功就接着发登录的请求 + * @author Jacky dada + * @date 2015-9-6 下午7:20:42 + */ + private void doRegistered() { + hm.register(new HttpListener>() { + @Override + public void success(BaseBean baseBean) { + doRegisteredResult = baseBean.result; + } + + @Override + public void finish() { + regeditHandler.sendEmptyMessage(doRegisteredResult); + } + + @Override + public void error(Exception e, String msg) { + doRegisteredResult = NetWork.ERROR; + } + }, et_phone.getText().toString(), et_psw.getText().toString()); + } + + /** + * @param + * @Description: 登录 + * @author Jacky dada + * @date 2015-9-8 下午2:33:05 + */ + private void userLogin() { + hm.userLogin(new HttpListener>() { + @Override + public void success(BaseBean baseBean) { + if (baseBean == null) { + result = NetWork.ERROR; + return; + } + result = baseBean.result; + if (result == NetWork.Success) { + loginUser = baseBean.data.getUser(); + Commons.USER = loginUser; + List device = baseBean.data.getDevice(); + List camera = baseBean.data.camera; + List deviceCamera = baseBean.data.deviceCamera; + Commons.DEVICE = device; + Commons.CAMERA = camera; + Commons.INFO = baseBean.data.information; + Commons.DeviceCamera = deviceCamera; + Commons.SHOP = baseBean.data.shopsInfo; + Commons.SHOP2 = baseBean.data.shopsInfo2; + Commons.USERASSET = baseBean.data.userAsset; + Commons.GOLDTASKS = baseBean.data.goldTasks; + if (device.size() == 0) { + Commons.HAVE_DEVICE = false; + } else { + Commons.HAVE_DEVICE = true; + Commons.IS_EventBus = true; + } + if (camera.size() == 0) { + Commons.HAVE_CAMERA = false; + } else { + Commons.HAVE_CAMERA = true; + } + if (!Commons.HAVE_DEVICE && Commons.HAVE_CAMERA) {//用户没有鱼缸,只有摄像头则默认展示摄像头界面 + Commons.IS_CAMERA = true; + } else { + Commons.IS_CAMERA = false; + } + /** + * 登录云信 + */ + AbortableFuture login = NIMClient.getService(AuthService.class).login(new LoginInfo(Commons.USER.getUserId(), Commons.USER.neteaseToken)); + login.setCallback(new RequestCallback() { + + @Override + public void onException(Throwable arg0) { + arg0.printStackTrace(); + L.d("yunxin onException"); + } + + @Override + public void onFailed(int arg0) { + // TODO Auto-generated method stub + L.d("yunxin onFailed code=" + arg0 + " Account=" + Commons.USER.getUserId() + " token=" + Commons.USER.neteaseToken); + + } + + @Override + public void onSuccess(LoginInfo arg0) { + DemoCache.setAccount(Commons.USER.getUserId()); + DataCacheManager.buildDataCacheAsync(); + } + }); + /** + * 登录友盟微社区 + */ + LoginSDKManager.getInstance().addAndUse(new UmengLoginImpl()); + CommunitySDK commSDK = CommunityFactory.getCommSDK(RegisteredActivity.this); + commSDK.login(RegisteredActivity.this, new LoginListener() { + @Override + public void onStart() { + + } + + @Override + public void onComplete(int arg0, CommUser arg1) { + L.i("state" + arg0); + } + }); + } + } + + @Override + public void finish() { + loginHandler.sendEmptyMessage(result); + } + + @Override + public void error(Exception e, String msg) { + result = NetWork.ERROR; + } + }, et_phone.getText().toString(), MD5Util.GetMD5(et_psw.getText().toString())); + } + + class TimeCount extends CountDownTimer { + + public TimeCount(long millisInFuture, long countDownInterval) { + super(millisInFuture, countDownInterval); + } + + @Override + public void onTick(long millisUntilFinished) { + tv_msgcode.setClickable(false); + tv_msgcode.setText(millisUntilFinished / 1000 + "\""); + tv_msgcode.setBackgroundDrawable(tv_msgcode + .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); + } + + @Override + public void onFinish() { + tv_msgcode.setText("短信验证码"); + tv_msgcode.setClickable(true); + tv_msgcode.setBackgroundDrawable(tv_msgcode + .isClickable() ? getResources().getDrawable(ebleColor) : getResources().getDrawable(disableColor)); + } + } + + private void showSmsCode() { + if (isShowSmsCode) { + tv_code.setVisibility(View.GONE); + tv_msgcode.setVisibility(View.VISIBLE); + tv_changesmscode.setText("语音验证码"); + } else { + tv_code.setVisibility(View.VISIBLE); + tv_msgcode.setVisibility(View.GONE); + tv_changesmscode.setText("短信验证码"); + } + } } diff --git a/iFish7/src/main/res/layout/registered_activity.xml b/iFish7/src/main/res/layout/registered_activity.xml index a52df1fe4..a0313a1e5 100644 --- a/iFish7/src/main/res/layout/registered_activity.xml +++ b/iFish7/src/main/res/layout/registered_activity.xml @@ -1,219 +1,240 @@ + android:focusable="true" + android:focusableInTouchMode="true"> + - - - - - + - - - - - + + + + + + + + + + + android:paddingRight="10dp" + android:singleLine="true" + android:textColor="@color/text_black_my" + android:textColorHint="@color/galy_my" /> - - -