package com.smartdot.cgt.activity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Message; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.smartdot.cgt.R; import com.smartdot.cgt.util.ApplicationMain; import com.smartdot.cgt.view.LinePieView; import com.smartdot.cgt.view.TitleBar; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; /** * Created by W530 on 2019/11/13. */ public class FrmAnalysisDetail extends BaseActivity{ private Button caselist,casepiechart; private JSONArray jsonArray; private View view = null; private LinearLayout wr_areas; /** * 数据源数字数组 */ private int[] numbers; /** * 数据源名称数组 */ private String[] names; @Override protected void setLayout() { initActivity(); setContentView(R.layout.analysisresult); TitleBar titlebar = (TitleBar) this.findViewById(R.id.titlebar); Bundle bundle = this.getIntent().getExtras(); titlebar.setTitleText(bundle.getString("title")); caselist = (Button) findViewById(R.id.btnList); casepiechart = (Button) findViewById(R.id.btnPie); view = getLayoutInflater().inflate(R.layout.analysisresult, null); wr_areas=(LinearLayout) findViewById(R.id.wr_areas); } @Override protected void doInit() { try { Bundle bundle = this.getIntent().getExtras(); String jsonstr = bundle.getString("jsonstr"); jsonArray = new JSONArray(jsonstr); try { if(bundle.getString("title").equals("高发问题")){ int num = 0; names = new String[jsonArray.length()-1]; numbers = new int[jsonArray.length()-1]; for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); if(!json.getString("eorc").equals("合计")){ names[num] = json.getString("caseType"); numbers[num] = Integer.parseInt(json.getString("caseNum")); num++; } } }else if(bundle.getString("title").equals("问题来源")){ List<Integer> listnum = new ArrayList<Integer>(); List<String> listname = new ArrayList<String>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); if(!json.getString("caseNum").equals("0")&& !json.getString("caseSource").equals("--")){ listname.add(json.getString("caseSource")); listnum.add(Integer.parseInt(json.getString("caseNum"))); } } names = listname.toArray(new String[listname.size()]); numbers = new int[listnum.size()]; for(int i=0; i<listnum.size();i++){ numbers[i]=listnum.get(i); } } }catch (Exception e){ e.printStackTrace(); } }catch (Exception e){ e.printStackTrace(); } showlist(); } @Override protected void addEventListener() { caselist.setOnClickListener(btnOnClick); casepiechart.setOnClickListener(btnOnClick); } public void showlist(){ try{ wr_areas.removeAllViews(); LinearLayout llWashingTitleItem = new LinearLayout(view.getContext()); llWashingTitleItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); llWashingTitleItem = (LinearLayout) getLayoutInflater().inflate(R.layout.analysisresult_list, null); TextView txt = (TextView) llWashingTitleItem.findViewById(R.id.titlecontent); Bundle bundle = this.getIntent().getExtras(); final String title = bundle.getString("title"); txt.setText(title); wr_areas.addView(llWashingTitleItem); for (int i = 0; i < names.length; i++) { if(!names[i].equals("null/null")){ 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_view5, null); TextView txt1 = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_1); txt1.setText(i+1+""); TextView txt2 = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_2); txt2.setText(names[i]); TextView txt3 = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_3); txt3.setText(numbers[i]+""); wr_areas.addView(llWashingRoomItem); } } }catch (Exception e){ e.printStackTrace(); } } public void showpie(){ wr_areas.removeAllViews(); LinearLayout llWashingTitleItem = new LinearLayout(view.getContext()); llWashingTitleItem.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); llWashingTitleItem = (LinearLayout) getLayoutInflater().inflate(R.layout.analysisresult_pie, null); // LinePieView linePieView = (LinePieView)llWashingTitleItem.findViewById(R.id.Big_linePieView) ; // try{ // while(numbers==null||names==null){ // Thread.currentThread().sleep(500); // } // }catch (Exception e){ // e.printStackTrace(); // } // linePieView.setData(numbers,names); WebView webView = (WebView)llWashingTitleItem.findViewById(R.id.Big_linePieView); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient()); Bundle bundle = this.getIntent().getExtras(); String title = bundle.getString("title"); String begTime = bundle.getString("begTime"); String endTime = bundle.getString("endTime"); if(title.equals("高发问题")){ webView.loadUrl("file:///android_asset/highEvent.html?begTime=" +begTime+ "&endTime=" + endTime + "&token=" + ApplicationMain.getInstance().getCgtConfig().gettokenStr()); // webView.loadUrl("http://124.42.118.61:8095/app/highEvent.html?begTime=" +begTime+ // "&endTime=" + endTime + // "&token=" + ApplicationMain.getInstance().getCgtConfig().gettokenStr()); }else if(title.equals("问题来源")){ webView.loadUrl("file:///android_asset/source.html?begTime=" +begTime+ "&endTime=" + endTime + "&token=" + ApplicationMain.getInstance().getCgtConfig().gettokenStr()); // webView.loadUrl("http://124.42.118.61:8095/app/source.html?begTime=" +begTime+ // "&endTime=" + endTime + // "&token=" + ApplicationMain.getInstance().getCgtConfig().gettokenStr()); } wr_areas.addView(llWashingTitleItem); } private View.OnClickListener btnOnClick = new View.OnClickListener() { @Override public void onClick(View v){ switch (v.getId()) { case R.id.btnList: showlist(); break; case R.id.btnPie: showpie(); break; default: break; } } }; @Override protected void handleMessage(Message msg) { } @Override protected void onCancelProgress(DialogInterface arg0) { } }