package com.casic.gasoperation; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.casic.gasoperation.config.ApiClent; import com.casic.gasoperation.utils.BaseThread; import com.casic.gasoperation.utils.HandlerStatus; import com.casic.gasoperation.utils.Msg; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class HistoryAlarmActivity extends BaseActivity { private View view = null; private LinearLayout wr_areas; private BaseThread thread; private ImageView back; public String id; private EditText searchText; private ImageView search; public int clicknum = 880000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.history_alarm); view = getLayoutInflater().inflate(R.layout.alarm_list, null); wr_areas=(LinearLayout) findViewById(R.id.wr_areas); back=(ImageView) findViewById(R.id.back); back.setOnClickListener(onClickListener); Bundle bundle=getIntent().getExtras(); id =bundle.getString("id"); search = (ImageView) findViewById(R.id.search); search.setOnClickListener(onClickListener); searchText = (EditText) findViewById(R.id.search_adress); searchText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if(searchText.getText().equals("")){ getAlarmList(); } } }); getAlarmList(); } private View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View arg0) { if (arg0 == search) { getAlarmList(); } if (arg0 == back) { finish(); } } }; public void getAlarmList() { wr_areas.removeAllViews(); thread = new BaseThread(baseHandler) { @Override public void runThread() { final Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.HANDLE_ALARMLIST; try { ApiClent.historyAlarmList(id,searchText.getText().toString(),new ApiClent.ClientCallback() { @Override public void onSuccess(Object data) { try { JSONObject jsonObject = new JSONObject(data.toString()).getJSONObject("data"); JSONArray jsonArray = jsonObject.getJSONArray("rows"); 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 protected void onCancelProgress(DialogInterface arg0) { if (thread != null) { thread.interrupt(); } HistoryAlarmActivity.this.finish(); } @Override protected void handleMessage(Message msg) { if (msg.what == HandlerStatus.HANDLE_ALARMLIST) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { if (msg.obj != null) { try { final JSONArray jsonArray = (JSONArray) msg.obj; if (jsonArray.length()== 0) { Msg.showInfo(HistoryAlarmActivity.this, "未查询到任何项"); closeProgress(); return; } for(int i=0;i<jsonArray.length();i++){ JSONObject json = jsonArray.getJSONObject(i); 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_view0, null); TextView name = (TextView) llWashingRoomItem.findViewById(R.id.name); TextView index = (TextView) llWashingRoomItem.findViewById(R.id.index); TextView starttime = (TextView) llWashingRoomItem.findViewById(R.id.starttime); TextView status = (TextView) llWashingRoomItem.findViewById(R.id.status); index.setText(Integer.toString(i+1)); name.setText(json.getString("alarmContent")); starttime.setText(json.getString("alarmTime")); status.setText(json.getString("alarmPosition")); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); index.setLayoutParams(lp); //动态设置layout_weight权重设置表格宽度 lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); status.setLayoutParams(lp); name.setLayoutParams(lp); starttime.setLayoutParams(lp); llWashingRoomItem.setTag(clicknum+i); llWashingRoomItem.setClickable(true); llWashingRoomItem.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { int i = (Integer) v.getTag(); //这里的i不能在外部定义,因为内部类的关系,内部类好多繁琐的东西,要好好研究一番 Intent intent = new Intent(); intent.setClass(HistoryAlarmActivity.this, HistoryMapActivity.class); Bundle bundle = new Bundle(); try { bundle.putString("data", jsonArray.getJSONObject(i-clicknum).toString()); }catch (JSONException e){ e.printStackTrace(); } intent.putExtras(bundle); startActivityForResult(intent,0x006); } }); wr_areas.addView(llWashingRoomItem); } }catch (Exception e){ Msg.showInfo(HistoryAlarmActivity.this, "获取当前作业报警列表时出错!"); } } } else { Msg.showInfo(HistoryAlarmActivity.this, "获取当前作业报警列表时出错!"); } closeProgress(); } } }