瀏覽代碼

首页导航权限设置

huyuguo 4 年之前
父節點
當前提交
9ed947b87c

+ 1 - 1
app/src/main/AndroidManifest.xml

@ -3,7 +3,7 @@
3 3
    xmlns:tools="http://schemas.android.com/tools"
4 4
    package="com.electric.chargingpile"
5 5
    android:versionCode="96"
6
    android:versionName="3.5.8">
6
    android:versionName="3.5.10">
7 7
8 8
    <uses-permission android:name="android.permission.BLUETOOTH" />
9 9
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

+ 101 - 69
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
22 22
import android.net.ConnectivityManager;
23 23
import android.net.NetworkInfo;
24 24
import android.net.Uri;
25
import android.nfc.Tag;
25 26
import android.os.Build;
26 27
import android.os.Bundle;
27 28
import android.os.Environment;
@ -377,7 +378,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
377 378
    public static boolean isStatusBack = false;
378 379
379 380
    private static final int RC_CAMERA_PERM = 123;
380
    private static final int RC_SAVE_PERM = 124;
381
    private static final int RC_Location_PERM = 124;
381 382
382 383
    private String adfloatUrl = "";
383 384
@ -916,6 +917,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
916 917
917 918
        mapView = (MapView) findViewById(R.id.mapView);
918 919
        mapView.onCreate(savedInstanceState);
920
919 921
        initViews();
920 922
        getRecyclerViewData();
921 923
        File databasePath = getDatabasePath("zhan_list");
@ -1220,24 +1222,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1220 1222
1221 1223
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
1222 1224
1223
1224 1225
        if (aMap == null) {
1225
            aMap = mapView.getMap();
1226
1227
            Util.setMapCustomStyleFile(aMap, getApplicationContext());
1228
            maxZoomLevel = aMap.getMaxZoomLevel();
1229
            minZoomLevel = aMap.getMinZoomLevel();
1230
            MyLocationStyle myLocationStyle = new MyLocationStyle();
1231
            myLocationStyle.myLocationIcon(BitmapDescriptorFactory
1232
                    .fromResource(R.drawable.point_icon));// 设置小蓝点的图标
1233
            myLocationStyle.strokeColor(getResources().getColor(R.color.transparent));
1234
            myLocationStyle.radiusFillColor(getResources().getColor(R.color.transparent));
1235
            aMap.setMyLocationStyle(myLocationStyle);
1236
            mUiSettings = aMap.getUiSettings();
1237 1226
            setUpMap();
1238 1227
        }
1239 1228
1240
1241 1229
        iv_find = (ImageView) findViewById(R.id.iv_find);
1242 1230
        iv_main = (ImageView) findViewById(R.id.iv_main);
1243 1231
        iv_screening = (ImageView) findViewById(R.id.iv_screening);
@ -1289,10 +1277,23 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1289 1277
     * 设置一些amap的属性
1290 1278
     */
1291 1279
    private void setUpMap() {
1280
        aMap = mapView.getMap();
1281
1282
        Util.setMapCustomStyleFile(aMap, getApplicationContext());
1283
        maxZoomLevel = aMap.getMaxZoomLevel();
1284
        minZoomLevel = aMap.getMinZoomLevel();
1285
        MyLocationStyle myLocationStyle = new MyLocationStyle();
1286
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory
1287
                .fromResource(R.drawable.point_icon));// 设置小蓝点的图标
1288
        myLocationStyle.strokeColor(getResources().getColor(R.color.transparent));
1289
        myLocationStyle.radiusFillColor(getResources().getColor(R.color.transparent));
1290
        aMap.setMyLocationStyle(myLocationStyle);
1291
        mUiSettings = aMap.getUiSettings();
1292 1292
//        aMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
1293 1293
1294 1294
        aMap.setOnCameraChangeListener(this);
1295 1295
        aMap.setLocationSource(this);// 设置定位监听
1296
        aMap.setMyLocationEnabled(true);
1296 1297
        aMap.setOnMapClickListener(this);
