package com.jqyd.son; import java.io.File; import java.util.ArrayList; import java.util.Date; import java.util.Map; import java.util.UUID; import com.jqyd.app.BitmapUtils; import com.jqyd.app.GetDistance; import com.jqyd.app.LocationUtils; import com.jqyd.app.MyApp; import com.jqyd.app.PublicDeal; import com.jqyd.app.ShareMethod; import com.jqyd.app.UpMyFile; import com.jqyd.camera.PhotoUtil; import com.jqyd.manager.R; import com.jqyd.model.LocationModule; import com.jqyd.model.RecordModel; import com.jqyd.pub.MyProgressDialog; import com.jqyd.shareInterface.Baidu_location; import com.jqyd.shareInterface.ConnectStateService; import com.jqyd.shareInterface.Optdb_interfce; import com.jqyd.shareInterface.Optsharepre_interface; import com.jqyd.shareInterface.SystemInfo; import com.jqyd.socket.UpSocketFile; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; 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.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; public class PicMoreDetail extends Activity implements OnClickListener { private EditText pic_detail; private ImageView imageView1, imageView2, imageView3, imageView4, imageView5; private Button up; private Button save; private Button giveup; private Bitmap bm1 = null, bm2 = null, bm3 = null, bm4 = null, bm5 = null; private Bundle bundle = null; private String pic_sort = ""; private MyApp myApp; private Optdb_interfce db = null; private Optsharepre_interface share_obj = null; private double cuLon = 0.0;// 客户真实经度 private double cuLat = 0.0;// 客户真实纬度 private double cuClon = 0.0;// 客户粗经度 private double cuClat = 0.0;// 客户粗纬度 private int dislimit = 0; private ArrayList<String> paths = new ArrayList<String>(); private int imageNum = 0; private PicDealThread picThread = null; private PicSaveThread saveThread = null; int param = 2; private String log = "";// 记录日志 private ShareMethod shareMethod = null; private final String TAG = "SCJC"; private Baidu_location baidu = null; private MyProgressDialog pBar; private MyBroadcastReciver receiveBroadCast; ShareMethod shareMethd; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.picmoreinfo); shareMethd = new ShareMethod(PicMoreDetail.this); pic_detail = (EditText) this.findViewById(R.id.pic_detail); imageView1 = (ImageView) this.findViewById(R.id.imageView1); imageView2 = (ImageView) this.findViewById(R.id.imageView2); imageView3 = (ImageView) this.findViewById(R.id.imageView3); imageView4 = (ImageView) this.findViewById(R.id.imageView4); imageView5 = (ImageView) this.findViewById(R.id.imageView5); up = (Button) this.findViewById(R.id.up); save = (Button) this.findViewById(R.id.save); giveup = (Button) this.findViewById(R.id.giveup); up.setOnClickListener(this); save.setOnClickListener(this); giveup.setOnClickListener(this); Intent intent = this.getIntent(); bundle = intent.getExtras(); pic_sort = intent.getStringExtra("pic_sort"); myApp = (MyApp) this.getApplication(); // 显示图片 paths = intent.getStringArrayListExtra("imagePaths"); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 10; share_obj = new Optsharepre_interface(PicMoreDetail.this); dislimit = Integer.parseInt(share_obj.getDataFromPres("DISLIMIT")); BitmapUtils bitmapUtils = new BitmapUtils(PicMoreDetail.this); if (paths.size() == 1) { // bm1 = BitmapFactory.decodeFile(paths.get(0),options); bm1 = bitmapUtils.decodeBitmap(paths.get(0)); this.imageView1.setImageBitmap(bm1); } else if (paths.size() == 2) { // bm1 = BitmapFactory.decodeFile(paths.get(0),options); bm1 = bitmapUtils.decodeBitmap(paths.get(0)); this.imageView1.setImageBitmap(bm1); // bm2 = BitmapFactory.decodeFile(paths.get(1),options); bm2 = bitmapUtils.decodeBitmap(paths.get(1)); this.imageView2.setVisibility(ImageView.VISIBLE); this.imageView2.setImageBitmap(bm2); } else if (paths.size() == 3) { // bm1 = BitmapFactory.decodeFile(paths.get(0),options); bm1 = bitmapUtils.decodeBitmap(paths.get(0)); this.imageView1.setImageBitmap(bm1); // bm2 = BitmapFactory.decodeFile(paths.get(1),options); bm2 = bitmapUtils.decodeBitmap(paths.get(1)); this.imageView2.setVisibility(ImageView.VISIBLE); this.imageView2.setImageBitmap(bm2); // bm3 = BitmapFactory.decodeFile(paths.get(2),options); bm3 = bitmapUtils.decodeBitmap(paths.get(2)); this.imageView3.setVisibility(ImageView.VISIBLE); this.imageView3.setImageBitmap(bm3); } else if (paths.size() == 4) { // bm1 = BitmapFactory.decodeFile(paths.get(0),options); bm1 = bitmapUtils.decodeBitmap(paths.get(0)); this.imageView1.setImageBitmap(bm1); // bm2 = BitmapFactory.decodeFile(paths.get(1),options); bm2 = bitmapUtils.decodeBitmap(paths.get(1)); this.imageView2.setVisibility(ImageView.VISIBLE); this.imageView2.setImageBitmap(bm2); // bm3 = BitmapFactory.decodeFile(paths.get(2),options); bm3 = bitmapUtils.decodeBitmap(paths.get(2)); this.imageView3.setVisibility(ImageView.VISIBLE); this.imageView3.setImageBitmap(bm3); // bm4 = BitmapFactory.decodeFile(paths.get(3),options); bm4 = bitmapUtils.decodeBitmap(paths.get(3)); this.imageView4.setVisibility(ImageView.VISIBLE); this.imageView4.setImageBitmap(bm4); } else if (paths.size() == 5) { // bm1 = BitmapFactory.decodeFile(paths.get(0),options); bm1 = bitmapUtils.decodeBitmap(paths.get(0)); this.imageView1.setImageBitmap(bm1); // bm2 = BitmapFactory.decodeFile(paths.get(1),options); bm2 = bitmapUtils.decodeBitmap(paths.get(1)); this.imageView2.setVisibility(ImageView.VISIBLE); this.imageView2.setImageBitmap(bm2); // bm3 = BitmapFactory.decodeFile(paths.get(2),options); bm3 = bitmapUtils.decodeBitmap(paths.get(2)); this.imageView3.setVisibility(ImageView.VISIBLE); this.imageView3.setImageBitmap(bm3); // bm4 = BitmapFactory.decodeFile(paths.get(3),options); bm4 = bitmapUtils.decodeBitmap(paths.get(3)); this.imageView4.setVisibility(ImageView.VISIBLE); this.imageView4.setImageBitmap(bm4); // bm5 = BitmapFactory.decodeFile(paths.get(4),options); bm5 = bitmapUtils.decodeBitmap(paths.get(4)); this.imageView5.setVisibility(ImageView.VISIBLE); this.imageView5.setImageBitmap(bm5); } if (pic_sort.equals("scjc")) { // 暂时性的容错处理 String lonStr = bundle.getString("cuLon"); String latStr = bundle.getString("cuLat"); String clonStr = bundle.getString("cuClon"); String clatStr = bundle.getString("cuClat"); if (lonStr == null || lonStr.equals("")) { lonStr = "0.0"; } if (latStr == null || latStr.equals("")) { latStr = "0.0"; } if (clonStr == null || clonStr.equals("")) { clonStr = "0.0"; } if (clatStr == null || clatStr.equals("")) { clatStr = "0.0"; } cuLon = Double.parseDouble(lonStr); cuLat = Double.parseDouble(latStr); cuClon = Double.parseDouble(clonStr); cuClat = Double.parseDouble(clatStr); Log.i(TAG, "拍照检查类别----------" + bundle.getString("jclb")); } else if (pic_sort.equals("rzsb")) { Log.i(TAG, "日志上报--拍照"); save.setVisibility(Button.GONE); } shareMethod = new ShareMethod(PicMoreDetail.this); // 注册百度 baidu = new Baidu_location(PicMoreDetail.this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == up) { if (pic_sort.equals("rzsb")) { shareMethod.recordLog("开始上传日志"); new WorkLogThread().start(); } else if (pic_sort.equals("xxfk")) { new xxfkThread().start(); } else { if (picThread != null && picThread.isAlive()) { System.out.println("终止上报线程"); try { PicDealThread.currentThread().interrupt(); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("终止线程出现异常"); e.printStackTrace(); } }// scjcUpToServer(); picThread = new PicDealThread(); picThread.start(); } } else if (v == save) { saveThread = new PicSaveThread(); saveThread.start(); } else if (v == giveup) { finish(); } } class xxfkThread extends Thread { @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); imageNum = 0; imageNum = imageNum + 1; Message msgHead = new Message(); msgHead.what = 3; myHander.sendMessage(msgHead); // 上传图片 String result = xxfkUpToServer(); Log.i(TAG, "jg:" + result + "," + param); Bundle bundle = new Bundle(); Message msgHead2 = new Message(); if (!result.equals("0")) { msgHead2.what = 2; bundle.putString("msg", "上传失败!"); } msgHead2.what = param; msgHead2.setData(bundle); myHander.sendMessage(msgHead2); Looper.loop(); } } public String xxfkUpToServer() { registerRec(); String result = "-1"; String relationid = UUID.randomUUID().toString(); bundle.putString("pic_detail", pic_detail.getText().toString()); // 获取基站相关信息 LocationModule loc = new LocationUtils(PicMoreDetail.this).takeCellInfos(); LocationUtils locationUtils = new LocationUtils(PicMoreDetail.this); boolean b = locationUtils.getLocation(loc, "All", "", baidu); bundle.putString("country_code", loc.getCcode()); bundle.putString("cell_id", loc.getCell_id()); bundle.putString("lac_code", loc.getLac()); bundle.putString("time", String.valueOf(loc.getTime())); bundle.putString("ncode", loc.getNcode()); bundle.putString("relationid", relationid); if (loc.getXhqd().trim().equals("")) { bundle.putString("signal_strength", "0"); } else { bundle.putString("signal_strength", loc.getXhqd()); } bundle.putString("yys", loc.getYys()); if (b) { bundle.putString("lon", String.valueOf(loc.getLon())); bundle.putString("lat", String.valueOf(loc.getLat())); bundle.putString("radius", loc.getRadius()); bundle.putString("loc_method", String.valueOf(loc.getDw_type())); } else { bundle.putString("lon", "0.0"); bundle.putString("lat", "0.0"); bundle.putString("radius", "0"); bundle.putString("loc_method", "-1"); } for (int i = 0; i < paths.size(); i++) { File uploadFile = new File(paths.get(i)); int uplength = (int) uploadFile.length(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (pBar != null) { pBar.setMax(uplength / 1000); } UpMyFile upfile = new UpMyFile(PicMoreDetail.this); bundle.putString("imagePath", paths.get(i)); result = upfile.upToServer(bundle, pic_sort); // 上传成功 if (result != null && result.equals("0")) { if (imageNum >= paths.size()) { Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "上传成功"); msgRet.what = 2; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); param = 17; } else { Message msg = new Message(); msg.what = 4; myHander.sendMessage(msg); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "继续成功"); msgRet.what = 3; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); imageNum += 1; param = 4; } } else { return "1"; } } return result; } /** * 信息反馈图片保存 * * @return */ public String xxfkSave() { bundle.putString("pic_detail", pic_detail.getText().toString()); LocationModule loc = new LocationUtils(PicMoreDetail.this).takeCellInfos(); LocationUtils locationUtils = new LocationUtils(PicMoreDetail.this); boolean b = locationUtils.getLocation(loc, "All", "", baidu); Optdb_interfce db = new Optdb_interfce(PicMoreDetail.this); ArrayList<Object> list = new ArrayList<Object>(); RecordModel record = new RecordModel(); record.setCcode(loc.getCcode()); record.setNcode(loc.getNcode()); record.setXhqd(loc.getXhqd()); record.setBz(loc.getYys()); record.setCid(loc.getCell_id()); record.setLac(loc.getLac()); record.setGid("3"); record.setXxcjlb(bundle.getString("xxcjlb")); record.setContent(bundle.getString("xxnr"));// 存放信息内容 record.setRemark2(bundle.getString("xxbt"));// 备注存放信息标题 record.setAdd_time(new Date().getTime() + "");// 保存时间 record.setPic_url("1");// 存放图片地址 String pathsStr = ""; for (int i = 0; i < paths.size(); i++) { pathsStr = pathsStr + ";" + paths.get(i); } record.setPic_detail(bundle.getString("pic_detail"));// 存放图片描述 record.setRemark5(pathsStr); if (b) {// 定位成功 record.setLon(String.valueOf(loc.getLon())); record.setLat(String.valueOf(loc.getLat())); record.setRaduis(loc.getRadius()); record.setWzbs(String.valueOf(loc.getDw_type())); } else { record.setLon("0.0"); record.setLat("0.0"); record.setRaduis("0"); record.setWzbs("-1"); } list.add(record); db = new Optdb_interfce(PicMoreDetail.this); db.updateToDb("T_RECORDS", list);// 写入数据库 db.close_SqlDb(); return "0"; } /** * 图片上传线程 * * @author Administrator * */ class PicDealThread extends Thread { @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); imageNum = imageNum + 1; Message message1 = new Message(); message1.what = 10; myHander.sendMessage(message1); String result = ""; result = scjcUpToServer(); if (result != null && !result.equals("0")) { Message message2 = new Message(); Bundle bundle = new Bundle(); int p = Integer.parseInt(result); switch (p) { case -999: bundle.putString("msg", "位置获取失败,请稍后重新操作!"); break; case -888: bundle.putString("msg", "超出管理员设置的误差范围" + dislimit + "米,请走近客户进行操作!"); break; case 2: bundle.putString("msg", "找不到图片的路径,无法上传!"); break; case -1: bundle.putString("msg", "拍照出现错误,无法正常上传!"); break; case 1: bundle.putString("msg", "请求连接服务器失败,上传失败!"); break; default: bundle.putString("msg", "上传失败,请联系管理员!"); } Message message3 = new Message(); message3.what = param; myHander.sendMessage(message3); message2.what = 16; message2.setData(bundle); myHander.sendMessage(message2); } Looper.loop(); } } /** * 图片保存线程 * * @author Administrator * */ class PicSaveThread extends Thread { @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); imageNum = imageNum + 1; Message message1 = new Message(); message1.what = 10; myHander.sendMessage(message1); String result = ""; Message message2 = new Message(); Bundle bundle = new Bundle(); // 保存 if (pic_sort.equals("xxfk")) { result = xxfkSave(); } else { result = scjcSave(); } if (result != null && !result.equals("0")) { int p = Integer.parseInt(result); switch (p) { case -999: bundle.putString("msg", "位置获取失败,请稍后重新操作!"); break; case -888: bundle.putString("msg", "超出管理员设置的误差范围" + dislimit + "米,请走近客户进行操作!"); break; case 2: bundle.putString("msg", "找不到图片的路径,无法保存!"); break; case -1: bundle.putString("msg", "拍照出现错误,无法正常上传!"); break; case 1: bundle.putString("msg", "请求连接服务器失败,上传失败!"); break; default: bundle.putString("msg", "上传失败,请联系管理员!"); } } else if (result != null && result.equals("0")) { bundle.putString("msg", "保存成功!"); } Message message3 = new Message(); message3.what = param; myHander.sendMessage(message3); message2.what = 16; message2.setData(bundle); myHander.sendMessage(message2); Looper.loop(); } } /** * 日志上报线程 * * @author Administrator * */ public class WorkLogThread extends Thread { @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); imageNum = 0; imageNum = imageNum + 1; Message msgHead = new Message(); msgHead.what = 3; myHander.sendMessage(msgHead); // 上传图片 String result = rzUpToServer2(); Log.i(TAG, "jg:" + result + "," + param); Bundle bundle = new Bundle(); if (!result.equals("0")) { bundle.putString("msg", "上传失败!"); } Message msgHead2 = new Message(); msgHead2.what = param; msgHead2.setData(bundle); myHander.sendMessage(msgHead2); Looper.loop(); } } 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); break; case 2: // removeDialog(2); pBar.dismiss(); Bundle data = msg.getData(); String message = data.getString("msg"); showToast(message); break; case 3: // showDialog(2); pBar = new MyProgressDialog(PicMoreDetail.this); pBar.setMessage("第" + imageNum + "张图片信息上传中,请稍候……"); pBar.setCancelable(false); pBar.show(); break; case 4: pBar.dismiss(); // removeDialog(2); break; case 5: showDialog(3); break; case 6: removeDialog(3); Bundle data2 = msg.getData(); String message2 = data2.getString("msg"); showToast(message2); break; case 7: removeDialog(2); break; case 8: showDialog(4); break; case 9: removeDialog(4); break; case 10: showDialog(5); break; case 11: break; case 12: break; case 13: break; case 14: removeDialog(5); pBar = new MyProgressDialog(PicMoreDetail.this); pBar.setMessage("第" + imageNum + "张图片信息上传中,请稍候……"); pBar.setCancelable(false); pBar.show(); // showDialog(2); break; case 15: removeDialog(5); break; case 16: Bundle data4 = msg.getData(); String message4 = data4.getString("msg"); showToast(message4); break; case 17: break; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("显示或取消运行框时出现异常"); } } }; /** * 市场检查上传图片 * * @return */ public String scjcUpToServer() { registerRec(); String upResult = ""; double distance = 0.0; bundle.putString("pic_detail", pic_detail.getText().toString()); // 获取基站相关信息 LocationModule loc = new LocationUtils(PicMoreDetail.this).takeCellInfos(); LocationUtils locationUtils = new LocationUtils(PicMoreDetail.this); boolean b = locationUtils.getLocation(loc, "All", bundle.getString("cid"), baidu); param = 15; if (b) { // 位置获取成功 int state = loc.getState(); boolean up = true;// 默认上传 if (state == 2) { // 百度获取位置成功 if (!flagDistance(loc.getLon(), loc.getLat(), 3)) { // 百度获得的位置超出误差范围,获取卫星位置 System.out .println("******************百度获取到位置超出距离,请求卫星******************"); boolean b2 = locationUtils.getLocation(loc, "", "", baidu); if (b2) { if (!flagDistance(loc.getLon(), loc.getLat(), 1)) {// 卫星位置判断误差 System.out .println("******************卫星获取到位置超出距离******************"); upResult = "-888"; up = false; } } else { int s = loc.getState(); if (s == -1) { upResult = "-888"; // 记录日志 log = "GPS模块未打开,获取位置失败!"; shareMethod.recordLog(log); up = false; } else if (s == 0) { System.out .println("******************通过卫星获取位置信息失败******************"); upResult = "-888"; // 记录日志 log = "通过卫星获取位置信息失败!"; shareMethod.recordLog(log); up = false; } } } } else if (state == 1) { // 卫星获取位置成功 if (!flagDistance(loc.getLon(), loc.getLat(), 1)) { // 卫星位置判断误差 System.out .println("******************卫星获取到位置超出距离******************"); upResult = "-888"; up = false; } } // 上报位置 if (up) { upResult = upFile(loc); } } else { // 位置获取失败 upResult = "-999"; } return upResult; } private class MyBroadcastReciver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); if (action.equals("upfile")) { int max = intent.getIntExtra("max", 0); if (max != 0) { if (pBar != null) { pBar.setMax(max / 1000); } } int length = intent.getIntExtra("length", 0); if (pBar != null) { pBar.setProgress(length / 1000); } } } } public void registerRec() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("upfile"); receiveBroadCast = new MyBroadcastReciver(); this.registerReceiver(receiveBroadCast, intentFilter); } /** * 日志拍照上传 Http */ public String rzUpToServer2() { registerRec(); String result = "-1"; bundle.putString("pic_detail", pic_detail.getText().toString()); bundle.putString("imagecode", share_obj.getDataFromPres("REGSIM") + "_" + new Date().getTime()); // 多图片上传 for (int i = 0; i < paths.size(); i++) { Log.i(TAG, "图片个数:" + i); sendBroadCastForSys(paths.get(i)); File uploadFile = new File(paths.get(i)); int uplength = (int) uploadFile.length(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (pBar != null) { pBar.setMax(uplength / 1000); } UpMyFile upfile = new UpMyFile(PicMoreDetail.this); bundle.putString("imagePath", paths.get(i)); result = upfile.upToServer(bundle, pic_sort); // 上传成功 if (result != null && result.equals("0")) { if (imageNum >= paths.size()) { System.out.println("jieshu1:" + imageNum + "," + paths.size()); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "上传成功"); msgRet.what = 2; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); param = 17; } else { System.out.println("jieshu2:" + imageNum + "," + paths.size()); Message msg = new Message(); msg.what = 4; myHander.sendMessage(msg); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "继续成功"); msgRet.what = 3; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); imageNum += 1; param = 4; } } else { return "1"; /* * if (imageNum < paths.size()) { System.out.println("jieshu3:" * + imageNum + "," + paths.size()); Message msg2 = new * Message(); msg2.what = 4; myHander.sendMessage(msg2); * * Bundle bundleRet = new Bundle(); Message msgRet = new * Message(); bundleRet.putString("msg", "第" + imageNum + * "张图片信息上传失败!"); msgRet.what = 3; msgRet.setData(bundleRet); * myHander.sendMessage(msgRet); imageNum += 1; param =4; } else * { System.out.println("jieshu4:" + imageNum + "," + * paths.size()); Bundle bundleRet = new Bundle(); Message * msgRet = new Message(); bundleRet.putString("msg", "上传失败!"); * msgRet.what = 2; msgRet.setData(bundleRet); * myHander.sendMessage(msgRet); param = 17; } */} } Log.i(TAG, "上传结束:" + result); return result; } private void sendBroadCastForSys(String string) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri uri = Uri.fromFile(new File(string)); intent.setData(uri); sendBroadcast(intent); } /** * 日志拍照上传 * * @return socket */ public String rzUpToServer() { registerRec(); String result = "-1"; bundle.putString("pic_detail", pic_detail.getText().toString()); bundle.putString("imagecode", share_obj.getDataFromPres("REGSIM") + "_" + new Date().getTime()); // 多图片上传 for (int i = 0; i < paths.size(); i++) { Log.i(TAG, "图片个数:" + i); File uploadFile = new File(paths.get(i)); int uplength = (int) uploadFile.length(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (pBar != null) { pBar.setMax(uplength / 1000); } UpSocketFile file = new UpSocketFile(PicMoreDetail.this); bundle.putString("imagePath", paths.get(i)); result = file.packageUp("rzsb", bundle); // 上传成功 if (result != null && result.equals("0")) { if (imageNum >= paths.size()) { System.out.println("jieshu1:" + imageNum + "," + paths.size()); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "上传成功"); msgRet.what = 2; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); param = 17; } else { System.out.println("jieshu2:" + imageNum + "," + paths.size()); Message msg = new Message(); msg.what = 4; myHander.sendMessage(msg); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "继续成功"); msgRet.what = 3; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); imageNum += 1; param = 4; } } else { return "1"; /* * if (imageNum < paths.size()) { System.out.println("jieshu3:" * + imageNum + "," + paths.size()); Message msg2 = new * Message(); msg2.what = 4; myHander.sendMessage(msg2); * * Bundle bundleRet = new Bundle(); Message msgRet = new * Message(); bundleRet.putString("msg", "第" + imageNum + * "张图片信息上传失败!"); msgRet.what = 3; msgRet.setData(bundleRet); * myHander.sendMessage(msgRet); imageNum += 1; param =4; } else * { System.out.println("jieshu4:" + imageNum + "," + * paths.size()); Bundle bundleRet = new Bundle(); Message * msgRet = new Message(); bundleRet.putString("msg", "上传失败!"); * msgRet.what = 2; msgRet.setData(bundleRet); * myHander.sendMessage(msgRet); param = 17; } */} } Log.i(TAG, "上传结束:" + result); return result; } /** * 上传图片 * * @param loc * @param dw_type * @return */ public String upFile(LocationModule loc) { Message msgHead = new Message(); msgHead.what = param; myHander.sendMessage(msgHead); Message msgHead2 = new Message(); msgHead2.what = 14; myHander.sendMessage(msgHead2); String result = "-1"; bundle.putString("country_code", loc.getCcode()); bundle.putString("cell_id", loc.getCell_id()); bundle.putString("lac_code", loc.getLac()); bundle.putString("lon", loc.getLon() + ""); bundle.putString("lat", loc.getLat() + ""); bundle.putString("time", loc.getTime() + ""); bundle.putString("ncode", loc.getNcode()); bundle.putString("radius", loc.getRadius()); bundle.putString("signal_strength", loc.getXhqd()); bundle.putString("loc_method", loc.getDw_type() + ""); bundle.putString("yys", loc.getYys()); bundle.putString("imagecode", share_obj.getDataFromPres("REGSIM") + "_" + new Date().getTime()); Log.i(TAG, "paths:" + paths.size()); Log.i(TAG, "检查类别:" + bundle.getString("jclb")); // 多图片上传 for (int i = 0; i < paths.size(); i++) { UpMyFile file = new UpMyFile(PicMoreDetail.this); bundle.putString("imagePath", paths.get(i)); File uploadFile = new File(paths.get(i)); int uplength = (int) uploadFile.length(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (pBar != null) { pBar.setMax(uplength / 1000); } result = file.upToServer(bundle, pic_sort); // 上传成功 if (result != null && result.equals("0")) { if (imageNum >= paths.size()) { System.out.println("jieshu1:" + imageNum + "," + paths.size()); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "上传成功"); msgRet.what = 2; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); } else { System.out.println("jieshu2:" + imageNum + "," + paths.size()); Message msg = new Message(); msg.what = 4; myHander.sendMessage(msg); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "继续成功"); msgRet.what = 3; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); imageNum += 1; } } else { if (imageNum < paths.size()) { System.out.println("jieshu3:" + imageNum + "," + paths.size()); Message msg2 = new Message(); msg2.what = 4; myHander.sendMessage(msg2); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "第" + imageNum + "张图片信息上传失败!"); msgRet.what = 3; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); imageNum += 1; // 自动保存 if (!result.equals("2")) {// 无法获得图片路径 failToSave(); } } else { System.out.println("jieshu4:" + imageNum + "," + paths.size()); Bundle bundleRet = new Bundle(); Message msgRet = new Message(); bundleRet.putString("msg", "上传失败!"); msgRet.what = 2; msgRet.setData(bundleRet); myHander.sendMessage(msgRet); } } } // 记录日志 log = "《市场检查拍照》-----" + "定位方式:" + loc.getDw_type() + ",经度:" + loc.getLon() + ",纬度:" + loc.getLat() + ",上传结果:" + result; Log.i(TAG, log); shareMethod.recordLog(log); param = 4; return result; } /** * 误差距离判断 * * @param lon * @param lat */ public boolean flagDistance(double lon, double lat, int dwType) { boolean b = true;// 默认在误差范围内 log = "《市场检查》-----" + "定位方式:" + dwType + ",经度:" + lon + ",纬度:" + lat; double distance = 0.0; switch (dwType) { case 1:// 卫星位置判断 // 如果客户的真实经纬度为空,则需要加对客户加密过后的经纬度加密比较 if (cuLon == 0.0 || cuLat == 0.0) { PublicDeal pd = new PublicDeal(); Map map = pd.jp(lon, lat); double clon = Double.parseDouble((String) map.get("x")); double clat = Double.parseDouble((String) map.get("y")); distance = GetDistance.getDistance(clon, clat, cuClon, cuClat); log += ",客户端对客户加过密后的经度:" + clon + ",纬度:" + clat + ",误差结果:" + distance; } else { distance = GetDistance.getDistance(lon, lat, cuLon, cuLat); log += ",客户真实经度:" + cuLon + ",真实纬度:" + cuLat + ",误差结果:" + distance; } break; case 3:// 百度位置判断 distance = GetDistance.getDistance(lon, lat, cuClon, cuClat); log += ",客户加过密后的经度:" + cuClon + ",纬度:" + cuClat + ",误差结果:" + distance; break; } // 记录日志 Log.i(TAG, log); shareMethod.recordLog(log); if (distance > dislimit) { b = false; } return b; } /** * 市场检查图片保存 * * @return */ public String scjcSave() { String upResult = ""; bundle.putString("pic_detail", pic_detail.getText().toString()); // 获取基站相关信息 LocationModule loc = new LocationUtils(PicMoreDetail.this).takeCellInfos(); LocationUtils locationUtils = new LocationUtils(PicMoreDetail.this); boolean b = locationUtils.getLocation(loc, "All", bundle.getString("cid"), baidu); param = 15; if (b) { // 位置获取成功 int state = loc.getState(); boolean up = true;// 默认上传 if (state == 2) { // 百度获取位置成功 if (!flagDistance(loc.getLon(), loc.getLat(), 3)) { // 百度获得的位置超出误差范围,获取卫星位置 System.out .println("******************百度获取到位置超出距离,请求卫星******************"); boolean b2 = locationUtils.getLocation(loc, "", "", baidu);// if (b2) { if (!flagDistance(loc.getLon(), loc.getLat(), 1)) {// 卫星位置判断误差 System.out .println("******************卫星获取到位置超出距离******************"); upResult = "-888"; up = false; } } else { int s = loc.getState(); if (s == -1) { upResult = "-888"; // 记录日志 log = "GPS模块未打开,获取位置失败!"; shareMethod.recordLog(log); up = false; } else if (s == 0) { System.out .println("******************通过卫星获取位置信息失败******************"); upResult = "-888"; // 记录日志 log = "通过卫星获取位置信息失败!"; shareMethod.recordLog(log); up = false; } } } } else if (state == 1) { // 卫星获取位置成功 if (!flagDistance(loc.getLon(), loc.getLat(), 1)) {// 卫星位置判断误差 System.out .println("******************卫星获取到位置超出距离******************"); upResult = "-888"; up = false; } } // 保存起来 if (up) { upResult = saveFile(loc); } } else { // 位置获取失败 upResult = "-999"; } return upResult; } /** * 保存文件 * * @param loc * @param dw_type * @return */ public String saveFile(LocationModule loc) { String result = "-1"; Message msgHead = new Message(); msgHead.what = param; myHander.sendMessage(msgHead); Message msgHead2 = new Message(); msgHead2.what = 8; myHander.sendMessage(msgHead2); bundle.putString("country_code", loc.getCcode()); bundle.putString("cell_id", loc.getCell_id()); bundle.putString("lac_code", loc.getLac()); bundle.putString("lon", loc.getLon() + ""); bundle.putString("lat", loc.getLat() + ""); bundle.putString("time", loc.getTime() + ""); bundle.putString("ncode", loc.getNcode()); bundle.putString("radius", loc.getRadius()); bundle.putString("signal_strength", loc.getXhqd()); bundle.putString("loc_method", loc.getDw_type() + ""); bundle.putString("yys", loc.getYys()); bundle.putString("imagecode", share_obj.getDataFromPres("REGSIM") + "_" + new Date().getTime()); Log.i(TAG, "paths:" + paths.size()); for (int i = 0; i < paths.size(); i++) { bundle.putString("imagePath", paths.get(i)); ArrayList<Object> list = new ArrayList<Object>(); RecordModel record = new RecordModel(); record.setPic_url(bundle.getString("imagePath"));// 存放图片地址 record.setPic_detail(bundle.getString("pic_detail"));// 存放图片描述 String time = ""; if (bundle.getString("time") != null && !bundle.getString("time").equals("0")) { time = bundle.getString("time"); } else { time = new Date().getTime() + ""; } record.setAdd_time(time); record.setCcode(bundle.getString("country_code")); record.setCid(bundle.getString("cell_id")); record.setContent(bundle.getString("content")); record.setCustid(bundle.getString("cid")); record.setGid("7"); record.setJclb(bundle.getString("jclb")); record.setLac(bundle.getString("lac_code")); record.setLat(bundle.getString("lat")); record.setLon(bundle.getString("lon")); record.setNcode(bundle.getString("ncode")); record.setRaduis(bundle.getString("radius")); record.setWzbs(bundle.getString("loc_method"));// 保存位置获取方式 record.setXhqd(bundle.getString("signal_strength")); record.setXxcjlb(bundle.getString("jhid"));// 保存计划id record.setRemark2(bundle.getString("cname"));// 保存客户名称 record.setRemark1(bundle.getString("zhpf"));// 综合评分 record.setRemark3(bundle.getString("yys"));// 保存运营商 record.setRemark4(bundle.getString("imagecode"));// 保存图片标示 list.add(record); if (db == null || !db.isOpen()) { db = new Optdb_interfce(PicMoreDetail.this); } db.updateToDb("T_RECORDS", list); result = "0"; } param = 9; return result; } /** * 上传失败后保存 */ public void failToSave() { ArrayList<Object> list = new ArrayList<Object>(); RecordModel record = new RecordModel(); record.setPic_url(bundle.getString("imagePath"));// 存放图片地址 record.setPic_detail(bundle.getString("pic_detail"));// 存放图片描述 String time = ""; if (bundle.getString("time") != null && !bundle.getString("time").equals("0")) { time = bundle.getString("time"); } else { time = new Date().getTime() + ""; } record.setAdd_time(time); record.setCcode(bundle.getString("country_code")); record.setCid(bundle.getString("cell_id")); record.setContent(bundle.getString("content")); record.setCustid(bundle.getString("cid")); record.setGid("7"); record.setJclb(bundle.getString("jclb")); record.setLac(bundle.getString("lac_code")); record.setLat(bundle.getString("lat")); record.setLon(bundle.getString("lon")); record.setNcode(bundle.getString("ncode")); record.setRaduis(bundle.getString("radius")); record.setWzbs(bundle.getString("loc_method"));// 保存位置获取方式 record.setXhqd(bundle.getString("signal_strength")); record.setXxcjlb(bundle.getString("jhid"));// 保存计划id record.setRemark2(bundle.getString("cname"));// 保存客户名称 record.setRemark1(bundle.getString("zhpf"));// 综合评分 record.setRemark3(bundle.getString("yys"));// 保存运营商 record.setRemark4(bundle.getString("imagecode"));// 保存图片标示 list.add(record); db = new Optdb_interfce(PicMoreDetail.this); db.updateToDb("T_RECORDS", list); db.close_SqlDb(); Toast.makeText(PicMoreDetail.this, "上传失败,自动保存成功", Toast.LENGTH_SHORT) .show(); } @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if (receiveBroadCast != null) { PicMoreDetail.this.unregisterReceiver(receiveBroadCast); } System.out .println("××××××××××××××××××××××××清空图片所占内存××××××××××××××××××××××××"); // 清空内存 if (bm1 != null && !bm1.isRecycled()) { bm1.recycle(); bm1 = null; } // 清空内存 if (bm2 != null && !bm2.isRecycled()) { bm2.recycle(); bm2 = null; } // 清空内存 if (bm3 != null && !bm3.isRecycled()) { bm3.recycle(); bm3 = null; } // 清空内存 if (bm4 != null && !bm4.isRecycled()) { bm4.recycle(); bm4 = null; } // 清空内存 if (bm5 != null && !bm5.isRecycled()) { bm5.recycle(); bm5 = null; } // 终止上报线程 if (picThread != null && picThread.isAlive()) { System.out.println("终止上报线程"); try { PicDealThread.currentThread().interrupt(); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("终止线程出现异常"); e.printStackTrace(); } } // 终止保存线程 if (saveThread != null && saveThread.isAlive()) { System.out.println("终止上报线程"); try { PicSaveThread.currentThread().interrupt(); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("终止线程出现异常"); e.printStackTrace(); } } freeBdListener(); // System.gc(); } /** * 回收资源 */ public void recyle(Bitmap bitmap) { if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); bitmap = null; // System.gc(); } } // 返回就清空图片内存 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { finish(); } return super.onKeyDown(keyCode, event); } /** * 登录结果显示 * * @param message */ public void showToast(final String message) { new AlertDialog.Builder(this).setTitle("提示").setMessage(message) .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (message.contains("成功")) { finish(); } } }).show(); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub ProgressDialog dialog = new ProgressDialog(PicMoreDetail.this); dialog.setIndeterminate(true); dialog.setCancelable(false); switch (id) { case 1: dialog.setMessage("正在上传,请稍候……"); break; case 2: dialog.setMessage("第" + imageNum + "张图片信息上传中,请稍候……"); break; case 3: dialog.setMessage("第" + imageNum + "张图片信息上传失败!"); break; case 4: dialog.setMessage("正在保存,请稍候……"); break; case 5: dialog.setMessage("正在获取位置,请稍候……"); break; } return dialog; } // 销毁百度定位监听器 public void freeBdListener() { if (baidu != null) { baidu.stopListener(); baidu = null; } } }