Browse Source

代码优化

huyuguo 5 years ago
parent
commit
31983f6f69

+ 9 - 228
app/src/main/java/com/electric/chargingpile/activity/RoutePlanMapActivity.java

21
import android.os.Environment;
21
import android.os.Environment;
22
import android.os.Handler;
22
import android.os.Handler;
23
import android.provider.MediaStore;
23
import android.provider.MediaStore;
24
24
import androidx.appcompat.app.AlertDialog;
25
import androidx.appcompat.app.AlertDialog;
26
25
import android.util.Log;
27
import android.util.Log;
26
import android.view.LayoutInflater;
28
import android.view.LayoutInflater;
27
import android.view.MotionEvent;
29
import android.view.MotionEvent;
137
import cn.sharesdk.wechat.moments.WechatMoments;
139
import cn.sharesdk.wechat.moments.WechatMoments;
138
import okhttp3.Call;
140
import okhttp3.Call;
139
141
140
//import com.electric.chargingpile.util.TTSController;
141
142
/**
142
/**
143
 * 创建时间:15/12/7 18:11
143
 * 创建时间:15/12/7 18:11
144
 * 项目名称:newNaviDemo
144
 * 项目名称:newNaviDemo
153
    NaviLatLng endLatlng;
153
    NaviLatLng endLatlng;
154
    NaviLatLng startLatlng;
154
    NaviLatLng startLatlng;
155
    NaviLatLng zhongLatlng;
155
    NaviLatLng zhongLatlng;
156
    NaviLatLng zhongLatlng1;
157
    List<NaviLatLng> startList = new ArrayList<NaviLatLng>();
156
    List<NaviLatLng> startList = new ArrayList<NaviLatLng>();
158
    List<NaviLatLng> endList = new ArrayList<NaviLatLng>();
157
    List<NaviLatLng> endList = new ArrayList<NaviLatLng>();
159
    List<NaviLatLng> zhongList = new ArrayList<NaviLatLng>();
158
    List<NaviLatLng> zhongList = new ArrayList<NaviLatLng>();
164
    private HashMap<Integer, RouteOverLay> routeOverlays = new HashMap<Integer, RouteOverLay>();
163
    private HashMap<Integer, RouteOverLay> routeOverlays = new HashMap<Integer, RouteOverLay>();
165
    private int routeIndex;
164
    private int routeIndex;
166
    private int[] routeIds;
165
    private int[] routeIds;
167
    //    private TTSController ttsManager;
168
    private boolean chooseRouteSuccess;
166
    private boolean chooseRouteSuccess;
169
    private boolean mapClickStartReady;
170
    private boolean mapClickEndReady;
171
    private Marker mStartMarker;
172
    private Marker mWayMarker;
173
    private Marker mEndMarker;
174
    private GeocodeSearch geocoderSearch;
167
    private GeocodeSearch geocoderSearch;
175
    private boolean calculateSuccess;
168
    private boolean calculateSuccess;
176
    private String start_name, start_address, start_jing, start_wei, end_name, end_address, end_jing, end_wei;
169
    private String start_name, start_address, start_jing, start_wei, end_name, end_address, end_jing, end_wei;
177
    String poi_jing, poi_wei;
170
    String poi_jing, poi_wei;
178
    private float minZoomLevel;
179
    private float maxZoomLevel;
180
    private UiSettings mUiSettings;
181
    TextView tv, tv_infowindow;
182
    private AMapLocationClient mlocationClient;
171
    private AMapLocationClient mlocationClient;
183
    private LocationSource.OnLocationChangedListener mListener;
172
    private LocationSource.OnLocationChangedListener mListener;
184
    private AMapLocationClientOption mLocationOption;
173
    private AMapLocationClientOption mLocationOption;
185
    LatLng target = null;
186
    private Marker mMarkerCity = null;
174
    private Marker mMarkerCity = null;
187
    private MarkerOptions oocity = null;
175
    private MarkerOptions oocity = null;
188
    LatLng center;
176
    LatLng center;
192
    private List<Zhan> list_zhong = new ArrayList<Zhan>();
180
    private List<Zhan> list_zhong = new ArrayList<Zhan>();
193
    private RoutePlanInfo routePlanInfo;
181
    private RoutePlanInfo routePlanInfo;
194
    private Zhan zhan;
182
    private Zhan zhan;
195
    private RelativeLayout rl_route1, rl_route2, rl_route3, rl_submit, rela_paopao, rl_zhong;
183
    private RelativeLayout rl_route1, rl_route2, rl_route3, rela_paopao;
196
    private View view1, view2;
184
    private View view1, view2;
197
    private RouteOverLay routeOverLay;
185
    private RouteOverLay routeOverLay;
198
    private ImageView iv_back, iv_zhong;
199
    private TextView detail_name, tv_fastNum, tv_slowNum, tv_charge, tv_service, tv_park, tv_cost_way, tv_zhong;
186
    private ImageView iv_back;
200
    String p1 = "", p2 = "", p3 = "";
187
    String p1 = "", p2 = "", p3 = "";
201
    private Marker currentClickedMarker;
202
    private Marker detailMarker;
203
    private int select;
188
    private int select;
204
    private LoadingDialog dialog;
189
    private LoadingDialog dialog;
205
    private LinearLayout ll_paoxiang, ll_share_ui;
206
    private RelativeLayout ll_comment, tv_notice;
207
    private TextView tv_num, tv_daohang, tvOne, tvTwo, tvThree, tv_start, tv_end;
208
    private double bd_lon, bd_lat, bd_jing, bd_wei;
209
    private PopupWindow popupWindow;
210
    private View popupWindowView;
211
    private Button cancleButton;
190
    private LinearLayout ll_share_ui;
191
    private RelativeLayout tv_notice;
192
    private TextView tv_num, tv_start, tv_end;
212
    private ImageView mIvMarkerBgYes, iv_screen;
193
    private ImageView mIvMarkerBgYes, iv_screen;
213
    private ScrollView sv;
194
    private ScrollView sv;
214
    private View mMarkerViewYes;
195
    private View mMarkerViewYes;
215
    private TextView tv_iknow, tv_setting, tv_route_name, tv_route_fast, tv_route_slow, tv_route_costway, tv_distance, tv_screenShot;
196
    private TextView tv_iknow, tv_route_fast, tv_route_slow, tv_route_costway, tv_distance, tv_screenShot;
216
    private RelativeLayout rl_yinying, rl_infowindow, rl_details, rl_routebtn, rl_share;
197
    private RelativeLayout rl_yinying, rl_infowindow, rl_details, rl_routebtn, rl_share;
217
    private boolean canRoute = false;
198
    private boolean canRoute = false;
218
    private boolean canSave = false;
199
    private boolean canSave = false;
222
    private RoueteInfoAdapter roueteInfoAdapter;
203
    private RoueteInfoAdapter roueteInfoAdapter;
223
    private float mLastTimeY;
204
    private float mLastTimeY;
224
    private TextView shaixuan_label;
205
    private TextView shaixuan_label;
225
226
    public void setEndLatlng(NaviLatLng endLatlng) {
227
        this.endLatlng = endLatlng;
228
    }
229
230
    private int zhan_num = 0;
206
    private int zhan_num = 0;
231
    private String tag = "";
207
    private String tag = "";
232
    private ImageView iv_setting, iv_screenShot;
208
    private ImageView iv_setting, iv_screenShot;
233
    private String mTime = "";
234
    private List<Zhan> list_zhan = new ArrayList<Zhan>();
209
    private List<Zhan> list_zhan = new ArrayList<Zhan>();
235
    ;
210
    ;
236
    private List<zhan_list> zhanDataList = new ArrayList<zhan_list>();
211
    private List<zhan_list> zhanDataList = new ArrayList<zhan_list>();
254
    private LinearLayout llOpen, ll;
229
    private LinearLayout llOpen, ll;
255
    private RelativeLayout rlRouteTip, activity_route_plan;
230
    private RelativeLayout rlRouteTip, activity_route_plan;
256
    private MyAutoLayout ll_route;
231
    private MyAutoLayout ll_route;
257
    private Zhan newZhan;
258
    private int noNameCount = 0;
232
    private int noNameCount = 0;
259
    private int haveNameCount = 0;
233
    private int haveNameCount = 0;
260
    private final String CAN_PAY_MARKER = "canPayMarker";
234
    private final String CAN_PAY_MARKER = "canPayMarker";
281
        dialog.show();
255
        dialog.show();
282
        mapView = (MapView) findViewById(R.id.mapview);
256
        mapView = (MapView) findViewById(R.id.mapview);
283
        mapView.onCreate(savedInstanceState);// 此方法必须重写
257
        mapView.onCreate(savedInstanceState);// 此方法必须重写
284
//        ttsManager = TTSController.getInstance(getApplicationContext());
285
//        ttsManager.init();
286
//        ttsManager.startSpeaking();
287
258
288
        // 初始化Marker添加到地图
259
        // 初始化Marker添加到地图
289
        initViews();
260
        initViews();
296
267
297
    private void initViews() {
268
    private void initViews() {
298
        ll = findViewById(R.id.ll);
269
        ll = findViewById(R.id.ll);
299
//        llView = findViewById(R.id.ll_view);
300
        activity_route_plan = findViewById(R.id.activity_route_plan);
270
        activity_route_plan = findViewById(R.id.activity_route_plan);
301
        ll_route = findViewById(R.id.ll_route);
271
        ll_route = findViewById(R.id.ll_route);
302
        tvRouteTips = findViewById(R.id.tv_route_tips);
272
        tvRouteTips = findViewById(R.id.tv_route_tips);
328
        tv_start = (TextView) findViewById(R.id.tv_start);
298
        tv_start = (TextView) findViewById(R.id.tv_start);
329
        tv_end = (TextView) findViewById(R.id.tv_end);
299
        tv_end = (TextView) findViewById(R.id.tv_end);
330
        rl_infowindow = (RelativeLayout) findViewById(R.id.rl_infowindow);
300
        rl_infowindow = (RelativeLayout) findViewById(R.id.rl_infowindow);
331
        tv_route_name = (TextView) findViewById(R.id.tv_route_name);
332
        tv_route_fast = (TextView) findViewById(R.id.tv_window_fast);
301
        tv_route_fast = (TextView) findViewById(R.id.tv_window_fast);
333
        tv_route_slow = (TextView) findViewById(R.id.tv_window_slow);
302
        tv_route_slow = (TextView) findViewById(R.id.tv_window_slow);
334
        tv_route_costway = (TextView) findViewById(R.id.tv_window_costway);
303
        tv_route_costway = (TextView) findViewById(R.id.tv_window_costway);
355
        });
324
        });
356
325
357
        tv_zhan_num = (TextView) findViewById(R.id.tv_zhan_num);
326
        tv_zhan_num = (TextView) findViewById(R.id.tv_zhan_num);
358
//        tv_screenShot = (TextView) findViewById(R.id.tv_screenShot);
359
//        tv_screenShot.setOnClickListener(this);
360
        mMarkerViewYes = LayoutInflater.from(this).inflate(R.layout.view_custom_yes, null);
327
        mMarkerViewYes = LayoutInflater.from(this).inflate(R.layout.view_custom_yes, null);
361
        mMarkerViewYes.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
328
        mMarkerViewYes.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
362
                LinearLayout.LayoutParams.WRAP_CONTENT));
329
                LinearLayout.LayoutParams.WRAP_CONTENT));
363
        mIvMarkerBgYes = (ImageView) mMarkerViewYes.findViewById(R.id.iv_icon);
330
        mIvMarkerBgYes = (ImageView) mMarkerViewYes.findViewById(R.id.iv_icon);
364
        rela_paopao = (RelativeLayout) findViewById(R.id.rela_paopao);
331
        rela_paopao = (RelativeLayout) findViewById(R.id.rela_paopao);
365
        detail_name = (TextView) findViewById(R.id.detail_name);
366
        tv_fastNum = (TextView) findViewById(R.id.tv_fastNum);
367
        tv_slowNum = (TextView) findViewById(R.id.tv_slowNum);
368
        tv_charge = (TextView) findViewById(R.id.tv_charge);
369
        tv_service = (TextView) findViewById(R.id.tv_service);
370
        tv_park = (TextView) findViewById(R.id.tv_park);
371
        tv_cost_way = (TextView) findViewById(R.id.tv_cost_way);
372
        rl_zhong = (RelativeLayout) findViewById(R.id.rl_zhong);
373
        tv_zhong = (TextView) findViewById(R.id.tv_zhong);
374
        iv_zhong = (ImageView) findViewById(R.id.iv_zhong);
375
        ll_share_ui = (LinearLayout) findViewById(R.id.ll_share_ui);
332
        ll_share_ui = (LinearLayout) findViewById(R.id.ll_share_ui);
376
333
377
334
395
        view1 = findViewById(R.id.view_1);
352
        view1 = findViewById(R.id.view_1);
396
        view2 = findViewById(R.id.view_2);
353
        view2 = findViewById(R.id.view_2);
397
354
398
        ll_paoxiang = (LinearLayout) findViewById(R.id.ll_paoxiang);
399
        ll_comment = (RelativeLayout) findViewById(R.id.ll_comment);
400
        tv_num = (TextView) findViewById(R.id.tv_num);
355
        tv_num = (TextView) findViewById(R.id.tv_num);
401
        tv_daohang = (TextView) findViewById(R.id.tv_daohang);
402
356
403
        tv_navigation_route = (TextView) findViewById(R.id.tv_navigation_route);
357
        tv_navigation_route = (TextView) findViewById(R.id.tv_navigation_route);
404
        tv_navigation_route.setOnClickListener(this);
358
        tv_navigation_route.setOnClickListener(this);
430
                                showListData(routeOverlays, routeNum);
384
                                showListData(routeOverlays, routeNum);
431
                                ivListStatus.setImageResource(R.drawable.icon_route_list_open);
385
                                ivListStatus.setImageResource(R.drawable.icon_route_list_open);
432
                                tvOpen.setText("显示地图");
386
                                tvOpen.setText("显示地图");
433
//                Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_route);
434
//                animation1.setDuration(2000);
435
                                lvRouteInfo.setVisibility(View.VISIBLE);
387
                                lvRouteInfo.setVisibility(View.VISIBLE);
436
                                AnimatorStart();
388
                                AnimatorStart();
437
                            } else {
389
                            } else {
468
            myLocationStyle.myLocationIcon(com.amap.api.maps.model.BitmapDescriptorFactory
420
            myLocationStyle.myLocationIcon(com.amap.api.maps.model.BitmapDescriptorFactory
469
                    .fromResource(R.drawable.point_icon));// 设置小蓝点的图标
421
                    .fromResource(R.drawable.point_icon));// 设置小蓝点的图标
470
            amap.setMyLocationStyle(myLocationStyle);
422
            amap.setMyLocationStyle(myLocationStyle);
471
            mUiSettings = amap.getUiSettings();
472
            //获得地图的最大和最小缩放级别
423
            //获得地图的最大和最小缩放级别
473
            maxZoomLevel = amap.getMaxZoomLevel();
474
            minZoomLevel = amap.getMinZoomLevel();
475
            geocoderSearch = new GeocodeSearch(this);
424
            geocoderSearch = new GeocodeSearch(this);
476
            geocoderSearch.setOnGeocodeSearchListener(this);
425
            geocoderSearch.setOnGeocodeSearchListener(this);
477
            setUpMap();
426
            setUpMap();
571
520
572
            }
521
            }
573
            if (list_zhong.size() > 0) {
522
            if (list_zhong.size() > 0) {
574
//                tv_navigation_route.setBackgroundResource(R.drawable.bg_route_btn_green);
575
//                tv_save_route.setBackgroundResource(R.drawable.bg_route_btn_green);
576
                canRoute = true;
523
                canRoute = true;
577
                canSave = true;
524
                canSave = true;
578
            }
525
            }
780
        super.onDestroy();
727
        super.onDestroy();
781
        mapView.onDestroy();
728
        mapView.onDestroy();
782
        aMapNavi.stopNavi();
729
        aMapNavi.stopNavi();
783
//        ttsManager.destroy();
784
        aMapNavi.destroy();
730
        aMapNavi.destroy();
785
    }
731
    }
786
732
798
        if (strategyFlag >= 0) {
744
        if (strategyFlag >= 0) {
799
            aMapNavi.calculateDriveRoute(startList, endList, null, strategyFlag);
745
            aMapNavi.calculateDriveRoute(startList, endList, null, strategyFlag);
800
            dialog.show();
746
            dialog.show();
801
//            ToastUtil.showToast(getApplicationContext(),"111",Toast.LENGTH_SHORT);
802
        }
747
        }
803
    }
748
    }
804
749
820
765
821
            //你可以通过对应的路径ID获得一条道路路径AMapNaviPath
766
            //你可以通过对应的路径ID获得一条道路路径AMapNaviPath
822
            AMapNaviPath path = null;
767
            AMapNaviPath path = null;
823
//
824
            path = (aMapNavi.getNaviPaths()).get(routeIds[i]);
768
            path = (aMapNavi.getNaviPaths()).get(routeIds[i]);
825
//            LogUtils.e(Arrays.toString(path.wayPointIndex));
826
//            LogUtils.e(path.getStepsCount());
827
//            LogUtils.e(Arrays.toString(path.getWayPointIndex()));
828
//            path.getSteps().get(1).getIconType();
829
830
            //你可以通过这个AMapNaviPath生成一个RouteOverLay用于加在地图上
769
            //你可以通过这个AMapNaviPath生成一个RouteOverLay用于加在地图上
831
            RouteOverLay routeOverLay = new RouteOverLay(amap, path, this);
770
            RouteOverLay routeOverLay = new RouteOverLay(amap, path, this);
832
            routeOverLay.setStartPointBitmap(drawableToBitamp(getResources().getDrawable(R.drawable.icon_newstarr)));
771
            routeOverLay.setStartPointBitmap(drawableToBitamp(getResources().getDrawable(R.drawable.icon_newstarr)));
842
            routePlanInfo.setDistance(routeOverlays.get(routeIds[i]).getAMapNaviPath().getAllLength() + "");
781
            routePlanInfo.setDistance(routeOverlays.get(routeIds[i]).getAMapNaviPath().getAllLength() + "");
843
782
844
            list.add(routePlanInfo);
783
            list.add(routePlanInfo);
845
846
//            routeOverlays.get(routeIds[i]).getAMapNaviPath().getSteps().get(i).getLength();
847
//            routeOverlays.get(routeIds[i]).getAMapNaviPath().getSteps().get(i).getIconType();
848
849
        }
784
        }
850
        Log.e("list_size===", list.size() + "");
785
        Log.e("list_size===", list.size() + "");
851
        updateView(list);
786
        updateView(list);
852
787
853
        routeOverlays.get(routeIds[0]).zoomToSpan();
788
        routeOverlays.get(routeIds[0]).zoomToSpan();
854
        aMapNavi.selectRouteId(routeIds[0]);
789
        aMapNavi.selectRouteId(routeIds[0]);
855
856
857
//        LogUtils.e(routePointInfo.toString());
858
//
859
//        LogUtils.e(routePointInfoList.size());
860
861
        routeIndex = 0;
790
        routeIndex = 0;
862
        calculateSuccess = true;
791
        calculateSuccess = true;
863
792
907
                routePointInfo.setRouteLength(getMToKm(String.valueOf(routeLength)));
836
                routePointInfo.setRouteLength(getMToKm(String.valueOf(routeLength)));
908
                routePointInfo.setRouteTime(getSToHm(String.valueOf(routeTime)));
837
                routePointInfo.setRouteTime(getSToHm(String.valueOf(routeTime)));
909
                routePointInfoList.add(routePointInfo);
838
                routePointInfoList.add(routePointInfo);
910
911
//                LogUtils.e(routePointInfo.toString());
912
913
                routeLength = 0;
839
                routeLength = 0;
914
                routeTime = 0;
840
                routeTime = 0;
915
841
1151
1077
1152
        //必须告诉AMapNavi 你最后选择的哪条路
1078
        //必须告诉AMapNavi 你最后选择的哪条路
1153
        aMapNavi.selectRouteId(routeIds[routeIndex]);
1079
        aMapNavi.selectRouteId(routeIds[routeIndex]);
1154
//        Toast.makeText(this, "导航距离:" + (aMapNavi.getNaviPaths()).get(routeIds[routeIndex]).getAllLength() + "m" + "\n" + "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[routeIndex]).getAllTime() + "s", Toast.LENGTH_SHORT).show();
1155
//        Toast.makeText(this, "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[routeIndex]).getStrategy() + "z", Toast.LENGTH_SHORT).show();
1156
        List<NaviLatLng> nl = (aMapNavi.getNaviPaths()).get(routeIds[routeIndex]).getCoordList();
1080
        List<NaviLatLng> nl = (aMapNavi.getNaviPaths()).get(routeIds[routeIndex]).getCoordList();
1157
//        Toast.makeText(this, nl.size() + "", Toast.LENGTH_SHORT).show();
1158
1159
1160
        routeIndex++;
1081
        routeIndex++;
1161
1162
        chooseRouteSuccess = true;
1082
        chooseRouteSuccess = true;
1163
//        getRouteZhan(nl);
1164
1165
    }
1083
    }
1166
1084
1167
    private void getRouteZhan(List<NaviLatLng> nl) {
1085
    private void getRouteZhan(List<NaviLatLng> nl) {
1220
                String conditionSql = " ( status = '4' and suit_car != '特斯拉' )  ";
1138
                String conditionSql = " ( status = '4' and suit_car != '特斯拉' )  ";
1221
1139
1222
                RangConditionStr = RangConditionStr.substring(0, RangConditionStr.lastIndexOf('O'));
1140
                RangConditionStr = RangConditionStr.substring(0, RangConditionStr.lastIndexOf('O'));
1223
1224
1225
                final String sql = "SELECT id,status,poi_jing,poi_wei,total_num,fast_num,slow_num,belong_attribute,suit_car,charge_cost_way,city,own_pay FROM zhan_list WHERE " + conditionSql + " AND " + RangConditionStr;
1141
                final String sql = "SELECT id,status,poi_jing,poi_wei,total_num,fast_num,slow_num,belong_attribute,suit_car,charge_cost_way,city,own_pay FROM zhan_list WHERE " + conditionSql + " AND " + RangConditionStr;
1226
1227
//                new Thread(new Runnable() {
1228
//                    @Override
1229
//                    public void run() {
1230
                getZhanListData(sql);
1142
                getZhanListData(sql);
1231
//                    }
1232
//                }).start();
1233
1234
                count = 0;
1143
                count = 0;
1235
                RangConditionStr = "";
1144
                RangConditionStr = "";
1236
            }
1145
            }
1249
                }
1158
                }
1250
            }).start();
1159
            }).start();
1251
        }
1160
        }
1252
1253
//        initOver(list_zhan);
1254
1255
    }
1161
    }
1256
1162
1257
    private void getZhanData() {
1163
    private void getZhanData() {
1369
                continue;
1275
                continue;
1370
            }
1276
            }
1371
            Double zhan_jing = Double.parseDouble(zhanDataList.get(i).getPoi_jing());
1277
            Double zhan_jing = Double.parseDouble(zhanDataList.get(i).getPoi_jing());
1372
//            Log.e(TAG, "getZhanPoint: zhan_jing="+zhan_jing );
1373
            Double zhan_wei = Double.parseDouble(zhanDataList.get(i).getPoi_wei());
1278
            Double zhan_wei = Double.parseDouble(zhanDataList.get(i).getPoi_wei());
1374
//            Log.e(TAG, "getZhanPoint: zhan_wei="+zhan_wei );
1375
            for (int j = 0; j < rectList.size(); j++) {
1279
            for (int j = 0; j < rectList.size(); j++) {
1376
                Double mMinLat = rectList.get(j).getMinLat();
1280
                Double mMinLat = rectList.get(j).getMinLat();
1377
//                Log.e(TAG, "getZhanPoint: mMinLat="+mMinLat );
1378
                Double mMinLon = rectList.get(j).getMinLon();
1281
                Double mMinLon = rectList.get(j).getMinLon();
1379
                Double mMaxLat = rectList.get(j).getMaxLat();
1282
                Double mMaxLat = rectList.get(j).getMaxLat();
1380
                Double mMaxLon = rectList.get(j).getMaxLon();
1283
                Double mMaxLon = rectList.get(j).getMaxLon();
1413
        try {
1316
        try {
1414
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
1317
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
1415
1318
1416
//            Log.e("sql===",sql);
1417
            Cursor cursor = db.rawQuery(sql, null);
1319
            Cursor cursor = db.rawQuery(sql, null);
1418
            Zhan zhan;
1320
            Zhan zhan;
1419
            while (cursor.moveToNext()) {
1321
            while (cursor.moveToNext()) {
1420
                zhan = new Zhan();
1322
                zhan = new Zhan();
1421
1323
1422
                zhan.setPoi_jing(cursor.getString(cursor.getColumnIndex("poi_jing")));
1324
                zhan.setPoi_jing(cursor.getString(cursor.getColumnIndex("poi_jing")));
1423
//                Log.e(k+"==",cursor.getString(cursor.getColumnIndex("poi_jing")));
1424
                zhan.setPoi_wei(cursor.getString(cursor.getColumnIndex("poi_wei")));
1325
                zhan.setPoi_wei(cursor.getString(cursor.getColumnIndex("poi_wei")));
1425
//                Log.e(k+"==",cursor.getString(cursor.getColumnIndex("poi_wei")));
1426
                zhan.setZhan_id(cursor.getString(cursor.getColumnIndex("id")));
1326
                zhan.setZhan_id(cursor.getString(cursor.getColumnIndex("id")));
1427
                zhan.setStatus(cursor.getString(cursor.getColumnIndex("status")));
1327
                zhan.setStatus(cursor.getString(cursor.getColumnIndex("status")));
1428
                zhan.setSuit_car(cursor.getString(cursor.getColumnIndex("suit_car")));
1328
                zhan.setSuit_car(cursor.getString(cursor.getColumnIndex("suit_car")));
1429
                zhan.setOwn_pay(cursor.getString(cursor.getColumnIndex("own_pay")));
1329
                zhan.setOwn_pay(cursor.getString(cursor.getColumnIndex("own_pay")));
1430
                list_zhan.add(zhan);
1330
                list_zhan.add(zhan);
1431
            }
1331
            }
1432
//            Log.e("size===",list_db.size()+"");
1433
//            Log.e("list===", list.size() + "");
1434
1435
//            new Thread(new Runnable() {
1436
//                @Override
1437
//                public void run() {
1438
//                    initOver(list);
1439
//                }
1440
//            }).start();
1441
1442
            cursor.close();
1332
            cursor.close();
1443
            db.close();
1333
            db.close();
1444
        } catch (Exception e) {
1334
        } catch (Exception e) {
1529
                    p3 = my[2];
1419
                    p3 = my[2];
1530
                }
1420
                }
1531
1421
1532
                Log.e("ssss", p1 + "---" + p2 + "---" + p3);
1533
                for (int i = 0; i < list.size(); i++) {
1422
                for (int i = 0; i < list.size(); i++) {
1534
                    if (!list.get(i).getPoi_wei().equals("") && !list.get(i).getPoi_jing().equals("")
1423
                    if (!list.get(i).getPoi_wei().equals("") && !list.get(i).getPoi_jing().equals("")
1535
                            && !String.valueOf(list.get(i).getId()).equals(p1) && !String.valueOf(list.get(i).getId()).equals(p2) && !String.valueOf(list.get(i).getId()).equals(p3)) {
1424
                            && !String.valueOf(list.get(i).getId()).equals(p1) && !String.valueOf(list.get(i).getId()).equals(p2) && !String.valueOf(list.get(i).getId()).equals(p3)) {
1540
                            ll = new LatLng(Double.parseDouble(list.get(i).getPoi_wei()), Double.parseDouble(list.get(i).getPoi_jing()));
1429
                            ll = new LatLng(Double.parseDouble(list.get(i).getPoi_wei()), Double.parseDouble(list.get(i).getPoi_jing()));
1541
                        } else if (position <= 13) {
1430
                        } else if (position <= 13) {
1542
                            double dwei = Double.parseDouble(list.get(i).getPoi_wei());
1431
                            double dwei = Double.parseDouble(list.get(i).getPoi_wei());
1543
//                System.out.print("wei:"+l.get(i).getPoi_wei());
1544
                            double djing = Double.parseDouble(list.get(i).getPoi_jing());
1432
                            double djing = Double.parseDouble(list.get(i).getPoi_jing());
1545
//                System.out.println("jing:"+l.get(i).getPoi_jing());
1546
                            getGaode(djing, dwei);
1433
                            getGaode(djing, dwei);
1547
1434
1548
                            ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
1435
                            ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
1680
1567
1681
    }
1568
    }
1682
1569
1683
//    @Override
1684
//    public void onArriveDestination(NaviStaticInfo naviStaticInfo) {
1685
//
1686
//    }
1687
//
1688
//    @Override
1689
//    public void onArriveDestination(AMapNaviStaticInfo aMapNaviStaticInfo) {
1690
//
1691
//    }
1692
//
1693
//    @Override
1694
//    public void onCalculateRouteSuccess() {
1695
//
1696
//    }
1697
1698
    @Override
1570
    @Override
1699
    public void onCalculateRouteFailure(int errorInfo) {
1571
    public void onCalculateRouteFailure(int errorInfo) {
1700
1572
1795
1667
1796
    public void chooseStart(View view) {
1668
    public void chooseStart(View view) {
1797
        Toast.makeText(this, "请在地图上点选起点", Toast.LENGTH_SHORT).show();
1669
        Toast.makeText(this, "请在地图上点选起点", Toast.LENGTH_SHORT).show();
1798
        mapClickStartReady = true;
1799
    }
1670
    }
1800
1671
1801
    public void chooseEnd(View view) {
1672
    public void chooseEnd(View view) {
1802
        Toast.makeText(this, "请在地图上点选终点", Toast.LENGTH_SHORT).show();
1673
        Toast.makeText(this, "请在地图上点选终点", Toast.LENGTH_SHORT).show();
1803
        mapClickEndReady = true;
1804
    }
1674
    }
1805
1675
1806
    public void goToGPSActivity(View view) {
1676
    public void goToGPSActivity(View view) {
1816
1686
1817
    @Override
1687
    @Override
1818
    public void activate(OnLocationChangedListener onLocationChangedListener) {
1688
    public void activate(OnLocationChangedListener onLocationChangedListener) {
1819
//        Toast.makeText(getApplicationContext(), "activate", Toast.LENGTH_SHORT).show();
1820
        mListener = onLocationChangedListener;
1689
        mListener = onLocationChangedListener;
1821
        if (mlocationClient == null) {
1690
        if (mlocationClient == null) {
1822
            mlocationClient = new AMapLocationClient(this);
1691
            mlocationClient = new AMapLocationClient(this);
1826
            //设置为高精度定位模式
1695
            //设置为高精度定位模式
1827
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
1696
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
1828
            mLocationOption.setGpsFirst(true);
1697
            mLocationOption.setGpsFirst(true);
1829
//            mLocationOption.setOnceLocation(true);
1830
            mLocationOption.setInterval(1500);
1698
            mLocationOption.setInterval(1500);
1831
1699
1832
            //设置是否强制刷新WIFI,默认为强制刷新
1700
            //设置是否强制刷新WIFI,默认为强制刷新
1866
                } catch (NullPointerException e) {
1734
                } catch (NullPointerException e) {
1867
                    e.printStackTrace();
1735
                    e.printStackTrace();
1868
                }
1736
                }
1869
//                ProfileManager.getInstance().setAtCity(getApplicationContext(), MainApplication.atCity);
1870
                center = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
1737
                center = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
1871
//                Toast.makeText(getApplicationContext(), "!!!" + amapLocation.getLongitude() + "---" + amapLocation.getLatitude(), Toast.LENGTH_SHORT).show();
1872
                mlocationClient.stopLocation();
1738
                mlocationClient.stopLocation();
1873
                dialog.cancel();
1739
                dialog.cancel();
1874
1740
1875
                initDatas();
1741
                initDatas();
1876
//                Log.e("!@#$",amapLocation.getLatitude()+"```"+amapLocation.getLongitude());
1877
////                Toast.makeText(this, amapLocation.getAddress(), Toast.LENGTH_SHORT).show();
1878
////                Toast.makeText(this, amapLocation.getCity(), Toast.LENGTH_SHORT).show();
1879
//                ete("{\"fun\":\"timer\"}");
1880
//                if (isFirstLoc) {
1881
//                    //设置缩放级别
1882
//                    aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
1883
//                    //将地图移动到定位点
1884
//                    aMap.moveCamera(CameraUpdateFactory.changeLatLng(center));
1885
//
1886
//                    //点击定位按钮 能够将地图的中心移动到定位点
1887
//                    mListener.onLocationChanged(amapLocation);
1888
//                    isFirstLoc = false;
1889
//                }
1890
//                initDatas();
1891
            } else {
1742
            } else {
1892
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
1743
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
1893
                Log.e("AmapErr", errText);
1744
                Log.e("AmapErr", errText);
1894
//                mLocationErrText.setVisibility(View.VISIBLE);
1895
                Toast.makeText(this, errText, Toast.LENGTH_SHORT).show();
1745
                Toast.makeText(this, errText, Toast.LENGTH_SHORT).show();
1896
            }
1746
            }
1897
        }
1747
        }
1902
        amap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
1752
        amap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
1903
        // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
1753
        // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
1904
        amap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
1754
        amap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
1905
//        aMap.moveCamera();
1906
//        amap.moveCamera(CameraUpdateFactory.zoomTo(14));
1907
1908
        Log.d("??", "!");
1909
    }
1755
    }
1910
1756
1911
    @Override
1757
    @Override
2003
                                for (int i = 0; i < changedScreenList.length; i++) {
1849
                                for (int i = 0; i < changedScreenList.length; i++) {
2004
                                    if (changedScreenList[i]) {
1850
                                    if (changedScreenList[i]) {
2005
                                        String t = "";
1851
                                        String t = "";
2006
                                        if (i==0){
1852
                                        if (i == 0) {
2007
                                            t = "红包站点";
1853
                                            t = "红包站点";
2008
                                        } else if (i == 1) {
1854
                                        } else if (i == 1) {
2009
                                            t = "免费停车";
1855
                                            t = "免费停车";
2029
            case R.id.rl_route_tip:
1875
            case R.id.rl_route_tip:
2030
                ivListStatus.setImageResource(R.drawable.icon_route_list_open);
1876
                ivListStatus.setImageResource(R.drawable.icon_route_list_open);
2031
                tvOpen.setText("显示地图");
1877
                tvOpen.setText("显示地图");
2032
//                Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_route);
2033
//                animation1.setDuration(2000);
2034
                lvRouteInfo.setVisibility(View.VISIBLE);
1878
                lvRouteInfo.setVisibility(View.VISIBLE);
2035
                AnimatorStart();
1879
                AnimatorStart();
2036
2037
//                llOpenView.startAnimation(animation1);
2038
                break;
1880
                break;
2039
            case R.id.ll_open:
1881
            case R.id.ll_open:
2040
                if (canRoute == false) {
1882
                if (canRoute == false) {
2044
                        showListData(routeOverlays, routeNum);
1886
                        showListData(routeOverlays, routeNum);
2045
                        ivListStatus.setImageResource(R.drawable.icon_route_list_open);
1887
                        ivListStatus.setImageResource(R.drawable.icon_route_list_open);
2046
                        tvOpen.setText("显示地图");
1888
                        tvOpen.setText("显示地图");
2047
//                Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_route);
2048
//                animation1.setDuration(2000);
2049
                        lvRouteInfo.setVisibility(View.VISIBLE);
1889
                        lvRouteInfo.setVisibility(View.VISIBLE);
2050
                        AnimatorStart();
1890
                        AnimatorStart();
2051
1891
2075
                dialog.show();
1915
                dialog.show();
2076
                new Handler().postDelayed(new Runnable() {
1916
                new Handler().postDelayed(new Runnable() {
2077
                    public void run() {
1917
                    public void run() {
2078
//                        showSimpleBottomSheetGrid();
2079
                        mapScreenShot();
1918
                        mapScreenShot();
2080
                    }
1919
                    }
2081
                }, 1000);
1920
                }, 1000);
2123
1962
2124
                    //必须告诉AMapNavi 你最后选择的哪条路
1963
                    //必须告诉AMapNavi 你最后选择的哪条路
2125
                    aMapNavi.selectRouteId(routeIds[0]);
1964
                    aMapNavi.selectRouteId(routeIds[0]);
2126
//                Toast.makeText(this, "导航距离:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getAllLength() + "m" + "\n" + "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getAllTime() + "s", Toast.LENGTH_SHORT).show();
2127
//                Toast.makeText(this, "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getStrategy() + "z", Toast.LENGTH_SHORT).show();
2128
                    final List<NaviLatLng> nl = (aMapNavi.getNaviPaths()).get(routeIds[0]).getCoordList();
1965
                    final List<NaviLatLng> nl = (aMapNavi.getNaviPaths()).get(routeIds[0]).getCoordList();
2129
//                Toast.makeText(this, (aMapNavi.getNaviPaths()).get(routeIds[0]).getStrategy(), Toast.LENGTH_SHORT).show();
2130
2131
2132
                    routeIndex++;
1966
                    routeIndex++;
2133
1967
2134
                    chooseRouteSuccess = true;
1968
                    chooseRouteSuccess = true;
2250
2084
2251
                    //必须告诉AMapNavi 你最后选择的哪条路
2085
                    //必须告诉AMapNavi 你最后选择的哪条路
2252
                    aMapNavi.selectRouteId(routeIds[2]);
2086
                    aMapNavi.selectRouteId(routeIds[2]);
2253
//                Toast.makeText(this, "导航距离:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getAllLength() + "m" + "\n" + "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getAllTime() + "s", Toast.LENGTH_SHORT).show();
2254
//                Toast.makeText(this, "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[2]).getStrategy() + "z", Toast.LENGTH_SHORT).show();
2255
                    final List<NaviLatLng> nlll = (aMapNavi.getNaviPaths()).get(routeIds[2]).getCoordList();
2087
                    final List<NaviLatLng> nlll = (aMapNavi.getNaviPaths()).get(routeIds[2]).getCoordList();
2256
2257
//                Toast.makeText(this, (aMapNavi.getNaviPaths()).get(routeIds[2]).getStrategy(), Toast.LENGTH_SHORT).show();
2258
2259
2260
                    routeIndex++;
2088
                    routeIndex++;
2261
2089
2262
                    chooseRouteSuccess = true;
2090
                    chooseRouteSuccess = true;
2286
                        MobclickAgent.onEvent(getApplicationContext(), "0308");
2114
                        MobclickAgent.onEvent(getApplicationContext(), "0308");
2287
                        if ("0".equals(save_id)) {
2115
                        if ("0".equals(save_id)) {
2288
                            if (noNameCount == haveNameCount)
2116
                            if (noNameCount == haveNameCount)
2289
//                                LogUtils.e(noNameCount+"---"+haveNameCount);
2290
                                creatSaveData();
2117
                                creatSaveData();
2291
                        } else {
2118
                        } else {
2292
                            AlertDialog.Builder builder = new AlertDialog.Builder(RoutePlanMapActivity.this);
2119
                            AlertDialog.Builder builder = new AlertDialog.Builder(RoutePlanMapActivity.this);
2297
                                @Override
2124
                                @Override
2298
                                public void onClick(DialogInterface dialog, int which) {
2125
                                public void onClick(DialogInterface dialog, int which) {
2299
                                    if (noNameCount == haveNameCount)
2126
                                    if (noNameCount == haveNameCount)
2300
//                                        LogUtils.e(noNameCount+"---"+haveNameCount);
2301
                                        creatSaveData();
2127
                                        creatSaveData();
2302
                                }
2128
                                }
2303
                            });
2129
                            });
2317
                } else {
2143
                } else {
2318
                    if (select == 0) {
2144
                    if (select == 0) {
2319
                        exchangeView(1);
2145
                        exchangeView(1);
2320
//                        amap.clear();
2321
                        for (int i = 0; i < routeIds.length; i++) {
2146
                        for (int i = 0; i < routeIds.length; i++) {
2322
                            AMapNaviPath path = (aMapNavi.getNaviPaths()).get(routeIds[i]);
2147
                            AMapNaviPath path = (aMapNavi.getNaviPaths()).get(routeIds[i]);
2323
                            //你可以通过这个AMapNaviPath生成一个RouteOverLay用于加在地图上
2148
                            //你可以通过这个AMapNaviPath生成一个RouteOverLay用于加在地图上
2344
2169
2345
                        }
2170
                        }
2346
                        routeOverlays.get(routeIds[0]).setTransparency(0.8f);
2171
                        routeOverlays.get(routeIds[0]).setTransparency(0.8f);
2347
2348
2349
                        //必须告诉AMapNavi 你最后选择的哪条路
2172
                        //必须告诉AMapNavi 你最后选择的哪条路
2350
                        aMapNavi.selectRouteId(routeIds[0]);
2173
                        aMapNavi.selectRouteId(routeIds[0]);
2351
//                Toast.makeText(this, "导航距离:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getAllLength() + "m" + "\n" + "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getAllTime() + "s", Toast.LENGTH_SHORT).show();
2352
//                Toast.makeText(this, "导航时间:" + (aMapNavi.getNaviPaths()).get(routeIds[0]).getStrategy() + "z", Toast.LENGTH_SHORT).show();
2353
                        List<NaviLatLng> nnll = (aMapNavi.getNaviPaths()).get(routeIds[0]).getCoordList();
2174
                        List<NaviLatLng> nnll = (aMapNavi.getNaviPaths()).get(routeIds[0]).getCoordList();
2354
//                Toast.makeText(this, (aMapNavi.getNaviPaths()).get(routeIds[0]).getStrategy(), Toast.LENGTH_SHORT).show();
2355
2356
2357
                        routeIndex++;
2175
                        routeIndex++;
2358
2176
2359
                        chooseRouteSuccess = true;
2177
                        chooseRouteSuccess = true;
2360
//                        if (nnll != null) {
2361
//                            getRouteZhan(nnll);
2362
//                        }
2363
                    }
2178
                    }
2364
                    if (chooseRouteSuccess && calculateSuccess) {
2179
                    if (chooseRouteSuccess && calculateSuccess) {
2365
                        MobclickAgent.onEvent(getApplicationContext(), "0309");
2180
                        MobclickAgent.onEvent(getApplicationContext(), "0309");
2392
2207
2393
                break;
2208
                break;
2394
            case R.id.iv_back:
2209
            case R.id.iv_back:
2395
//                tag = 0;
2396
                finish();
2210
                finish();
2397
//                amap.setLocationSource(this);// 设置定位监听
2398
//            amap.setMyLocationEnabled(true);// 是否可触发定位并显示定位层
2399
////            ?aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
2400
//            mlocationClient.startLocation();
2401
                break;
2211
                break;
2402
            default:
2212
            default:
2403
                break;
2213
                break;
2594
                        }
2404
                        }
2595
                        if (strategyFlag >= 0) {
2405
                        if (strategyFlag >= 0) {
2596
                            aMapNavi.calculateDriveRoute(startList, endList, zhongList, strategyFlag);
2406
                            aMapNavi.calculateDriveRoute(startList, endList, zhongList, strategyFlag);
2597
//                                                Toast.makeText(getApplicationContext(), "策略:" + strategyFlag, Toast.LENGTH_LONG).show();
2598
                        }
2407
                        }
2599
                        rl_infowindow.setVisibility(View.GONE);
2408
                        rl_infowindow.setVisibility(View.GONE);
2600
                    } else {
2409
                    } else {
2726
2535
2727
    }
2536
    }
2728
2537
2729
    private void getBaidu(Double jing, Double wei) {
2730
        double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
2731
        double x = jing;
2732
        double y = wei;
2733
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
2734
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
2735
        bd_lon = z * Math.cos(theta) + 0.0065;
2736
        bd_lat = z * Math.sin(theta) + 0.006;
2737
    }
2738
2739
    private boolean isAvilible(Context context, String packageName) {
2740
        //获取packagemanager
2741
        final PackageManager packageManager = context.getPackageManager();
2742
        //获取所有已安装程序的包信息
2743
        List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
2744
        //用于存储所有已安装程序的包名
2745
        List<String> packageNames = new ArrayList<String>();
2746
        //从pinfo中将包名字逐一取出,压入pName list中
2747
        if (packageInfos != null) {
2748
            for (int i = 0; i < packageInfos.size(); i++) {
2749
                String packName = packageInfos.get(i).packageName;
2750
                packageNames.add(packName);
2751
            }
2752
        }
2753
        //判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE
2754
        return packageNames.contains(packageName);
2755
    }
2756
2757
    public static Bitmap getBitmapFromView(View view) {
2538
    public static Bitmap getBitmapFromView(View view) {
2758
        view.destroyDrawingCache();
2539
        view.destroyDrawingCache();
2759
        view.measure(View.MeasureSpec.makeMeasureSpec(0,
2540
        view.measure(View.MeasureSpec.makeMeasureSpec(0,