package com.jqyd.manager; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.RunningServiceInfo; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import cn.jpush.android.api.InstrumentedActivity; import com.jqyd.app.LocationUtils; import com.jqyd.app.MyApp; import com.jqyd.app.ShareMethod; import com.jqyd.model.CoUserModule; import com.jqyd.model.CustomerModule; import com.jqyd.model.LocationModule; import com.jqyd.model.RecordModel; import com.jqyd.newprocess.EmpGroupList; import com.jqyd.newprocess.GroupList; import com.jqyd.newprocess.MorePage; import com.jqyd.shareInterface.Baidu_location; import com.jqyd.shareInterface.CheckState_interface; import com.jqyd.shareInterface.GpsService; import com.jqyd.shareInterface.Optdb_interfce; import com.jqyd.shareInterface.Optsharepre_interface; import com.jqyd.shareInterface.SystemInfo; import com.jqyd.shareInterface.UpLocationService; import com.jqyd.shareInterface.UpPlanService; import com.jqyd.shareInterface.UpdataToServer; import com.jqyd.son.Ddcx; import com.jqyd.son.Ddxq; import com.jqyd.son.Khlb; import com.jqyd.son.KqList; public class MainActivity extends InstrumentedActivity implements OnClickListener { private Button gzt;// 工作台 private Button grbg;// 个人办公 private Button xxfk;// 信息反馈 private Button txl;// 通讯录 private Button xszs;// 销售助手 private Button xtbg;// 协同办公 private Button sbqd;// 上班签到 private Button xbqt;// 下班签退 private Button sjcj;// 数据采集 private Button khbf;// 客户拜访 private Button scjc;// 市场检查 private Button ddgl;// 订单管理 private Button stone1;// 基石 private Button stone2;// 基石 private LinearLayout layout1; private LinearLayout layout2; private LinearLayout layout3; private LinearLayout layout4; private LinearLayout all_fun; private Button xcgl;// 行程管理 private Button more; private MyApp myApp; Baidu_location baidu = null; private Optsharepre_interface share_obj; private Optdb_interfce db = null; final String screenService = "com.jqyd.shareInterface.ScreenService"; final String logService = "com.jqyd.shareInterface.LogService"; private FrameLayout gztFrame; private TextView gztNum; private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); // 隐藏标题 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); gzt = (Button) findViewById(R.id.gzt); sbqd = (Button) findViewById(R.id.sbqd); xbqt = (Button) findViewById(R.id.xbqt); grbg = (Button) findViewById(R.id.grbg); khbf = (Button) findViewById(R.id.khbf); scjc = (Button) findViewById(R.id.scjc); xxfk = (Button) findViewById(R.id.xxfk); ddgl = (Button) findViewById(R.id.ddgl); sjcj = (Button) findViewById(R.id.sjcj); xszs = (Button) findViewById(R.id.xszs); txl = (Button) findViewById(R.id.txl); xtbg = (Button) findViewById(R.id.xtbg); layout1 = (LinearLayout) findViewById(R.id.layout1); layout2 = (LinearLayout) findViewById(R.id.layout2); layout3 = (LinearLayout) findViewById(R.id.layout3); layout4 = (LinearLayout) findViewById(R.id.layout4); all_fun = (LinearLayout) findViewById(R.id.all_fun); more = (Button) findViewById(R.id.more); xcgl = (Button) findViewById(R.id.xcgl); stone1 = (Button) findViewById(R.id.stone1); stone2 = (Button) findViewById(R.id.stone2); gztFrame=(FrameLayout)findViewById(R.id.gztFrame); gztNum=(TextView)findViewById(R.id.gztNum); //gztNum.setVisibility(View.VISIBLE); gzt.setOnClickListener(this); sbqd.setOnClickListener(this); xbqt.setOnClickListener(this); grbg.setOnClickListener(this); khbf.setOnClickListener(this); scjc.setOnClickListener(this); xxfk.setOnClickListener(this); ddgl.setOnClickListener(this); sjcj.setOnClickListener(this); xszs.setOnClickListener(this); txl.setOnClickListener(this); xtbg.setOnClickListener(this); more.setOnClickListener(this); xcgl.setOnClickListener(this); share_obj = new Optsharepre_interface(MainActivity.this); share_obj.editPres("istakephoto", "0"); String gnjs_all = share_obj.getDataFromPres("GNJS"); String ismager = share_obj.getDataFromPres("ISMAGER"); Log.i("LOGIN", "功能角色:" + gnjs_all + "," + ismager); // 测试区*************************************************************************** // ismager = "1";//**********************************************测试值 // gnjs_all = "xtbg,xsgl,scgl,kqgl,xcgl"; // ismager = "1"; // ************************************公共显示区******************************** all_fun.removeView(gztFrame); all_fun.removeView(grbg); all_fun.removeView(xxfk); all_fun.removeView(txl); all_fun.removeView(xszs); layout1.addView(gztFrame); layout1.addView(grbg); layout1.addView(xxfk); layout2.addView(txl); layout2.addView(xszs); //ismager t_user CO2(扩展字段) t_role id = CO2 ismanager 0不具备 1具备 //gnjs - t_user zdsf 终端身份(定制的业务) //默认显示 工作台,个人办公,信息反馈,通讯录,销售助手 //协同办公(协同办公),销售管理(数据采集,订单管理),市场管理(客户拜访、市场检查),考勤管理(上班签到,下班签退) // ************************************over******************************** if (gnjs_all != null && !gnjs_all.equals("")) { int index = 0; if ((!ismager.equals("1") || (ismager.equals("1") && !gnjs_all .contains("xtbg"))) && !gnjs_all.equals("xtbg")) {// 不具备管理权限且未定制协同办公功能,定制有其它功能项 index = 0; } else if (ismager.equals("1") && gnjs_all.contains("xtbg") && !gnjs_all.equals("xtbg")) {// 具备管理权限且定制有协同办公功能及其它功能项 index = 1; } else if (ismager.equals("1") && gnjs_all.equals("xtbg")) {// 具备管理权限且定制有协同办公功能未定制其它功能项 index = 2; } System.out.println("索引:" + index); switch (index) { case 0:// 协同办公按钮不显示 if (gnjs_all.contains("kqgl") && !gnjs_all.contains("scgl") && !gnjs_all.contains("xsgl")) {// 考勤管理 Log.i("功能定制", "***************考勤管理***************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(stone1); all_fun.removeView(stone2); layout2.addView(sbqd); layout3.addView(xbqt); layout3.addView(stone1); layout3.addView(stone2); } else if (!gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && !gnjs_all.contains("xsgl")) {// 市场管理 Log.i("功能定制", "***************市场管理***************"); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(stone1); all_fun.removeView(stone2); layout2.addView(khbf); layout3.addView(scjc); layout3.addView(stone1); layout3.addView(stone2); } else if (!gnjs_all.contains("kqgl") && !gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 销售管理 Log.i("功能定制", "***************销售管理***************"); all_fun.removeView(sjcj); all_fun.removeView(ddgl); all_fun.removeView(stone1); all_fun.removeView(stone2); layout2.addView(sjcj); layout3.addView(ddgl); layout3.addView(stone1); layout3.addView(stone2); } else if (gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && !gnjs_all.contains("xsgl")) {// 考勤管理、市场管理 Log.i("功能定制", "***************考勤管理、市场管理***************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(khbf); all_fun.removeView(scjc); layout2.addView(sbqd); layout3.addView(xbqt); layout3.addView(khbf); layout3.addView(scjc); } else if (gnjs_all.contains("kqgl") && !gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 考勤管理、销售管理 Log.i("功能定制", "***************考勤管理、销售管理***************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(sjcj); all_fun.removeView(ddgl); layout2.addView(sbqd); layout3.addView(xbqt); layout3.addView(sjcj); layout3.addView(ddgl); } else if (!gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 市场管理、销售管理 Log.i("功能定制", "***************市场管理、销售管理***************"); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(sjcj); all_fun.removeView(ddgl); layout2.addView(khbf); layout3.addView(scjc); layout3.addView(sjcj); layout3.addView(ddgl); } else if (gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 考勤管理、市场管理、销售管理 Log.i("功能定制", "***************考勤管理、市场管理、销售管理***************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(sjcj); all_fun.removeView(ddgl); all_fun.removeView(stone1); layout2.addView(sbqd); layout3.addView(xbqt); layout3.addView(khbf); layout3.addView(scjc); layout4.addView(sjcj); layout4.addView(ddgl); layout4.addView(stone1); } break; case 1:// 协同办公按钮显示 all_fun.removeView(xtbg); layout2.addView(xtbg); if (gnjs_all.contains("kqgl") && !gnjs_all.contains("scgl") && !gnjs_all.contains("xsgl")) {// 考勤管理 Log.i("功能定制", "***************考勤管理***************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(stone1); layout3.addView(sbqd); layout3.addView(xbqt); layout3.addView(stone1); } else if (!gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && !gnjs_all.contains("xsgl")) {// 市场管理 Log.i("功能定制", "***************市场管理***************"); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(stone1); layout3.addView(khbf); layout3.addView(scjc); layout3.addView(stone1); } else if (!gnjs_all.contains("kqgl") && !gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 销售管理 Log.i("功能定制", "***************销售管理***************"); all_fun.removeView(sjcj); all_fun.removeView(ddgl); all_fun.removeView(stone1); layout3.addView(sjcj); layout3.addView(ddgl); layout3.addView(stone1); } else if (gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && !gnjs_all.contains("xsgl")) {// 考勤管理、市场管理 Log.i("功能定制", "***************考勤管理、市场管理**************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(stone1); all_fun.removeView(stone2); layout3.addView(sbqd); layout3.addView(xbqt); layout3.addView(khbf); layout4.addView(scjc); layout4.addView(stone1); layout4.addView(stone2); } else if (gnjs_all.contains("kqgl") && !gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 考勤管理、销售管理 Log.i("功能定制", "***************考勤管理、销售管理**************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(sjcj); all_fun.removeView(ddgl); all_fun.removeView(stone1); all_fun.removeView(stone2); layout3.addView(sbqd); layout3.addView(xbqt); layout3.addView(sjcj); layout4.addView(ddgl); layout4.addView(stone1); layout4.addView(stone2); } else if (!gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 市场管理、销售管理 Log.i("功能定制", "***************市场管理、销售管理**************"); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(sjcj); all_fun.removeView(ddgl); all_fun.removeView(stone1); all_fun.removeView(stone2); layout3.addView(khbf); layout3.addView(scjc); layout3.addView(sjcj); layout4.addView(ddgl); layout4.addView(stone1); layout4.addView(stone2); } else if (gnjs_all.contains("kqgl") && gnjs_all.contains("scgl") && gnjs_all.contains("xsgl")) {// 考勤管理、市场管理、销售管理 Log.i("功能定制", "***************考勤管理、市场管理、销售管理**************"); all_fun.removeView(sbqd); all_fun.removeView(xbqt); all_fun.removeView(khbf); all_fun.removeView(scjc); all_fun.removeView(sjcj); all_fun.removeView(ddgl); layout3.addView(sbqd); layout3.addView(xbqt); layout3.addView(khbf); layout4.addView(scjc); layout4.addView(sjcj); layout4.addView(ddgl); } break; case 2: all_fun.removeView(xtbg); layout2.addView(xtbg); break; default: Log.i("功能定制", "***************无定制任何功能**************"); all_fun.removeView(stone1); layout2.addView(stone1); } } else { Log.i("功能定制", "***************无定制任何功能**************"); all_fun.removeView(stone1); layout2.addView(stone1); } share_obj = new Optsharepre_interface(MainActivity.this); myApp = (MyApp) this.getApplication(); // 将当前Activity放入存储器中 ArrayList<Activity> listActivity = myApp.getListActivity(); listActivity.add(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == gzt) { startActivity(new Intent().setClass(this, GztAllList.class)); } else if (v == sbqd) { //1网络优先2仅仅GPS3GPS优先 String dwMode = share_obj.getDataFromPres("DWMODE"); // String dwMode=""; share_obj.editPres("istakephoto", "0"); boolean flag = false; if (dwMode.equals("2")) { flag = checkGpState(); if (flag) { Intent stateService = new Intent(MainActivity.this,GpsService.class); startService(stateService); } } if (flag || !dwMode.equals("2")) { myApp.setType(1); // 判断是否精签到或粗签到 if (share_obj.getDataFromPres("QDMODE").equals("1")) {// 粗签到 Intent intent = new Intent(); intent.putExtra("point", 0);// 参数无效 startActivity(intent.setClass(this, Ddxq.class)); } else if (share_obj.getDataFromPres("QDMODE").equals("2")) {// 精签到 // 判断是否存在客户 Optdb_interfce db = new Optdb_interfce(MainActivity.this); ArrayList<CustomerModule> custs = db.searchkqAddrs(1, ""); db.close_SqlDb(); if (custs != null && custs.size() > 0) {// 精签到 startActivity(new Intent().setClass(this, KqList.class)); } else {// 非正常签到 Intent intent = new Intent(); intent.putExtra("point", 1); startActivity(intent.setClass(this, Ddxq.class)); } } else if(share_obj.getDataFromPres("QDMODE").equals("3")){//严格精签到 // 判断是否存在客户 Optdb_interfce db = new Optdb_interfce(MainActivity.this); ArrayList<CustomerModule> custs = db.searchkqAddrs(1, ""); db.close_SqlDb(); if (custs != null && custs.size() > 0) {// 精签到 startActivity(new Intent().setClass(this, KqList.class)); } else { new AlertDialog.Builder(MainActivity.this) .setTitle("提示") .setMessage("对不起,请先联系管理员为您的签到地点,然后才能使用此功能!") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show(); } }else{ new AlertDialog.Builder(MainActivity.this) .setTitle("提示") .setMessage("对不起,请先联系管理员为您的分配考勤策略,然后才能使用此功能!") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show(); } } } else if (v == xbqt) { share_obj.editPres("istakephoto", "0"); String dwMode = share_obj.getDataFromPres("DWMODE"); boolean flag = false; if (dwMode.equals("2")) { flag = checkGpState(); if (flag) { Intent stateService = new Intent(MainActivity.this, GpsService.class); startService(stateService); } } if (flag || !dwMode.equals("2")) { myApp.setType(2); // 判断是否精签退或粗签退 if (share_obj.getDataFromPres("QDMODE").equals("1")) { Intent intent = new Intent(); intent.putExtra("point", 0);// 参数无效 startActivity(intent.setClass(this, Ddxq.class)); } else if (share_obj.getDataFromPres("QDMODE").equals("2")) { // 判断是否存在客户 Optdb_interfce db = new Optdb_interfce(MainActivity.this); ArrayList<CustomerModule> custs = db.searchkqAddrs(1, ""); db.close_SqlDb(); if (custs != null && custs.size() > 0) {// 精签到 startActivity(new Intent().setClass(this, KqList.class)); } else {// 非正常签退 Intent intent = new Intent(); intent.putExtra("point", 1); startActivity(intent.setClass(this, Ddxq.class)); } } else if(share_obj.getDataFromPres("QDMODE").equals("3")){//严格精签退 // 判断是否存在客户 Optdb_interfce db = new Optdb_interfce(MainActivity.this); ArrayList<CustomerModule> custs = db.searchkqAddrs(1, ""); db.close_SqlDb(); if (custs != null && custs.size() > 0) {// 精签到 startActivity(new Intent().setClass(this, KqList.class)); } else { new AlertDialog.Builder(MainActivity.this) .setTitle("提示") .setMessage("对不起,请先联系管理员为您分配签到地点,然后才能使用此功能!") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show(); } }else{ new AlertDialog.Builder(MainActivity.this) .setTitle("提示") .setMessage("对不起,请先联系管理员为您分配考勤策略,然后才能使用此功能!") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show(); } } } else if (v == grbg) { startActivity(new Intent().setClass(this, Grbg.class)); } else if (v == khbf) { String dwMode = share_obj.getDataFromPres("DWMODE"); boolean flag = false; if (dwMode.equals("2")) { flag = checkGpState(); if (flag) { Intent stateService = new Intent(MainActivity.this, GpsService.class); startService(stateService); } } if (flag || !dwMode.equals("2")) { ShareMethod shareMethod = null; shareMethod = new ShareMethod(MainActivity.this); shareMethod.recordLog("khbf"); startActivity(new Intent().setClass(this, Khbf.class)); } } else if (v == scjc) { String dwMode = share_obj.getDataFromPres("DWMODE"); boolean flag = false; if (dwMode.equals("2")) { flag = checkGpState(); } if (flag || !dwMode.equals("2")) { // String jclb // ="堆头检查,设施使用,促销力度";//模拟数据************************************************ Optdb_interfce db = new Optdb_interfce(MainActivity.this); CoUserModule co = (CoUserModule) db.searchFromDb("COUSERS") .get(0); db.close_SqlDb(); if (co.getJclb() == null || co.getJclb().equals("-1") || co.getJclb().equals("")) { new AlertDialog.Builder(MainActivity.this) .setTitle("提示") .setMessage("对不起,请先在平台中添加市场检查类别,然后才能使用此功能!") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show(); } else { final String[] jcxx = co.getJclb().split(","); new AlertDialog.Builder(MainActivity.this) .setTitle("请选择市场检查类型") .setItems(jcxx, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { String dwMode = share_obj .getDataFromPres("DWMODE"); if (dwMode.equals("2")) { Intent stateService = new Intent( MainActivity.this, GpsService.class); startService(stateService); } myApp.setModuleName("scjc"); myApp.setSort(jcxx[which]); share_obj.editPres("istakephoto", "0"); startActivity(new Intent() .setClass( MainActivity.this, Khlb.class)); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show(); } } } else if (v == xxfk) { Optdb_interfce db = new Optdb_interfce(MainActivity.this); CoUserModule co = (CoUserModule) db.searchFromDb("COUSERS").get(0); db.close_SqlDb(); // String cjlb // ="竞品信息,商品促销,客户建议,现场活动";//模拟数据************************************************ String cjlb = co.getXxcjlb(); if (cjlb == null || cjlb.equals("-1") || cjlb.equals("")) { new AlertDialog.Builder(MainActivity.this) .setTitle("提示") .setMessage("对不起,请先在平台中添加信息采集类别,然后才能使用此功能!") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } else { final String[] cjxx = cjlb.split(","); new AlertDialog.Builder(MainActivity.this) .setTitle("请选择信息采集类别") .setItems(cjxx, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { share_obj.editPres("istakephoto", "0"); startActivity(new Intent().setClass( MainActivity.this, Xxfk.class) .putExtra("xxcjlb", cjxx[which])); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } } else if (v == ddgl) { String cxlb = "订单上报,订单查询"; final String[] xxcj = cxlb.split(","); new AlertDialog.Builder(MainActivity.this) .setTitle("选择操作类型") .setItems(xxcj, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == 0) { myApp.setModuleName("ddsb"); myApp.setDataType("1"); startActivity(new Intent().setClass( MainActivity.this, GroupList.class)); } else { startActivity(new Intent().setClass( MainActivity.this, Ddcx.class)); } } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } else if (v == sjcj) { String cxlb = "销售上报,竞品上报,库存上报"; final String[] xxcj = cxlb.split(","); new AlertDialog.Builder(MainActivity.this) .setTitle("选择数据采集类型") .setItems(xxcj, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == 0) { myApp.setModuleName("xssb"); } else if (which == 1) { myApp.setModuleName("jpsb"); } else if (which == 2) { myApp.setModuleName("kcsb"); } startActivity(new Intent().setClass( MainActivity.this, GroupList.class)); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } else if (v == xszs) { myApp.setModuleName("xszs"); startActivity(new Intent().setClass(this, Xszs.class)); } else if (v == txl) { Optdb_interfce db = new Optdb_interfce(MainActivity.this); CoUserModule co = (CoUserModule) db.searchFromDb("COUSERS").get(0); db.close_SqlDb(); // String cjlb // ="竞品信息,商品促销,客户建议,现场活动";//模拟数据************************************************ String txl = "0"; try { if (co.getTxl() != null) { txl = co.getTxl(); System.out.println("co.getTxl()" + co.getTxl()); } } catch (Exception e) { e.printStackTrace(); txl = "0"; } if (txl.equals("1")) { new AlertDialog.Builder(MainActivity.this) .setTitle("注意") .setMessage("通讯录功能未开启") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } else { myApp.setModuleName("txl"); startActivity(new Intent().setClass(this, TabThird.class)); } } else if (v == xtbg) { startActivity(new Intent().setClass(this, Xtbg.class)); } else if (v == more) { this.openOptionsMenu(); } else if (v == xcgl) { Optdb_interfce db = new Optdb_interfce(MainActivity.this); CoUserModule co = (CoUserModule) db.searchFromDb("COUSERS").get(0); db.close_SqlDb(); String lb = co.getJclb(); final String[] xx = lb.split(","); new AlertDialog.Builder(MainActivity.this) .setTitle("选择操作类型") .setItems(xx, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == 0) { myApp.setModuleName("wzcx"); } else if (which == 1) { myApp.setModuleName("gjhf"); } startActivity(new Intent().setClass( MainActivity.this, EmpGroupList.class)); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } } @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); Log.i("MAIN", "------onStart-------"); ShareMethod shareMethod = new ShareMethod(MainActivity.this); // 检测错误日志、锁屏服务是否启动 startService(new Intent(MainActivity.this,UpPlanService.class)); shareMethod.checkService(); // if(!myApp.isServiceRunning()){ // Log.e("startService", "UpLocationService"); // startService(new Intent(MainActivity.this,UpLocationService.class)); // } // 关闭Gps调用 closeGps(); // 初始化共享池中的数据 myApp.setModuleName("");// 功能模块 myApp.setGroupNums("");// 分组编号 myApp.setGoodGroupNum("");// 商品分组编号 myApp.setGoodList(new ArrayList<Bundle>());// 商品数据 myApp.setCustBundle(new Bundle());// 客户数据 myApp.setDataType("1");// 数据类型 myApp.setFzid("");// 分组id } /** * 检测并启动Gps搜星 */ public void startGps() { int gps_flag = new CheckState_interface(MainActivity.this) .checkGpState(); if (gps_flag == 1) {// GPS设备已打开 Intent stateService = new Intent(MainActivity.this, GpsService.class); startService(stateService); } else {// GPS设备未打开 Toast.makeText(this, "GPS模块不可用,请打开GPS功能!", Toast.LENGTH_LONG) .show(); } } /** * 检测并关闭Gps设备 */ public void closeGps() { SystemInfo sys = new SystemInfo(MainActivity.this); boolean flag = sys .isServiceRunning("com.jqyd.shareInterface.GpsService"); if (flag) { Intent intent = new Intent(MainActivity.this, GpsService.class); stopService(intent); } } /** * 创建菜单按钮,并添加点击事件 */ @Override public boolean onCreateOptionsMenu(Menu menu) { boolean result = super.onCreateOptionsMenu(menu); System.out.println("--------------------------menu------------------"); menu.add(0, 0, 0, "客户采集"); menu.add(0, 1, 0, "位置上报"); menu.add(0, 2, 0, "数据重传"); menu.add(0, 3, 0, "更多"); return result; } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case 0: boolean flag = checkGpState(); if (flag) { Intent stateService = new Intent(MainActivity.this, GpsService.class); startService(stateService); myApp.setModuleName("khcj"); share_obj.editPres("cjlx", "khcj"); ShareMethod shareMethod = null; shareMethod = new ShareMethod(MainActivity.this); shareMethod.recordLog("khcj"); startActivity(new Intent().setClass(this, Khcjlb.class)); } break; case 1: // 判断是否需要检测GPS设备的状态 String dwMode2 = share_obj.getDataFromPres("DWMODE"); boolean flag2 = false; if (dwMode2.equals("2")) { flag2 = checkGpState(); } if (flag2 || !dwMode2.equals("2")) { new WzsbThread().start(); } // sendMess(); break; case 2: startActivity(new Intent().setClass(this, Sjcc.class)); break; case 3: startActivity(new Intent().setClass(this, MorePage.class)); finish(); break; } return super.onMenuItemSelected(featureId, item); } private void sendMess() { new Thread(){ @Override public void run() { try { MyApp myApp = (MyApp) getApplication(); JSONObject obj = new JSONObject(); obj.put("khlb", myApp.getVersion()); obj.put("dwhm", new Optsharepre_interface(MainActivity.this).getDataFromPres("REGSIM")); obj.put("dwms", new Optsharepre_interface(MainActivity.this).getDataFromPres("DWMODE")); UpdataToServer server = new UpdataToServer(MainActivity.this); String result = server.dataToServer("SENDMESS", obj); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); } /** * 检查GPS状态 */ private boolean checkGpState() { boolean flag = false; LocationManager locMgr = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); if (!locMgr .isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { new AlertDialog.Builder(MainActivity.this) .setMessage("GPS模块不可用,请打开GPS功能") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialoginterface, int i) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }).show(); } else { flag = true; } return flag; } /** * 位置上报线程 */ class WzsbThread extends Thread { @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); System.out .println("-------------------------调用位置上报线程-------------------------"); String upResult = ""; Message message = new Message(); message.what = 1; myHander.sendMessage(message); // 获取基站相关信息 LocationModule loc = new LocationUtils(MainActivity.this) .takeCellInfos(); LocationUtils locationUtils = new LocationUtils(MainActivity.this); boolean b = locationUtils.getLocation(loc, "All", "", baidu); if (b) { // 获取到位置 // 调用位置上报方法 upResult = upLocation(loc); } else { upResult = "位置获取失败,请稍后重新操作!"; } // freeBdListener(); Message message2 = new Message(); Bundle bundle = new Bundle(); bundle.putString("msg", upResult); message2.setData(bundle); message2.what = 2; myHander.sendMessage(message2); Looper.loop(); } } /** * 上传位置信息 * * @param loc * @param dw_type * @return */ public String upLocation(LocationModule loc) { String result = "-1"; db = new Optdb_interfce(MainActivity.this); // 获得登录者姓名 String userName = db.searchEmpName(share_obj.getDataFromPres("GUID")); db.close_SqlDb(); JSONObject object = new JSONObject(); try { object.put("cosim", share_obj.getDataFromPres("COSIM")); object.put("regsim", share_obj.getDataFromPres("REGSIM")); object.put("time", loc.getTime()); object.put("lon", loc.getLon()); object.put("lat", loc.getLat()); object.put("cell_id", loc.getCell_id()); object.put("lac_code", loc.getLac()); object.put("country_code", loc.getCcode()); object.put("ncode", loc.getNcode()); object.put("signal_strength", loc.getXhqd()); object.put("loc_method", loc.getDw_type()); object.put("radius", loc.getRadius()); object.put("gguid", share_obj.getDataFromPres("GGUID")); object.put("guid", share_obj.getDataFromPres("GUID")); object.put("zdmc", userName); object.put("yys", loc.getYys()); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } UpdataToServer server = new UpdataToServer(MainActivity.this); // 请求服务器 result = server.dataToServer("WZSB", object); // 记录日志 String log = "《位置上报》-----" + "定位方式:" + loc.getDw_type() + ",经度:" + loc.getLon() + ",纬度:" + loc.getLat() + ",上传结果:" + result; Log.e("WZSB", log); new ShareMethod(MainActivity.this).recordLog(log); if (result != null && !result.equals("-1") && !result.equals("500")) { try { JSONObject obj = new JSONObject(result); String retMsg = obj.getString("detail"); result = retMsg; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { failToSave(object); } return result; } /** * 上传失败后保存 */ public void failToSave(final JSONObject object) { new AlertDialog.Builder(MainActivity.this).setTitle("提示") .setMessage("上传失败,是否保存?") .setPositiveButton("保存", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ArrayList<Object> list = new ArrayList<Object>(); RecordModel record = new RecordModel(); try { String time = ""; if (object.getLong("time") != 0) { time = object.getLong("time") + ""; } else { time = new Date().getTime() + ""; } record.setAdd_time(time); record.setCcode(object.getString("country_code")); record.setCid(object.getString("cell_id")); record.setGid("9"); record.setJclb(object.getString("yys"));// 保存运营商字段值 record.setLac(object.getString("lac_code")); record.setLat(object.getDouble("lat") + ""); record.setLon(object.getDouble("lon") + ""); record.setNcode(object.getString("ncode")); record.setRaduis(object.getString("radius")); record.setWzbs(object.getString("loc_method"));// 保存位置获取方式 record.setXhqd(object.getString("signal_strength")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } list.add(record); db = new Optdb_interfce(MainActivity.this); db.updateToDb("T_RECORDS", list); db.close_SqlDb(); Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show(); } }).setNegativeButton("取消", null).show(); } Handler myHander = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); try { switch (msg.what) { case 1: showDialog(1); // 注册百度 // baidu = new Baidu_location(MainActivity.this); break; case 2: removeDialog(1); Bundle data = msg.getData(); String message = data.getString("msg"); showToast(message); break; case 3: //工作台数量请求交互成功,改变时间 Calendar cc=Calendar.getInstance(); cc.setTimeInMillis(System.currentTimeMillis()); Date d=new Date(cc.getTimeInMillis()); //记录下时间 share_obj.editPres("gztLastUpdateTime", sdf.format(d)); int n=msg.arg1; if(n!=0&&n<10){ gztNum.setText(String.valueOf(n)); gztNum.setVisibility(View.VISIBLE); share_obj.editPres("gztNum", String.valueOf(n)); }else if(n==0){ gztNum.setText(String.valueOf(n)); gztNum.setVisibility(View.INVISIBLE); share_obj.editPres("gztNum", String.valueOf(n)); }else{ gztNum.setText("10+"); gztNum.setVisibility(View.VISIBLE); share_obj.editPres("gztNum", String.valueOf(n)); } break; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("显示或取消运行框时出现异常"); } } }; /** * 判断服务是否运行 * * @return */ public boolean isServiceRunning(String pac_act) { boolean flag = false; ActivityManager myManager = (ActivityManager) MainActivity.this .getSystemService(Context.ACTIVITY_SERVICE); ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager .getRunningServices(Integer.MAX_VALUE); for (int i = 0; i < runningService.size(); i++) { if (runningService.get(i).service.getClassName().toString() .equals(pac_act)) { flag = true; } } return flag; } // 销毁百度定位监听器 public void freeBdListener() { if (baidu != null) { baidu.stopListener(); baidu = null; } } /** * 结果显示 * * @param message */ public void showToast(String message) { new AlertDialog.Builder(MainActivity.this).setTitle("提示") .setMessage(message).setPositiveButton("确定", null).show(); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub ProgressDialog dialog = new ProgressDialog(MainActivity.this); dialog.setIndeterminate(true); dialog.setCancelable(false); switch (id) { case 1: dialog.setMessage("正在获取位置信息,请稍候……"); break; } return dialog; } /** * 点击注销登录 */ public void exit() { new AlertDialog.Builder(MainActivity.this) .setTitle("注意") .setMessage("确认注销登录?") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { closeGps(); finish(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } // 原文链接:http://www.linuxidc.com/Linux/2012-04/59223.htm /** * 点击返回键,保持当前Activity不退出 */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { closeGps();// 关闭GPS Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// 注意 intent.addCategory(Intent.CATEGORY_HOME); this.startActivity(intent); return true; } return super.onKeyDown(keyCode, event); } @Override public void finish() { // TODO Auto-generated method stub super.finish(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.e("MainActivity", "onDestroy"); ArrayList<Activity> listActivity = myApp.getListActivity(); System.out.println("关闭程序---------------------------------------" + listActivity.size()); for (Activity ac : listActivity) { if (ac != null) { ac.finish(); } } // 销毁百度监听器 freeBdListener(); // 关闭GPS closeGps(); // android.os.Process.killProcess(android.os.Process.myPid()); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); baidu = new Baidu_location(MainActivity.this); String updataLastTime=share_obj.getDataFromPres("gztLastUpdateTime"); //判断是否要进行数据更新 if(!updataLastTime.equals("")&&updataLastTime!=null){ //说明上次有时间记录 Calendar c=Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); Date nowDate=new Date(c.getTimeInMillis()); Long time = null;//毫秒 try { Date updataLastDate=sdf.parse(updataLastTime); time=nowDate.getTime()-updataLastDate.getTime(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(time!=null&&time>=60*60*1000){ //说明超过了60分钟,进行数据更新 Log.e("-----------", "--------数据更新"); new UpdateGztNumThread().start(); new UpdateThread().start();//数据更新 }else { //记录下时间 int n=Integer.parseInt(share_obj.getDataFromPres("gztNum")); if(n!=0&&n<10){ gztNum.setText(String.valueOf(n)); gztNum.setVisibility(View.VISIBLE); }else if(n==0){ gztNum.setText(String.valueOf(n)); gztNum.setVisibility(View.INVISIBLE); }else { gztNum.setText("10+"); gztNum.setVisibility(View.VISIBLE); } } }else{ //第一次进入 new UpdateGztNumThread().start(); } } //工作台数量更新线程 class UpdateGztNumThread extends Thread implements Runnable{ @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); JSONObject object = new JSONObject(); Optsharepre_interface share_obj = new Optsharepre_interface(MainActivity.this); try { object.put("guid", share_obj.getDataFromPres("GUID")); object.put("gguid", share_obj.getDataFromPres("GGUID")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String result = new UpdataToServer(MainActivity.this).searchFromServer("gztnum", object); if(!result.equals("") && !result.equals("-1") && !result.equals("500")){ JSONObject obj = null; int n=0; try { obj = new JSONObject(result); n = (Integer) obj.get("gztNum"); } catch (JSONException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } //同Server端交互成功 Message msg =new Message(); msg.what = 3; msg.arg1=n; myHander.sendMessage(msg); } Looper.loop(); } } class UpdateThread extends Thread { String username; String password; String imsi; String gnjs; String timeNode; String version; String vercode; public UpdateThread() { db = new Optdb_interfce(MainActivity.this); String loginNameStr = share_obj.getDataFromPres("REGSIM"); String pwdStr = share_obj.getDataFromPres("password"); String timeNode = "19000101"; ArrayList<Object> list = new ArrayList<Object>(); try { list = db.searchFromDb("DATA_UPDATES"); // 关闭数据库 db.close_SqlDb(); } catch (Exception e) { // TODO Auto-generated catch block } if (list.size() > 0) { timeNode = ""; for (int i = 0; i < list.size(); i++) { timeNode += list.get(i) + "#"; } timeNode = timeNode.substring(0, timeNode.length() - 1); } String values = share_obj.getDataFromPres("LOGIN"); String vals[] = values.split("#"); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String imsi = tm.getSubscriberId(); // 取出现在的IMSI号码 if(imsi==null){ imsi="000000000000000"; } this.username = loginNameStr; this.password = pwdStr; this.imsi = imsi; this.gnjs = vals[0]; this.timeNode = timeNode; this.version = myApp.getVersion(); } @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); Message message1 = new Message(); UpdataToServer server = new UpdataToServer(MainActivity.this); String Result = server.Update(username, password, imsi, gnjs, timeNode, version, vercode); Looper.loop(); } } }