package com.jqyd.manager; import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.jqyd.app.MyApp; import com.jqyd.shareInterface.Optsharepre_interface; import com.jqyd.shareInterface.SystemInfo; import com.jqyd.shareInterface.UpdataToServer; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public class Wdzt extends Activity implements OnClickListener{ private TextView dwzt;//第三方定位状态 private TextView dwlx;//计划定位状态 private TextView dssb;//定时上报 private TextView qdzt;//签到状态 private TextView qtzt;//签退状态 private TextView sbsj;//上班时间 private TextView xbsj;//下班时间 private TextView signTime;//签到开始时间 private TextView endTime;//签到结束时间 private TextView qdsj;//签到时间 private TextView qtsj;//签退时间 private TextView jlxz;//距离限制 private TextView bbzt;//版本状态 private Button abort; private Button back; private TextView title; private Optsharepre_interface share_obj = null; private TextView vercontent; private LinearLayout myState; private ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); private MyApp myApp; private JSONObject obj = null; private boolean isNoChange = true; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.wdzt); dwzt = (TextView) this.findViewById(R.id.dwzt); dwlx= (TextView) this.findViewById(R.id.dwlx); qdzt= (TextView) this.findViewById(R.id.qdzt); qtzt= (TextView) this.findViewById(R.id.qtzt); dssb= (TextView) this.findViewById(R.id.dssb); sbsj= (TextView) this.findViewById(R.id.sbsj); xbsj= (TextView) this.findViewById(R.id.xbsj); qdsj= (TextView) this.findViewById(R.id.qdsj); qtsj= (TextView) this.findViewById(R.id.qtsj); signTime= (TextView) this.findViewById(R.id.signTime); endTime= (TextView) this.findViewById(R.id.endTime); vercontent = (TextView) this.findViewById(R.id.vercontent); jlxz= (TextView) this.findViewById(R.id.jlxz); bbzt= (TextView) this.findViewById(R.id.bbzt); abort = (Button) this.findViewById(R.id.sure); abort.setText("关于"); back = (Button) this.findViewById(R.id.back); title= (TextView) this.findViewById(R.id.title); title.setText("我的状态"); myState = (LinearLayout) this.findViewById(R.id.mystate); abort.setOnClickListener(this); back.setOnClickListener(this); myApp = (MyApp) this.getApplication(); new CxThread().start(); } public void init(){ share_obj = new Optsharepre_interface(Wdzt.this); String dislimit = share_obj.getDataFromPres("DISLIMIT")+"米"; String vercode = new SystemInfo(Wdzt.this).getVersionInfo(); String []kqcls = share_obj.getDataFromPres("KQCL").split("#"); sbsj.setText(kqcls[0]); xbsj.setText(kqcls[1]); signTime.setText(kqcls[2]); endTime.setText(kqcls[3]); jlxz.setText(dislimit); bbzt.setText(vercode); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == abort){ if(list.size()>0){ isNoChange = false; vercontent.setVisibility(TextView.VISIBLE); abortVersion(); }else{ showToast("抱歉,未查到历史版本信息!"); } }else if(v == back){ if(isNoChange){ finish(); }else{ vercontent.setVisibility(TextView.GONE); myState.setVisibility(LinearLayout.VISIBLE); abort.setVisibility(View.VISIBLE); isNoChange = true; } } } /** * 版本历史 */ public void abortVersion(){ myState.setVisibility(LinearLayout.GONE); abort.setVisibility(View.INVISIBLE); String content = "久其管家客户端升级历史回顾:\n"; for(int i=0;i<list.size();i++){ HashMap<String,String> map = list.get(i); String vercode = map.get("vercode"); String upcontent = map.get("upcontent"); content+=vercode+":"+upcontent+"\n"; } vercontent.setText(content); } /** * 控件赋值 */ public void setShow(){ try { if(obj!= null){ String onState = obj.getString("onstate"); String qdisnormal = obj.getString("qdisnormal"); String workmode = obj.getString("workmode"); System.out.println("我的状态-----------------------"+workmode+","+onState+","); if(qdisnormal == null){ qdisnormal = ""; } String qd_value = ""; if(workmode.equals("2")){ if(onState.equals("1")){ qd_value = "未签到"; }else if(onState.equals("2")){ qd_value = "正常签到"; }else if(onState.equals("3")){ qd_value = "迟到"; }else{ qd_value = ""; } if(onState.equals("-2")){ qd_value ="非正常签到"; }else if(!qdisnormal.equals("1") && !qdisnormal.equals("4")){ qd_value +="(非正常签到)"; } }else{ if(onState.equals("1")){ qd_value = "未签到"; }else if(onState.equals("-2")){ qd_value = "已签到"; }else{ qd_value = ""; } if(!qdisnormal.equals("1") && !qdisnormal.equals("4")){ qd_value ="非正常签到"; } } qdzt.setText(qd_value); String offState = obj.getString("offstate"); String qtisnormal = obj.getString("qtisnormal"); if(qtisnormal == null){ qtisnormal = ""; } String qt_value = ""; if(workmode.equals("2")){ if(offState.equals("1")){ qt_value = "未签退"; }else if(offState.equals("2")){ qt_value = "正常签退"; }else if(offState.equals("3")){ qt_value = "早退"; }else{ qt_value = ""; } if(offState.equals("-2")){ qt_value ="非正常签退"; }else if(!qtisnormal.equals("1") && !qtisnormal.equals("4")){ qt_value +="(非正常签退)"; } }else{ if(offState.equals("1")){ qt_value = "未签退"; }else if(offState.equals("-2")){ qt_value = "已签退"; }else{ qt_value = ""; } if(!qtisnormal.equals("1") && !qtisnormal.equals("4")){ qt_value ="非正常签退"; } } qtzt.setText(qt_value); String qdsjStr = obj.getString("signon"); String qtsjStr = obj.getString("signoff"); if(!qdsjStr.equals("1")){ qdsj.setText(qdsjStr); } if(!qtsjStr.equals("1")){ qtsj.setText(qtsjStr); } String dwState = obj.getString("dwgn"); //定位状态(9、未激活 1、正常 2、关闭定位) if(dwState.equals("1")){ dwzt.setText("已打开"); }else if(dwState.equals("2")){ dwzt.setText("已关闭"); }else if(dwState.equals("1")){ dwzt.setText("未激活"); } String jhdwState = obj.getString("jhdw"); //当前状态,1正在处理,2欠费暂停,3签退暂停,4关闭定位,5其它,99废弃 if(jhdwState.equals("1") || jhdwState.equals("3") || jhdwState.equals("4")){ dwlx.setText("已制定"); }else if(jhdwState.equals("2") || jhdwState.equals("4")){ dwlx.setText("未制定"); }else{ dwlx.setText("未制定"); } //制定定时上报 String dssbState = obj.getString("dssb"); if(dssbState.equals("yes")){ dssb.setText("已制定"); }else{ dssb.setText("未制定"); } init(); JSONArray arr = (JSONArray) obj.get("versions");//版本升级内容 HashMap<String,String> m = null; for(int i=0;i<arr.length();i++){ m = new HashMap<String,String>(); m.put("vercode", ((JSONObject)arr.get(i)).getString("vercode")); m.put("upcontent", ((JSONObject)arr.get(i)).getString("upcontent")); list.add(m); System.out.println("版本信息-------------------"+list.size()+"-----------"+((JSONObject)arr.get(i)).getString("vercode")); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 查询服务 */ public String cxFromDb(){ String mgs = ""; JSONObject object = new JSONObject(); Optsharepre_interface share_obj = new Optsharepre_interface(Wdzt.this); try { object.put("guid", share_obj.getDataFromPres("GUID")); object.put("gguid", share_obj.getDataFromPres("GGUID")); object.put("version", myApp.getVersion()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String result = new UpdataToServer(Wdzt.this).searchFromServer("WDZT", object); Log.e("result---", result); if(!result.equals("") && !result.equals("-1") && !result.equals("500")){ try { obj = new JSONObject(result); } catch (JSONException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } try { JSONObject jg = (JSONObject) obj.get("cxjg"); if(jg.getString("result").equals("0")){//有数据 HashMap<String,String> map = null; mgs = "0";//成功获得数据 }else{ mgs = jg.getString("detail"); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); mgs = ""; } }else if(result.equals("-1")){ mgs = "抱歉,网络连接失败!"; }else{ mgs = "查询失败,请联系你的管理员!"; } return mgs; } /** * 我的状态查询线程 */ class CxThread extends Thread implements Runnable{ @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); Message msg =new Message(); msg.what = 1; myHander.sendMessage(msg); Message msg2 =new Message(); String result = cxFromDb(); Bundle bunlde = new Bundle(); if(result.equals("0")){//网络连接失败 msg2.what = 2; }else{ msg2.what = 3; bunlde.putString("msg", result); } msg2.setData(bunlde); myHander.sendMessage(msg2); Looper.loop(); } } 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); setShow(); break; case 3: removeDialog(1); Bundle bundle = msg.getData(); showToast(bundle.getString("msg")); break; } } }; /** * 结果显示 * @param message */ public void showToast(String message){ new AlertDialog.Builder(Wdzt.this) .setTitle("提示") .setMessage(message) .setPositiveButton("确定", null) .show(); } /** * 点击返回键,保持当前Activity不退出 */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if(isNoChange){ finish(); }else{ vercontent.setVisibility(TextView.GONE); myState.setVisibility(LinearLayout.VISIBLE); abort.setVisibility(View.VISIBLE); isNoChange = true; } return true; } return super.onKeyDown(keyCode, event); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub ProgressDialog dialog = new ProgressDialog(Wdzt.this); dialog.setIndeterminate(true); dialog.setCancelable(false); switch(id){ case 1: dialog.setMessage("正在查询,请稍候……"); break; case 2: break; case 3: break; } return dialog; } }