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.Intent; 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.CheckBox; import android.widget.LinearLayout; import android.widget.TextView; public class DwKq extends Activity implements OnClickListener { private CheckBox open; private LinearLayout dwgl_layout; private LinearLayout zdkq_layout; private Button up; private Button back; private TextView title; private String opt_name; private int opt_sort = 0;//0、打开1、关闭 private String isOpen= "1" ;//1、正常2、关闭3、未激活 private Optsharepre_interface share_obj =null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.dwkq); open = (CheckBox) this.findViewById(R.id.open); up = (Button) this.findViewById(R.id.sure); back = (Button) this.findViewById(R.id.back); title = (TextView) this.findViewById(R.id.title); dwgl_layout = (LinearLayout) this.findViewById(R.id.dwgl_layout); zdkq_layout = (LinearLayout) this.findViewById(R.id.zdkq_layout); open.setOnClickListener(this); up.setOnClickListener(this); back.setOnClickListener(this); Intent intent = this.getIntent(); opt_name = intent.getStringExtra("moduleName"); if(opt_name.equals("dwgl")){ title.setText("定位管理"); up.setText("上传"); dwgl_layout.setVisibility(LinearLayout.VISIBLE); zdkq_layout.setVisibility(LinearLayout.GONE); }else if(opt_name.equals("zdkq")){ this.setTitle("自动考勤"); zdkq_layout.setVisibility(LinearLayout.VISIBLE); dwgl_layout.setVisibility(LinearLayout.GONE); } //判断是否已经打开定位功能 share_obj = new Optsharepre_interface(DwKq.this); isOpen = share_obj.getDataFromPres("DWZT"); System.out.println("定位状态*********************************"+isOpen); if(isOpen.equals("1") && opt_name.equals("dwgl")){ open.setChecked(true); }else if((isOpen.equals("2") || isOpen.equals("9")) && opt_name.equals("dwgl")){ open.setChecked(false); }/*else if(isOpen.equals("9") && opt_name.equals("dwgl")){ open.setClickable(false); //up.setClickable(true); }*/ } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == up){ if(opt_name.equals("dwgl")){ if(open.isChecked()){ opt_sort = 0; }else{ opt_sort = 1; } new DwkqThread().start(); }else{ warnTell("暂未开放此功能,如需定制,请致电400-611-9797.联系我们!"); } /* if(isOpen.equals("9")){ warnTell("请先回复短信开通第三方定位后再使用此功能!"); }*/ }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(DwKq.this).setTitle("警告").setMessage(message) .setPositiveButton("确定", null).show(); } /** * 信息反馈线程 * @author Administrator * */ class DwkqThread 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(DwKq.this); Bundle bundle = new Bundle(); JSONObject object = new JSONObject(); try { object.put("gguid", share_obj.getDataFromPres("GGUID")); object.put("guid", share_obj.getDataFromPres("GUID")); object.put("flag", opt_sort); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String result = "-1"; // 请求服务器 if(opt_name.equals("dwgl")){ result = new UpdataToServer(DwKq.this).dataToServer("DWGL", 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")) { if(open.isChecked()){ bundle.putString("msg", "定位已打开"); share_obj.editPres("DWZT", "1"); }else{ bundle.putString("msg", "定位已关闭"); share_obj.editPres("DWZT", "2"); } }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(); } } /** * 结果显示 * * @param message */ public void showToast(String message) { new AlertDialog.Builder(DwKq.this).setTitle("提示").setMessage(message) .setPositiveButton("确定", null).show(); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub ProgressDialog dialog = new ProgressDialog(DwKq.this); dialog.setIndeterminate(true); dialog.setCancelable(false); switch (id) { case 1: dialog.setMessage("正在执行,请稍候……"); break; } return dialog; } }