|
@ -1,23 +1,29 @@
|
1
|
1
|
package com.electric.chargingpile.activity;
|
2
|
2
|
|
3
|
|
import android.app.ProgressDialog;
|
|
3
|
import android.content.Context;
|
4
|
4
|
import android.content.Intent;
|
|
5
|
import android.content.pm.PackageInfo;
|
|
6
|
import android.content.pm.PackageManager;
|
5
|
7
|
import android.graphics.Color;
|
|
8
|
import android.graphics.drawable.BitmapDrawable;
|
6
|
9
|
import android.support.constraint.ConstraintLayout;
|
7
|
10
|
import android.support.v7.app.AppCompatActivity;
|
8
|
11
|
import android.os.Bundle;
|
9
|
12
|
import android.support.v7.widget.LinearLayoutManager;
|
10
|
13
|
import android.support.v7.widget.RecyclerView;
|
11
|
|
import android.util.Log;
|
|
14
|
import android.view.Gravity;
|
12
|
15
|
import android.view.LayoutInflater;
|
13
|
16
|
import android.view.View;
|
14
|
17
|
import android.view.ViewGroup;
|
15
|
18
|
import android.widget.Button;
|
16
|
19
|
import android.widget.ImageView;
|
17
|
20
|
import android.widget.LinearLayout;
|
|
21
|
import android.widget.PopupWindow;
|
18
|
22
|
import android.widget.TextView;
|
19
|
23
|
import android.widget.Toast;
|
20
|
24
|
|
|
25
|
import com.amap.api.maps.AMapUtils;
|
|
26
|
import com.amap.api.maps.model.LatLng;
|
21
|
27
|
import com.electric.chargingpile.R;
|
22
|
28
|
import com.electric.chargingpile.application.MainApplication;
|
23
|
29
|
import com.electric.chargingpile.data.RecommendZhan;
|
|
@ -25,10 +31,14 @@ import com.electric.chargingpile.util.BarColorUtil;
|
25
|
31
|
import com.electric.chargingpile.util.JsonUtils;
|
26
|
32
|
import com.electric.chargingpile.util.LoadingDialog;
|
27
|
33
|
import com.electric.chargingpile.util.ToastUtil;
|
|
34
|
import com.electric.chargingpile.util.Util;
|
|
35
|
import com.umeng.analytics.MobclickAgent;
|
28
|
36
|
import com.zhy.http.okhttp.OkHttpUtils;
|
29
|
37
|
import com.zhy.http.okhttp.callback.StringCallback;
|
30
|
38
|
|
|
39
|
import java.net.URISyntaxException;
|
31
|
40
|
import java.util.ArrayList;
|
|
41
|
import java.util.HashMap;
|
32
|
42
|
import java.util.List;
|
33
|
43
|
|
34
|
44
|
import okhttp3.Call;
|
|
@ -37,8 +47,14 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
37
|
47
|
private static final String TAG = "RecommendChargingStationActivity";
|
38
|
48
|
List<RecommendZhan> recommendZhanList;
|
39
|
49
|
private LoadingDialog loadingDialog;
|
40
|
|
private String center_jing = "";
|
41
|
|
private String center_wei = "";
|
|
50
|
private View popupWindowView;
|
|
51
|
private PopupWindow popupWindow;
|
|
52
|
private Button cancleButton;
|
|
53
|
private TextView tvOne, tvTwo, tvThree;
|
|
54
|
private Double bd_lon, bd_lat, bd_jing, bd_wei;
|
|
55
|
|
|
56
|
private String center_jing, center_wei, gd_jing, gd_wei, bd_jing1, bd_wei1;
|
|
57
|
private LatLng center;
|
42
|
58
|
private RecommendChargingStationActivity activity;
|
43
|
59
|
|
44
|
60
|
private LinearLayout first_condition;
|
|
@ -84,6 +100,8 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
84
|
100
|
center_jing = getIntent().getStringExtra("center_jing");
|
85
|
101
|
center_wei = getIntent().getStringExtra("center_wei");
|
86
|
102
|
|
|
103
|
center = new LatLng(Double.parseDouble(center_wei), Double.parseDouble(center_jing));
|
|
104
|
|
87
|
105
|
findViewById(R.id.iv_back).setOnClickListener(this);
|
88
|
106
|
|
89
|
107
|
first_condition = findViewById(R.id.first_condition);
|
|
@ -274,6 +292,28 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
274
|
292
|
String data = JsonUtils.getKeyResult(response, "data");
|
275
|
293
|
List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
|
276
|
294
|
if (list != null) {
|
|
295
|
|
|
296
|
for (int i = 0; i < list.size(); i++) {
|
|
297
|
String wei = list.get(i).getPoi_wei().trim();
|
|
298
|
String jing = list.get(i).getPoi_jing().trim();
|
|
299
|
|
|
300
|
int position_jing = jing.length() - jing.indexOf(".") - 1;
|
|
301
|
int position_wei = wei.length() - wei.indexOf(".") - 1;
|
|
302
|
|
|
303
|
|
|
304
|
LatLng ll;
|
|
305
|
if (position_jing > 13 || position_wei > 13) {
|
|
306
|
ll = new LatLng(Double.parseDouble(wei), Double.parseDouble(jing));
|
|
307
|
} else {
|
|
308
|
double dwei = Double.parseDouble(wei);
|
|
309
|
double djing = Double.parseDouble(jing);
|
|
310
|
getGaode(djing, dwei);
|
|
311
|
ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
|
|
312
|
}
|
|
313
|
|
|
314
|
double d = AMapUtils.calculateLineDistance(center, ll);
|
|
315
|
list.get(i).setDistance(Util.getDistance(d));
|
|
316
|
}
|
277
|
317
|
recommendZhanList = list;
|
278
|
318
|
recommendChargingStationAdapter.setData(list);
|
279
|
319
|
}
|
|
@ -287,8 +327,9 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
287
|
327
|
private List<RecommendZhan> mList;
|
288
|
328
|
|
289
|
329
|
class ViewHolder extends RecyclerView.ViewHolder {
|
290
|
|
|
|
330
|
final LinearLayout station_item;
|
291
|
331
|
final TextView zhan_name;
|
|
332
|
final TextView distance;
|
292
|
333
|
final ImageView red_pager_bag_icon;
|
293
|
334
|
final Button recommend_nav;
|
294
|
335
|
final ImageView score_img;
|
|
@ -309,10 +350,11 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
309
|
350
|
final TextView slow_free;
|
310
|
351
|
final TextView slow_free_num;
|
311
|
352
|
|
312
|
|
|
313
|
353
|
public ViewHolder(View itemView) {
|
314
|
354
|
super(itemView);
|
|
355
|
station_item = itemView.findViewById(R.id.station_item);
|
315
|
356
|
zhan_name = itemView.findViewById(R.id.zhan_name);
|
|
357
|
distance = itemView.findViewById(R.id.distance);
|
316
|
358
|
red_pager_bag_icon = itemView.findViewById(R.id.red_paper_bag);
|
317
|
359
|
recommend_nav = itemView.findViewById(R.id.recommend_nav);
|
318
|
360
|
score_img = itemView.findViewById(R.id.score_img);
|
|
@ -357,7 +399,22 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
357
|
399
|
@Override
|
358
|
400
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
359
|
401
|
RecommendZhan recommendZhan = mList.get(position);
|
|
402
|
|
|
403
|
holder.station_item.setOnClickListener(new View.OnClickListener() {
|
|
404
|
@Override
|
|
405
|
public void onClick(View v) {
|
|
406
|
Intent intent = new Intent(getApplication(),
|
|
407
|
NewZhanDetailsActivity.class);
|
|
408
|
intent.putExtra("zhan_id", recommendZhan.getId());
|
|
409
|
startActivity(intent);
|
|
410
|
}
|
|
411
|
});
|
360
|
412
|
holder.zhan_name.setText(recommendZhan.getZhan_name());
|
|
413
|
if ("0m".equals(recommendZhan.getDistance())) {
|
|
414
|
holder.distance.setText("未知");
|
|
415
|
} else {
|
|
416
|
holder.distance.setText(recommendZhan.getDistance());
|
|
417
|
}
|
361
|
418
|
if ("1".equals(recommendZhan.getOwn_pay())) {
|
362
|
419
|
holder.red_pager_bag_icon.setVisibility(View.VISIBLE);
|
363
|
420
|
} else {
|
|
@ -374,19 +431,41 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
374
|
431
|
}
|
375
|
432
|
});
|
376
|
433
|
|
|
434
|
holder.recommend_nav.setOnClickListener(new View.OnClickListener() {
|
|
435
|
@Override
|
|
436
|
public void onClick(View v) {
|
|
437
|
recommendNav(recommendZhan);
|
|
438
|
}
|
|
439
|
});
|
|
440
|
|
377
|
441
|
showStarInfoView(holder, recommendZhan);
|
378
|
442
|
if (recommendZhan.getCharge_record_cnt() == 0) {
|
379
|
443
|
holder.charge_record_cnt.setVisibility(View.GONE);
|
380
|
444
|
} else {
|
381
|
445
|
holder.charge_record_cnt.setVisibility(View.VISIBLE);
|
382
|
|
holder.charge_record_cnt.setText(recommendZhan.getCharge_record_cnt() + "次充电成功");
|
|
446
|
|
|
447
|
if (recommendZhan.getCharge_record_cnt() < 1000) {
|
|
448
|
holder.charge_record_cnt.setText(recommendZhan.getCharge_record_cnt() + "次充电成功");
|
|
449
|
} else if (recommendZhan.getCharge_record_cnt() < 10000) {
|
|
450
|
holder.charge_record_cnt.setText(recommendZhan.getCharge_record_cnt() / 1000 + "k+次充电成功");
|
|
451
|
} else {
|
|
452
|
holder.charge_record_cnt.setText(recommendZhan.getCharge_record_cnt() / 10000 + "w+次充电成功");
|
|
453
|
}
|
|
454
|
|
383
|
455
|
}
|
384
|
456
|
|
385
|
457
|
if (recommendZhan.getComment_cnt() == 0) {
|
386
|
458
|
holder.comment_cnt.setVisibility(View.GONE);
|
387
|
459
|
} else {
|
388
|
460
|
holder.comment_cnt.setVisibility(View.VISIBLE);
|
389
|
|
holder.comment_cnt.setText(recommendZhan.getComment_cnt() + "次评论");
|
|
461
|
if (recommendZhan.getComment_cnt() < 1000) {
|
|
462
|
holder.comment_cnt.setText(recommendZhan.getComment_cnt() + "次评论");
|
|
463
|
} else if (recommendZhan.getComment_cnt() < 10000) {
|
|
464
|
holder.comment_cnt.setText(recommendZhan.getComment_cnt() / 1000 + "k+次评论");
|
|
465
|
} else {
|
|
466
|
holder.comment_cnt.setText(recommendZhan.getComment_cnt() / 10000 + "w+次评论");
|
|
467
|
}
|
|
468
|
|
390
|
469
|
}
|
391
|
470
|
|
392
|
471
|
if (recommendZhan.getComment_cnt() == 0 || recommendZhan.getCharge_record_cnt() == 0 && recommendZhan.getComment_cnt() == 0) {
|
|
@ -474,6 +553,174 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
|
474
|
553
|
holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_5xing));
|
475
|
554
|
}
|
476
|
555
|
}
|
|
556
|
|
|
557
|
private void recommendNav(RecommendZhan rz) {
|
|
558
|
|
|
559
|
String wei = rz.getPoi_wei().trim();
|
|
560
|
String jing = rz.getPoi_jing().trim();
|
|
561
|
int position_jing = jing.length() - jing.indexOf(".") - 1;
|
|
562
|
int position_wei = wei.length() - wei.indexOf(".") - 1;
|
|
563
|
final LatLng ll;
|
|
564
|
if (position_jing > 13 || position_wei > 13) {
|
|
565
|
ll = new LatLng(Double.parseDouble(wei), Double.parseDouble(jing));
|
|
566
|
} else {
|
|
567
|
double dwei = Double.parseDouble(wei);
|
|
568
|
double djing = Double.parseDouble(jing);
|
|
569
|
getGaode(djing, dwei);
|
|
570
|
ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
|
|
571
|
}
|
|
572
|
|
|
573
|
if (!isAvilible(getApplicationContext(), "com.baidu.BaiduMap") &&
|
|
574
|
!isAvilible(getApplicationContext(), "com.autonavi.minimap")) {
|
|
575
|
Intent intent = new Intent(getApplication(), BasicNaviActivity.class);
|
|
576
|
intent.putExtra("start_jing", center.longitude + "");
|
|
577
|
intent.putExtra("start_wei", center.latitude + "");
|
|
578
|
intent.putExtra("stop_jing", ll.longitude + "");
|
|
579
|
intent.putExtra("stop_wei", ll.latitude + "");
|
|
580
|
startActivity(intent);
|
|
581
|
} else {
|
|
582
|
if (center != null) {
|
|
583
|
LayoutInflater inflater1 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
584
|
popupWindowView = inflater1.inflate(R.layout.item_selectmap, null);
|
|
585
|
popupWindow = new PopupWindow(popupWindowView,
|
|
586
|
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT,
|
|
587
|
true);
|
|
588
|
popupWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
589
|
// 设置PopupWindow的弹出和消失效果
|
|
590
|
popupWindow.setAnimationStyle(R.style.popupAnimation);
|
|
591
|
LinearLayout ll_tvTwo = (LinearLayout) popupWindowView.findViewById(R.id.ll_tvTwo);
|
|
592
|
if (!isAvilible(getApplicationContext(), "com.autonavi.minimap")) {
|
|
593
|
ll_tvTwo.setVisibility(View.GONE);
|
|
594
|
}
|
|
595
|
LinearLayout ll_tvOne = (LinearLayout) popupWindowView.findViewById(R.id.ll_tvOne);
|
|
596
|
if (!isAvilible(getApplicationContext(), "com.baidu.BaiduMap")) {
|
|
597
|
ll_tvOne.setVisibility(View.GONE);
|
|
598
|
}
|
|
599
|
cancleButton = (Button) popupWindowView
|
|
600
|
.findViewById(R.id.cancleButton);
|
|
601
|
cancleButton.setOnClickListener(new View.OnClickListener() {
|
|
602
|
@Override
|
|
603
|
public void onClick(View view) {
|
|
604
|
popupWindow.dismiss();
|
|
605
|
}
|
|
606
|
});
|
|
607
|
tvThree = (TextView) popupWindowView.findViewById(R.id.tvThree);
|
|
608
|
tvThree.setOnClickListener(new View.OnClickListener() {
|
|
609
|
@Override
|
|
610
|
public void onClick(View v) {
|
|
611
|
Intent intent = new Intent(getApplication(), BasicNaviActivity.class);
|
|
612
|
intent.putExtra("start_jing", center.longitude + "");
|
|
613
|
intent.putExtra("start_wei", center.latitude + "");
|
|
614
|
intent.putExtra("stop_jing", ll.longitude + "");
|
|
615
|
intent.putExtra("stop_wei", ll.latitude + "");
|
|
616
|
startActivity(intent);
|
|
617
|
popupWindow.dismiss();
|
|
618
|
}
|
|
619
|
});
|
|
620
|
tvOne = (TextView) popupWindowView.findViewById(R.id.tvOne);
|
|
621
|
tvOne.setOnClickListener(new View.OnClickListener() {
|
|
622
|
@Override
|
|
623
|
public void onClick(View view) {
|
|
624
|
Intent intent = null;
|
|
625
|
int position_jing = rz.getPoi_jing().length() - rz.getPoi_jing().indexOf(".") - 1;
|
|
626
|
int position_wei = rz.getPoi_wei().length() - rz.getPoi_wei().indexOf(".") - 1;
|
|
627
|
if (position_jing > 13 || position_wei > 13) {
|
|
628
|
getBaidu1(Double.parseDouble(rz.getPoi_jing()), Double.parseDouble(rz.getPoi_wei()));
|
|
629
|
} else {
|
|
630
|
bd_jing = Double.parseDouble(rz.getPoi_jing());
|
|
631
|
bd_wei = Double.parseDouble(rz.getPoi_wei());
|
|
632
|
}
|
|
633
|
getBaidu(center.longitude, center.latitude);
|
|
634
|
try {
|
|
635
|
String s = "intent://map/direction?" +
|
|
636
|
"origin=" + bd_lat + "," + bd_lon + "&" +
|
|
637
|
"destination=" + bd_wei + "," + bd_jing +
|
|
638
|
"&mode=driving&" +
|
|
639
|
"src=充电桩#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end";
|
|
640
|
intent = Intent.getIntent(s);
|
|
641
|
} catch (URISyntaxException e) {
|
|
642
|
e.printStackTrace();
|
|
643
|
}
|
|
644
|
startActivity(intent);
|
|
645
|
popupWindow.dismiss();
|
|
646
|
}
|
|
647
|
});
|
|
648
|
tvTwo = (TextView) popupWindowView.findViewById(R.id.tvTwo);
|
|
649
|
tvTwo.setOnClickListener(new View.OnClickListener() {
|
|
650
|
@Override
|
|
651
|
public void onClick(View view) {
|
|
652
|
try {
|
|
653
|
Intent intent4 = new Intent("android.intent.action.VIEW",
|
|
654
|
android.net.Uri.parse("androidamap://route?sourceApplication=amap&slat=" + center.latitude + "&slon=" + center.longitude + "&sname=我的位置&dlat=" + ll.latitude + "&dlon=" + ll.longitude + "&dname=" + rz.getZhan_name() + "&dev=0&m=0&t=2"));
|
|
655
|
intent4.setPackage("com.autonavi.minimap");
|
|
656
|
startActivity(intent4);
|
|
657
|
popupWindow.dismiss();
|
|
658
|
} catch (Exception e) {
|
|
659
|
e.printStackTrace();
|
|
660
|
Toast.makeText(getApplication(), "请您确认是否安装高德地图APP", Toast.LENGTH_SHORT).show();
|
|
661
|
}
|
|
662
|
|
|
663
|
}
|
|
664
|
});
|
|
665
|
popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0);
|
|
666
|
} else {
|
|
667
|
Toast.makeText(getApplication(),
|
|
668
|
"没有定位到您的当前位置", Toast.LENGTH_SHORT)
|
|
669
|
.show();
|
|
670
|
}
|
|
671
|
}
|
|
672
|
}
|
|
673
|
|
|
674
|
private boolean isAvilible(Context context, String packageName) {
|
|
675
|
//获取packagemanager
|
|
676
|
final PackageManager packageManager = context.getPackageManager();
|
|
677
|
//获取所有已安装程序的包信息
|
|
678
|
List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
|
|
679
|
//用于存储所有已安装程序的包名
|
|
680
|
List<String> packageNames = new ArrayList<String>();
|
|
681
|
//从pinfo中将包名字逐一取出,压入pName list中
|
|
682
|
if (packageInfos != null) {
|
|
683
|
for (int i = 0; i < packageInfos.size(); i++) {
|
|
684
|
String packName = packageInfos.get(i).packageName;
|
|
685
|
packageNames.add(packName);
|
|
686
|
}
|
|
687
|
}
|
|
688
|
//判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE
|
|
689
|
return packageNames.contains(packageName);
|
|
690
|
}
|
|
691
|
|
|
692
|
private void getBaidu(Double jing, Double wei) {
|
|
693
|
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
|
694
|
double x = jing;
|
|
695
|
double y = wei;
|
|
696
|
double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
|
|
697
|
double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
|
|
698
|
bd_lon = z * Math.cos(theta) + 0.0065;
|
|
699
|
bd_lat = z * Math.sin(theta) + 0.006;
|
|
700
|
}
|
|
701
|
|
|
702
|
private void getBaidu1(Double jing, Double wei) {
|
|
703
|
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
|
704
|
double x = jing;
|
|
705
|
double y = wei;
|
|
706
|
double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
|
|
707
|
double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
|
|
708
|
bd_jing = z * Math.cos(theta) + 0.0065;
|
|
709
|
bd_wei = z * Math.sin(theta) + 0.006;
|
|
710
|
}
|
|
711
|
}
|
|
712
|
|
|
713
|
private void getGaode(Double jing, Double wei) {
|
|
714
|
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
|
715
|
double gg_lon;
|
|
716
|
double gg_lat;
|
|
717
|
double x = jing - 0.0065, y = wei - 0.006;
|
|
718
|
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
|
|
719
|
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
|
|
720
|
gg_lon = z * Math.cos(theta);
|
|
721
|
gd_jing = String.valueOf(gg_lon);
|
|
722
|
gg_lat = z * Math.sin(theta);
|
|
723
|
gd_wei = String.valueOf(gg_lat);
|
477
|
724
|
}
|
478
|
725
|
|
479
|
726
|
}
|