package cn.flightfeather.thirdapp.dataanalysis;
|
|
|
import android.app.DatePickerDialog;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.graphics.Color;
|
import android.icu.text.DecimalFormat;
|
import android.icu.util.Calendar;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.support.annotation.Nullable;
|
import android.support.annotation.RequiresApi;
|
import android.support.design.widget.FloatingActionButton;
|
import android.support.v4.app.Fragment;
|
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.RecyclerView;
|
import android.util.Log;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.AdapterView;
|
import android.widget.DatePicker;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.Spinner;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.github.mikephil.charting.animation.Easing;
|
import com.github.mikephil.charting.charts.PieChart;
|
import com.github.mikephil.charting.components.Legend;
|
import com.github.mikephil.charting.data.PieData;
|
import com.github.mikephil.charting.data.PieDataSet;
|
import com.github.mikephil.charting.data.PieEntry;
|
import com.github.mikephil.charting.formatter.PercentFormatter;
|
import com.github.mikephil.charting.utils.ColorTemplate;
|
import com.ping.greendao.gen.CityDao;
|
import com.ping.greendao.gen.DistrictDao;
|
import com.ping.greendao.gen.DomainitemDao;
|
import com.ping.greendao.gen.ProvinceDao;
|
import com.ping.greendao.gen.TownDao;
|
|
import org.greenrobot.greendao.query.QueryBuilder;
|
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Objects;
|
|
import cn.flightfeather.thirdapp.CommonApplication;
|
import cn.flightfeather.thirdapp.R;
|
import cn.flightfeather.thirdapp.adapter.AllListViewAdapter;
|
import cn.flightfeather.thirdapp.adapter.AllRecyclerViewAdapter;
|
import cn.flightfeather.thirdapp.bean.entity.City;
|
import cn.flightfeather.thirdapp.bean.entity.District;
|
import cn.flightfeather.thirdapp.bean.entity.Domainitem;
|
import cn.flightfeather.thirdapp.bean.entity.Province;
|
import cn.flightfeather.thirdapp.bean.entity.Town;
|
import cn.flightfeather.thirdapp.bean.vo.AreaVo;
|
import cn.flightfeather.thirdapp.bean.vo.ProblemlistVo;
|
import cn.flightfeather.thirdapp.httpservice.ProblemListService;
|
import cn.flightfeather.thirdapp.util.CommonUtils;
|
import cn.flightfeather.thirdapp.util.Constant;
|
import cn.flightfeather.thirdapp.util.DateFormatter;
|
import cn.flightfeather.thirdapp.util.DialogUtil;
|
import cn.flightfeather.thirdapp.util.Domain;
|
import cn.flightfeather.thirdapp.util.ScreenUtils;
|
import cn.flightfeather.thirdapp.view.ScrollTextView;
|
import retrofit2.Call;
|
import retrofit2.Callback;
|
import retrofit2.Response;
|
|
/**
|
* A simple {@link Fragment} subclass.
|
*/
|
public class AnysisProblemFragment extends Fragment implements View.OnClickListener, AdapterView.OnItemSelectedListener {
|
|
private CommonApplication application;
|
private Context context;
|
private ProblemListService problemListService;
|
|
private final static String ALLDISTRICT = "全部区县";
|
private final static String ALLTOWN = "全部街道";
|
private int TIME_TYPE;//0:快速选择/1:任意时段
|
private String BRIEF_TIME = "本月";//初始默认选择本月
|
private final static int MAX_CHART_COUNT = 5; //饼图最多显示区块数
|
private final static String REMAIN_PROBLEM = "其余";
|
|
private List<ProblemlistVo> problemlists;
|
private PieChart mChart;
|
private ArrayList<PieEntry> entries = new ArrayList<>();//饼图数据
|
|
//下拉框数据
|
private List<Province> allProvinceData = null;//所有省份
|
private List<Province> provinceData = new ArrayList<>();//省份
|
|
private List<City> allCityData = new ArrayList<>();//所有城市
|
private List<City> cityData = new ArrayList<>();//城市
|
|
private List<District> allDistrictData = new ArrayList<>();//所有区县
|
private List<District> districtData = new ArrayList<>();//区县
|
|
private List<Town> allTownData = new ArrayList<>();//所有街镇
|
private List<Town> townData = new ArrayList<>();//街镇
|
|
private List<Domainitem> scenseTypeData = new ArrayList<>();//场景类型
|
private List<String> dateData = new ArrayList<>();//时间
|
//下拉框数据适配器
|
private AllListViewAdapter<Province> provinceAdapter= null;
|
private AllListViewAdapter<City> cityAdapter= null;
|
private AllListViewAdapter<District> districtAdapter= null;
|
private AllListViewAdapter<Town> townAdapter= null;
|
private AllListViewAdapter<Domainitem> scenseAdapter= null;
|
// private AllListViewAdapter<String> dateAdapter= null;
|
//RecyclerView时间快速选择列表
|
private AllRecyclerViewAdapter<String> dateAdapter = null;
|
private AllRecyclerViewAdapter<PieEntry> entryAdapter = null;
|
//
|
private RecyclerView RV_quick_choose;//时间快速选择
|
private RecyclerView rv_problem_type;//问题类型统计
|
//
|
private LinearLayout LL_any_time;
|
//
|
private ImageView IV_problem;
|
private ImageView IV_scene_type;
|
//
|
private TextView TV_problem;
|
private TextView TV_area;
|
private TextView tv_Cancel;
|
private TextView tv_Ok;
|
private TextView TV_quick_choose;
|
private TextView TV_any_time;
|
private TextView TV_start_time;
|
private TextView TV_end_time;
|
private TextView TV_date_display1;
|
private ScrollTextView stv_date_display2;
|
//
|
private PieChart PC_problem;
|
//
|
private Spinner SP_scense_type;
|
// private Spinner SP_date;
|
private Spinner SP_province;
|
private Spinner SP_city;
|
private Spinner SP_district;
|
private Spinner SP_town;
|
//
|
private FloatingActionButton FAB_menu;
|
//
|
private Dialog dialog;
|
|
|
public AnysisProblemFragment() {
|
// Required empty public constructor
|
}
|
|
|
@Override
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
Bundle savedInstanceState) {
|
return inflater.inflate(R.layout.fragment_anysis_problem, container, false);
|
}
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
@Override
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
super.onViewCreated(view, savedInstanceState);
|
|
application = (CommonApplication) getActivity().getApplication();
|
context = getContext();
|
problemListService = application.getRetrofit().create(ProblemListService.class);
|
problemlists = new ArrayList<>();
|
|
initUI(view);
|
initDialog();
|
initPieChart(view);
|
initSpinnerData();
|
initSpinner(view);
|
initRecyclerView(view);
|
}
|
|
@Override
|
public void onHiddenChanged(boolean hidden) {
|
super.onHiddenChanged(hidden);
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
dialog.dismiss();
|
}
|
|
private void initUI(View view) {
|
IV_scene_type = (ImageView) view.findViewById(R.id.IV_scense_type);
|
FAB_menu = (FloatingActionButton) view.findViewById(R.id.FAB_menu);
|
TV_area = (TextView) view.findViewById(R.id.TV_area);
|
stv_date_display2 = (ScrollTextView) view.findViewById(R.id.stv_date_display2);
|
|
FAB_menu.setOnClickListener(this);
|
}
|
|
/**
|
* 初始化下拉框数据(包括popupWindow)
|
*/
|
private void initSpinnerData() {
|
ProvinceDao provinceDao = application.getDaoSession().getProvinceDao();
|
CityDao cityDao = application.getDaoSession().getCityDao();
|
DistrictDao districtDao = application.getDaoSession().getDistrictDao();
|
TownDao townDao = application.getDaoSession().getTownDao();
|
|
DomainitemDao domainitemDao = application.getDaoSession().getDomainitemDao();
|
|
allProvinceData = provinceDao.loadAll();
|
provinceData = provinceDao.loadAll();
|
|
allCityData = cityDao.loadAll();
|
cityData = cityDao.loadAll();
|
|
allDistrictData = districtDao.loadAll();
|
District emptydistrict = new District();
|
emptydistrict.setDistrictname(ALLDISTRICT);
|
districtData.add(emptydistrict);
|
|
allTownData = townDao.loadAll();
|
Town emptytown = new Town();
|
emptytown.setTownname(ALLTOWN);
|
townData.add(emptytown);
|
|
//场景类型
|
QueryBuilder<Domainitem> queryBuilder = domainitemDao.queryBuilder()
|
.where(DomainitemDao.Properties.Dcguid.eq(Domain.DOMAINGUID_SCENSETYPE))
|
.orderAsc(DomainitemDao.Properties.Value);
|
scenseTypeData.addAll(queryBuilder.list());
|
|
dateData.add(Constant.THIS_WEEK);
|
dateData.add(Constant.LAST_WEEK);
|
dateData.add(Constant.THIS_MONTH);
|
dateData.add(Constant.LAST_MONTH);
|
dateData.add(Constant.THIS_SEASON);
|
dateData.add(Constant.LAST_SEASON);
|
dateData.add(Constant.THIS_YEAR);
|
dateData.add(Constant.LAST_YEAR);
|
}
|
|
private void initSpinner(View view) {
|
SP_scense_type = (Spinner) view.findViewById(R.id.SP_scense_type);
|
SP_scense_type.setOnItemSelectedListener(this);
|
// SP_date.setOnItemSelectedListener(this);
|
initAdapter();
|
|
// dialog.dismiss();
|
SP_province.setSelection(0);
|
SP_city.setSelection(0);
|
SP_district.setSelection(0);
|
SP_town.setSelection(0);
|
SP_scense_type.setSelection(0);//会同时通过onClick时间触发setChartTitle(),所以放在最后
|
}
|
|
/**
|
* 问题类型分布的列表
|
* @param view 问题类型分布fragment
|
*/
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
private void initRecyclerView(View view) {
|
final DecimalFormat decimalFormat = new DecimalFormat("#0.00");
|
rv_problem_type = (RecyclerView) view.findViewById(R.id.rv_problem_type);
|
entryAdapter = new AllRecyclerViewAdapter<PieEntry>(entries, R.layout.item_day_task_progress, context) {
|
@Override
|
public void bindView(AllRecyclerViewAdapter.MyViewHolder holder, PieEntry obj, boolean bool, int position) {
|
float total = 0;
|
for (PieEntry entry : entries) {
|
total = total + entry.getValue();
|
}
|
holder.setText(R.id.tv_item1, entries.get(position).getLabel())
|
.setText(R.id.tv_item2, entries.get(position).getValue() + "")
|
.setText(R.id.tv_item3, decimalFormat.format(entries.get(position).getValue()/ total * 100) + "%");
|
}
|
};
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
rv_problem_type.setLayoutManager(layoutManager);
|
rv_problem_type.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
rv_problem_type.setAdapter(entryAdapter);
|
}
|
|
private void initPieChart(View view) {
|
|
//饼图样式设置***************************************************************************************************
|
mChart = (PieChart) view.findViewById(R.id.PC_problem);
|
mChart.setUsePercentValues(true);
|
mChart.getDescription().setEnabled(false);
|
mChart.setExtraOffsets(5, 10, 5, 5);
|
// mChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
|
|
mChart.setDragDecelerationFrictionCoef(0.95f);
|
|
// mChart.setCenterTextTypeface(mTfLight);
|
// mChart.setCenterText(generateCenterSpannableText());
|
|
mChart.setDrawHoleEnabled(true);
|
mChart.setHoleColor(Color.WHITE);
|
|
mChart.setTransparentCircleColor(Color.WHITE);
|
mChart.setTransparentCircleAlpha(110);
|
|
mChart.setHoleRadius(39f);
|
mChart.setTransparentCircleRadius(41f);
|
|
mChart.setDrawCenterText(true);
|
|
mChart.setRotationAngle(0);
|
// enable rotation of the chart by touch
|
mChart.setRotationEnabled(true);
|
mChart.setHighlightPerTapEnabled(true);
|
|
Legend l = mChart.getLegend();
|
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
|
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
|
l.setOrientation(Legend.LegendOrientation.VERTICAL);
|
l.setDrawInside(false);
|
l.setXEntrySpace(7f);
|
l.setYEntrySpace(0f);
|
l.setYOffset(0f);
|
|
// entry label styling
|
mChart.setEntryLabelColor(Color.WHITE);
|
// mChart.setEntryLabelTypeface(mTfRegular);
|
mChart.setEntryLabelTextSize(12f);
|
mChart.setDrawEntryLabels(false);
|
|
//test
|
// setData(new ArrayList<ProblemlistVo>());
|
//
|
|
}
|
|
private void setData(List<ProblemlistVo> problemlists) {
|
//数据初始化***************************************************************************************************
|
entries.clear();
|
|
PieDataSet dataSet = new PieDataSet(entries, "问题类型");
|
|
//test*****
|
// int count = 5;
|
// int mult = 100;
|
// String[] mParties = {"路面积尘", "地面局部未硬化", "站厂出入口无外围护", "无喷淋装置", REMAIN_PROBLEM};
|
// for (int i = 0; i < count; i++) {
|
// entries.add(new PieEntry((int) (Math.random() * mult) + mult / 5, mParties[i]));
|
// }
|
//*********
|
|
//初始化数据
|
HashMap<String, Integer> problemTypeMap = new HashMap<>();
|
while (!problemlists.isEmpty()) {
|
String problemType = problemlists.get(0).getTypename();
|
if (problemType == null) {
|
problemlists.remove(0);
|
continue;
|
}
|
|
int problemCount = 0;
|
for (int i = 0; i < problemlists.size(); i++) {
|
if (Objects.equals(problemType, problemlists.get(i).getTypename())) {
|
problemCount++;
|
problemlists.remove(i);
|
i--;
|
}
|
}
|
problemTypeMap.put(problemType, problemCount);
|
}
|
//按HashMap的value降序排序
|
List<HashMap.Entry<String, Integer>> list = new ArrayList<>(problemTypeMap.entrySet());
|
Collections.sort(list, new Comparator<HashMap.Entry<String, Integer>>() {
|
@Override
|
public int compare(HashMap.Entry<String, Integer> o1, HashMap.Entry<String, Integer> o2) {
|
return o2.getValue().compareTo(o1.getValue());
|
}
|
});
|
// problemTypeMap.clear();
|
// problemTypeMap.entrySet().addAll(list);
|
//初始化Entry,限定最多显示5个扇区,超出的合并为第5个扇区
|
String remainProblemType = "";
|
int remainProblemCount = 0;
|
int chartcount = 0;
|
for (HashMap.Entry<String, Integer> entry : list) {
|
if (chartcount < MAX_CHART_COUNT - 1) {
|
entries.add(new PieEntry((float)entry.getValue(), entry.getKey()));
|
} else {
|
remainProblemCount = remainProblemCount + entry.getValue();
|
remainProblemType = entry.getKey();
|
}
|
chartcount++;
|
}
|
if (chartcount == MAX_CHART_COUNT) {
|
entries.add(new PieEntry((float) remainProblemCount, remainProblemType));
|
} else if (chartcount > MAX_CHART_COUNT) {
|
entries.add(new PieEntry((float) remainProblemCount, REMAIN_PROBLEM));
|
}
|
|
// add a lot of colors
|
ArrayList<Integer> colors = new ArrayList<>();
|
|
for (int c : ColorTemplate.JOYFUL_COLORS)
|
colors.add(c);
|
|
for (int c : ColorTemplate.COLORFUL_COLORS)
|
colors.add(c);
|
|
for (int c : ColorTemplate.VORDIPLOM_COLORS)
|
colors.add(c);
|
|
for (int c : ColorTemplate.LIBERTY_COLORS)
|
colors.add(c);
|
|
for (int c : ColorTemplate.PASTEL_COLORS)
|
colors.add(c);
|
|
colors.add(ColorTemplate.getHoloBlue());
|
|
dataSet.setColors(colors);
|
|
//value line
|
dataSet.setValueLinePart1OffsetPercentage(80.f);
|
dataSet.setValueLinePart1Length(0.2f);
|
dataSet.setValueLinePart2Length(0.4f);
|
//dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
|
//
|
PieData data = new PieData(dataSet);
|
data.setValueFormatter(new PercentFormatter());
|
data.setValueTextSize(11f);
|
data.setValueTextColor(Color.BLACK);
|
// data.setValueTypeface(mTfLight);
|
if (!entries.isEmpty()) {//数据全为空时,不显示
|
mChart.setData(data);
|
} else {
|
mChart.setData(null);
|
}
|
mChart.setNoDataText("暂无数据");
|
|
// undo all highlights
|
mChart.highlightValues(null);
|
|
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
|
}
|
|
/**
|
* 初始化下拉框适配器
|
*/
|
private void initAdapter() {
|
//****下面为设置适配器**********************************************
|
//省份
|
provinceAdapter = new AllListViewAdapter<Province>((ArrayList<Province>)provinceData, R.layout.item_scense_detail_list) {
|
@Override
|
public void bindView(ViewHolder holder, Province obj) {
|
holder.setText(R.id.tv_item, obj.getProvincename());
|
}
|
};
|
SP_province.setAdapter(provinceAdapter);
|
provinceAdapter.notifyDataSetChanged();
|
//城市
|
cityAdapter = new AllListViewAdapter<City>((ArrayList<City>)cityData, R.layout.item_scense_detail_list) {
|
@Override
|
public void bindView(ViewHolder holder, City obj) {
|
holder.setText(R.id.tv_item, obj.getCityname());
|
}
|
};
|
SP_city.setAdapter(cityAdapter);
|
cityAdapter.notifyDataSetChanged();
|
//区县
|
districtAdapter = new AllListViewAdapter<District>((ArrayList<District>)districtData, R.layout.item_scense_detail_list) {
|
@Override
|
public void bindView(ViewHolder holder, District obj) {
|
holder.setText(R.id.tv_item, obj.getDistrictname());
|
}
|
};
|
SP_district.setAdapter(districtAdapter);
|
districtAdapter.notifyDataSetChanged();
|
//街镇
|
townAdapter = new AllListViewAdapter<Town>((ArrayList<Town>)townData, R.layout.item_scense_detail_list) {
|
@Override
|
public void bindView(ViewHolder holder, Town obj) {
|
holder.setText(R.id.tv_item, obj.getTownname());
|
}
|
};
|
|
SP_town.setAdapter(townAdapter);
|
//场景类型
|
scenseAdapter = new AllListViewAdapter<Domainitem>((ArrayList<Domainitem>) scenseTypeData, R.layout.item_spinner_simple_text) {
|
@Override
|
public void bindView(ViewHolder holder, Domainitem obj) {
|
holder.setText(R.id.tv_item, obj.getText());
|
}
|
};
|
SP_scense_type.setAdapter(scenseAdapter);
|
scenseAdapter.notifyDataSetChanged();
|
//时间
|
dateAdapter = new AllRecyclerViewAdapter<String>(dateData, R.layout.item_scense_detail_list, context) {
|
@Override
|
public void bindView(final AllRecyclerViewAdapter.MyViewHolder holder, final String obj, boolean bool, final int position) {
|
holder.setText(R.id.tv_item, obj);
|
holder.setSelected(R.id.tv_item, bool);
|
holder.setOnClickListener(R.id.tv_item, new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
dateAdapter.setAllFalse();
|
dateAdapter.setSelected(true, position);
|
dateAdapter.notifyDataSetChanged();
|
BRIEF_TIME = obj;
|
Log.e("对象名称", obj);
|
showDialog();
|
search();
|
}
|
});
|
if (Objects.equals(BRIEF_TIME, obj)) {
|
holder.setSelected(R.id.tv_item, true);
|
}
|
}
|
};
|
RV_quick_choose.setAdapter(dateAdapter);
|
dateAdapter.notifyDataSetChanged();
|
//****上面为设置适配器**********************************************
|
}
|
|
/**
|
* 区域选择弹出框
|
*/
|
private void initDialog() {
|
// int mScreenWidth = getResources().getDisplayMetrics().widthPixels;
|
// 讲布局文件转换成 view 对象
|
dialog = new Dialog(context);
|
dialog.setContentView(R.layout.popwindow);
|
//设置dialog宽度
|
Window dialogWindow = dialog.getWindow();
|
assert dialogWindow != null;
|
dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
|
final WindowManager.LayoutParams p = dialogWindow.getAttributes();
|
p.width = ScreenUtils.getScreenWidth(context);
|
// p.height = (int) (ScreenUtils.getScreenHeight(context) * 0.9);
|
/* 获取 PopupWindow 加载布局文件中的view */
|
SP_province = (Spinner) dialog.findViewById(R.id.SP_province);
|
SP_city = (Spinner) dialog.findViewById(R.id.SP_city);
|
SP_district = (Spinner) dialog.findViewById(R.id.SP_district);
|
SP_town = (Spinner) dialog.findViewById(R.id.SP_town);
|
SP_province.setOnItemSelectedListener(this);
|
SP_city.setOnItemSelectedListener(this);
|
SP_district.setOnItemSelectedListener(this);
|
SP_town.setOnItemSelectedListener(this);
|
// SP_province.setSelection(0);
|
// SP_city.setSelection(0);
|
// SP_district.setSelection(0);
|
// SP_town.setSelection(0);
|
/*设置时间选择按钮*/
|
TV_quick_choose = (TextView) dialog.findViewById(R.id.TV_quick_choose);
|
TV_any_time = (TextView) dialog.findViewById(R.id.TV_any_time);
|
TV_quick_choose.setSelected(true);
|
TV_quick_choose .setOnClickListener(this);
|
TV_any_time .setOnClickListener(this);
|
/*设置快速时间选择列表*/
|
TV_start_time = (TextView) dialog.findViewById(R.id.TV_start_time);
|
TV_end_time = (TextView) dialog.findViewById(R.id.TV_end_time);
|
TV_start_time.setText(DateFormatter.dateFormat.format(CommonUtils.getTimesMonthmorning()));
|
TV_end_time.setText(DateFormatter.dateFormat.format(CommonUtils.getTimesMonthnight()));
|
TV_start_time.setOnClickListener(this);
|
TV_end_time.setOnClickListener(this);
|
//设置显示对其方式
|
GridLayoutManager layoutManager = new GridLayoutManager(context, 2);
|
layoutManager.setOrientation(GridLayoutManager.VERTICAL);
|
layoutManager.setAutoMeasureEnabled(true);
|
RV_quick_choose = (RecyclerView) dialog.findViewById(R.id.RV_quick_choose);
|
RV_quick_choose.setLayoutManager(layoutManager);
|
RV_quick_choose.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
/* 设置任意时间选择列表*/
|
LL_any_time = (LinearLayout) dialog.findViewById(R.id.LL_any_time);
|
LL_any_time.setVisibility(View.GONE);
|
/*设置确定、取消按钮*/
|
tv_Cancel = (TextView) dialog.findViewById(R.id.btn_cancel);
|
tv_Ok = (TextView) dialog.findViewById(R.id.btn_ok);
|
tv_Cancel.setOnClickListener(this);
|
tv_Ok.setOnClickListener(this);
|
dialog.show();
|
// dialog.hide();
|
// 点击会自动 PopupWindow 关闭
|
// dialog.setOutsideTouchable(false);
|
/* 设置 PopupWindow 出现时的动画 */
|
// dialog.setAnimationStyle(R.style.anim_menu_dialog);
|
/* 设置背景颜色 */
|
// dialog.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
|
// dialog.update();
|
/* 允许 PopupWindow 获取焦点 */
|
// this.dialog.setFocusable(false);
|
}
|
|
/**
|
* 显示和隐藏Popupwindow
|
*/
|
private void showDialog(){
|
// 设置显示的位置
|
if (!dialog.isShowing())
|
dialog.show();
|
else
|
dialog.dismiss();
|
}
|
|
/**
|
* 按照搜索条件查询问题分布结果
|
*/
|
private void search() {
|
final Dialog dialog = DialogUtil.createLoadingDialog(getActivity(), "加载中...");
|
AreaVo areaVo = new AreaVo();
|
areaVo.setProvincecode(((Province)SP_province.getSelectedItem()).getProvincecode());
|
areaVo.setProvincename(((Province)SP_province.getSelectedItem()).getProvincename());
|
areaVo.setCitycode(((City)SP_city.getSelectedItem()).getCitycode());
|
areaVo.setCityname(((City)SP_city.getSelectedItem()).getCityname());
|
areaVo.setDistrictcode(((District)SP_district.getSelectedItem()).getDistrictcode());
|
areaVo.setDistrictname(((District)SP_district.getSelectedItem()).getDistrictname());
|
areaVo.setTowncode(((Town) SP_town.getSelectedItem()).getTowncode());
|
areaVo.setTownname(((Town) SP_town.getSelectedItem()).getTownname());
|
areaVo = gettime(areaVo);
|
int position = SP_scense_type.getSelectedItemPosition();
|
areaVo.setScensetypeid(scenseTypeData.get(position).getValue());
|
Call<List<ProblemlistVo>> getProblemByArea = problemListService.getByArea(areaVo);
|
getProblemByArea.enqueue(new Callback<List<ProblemlistVo>>() {
|
@Override
|
public void onResponse(Call<List<ProblemlistVo>> call, Response<List<ProblemlistVo>> response) {
|
if (response.body() != null) {
|
problemlists = response.body();
|
}
|
setData(problemlists);
|
entryAdapter.notifyDataSetChanged();//刷新列表
|
DialogUtil.closeDialog(dialog);
|
}
|
|
@Override
|
public void onFailure(Call<List<ProblemlistVo>> call, Throwable t) {
|
setData(problemlists);
|
DialogUtil.closeDialog(dialog);
|
}
|
});
|
|
setChartTitle();//刷新标题
|
setDateDisplay();//刷新时间
|
}
|
|
/**
|
* 设定饼图标题及图标
|
*/
|
private void setChartTitle() {
|
String title = ((Province)SP_province.getSelectedItem()).getProvincename();
|
if (!Objects.equals(title, ((City) SP_city.getSelectedItem()).getCityname()))
|
title = title + ((City) SP_city.getSelectedItem()).getCityname();
|
if (!Objects.equals(((District)SP_district.getSelectedItem()).getDistrictname(), ALLDISTRICT))
|
title = title + ((District)SP_district.getSelectedItem()).getDistrictname();
|
if (!Objects.equals(((Town)SP_town.getSelectedItem()).getTownname(), ALLTOWN))
|
title = title + ((Town)SP_town.getSelectedItem()).getTownname();
|
title = title + "问题类型分布情况";
|
TV_area.setText(title);
|
IV_scene_type.setImageResource(CommonUtils.getIconBySceneType(((Domainitem)SP_scense_type.getSelectedItem()).getValue()));
|
}
|
|
/**
|
* 获取所选的时间
|
* @param areaVo RequestBody,查询问题列表
|
* @return
|
*/
|
private AreaVo gettime(AreaVo areaVo){
|
if (TIME_TYPE == 0) {//快速选择
|
Date date1;
|
Date date2;
|
switch (BRIEF_TIME) {
|
case Constant.THIS_WEEK:
|
date1 = CommonUtils.getTimesWeekmorning();
|
date2 = CommonUtils.getTimesWeeknight();
|
break;
|
case Constant.LAST_WEEK:
|
date1 = CommonUtils.getTimesLastWeekmorning();
|
date2 = CommonUtils.getTimesLastWeeknight();
|
break;
|
case Constant.THIS_MONTH:
|
date1 = CommonUtils.getTimesMonthmorning();
|
date2 = CommonUtils.getTimesMonthnight();
|
break;
|
case Constant.LAST_MONTH:
|
date1 = CommonUtils.getTimesLastMonthmorning();
|
date2 = CommonUtils.getTimesLastMonthnight();
|
break;
|
case Constant.THIS_SEASON:
|
date1 = CommonUtils.getTimesSeasonmorning();
|
date2 = CommonUtils.getTimesSeasonnight();
|
break;
|
case Constant.LAST_SEASON:
|
date1 = CommonUtils.getTimesLastSeasonmorning();
|
date2 = CommonUtils.getTimesLastSeasonnight();
|
break;
|
case Constant.THIS_YEAR:
|
date1 = CommonUtils.getCurrentYearStartTime();
|
date2 = CommonUtils.getCurrentYearEndTime();
|
break;
|
case Constant.LAST_YEAR:
|
date1 = CommonUtils.getLastYearStartTime();
|
date2 = CommonUtils.getLastYearEndTime();
|
break;
|
default:
|
date1 = CommonUtils.getTimesMonthmorning();
|
date2 = CommonUtils.getTimesMonthnight();
|
break;
|
}
|
areaVo.setStarttime(DateFormatter.dateTimeFormat2.format(date1));
|
areaVo.setEndtime(DateFormatter.dateTimeFormat2.format(date2));
|
}
|
else if (TIME_TYPE == 1){//任意时段
|
areaVo.setStarttime(TV_start_time.getText().toString());
|
areaVo.setEndtime(TV_end_time.getText().toString());
|
return areaVo;
|
}
|
return areaVo;
|
}
|
|
/**
|
* 设置所选时间的显示
|
*/
|
private void setDateDisplay() {
|
if (TIME_TYPE == 0) {//快速选择
|
// TV_date_display1.setTitle(BRIEF_TIME);
|
stv_date_display2.setText(BRIEF_TIME);
|
} else if (TIME_TYPE == 1) {//任意时段
|
// TV_date_display1.setTitle(TV_start_time.getTitle().toString());
|
stv_date_display2.setText(TV_start_time.getText().toString() + " ~ " + TV_end_time.getText().toString());
|
}
|
}
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.FAB_menu:
|
showDialog();
|
// FAB_menu.setImageResource(dialog.isShowing()? R.drawable.icon_close_white : R.drawable.icon_open_white);
|
break;
|
case R.id.btn_cancel:
|
showDialog();
|
break;
|
case R.id.btn_ok:
|
search();
|
showDialog();
|
break;
|
case R.id.TV_quick_choose:
|
TV_quick_choose.setSelected(true);
|
TV_any_time.setSelected(false);
|
TV_quick_choose.setTextColor(Color.WHITE);
|
TV_any_time.setTextColor(Color.BLACK);
|
RV_quick_choose.setVisibility(View.VISIBLE);
|
LL_any_time.setVisibility(View.GONE);
|
TIME_TYPE = 0;
|
break;
|
case R.id.TV_any_time:
|
TV_any_time.setSelected(true);
|
TV_quick_choose.setSelected(false);
|
TV_any_time.setTextColor(Color.WHITE);
|
TV_quick_choose.setTextColor(Color.BLACK);
|
LL_any_time.setVisibility(View.VISIBLE);
|
RV_quick_choose.setVisibility(View.GONE);
|
TIME_TYPE = 1;
|
break;
|
//开始时间
|
case R.id.TV_start_time:
|
dialog.hide();
|
Calendar calendar1 = Calendar.getInstance();
|
new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener(){
|
|
@Override
|
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
|
String result = "";
|
result += year + "." + (month+1) + "." + day + ".";
|
Toast.makeText(getContext(), result, Toast.LENGTH_SHORT).show();
|
dialog.show();
|
TV_start_time.setText(result);
|
}
|
}
|
,calendar1.get(Calendar.YEAR)
|
,calendar1.get(Calendar.MONTH)
|
,calendar1.get(Calendar.DAY_OF_MONTH)).show();
|
break;
|
//结束时间
|
case R.id.TV_end_time:
|
dialog.hide();
|
Calendar calendar2 = Calendar.getInstance();
|
new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener(){
|
|
@Override
|
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
|
String result = "";
|
result += year + "." + (month+1) + "." + day + ".";
|
Toast.makeText(getActivity(), result, Toast.LENGTH_SHORT).show();
|
dialog.show();
|
TV_end_time.setText(result);
|
}
|
}
|
,calendar2.get(Calendar.YEAR)
|
,calendar2.get(Calendar.MONTH)
|
,calendar2.get(Calendar.DAY_OF_MONTH)).show();
|
break;
|
}
|
}
|
|
@Override
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
switch (parent.getId()) {
|
case R.id.SP_province:
|
cityData.clear();
|
for (int y = 0; y < allCityData.size(); y++){
|
if(Objects.equals(allCityData.get(y).getPronvinceid(), ((Province) SP_province.getSelectedItem()).getProvinceid()))
|
cityData.add(allCityData.get(y));
|
}
|
cityAdapter.notifyDataSetChanged();
|
break;
|
case R.id.SP_city:
|
districtData.clear();
|
District emptydistrict = new District();
|
emptydistrict.setDistrictname(ALLDISTRICT);
|
districtData.add(emptydistrict);
|
for (int y = 0; y < allDistrictData.size(); y++){
|
if(Objects.equals(allDistrictData.get(y).getCityid(), ((City) SP_city.getSelectedItem()).getCityId()))
|
districtData.add(allDistrictData.get(y));
|
}
|
districtAdapter.notifyDataSetChanged();
|
break;
|
case R.id.SP_district:
|
townData.clear();
|
Town emptytown = new Town();
|
emptytown.setTownname(ALLTOWN);
|
townData.add(emptytown);
|
for (int y = 0; y < allTownData.size(); y++){
|
if(Objects.equals(allTownData.get(y).getDistrictid(), ((District) SP_district.getSelectedItem()).getDistrictid()))
|
townData.add(allTownData.get(y));
|
}
|
townAdapter.notifyDataSetChanged();
|
break;
|
case R.id.SP_town:
|
// setChartTitle();
|
break;
|
case R.id.SP_scense_type:
|
search();
|
// setDateDisplay();
|
break;
|
}
|
}
|
|
@Override
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
}
|
}
|