package com.smartdot.cgt.activity; import android.content.DialogInterface; import android.content.Intent; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.Toast; import com.smartdot.cgt.R; import com.smartdot.cgt.model.CaseModel; import com.smartdot.cgt.model.ResponseResult; import com.smartdot.cgt.request.Request; import com.smartdot.cgt.util.ApplicationMain; import com.smartdot.cgt.util.BaseThread; import com.smartdot.cgt.util.HandlerStatus; import com.smartdot.cgt.util.Msg; import com.smartdot.cgt.util.StringUtils; import com.smartdot.cgt.view.TitleBar; import java.util.HashMap; public class FrmPwd extends BaseActivity { private EditText txtAddress; private EditText txtEventDesc; private EditText txtLongitude; private String newPwd; private String newPwd1; private String oldPwd; private HashMap<String, BaseThread> threadList = new HashMap<String, BaseThread>( 5); private final String THREAD_SUBMIT_FIELD = "THREAD_SUBMIT_FIELD"; private DialogHandler dialogHandler; @Override protected void setLayout() { initActivity(); setContentView(R.layout.pwd); txtAddress = (EditText) findViewById(R.id.txtAddress); txtEventDesc = (EditText) findViewById(R.id.txtEventDesc); txtLongitude = (EditText) findViewById(R.id.txtLongitude); TitleBar titlebar = (TitleBar) this.findViewById(R.id.titlebar); titlebar.setTitleText("修改密码"); titlebar.setRigthText(R.string.below_btn_submit); titlebar.setRightBtnListener(btnSubmitOnClick); dialogHandler = new DialogHandler(); //spinProblemType.performClick(); } @Override protected void doInit() { } private OnClickListener btnSubmitOnClick = new OnClickListener() { @Override public void onClick(View v) { submitField(); } }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { } @Override protected void addEventListener() { } @SuppressWarnings("unchecked") @Override protected void handleMessage(Message msg) { if (msg.what == HandlerStatus.SUBMIT_FIELDVALUE) { threadList.get(THREAD_SUBMIT_FIELD).interrupt(); if (msg.arg1 == HandlerStatus.HANDLE_OK) { if (msg.obj != null) { String[] resultIds = ((ResponseResult<String[]>) msg.obj) .getResultObj(); if (resultIds != null) { if("旧密码不正确".equals(resultIds[0])) { Msg.showInfo(FrmPwd.this, "旧密码不正确!"); }else { Msg.showInfo(FrmPwd.this, "修改成功!"); } } else { Msg.showInfo(FrmPwd.this, "修改失败!"); } } } else if (msg.arg1 == HandlerStatus.HANDLE_FAIL) { Msg.showInfo(FrmPwd.this, "修改密码提交失败!"); } else { } checkIsNeedCloseProgress(); } } @Override protected void onCancelProgress(DialogInterface arg0) { for (BaseThread thread : threadList.values()) { if (thread != null) { thread.interrupt(); } } threadList.clear(); // FrmProblemInput.this.finish(); } private boolean checkFieldValue(CaseModel inputCase) { StringBuilder errorBuilder = new StringBuilder(); oldPwd=txtAddress.getText().toString(); newPwd=txtEventDesc.getText().toString(); newPwd1=txtLongitude.getText().toString(); if (!StringUtils.isNullOrEmpty(oldPwd)) { } else { errorBuilder.append("旧密码不能为空!\n"); } if (!StringUtils.isNullOrEmpty(newPwd)) { } else { errorBuilder.append("新密码不能为空!\n"); } if (!StringUtils.isNullOrEmpty(newPwd1)) { } else { errorBuilder.append("确认新密码不能为空!\n"); } if (newPwd.equals(newPwd1)) { } else { errorBuilder.append("新密码与确认新密码必须相同!\n"); } boolean checkResult = errorBuilder.length() == 0; if (!checkResult) { Msg.showInfo(FrmPwd.this, errorBuilder.toString()); } return checkResult; } private void submitField() { CaseModel inputCase = new CaseModel(); if (checkFieldValue(inputCase)) { final CaseModel toSubmitCase = inputCase; BaseThread thread = new BaseThread(baseHandler) { @Override public void runThread() { Message msg = this.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.SUBMIT_FIELDVALUE; try { ResponseResult<String[]> result = Request .getRequest() .updatePwd( ApplicationMain.getInstance() .getUserModel() .getBgAdminId(), newPwd, oldPwd); if (result.isSuccess()) { msg.arg1 = HandlerStatus.HANDLE_OK; msg.obj = result; } else if (result.isHadError()) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } else { msg.arg1 = HandlerStatus.HANDLE_FAIL; } } catch (Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; msg.obj = toSubmitCase; } this.sendMessage(msg); } } }; showProgress("案卷提交中。。。", "案卷录入"); thread.start(); threadList.put(THREAD_SUBMIT_FIELD, thread); } } private void finishActivity(boolean canClose) { this.finishActivity(canClose, false); } private void finishActivity(boolean canClose, boolean needCacheAudio) { if (canClose) { FrmPwd.this.finish(); } } /** * */ private boolean checkIsNeedCloseProgress() { boolean canCloseProgress = true; for (BaseThread thread : threadList.values()) { if (thread != null && thread.getIsThreadGoing()) { canCloseProgress = false; } } if (canCloseProgress) { try { closeProgress(); } catch (Exception e) { e.printStackTrace(); } } return canCloseProgress; } // TODO class DialogHandler extends Handler { @Override public void handleMessage(Message msg) { super.handleMessage(msg); closeProgress(); Toast.makeText(FrmPwd.this, "上报成功", Toast.LENGTH_SHORT) .show(); } } public String getNewPwd() { return newPwd; } public void setNewPwd(String newPwd) { this.newPwd = newPwd; } public String getOldPwd() { return oldPwd; } public void setOldPwd(String oldPwd) { this.oldPwd = oldPwd; } public String getNewPwd1() { return newPwd1; } public void setNewPwd1(String newPwd1) { this.newPwd1 = newPwd1; } }