From bd22ede4884f6198e61213e6122b6d9cb3a0f034 Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Tue, 10 Jan 2023 17:35:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=8B=8D=E6=91=84?= =?UTF-8?q?=E5=92=8C=E8=87=AA=E5=8A=A8=E6=8D=95=E6=8D=89=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E4=B8=BB=E5=AE=9A=E4=BD=8D=E6=A8=A1=E5=BC=8F=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 7 ++++ app/src/main/AndroidManifest.xml | 5 +++ .../activity/AutoTakePictureActivity.java | 18 +++++++++- .../outdoor/activity/HomeActivity.java | 8 +++++ .../outdoor/activity/MainActivity.java | 5 ++- .../outdoor/activity/PicturesActivity.java | 17 +++++++++- .../navinfo/outdoor/api/UserApplication.java | 11 ------- .../outdoor/fragment/TreasureFragment.java | 10 +++--- .../outdoor/util/LocationLifeCycle.java | 33 ++++++++++++------- .../outdoor/util/TalentLocationUtils.java | 12 ++++--- .../drawable/ic_baseline_satellite_alt_24.xml | 5 +++ .../ic_baseline_satellite_alt_24_p.xml | 5 +++ .../ic_baseline_share_location_24.xml | 10 ++++++ .../ic_baseline_share_location_24_p.xml | 10 ++++++ .../res/drawable/selector_location_type.xml | 14 ++++++++ .../main/res/drawable/selector_round_bg.xml | 2 +- .../layout/activity_auto_take_pictures.xml | 12 +++++++ app/src/main/res/layout/activity_pictures.xml | 12 +++++++ 18 files changed, 160 insertions(+), 36 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_satellite_alt_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_satellite_alt_24_p.xml create mode 100644 app/src/main/res/drawable/ic_baseline_share_location_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_share_location_24_p.xml create mode 100644 app/src/main/res/drawable/selector_location_type.xml diff --git a/app/build.gradle b/app/build.gradle index 28a889c..add0bdb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,6 +15,11 @@ android { versionCode 41 versionName "8.230109" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + ndk { + // 设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so) + abiFilters "armeabi", "armeabi-v7a", "arm64-v8a" + } } lintOptions { checkReleaseBuilds false @@ -170,4 +175,6 @@ dependencies { // implementation 'com.github.JiongBull:jlog-storage-qiniu:0.1.0' // https://github.com/elvishew/xLog/blob/master/README_ZH.md 日志记录 implementation 'com.elvishew:xlog:1.10.1' +// // 百度定位 +// implementation 'com.baidu.lbsyun:BaiduMapSDK_Location:9.3.7' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1e87300..bb94c2d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -100,6 +100,11 @@ android:name="design_height_in_dp" android:value="640" /> + + + + + adapterView, View view, int i, long l) { if (i == 0) { - LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.ORIGIN); - } else if (i==1) { LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.TENCENT); + } else if (i==1) { + LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.ORIGIN); } } @@ -454,9 +454,9 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public void onItemSelected(AdapterView adapterView, View view, int i, long l) { if (i == 0) { - LocationLifeCycle.getInstance().setReferenceLocationFrom(LocationLifeCycle.LOCATION_FROM.ORIGIN); - } else if (i==1) { LocationLifeCycle.getInstance().setReferenceLocationFrom(LocationLifeCycle.LOCATION_FROM.TENCENT); + } else if (i==1) { + LocationLifeCycle.getInstance().setReferenceLocationFrom(LocationLifeCycle.LOCATION_FROM.ORIGIN); } } diff --git a/app/src/main/java/com/navinfo/outdoor/util/LocationLifeCycle.java b/app/src/main/java/com/navinfo/outdoor/util/LocationLifeCycle.java index cc3dd80..9921d63 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/LocationLifeCycle.java +++ b/app/src/main/java/com/navinfo/outdoor/util/LocationLifeCycle.java @@ -1,6 +1,5 @@ package com.navinfo.outdoor.util; -import android.app.Activity; import android.content.Context; import android.location.Location; import android.os.Message; @@ -10,10 +9,7 @@ import androidx.lifecycle.DefaultLifecycleObserver; import androidx.lifecycle.LifecycleOwner; import com.navinfo.outdoor.api.Constant; -import com.tencent.map.fusionlocation.model.TencentGeoLocation; import com.tencent.map.geolocation.TencentLocation; -import com.tencent.map.location.api.GeoLocationObserver; -import com.tencent.map.location.core.FusionGeoLocationAdapter; import com.tencent.tencentmap.mapsdk.maps.LocationSource; import org.greenrobot.eventbus.EventBus; @@ -25,7 +21,7 @@ import java.util.List; public class LocationLifeCycle implements DefaultLifecycleObserver { private Context mContext; - private LOCATION_FROM mainLocationFrom = LOCATION_FROM.ORIGIN/*主要位置源*/, referenceLocationFrom = LOCATION_FROM.TENCENT/*参考位置源*/; + private LOCATION_FROM mainLocationFrom = LOCATION_FROM.TENCENT/*主要位置源*/, referenceLocationFrom = LOCATION_FROM.ORIGIN/*参考位置源*/; private TencentLocation tencentLocation; // 腾讯定位获取到的最新位置信息 private Location gpsLocation; // 原生系统获取到的最新位置 private List locationChangedListenerList; @@ -45,16 +41,29 @@ public class LocationLifeCycle implements DefaultLifecycleObserver { @Override public void onCreate(@NonNull LifecycleOwner owner) { DefaultLifecycleObserver.super.onCreate(owner); - locationChangedListenerList = new ArrayList<>(); - // 开启腾讯定位 - TalentLocationUtils.getInstance(mContext).startLocation(mContext); - // 开启原生定位 - GPSUtils.getInstance(mContext).startLocation(); if (!EventBus.getDefault().isRegistered(this)) { EventBus.getDefault().register(this); } } + public void startTencentLocation() { + // 开启腾讯定位 + TalentLocationUtils.getInstance(mContext).startLocation(mContext); + } + + public void stopTencentLocation() { + // 停止腾讯定位 + TalentLocationUtils.getInstance(mContext).stopLocation(); + } + + public void startGPSLocation() { + GPSUtils.getInstance(mContext).startLocation(); + } + + public void stopGPSLocation() { + GPSUtils.getInstance(mContext).startLocation(); + } + @Override public void onDestroy(@NonNull LifecycleOwner owner) { DefaultLifecycleObserver.super.onDestroy(owner); @@ -69,7 +78,6 @@ public class LocationLifeCycle implements DefaultLifecycleObserver { @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMessageMainThread(Message msg) { - Location mapLocation; if (msg.what == Constant.EVENT_WHAT_LOCATION_CHANGE) { // 用户位置更新 if (msg.arg1 == LOCATION_FROM.ORIGIN.ordinal()) { gpsLocation = (Location) msg.obj; @@ -104,6 +112,9 @@ public class LocationLifeCycle implements DefaultLifecycleObserver { } public List getLocationChangedListenerList() { + if (locationChangedListenerList == null) { + locationChangedListenerList = new ArrayList<>(); + } return locationChangedListenerList; } diff --git a/app/src/main/java/com/navinfo/outdoor/util/TalentLocationUtils.java b/app/src/main/java/com/navinfo/outdoor/util/TalentLocationUtils.java index d7e25b4..4f97287 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/TalentLocationUtils.java +++ b/app/src/main/java/com/navinfo/outdoor/util/TalentLocationUtils.java @@ -6,6 +6,7 @@ import android.os.Looper; import android.os.Message; import android.util.Log; +import com.elvishew.xlog.XLog; import com.github.lazylibrary.util.ToastUtils; import com.navinfo.outdoor.api.Constant; import com.tencent.map.fusionlocation.observer.TencentGeoLocationObserver; @@ -55,6 +56,7 @@ public class TalentLocationUtils implements TencentLocationListener { } if (!isLocationStart) { int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper(), 0); + XLog.d( "开始腾讯定位"); isLocationStart = true; switch (err) { case 1: @@ -91,27 +93,27 @@ public class TalentLocationUtils implements TencentLocationListener { currentLocationMsg.what = Constant.EVENT_WHAT_LOCATION_CHANGE; currentLocationMsg.arg1 = LocationLifeCycle.LOCATION_FROM.TENCENT.ordinal(); // 设置定位来源 currentLocationMsg.obj = tencentLocation; - EventBus.getDefault().post(currentLocationMsg); + EventBus.getDefault().postSticky(currentLocationMsg); }else if (i==TencentLocation.ERROR_NETWORK){//网络问题引起的定位失败 Message currentLocationMsg = Message.obtain(); currentLocationMsg.what = Constant.EVENT_MESSAGE; currentLocationMsg.obj = "网络问题引起的定位失败"; - EventBus.getDefault().post(currentLocationMsg); + EventBus.getDefault().postSticky(currentLocationMsg); }else if (i==TencentLocation.ERROR_BAD_JSON){//GPS, Wi-Fi 或基站错误引起的定位失败: 1、用户的手机确实采集不到定位凭据,比如偏远地区比如地下车库电梯内等; 2、开关跟权限问题,比如用户关闭了位置信息,关闭了Wi-Fi,未授予app定位权限等。 Message currentLocationMsg = Message.obtain(); currentLocationMsg.what = Constant.EVENT_MESSAGE; currentLocationMsg.obj = "GPS, Wi-Fi 或基站错误引起的定位失败"; - EventBus.getDefault().post(currentLocationMsg); + EventBus.getDefault().postSticky(currentLocationMsg); }else if (i==TencentLocation.ERROR_WGS84){ Message currentLocationMsg = Message.obtain(); currentLocationMsg.what = Constant.EVENT_MESSAGE; currentLocationMsg.obj ="无法将WGS84坐标转换成GCJ-02坐标时的定位失败"; - EventBus.getDefault().post(currentLocationMsg); + EventBus.getDefault().postSticky(currentLocationMsg); }else if (i==TencentLocation.ERROR_UNKNOWN){ Message currentLocationMsg = Message.obtain(); currentLocationMsg.what = Constant.EVENT_MESSAGE; currentLocationMsg.obj ="未知原因引起的定位失败"; - EventBus.getDefault().post(currentLocationMsg); + EventBus.getDefault().postSticky(currentLocationMsg); } } diff --git a/app/src/main/res/drawable/ic_baseline_satellite_alt_24.xml b/app/src/main/res/drawable/ic_baseline_satellite_alt_24.xml new file mode 100644 index 0000000..42d16b2 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_satellite_alt_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_satellite_alt_24_p.xml b/app/src/main/res/drawable/ic_baseline_satellite_alt_24_p.xml new file mode 100644 index 0000000..5172bde --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_satellite_alt_24_p.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_share_location_24.xml b/app/src/main/res/drawable/ic_baseline_share_location_24.xml new file mode 100644 index 0000000..0d480f1 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_share_location_24.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_baseline_share_location_24_p.xml b/app/src/main/res/drawable/ic_baseline_share_location_24_p.xml new file mode 100644 index 0000000..721e56f --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_share_location_24_p.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/selector_location_type.xml b/app/src/main/res/drawable/selector_location_type.xml new file mode 100644 index 0000000..be49e79 --- /dev/null +++ b/app/src/main/res/drawable/selector_location_type.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_round_bg.xml b/app/src/main/res/drawable/selector_round_bg.xml index 25dc80d..35a4565 100644 --- a/app/src/main/res/drawable/selector_round_bg.xml +++ b/app/src/main/res/drawable/selector_round_bg.xml @@ -5,7 +5,7 @@ + android:drawable="@drawable/round_bg_white"/> + + + +