package com.jqyd.son;
import org.json.JSONException;
import org.json.JSONObject;
import com.jqyd.manager.R;
import com.jqyd.shareInterface.Optsharepre_interface;
import com.jqyd.shareInterface.UpdataToServer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Xgmm extends Activity implements OnClickListener {
private EditText newPwd;
private EditText nextPwd;
private Button up;
private Button back;
private TextView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xgmm);
newPwd = (EditText) this.findViewById(R.id.newPwd);
nextPwd = (EditText) this.findViewById(R.id.nextPwd);
up = (Button) this.findViewById(R.id.sure);
up.setText("上传");
back = (Button) this.findViewById(R.id.back);
title = (TextView) this.findViewById(R.id.title);
title.setText("修改密码");
up.setOnClickListener(this);
back.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == up){
String newPwdStr = newPwd.getText().toString();
String nextPwdStr = nextPwd.getText().toString();
if(newPwdStr.equals("")){
warnTell("请输入新的密码!");
}else if(nextPwdStr.equals("")){
warnTell("请再次输入新的密码!");
}else if(!newPwdStr.equals(nextPwdStr)){
warnTell("两次密码输入不一致!");
}else{
new XgmmThread().start();
}
}else if(v == back){
finish();
}
}
Handler myHander = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
showDialog(1);
break;
case 2:
removeDialog(1);
Bundle data = msg.getData();
String message = data.getString("msg");
showToast(message);
break;
}
}
};
/**
* 警告提示
*/
public void warnTell(String message){
new AlertDialog.Builder(Xgmm.this).setTitle("警告").setMessage(message)
.setPositiveButton("确定", null).show();
}
/**
* 信息反馈线程
* @author Administrator
*
*/
class XgmmThread extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
Looper.prepare();
Message message = new Message();
message.what = 1;
myHander.sendMessage(message);
Message message2 = new Message();
message2.what = 2;
Optsharepre_interface share_obj = new Optsharepre_interface(Xgmm.this);
Bundle bundle = new Bundle();
JSONObject object = new JSONObject();
try {
object.put("ywmc", share_obj.getDataFromPres("YWMC"));
object.put("cpmc", share_obj.getDataFromPres("CPMC"));
object.put("zhmc", share_obj.getDataFromPres("REGSIM"));
object.put("mm", newPwd.getText().toString());
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String result = "-1";
// 请求服务器
result = new UpdataToServer(Xgmm.this).dataToServer("XGMM", object);
if (result != null && !result.equals("-1") && !result.equals("500")) {
try {
JSONObject obj = new JSONObject(result);
String res = obj.getString("result");
if (res.equals("0")) {
bundle.putString("msg", "修改成功");
}else {
String errMsg = obj.getString("detail");
bundle.putString("msg", errMsg);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
bundle.putString("msg", "抱歉,网络连接失败!");
} else if(result.equals("500")){
bundle.putString("msg", "上传失败,请联系你的管理员!");
}
message2.setData(bundle);
myHander.sendMessage(message2);
Looper.loop();
}
}
/**
* 清空历史数据
*/
public void cheanHisdatas(){
newPwd.setText("");
nextPwd.setText("");
}
/**
* 结果显示
*
* @param message
*/
public void showToast(final String message) {
new AlertDialog.Builder(Xgmm.this).setTitle("提示").setMessage(message)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(message.contains("成功")){
cheanHisdatas();
}
}
}).show();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
ProgressDialog dialog = new ProgressDialog(Xgmm.this);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
switch (id) {
case 1:
dialog.setMessage("正在执行,请稍候……");
break;
}
return dialog;
}
}