Newer
Older
dxcgt / app / src / main / java / com / smartdot / cgt / activity / FrmProblemSupervisePr.java
wangxitong on 6 Apr 2021 5 KB first commit
package com.smartdot.cgt.activity;

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.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.TitleBar;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class FrmProblemSupervisePr extends BaseActivity
{
	private View view = null;
	private LinearLayout wr_areas;
	private TitleBar titlebar;
	private BaseThread thread;
	private HashMap<String, BaseThread> threadList = new HashMap<String, BaseThread>(5);
	@Override
	protected void setLayout()
	{
		initActivity();
		setContentView(R.layout.problemoverpr);

		titlebar = (TitleBar) this.findViewById(R.id.titlebar);
		titlebar.setTitleText("处理记录");
		view = getLayoutInflater().inflate(R.layout.problemoverpr, null);
		wr_areas=(LinearLayout) findViewById(R.id.wr_areas);
		initlist();
	}
	@Override
	protected void addEventListener()
	{
	}
	@Override
	protected  void onActivityResult(int requestCode, int resultCode, Intent data){
		super.onActivityResult(requestCode,resultCode,data);
	}

	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_LIST){
			if (msg.arg1 == HandlerStatus.HANDLE_OK) {
				JSONArray jsonArray = (JSONArray) msg.obj;
				wr_areas.removeAllViews();
				if (jsonArray.length() == 0)
				{
					Toast.makeText(FrmProblemSupervisePr.this, "当前暂无记录", Toast.LENGTH_SHORT).show();
					return;
				}
				else {
					try{
						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_view2, null);

							TextView txtname = (TextView) llWashingRoomItem.findViewById(R.id.handlename);
							TextView txtperson = (TextView) llWashingRoomItem.findViewById(R.id.handleperson);
							TextView txttime = (TextView) llWashingRoomItem.findViewById(R.id.handletime);
							TextView txtremark = (TextView) llWashingRoomItem.findViewById(R.id.handleremark);
							LinearLayout row3 = (LinearLayout) llWashingRoomItem.findViewById(R.id.row3);
							txtname.setText(json.getString("operationTypeName"));
							txtperson.setText(json.getString("userName"));
							txttime.setText(json.getString("time"));
							txtremark.setText(json.getString("remarks"));

//							//动态设置layout_weight权重设置表格宽度
//							LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
//							txt.setLayoutParams(lp);
							wr_areas.addView(llWashingRoomItem);
							if(i==0 && json.getString("remarks").equals(""))
							{
								row3.setVisibility(View.GONE);
							}
						}

					}catch (JSONException e){
						e.printStackTrace();
					}
				}
			}
			else if (msg.arg1 == HandlerStatus.HANDLE_FAIL)
			{
				Msg.showInfo(FrmProblemSupervisePr.this, "获取处理记录失败!");
			}
			else
			{
				Msg.showInfo(FrmProblemSupervisePr.this, "获取处理记录时出现错误!");
			}
			checkIsNeedCloseProgress();
		}
	}

	public void initlist(){
		thread = new BaseThread(baseHandler)
		{
			@Override
			public void runThread()
			{
				final Message msg = thread.obtainMessage();
				if (msg != null)
				{
					Bundle bundle=getIntent().getExtras();
					String processId = bundle.getString("processId");
					msg.what = HandlerStatus.REQUEST_LIST;
					ApiClent.caseProcess(processId, new ApiClent.ClientCallback() {
						@Override
						public void onSuccess(Object data)
						{
							try {
								JSONObject jsonObject = new JSONObject(data.toString());
								JSONArray jsonarr = jsonObject.getJSONArray("data");
								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()) {
				default:
					break;
			}
		}
	};

	@Override
	protected void onCancelProgress(DialogInterface arg0)
	{
		for (BaseThread thread : threadList.values())
		{
			if (thread != null)
			{
				thread.interrupt();
			}
		}
		threadList.clear();
	}
}