package com.smartdot.cgt.activity; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.location.Location; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Message; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; import com.esri.core.geometry.Point; import com.esri.core.map.FeatureSet; import com.esri.core.tasks.SpatialRelationship; import com.smartdot.cgt.R; import com.smartdot.cgt.model.ResponseResult; import com.smartdot.cgt.request.ApiClent; import com.smartdot.cgt.request.Request; import com.smartdot.cgt.util.ActivityTools; import com.smartdot.cgt.util.ApplicationMain; import com.smartdot.cgt.util.BaseThread; import com.smartdot.cgt.util.BitmapConvert; import com.smartdot.cgt.util.GpsManager; import com.smartdot.cgt.util.HandlerStatus; import com.smartdot.cgt.util.MapUtil; import com.smartdot.cgt.util.Msg; import com.smartdot.cgt.util.PointD; import com.smartdot.cgt.util.StringUtils; import com.smartdot.cgt.view.ImagesLayout; import com.smartdot.cgt.view.TitleBar; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class FrmProblemHisDetail extends BaseActivity { private TitleBar titlebar; private BaseThread thread; LinearLayout handlehis; private HashMap<String, BaseThread> threadList = new HashMap<String, BaseThread>(5); JSONObject casejson; TextView txtcasenum,txtcasetype,txtcaselclass,txtcasesclass; TextView txtcasestate; TextView txtshequ,txtaddress,txtdetail; private View btnGetPosition; private ImagesLayout imagesLayout1, imagesLayout2, imagesLayout3; private LinearLayout mainLayout1, mainLayout2, mainLayout3; private LinearLayout title0,title1,title2; public String nowstate,processId; public int imgcount=0; private String longitude,latitude; Long id; @Override protected void setLayout() { initActivity(); setContentView(R.layout.problemhisdetail); titlebar = (TitleBar) this.findViewById(R.id.titlebar); titlebar.setTitleText("案卷详情"); txtcasenum = (TextView) findViewById(R.id.casenum); handlehis = (LinearLayout)findViewById(R.id.handlehis_allow_button); txtcasetype = (TextView) findViewById(R.id.casetype); txtcaselclass = (TextView) findViewById(R.id.caselclass); txtcasesclass = (TextView) findViewById(R.id.casesclass); txtshequ = (TextView) findViewById(R.id.spinSq); txtaddress = (TextView) findViewById(R.id.txtAddress); txtdetail = (TextView) findViewById(R.id.txtEventDesc); btnGetPosition = (View) findViewById(R.id.btnGetPosition); txtcasestate = (TextView) findViewById(R.id.casestate); imagesLayout1 = (ImagesLayout) ApplicationMain.getInstance().inflateView(R.layout.imagelayout1); mainLayout1 = (LinearLayout) findViewById(R.id.layout_pic1); mainLayout1.addView(imagesLayout1); imagesLayout2 = (ImagesLayout) ApplicationMain.getInstance().inflateView(R.layout.imagelayout1); mainLayout2 = (LinearLayout) findViewById(R.id.layout_pic2); mainLayout2.addView(imagesLayout2); imagesLayout3 = (ImagesLayout) ApplicationMain.getInstance().inflateView(R.layout.imagelayout1); mainLayout3 = (LinearLayout) findViewById(R.id.layout_pic3); mainLayout3.addView(imagesLayout3); title0 = (LinearLayout) findViewById(R.id.title0); title1 = (LinearLayout) findViewById(R.id.title1); title2 = (LinearLayout) findViewById(R.id.title2); } @Override protected void doInit() { // getPosition(); initview(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { } @Override protected void addEventListener() { btnGetPosition.setOnClickListener(onClickListener); handlehis.setOnClickListener(onClickListener); imagesLayout1.setOnPreviewImage(imagesLayout1.new OnPreviewImage() { @Override public void previewImage(int viewIndex) { Intent intent = new Intent(FrmProblemHisDetail.this, FrmViewImage.class); intent.putExtra(FrmViewImage.BITMAPKEY, imagesLayout1.getSelectedImagesPath()); intent.putExtra(FrmViewImage.FIRSTSHOWINDEX, viewIndex); startActivity(intent); } }); imagesLayout2.setOnPreviewImage(imagesLayout2.new OnPreviewImage() { @Override public void previewImage(int viewIndex) { Intent intent = new Intent(FrmProblemHisDetail.this, FrmViewImage.class); intent.putExtra(FrmViewImage.BITMAPKEY, imagesLayout2.getSelectedImagesPath()); intent.putExtra(FrmViewImage.FIRSTSHOWINDEX, viewIndex); startActivity(intent); } }); imagesLayout3.setOnPreviewImage(imagesLayout3.new OnPreviewImage() { @Override public void previewImage(int viewIndex) { Intent intent = new Intent(FrmProblemHisDetail.this, FrmViewImage.class); intent.putExtra(FrmViewImage.BITMAPKEY, imagesLayout3.getSelectedImagesPath()); intent.putExtra(FrmViewImage.FIRSTSHOWINDEX, viewIndex); startActivity(intent); } }); } private OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View arg0) { if (arg0 == btnGetPosition) { //地图和百度地图切换 int getLocationId = ActivityTools.GETLOCATION_NONE; Intent intent = new Intent(); intent.setClass(FrmProblemHisDetail.this,FrmMap.class); Bundle bundle = new Bundle(); bundle.putString("lng",longitude); bundle.putString("lat",latitude); intent.putExtras(bundle); startActivity(intent); }else if(arg0 == handlehis){ Intent intent = new Intent(); intent.setClass(FrmProblemHisDetail.this,FrmProblemSupervisePr.class); Bundle bundle = new Bundle(); bundle.putString("processId",processId); intent.putExtras(bundle); startActivity(intent); } } }; private boolean checkIsNeedCloseProgress() { boolean canCloseProgress = true; for (BaseThread thread : threadList.values()) { if (thread != null && thread.getIsThreadGoing()) { canCloseProgress = false; } } if (canCloseProgress) { try { closeProgress(); } catch (Exception e) { e.printStackTrace(); } } return canCloseProgress; } @SuppressWarnings("unchecked") @Override protected void handleMessage(Message msg) { if(msg.what == HandlerStatus.REQUEST_PIC0){ if (msg.arg1 == HandlerStatus.HANDLE_OK) { List<Bitmap> bitmaps = (List<Bitmap>) msg.obj; for(int i=0;i<bitmaps.size();i++){ Bitmap bitmap = bitmaps.get(i); imagesLayout1.addSelectedImage(bitmap); } } else if (msg.arg1 == HandlerStatus.HANDLE_FAIL) { Msg.showInfo(FrmProblemHisDetail.this, "案卷图片加载失败!"); } checkIsNeedCloseProgress(); }else if(msg.what == HandlerStatus.REQUEST_PIC1){ if (msg.arg1 == HandlerStatus.HANDLE_OK) { List<Bitmap> bitmaps = (List<Bitmap>) msg.obj; for(int i=0;i<bitmaps.size();i++){ Bitmap bitmap = bitmaps.get(i); imagesLayout2.addSelectedImage(bitmap); } } else if (msg.arg1 == HandlerStatus.HANDLE_FAIL) { Msg.showInfo(FrmProblemHisDetail.this, "处理图片加载失败!"); } checkIsNeedCloseProgress(); }else if(msg.what == HandlerStatus.REQUEST_PIC2){ if (msg.arg1 == HandlerStatus.HANDLE_OK) { List<Bitmap> bitmaps = (List<Bitmap>) msg.obj; for(int i=0;i<bitmaps.size();i++){ Bitmap bitmap = bitmaps.get(i); imagesLayout3.addSelectedImage(bitmap); } } else if (msg.arg1 == HandlerStatus.HANDLE_FAIL) { Msg.showInfo(FrmProblemHisDetail.this, "核查图片加载失败!"); } checkIsNeedCloseProgress(); }else if(msg.what ==HandlerStatus.REQUEST_DETAIL) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { casejson = (JSONObject) msg.obj; try { txtcasenum.setText(casejson.getString("caseid")); txtcasetype.setText(casejson.getString("eorcName")); txtcaselclass.setText(casejson.getString("casetypeName")); txtcasesclass.setText(casejson.getString("casetypeDetailName")); txtcasestate.setText(casejson.getString("caseStateName")); txtshequ.setText(casejson.getString("communityName")); txtaddress.setText(casejson.getString("fieldintro")); txtdetail.setText(casejson.getString("description")); nowstate = casejson.getString("caseState"); processId = casejson.getString("processId"); longitude = casejson.getString("lng"); latitude = casejson.getString("lat"); String fileIdVerify = casejson.getString("fileIdVerify").replace(" ", "").replace("\\", "/"); List<String> list = Arrays.asList(fileIdVerify.split(",")); if (!fileIdVerify.equals("")) { initpic(list,0); } else { mainLayout1.setVisibility(View.GONE); title0.setVisibility(View.GONE); } fileIdVerify = casejson.getString("fileIdProcess").replace(" ", "").replace("\\", "/"); list = Arrays.asList(fileIdVerify.split(",")); if (!fileIdVerify.equals("")) { initpic(list,1); } else { mainLayout2.setVisibility(View.GONE); title1.setVisibility(View.GONE); } fileIdVerify = casejson.getString("fileIdCheck").replace(" ", "").replace("\\", "/"); list = Arrays.asList(fileIdVerify.split(",")); if (!fileIdVerify.equals("")) { initpic(list,2); } else { mainLayout3.setVisibility(View.GONE); title2.setVisibility(View.GONE); } } catch (JSONException e) { e.printStackTrace(); } } else if (msg.arg1 == HandlerStatus.HANDLE_FAIL) { Msg.showInfo(FrmProblemHisDetail.this, "获取案卷详情失败!"); } else { Msg.showInfo(FrmProblemHisDetail.this, "获取案卷详情时出现错误!"); } checkIsNeedCloseProgress(); } } private void initpic(final List<String> list,int num){ final int length = list.size()<3 ? list.size() : 3; final int handlerStatusId = HandlerStatus.REQUEST_PIC0 + num; thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); msg.what = handlerStatusId; if (msg != null) { final List<Bitmap> bitmaps = new ArrayList<Bitmap>(); for(int i=0; i<length; i++) { final int nowIndex = i; try { String urlStr = ApplicationMain.getInstance().getCgtConfig().getRequestUrl()+"/static/"+list.get(nowIndex); URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("token",ApplicationMain.getInstance().getCgtConfig().gettokenStr()); conn.setRequestMethod("GET"); if (conn.getResponseCode() == 200) { InputStream inputStream = conn.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); bitmaps.add(bitmap); } }catch (Exception e){ e.printStackTrace(); msg.arg1 = HandlerStatus.HANDLE_FAIL; } } if(msg.arg1!=HandlerStatus.HANDLE_FAIL){ msg.arg1 = HandlerStatus.HANDLE_OK; msg.obj = bitmaps; } this.sendMessage(msg); } } }; thread.start(); } private void initview(){ thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.REQUEST_DETAIL; Bundle bundle=getIntent().getExtras(); id = bundle.getLong("id"); ApiClent.caseDetail(id, new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()); JSONObject json = jsonObject.getJSONArray("data").getJSONObject(0); msg.obj = json; msg.arg1 = HandlerStatus.HANDLE_OK; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.i("list_error", e.getMessage()); msg.arg1 = HandlerStatus.HANDLE_FAIL; } } @Override public void onFailure(String message) { msg.arg1 = HandlerStatus.HANDLE_FAIL; } @Override public void onError(Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } }); this.sendMessage(msg); } } }; thread.start(); } private OnClickListener btnOnClick = new OnClickListener() { @Override public void onClick(View v){ switch (v.getId()) { default: break; } } }; @Override protected void onCancelProgress(DialogInterface arg0) { for (BaseThread thread : threadList.values()) { if (thread != null) { thread.interrupt(); } } threadList.clear(); } private void finishActivity(boolean canClose) { this.finishActivity(canClose, false); } private void finishActivity(boolean canClose, boolean needCacheAudio) { if (canClose) { FrmProblemHisDetail.this.finish(); } } }