package com.casic.gasoperation; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.util.Log; import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.amap.api.maps.AMap; import com.amap.api.maps.AMapUtils; import com.amap.api.maps.CameraUpdateFactory; import com.amap.api.maps.MapView; import com.amap.api.maps.UiSettings; import com.amap.api.maps.model.BitmapDescriptor; import com.amap.api.maps.model.BitmapDescriptorFactory; import com.amap.api.maps.model.LatLng; import com.amap.api.maps.model.Marker; import com.amap.api.maps.model.MarkerOptions; import com.amap.api.maps.model.Polyline; import com.amap.api.maps.model.PolylineOptions; import com.amap.api.maps.model.Text; import com.amap.api.maps.model.TextOptions; import com.amap.api.maps.model.animation.AlphaAnimation; import com.amap.api.maps.model.animation.Animation; import com.amap.api.maps.model.animation.AnimationSet; import com.amap.api.maps.model.animation.ScaleAnimation; import com.casic.gasoperation.config.ApiClent; import com.casic.gasoperation.utils.BaseThread; import com.casic.gasoperation.utils.HandlerStatus; import com.casic.gasoperation.utils.JWebSocketClient; import com.casic.gasoperation.utils.Msg; import com.casic.gasoperation.utils.MsgCallback; import com.casic.gasoperation.view.ButtomBar; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; public class CurrentMapActivity extends BaseActivity implements AMap.InfoWindowAdapter, AMap.OnMapClickListener { private ImageView back; private TextView person_list,person_manager,device_manager,ch4,battery,alarm_list,overall; private TextView title; public String id; private AMap aMap; LatLng latLng; private MapView mapView; private UiSettings mUiSettings; private BaseThread thread; private Marker currentMarker; private int clicknum = 770000; private Button do_job; Text lengthText; private JWebSocketClient client; public List<Marker> deviceMarkerList,treeMarkerList,nearList,enterList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_current); mapView = (MapView) findViewById(R.id.map); mapView.onCreate(savedInstanceState); back = (ImageView) findViewById(R.id.back); person_list = (TextView) findViewById(R.id.person_list); overall = (TextView) findViewById(R.id.overall); person_manager = (TextView) findViewById(R.id.person_manager); device_manager = (TextView) findViewById(R.id.device_manager); do_job = (Button) findViewById(R.id.dojob); ch4 = (TextView) findViewById(R.id.ch4); battery = (TextView) findViewById(R.id.battery); alarm_list = (TextView) findViewById(R.id.alarm_list); title = (TextView) findViewById(R.id.title); Bundle bundle=getIntent().getExtras(); try { String data =bundle.getString("data"); JSONObject json = new JSONObject(data); title.setText("作业现场名称:"+ json.getString("jobPosition")); if(json.getString("status").equals("0")) { do_job.setText("开始作业"); do_job.setBackgroundColor(Color.argb(255,139,195,74)); }else { do_job.setText("结束作业"); do_job.setBackgroundColor(Color.argb(255,255,0,0)); } id = json.getString("id"); }catch (Exception e) { Msg.showInfo(CurrentMapActivity.this, "获取作业详情出错!"); } init(); back.setOnClickListener(onClickListener); person_list.setOnClickListener(onClickListener); person_manager.setOnClickListener(onClickListener); device_manager.setOnClickListener(onClickListener); do_job.setOnClickListener(onClickListener); ch4.setOnClickListener(onClickListener); battery.setOnClickListener(onClickListener); alarm_list.setOnClickListener(onClickListener); ApiClent.overAll(id,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()).getJSONObject("data"); overall.setText("风速:"+ jsonObject.getString("windSpeed")+"m/s \n温度:"+ jsonObject.getString("temperature")+ "℃"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(String message) { } @Override public void onError(Exception e) { } }); // initSocket(); } private void initSocket(){ URI uri = URI.create("ws://139.198.6.177:14500/websocket/"+ApiClent.token); client = new JWebSocketClient(uri) { @Override public void onMessage(String message) { //message就是接收到的消息 Log.e("JWebSClientService", message); try { JSONObject json = new JSONObject(message); if(json.getString("type").equals("alarm")){ String typeId = json.getString("alarmType"); String alarmtype ="",alarmvalue=""; if(typeId.equals("1")){ alarmtype = "甲烷浓度超标"; alarmvalue = "甲烷浓度:" + json.getString("value") + "ppm.m"; } else if(typeId.equals("2")) alarmtype = "非作业人员入侵"; else if(typeId.equals("3")) alarmtype = "人员靠近预警"; else if(typeId.equals("4")){ alarmtype = "心率异常"; alarmvalue = "心率:" + json.getString("value") + "次/分钟"; } else if(typeId.equals("5")){ alarmtype = "血氧异常"; alarmvalue = "血氧浓度:" + json.getString("value") + "%"; } else if(typeId.equals("6")){ alarmtype = "氧气浓度异常"; alarmvalue = "氧气浓度:" + json.getString("value") + "%"; } else if(typeId.equals("7")){ alarmtype = "硫化氢浓度异常"; alarmvalue = "硫化氢浓度:" + json.getString("value") + "%"; } AlertDialog.Builder dialog = new AlertDialog.Builder(CurrentMapActivity.this); dialog.setIcon(R.mipmap.ic_launcher_round); if(!alarmvalue.equals("")){ dialog.setTitle("报警:"+alarmtype); dialog.setMessage(alarmvalue); }else { dialog.setTitle("报警:"); dialog.setMessage(alarmtype); } dialog.setCancelable(true); //设置是否可以通过点击对话框外区域或者返回按键关闭对话框 dialog.show(); if(typeId.equals("1")){ for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ treeMarkerList.get(i).setIcon( BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource( CurrentMapActivity.this.getResources(), R.drawable.tree_alarm))); break; } } } else if(typeId.equals("2")){ List<LatLng> list = new ArrayList<>(); for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ if(i==0){ list.add(treeMarkerList.get(0).getPosition()); list.add(treeMarkerList.get(treeMarkerList.size()-1).getPosition()); }else{ list.add(treeMarkerList.get(i).getPosition()); list.add(treeMarkerList.get(i-1).getPosition()); } break; } } Polyline polyline =aMap.addPolyline(new PolylineOptions() .add(list.get(0),list.get(1)) .width(8).color(Color.argb(180, 255, 0, 0))); Marker marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f) .position(new LatLng((list.get(0).longitude+list.get(1).longitude)/2, (list.get(0).latitude+list.get(1).latitude)/2)) .rotateAngle((float) (180+Math.atan2((list.get(0).longitude-list.get(1).longitude), (list.get(0).latitude-list.get(1).latitude))/0.017453292)) .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(CurrentMapActivity.this.getResources(), R.drawable.inalarm))) .draggable(false)); marker.setObject(json.getString("devcode")); enterList.add(marker); } else if(typeId.equals("3")){ for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ Marker marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f) .position(treeMarkerList.get(i).getPosition()) .icon(BitmapDescriptorFactory.fromBitmap( BitmapFactory.decodeResource(CurrentMapActivity.this.getResources(), R.drawable.nearalarm))) .title(json.getString("id"))//图片防伪id .snippet(json.getString("id")) .draggable(false)); marker.setObject(json); nearList.add(marker); break; } } } else if(typeId.equals("4")||typeId.equals("5")||typeId.equals("6")||typeId.equals("7")){ for(int i=0;i<deviceMarkerList.size();i++) { JSONObject markerJson = (JSONObject) deviceMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ deviceMarkerList.get(i).setIcon( BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource( CurrentMapActivity.this.getResources(), R.drawable.person1_alarm))); break; } } } } else if(json.getString("type").equals("location")){ for(int i=0;i<deviceMarkerList.size();i++) { JSONObject markerJson = (JSONObject) deviceMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ deviceMarkerList.get(i).setPosition( new LatLng(Double.parseDouble(json.getString("longitude")), Double.parseDouble(json.getString("latitude")))); break; } } } }catch (Exception e){ } } }; try { client.connectBlocking(); } catch (InterruptedException e) { e.printStackTrace(); } } /** * 断开连接 */ public void closeConnect() { try { if (null != client) { client.close(); } } catch (Exception e) { e.printStackTrace(); } finally { client = null; } } private void init() { if (aMap == null) { aMap = mapView.getMap(); mUiSettings = aMap.getUiSettings(); mUiSettings.setScaleControlsEnabled(true); mUiSettings.setCompassEnabled(true); aMap.setInfoWindowAdapter(this); aMap.setOnMapClickListener(this); // setUpMap(); //设置地图样式 getMarkers(); } } public void getMarkers() { thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.HANDLE_CURRENTDEVICE; try { ApiClent.deviceCurrentList(id,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()); JSONArray jsonArray = jsonObject.getJSONArray("data"); msg.arg1 = HandlerStatus.HANDLE_OK; msg.obj = jsonArray; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(String message) { msg.arg1 = HandlerStatus.HANDLE_FAIL; } @Override public void onError(Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } }); } catch (Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; e.printStackTrace(); } thread.sendMessage(msg); } } }; showProgress("当前作业设备列表查询中。。。", "设备列表"); thread.start(); } private void showAlarm(String message){ try { JSONObject json = new JSONObject(message); String typeId = json.getString("alarmType"); String alarmtype ="",alarmvalue=""; if(typeId.equals("1")){ alarmtype = "甲烷浓度超标"; alarmvalue = "甲烷浓度:" + json.getString("value") + "ppm.m"; } else if(typeId.equals("2")) alarmtype = "非作业人员入侵"; else if(typeId.equals("3")) alarmtype = "人员靠近预警"; else if(typeId.equals("4")){ alarmtype = "心率异常"; alarmvalue = "心率:" + json.getString("alarmValue") + "次/分钟"; } else if(typeId.equals("5")){ alarmtype = "血氧异常"; alarmvalue = "血氧浓度:" + json.getString("alarmValue") + "%"; } else if(typeId.equals("6")){ alarmtype = "氧气浓度异常"; alarmvalue = "氧气浓度:" + json.getString("alarmValue") + "%"; } else if(typeId.equals("7")){ alarmtype = "硫化氢浓度异常"; alarmvalue = "硫化氢浓度:" + json.getString("alarmValue") + "%"; } AlertDialog.Builder dialog = new AlertDialog.Builder(CurrentMapActivity.this); dialog.setIcon(R.mipmap.ic_launcher_round); if(!alarmvalue.equals("")){ dialog.setTitle("报警:"+alarmtype); dialog.setMessage(alarmvalue); }else { dialog.setTitle("报警:"); dialog.setMessage(alarmtype); } dialog.setCancelable(true); //设置是否可以通过点击对话框外区域或者返回按键关闭对话框 dialog.show(); if(typeId.equals("1")){ for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ treeMarkerList.get(i).setIcon( BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource( CurrentMapActivity.this.getResources(), R.drawable.tree_alarm))); AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); alphaAnimation.setDuration(500); alphaAnimation.setRepeatCount(20); alphaAnimation.setRepeatMode(Animation.REVERSE); animationSet.addAnimation(alphaAnimation); animationSet.setInterpolator(new LinearInterpolator()); treeMarkerList.get(i).setAnimation(animationSet); treeMarkerList.get(i).startAnimation(); break; } } } else if(typeId.equals("2")){ for(int i=0;i<enterList.size();i++) { JSONObject markerJson = (JSONObject) enterList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); alphaAnimation.setDuration(500); alphaAnimation.setRepeatCount(20); alphaAnimation.setRepeatMode(Animation.REVERSE); animationSet.addAnimation(alphaAnimation); animationSet.setInterpolator(new LinearInterpolator()); enterList.get(i).setAnimation(animationSet); enterList.get(i).startAnimation(); break; } } } else if(typeId.equals("3")){ for(int i=0;i<nearList.size();i++) { JSONObject markerJson = (JSONObject) nearList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); alphaAnimation.setDuration(500); alphaAnimation.setRepeatCount(20); alphaAnimation.setRepeatMode(Animation.REVERSE); animationSet.addAnimation(alphaAnimation); animationSet.setInterpolator(new LinearInterpolator()); nearList.get(i).setAnimation(animationSet); nearList.get(i).startAnimation(); break; } } } else if(typeId.equals("4")||typeId.equals("5")||typeId.equals("6")||typeId.equals("7")){ for(int i=0;i<deviceMarkerList.size();i++) { JSONObject markerJson = (JSONObject) deviceMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ deviceMarkerList.get(i).setIcon( BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource( CurrentMapActivity.this.getResources(), R.drawable.person1_alarm))); AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); alphaAnimation.setDuration(500); alphaAnimation.setRepeatCount(20); alphaAnimation.setRepeatMode(Animation.REVERSE); animationSet.addAnimation(alphaAnimation); animationSet.setInterpolator(new LinearInterpolator()); deviceMarkerList.get(i).setAnimation(animationSet); deviceMarkerList.get(i).startAnimation(); break; } } } }catch (Exception e){ } } @Override protected void handleMessage(Message msg) { if (msg.what == HandlerStatus.HANDLE_CURRENTDEVICE) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { if (msg.obj != null) { try { aMap.clear(); deviceMarkerList = new ArrayList<>(); treeMarkerList = new ArrayList<>(); nearList = new ArrayList<>(); enterList = new ArrayList<>(); lengthText = aMap.addText(new TextOptions() .text("") .position(new LatLng(39.921170000000004, 116.320228)) .fontColor(Color.argb(255, 0, 0, 0)) .backgroundColor(Color.argb(100,255,255,255)) .fontSize(30).visible(false)); JSONArray jsonArray = (JSONArray) msg.obj; List<LatLng> treeList = new ArrayList<LatLng>(); if(jsonArray.length()==0) { Msg.showInfo(CurrentMapActivity.this, "未查询到任何设备"); closeProgress(); return; } String outLine = ""; for(int i=0;i<jsonArray.length();i++){ JSONObject json = jsonArray.getJSONObject(i); if(json.getString("type").equals("1")&&json.getString("online").equals("0")){ outLine = outLine + json.getString("name") + ","; } } if(outLine.length()!=0){ AlertDialog.Builder builder = new AlertDialog.Builder(CurrentMapActivity.this); builder.setMessage("未检测到"+ outLine+ "请打开电源后刷新界面。"); builder.setTitle("系统信息"); builder.setCancelable(false); builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); closeProgress(); } }); AlertDialog dialog = builder.create(); dialog.show(); return ; } for(int i=0;i<jsonArray.length();i++){ JSONObject json = jsonArray.getJSONObject(i); if(json.getString("latitude").length()==0||json.getString("longitude").length()==0) continue; latLng = new LatLng(json.getDouble("latitude"), json.getDouble("longitude")); if(i==0){ aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng)); aMap.moveCamera(CameraUpdateFactory.zoomTo(20)); } if(json.getString("type").equals("1")){ Marker marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f).position(latLng) .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(CurrentMapActivity.this.getResources(), R.drawable.tree))) .title(json.getString("id"))//图片防伪id .snippet(json.getString("id")) .draggable(false)); marker.setObject(json); treeMarkerList.add(marker); treeList.add(latLng); if(treeList.size()>=2){ Polyline polyline =aMap.addPolyline(new PolylineOptions() .add(treeList.get(treeList.size()-1),treeList.get(treeList.size()-2)) .width(8).color(Color.argb(180, 15, 99, 171))); } }else{ Marker marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f).position(latLng) .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(CurrentMapActivity.this.getResources(), R.drawable.person1))) .title(json.getString("personId")) .snippet(json.getString("id")) .draggable(false)); marker.setObject(json); deviceMarkerList.add(marker); } } Polyline polyline =aMap.addPolyline(new PolylineOptions() .add(treeList.get(treeList.size()-1),treeList.get(0)) .width(8).color(Color.argb(180, 15, 99, 171))); aMap.setOnPolylineClickListener(new AMap.OnPolylineClickListener() { @Override public void onPolylineClick(Polyline polyline) { List<LatLng> list = polyline.getPoints(); lengthText.setPosition(new LatLng((list.get(0).latitude + list.get(1).latitude)/2, (list.get(0).longitude + list.get(1).longitude)/2)); lengthText.setText("边界:"+AMapUtils.calculateLineDistance(list.get(0),list.get(1))+"米"); lengthText.setVisible(true); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // 执行的操作 lengthText.setVisible(false); } }, 5000);//5秒后执行Runnable中的run方法 } }); initAlarm(); }catch (Exception e){ Msg.showInfo(CurrentMapActivity.this, "获取当前作业设备列表时出错!"); } } } else { Msg.showInfo(CurrentMapActivity.this, "获取当前作业设备列表时出错!"); } closeProgress(); } else if (msg.what == HandlerStatus.HANDLE_ALARMLIST) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { if (msg.obj != null) { try { JSONArray jsonArray = (JSONArray) msg.obj; if (jsonArray.length()== 0) { Msg.showInfo(CurrentMapActivity.this, "当前无报警"); closeProgress(); return; } for(int j=0;j<jsonArray.length();j++){ JSONObject json = jsonArray.getJSONObject(j); String typeId = json.getString("alarmType"); // String alarmtype ="",alarmvalue=""; if(typeId.equals("1")){ for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ treeMarkerList.get(i).setIcon( BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource( CurrentMapActivity.this.getResources(), R.drawable.tree_alarm))); break; } } } else if(typeId.equals("2")){ List<LatLng> list = new ArrayList<>(); for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ if(i==0){ list.add(treeMarkerList.get(0).getPosition()); list.add(treeMarkerList.get(treeMarkerList.size()-1).getPosition()); }else{ list.add(treeMarkerList.get(i).getPosition()); list.add(treeMarkerList.get(i-1).getPosition()); } break; } } Polyline polyline =aMap.addPolyline(new PolylineOptions() .add(list.get(0),list.get(1)) .width(8).color(Color.argb(180, 255, 0, 0))); Marker marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f) .position(new LatLng((list.get(0).longitude+list.get(1).longitude)/2, (list.get(0).latitude+list.get(1).latitude)/2)) .rotateAngle((float) (180+Math.atan2((list.get(0).longitude-list.get(1).longitude), (list.get(0).latitude-list.get(1).latitude))/0.017453292)) .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(CurrentMapActivity.this.getResources(), R.drawable.inalarm))) .draggable(false)); marker.setObject(json.getString("devcode")); enterList.add(marker); } else if(typeId.equals("3")){ for(int i=0;i<treeMarkerList.size();i++) { JSONObject markerJson = (JSONObject) treeMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ Marker marker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f) .position(treeMarkerList.get(i).getPosition()) .icon(BitmapDescriptorFactory.fromBitmap( BitmapFactory.decodeResource(CurrentMapActivity.this.getResources(), R.drawable.nearalarm))) .title(json.getString("id"))//图片防伪id .snippet(json.getString("id")) .draggable(false)); marker.setObject(json); nearList.add(marker); break; } } } else if(typeId.equals("4")||typeId.equals("5")||typeId.equals("6")||typeId.equals("7")){ for(int i=0;i<deviceMarkerList.size();i++) { JSONObject markerJson = (JSONObject) deviceMarkerList.get(i).getObject(); if(json.getString("devcode").equals(markerJson.getString("devcode"))){ deviceMarkerList.get(i).setIcon( BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource( CurrentMapActivity.this.getResources(), R.drawable.person1_alarm))); break; } } } } }catch (Exception e){ Msg.showInfo(CurrentMapActivity.this, "查询当前报警出错!"); } } } else { Msg.showInfo(CurrentMapActivity.this, "查询当前报警出错!"); } } } @Override protected void onActivityResult(int requestCode,int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (22 == requestCode && data!=null) { showAlarm(data.getStringExtra("data")); } } public void initAlarm(){ thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.HANDLE_ALARMLIST; try { ApiClent.alarmList(id,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()); JSONArray jsonArray = jsonObject.getJSONArray("data"); msg.arg1 = HandlerStatus.HANDLE_OK; msg.obj = jsonArray; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(String message) { msg.arg1 = HandlerStatus.HANDLE_FAIL; } @Override public void onError(Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } }); } catch (Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; e.printStackTrace(); } thread.sendMessage(msg); } } }; // showProgress("当前报警列表查询中。。。", "报警列表"); thread.start(); } @Override public View getInfoContents(Marker arg0) { // TODO Auto-generated method stub return null; } @Override public void onMapClick(LatLng latLng) { if (currentMarker != null) { currentMarker.hideInfoWindow();// 隐藏InfoWindow框 } } @Override public View getInfoWindow(Marker marker) { // TODO Auto-generated method stub currentMarker = marker; JSONObject markerJson = (JSONObject)marker.getObject(); try { if(markerJson.getString("typeName").equals("安全树")){ final View infoWindow = getLayoutInflater().inflate(R.layout.tree_window, null); TextView name = (TextView) infoWindow.findViewById(R.id.name); name.setText(markerJson.getString("name")); TextView latitude = (TextView) infoWindow.findViewById(R.id.latitude); latitude.setText(markerJson.getString("latitude")); TextView longitude = (TextView) infoWindow.findViewById(R.id.longitude); longitude.setText(markerJson.getString("longitude")); ApiClent.deviceInfo(marker.getTitle(),new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject1 = new JSONObject(data.toString()); JSONObject jsonObject = jsonObject1.getJSONObject("data"); TextView ch4 = (TextView) infoWindow.findViewById(R.id.ch4); ch4.setText(jsonObject.getString("gas")); TextView cell = (TextView) infoWindow.findViewById(R.id.battery); cell.setText(jsonObject.getString("cell")); final JSONArray jsonArray = jsonObject.getJSONArray("alarmList"); LinearLayout wr_areas=(LinearLayout) infoWindow.findViewById(R.id.wr_areas); for(int i=0;i<jsonArray.length();i++) { JSONObject json = jsonArray.getJSONObject(i); LinearLayout llWashingRoomItem = new LinearLayout(infoWindow.getContext()); llWashingRoomItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); llWashingRoomItem = (LinearLayout) getLayoutInflater().inflate(R.layout.table_view7, null); TextView name = (TextView) llWashingRoomItem.findViewById(R.id.name); name.setText(json.getString("alarmContent")); Button delete = (Button) llWashingRoomItem.findViewById(R.id.delete); delete.setTag(clicknum+i); delete.setClickable(true); delete.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { int i = (Integer) v.getTag(); //这里的i不能在外部定义,因为内部类的关系,内部类好多繁琐的东西,要好好研究一番 try { deleteAlarm(jsonArray.getJSONObject(i-clicknum).getString("id").toString()); }catch (JSONException e){ e.printStackTrace(); } } }); wr_areas.addView(llWashingRoomItem); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(String message) { } @Override public void onError(Exception e) { } }); return infoWindow; }else{ final View infoWindow = getLayoutInflater().inflate(R.layout.person_window, null); ApiClent.personInfo(marker.getTitle(),new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()); JSONObject json = jsonObject.getJSONObject("data"); TextView name = (TextView) infoWindow.findViewById(R.id.name); name.setText(json.getString("name")); TextView o2value = (TextView) infoWindow.findViewById(R.id.o2); o2value.setText(json.getString("o2value")); if(json.getString("o2value").length()>0&&Float.parseFloat(json.getString("o2value"))<=15) o2value.setTextColor(Color.argb(255, 255, 0, 0)); else o2value.setTextColor(Color.argb(255, 0, 0, 0)); TextView h2Svalue = (TextView) infoWindow.findViewById(R.id.h2s); h2Svalue.setText(json.getString("h2Svalue")); if(json.getString("h2Svalue").length()>0&&Float.parseFloat(json.getString("h2Svalue"))>=10) h2Svalue.setTextColor(Color.argb(255, 255, 0, 0)); else h2Svalue.setTextColor(Color.argb(255, 0, 0, 0)); TextView heartbeat = (TextView) infoWindow.findViewById(R.id.heartbeat); heartbeat.setText(json.getString("heartbeat")); if(json.getString("heartbeat").length()>0&&Float.parseFloat(json.getString("heartbeat"))<=50) heartbeat.setTextColor(Color.argb(255, 255, 0, 0)); else heartbeat.setTextColor(Color.argb(255, 0, 0, 0)); TextView spo = (TextView) infoWindow.findViewById(R.id.spo); spo.setText(json.getString("spo")); if(json.getString("spo").length()>0&&Float.parseFloat(json.getString("spo"))<=90) spo.setTextColor(Color.argb(255, 255, 0, 0)); else spo.setTextColor(Color.argb(255, 0, 0, 0)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFailure(String message) { } @Override public void onError(Exception e) { } }); return infoWindow; } }catch (Exception e){ } return null; } public void deleteAlarm(String id){ final String alarmId = id; Msg.confirm(CurrentMapActivity.this, "确认消除该报警吗?", "消警", new MsgCallback() { @Override public void callBack(Boolean result) { if (result != null && result.booleanValue()) { try { ApiClent.deleteAlarm(alarmId,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { currentMarker.hideInfoWindow(); currentMarker.showInfoWindow(); } @Override public void onFailure(String message) { Msg.showInfo(CurrentMapActivity.this, "消警失败!"); } @Override public void onError(Exception e) { Msg.showInfo(CurrentMapActivity.this, "消警异常!"); } }); }catch (Exception e){ e.printStackTrace(); } } } }); } private View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View arg0) { if (arg0 == back) { closeConnect(); finish(); } else if(arg0 == person_list) { Intent intent = new Intent(CurrentMapActivity.this, PersonListActivity.class); Bundle bundle=new Bundle(); bundle.putString("id",id); intent.putExtras(bundle); startActivity(intent); } else if(arg0 == ch4) { Intent intent = new Intent(CurrentMapActivity.this, CH4ListActivity.class); Bundle bundle=new Bundle(); bundle.putString("id",id); intent.putExtras(bundle); startActivity(intent); } else if(arg0 == battery) { Intent intent = new Intent(CurrentMapActivity.this, BatteryListActivity.class); Bundle bundle=new Bundle(); bundle.putString("id",id); intent.putExtras(bundle); startActivity(intent); } else if(arg0 == alarm_list) { Intent intent = new Intent(CurrentMapActivity.this, AlarmListActivity.class); Bundle bundle=new Bundle(); bundle.putString("id",id); intent.putExtras(bundle); startActivityForResult(intent,22); } else if(arg0 == person_manager) { Intent intent = new Intent(CurrentMapActivity.this, PersonManagerActivity.class); Bundle bundle=new Bundle(); bundle.putString("id",id); intent.putExtras(bundle); startActivity(intent); } else if(arg0 == device_manager) { Intent intent = new Intent(CurrentMapActivity.this, DeviceManagerActivity.class); Bundle bundle=new Bundle(); bundle.putString("id",id); intent.putExtras(bundle); startActivity(intent); } else if(arg0 == do_job) { DoJob(); } } }; public void DoJob(){ if(do_job.getText().toString().equals("开始作业")){ Msg.confirm(CurrentMapActivity.this, "确认开始该作业吗?", "开始作业", new MsgCallback() { @Override public void callBack(Boolean result) { if (result != null && result.booleanValue()) { try { ApiClent.startJob(id,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { do_job.setText("结束作业"); do_job.setBackgroundColor(Color.argb(255,255,0,0)); } @Override public void onFailure(String message) { Msg.showInfo(CurrentMapActivity.this, "开始作业失败!"); } @Override public void onError(Exception e) { Msg.showInfo(CurrentMapActivity.this, "开始作业异常!"); } }); }catch (Exception e){ e.printStackTrace(); } } } }); } else if(do_job.getText().toString().equals("结束作业")){ Msg.confirm(CurrentMapActivity.this, "确认结束该作业吗?", "结束作业", new MsgCallback() { @Override public void callBack(Boolean result) { if (result != null && result.booleanValue()) { try { ApiClent.endJob(id,new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { Intent intent = new Intent(CurrentMapActivity.this,HistoryJobActivity.class); ButtomBar.status = 2; for (Activity activity : activedActivity) { if (activity != CurrentMapActivity.this) { activity.finish(); } } activedActivity.clear(); startActivity(intent); finish(); } @Override public void onFailure(String message) { Msg.showInfo(CurrentMapActivity.this, "结束作业失败!"); } @Override public void onError(Exception e) { Msg.showInfo(CurrentMapActivity.this, "结束作业异常!"); } }); }catch (Exception e){ e.printStackTrace(); } } } }); } } @Override protected void onCancelProgress(DialogInterface arg0) { // if (thread != null) // { // thread.interrupt(); // } CurrentMapActivity.this.finish(); } }