|
|
@@ -1,37 +1,27 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
|
|
|
-import android.graphics.Color;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
-import android.util.DisplayMetrics;
|
|
|
-
|
|
|
-import com.github.mikephil.charting.charts.BarChart;
|
|
|
-import com.github.mikephil.charting.charts.PieChart;
|
|
|
-import com.github.mikephil.charting.components.Legend;
|
|
|
-import com.github.mikephil.charting.components.XAxis;
|
|
|
-import com.github.mikephil.charting.components.YAxis;
|
|
|
-import com.github.mikephil.charting.data.BarData;
|
|
|
-import com.github.mikephil.charting.data.BarDataSet;
|
|
|
-import com.github.mikephil.charting.data.BarEntry;
|
|
|
-import com.github.mikephil.charting.data.Entry;
|
|
|
-import com.github.mikephil.charting.data.PieData;
|
|
|
-import com.github.mikephil.charting.data.PieDataSet;
|
|
|
-import com.github.mikephil.charting.utils.LargeValueFormatter;
|
|
|
+import android.util.Log;
|
|
|
+
|
|
|
+import com.baidu.mapapi.search.route.BikingRouteResult;
|
|
|
+import com.baidu.mapapi.search.route.DrivingRouteLine;
|
|
|
+import com.baidu.mapapi.search.route.DrivingRoutePlanOption;
|
|
|
+import com.baidu.mapapi.search.route.DrivingRouteResult;
|
|
|
+import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
|
|
|
+import com.baidu.mapapi.search.route.PlanNode;
|
|
|
+import com.baidu.mapapi.search.route.RoutePlanSearch;
|
|
|
+import com.baidu.mapapi.search.route.TransitRouteResult;
|
|
|
+import com.baidu.mapapi.search.route.WalkingRouteResult;
|
|
|
import com.lidroid.xutils.ViewUtils;
|
|
|
-import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.view.MyMarkerView;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class TestActivity extends AppCompatActivity {
|
|
|
- @ViewInject(R.id.bar_chart)
|
|
|
- private BarChart barChart;
|
|
|
- @ViewInject(R.id.pie_chart)
|
|
|
- private PieChart pieChart;
|
|
|
- private MyMarkerView mv;
|
|
|
- private ArrayList<ArrayList<String>> gridlists = new ArrayList<ArrayList<String>>();
|
|
|
- private ArrayList<Integer> colors;
|
|
|
+
|
|
|
+ private RoutePlanSearch mSearch;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -39,143 +29,60 @@ public class TestActivity extends AppCompatActivity {
|
|
|
setContentView(R.layout.activity_test);
|
|
|
ViewUtils.inject(this);
|
|
|
init();
|
|
|
- initView();
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
|
//初始化饼图颜色
|
|
|
- colors = new ArrayList();
|
|
|
- colors.add(Color.rgb(0, 191, 255));
|
|
|
- colors.add(Color.rgb(255, 254, 179));
|
|
|
- colors.add(Color.rgb(205, 133, 63));
|
|
|
- colors.add(Color.rgb(173, 255, 47));
|
|
|
- colors.add(Color.rgb(0, 128, 0));
|
|
|
- colors.add(Color.rgb(139, 0, 0));
|
|
|
- }
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- initBar();
|
|
|
- initPieChart();
|
|
|
+ mSearch = RoutePlanSearch.newInstance();
|
|
|
+ mSearch.setOnGetRoutePlanResultListener(listener);
|
|
|
+ PlanNode stNode = PlanNode.withCityNameAndPlaceName("深圳", "坪洲地铁站");
|
|
|
+ PlanNode enNode = PlanNode.withCityNameAndPlaceName("深圳", "深大地铁站");
|
|
|
+ mSearch.drivingSearch((new DrivingRoutePlanOption())
|
|
|
+ .from(stNode)
|
|
|
+ .to(enNode));
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void initPieChart() {
|
|
|
- pieChart.setHoleColorTransparent(true);
|
|
|
- pieChart.setHoleRadius(30f); //半径
|
|
|
- pieChart.setTransparentCircleRadius(64f); // 半透明圈
|
|
|
- pieChart.setDescription("");
|
|
|
- pieChart.setDrawCenterText(true); //饼状图中间可以添加文字
|
|
|
- pieChart.setDrawHoleEnabled(true);
|
|
|
- pieChart.setTransparentCircleRadius(40f); // 设置中间透明圈的大小
|
|
|
- pieChart.setRotationAngle(90); // 初始旋转角度
|
|
|
- pieChart.setRotationEnabled(true); // 可以手动旋转
|
|
|
- pieChart.setUsePercentValues(true); //显示成百分比
|
|
|
- pieChart.setCenterText("8000"); //饼状图中间的文字
|
|
|
- pieChart.setData(getPieData(6)); //设置数据
|
|
|
- Legend mLegend = pieChart.getLegend(); //设置说明
|
|
|
- mLegend.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); //设置比例显示位置
|
|
|
- mLegend.setXEntrySpace(10f);
|
|
|
- mLegend.setYEntrySpace(10f);
|
|
|
- pieChart.animateXY(1000, 1000); //设置动画
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ mSearch.destroy();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param count 分成几部分
|
|
|
- * @param
|
|
|
- */
|
|
|
- private PieData getPieData(int count) {
|
|
|
- ArrayList<String> xValues = new ArrayList<String>(); //xVals用来表示每个饼块上的内容
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- xValues.add("YT000" + (i + 1)); //饼块上显示成Quarterly1, Quarterly2, Quarterly3, Quarterly4
|
|
|
+ OnGetRoutePlanResultListener listener = new OnGetRoutePlanResultListener() {
|
|
|
+ @Override
|
|
|
+ public void onGetWalkingRouteResult(WalkingRouteResult result) {
|
|
|
+ //获取步行线路规划结果
|
|
|
+ show("onGetWalkingRouteResult");
|
|
|
}
|
|
|
- ArrayList<Entry> yValues = new ArrayList<Entry>(); //yVals用来表示封装每个饼块的实际数据
|
|
|
- // 饼图数据
|
|
|
- float quarterly1 = 14;
|
|
|
- float quarterly2 = 5;
|
|
|
- float quarterly3 = 33;
|
|
|
- float quarterly4 = 21;
|
|
|
- float quarterly5 = 11;
|
|
|
- float quarterly6 = 16;
|
|
|
- yValues.add(new Entry(quarterly1, 0));
|
|
|
- yValues.add(new Entry(quarterly2, 1));
|
|
|
- yValues.add(new Entry(quarterly3, 2));
|
|
|
- yValues.add(new Entry(quarterly4, 3));
|
|
|
- yValues.add(new Entry(quarterly5, 4));
|
|
|
- yValues.add(new Entry(quarterly6, 5));
|
|
|
- //y轴的集合
|
|
|
- PieDataSet pieDataSet = new PieDataSet(yValues, ""/*显示在比例图上*/);
|
|
|
- pieDataSet.setSliceSpace(0f); //设置个饼状图之间的距离
|
|
|
- pieDataSet.setColors(colors);
|
|
|
- DisplayMetrics metrics = getResources().getDisplayMetrics();
|
|
|
- float px = 5 * (metrics.densityDpi / 160f);
|
|
|
- pieDataSet.setSelectionShift(px); // 选中态多出的长度
|
|
|
- PieData pieData = new PieData(xValues, pieDataSet);
|
|
|
- return pieData;
|
|
|
- }
|
|
|
|
|
|
- private void initBar() {
|
|
|
- barChart.setDrawBorders(false); ////是否在折线图上添加边框
|
|
|
- // 如果没有数据的时候,会显示这个,类似ListView的EmptyView
|
|
|
- barChart.setNoDataTextDescription("没有数据");
|
|
|
- barChart.setDrawGridBackground(false); // 是否显示表格颜色
|
|
|
- barChart.setTouchEnabled(true); // 设置是否可以触摸
|
|
|
- barChart.setDragEnabled(true);// 是否可以拖拽
|
|
|
- barChart.setScaleEnabled(true);// 是否可以缩放
|
|
|
- barChart.setPinchZoom(false);//
|
|
|
- mv = new MyMarkerView(this, R.layout.custom_marker_view);
|
|
|
- barChart.setMarkerView(mv);
|
|
|
- barChart.setDescription("");
|
|
|
- barChart.setMaxVisibleValueCount(60);
|
|
|
- barChart.setDrawBarShadow(false);
|
|
|
- XAxis xAxis = barChart.getXAxis();
|
|
|
- xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
|
|
- // xAxis.setSpaceBetweenLabels(30);
|
|
|
- xAxis.setLabelsToSkip(0);
|
|
|
- xAxis.setAxisLineColor(getResources().getColor(R.color.red));
|
|
|
- xAxis.setSpaceBetweenLabels(8);
|
|
|
- xAxis.setAxisLineWidth(0f);
|
|
|
- xAxis.setDrawGridLines(false);
|
|
|
- barChart.getAxisLeft().setDrawGridLines(false);
|
|
|
-// barChart.setBackgroundColor();// 设置背景
|
|
|
- barChart.setDrawBarShadow(true);
|
|
|
- barChart.setData(getBarData(7, 500)); // 设置数据
|
|
|
- Legend mLegend = barChart.getLegend(); // 设置比例图标示
|
|
|
- mLegend.setForm(Legend.LegendForm.CIRCLE);// 样式
|
|
|
- mLegend.setFormSize(6f);// 字体
|
|
|
- mLegend.setTextColor(Color.BLACK);// 颜色
|
|
|
- YAxis leftAxis = barChart.getAxisLeft();
|
|
|
- leftAxis.setValueFormatter(new LargeValueFormatter());
|
|
|
- leftAxis.setDrawGridLines(false);
|
|
|
- leftAxis.setSpaceTop(25f);
|
|
|
- leftAxis.setAxisLineColor(getResources().getColor(R.color.red));
|
|
|
- barChart.getAxisRight().setEnabled(false);
|
|
|
- barChart.setMaxVisibleValueCount(10);
|
|
|
+ @Override
|
|
|
+ public void onGetTransitRouteResult(TransitRouteResult result) {
|
|
|
+ //获取公交换乘路径规划结果
|
|
|
+ show("onGetTransitRouteResult");
|
|
|
+ }
|
|
|
|
|
|
- barChart.animateY(2500);
|
|
|
- barChart.animateX(2500); // 立即执行的动画,x轴
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onGetDrivingRouteResult(DrivingRouteResult result) {
|
|
|
+ //获取驾车线路规划结果
|
|
|
+ List<DrivingRouteLine> list = result.getRouteLines();
|
|
|
+ for (DrivingRouteLine e : list) {
|
|
|
+ show("result.getTitle()=" + e.getTitle());//获取名称
|
|
|
+ show("result.getDistance()=" + e.getDistance());//获取路段长度
|
|
|
+ show("result.getDuration()=" + e.getDuration());//获取路段耗时
|
|
|
+ }
|
|
|
|
|
|
- private BarData getBarData(int count, float range) {
|
|
|
- ArrayList<String> xValues = new ArrayList<String>();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- xValues.add("YT00\n00" + count);
|
|
|
}
|
|
|
- BarEntry entry = null;
|
|
|
|
|
|
- ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- float value = (float) (Math.random() * range/*100以内的随机数*/) + 3;
|
|
|
-
|
|
|
- yValues.add(new BarEntry(value, i));
|
|
|
+ @Override
|
|
|
+ public void onGetBikingRouteResult(BikingRouteResult bikingRouteResult) {
|
|
|
+ //获取自行车线路规划结果
|
|
|
+ show("onGetBikingRouteResult");
|
|
|
}
|
|
|
- // y轴的数据集合
|
|
|
- BarDataSet barDataSet = new BarDataSet(yValues, "测试饼状图");
|
|
|
- barDataSet.setColors(colors);
|
|
|
- ArrayList<BarDataSet> barDataSets = new ArrayList<BarDataSet>();
|
|
|
- barDataSets.add(barDataSet); // add the datasets
|
|
|
- BarData barData = new BarData(xValues, barDataSets);
|
|
|
- return barData;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
+ private void show(String str) {
|
|
|
+ if (StringUtils.isEmpty(str)) return;
|
|
|
+ Log.i("gongpengming", str);
|
|
|
+ }
|
|
|
}
|