package com.jiuqi.njt.son; import java.lang.reflect.UndeclaredThrowableException; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewStub; import android.view.Window; import android.widget.Button; import android.widget.EditText; import com.jqyd.android.module.lbs.util.CheckState_interface; import com.jiuqi.mobile.nigo.comeclose.exception.LoginException; import com.jiuqi.mobile.nigo.comeclose.manager.base.ILoginManager; import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientContext; import com.jiuqi.njt.R; import com.jiuqi.njt.data.MyApp; import com.jiuqi.njt.data.OptsharepreInterface; import com.jiuqi.njt.ui.LoginActivityNew; import com.jiuqi.njt.util.Constants; import com.jiuqi.njt.util.PatternUtils; import com.jiuqi.njt.util.TitleBarUtil; import com.jiuqi.njt.util.UIUtil; import com.jiuqi.njt.util.ValidateRule; import com.jiuqi.njt.widget.ProgressDialogStyle; /** * 修改密码 * */ public class ChangePwd extends Activity { EditText formerpwd; EditText newpwd; EditText newpwdOk; Button changepwd; String pwdStr; OptsharepreInterface sharePre = null; Boolean b;// 标识此Activity是否前台 MyApp application; private Dialog pd; private EditText telephone; private EditText account; private EditText userName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // 注意顺序 setContentView(R.layout.changepwd); sharePre = new OptsharepreInterface(this); application = (MyApp) getApplication(); ViewStub rlTitleBar = (ViewStub) findViewById(R.id.titleBarStub); TitleBarUtil.createTitleBar(this, rlTitleBar, "修改密码", new OnClickListener() { @Override public void onClick(View v) { ChangePwd.this.finish(); } }); inInUI(); inItParam(); changepwd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (UIUtil.isFastDoubleClick()) { return; } String msg = checkParams(); if (!"".equals(msg)) { AlertDialog.Builder build = new AlertDialog.Builder( ChangePwd.this); build.setTitle("警告").setMessage(msg) .setPositiveButton("确定", null); AlertDialog dialog = build.create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); } else { pwdStr = newpwd.getText().toString(); if (new CheckState_interface(ChangePwd.this) .checkConnection()) { new changePwdTask().execute(); } else { UIUtil.showMsg(ChangePwd.this, Constants.NETWORK_STATE_ERROR); } } } }); } private void inInUI() { // TODO Auto-generated method stub userName = (EditText) findViewById(R.id.userName); account = (EditText) findViewById(R.id.account); telephone = (EditText) findViewById(R.id.telephone); formerpwd = (EditText) findViewById(R.id.formerpwd); newpwd = (EditText) findViewById(R.id.newpwd); newpwdOk = (EditText) findViewById(R.id.newpwdOk); changepwd = (Button) findViewById(R.id.changepwd); } private void inItParam() { // TODO Auto-generated method stub userName.setText(sharePre.getPres("username")); account.setText(sharePre.getPres("account")); telephone.setText(sharePre.getPres("mobileNumber")); } private String checkParams() { // TODO Auto-generated method stub String former = sharePre.getPres("password");// 老密码 String msg = ""; if (formerpwd.getText().toString().equals("") || formerpwd.getText().toString() == null) { msg = "请输入原始密码!"; } else if (formerpwd != null && !formerpwd.getText().toString().equals(former)) { msg = "原始密码输入错误"; } else if (!newpwd.getText().toString() .equals(newpwdOk.getText().toString())) { msg = "两次输入密码不一致!"; } else if (newpwd.getText().toString().equals("") || newpwd.getText().toString() == null) { msg = "请输入 新密码!"; } else if (userName.getText().toString().equals("") || userName.getText().toString() == null) { msg = "用户名称不能为空"; } else if (telephone.getText().toString().equals("") || telephone.getText().toString() == null) { msg = "手机号码不能为空"; } else if (!PatternUtils.isMobileNO(telephone.getText().toString())) { msg = "手机号码不符合格式!"; } else if (telephone.getText().toString().length() != 11) { msg = "手机号码长度不符合格式!"; } else if (account.getText().toString().equals("") || account.getText().toString() == null) { msg = "账户别名不能为空"; } else if (!PatternUtils.checkAccount(account.getText().toString())) { msg = "账户别名不符合格式,只能包含字母和数字!"; } else if (!PatternUtils.checkPassWord(newpwd.getText().toString())) { msg =ValidateRule.PASSWORDERRORALERT; } else if (!PatternUtils.checkPassWord(newpwdOk.getText().toString())) { msg =ValidateRule.PASSWORDERRORALERT; } return msg; } class changePwdTask extends AsyncTask<String, Integer, String> { private String msg; @Override protected void onPreExecute() { if (!application.getIsLogin()) { UIUtil.alert(ChangePwd.this, "请先登录", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ChangePwd.this.finish(); } }); } else { showDialog(1); } } @Override protected String doInBackground(String... params) { try { String password = sharePre.getPres("password"); String userAccount = account.getText().toString(); String cosim = telephone.getText().toString(); String coName = userName.getText().toString(); String guid = sharePre.getPres("guid"); if (application.getIsLogin()) { ClientContext context = application.getClientContext(); ILoginManager manager = context .getManager(ILoginManager.class); // manager.updatePassword(account, password, pwdStr); manager.updateUser(guid, userAccount, coName, cosim, password, pwdStr); msg = "修改成功"; // 保存新密码 sharePre.putPres("username", coName); sharePre.putPres("account", userAccount); sharePre.putPres("mobileNumber", cosim); sharePre.putPres("password", pwdStr); } } catch (Exception e) { if (e instanceof UndeclaredThrowableException) { msg = e.getCause().getMessage(); } else if (e.getCause() instanceof LoginException) { msg = e.getCause().getMessage(); } else { msg = "请求服务器异常"; } e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { removeDialog(1); if (!"".equals(msg)) { UIUtil.showMsg(ChangePwd.this, msg); if("修改成功".equals(msg)){ UIUtil.showMsg(ChangePwd.this, "请重新登录..."); Intent in = new Intent(getApplicationContext(), LoginActivityNew.class); in.putExtra("IsPerfect", true); startActivity(in); finish(); } } } } class GetUserMessage extends AsyncTask<String, Void, Void> { @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); myshowDialog(1); } @Override protected Void doInBackground(String... params) { // TODO Auto-generated method stub return null; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); } } private void myshowDialog(int i) { if (i == 1) { pd = ProgressDialogStyle.createLoadingDialog(this, "正在获取我的信息..."); pd.show(); } else if (i == 2) { pd = ProgressDialogStyle.createLoadingDialog(this, "正在提交数据..."); pd.show(); } } protected Dialog onCreateDialog(int id) { ProgressDialog dialog = new ProgressDialog(ChangePwd.this); dialog.setIndeterminate(true); dialog.setCancelable(true); switch (id) { case 1: dialog.setMessage("正在保存,请稍候……"); break; } return dialog; } }