package com.smartdot.cgt.activity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.os.Message; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.smartdot.cgt.R; import com.smartdot.cgt.request.ApiClent; import com.smartdot.cgt.util.BaseThread; import com.smartdot.cgt.util.HandlerStatus; import com.smartdot.cgt.util.Msg; import com.smartdot.cgt.view.CustomScrollView; import com.smartdot.cgt.view.TitleBar; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class FrmProblemReCheck extends BaseActivity { private View view = null; private LinearLayout wr_areas; Button btn_todo,btn_finish; public int patrolclick = 770000; private TitleBar titlebar; private BaseThread thread; private HashMap<String, BaseThread> threadList = new HashMap<String, BaseThread>(5); String requeststr; private int pagenum=1; private CustomScrollView scrollView; List<String> listid = new ArrayList<>(); @Override protected void setLayout() { initActivity(); setContentView(R.layout.problemlist); titlebar = (TitleBar) this.findViewById(R.id.titlebar); titlebar.setTitleText(R.string.module_problemrecheck); view = getLayoutInflater().inflate(R.layout.problemlist, null); wr_areas=(LinearLayout) findViewById(R.id.wr_areas); btn_finish = (Button) findViewById(R.id.btn_finish); btn_todo = (Button)findViewById(R.id.btn_todo); scrollView = (CustomScrollView) findViewById(R.id.scrollView1); } @Override protected void addEventListener() { btn_finish.setOnClickListener(btnOnClick); btn_todo.setOnClickListener(btnOnClick); scrollView.setOnScrollChangeListener(new CustomScrollView.OnScrollChangeListener() { @Override public void onScrollToStart() { } @Override public void onScrollToEnd() { showlist(requeststr); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode,resultCode,data); if (requestCode==0x006&&resultCode==0x007){ try { Thread.currentThread().sleep(500); pagenum = 1; wr_areas.removeAllViews(); listid.clear(); showlist("/case/toCheckListPage"); }catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 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; } @Override protected void doInit() { btn_todo.setBackgroundColor(Color.parseColor("#FFFFFF")); requeststr ="/case/toCheckListPage"; showlist("/case/toCheckListPage"); } @SuppressWarnings("unchecked") @Override protected void handleMessage(Message msg) { if(msg.what ==HandlerStatus.REQUEST_LIST){ if (msg.arg1 == HandlerStatus.HANDLE_OK) { JSONArray jsonArray = (JSONArray) msg.obj; if (jsonArray.length() == 0 && pagenum == 1) { Toast.makeText(FrmProblemReCheck.this, "当前暂无记录", Toast.LENGTH_SHORT).show(); }else if(jsonArray.length() == 0 && pagenum > 1){ Toast.makeText(FrmProblemReCheck.this, "到底了", Toast.LENGTH_SHORT).show(); } else { try{ for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); listid.add(json.getString("id")); LinearLayout llWashingRoomItem = new LinearLayout(view.getContext()); llWashingRoomItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); llWashingRoomItem = (LinearLayout) getLayoutInflater().inflate(R.layout.table_view3, null); TextView txt = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_txt); String txtstr = json.getString("description"); //案卷描述 if(json.getString("description").length()>15){ txtstr = json.getString("description").substring(0,15); //案卷描述 txtstr+="..."; } if(json.getString("fieldintro").length()>10){ txtstr += "\n"+"发生地点:"+json.getString("fieldintro").substring(0,10); txtstr+="..."; }else { txtstr += "\n"+"发生地点:"+json.getString("fieldintro"); } txtstr += "\n"+"上报时间:"+json.getString("reportTime"); txt.setText(txtstr); ImageView imageView = (ImageView) llWashingRoomItem.findViewById(R.id.layout_pic); if(json.getString("eorc").equals("1")){//事件 imageView.setBackgroundResource(R.drawable.icon_task); }else if(json.getString("eorc").equals("2")){//部件 imageView.setBackgroundResource(R.drawable.icon_task1); }else if(json.getInt("source") == 12){//微信 imageView.setBackgroundResource(R.drawable.icon_task2); }else if(json.getInt("source") == 11){//热线 imageView.setBackgroundResource(R.drawable.icon_task4); } //动态设置layout_weight权重设置表格宽度 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); txt.setLayoutParams(lp); if(requeststr.equals("/case/toCheckListPage")){ llWashingRoomItem.setTag(patrolclick + (pagenum-1)*20 + i); llWashingRoomItem.setClickable(true); llWashingRoomItem.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { int i = (Integer) v.getTag(); Intent intent = new Intent(); intent.setClass(FrmProblemReCheck.this, FrmProblemReCheckDetail.class); Bundle bundle = new Bundle(); // try { // Long id = Long.parseLong(jsonArray.getJSONObject(i-patrolclick).getString("id")); // bundle.putLong("id", id); // }catch (JSONException e){ // e.printStackTrace(); // } Long id = Long.parseLong(listid.get(i-patrolclick)); bundle.putLong("id", id); intent.putExtras(bundle); startActivityForResult(intent,0x006); } }); }else{ llWashingRoomItem.setTag(patrolclick + (pagenum-1)*20 + i); llWashingRoomItem.setClickable(true); llWashingRoomItem.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { int i = (Integer) v.getTag(); Intent intent = new Intent(); intent.setClass(FrmProblemReCheck.this, FrmProblemRecheckFinish.class); Bundle bundle = new Bundle(); // try { // Long id = Long.parseLong(jsonArray.getJSONObject(i-patrolclick).getString("id")); // bundle.putLong("id", id); // }catch (JSONException e){ // e.printStackTrace(); // } Long id = Long.parseLong(listid.get(i-patrolclick)); bundle.putLong("id", id); intent.putExtras(bundle); startActivity(intent); } }); } wr_areas.addView(llWashingRoomItem); } pagenum++; }catch (JSONException e){ e.printStackTrace(); } } } else if (msg.arg1 == HandlerStatus.HANDLE_FAIL) { Msg.showInfo(FrmProblemReCheck.this, "获取案卷列表失败!"); } else { Msg.showInfo(FrmProblemReCheck.this, "获取案卷列表时出现错误!"); } btn_finish.setClickable(true); btn_todo.setClickable(true); checkIsNeedCloseProgress(); } } public void showlist(final String url){ thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.REQUEST_LIST; ApiClent.caseListPage(url,20,pagenum, new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()); JSONArray jsonarr = jsonObject.getJSONObject("data").getJSONArray("rows"); msg.obj = jsonarr; 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 View.OnClickListener btnOnClick = new View.OnClickListener() { @Override public void onClick(View v){ switch (v.getId()) { case R.id.btn_finish: btn_finish.setClickable(false); btn_todo.setClickable(false); btn_finish.setBackgroundColor(Color.parseColor("#FFFFFF")); btn_todo.setBackgroundColor(Color.parseColor("#C0C0C0")); requeststr = "/case/checkedListPage"; pagenum = 1; wr_areas.removeAllViews(); listid.clear(); showlist("/case/checkedListPage"); break; case R.id.btn_todo: btn_finish.setClickable(false); btn_todo.setClickable(false); btn_todo.setBackgroundColor(Color.parseColor("#FFFFFF")); btn_finish.setBackgroundColor(Color.parseColor("#C0C0C0")); requeststr ="/case/toCheckListPage"; pagenum = 1; wr_areas.removeAllViews(); listid.clear(); showlist("/case/toCheckListPage"); break; default: break; } } }; @Override protected void onCancelProgress(DialogInterface arg0) { for (BaseThread thread : threadList.values()) { if (thread != null) { thread.interrupt(); } } threadList.clear(); } }