You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
8.0 KiB
201 lines
8.0 KiB
package com.project.survey.dialog;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
|
|
import com.bingce.coordlib.model.Blh;
|
|
import com.bingce.coordlib.model.Coordinate;
|
|
import com.project.survey.R;
|
|
import com.project.survey.model.ControlRecord;
|
|
import com.project.survey.ui.pointmeasure.measure.ControlRecordListActivity;
|
|
import com.project.survey.util.CommonUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
|
|
import lecho.hellocharts.model.Line;
|
|
import lecho.hellocharts.model.LineChartData;
|
|
import lecho.hellocharts.model.PointValue;
|
|
import lecho.hellocharts.renderer.LineChartRenderer;
|
|
import lecho.hellocharts.view.LineChartView;
|
|
|
|
public class CustomLineChartDialog extends Dialog {
|
|
private CustomLineChartDialog(Context context, int themeResId) {
|
|
super(context, themeResId);
|
|
}
|
|
|
|
private CustomLineChartDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
|
|
super(context, cancelable, cancelListener);
|
|
}
|
|
|
|
/* Builder */
|
|
public static class Builder {
|
|
private TextView tvTitle,tvDetail;
|
|
private TextView btnCancel, btnConfirm;
|
|
private LineChartView lineChartView;
|
|
public List<ControlRecord> pointList;
|
|
private View mLayout;
|
|
private View.OnClickListener mButtonCancelClickListener;
|
|
private View.OnClickListener mButtonConfirmClickListener;
|
|
private Context mContext;
|
|
private Line blackPointLine = new Line();
|
|
private Line redPointLine = new Line();
|
|
private CustomLineChartDialog mDialog;
|
|
|
|
public Builder(Context context) {
|
|
pointList = new ArrayList<>();
|
|
mContext = context;
|
|
mDialog = new CustomLineChartDialog(context, R.style.gif_dialog);
|
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
// 加载布局文件
|
|
mLayout = inflater.inflate(R.layout.layout_linechart_dialog, null, false);
|
|
// 添加布局文件到 Dialog
|
|
mDialog.addContentView(mLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
|
tvTitle = mLayout.findViewById(R.id.tv_title);
|
|
tvDetail = mLayout.findViewById(R.id.tv_detail);
|
|
lineChartView = mLayout.findViewById(R.id.line_chart_view_dialog);
|
|
btnCancel = mLayout.findViewById(R.id.btn_cancel);
|
|
btnConfirm = mLayout.findViewById(R.id.btn_confirm);
|
|
|
|
tvDetail.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
ControlRecordListActivity.start(mContext,pointList);
|
|
}
|
|
});
|
|
|
|
List<LineChartData> lineChartDataList = new ArrayList<>();
|
|
LineChartData tempPointRecord = new LineChartData();
|
|
int blackPointColor = context.getResources().getColor(R.color.color_575757);
|
|
int redPointColor = context.getResources().getColor(R.color.color_FF1515);
|
|
blackPointLine.setCubic(false).setHasLabels(true).setHasPoints(true).setStrokeWidth(0).setHasLines(false).setPointRadius(3).
|
|
setPointColor(blackPointColor).setShowLabelBackground(false).setLabelTextColor(blackPointColor);
|
|
redPointLine.setCubic(false).setHasLabels(true).setHasPoints(true).setStrokeWidth(0).setHasLines(false).setPointRadius(3).
|
|
setPointColor(redPointColor).setShowLabelBackground(false).setLabelTextColor(redPointColor);
|
|
tempPointRecord.getLines().add(blackPointLine);
|
|
tempPointRecord.getLines().add(redPointLine);
|
|
lineChartDataList.add(tempPointRecord);
|
|
if (!lineChartDataList.isEmpty()) {
|
|
CommonUtils.mChartViewSetLineChartDatas(lineChartView, lineChartDataList, false, false);
|
|
}
|
|
if (lineChartView.getChartRenderer() instanceof LineChartRenderer) {
|
|
((LineChartRenderer) lineChartView.getChartRenderer()).calculateMaxViewport(1.5f);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 设置 Dialog 标题
|
|
*/
|
|
public Builder setTitle(String title) {
|
|
tvTitle.setText(title);
|
|
tvTitle.setVisibility(View.VISIBLE);
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* 设置 Warning
|
|
*/
|
|
public Builder addDrawBlackSurveyPoint(Coordinate coordinate,Blh blh) {
|
|
ControlRecord controlRecord = new ControlRecord(coordinate.getX(),coordinate.getY(),coordinate.getZ(), blh.getLatitude(),blh.getLongitude(),blh.getAltitude(), "p" + (pointList.size() + 1));
|
|
blackPointLine.getValues().add(new PointValue(controlRecord.getY(),controlRecord.getX()).setLabel(controlRecord.getPointName()));
|
|
pointList.add(controlRecord);
|
|
if (pointList != null && pointList.size() == 0) {
|
|
lineChartView.setCurrentViewport(lineChartView.getMaximumViewport());
|
|
}
|
|
((LineChartRenderer) lineChartView.getChartRenderer()).calculateMaxViewport(1.5f);
|
|
lineChartView.onChartDataChange();
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* 动态添加测量点
|
|
*/
|
|
public void addDrawRedSurvryPoint(ControlRecord record) {
|
|
redPointLine.getValues().add(new PointValue(record.getY(),record.getX()).setLabel(record.getPointName()));
|
|
lineChartView.setCurrentViewport(lineChartView.getMaximumViewport());
|
|
((LineChartRenderer) lineChartView.getChartRenderer()).calculateMaxViewport(1.5f);
|
|
lineChartView.onChartDataChange();
|
|
}
|
|
|
|
/**
|
|
* 设置取消按钮文字和监听
|
|
*/
|
|
|
|
/**
|
|
* 设置取消按钮文字和监听
|
|
*/
|
|
public Builder setButtonCancel(String text) {
|
|
btnCancel.setText(text);
|
|
return this;
|
|
}
|
|
|
|
public Builder setButtonCancel(View.OnClickListener listener) {
|
|
mButtonCancelClickListener = listener;
|
|
return this;
|
|
}
|
|
|
|
public Builder setButtonCancel(String text, View.OnClickListener listener) {
|
|
btnCancel.setText(text);
|
|
mButtonCancelClickListener = listener;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* 设置确认按钮文字和监听
|
|
*/
|
|
public Builder setButtonConfirmTextColor(int textColor) {
|
|
btnConfirm.setTextColor(mContext.getColor(textColor));
|
|
return this;
|
|
}
|
|
|
|
public Builder setButtonConfirm(String text) {
|
|
btnConfirm.setText(text);
|
|
return this;
|
|
}
|
|
|
|
public Builder setButtonConfirm(View.OnClickListener listener) {
|
|
mButtonConfirmClickListener = listener;
|
|
return this;
|
|
}
|
|
|
|
public Builder setButtonConfirm(String text, View.OnClickListener listener) {
|
|
btnConfirm.setText(text);
|
|
mButtonConfirmClickListener = listener;
|
|
return this;
|
|
}
|
|
|
|
public CustomLineChartDialog create() {
|
|
btnCancel.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
mDialog.dismiss();
|
|
if (mButtonCancelClickListener != null) {
|
|
mButtonCancelClickListener.onClick(view);
|
|
}
|
|
}
|
|
});
|
|
|
|
btnConfirm.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
mDialog.dismiss();
|
|
if (mButtonConfirmClickListener != null) {
|
|
mButtonConfirmClickListener.onClick(view);
|
|
}
|
|
}
|
|
});
|
|
|
|
mDialog.setContentView(mLayout);
|
|
mDialog.setCancelable(true);
|
|
mDialog.setCanceledOnTouchOutside(false);
|
|
return mDialog;
|
|
}
|
|
}
|
|
}
|
|
|