Quellcode durchsuchen

气泡功能咖啡

huyuguo vor 5 Jahren
Ursprung
Commit
b54a935e28

+ 67 - 3
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

@ -171,7 +171,8 @@ import pub.devrel.easypermissions.EasyPermissions;
171 171
172 172
public class MainMapActivity extends Activity implements LocationSource, AMapLocationListener,
173 173
        View.OnClickListener, AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMapClickListener,
174
        ClusterRender, ClusterClickListener, WeatherSearch.OnWeatherSearchListener, EasyPermissions.PermissionCallbacks {
174
        ClusterRender, ClusterClickListener, WeatherSearch.OnWeatherSearchListener, EasyPermissions.PermissionCallbacks,
175
        AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener {
175 176
    private static final String TAG = "MainMapActivity";
176 177
    public static String screen_jing = "", screen_wei = "";
177 178
    public static String location_city = "";
@ -736,6 +737,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
736 737
            }
737 738
        }
738 739
    };
740
    private View infoWindow;
739 741
740 742
741 743
    @Override
@ -1483,6 +1485,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1483 1485
        aMap.setOnCameraChangeListener(this);
1484 1486
        aMap.setLocationSource(this);// 设置定位监听
1485 1487
        aMap.setOnMapClickListener(this);
1488
        aMap.setOnMarkerClickListener(this);
1489
        aMap.setInfoWindowAdapter(this);
1490
        aMap.setOnInfoWindowClickListener(this);
1486 1491
        aMap.setOnMapLoadedListener(this);// 设置amap加载成功事件监听器
1487 1492
        aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
1488 1493
        aMap.getUiSettings().setZoomControlsEnabled(false);// 设置默认缩放按钮是否显示
@ -3398,6 +3403,57 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3398 3403
        }
3399 3404
    }
3400 3405
3406
    @Override
3407
    public boolean onMarkerClick(Marker marker) {
3408
        return false;
3409
    }
3410
3411
    /**
3412
     * 监听自定义infowindow窗口的infowindow时间回调
3413
     * add by huyuguo
3414
     * @param marker
3415
     * @return
3416
     */
3417
    @Override
3418
    public View getInfoWindow(Marker marker) {
3419
        if (infoWindow == null) {
3420
            infoWindow = getLayoutInflater().inflate(R.layout.custom_info_window, null);
3421
        }
3422
        return infoWindow;
3423
    }
3424
3425
    @Override
3426
    public View getInfoContents(Marker marker) {
3427
        return null;
3428
    }
3429
3430
    /**
3431
     * 自定义infowindow窗口
3432
     * 如果想修改自定义Infow中内容,请通过view找到它并修改
3433
     */
3434
    public void updateInfoWindow(String text) {
3435
        if (nMarker == null) {
3436
            return;
3437
        }
3438
3439
        if (infoWindow == null) {
3440
            return;
3441
        }
3442
3443
        TextView distance = infoWindow.findViewById(R.id.distance);
3444
        distance.setText(text);
3445
3446
    }
3447
3448
    /**
3449
     * 点击自定义气泡,进行导航操作
3450
     * @param marker
3451
     */
3452
    @Override
3453
    public void onInfoWindowClick(Marker marker) {
3454
        ToastUtil.showToast(getApplicationContext(), "sdsfsdf", Toast.LENGTH_SHORT);
3455
    }
3456
3401 3457
    public class ZhanAdapter extends BaseAdapter {
3402 3458
        @Override
3403 3459
        public int getCount() {
@ -4914,6 +4970,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4914 4970
//            Log.d(TAG, "onClick: latitude=" + position.latitude + "   long=" + position.longitude + "\n" + ((RegionItem) clusterItem).getChargePoint().toString());
4915 4971
            Long zhan_id = ((RegionItem) clusterItem).getChargePoint().getId();
4916 4972
            nMarker = marker;
4973
4974
            // add by hyg 显示气泡
4975
            nMarker.showInfoWindow();
4976
4917 4977
            current_chargePoint = chargePoint;
4918 4978
            dialog.show();
4919 4979
            if (null != marker.getPosition()) {
@ -5005,13 +5065,17 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5005 5065
                latLng = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
5006 5066
            }
5007 5067
5008
            //OK
5068
            // OK
5009 5069
            double d = AMapUtils.calculateLineDistance(center, latLng);
5010 5070
            if ("0m".equals(Util.getDistance(d))) {
5011 5071
                windowDistance.setText("未知");
5072
                updateInfoWindow("未知距离");
5012 5073
            } else {
5013
                windowDistance.setText(Util.getDistance(d));
5074
                String text = Util.getDistance(d);
5075
                windowDistance.setText(text);
5076
                updateInfoWindow("距您 " + text);
5014 5077
            }
5078
5015 5079
        }
5016 5080
5017 5081
        String acNum = null, dcNum = null, acableNum = null, dcableNum = null;

BIN
app/src/main/res/drawable-hdpi/custom_info_window_bg.9.png


+ 47 - 0
app/src/main/res/layout/custom_info_window.xml

@ -0,0 +1,47 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="wrap_content"
6
    android:layout_height="wrap_content"
7
    android:background="@drawable/custom_info_window_bg"
8
    android:layout_marginRight="20dp">
9
10
    <LinearLayout
11
        android:layout_width="wrap_content"
12
        android:layout_height="40dp"
13
        android:gravity="center"
14
        app:layout_constraintBottom_toBottomOf="parent"
15
        app:layout_constraintLeft_toLeftOf="parent"
16
        app:layout_constraintRight_toRightOf="parent"
17
        app:layout_constraintTop_toTopOf="parent">
18
19
        <TextView
20
            android:id="@+id/distance"
21
            android:layout_width="wrap_content"
22
            android:layout_height="wrap_content"
23
            android:text="距您 ..."
24
            android:textColor="@color/white"
25
            android:textSize="13dp" />
26
27
        <View
28
            android:layout_width="0.5dp"
29
            android:layout_height="15dp"
30
            android:layout_marginLeft="5dp"
31
            android:layout_marginRight="5dp"
32
            android:background="@color/white" />
33
34
        <ImageView
35
            android:layout_width="wrap_content"
36
            android:layout_height="wrap_content"
37
            android:layout_marginRight="2dp"
38
            android:src="@drawable/navigation_white_icon" />
39
40
        <TextView
41
            android:layout_width="wrap_content"
42
            android:layout_height="wrap_content"
43
            android:text="导航"
44
            android:textColor="@color/white"
45
            android:textSize="13dp" />
46
    </LinearLayout>
47
</android.support.constraint.ConstraintLayout>