1297 1298
        aMap.setOnMarkerClickListener(this);
1298 1299
        aMap.setInfoWindowAdapter(this);
@ -1370,11 +1371,12 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1370 1371
            if (!isFirstLoc) {
1371 1372
                isFirstLoc = true;
1372 1373
                mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
1373
                aMap.setLocationSource(this);// 设置定位监听
1374
                aMap.setMyLocationEnabled(true);// 是否可触发定位并显示定位层
1375 1374
                aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
1376 1375
                mlocationClient.startLocation();
1377 1376
            }
1377
            if (!hasLocationPermission()) {
1378
                requestLocationPermission();
1379
            }
1378 1380
            againPoint = "";
1379 1381
            back = "";
1380 1382
        }
@ -1400,7 +1402,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1400 1402
        MainApplication.search_wei = wei;
1401 1403
1402 1404
        final LatLng screenCity = new LatLng(wei, jing);
1403
        aMap = mapView.getMap();
1405
        if (aMap == null) {
1406
            setUpMap();
1407
        }
1408
1404 1409
        Util.setMapCustomStyleFile(aMap, getApplicationContext());
1405 1410
        new Handler().postDelayed(new Runnable() {
1406 1411
            @Override
@ -1428,10 +1433,20 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1428 1433
    protected void onPause() {
1429 1434
        super.onPause();
1430 1435
        mapView.onPause();
1431
//        Log.e("onPause", "onPause");
1432
        deactivate();
1433 1436
    }
1434 1437
1438
    @Override
1439
    public void deactivate() {
1440
        mListener = null;
1441
        if (mlocationClient != null) {
1442
            mlocationClient.stopLocation();
1443
            mlocationClient.onDestroy();
1444
        }
1445
        mlocationClient = null;
1446
    }
1447
1448
1449
1435 1450
    /**
1436 1451
     * 方法必须重写
1437 1452
     */
@ -1492,22 +1507,15 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1492 1507
            // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
1493 1508
            // 设置是否只定位一次,默认为false
1494 1509
            mLocationOption.setOnceLocation(false);
1495
1496 1510
            //设置是否强制刷新WIFI,默认为强制刷新
1497 1511
            //mLocationOption.setWifiActiveScan(false);
1498 1512
            mLocationOption.setWifiScan(true);
1499
            mlocationClient.startLocation();
1500
        }
1501
    }
1502 1513
1503
    @Override
1504
    public void deactivate() {
1505
        mListener = null;
1506
        if (mlocationClient != null) {
1507
            mlocationClient.stopLocation();
1508
            mlocationClient.onDestroy();
1514
            if (!ProfileManager.getInstance().getRequestLocationPermission(MainMapActivity.this)) {
1515
                requestLocationPermission();
1516
                ProfileManager.getInstance().setRequestLocationPermission(MainMapActivity.this, true);
1517
            }
1509 1518
        }
1510
        mlocationClient = null;
1511 1519
    }
1512 1520
1513 1521
    @Override
@ -1564,11 +1572,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1564 1572
                }
1565 1573
            } else {
1566 1574
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
1567
//                Log.e("AmapErr", errText);
1568
//                mLocationErrText.setVisibility(View.VISIBLE);
1569
                Toast.makeText(this, errText, Toast.LENGTH_SHORT).show();
1575
                Log.e(TAG, errText);
1576
                Toast.makeText(this, "定位失败", Toast.LENGTH_SHORT).show();
1570 1577
            }
1571
1572 1578
        }
1573 1579
    }
1574 1580
@ -2262,16 +2268,16 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2262 2268
        SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(getApplication());
2263 2269
        switch (v.getId()) {
2264 2270
            case R.id.iv_tuijian:
2265
                if (null != center) {
2271
                if (hasLocationPermission()) {
2266 2272
                    MobclickAgent.onEvent(getApplicationContext(), "0111");
2267 2273
                    Intent i = new Intent(getApplicationContext(), RecommendZhanActivity.class);
2268 2274
                    i.putExtra("center_jing", String.valueOf(center.longitude));
2269 2275
                    i.putExtra("center_wei", String.valueOf(center.latitude));
2270 2276
                    startActivity(i);
2277
                    MobclickAgent.onEvent(context, "0068");
2271 2278
                } else {
2272
                    ToastUtil.showToast(getApplicationContext(), "没有获取到您当前的位置,请检查网络或定位权限", Toast.LENGTH_SHORT);
2279
                    requestLocationPermission();
2273 2280
                }
2274
                MobclickAgent.onEvent(context, "0068");
2275 2281
                break;
2276 2282
            case R.id.iv_clear_address:
2277 2283
                tv_search.setText("请输入地址/关键字");
@ -2359,8 +2365,12 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2359 2365
2360 2366
                break;
2361 2367
            case R.id.iv_route:
2362
                startActivity(new Intent(getApplication(), RoutePlanShowAddressActivity.class));
2363
                MobclickAgent.onEvent(getApplicationContext(), "0112");
2368
                if (hasLocationPermission()) {
2369
                    startActivity(new Intent(getApplication(), RoutePlanShowAddressActivity.class));
2370
                    MobclickAgent.onEvent(getApplicationContext(), "0112");
2371
                } else {
2372
                    requestLocationPermission();
2373
                }
2364 2374
                break;
2365 2375
            case R.id.second_hand_car:
2366 2376
                Intent adfloatIntent = new Intent(this, MyWebViewActivity.class);
@ -2395,6 +2405,11 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2395 2405
                break;
2396 2406
            //地图&列表切换按钮
2397 2407
            case R.id.iv_list:
2408
                if (!hasLocationPermission()) {
2409
                    requestLocationPermission();
2410
                    return;
2411
                }
2412
2398 2413
                sharedPreferencesUtil.putBoolean("cdz_recommend_more_detail", true);
2399 2414
                String jing, wei;
2400 2415
                if (MainApplication.search_jing != 0.0 && MainApplication.search_wei != 0.0) {
@ -2427,11 +2442,14 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2427 2442
                if (!isFirstLoc) {
2428 2443
                    isFirstLoc = true;
2429 2444
                    mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
2430
                    aMap.setLocationSource(this);// 设置定位监听
2431
                    aMap.setMyLocationEnabled(true);// 是否可触发定位并显示定位层
2432 2445
                    aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
2433 2446
                    mlocationClient.startLocation();
2434 2447
                }
2448
2449
                if (!hasLocationPermission()) {
2450
                    requestLocationPermission();
2451
                }
2452
2435 2453
                windowLayout.setVisibility(View.GONE);
2436 2454
                rl_control.setVisibility(View.VISIBLE);
2437 2455
                ll_open.setVisibility(View.GONE);
@ -2756,30 +2774,27 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2756 2774
2757 2775
    @Override
2758 2776
    public void onPermissionsGranted(int requestCode, List<String> perms) {
2759
        if (requestCode == RC_CAMERA_PERM) {
2760
            Intent iintent = new Intent(getApplicationContext(), com.google.zxing.client.android.CaptureActivity.class);
2761
            iintent.putExtra("url", MainApplication.url);
2762
            iintent.putExtra("user_id", MainApplication.userId);
2763
            iintent.putExtra("user_password", MainApplication.userPassword);
2764
            iintent.putExtra("user_phone", MainApplication.userPhone);
2765
            iintent.putExtra("cha", MainMapActivity.cha);
2766
            iintent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
2767
            startActivity(iintent);
2768
            overridePendingTransition(0, 0);
2769
        }
2770 2777
    }
2771 2778
2772 2779
    @Override
2773 2780
    public void onPermissionsDenied(int requestCode, List<String> perms) {
2774
2775
//        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
2776
//            new AppSettingsDialog.Builder(MainMapActivity.this).build().show();
2777
//        }
2778
2779 2781
        if (requestCode == RC_CAMERA_PERM) {
2780 2782
            new AlertDialogCommon(MainMapActivity.this).builder()
2781
                    .setMsg("为保证您正常、安全的使用充电桩,需要获取您的相机权限,请允许。")
2782
                    .setPositiveButton("去设置", new View.OnClickListener() {
2783
                    .setMsg("扫码充电需要开启位置权限,是否前往开启?")
2784
                    .setPositiveButton("去开启", new View.OnClickListener() {
2785
                        @Override
2786
                        public void onClick(View v) {
2787
                            SystemTypeUtil.goToPermissionManager(MainMapActivity.this);
2788
                        }
2789
                    }).setNegativeButton("取消", new View.OnClickListener() {
2790
                @Override
2791
                public void onClick(View v) {
2792
                }
2793
            }).show();
2794
        } else if (requestCode == RC_Location_PERM) {
2795
            new AlertDialogCommon(MainMapActivity.this).builder()
2796
                    .setMsg("为了定位您的位置,推荐充电桩,充电桩位置路线导航需要开启位置权限,是否前往开启?")
2797
                    .setPositiveButton("去开启", new View.OnClickListener() {
2783 2798
                        @Override
2784 2799
                        public void onClick(View v) {
2785 2800
                            SystemTypeUtil.goToPermissionManager(MainMapActivity.this);
@ -2787,7 +2802,6 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2787 2802
                    }).setNegativeButton("取消", new View.OnClickListener() {
2788 2803
                @Override
2789 2804
                public void onClick(View v) {
2790
                    android.os.Process.killProcess(android.os.Process.myPid());
2791 2805
                }
2792 2806
            }).show();
2793 2807
        }
@ -2800,13 +2814,24 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2800 2814
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
2801 2815
    }
2802 2816
2803
    private boolean isPermissionOK() {
2817
    private boolean hasLocationPermission() {
2804 2818
        return EasyPermissions.hasPermissions(this,
2805
                Manifest.permission.CAMERA,
2806
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
2807
                Manifest.permission.READ_EXTERNAL_STORAGE
2819
                Manifest.permission.ACCESS_FINE_LOCATION
2808 2820
        );
2809 2821
    }
2822
    @AfterPermissionGranted(RC_Location_PERM)
2823
    public void requestLocationPermission() {
2824
        if (hasLocationPermission()) {
2825
            mlocationClient.startLocation();
2826
        } else {
2827
            EasyPermissions.requestPermissions(
2828
                    this,
2829
                    "为了定位您的位置,推荐充电桩,充电桩位置路线导航需要开启位置权限,是否前往开启?",
2830
                    RC_Location_PERM,
2831
                    Manifest.permission.ACCESS_FINE_LOCATION);
2832
        }
2833
    }
2834
2810 2835
2811 2836
    private boolean hasCameraPermission() {
2812 2837
        return EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA);
@ -2831,7 +2856,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2831 2856
        } else {
2832 2857
            EasyPermissions.requestPermissions(
2833 2858
                    this,
2834
                    "扫码充电需要开启摄像头权限,是否前往开启",
2859
                    "扫码充电需要开启相机权限,是否前往开启?",
2835 2860
                    RC_CAMERA_PERM,
2836 2861
                    Manifest.permission.CAMERA);
2837 2862
        }
@ -3252,7 +3277,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3252 3277
            MainApplication.search_wei = wei;
3253 3278
3254 3279
            final LatLng screenCity = new LatLng(wei, jing);
3255
            aMap = mapView.getMap();
3280
            if (aMap == null) {
3281
                setUpMap();
3282
            }
3256 3283
            Util.setMapCustomStyleFile(aMap, getApplicationContext());
3257 3284
            new Handler().postDelayed(new Runnable() {
3258 3285
                @Override
@ -3276,7 +3303,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3276 3303
            double jing = Double.valueOf(data.getStringExtra("jing"));
3277 3304
            double wei = Double.valueOf(data.getStringExtra("wei"));
3278 3305
            final LatLng screenCity = new LatLng(wei, jing);
3279
            aMap = mapView.getMap();
3306
            if (aMap == null) {
3307
                setUpMap();
3308
            }
3309
3280 3310
            Util.setMapCustomStyleFile(aMap, getApplicationContext());
3281 3311
            new Handler().postDelayed(new Runnable() {
3282 3312
                @Override
@ -5683,11 +5713,13 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5683 5713
                isFirstLoc = true;
5684 5714
                mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
5685 5715
                aMap.setLocationSource(this);// 设置定位监听
5686
                aMap.setMyLocationEnabled(true);// 是否可触发定位并显示定位层
5687 5716
                aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
5688 5717
                mlocationClient.setLocationListener(this);
5689 5718
                mlocationClient.startLocation();
5690 5719
            }
5720
            if (!hasLocationPermission()) {
5721
                requestLocationPermission();
5722
            }
5691 5723
        }
5692 5724
    }
5693 5725

+ 4 - 4
app/src/main/java/com/electric/chargingpile/activity/PermissionAgreementActivity.java

@ -94,8 +94,8 @@ public class PermissionAgreementActivity extends Activity implements EasyPermiss
94 94
    public void onPermissionsDenied(int requestCode, List<String> perms) {
95 95
        if (requestCode == RC_PHONE_PERM) {
96 96
            new AlertDialogCommon(PermissionAgreementActivity.this).builder()
97
                    .setMsg("为保证您正常、安全的使用充电桩,需要获取您的电话使用权限,请允许。")
98
                    .setPositiveButton("去设置", new View.OnClickListener() {
97
                    .setMsg("为保证您正常、安全的使用充电桩,需要获取您的电话使用权限,是否前往开启?")
98
                    .setPositiveButton("去开启", new View.OnClickListener() {
99 99
                        @Override
100 100
                        public void onClick(View v) {
101 101
                            SystemTypeUtil.goToPermissionManager(PermissionAgreementActivity.this);
@ -108,8 +108,8 @@ public class PermissionAgreementActivity extends Activity implements EasyPermiss
108 108
            }).show();
109 109
        } else if (requestCode == RC_STORAGE_PERM) {
110 110
            new AlertDialogCommon(PermissionAgreementActivity.this).builder()
111
                    .setMsg("为保证您正常、安全的使用充电桩,需要获取您的存储权限,请允许。")
112
                    .setPositiveButton("去设置", new View.OnClickListener() {
111
                    .setMsg("为保证您正常、安全的使用充电桩,需要获取您的存储权限,是否前往开启?")
112
                    .setPositiveButton("去开启", new View.OnClickListener() {
113 113
                        @Override
114 114
                        public void onClick(View v) {
115 115
                            SystemTypeUtil.goToPermissionManager(PermissionAgreementActivity.this);

+ 10 - 0
app/src/main/java/com/electric/chargingpile/manager/ProfileManager.java

@ -15,6 +15,7 @@ public class ProfileManager {
15 15
    private static final String KEY_GUIDE = "key_guide";
16 16
    private static final String KEY_PRIVACY_AGREEMENT = "key_privacy_agreement";
17 17
    private static final String KEY_PRIVACY_PERMISSION = "key_privacy_permission";
18
    private static final String KEY_LOCATION_PERMISSION = "key_location_permission";
18 19
    private static final String KEY_TYPE = "key_type";
19 20
    private static final String KEY_USERID = "key_userid";
20 21
    private static final String KEY_USERICON = "key_usericon";
@ -592,6 +593,15 @@ public class ProfileManager {
592 593
                false);
593 594
    }
594 595

596
    public void setRequestLocationPermission(Context context, boolean permission) {
597
        PreferenceManager.getInstance(context).putBoolean(KEY_LOCATION_PERMISSION, permission);
598
    }
599

600
    public boolean getRequestLocationPermission(Context context) {
601
        return PreferenceManager.getInstance(context).getBoolean(KEY_LOCATION_PERMISSION,
602
                false);
603
    }
604

595 605

596 606
    public void setFirstssyd(Context context, boolean firstssyd) {
597 607
        PreferenceManager.getInstance(context).putBoolean(KEY_FIRSTSSYD, firstssyd);