| | |
| | | private List<AxisValue> mAxisXValues = new ArrayList<>(); |
| | | |
| | | private RadioGroup rg_time; |
| | | private TextView tv_starttime,tv_endtime,tv_value,tv_status; |
| | | private ImageView iv_pre,iv_next; |
| | | private int type=2; |
| | | private TextView tv_starttime, tv_endtime, tv_value, tv_status; |
| | | private ImageView iv_pre, iv_next; |
| | | private int type = 2; |
| | | |
| | | @Override |
| | | protected void getBundleExtras(Bundle extras) { |
| | | |
| | |
| | | rg_time.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
| | | @Override |
| | | public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) { |
| | | switch (i){ |
| | | switch (i) { |
| | | case R.id.rb_week: |
| | | type = 0; |
| | | axisX.setName("时间段(按周)"); //表格名称 |
| | | data.setAxisXBottom(axisX); //x 轴在底部 |
| | | chartView.setLineChartData(data); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",TimeUtil.getCurrentDate("yyyy-MM-dd"),-1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),-6)); |
| | | getData(tv_starttime.getText().toString(),tv_endtime.getText().toString()); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", TimeUtil.getCurrentDate("yyyy-MM-dd"), -1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), -6)); |
| | | getData(tv_starttime.getText().toString(), tv_endtime.getText().toString()); |
| | | break; |
| | | case R.id.rb_month: |
| | | type = 1; |
| | | axisX.setName("时间段(按月)"); //表格名称 |
| | | data.setAxisXBottom(axisX); //x 轴在底部 |
| | | chartView.setLineChartData(data); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",TimeUtil.getCurrentDate("yyyy-MM-dd"),-1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),-28)); |
| | | getData(tv_starttime.getText().toString(),tv_endtime.getText().toString()); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", TimeUtil.getCurrentDate("yyyy-MM-dd"), -1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), -28)); |
| | | getData(tv_starttime.getText().toString(), tv_endtime.getText().toString()); |
| | | break; |
| | | case R.id.rb_day: |
| | | type = 2; |
| | | axisX.setName("时间段(按日)"); //表格名称 |
| | | data.setAxisXBottom(axisX); //x 轴在底部 |
| | | chartView.setLineChartData(data); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",TimeUtil.getCurrentDate("yyyy-MM-dd"),0)); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", TimeUtil.getCurrentDate("yyyy-MM-dd"), 0)); |
| | | tv_starttime.setText(tv_endtime.getText().toString()); |
| | | getData(tv_starttime.getText().toString(),tv_endtime.getText().toString()); |
| | | getData(tv_starttime.getText().toString(), tv_endtime.getText().toString()); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",TimeUtil.getCurrentDate("yyyy-MM-dd"),0)); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", TimeUtil.getCurrentDate("yyyy-MM-dd"), 0)); |
| | | tv_starttime.setText(tv_endtime.getText().toString()); |
| | | getData(tv_starttime.getText().toString(),tv_endtime.getText().toString()); |
| | | getData(tv_starttime.getText().toString(), tv_endtime.getText().toString()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | protected void processClick(View view) { |
| | | switch (view.getId()){ |
| | | switch (view.getId()) { |
| | | case R.id.tv_left: |
| | | finish(); |
| | | break; |
| | | case R.id.iv_pre: |
| | | if(type==0){ |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),-1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),-6)); |
| | | }else if(type == 1){ |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),-1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),-28)); |
| | | }else if(type == 2){ |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),-1)); |
| | | if (type == 0) { |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), -1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), -6)); |
| | | } else if (type == 1) { |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), -1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), -28)); |
| | | } else if (type == 2) { |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), -1)); |
| | | tv_starttime.setText(tv_endtime.getText().toString()); |
| | | } |
| | | getData(tv_starttime.getText().toString(),tv_endtime.getText().toString()); |
| | | getData(tv_starttime.getText().toString(), tv_endtime.getText().toString()); |
| | | break; |
| | | case R.id.iv_next: |
| | | if(type==0){ |
| | | if(TimeUtil.getCurrentDate("yyyy-MM-dd").equals(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),1))){ |
| | | if (type == 0) { |
| | | if (TimeUtil.getCurrentDate("yyyy-MM-dd").equals(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), 1))) { |
| | | return; |
| | | } |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),1)); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),6)); |
| | | }else if(type == 1){ |
| | | if(TimeUtil.getCurrentDate("yyyy-MM-dd").equals(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),1))){ |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), 1)); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), 6)); |
| | | } else if (type == 1) { |
| | | if (TimeUtil.getCurrentDate("yyyy-MM-dd").equals(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), 1))) { |
| | | return; |
| | | } |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),1)); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),28)); |
| | | }else if(type == 2){ |
| | | if(TimeUtil.getCurrentDate("yyyy-MM-dd").equals(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),0))){ |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), 1)); |
| | | tv_endtime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), 28)); |
| | | } else if (type == 2) { |
| | | if (TimeUtil.getCurrentDate("yyyy-MM-dd").equals(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), 0))) { |
| | | return; |
| | | } |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd",tv_endtime.getText().toString(),1)); |
| | | tv_starttime.setText(TimeUtil.getAfterDate("yyyy-MM-dd", tv_endtime.getText().toString(), 1)); |
| | | tv_endtime.setText(tv_starttime.getText().toString()); |
| | | } |
| | | getData(tv_starttime.getText().toString(),tv_endtime.getText().toString()); |
| | | getData(tv_starttime.getText().toString(), tv_endtime.getText().toString()); |
| | | break; |
| | | } |
| | | |
| | |
| | | //data.setAxisXTop(axisX); //x 轴在顶部 |
| | | |
| | | // Y轴是根据数据的大小自动设置Y轴上限(在下面我会给出固定Y轴数据个数的解决方案) |
| | | axisY = Axis.generateAxisFromRange((float)0.0,(float)4.0, (float) 0.25); //Y轴 |
| | | axisY = Axis.generateAxisFromRange((float) 0.0, (float) 4.0, (float) 0.25); //Y轴 |
| | | axisY.setAutoGenerated(false); |
| | | AxisValueFormatter yvalue = new SimpleAxisValueFormatter(1); |
| | | axisY.setFormatter(yvalue); |
| | |
| | | public void run() { |
| | | mPointValues.clear(); |
| | | mAxisXValues.clear(); |
| | | for (int i=0;i<dataList.size();i++){ |
| | | if(type == 2){ |
| | | mPointValues.add(new PointValue(i,dataList.get(i).getHour_avg())); |
| | | mAxisXValues.add(new AxisValue(i).setLabel((dataList.get(i).getTime_level()-1)*3+"时")); |
| | | }else{ |
| | | mPointValues.add(new PointValue(i,dataList.get(i).getDay_avg())); |
| | | mAxisXValues.add(new AxisValue(i).setLabel(dataList.get(i).getDate().substring(5,10))); |
| | | for (int i = 0; i < dataList.size(); i++) { |
| | | if (type == 2) { |
| | | mPointValues.add(new PointValue(i, dataList.get(i).getHour_avg())); |
| | | mAxisXValues.add(new AxisValue(i).setLabel((dataList.get(i).getTime_level() - 1) * 3 + "时")); |
| | | } else { |
| | | mPointValues.add(new PointValue(i, dataList.get(i).getDay_avg())); |
| | | mAxisXValues.add(new AxisValue(i).setLabel(dataList.get(i).getDate().substring(5, 10))); |
| | | } |
| | | |
| | | // mAxisXValues.add(new AxisValue(i).setLabel(i+"")); |
| | |
| | | } |
| | | |
| | | private ArrayList<UserData> dataList = new ArrayList<>(); |
| | | private void getData(String startTime,String endTime){ |
| | | HashMap<String,String> params = new HashMap<>(); |
| | | |
| | | private void getData(String startTime, String endTime) { |
| | | HashMap<String, String> params = new HashMap<>(); |
| | | params.put("user_id", MainApp.userId); |
| | | params.put("start_time", startTime); |
| | | params.put("end_time", endTime); |
| | | HttpUtils.doPost(API.GETUSERDATALIST, params, CacheMode.DEFAULT, true, new HttpCallBack() { |
| | | @Override |
| | | public void onSuccess(String res, String msg) { |
| | | if(progressDialog.isShowing()){ |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(res); |
| | | String data = jsonObject.optString("data"); |
| | | ArrayList<UserData> temp = (ArrayList<UserData>) FastJsonTools.getArrayJson(data,UserData.class); |
| | | ArrayList<UserData> temp = (ArrayList<UserData>) FastJsonTools.getArrayJson(data, UserData.class); |
| | | dataList.clear(); |
| | | |
| | | dataList.addAll(resetData(temp)); |
| | | |
| | | //重绘 |
| | | reshowChart(dataList); |
| | | tv_value.setText(NumberUtils.getBigDecimalValue(jsonObject.optDouble("avg"),3)+"uSv"); |
| | | tv_value.setText(NumberUtils.getBigDecimalValue(jsonObject.optDouble("avg"), 3) + "uSv"); |
| | | tv_status.setText(jsonObject.optString("status")); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | |
| | | |
| | | @Override |
| | | public void onFail(int errno, String s) { |
| | | if(progressDialog.isShowing()){ |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | dataList.clear(); |
| | |
| | | } |
| | | |
| | | |
| | | private ArrayList<UserData> resetData(ArrayList<UserData> tempList){ |
| | | private ArrayList<UserData> resetData(ArrayList<UserData> tempList) { |
| | | ArrayList<UserData> newList = new ArrayList<>(); |
| | | if(type == 0){//周 |
| | | for (int i=0;i<7;i++){ |
| | | if (type == 0) {//周 |
| | | for (int i = 0; i < 7; i++) { |
| | | UserData data = new UserData(); |
| | | data.setDate(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),i)); |
| | | data.setDate(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), i)); |
| | | data.setDay_avg(0); |
| | | newList.add(data); |
| | | } |
| | | }else if(type == 1){//月 |
| | | for (int i=0;i<7;i++){ |
| | | } else if (type == 1) {//月 |
| | | for (int i = 0; i < 7; i++) { |
| | | UserData data = new UserData(); |
| | | data.setDate(TimeUtil.getAfterDate("yyyy-MM-dd",tv_starttime.getText().toString(),i*4)); |
| | | data.setDate(TimeUtil.getAfterDate("yyyy-MM-dd", tv_starttime.getText().toString(), i * 4)); |
| | | data.setDay_avg(0); |
| | | newList.add(data); |
| | | } |
| | | }else if(type == 2){//日 |
| | | for (int i=0;i<8;i++){ |
| | | } else if (type == 2) {//日 |
| | | for (int i = 0; i < 8; i++) { |
| | | UserData data = new UserData(); |
| | | data.setTime_level(i+1); |
| | | data.setTime_level(i + 1); |
| | | data.setHour_avg(0); |
| | | newList.add(data); |
| | | } |
| | | } |
| | | //重构数据 |
| | | float totalValues = 0; |
| | | if(tempList!=null&&tempList.size()>0){ |
| | | for (UserData data : tempList){ |
| | | totalValues+= data.getDay_avg(); |
| | | for(UserData data1 : newList){ |
| | | if(type == 2){ |
| | | if(data.getTime_level() == data1.getTime_level()){ |
| | | if (tempList != null && tempList.size() > 0) { |
| | | for (UserData data : tempList) { |
| | | totalValues += data.getDay_avg(); |
| | | for (UserData data1 : newList) { |
| | | if (type == 2) { |
| | | if (data.getTime_level() == data1.getTime_level()) { |
| | | data1.setHour_avg(data.getHour_avg()); |
| | | } |
| | | }else{ |
| | | if(data.getDate().equals(data1.getDate())){ |
| | | } else { |
| | | if (data.getDate().equals(data1.getDate())) { |
| | | data1.setDay_avg(data.getDay_avg()); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | // tv_value.setText(totalValues/tempList.size()+"uSv"); |
| | | }else{ |
| | | } else { |
| | | // tv_value.setText(0+"uSv"); |
| | | } |
| | | return newList; |
| | |
| | | |
| | | private AlertDialog adDialog; |
| | | private View adView; |
| | | private TextView tv_content,tv_name; |
| | | private TextView tv_content, tv_name; |
| | | private ImageView iv_logo; |
| | | private Button bt_cancel,bt_ok; |
| | | private void showAd(String content,String logo,String name){ |
| | | adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout,null); |
| | | private Button bt_cancel, bt_ok; |
| | | |
| | | private void showAd(String content, String logo, String name) { |
| | | adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout, null); |
| | | tv_content = (TextView) adView.findViewById(R.id.tv_content); |
| | | tv_name = (TextView) adView.findViewById(R.id.tv_name); |
| | | bt_cancel = (Button) adView.findViewById(R.id.bt_cancel); |
| | |
| | | iv_logo = (ImageView) adView.findViewById(R.id.iv_logo); |
| | | tv_content.setText(content); |
| | | tv_name.setText(name); |
| | | ImageLoader.setCircleImageView(this,logo,iv_logo,R.mipmap.circle); |
| | | ImageLoader.setCircleImageView(this, logo, iv_logo, R.mipmap.circle); |
| | | bt_cancel.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | |
| | | } |
| | | }); |
| | | adDialog = new AlertDialog.Builder(this).setView(adView).create(); |
| | | Window window=adDialog.getWindow(); |
| | | Window window = adDialog.getWindow(); |
| | | window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| | | adDialog.show(); |
| | | } |
| | | |
| | | |
| | | private void getAd(){ |
| | | private void getAd() { |
| | | HttpUtils.doPost(API.GETAD, null, CacheMode.DEFAULT, false, new HttpCallBack() { |
| | | @Override |
| | | public void onSuccess(String res, String msg) { |
| | | if(TextUtils.isEmpty(res)){ |
| | | if (TextUtils.isEmpty(res)) { |
| | | return; |
| | | } |
| | | try { |
| | | JSONObject json = new JSONObject(res); |
| | | showAd(json.optString("content"),json.optString("logo"),json.optString("name")); |
| | | showAd(json.optString("content"), json.optString("logo"), json.optString("name")); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |