@Override public void handleMessage(Message msg) { switch (msg.what) { case NetUtil.RESULTTRUE + NetUtil.Login: ToastUtil.show(LoginActivity.this, "登录成功"); Intent loginIntent = new Intent(LoginActivity.this, MainActivity.class); startActivity(loginIntent); finish(); break; case NetUtil.RESULTNULL + NetUtil.Login: ToastUtil.show(LoginActivity.this, "该用户名不存在"); break; case NetUtil.RESULTFALSE + NetUtil.Login: ToastUtil.show(LoginActivity.this, "密码输入错误"); break; } };
@Override public void handleMessage(Message msg) { switch (msg.what) { case NetUtil.RESULTTRUE + NetUtil.appSendCode: ToastUtil.show(RegisterActivity.this, "验证码已发送至您的手机"); break; case NetUtil.RESULTNULL + NetUtil.appSendCode: ToastUtil.show(RegisterActivity.this, "手机号格式不正确"); break; case NetUtil.RESULTFALSE + NetUtil.appSendCode: ToastUtil.show(RegisterActivity.this, "该手机号已经注册过"); break; case NetUtil.RESULTTRUE + NetUtil.appCheckCode: new NetUtil(getPerfectParentsAPP(), this) .urlGetData(NetUtil.save, nnTemp, pTemp, pwTemmp, upTemp); break; case NetUtil.RESULTNULL + NetUtil.appCheckCode: ToastUtil.show(RegisterActivity.this, "验证码过期"); break; case NetUtil.RESULTFALSE + NetUtil.appCheckCode: ToastUtil.show(RegisterActivity.this, "验证码输入错误"); break; case NetUtil.RESULTFALSE + NetUtil.save: ToastUtil.show(RegisterActivity.this, "该用户已经注册过"); break; case NetUtil.RESULTTRUE + NetUtil.save: ToastUtil.show(RegisterActivity.this, "注册成功"); break; } };
@Override public void onClick(View v) { switch (v.getId()) { case R.id.includetitle1_backarrow: finish(); break; case R.id.registeractivity_nicknameclear: nickname.setText(""); break; case R.id.registeractivity_phoneclear: phone.setText(""); break; case R.id.registeractivity_pwdclear: pwd.setText(""); break; case R.id.registeractivity_pwdagainclear: pwdagain.setText(""); break; case R.id.registeractivity_pwdshow: if (pwd.getInputType() == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) { pwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL); } else { pwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } break; case R.id.registeractivity_pwdagainshow: if (pwd.getInputType() == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) { pwdagain.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL); } else { pwdagain.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } break; case R.id.registeractivity_vercode: pTemp = phone.getText().toString(); if (InputValidateUtil.isPhone(pTemp)) { ToastUtil.show(this, "请正确输入手机号码"); return; } new NetUtil(getPerfectParentsAPP(), registerHandler).urlGetData(NetUtil.appSendCode, pTemp); break; case R.id.registeractivity_submit: nnTemp = nickname.getText().toString(); cTemp = code.getText().toString(); pwTemmp = pwd.getText().toString(); if (InputValidateUtil.isNickname(nnTemp)) { ToastUtil.show(this, "用户名只能使用字母和数字(6-18位)"); } else if (InputValidateUtil.isVercode(cTemp)) { ToastUtil.show(this, "验证码为6为数字"); } else if (InputValidateUtil.isPassword(pwTemmp)) { ToastUtil.show(this, "用户名只能使用字母和数字(6-18位)"); } else if (pwTemmp.equals(pwdagain.getText().toString())) { ToastUtil.show(this, "两次输入密码不一致"); } ; new NetUtil(getPerfectParentsAPP(), registerHandler) .urlGetData(NetUtil.appCheckCode, cTemp); break; case R.id.registeractivity_userpic: new AlertDialog.Builder(this) .setTitle("设置头像") .setItems( new String[] {"选择本地图片"}, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: Intent imgIntent = new Intent(); imgIntent.setType("image/*"); imgIntent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(imgIntent, RESULT_USERIMG); break; default: break; } } }) .setNegativeButton( "取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); break; } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case RESULT_USERIMG: if (null == data) { ToastUtil.show(this, "未选择图片"); } else { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(data.getData(), "image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", 320); intent.putExtra("outputY", 320); intent.putExtra("return-data", true); startActivityForResult(intent, RESULT_USERIMGCROP); } break; case RESULT_USERIMGCROP: if (data != null) { Bundle extras = data.getExtras(); if (extras != null) { Bitmap photo = extras.getParcelable("data"); if (photo != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] buf = baos.toByteArray(); File file = new File(Environment.getExternalStorageDirectory(), "headdisplay"); upTemp = file.getAbsolutePath(); BufferedOutputStream bos = null; FileOutputStream fos = null; try { fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(buf); userpic.setImageBitmap(photo); } catch (Exception e) { ToastUtil.show(this, "获取图片失败"); } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { } } if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } else { ToastUtil.show(this, "未选择图片"); } } else { ToastUtil.show(this, "未选择图片"); } } else { ToastUtil.show(this, "未选择图片"); } break; } }