Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
app
/
ai-car
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 351d9d48
authored
Sep 20, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: remediate permissions and rescue flow for 3.7.1.6
1 parent
9fbcf126
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
928 additions
and
1030 deletions
CommonRes/src/main/java/com/glsx/commonres/permission/PermissionRequestUtil.java
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/glsx/aicar/app/AiCarApplication.java
app/src/main/java/com/glsx/aicar/ui/fragment/accident/DamageChoosePosFragment.java
app/src/main/java/com/glsx/aicar/ui/fragment/accident/PhotoDamageFragment.java
app/src/main/java/com/glsx/aicar/ui/fragment/accident/RescueLocationSelection.java
app/src/main/java/com/glsx/aicar/ui/fragment/accident/RescueMediaType.java
app/src/main/java/com/glsx/aicar/ui/fragment/accident/UploadMediaFileToALiYunManager.java
app/src/main/java/com/glsx/aicar/ui/fragment/intelligent/IntelligentCarFragment.java
app/src/main/java/com/glsx/aicar/ui/fragment/intelligent/IntelligentServerFragment.java
app/src/main/java/com/glsx/aicar/ui/fragment/main/MainFragment.java
app/src/main/res/layout/fragment_photo_damage.xml
app/src/main/res/layout/fragment_photo_damage_choose_pos.xml
app/src/main/res/layout/rescue_baidu_map_choose.xml
app/src/main/res/layout/rescue_baidu_map_photo.xml
app/src/main/res/layout/rescue_debug_map_placeholder.xml
app/src/test/java/com/glsx/aicar/ui/fragment/accident/RescueAsyncCallbackTest.java
app/src/test/java/com/glsx/aicar/ui/fragment/accident/RescueLocationSelectionTest.java
app/src/test/java/com/glsx/aicar/ui/fragment/accident/RescueMediaTypeTest.java
gradle.properties
libaccount/src/main/java/com/glsx/libaccount/AccidentApiManager.java
libaccount/src/main/java/com/glsx/libaccount/http/HttpConst.java
libaccount/src/main/java/com/glsx/libaccount/http/base/RxHttpManager.java
libaccount/src/testDebug/java/com/glsx/libaccount/RescueDebugIsolationTest.java
local.properties
CommonRes/src/main/java/com/glsx/commonres/permission/PermissionRequestUtil.java
View file @
351d9d4
...
...
@@ -81,9 +81,9 @@ public class PermissionRequestUtil {
callback
.
onGranted
();
}
})
.
onDenied
(
permissions
->
{
if
(
AndPermission
.
hasAlwaysDeniedPermission
(
context
,
permissions
))
{
new
PermissionSetting
(
context
).
showSetting
(
permissions
);
.
onDenied
(
permissions
->
{
if
(
null
!=
callback
)
{
callback
.
onDenied
();
}
})
.
start
();
...
...
app/build.gradle
View file @
351d9d4
...
...
@@ -13,8 +13,8 @@ android {
targetSdkVersion
30
// versionCode 3504
// versionName "3.7.0." + getCurrentVersionCode()
versionCode
371
5
versionName
"3.7.1.
5
"
versionCode
371
6
versionName
"3.7.1.
6
"
//V3.3.5.2版本开始,单独打包32位和64位的版本。应用商店根据实际情况同时上架两个版本或只上架64位版本
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
//自定义Dialog控件DialogX要使用开启组件的实时模糊效果(例如IOS主题)
...
...
app/src/main/AndroidManifest.xml
View file @
351d9d4
...
...
@@ -269,9 +269,9 @@
tools:replace=
"android:resource"
/>
</provider>
<!-- 高德地图SDK接入,Key参数2021.12.9 user 15018517717 -->
<!-- <meta-data-->
<!-- android:name="com.amap.api.v2.apikey"-->
<!-- android:value="15787bb490e8d9132c9fbe0ba45aa008" />-->
<meta-data
android:name=
"com.amap.api.v2.apikey"
android:value=
"15787bb490e8d9132c9fbe0ba45aa008"
/>
<meta-data
android:name=
"com.baidu.lbsapi.API_KEY"
...
...
app/src/main/java/com/glsx/aicar/app/AiCarApplication.java
View file @
351d9d4
...
...
@@ -20,6 +20,7 @@ import com.alipay.mobile.framework.quinoxless.QuinoxlessApplicationLike;
//import com.alipay.mobile.framework.quinoxless.QuinoxlessPrivacyUtil;
import
com.alipay.mobile.framework.quinoxless.QuinoxlessFramework
;
import
com.amap.api.location.AMapLocationClient
;
import
com.amap.api.services.core.ServiceSettings
;
//import com.facebook.drawee.backends.pipeline.Fresco;
import
com.baidu.location.LocationClient
;
import
com.baidu.mapapi.SDKInitializer
;
...
...
@@ -119,10 +120,6 @@ public class AiCarApplication extends Application implements Application.Activit
mInstance
=
this
;
mContext
=
getApplicationContext
();
//
// 百度同意隐私协议
LocationClient
.
setAgreePrivacy
(
true
);
SDKInitializer
.
setAgreePrivacy
(
this
,
true
);
SDKInitializer
.
initialize
(
getApplicationContext
());
Hawk
.
init
(
this
).
build
();
...
...
@@ -174,6 +171,10 @@ public class AiCarApplication extends Application implements Application.Activit
WifiStatusObserver
.
Companion
.
getInstance
().
init
(
this
);
hasInitSDK
=
true
;
// Initialize map SDKs only after the user accepts the privacy notice.
LocationClient
.
setAgreePrivacy
(
true
);
SDKInitializer
.
setAgreePrivacy
(
this
,
true
);
SDKInitializer
.
initialize
(
getApplicationContext
());
//高德地图隐私合规检查
initAMap
();
...
...
@@ -337,6 +338,9 @@ public class AiCarApplication extends Application implements Application.Activit
AMapLocationClient
.
updatePrivacyShow
(
AiCarApplication
.
getConext
().
getApplicationContext
(),
true
,
true
);
//设置是否同意用户授权政策 <b>必须在AmapLocationClient实例化之前调用
AMapLocationClient
.
updatePrivacyAgree
(
AiCarApplication
.
getConext
().
getApplicationContext
(),
true
);
// The search SDK has its own privacy state; location SDK consent does not cover POI searches.
ServiceSettings
.
updatePrivacyShow
(
getApplicationContext
(),
true
,
true
);
ServiceSettings
.
updatePrivacyAgree
(
getApplicationContext
(),
true
);
}
/**
...
...
app/src/main/java/com/glsx/aicar/ui/fragment/accident/DamageChoosePosFragment.java
View file @
351d9d4
...
...
@@ -14,6 +14,7 @@ import android.text.TextWatcher;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewStub
;
import
android.widget.AdapterView
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
...
...
@@ -55,6 +56,7 @@ import com.baidu.mapapi.map.Marker;
import
com.baidu.mapapi.map.MyLocationConfiguration
;
import
com.baidu.mapapi.map.MyLocationData
;
import
com.baidu.mapapi.utils.DistanceUtil
;
import
com.glsx.aicar.BuildConfig
;
import
com.glsx.aicar.R
;
import
com.glsx.aicar.adapter.TrafficSearchAdapter
;
import
com.glsx.aicar.ly.LogFileEx
;
...
...
@@ -79,7 +81,7 @@ import me.yokeyword.fragmentation.ISupportActivity;
/**
* 首页-智能页面-服务-事故页-拍照定损页-事故位置选择页,功能页面
*/
public
class
DamageChoosePosFragment
extends
BaseFragment
implements
View
.
OnClickListener
,
PoiSearch
.
OnPoiSearchListener
{
public
class
DamageChoosePosFragment
extends
BaseFragment
implements
View
.
OnClickListener
{
private
String
TAG
=
"DamageChoosePosFragment"
;
private
View
view
;
...
...
@@ -100,13 +102,10 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
private
Marker
marker
;
private
SensorManager
mSensorManager
;
private
MyLocationConfiguration
.
LocationMode
mCurrentMode
;
private
LocationClient
mLocClient
;
private
MyLocationListener
myListener
=
new
MyLocationListener
();
private
PoiSearch
poiSearch
;
private
PoiSearch
.
Query
query
;
private
List
<
PoiItem
>
poiItemList
;
private
final
PoiSearchGate
poiSearchGate
=
new
PoiSearchGate
();
private
GeocodeSearch
geocodeSearch
;
private
GeocodeSearch
mGeocodeSearch
;
...
...
@@ -129,11 +128,7 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
mContext
=
getContext
();
initViews
();
initMapViews
(
savedInstanceState
);
try
{
initData
();
}
catch
(
AMapException
e
)
{
e
.
printStackTrace
();
}
initData
();
return
view
;
}
...
...
@@ -186,7 +181,13 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
LogUtils
.
v
(
TAG
,
"lv_search_result onItemClick position= "
+
position
);
if
(
listSearchString
!=
null
&&
listSearchString
.
size
()
>
position
)
{
EventBus
.
getDefault
().
post
(
listSearchString
.
get
(
position
));
TrafficSearchResultBean
choice
=
listSearchString
.
get
(
position
);
if
(
RescueLocationSelection
.
create
(
choice
.
getName
(),
choice
.
getDistrict
(),
choice
.
getLatitude
(),
choice
.
getLongitude
())
==
null
)
{
com
.
glsx
.
commonres
.
util
.
ToastUtil
.
show
(
"地点没有有效地址或坐标,请重新选择"
);
return
;
}
EventBus
.
getDefault
().
post
(
choice
);
if
(
getActivity
()
!=
null
)
((
ISupportActivity
)
getActivity
()).
onBackPressed
();
}
...
...
@@ -205,10 +206,15 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
}
private
void
initMapViews
(
Bundle
bundle
)
{
mMapView
=
(
MapView
)
view
.
findViewById
(
R
.
id
.
map_view_choose
);
// mMapView.onCreate(bundle);
ViewStub
mapStub
=
view
.
findViewById
(
R
.
id
.
rescue_choose_map_stub
);
if
(
BuildConfig
.
DEBUG
)
{
mapStub
.
setLayoutResource
(
R
.
layout
.
rescue_debug_map_placeholder
);
mapStub
.
inflate
();
view
.
findViewById
(
R
.
id
.
iv_center_location
).
setVisibility
(
View
.
GONE
);
return
;
}
mMapView
=
(
MapView
)
mapStub
.
inflate
();
mAMap
=
mMapView
.
getMap
();
mMapView
.
showZoomControls
(
false
);
// 获取传感器管理服务
mSensorManager
=
(
SensorManager
)
mContext
.
getSystemService
(
SENSOR_SERVICE
);
...
...
@@ -216,80 +222,7 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
// 为系统的方向传感器注册监听器
// mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI);
initLocation
();
// com.baidu.mapapi.map.BitmapDescriptor customMarker = com.baidu.mapapi.map.BitmapDescriptorFactory.fromResource(R.drawable.icon_blue);
//导航箭头
com
.
baidu
.
mapapi
.
map
.
BitmapDescriptor
arrow
=
com
.
baidu
.
mapapi
.
map
.
BitmapDescriptorFactory
.
fromResource
(
R
.
drawable
.
icon_map_search_my_position
);
final
MyLocationConfiguration
myLocationConfiguration
=
new
MyLocationConfiguration
.
Builder
(
mCurrentMode
,
true
)
.
setArrow
(
arrow
)
.
setArrowSize
(
0.5f
)
// .setCustomMarker(customMarker)
.
setMarkerSize
(
0.2f
)
.
setAnimation
(
true
).
setMarkerRotation
(
false
)
.
build
();
mAMap
.
setOnMapLoadedCallback
(()
->
{
mAMap
.
setMyLocationEnabled
(
true
);
mAMap
.
setMyLocationConfiguration
(
myLocationConfiguration
);
});
// MyLocationStyle myLocationStyle = new MyLocationStyle();
// //设置自定义定位模式,定位、且将视角移动到地图中心点,定位点跟随设备移动
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);
// myLocationStyle.showMyLocation(false);
// mAMap.setMyLocationStyle(myLocationStyle);
// mAMap.setMyLocationEnabled(true);
//
// mAMap.getUiSettings().setZoomControlsEnabled(true);
//
// setUserMapCenter(LocationManager.getInstance().mLatitude, LocationManager.getInstance().mLongitude);
//
// mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
// @Override
// public void onCameraChange(CameraPosition cameraPosition) {
// LogUtils.dTag(TAG, "OnCameraChangeListener onCameraChange");
// }
//
// @Override
// public void onCameraChangeFinish(CameraPosition cameraPosition) {
// LogUtils.dTag(TAG, "OnCameraChangeListener onCameraChangeFinish,cameraPosition.tilt = " + cameraPosition.tilt + ",target = " + cameraPosition.target.toString());
// try {
// geocodeSearch = new GeocodeSearch(mContext);
// } catch (AMapException e) {
// e.printStackTrace();
// }
// geocodeSearch.setOnGeocodeSearchListener(onGeocodeSearchListener);
// LatLonPoint latLonPoint = new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude);
// geocodeSearch.getFromLocationAsyn(new RegeocodeQuery(latLonPoint, 1000, GeocodeSearch.AMAP));
//
// }
// });
}
/**
* 定位初始化
*/
public
void
initLocation
()
{
// 开启定位图层
mAMap
.
setMyLocationEnabled
(
true
);
// 定位初始化
try
{
LocationClient
.
setAgreePrivacy
(
true
);
mLocClient
=
new
LocationClient
(
mContext
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
mLocClient
.
registerLocationListener
(
myListener
);
LocationClientOption
option
=
new
LocationClientOption
();
// 打开gps
option
.
setOpenGps
(
true
);
// 设置坐标类型
option
.
setCoorType
(
"bd09ll"
);
//获取定位请求间隔
option
.
setScanSpan
(
2000
*
30
);
mLocClient
.
setLocOption
(
option
);
mLocClient
.
start
();
// POI text search works without device location.
}
private
Handler
mHandler
=
new
Handler
()
{
...
...
@@ -301,16 +234,11 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
}
};
private
void
initData
()
throws
AMapException
{
listSearchString
=
new
ArrayList
<
TrafficSearchResultBean
>();
if
(
null
!=
LocationManager
.
getInstance
().
getmAmapLocationn
())
{
String
searchValue
=
LocationManager
.
getInstance
().
getmAmapLocationn
().
getDescription
();
et_search_address
.
setText
(
searchValue
);
searchInputAddress
(
searchValue
);
}
private
void
initData
()
{
listSearchString
=
new
ArrayList
<>();
// Leave the search box empty: opening this page must not use cached location.
}
// private void setMarker(double lat, double lon) {
// LogUtils.v(TAG, "setMarker : lat : " + lat + " lon : " + lon);
// //定义Maker坐标点
...
...
@@ -378,21 +306,34 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
/**
* 轮询POI搜索返回的结果,添加到展示列表
*/
private
void
handleSearchSuggestionResult
()
{
private
void
handleSearchSuggestionResult
(
List
<
PoiItem
>
poiItems
)
{
listSearchString
.
clear
();
for
(
PoiItem
item
:
poiItem
List
)
{
for
(
PoiItem
item
:
poiItem
s
)
{
TrafficSearchResultBean
searchResultEntity
=
new
TrafficSearchResultBean
();
searchResultEntity
.
setName
(
item
.
getTitle
());
//获取POI的名称
searchResultEntity
.
setDistrict
(
item
.
getAdName
());
//获取行政区划分
searchResultEntity
.
setDistrict
(
fullPoiAddress
(
item
));
// POI address and GCJ-02 coordinates stay together
searchResultEntity
.
setCity
(
item
.
getCityName
());
//获取城市名
searchResultEntity
.
setLatitude
(
item
.
getLatLonPoint
()
!=
null
?
item
.
getLatLonPoint
().
getLatitude
()
:
0
);
//获取经纬度
searchResultEntity
.
setLongitude
(
item
.
getLatLonPoint
()
!=
null
?
item
.
getLatLonPoint
().
getLongitude
()
:
0
);
//获取经纬度
searchResultEntity
.
setUid
(
item
.
getPoiId
());
//获取POI ID
listSearchString
.
add
(
searchResultEntity
);
if
(
item
.
getLatLonPoint
()
==
null
)
continue
;
searchResultEntity
.
setLatitude
(
item
.
getLatLonPoint
().
getLatitude
());
searchResultEntity
.
setLongitude
(
item
.
getLatLonPoint
().
getLongitude
());
searchResultEntity
.
setUid
(
item
.
getPoiId
());
if
(
RescueLocationSelection
.
create
(
searchResultEntity
.
getName
(),
searchResultEntity
.
getDistrict
(),
searchResultEntity
.
getLatitude
(),
searchResultEntity
.
getLongitude
())
!=
null
)
{
listSearchString
.
add
(
searchResultEntity
);
}
}
updateSearchResultUI
();
}
private
String
fullPoiAddress
(
PoiItem
item
)
{
StringBuilder
address
=
new
StringBuilder
();
if
(
item
.
getCityName
()
!=
null
)
address
.
append
(
item
.
getCityName
());
if
(
item
.
getAdName
()
!=
null
)
address
.
append
(
item
.
getAdName
());
if
(
item
.
getSnippet
()
!=
null
)
address
.
append
(
item
.
getSnippet
());
if
(
item
.
getTitle
()
!=
null
&&
!
address
.
toString
().
contains
(
item
.
getTitle
()))
address
.
append
(
item
.
getTitle
());
return
address
.
toString
().
trim
();
}
private
void
updateSearchResultUI
()
{
mTrafficSearchAdapter
.
update
(
listSearchString
);
...
...
@@ -443,14 +384,34 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
private
void
searchInputAddress
(
String
searchName
)
throws
AMapException
{
String
city
=
null
;
AMapLocation
aMapLocation
=
LocationManager
.
getInstance
().
getmAmapLocationn
();
if
(
aMapLocation
!=
null
)
city
=
aMapLocation
.
getCity
();
query
=
new
PoiSearch
.
Query
(
searchName
,
null
,
city
);
// Every edit invalidates pending callbacks, including an edit that clears the query.
final
long
generation
=
poiSearchGate
.
begin
();
listSearchString
.
clear
();
updateSearchResultUI
();
if
(
searchName
==
null
||
searchName
.
trim
().
isEmpty
())
return
;
final
String
requestedText
=
searchName
.
trim
();
// A nationwide POI query needs no device location or cached city.
PoiSearch
.
Query
query
=
new
PoiSearch
.
Query
(
requestedText
,
null
);
query
.
setPageSize
(
10
);
poiSearch
=
new
PoiSearch
(
mContext
,
query
);
poiSearch
.
setOnPoiSearchListener
(
this
);
poiSearch
.
setOnPoiSearchListener
(
new
PoiSearch
.
OnPoiSearchListener
()
{
@Override
public
void
onPoiSearched
(
PoiResult
result
,
int
code
)
{
mHandler
.
post
(()
->
{
if
(
view
==
null
||
et_search_address
==
null
||
!
poiSearchGate
.
accepts
(
generation
,
requestedText
,
et_search_address
.
getText
().
toString
()))
return
;
List
<
PoiItem
>
pois
=
result
==
null
?
null
:
result
.
getPois
();
if
(
pois
!=
null
)
handleSearchSuggestionResult
(
pois
);
// The previous result was cleared when this search started.
});
}
@Override
public
void
onPoiItemSearched
(
PoiItem
item
,
int
code
)
{
}
});
poiSearch
.
searchPOIAsyn
();
}
...
...
@@ -463,8 +424,9 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
for
(
PoiItem
item
:
listResult
)
{
TrafficSearchResultBean
searchResultEntity
=
new
TrafficSearchResultBean
();
searchResultEntity
.
setName
(
item
.
getTitle
());
searchResultEntity
.
setDistrict
(
item
.
getAdName
(
));
searchResultEntity
.
setDistrict
(
fullPoiAddress
(
item
));
searchResultEntity
.
setCity
(
item
.
getCityName
());
if
(
item
.
getLatLonPoint
()
==
null
)
continue
;
searchResultEntity
.
setLatitude
(
item
.
getLatLonPoint
().
getLatitude
());
searchResultEntity
.
setLongitude
(
item
.
getLatLonPoint
().
getLongitude
());
searchResultEntity
.
setUid
(
item
.
getPoiId
());
...
...
@@ -477,143 +439,34 @@ public class DamageChoosePosFragment extends BaseFragment implements View.OnClic
@Override
public
void
onDestroyView
()
{
poiSearchGate
.
invalidate
();
poiSearch
=
null
;
super
.
onDestroyView
();
// mBaiduMap.setMyLocationEnabled(false);
mMapView
.
getMap
().
clear
();
mMapView
.
onDestroy
();
mMapView
=
null
;
}
@Override
public
void
onPoiSearched
(
PoiResult
poiResult
,
int
i
)
{
//处理sug检索结果
poiItemList
=
poiResult
.
getPois
();
handleSearchSuggestionResult
();
}
if
(
mMapView
!=
null
)
{
mMapView
.
getMap
().
clear
();
mMapView
.
onDestroy
();
mMapView
=
null
;
}
mAMap
=
null
;
@Override
public
void
onPoiItemSearched
(
PoiItem
poiItem
,
int
i
)
{
}
// 是否首次定位
private
boolean
isFirstLoc
=
true
;
private
MyLocationData
myLocationData
;
private
int
mCurrentDirection
=
0
;
private
double
mCurrentLat
=
0.0
;
private
double
mCurrentLon
=
0.0
;
private
float
mCurrentAccracy
;
static
final
class
PoiSearchGate
{
private
volatile
long
currentSearch
;
/**
* 定位SDK监听函数
*/
public
class
MyLocationListener
extends
BDAbstractLocationListener
{
@Override
public
void
onReceiveLocation
(
BDLocation
location
)
{
// MapView 销毁后不在处理新接收的位置
if
(
location
==
null
||
mMapView
==
null
)
{
return
;
}
mCurrentLat
=
location
.
getLatitude
();
mCurrentLon
=
location
.
getLongitude
();
mCurrentAccracy
=
location
.
getRadius
();
myLocationData
=
new
MyLocationData
.
Builder
()
.
accuracy
(
location
.
getRadius
())
// 设置定位数据的精度信息,单位:米
.
direction
(
mCurrentDirection
)
// 此处设置开发者获取到的方向信息,顺时针0-360
.
latitude
(
location
.
getLatitude
())
.
longitude
(
location
.
getLongitude
())
.
build
();
mAMap
.
setMyLocationData
(
myLocationData
);
if
(
isFirstLoc
)
{
isFirstLoc
=
false
;
com
.
baidu
.
mapapi
.
model
.
LatLng
ll
=
new
com
.
baidu
.
mapapi
.
model
.
LatLng
(
location
.
getLatitude
(),
location
.
getLongitude
());
MapStatus
.
Builder
builder
=
new
MapStatus
.
Builder
();
builder
.
target
(
ll
).
zoom
(
18.0f
);
mAMap
.
animateMapStatus
(
MapStatusUpdateFactory
.
newMapStatus
(
builder
.
build
()));
}
// mMyLoc = new StdLatLng(2, mCurrentLat, mCurrentLon);
// updateMarkDistance(mMyLoc);
StdLatLng
std
=
new
StdLatLng
(
GPSData
.
COORD_TYPE_AMAP
,
mCurrentLat
,
mCurrentLon
);
long
begin
()
{
return
++
currentSearch
;
}
try
{
// callOnSuper(std);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
void
invalidate
()
{
++
currentSearch
;
}
boolean
accepts
(
long
search
,
String
requestedText
,
String
visibleText
)
{
return
search
==
currentSearch
&&
requestedText
!=
null
&&
visibleText
!=
null
&&
requestedText
.
equals
(
visibleText
.
trim
());
}
}
// private void callOnSuper(StdLatLng std) throws Exception {
// super.onReceiveMyLocation(std);
// updateMarkDistance(std);
// }
// private void updateMarkDistance(StdLatLng myPos) throws Exception {
// if (mAMap == null) {
// LogUtils.wTag(TAG, "mMap is not ready.");
// return;
// }
// if (!isWifiMode) {
//// LatLng my = fromStdLatLng(myPos);\
// com.baidu.mapapi.model.LatLng my = new com.baidu.mapapi.model.LatLng(myPos.getLatitude(), myPos.getLongitude());
// if (null != mTrackCarMar) {
// com.baidu.mapapi.model.LatLng car = mTrackCarMar.getPosition();
// LogFileEx.INSTANCE.logFile("updateMarkDistance1 car.lat=" + car.latitude +
// " car.lon=" + car.longitude + " my.lat=" + my.latitude + " my.lon=" + my.longitude);
//// mMap.clear();
////// LogUtils.vTag(TAG, "updateMarkDistance1 car.lat=" + car.latitude +
////// " car.lon=" + car.longitude + " my.lat=" + my.latitude + " my.lon=" + my.longitude);
//// String distance = "距您" + getDistanceStr((int) AMapUtils.calculateLineDistance(car, my));
//// LogUtils.dTag(TAG, "updateMarkDistance,distance=" + distance);
//// LatLng ll = new LatLng(car.latitude, car.longitude);
//// MarkerOptions oo = new MarkerOptions()
//// .position(ll)
//// .icon(getMarkIcon(distance));
//// mTrackCarMar = mMap.addMarker(oo);
//// searchDistance(car.latitude, car.longitude, my.latitude, my.longitude);
// updateDistance(car, my);
// } else {
// double carLat = RemoteCarPositionManager.instance().getCarLocationLat();
// double carLng = RemoteCarPositionManager.instance().getCarLocationLng();
// LogFileEx.INSTANCE.logFile("updateMarkDistance2 car.lat=" + carLat +
// " car.lon=" + carLng + " my.lat=" + my.latitude + " my.lon=" + my.longitude);
//
// if (Math.abs(carLat) > 0.1 && Math.abs(carLng) > 0.1) {
// com.baidu.mapapi.model.LatLng car = new com.baidu.mapapi.model.LatLng(carLat, carLng);
//// mMap.clear();
////
//// String distance = "距您" + getDistanceStr((int) AMapUtils.calculateLineDistance(car, my));
////// LogUtils.dTag(TAG, "updateMarkDistance,distance=" + distance);
//// LatLng ll = new LatLng(car.latitude, car.longitude);
//// MarkerOptions oo = new MarkerOptions()
//// .position(ll)
//// .icon(getMarkIcon(distance));
//// mTrackCarMar = mMap.addMarker(oo);
//
//// searchDistance(car.latitude, car.longitude, my.latitude, my.longitude);
// updateDistance(car, my);
// }
// }
// }
// }
//
// private void updateDistance(com.baidu.mapapi.model.LatLng car, com.baidu.mapapi.model.LatLng my){
// if (null == mAMap) {
// return;
// }
// mAMap.clear();
// String distance = "距您" + getDistanceStr((int) DistanceUtil.getDistance(car, my));
//
// com.baidu.mapapi.map.MarkerOptions oo = new com.baidu.mapapi.map.MarkerOptions()
// .position(car)
// .icon(getMarkIcon(distance))
// .zIndex(9);
// mTrackCarMar = (Marker) mBaiduMap.addOverlay(oo);
// }
}
\ No newline at end of file
app/src/main/java/com/glsx/aicar/ui/fragment/accident/PhotoDamageFragment.java
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
accident
;
import
static
android
.
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
;
import
static
com
.
alibaba
.
sdk
.
android
.
vod
.
upload
.
model
.
UploadFileInfo
.
UPLOAD_FILE_TYPE_IMAGE
;
import
static
com
.
alibaba
.
sdk
.
android
.
vod
.
upload
.
model
.
UploadFileInfo
.
UPLOAD_FILE_TYPE_VIDEO
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.Manifest
;
import
android.content.ClipData
;
import
android.content.pm.PackageManager
;
import
android.media.MediaMetadataRetriever
;
import
android.webkit.MimeTypeMap
;
import
com.amap.api.location.AMapLocation
;
import
com.amap.api.location.AMapLocationClient
;
import
com.amap.api.location.AMapLocationClientOption
;
import
com.glsx.aicar.BuildConfig
;
import
androidx.core.content.ContextCompat
;
import
java.io.InputStream
;
import
java.io.FileOutputStream
;
import
android.content.ContentResolver
;
import
android.content.ContentUris
;
import
android.content.Context
;
...
...
@@ -17,6 +28,7 @@ import android.os.Bundle;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.os.Looper
;
import
android.provider.DocumentsContract
;
import
android.provider.MediaStore
;
import
android.text.TextUtils
;
...
...
@@ -24,6 +36,7 @@ import android.view.Gravity;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewStub
;
import
android.view.WindowManager
;
import
android.widget.AdapterView
;
import
android.widget.Button
;
...
...
@@ -71,7 +84,6 @@ import com.baidu.mapapi.search.route.RoutePlanSearch;
import
com.baidu.mapapi.search.route.TransitRouteResult
;
import
com.baidu.mapapi.search.route.WalkingRouteResult
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.PermissionUtils
;
import
com.glsx.aicar.R
;
import
com.glsx.aicar.adapter.DamagePhotoAdapter
;
import
com.glsx.aicar.manager.LocationManager
;
...
...
@@ -94,8 +106,6 @@ import com.glsx.libaccount.http.entity.accident.AccidentUploadFileDetail;
import
com.glsx.libaccount.http.entity.fileupload.FileInfo
;
import
com.glsx.libaccount.http.inface.accident.SubmitDamagePhotoCallBack
;
import
com.glsx.libaccount.http.inface.fileupload.ALiYunUpLoadFileTokenCallBack
;
import
com.huantansheng.easyphotos.EasyPhotos
;
import
com.huantansheng.easyphotos.models.album.entity.Photo
;
import
com.kongzue.dialogx.DialogX
;
import
com.kongzue.dialogx.dialogs.MessageDialog
;
import
com.kongzue.dialogx.dialogs.TipDialog
;
...
...
@@ -120,6 +130,9 @@ import java.io.IOException;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.HashMap
;
import
java.util.concurrent.atomic.AtomicReference
;
import
me.yokeyword.fragmentation.ISupportActivity
;
...
...
@@ -170,10 +183,11 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
private
GridView
gv_damage1
;
//已选中待上传的文件列表,在GridView中进行展示
private
ArrayList
<
AccidentRecordDetailPhoto
>
mAccidentRecordPhotoList
=
new
ArrayList
<>();
//
已上传完成的文件列表,需要作为参数上传至后台
private
ArrayList
<
AccidentUploadFileDetail
>
mAccidentUploadFileDetailList
=
new
ArrayList
<>();
//
Upload results remain tied to media still visible to the user.
private
final
Map
<
String
,
AccidentUploadFileDetail
>
uploadedMediaByPath
=
new
HashMap
<>();
//已选择文件列表
private
List
<
AccidentRecordDetailPhoto
>
mSelectedFileList
=
new
ArrayList
<>();
private
final
List
<
File
>
createdMediaFiles
=
new
ArrayList
<>();
public
final
int
FROM_GALLERY
=
0x1000
;
public
final
int
FROM_CAMERA
=
0x2000
;
...
...
@@ -198,14 +212,19 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
private
double
storeLat
;
private
double
storeLng
;
//阿里云上传实例
private
static
VODUploadClient
UploadClient
;
//正在上传文件的文件信息对象
private
static
FileInfo
mUpLoadingFileInfo
=
null
;
// Each upload has its own callback/client. A previous attempt must never complete a retry.
private
volatile
FileInfo
mUpLoadingFileInfo
;
private
final
UploadAttemptGate
uploadAttemptGate
=
new
UploadAttemptGate
();
MyHandler
myHandler
=
new
MyHandler
(
PhotoDamageFragment
.
this
);
private
static
final
int
REQUEST_CODE_CHOOSE
=
101
;
private
static
final
int
REQUEST_CAMERA_PERMISSION
=
102
;
private
RescueLocationSelection
selectedLocation
;
private
AMapLocationClient
rescueLocationClient
;
private
final
Handler
rescueLocationHandler
=
new
Handler
(
Looper
.
getMainLooper
());
private
Runnable
rescueLocationTimeout
;
private
volatile
boolean
rescueBusy
;
private
boolean
mediaCopyInProgress
;
public
PhotoDamageFragment
()
{
}
...
...
@@ -231,7 +250,6 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
mContext
=
getContext
();
initViews
();
getArgumentsData
();
initALiYunUpLoad
();
try
{
initMapViews
(
savedInstanceState
);
}
catch
(
Exception
e
)
{
...
...
@@ -247,7 +265,7 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
tv_common_title_name
.
setOnClickListener
(
this
);
tv_common_title_name
.
setText
(
getResources
().
getString
(
R
.
string
.
public_accident_take_picture
));
mMapView
=
(
MapView
)
view
.
findViewById
(
R
.
id
.
mapView
);
ll_arrive_time
=
view
.
findViewById
(
R
.
id
.
ll_arrive_time
);
tv_arrive_tiem
=
view
.
findViewById
(
R
.
id
.
tv_arrive_tiem
);
...
...
@@ -274,7 +292,13 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
@Override
public
void
DeleteClick
(
int
position
)
{
//已选择文件的缩略图展示删除按钮,删除按钮的点击监听及处理,删除该列表当前索引的文件
mAccidentRecordPhotoList
.
remove
(
position
);
if
(
rescueBusy
||
mediaCopyInProgress
)
{
ToastUtil
.
show
(
"请等待当前操作完成"
);
return
;
}
AccidentRecordDetailPhoto
removed
=
mAccidentRecordPhotoList
.
remove
(
position
);
uploadedMediaByPath
.
remove
(
removed
.
getFilePath
());
discardPrivateMedia
(
removed
);
//已选择文件列表,文件数为0,则添加默认图标
if
(
mAccidentRecordPhotoList
.
size
()
==
0
)
{
mAccidentRecordPhotoList
.
add
(
getDefaultDetailPhotoBean
());
...
...
@@ -287,16 +311,29 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
LogUtils
.
d
(
TAG
,
"gv_damage1 onItemClick position= "
+
position
);
if
(
mediaCopyInProgress
||
rescueBusy
)
{
ToastUtil
.
show
(
"请等待当前操作完成"
);
return
;
}
gvDamageIndex
=
position
;
//默认点击了已选择文件列表的最后一个ImageView后,弹出添加文件的选择框
if
(
gvDamageIndex
==
mAccidentRecordPhotoList
.
size
()
-
1
)
{
if
(
gvDamageIndex
==
mAccidentRecordPhotoList
.
size
()
-
1
&&
TextUtils
.
isEmpty
(
mAccidentRecordPhotoList
.
get
(
gvDamageIndex
).
getFilePath
()))
{
if
(
mAccidentRecordPhotoList
.
size
()
-
1
>=
3
)
{
ToastUtil
.
show
(
"最多选择3个文件"
);
return
;
}
showChoosePhotoPopWindow
();
}
}
});
mAccidentRecordPhotoList
.
add
(
getDefaultDetailPhotoBean
());
if
(
mAccidentRecordPhotoList
.
isEmpty
())
mAccidentRecordPhotoList
.
add
(
getDefaultDetailPhotoBean
());
if
(
selectedLocation
!=
null
)
{
tv_accident_positon
.
setText
(
selectedLocation
.
label
);
tv_accident_positon_address
.
setText
(
selectedLocation
.
address
);
}
damagePhotoAdapter1
.
notifyDataSetChanged
();
}
...
...
@@ -333,7 +370,15 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
private
void
initMapViews
(
Bundle
bundle
)
throws
Exception
{
// mMapView.onCreate(bundle);
// mAMap = mMapView.getMap();
map
=
mMapView
.
getMap
();
ViewStub
mapStub
=
view
.
findViewById
(
R
.
id
.
rescue_map_stub
);
if
(
BuildConfig
.
DEBUG
)
{
mapStub
.
setLayoutResource
(
R
.
layout
.
rescue_debug_map_placeholder
);
mapStub
.
inflate
();
view
.
findViewById
(
R
.
id
.
iv_center_location
).
setVisibility
(
View
.
GONE
);
}
else
{
mMapView
=
(
MapView
)
mapStub
.
inflate
();
map
=
mMapView
.
getMap
();
}
// MyLocationStyle myLocationStyle = new MyLocationStyle();
//设置自定义定位模式,定位、且将视角移动到地图中心点,定位点跟随设备移动
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);
...
...
@@ -344,39 +389,11 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
// initLocation();
map
.
setMyLocationEnabled
(
true
);
MyLocationConfiguration
myLocationConfiguration
=
new
MyLocationConfiguration
.
Builder
(
MyLocationConfiguration
.
LocationMode
.
NORMAL
,
true
)
// .setArrow(arrow).setArrowSize(0.5f)
// .setCustomMarker(customMarker).setMarkerSize(0.2f)
.
setAnimation
(
true
).
setMarkerRotation
(
false
)
.
build
();
map
.
setOnMapLoadedCallback
(()
->
{
map
.
setMyLocationEnabled
(
true
);
map
.
setMyLocationConfiguration
(
myLocationConfiguration
);
});
// mAMap.setMyLocationStyle(myLocationStyle);
// mAMap.setMyLocationEnabled(true);
// mAMap.getUiSettings().setZoomControlsEnabled(false);
// mRouteSearch = new RouteSearch(mContext);
mSearch
=
RoutePlanSearch
.
newInstance
();
mSearch
.
setOnGetRoutePlanResultListener
(
this
);
//setMarker(LocationManager.getInstance().mLatitude, LocationManager.getInstance().mLongitude);
mDamageLatitude
=
LocationManager
.
getInstance
().
mLatitude
;
mDamageLongitude
=
LocationManager
.
getInstance
().
mLongitude
;
setUserMapCenter
(
mDamageLatitude
,
mDamageLongitude
);
if
(
null
!=
LocationManager
.
getInstance
().
getmAmapLocationn
())
{
tv_accident_positon
.
setText
(
LocationManager
.
getInstance
().
getmAmapLocationn
().
getDescription
());
tv_accident_positon_address
.
setText
(
LocationManager
.
getInstance
().
getmAmapLocationn
().
getAddress
());
LogUtils
.
dTag
(
TAG
,
"getTimeRouteResult initMapViews"
);
getTimeRouteResult
(
mDamageLatitude
,
mDamageLongitude
,
storeLat
,
storeLng
);
// Wait for an explicit user action before obtaining device location.
if
(
map
!=
null
)
{
mSearch
=
RoutePlanSearch
.
newInstance
();
mSearch
.
setOnGetRoutePlanResultListener
(
this
);
}
clearDamagePhotosPath
();
}
// /**
...
...
@@ -454,51 +471,28 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
// }
// }
private
static
LatLng
gcjToBaidu
(
double
latitude
,
double
longitude
)
{
double
pi
=
3.14159265358979324
*
3000.0
/
180.0
;
double
z
=
Math
.
sqrt
(
longitude
*
longitude
+
latitude
*
latitude
)
+
0.00002
*
Math
.
sin
(
latitude
*
pi
);
double
theta
=
Math
.
atan2
(
latitude
,
longitude
)
+
0.000003
*
Math
.
cos
(
longitude
*
pi
);
return
new
LatLng
(
z
*
Math
.
sin
(
theta
)
+
0.006
,
z
*
Math
.
cos
(
theta
)
+
0.0065
);
}
private
void
setUserMapCenter
(
double
lat
,
double
lon
)
{
if
(
map
==
null
)
return
;
LogUtils
.
v
(
TAG
,
"setUserMapCenter : lat : "
+
lat
+
" lon : "
+
lon
);
// LatLng cenpt = new LatLng(lat, lon);
// CameraUpdate cameraUpdateFactory = CameraUpdateFactory.newLatLngZoom(cenpt, 15);
// mAMap.moveCamera(cameraUpdateFactory);
double
PI
=
3.14159265358979324
*
3000.0
/
180.0
;
double
x
=
lon
,
y
=
lat
;
double
z
=
Math
.
sqrt
(
x
*
x
+
y
*
y
)
+
0.00002
*
Math
.
sin
(
y
*
PI
);
double
theta
=
Math
.
atan2
(
y
,
x
)
+
0.000003
*
Math
.
cos
(
x
*
PI
);
double
tempLon
=
z
*
Math
.
cos
(
theta
)
+
0.0065
;
double
tempLat
=
z
*
Math
.
sin
(
theta
)
+
0.006
;
LatLng
baiduPoint
=
gcjToBaidu
(
lat
,
lon
);
MapStatus
.
Builder
builder
=
new
MapStatus
.
Builder
();
builder
.
target
(
new
LatLng
(
tempLat
,
tempLon
)
).
zoom
(
18.0f
);
builder
.
target
(
baiduPoint
).
zoom
(
18.0f
);
map
.
animateMapStatus
(
MapStatusUpdateFactory
.
newMapStatus
(
builder
.
build
()));
}
private
void
clearDamagePhotosPath
()
{
if
(!
PermissionUtils
.
isGranted
(
WRITE_EXTERNAL_STORAGE
))
{
PermissionUtils
.
permission
(
WRITE_EXTERNAL_STORAGE
).
request
();
}
else
{
String
sdcardState
=
Environment
.
getExternalStorageState
();
String
sdcardPathDir
=
CommonConst
.
SDCARD_DAMAGE_PHOTOS_PATH
;
if
(
Environment
.
MEDIA_MOUNTED
.
equals
(
sdcardState
))
{
// 有sd卡,是否有myImage文件夹
File
fileDir
=
new
File
(
sdcardPathDir
);
if
(!
fileDir
.
exists
())
{
fileDir
.
mkdirs
();
}
else
{
//遍历文件夹
if
(
fileDir
.
isDirectory
())
{
File
[]
files
=
fileDir
.
listFiles
();
for
(
File
tempfile
:
files
)
{
tempfile
.
delete
();
}
}
}
}
}
}
@Override
public
void
onStart
()
{
super
.
onStart
();
...
...
@@ -532,13 +526,22 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
break
;
case
R
.
id
.
btn_send_damage
:
if
(
rescueBusy
||
mediaCopyInProgress
)
{
ToastUtil
.
show
(
"请等待当前操作完成"
);
return
;
}
if
(
selectedLocation
==
null
)
{
ToastUtil
.
show
(
"请先选择事故地点"
);
return
;
}
if
(
mAccidentRecordPhotoList
.
size
()
<
2
)
{
showDialog
(
getResources
().
getString
(
R
.
string
.
warnning_tips
),
getResources
().
getString
(
R
.
string
.
toSureSendRequest
),
TYPE_MESSAGE_DIALOG
,
true
);
// sendDamageEventToServer();
}
else
{
//开始上传已选择文件列表
s
tartUpLoadMediaFileList
(
);
s
etRescueBusy
(
true
);
showDialog
(
""
,
getResources
().
getString
(
R
.
string
.
file_uploading
),
TYPE_WAITDIALOG
,
false
);
startUpLoadMediaFileList
();
}
break
;
case
R
.
id
.
iv_current_location
:
...
...
@@ -559,21 +562,78 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
*/
private
void
showCurrentLocation
()
{
PermissionRequestUtil
.
requestLocationPermissions
(
mContext
,
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
LogUtils
.
d
(
TAG
,
"showCurrentLocation ..."
);
mDamageLatitude
=
LocationManager
.
getInstance
().
mLatitude
;
mDamageLongitude
=
LocationManager
.
getInstance
().
mLongitude
;
setUserMapCenter
(
mDamageLatitude
,
mDamageLongitude
);
@Override
public
void
onGranted
()
{
stopRescueLocation
();
if
(!
isAdded
())
return
;
try
{
AMapLocationClient
client
=
new
AMapLocationClient
(
mContext
.
getApplicationContext
());
AMapLocationClientOption
option
=
new
AMapLocationClientOption
();
option
.
setLocationMode
(
AMapLocationClientOption
.
AMapLocationMode
.
Hight_Accuracy
);
option
.
setNeedAddress
(
true
);
option
.
setLocationCacheEnable
(
false
);
option
.
setOnceLocation
(
true
);
option
.
setHttpTimeOut
(
15000
);
client
.
setLocationOption
(
option
);
rescueLocationClient
=
client
;
client
.
setLocationListener
(
location
->
rescueLocationHandler
.
post
(()
->
{
if
(
client
!=
rescueLocationClient
)
return
;
if
(
location
!=
null
&&
location
.
getErrorCode
()
==
0
)
{
RescueLocationSelection
choice
=
RescueLocationSelection
.
create
(
TextUtils
.
isEmpty
(
location
.
getDescription
())
?
location
.
getAddress
()
:
location
.
getDescription
(),
location
.
getAddress
(),
location
.
getLatitude
(),
location
.
getLongitude
());
if
(
choice
!=
null
&&
isAdded
()
&&
getView
()
!=
null
)
{
selectLocation
(
choice
);
stopRescueLocation
();
return
;
}
}
stopRescueLocation
();
if
(
isAdded
())
ToastUtil
.
show
(
"定位失败,请手动选择事故地点"
);
}));
rescueLocationTimeout
=
()
->
{
if
(
client
==
rescueLocationClient
)
{
stopRescueLocation
();
if
(
isAdded
())
ToastUtil
.
show
(
"定位超时,请手动选择事故地点"
);
}
};
rescueLocationHandler
.
postDelayed
(
rescueLocationTimeout
,
20000
);
client
.
startLocation
();
}
catch
(
Exception
e
)
{
stopRescueLocation
();
ToastUtil
.
show
(
"定位失败,请手动选择事故地点"
);
}
}
@Override
public
void
onDenied
()
{
@Override
public
void
onDenied
()
{
stopRescueLocation
();
ToastUtil
.
show
(
"可手动搜索并选择事故地点"
);
}
});
}
private
void
stopRescueLocation
()
{
if
(
rescueLocationTimeout
!=
null
)
{
rescueLocationHandler
.
removeCallbacks
(
rescueLocationTimeout
);
rescueLocationTimeout
=
null
;
}
if
(
rescueLocationClient
!=
null
)
{
rescueLocationClient
.
stopLocation
();
rescueLocationClient
.
onDestroy
();
rescueLocationClient
=
null
;
}
}
private
void
selectLocation
(
RescueLocationSelection
choice
)
{
selectedLocation
=
choice
;
mDamageLatitude
=
choice
.
latitude
;
mDamageLongitude
=
choice
.
longitude
;
tv_accident_positon
.
setText
(
choice
.
label
);
tv_accident_positon_address
.
setText
(
choice
.
address
);
setUserMapCenter
(
choice
.
latitude
,
choice
.
longitude
);
if
(
map
!=
null
&&
storeLat
!=
0
&&
storeLng
!=
0
)
{
getTimeRouteResult
(
storeLat
,
storeLng
,
choice
.
latitude
,
choice
.
longitude
);
}
}
private
static
final
int
TYPE_WAITDIALOG
=
1
;
private
static
final
int
TYPE_SUCCEED_DIALOG
=
2
;
private
static
final
int
TYPE_FAILED_DIALOG
=
3
;
...
...
@@ -600,6 +660,7 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
public
boolean
onBackPressed
(
WaitDialog
dialog
)
{
// if(mAccidentRecordPhotoList.size()>1){
UploadMediaFileToALiYunManager
.
getInstance
().
stopUploadFile
();
setRescueBusy
(
false
);
closeDialog
(
0
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
request_cancel
),
TYPE_FAILED_DIALOG
,
false
);
// }
...
...
@@ -667,19 +728,16 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
public
void
onDamageChoosePositionSuccess
(
TrafficSearchResultBean
resultBean
)
{
LogUtils
.
d
(
TAG
,
"onDamageChoosePositionSuccess resultBean"
+
resultBean
.
getName
());
mDamageLatitude
=
resultBean
.
getLatitude
();
mDamageLongitude
=
resultBean
.
getLongitude
();
setUserMapCenter
(
mDamageLatitude
,
mDamageLongitude
);
tv_accident_positon
.
setText
(
resultBean
.
getName
());
tv_accident_positon_address
.
setText
(
resultBean
.
getDistrict
());
LogUtils
.
dTag
(
TAG
,
"getTimeRouteResult onDamageChoosePositionSuccess"
);
getTimeRouteResult
(
storeLat
,
storeLng
,
resultBean
.
getLatitude
(),
resultBean
.
getLongitude
());
if
(
resultBean
==
null
)
return
;
RescueLocationSelection
choice
=
RescueLocationSelection
.
create
(
resultBean
.
getName
(),
resultBean
.
getDistrict
(),
resultBean
.
getLatitude
(),
resultBean
.
getLongitude
());
if
(
choice
==
null
)
{
ToastUtil
.
show
(
"地点没有有效地址或坐标,请重新选择"
);
return
;
}
selectLocation
(
choice
);
}
/**
* 根据门店位置及经纬度,按时间最短计算到事故位置的最快时间
*
...
...
@@ -786,7 +844,7 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
return
;
}
if
(
result
.
error
==
SearchResult
.
ERRORNO
.
NO_ERROR
)
{
if
(!
result
.
getRouteLines
().
isEmpty
())
{
if
(
result
.
getRouteLines
()
!=
null
&&
!
result
.
getRouteLines
().
isEmpty
())
{
RouteLine
mRouteLine
=
result
.
getRouteLines
().
get
(
0
);
DrivingRouteOverlayBAIDU
overlay
=
new
MyDrivingRouteOverlay
(
map
);
map
.
setOnMarkerClickListener
(
overlay
);
...
...
@@ -815,8 +873,8 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
});
PlanNode
start_point
=
PlanNode
.
withLocation
(
new
LatLng
(
startLat
,
startLng
));
PlanNode
end_point
=
PlanNode
.
withLocation
(
new
LatLng
(
endLat
,
endLng
));
PlanNode
start_point
=
PlanNode
.
withLocation
(
gcjToBaidu
(
startLat
,
startLng
));
PlanNode
end_point
=
PlanNode
.
withLocation
(
gcjToBaidu
(
endLat
,
endLng
));
mSearch
.
drivingSearch
(
new
DrivingRoutePlanOption
()
.
trafficPolicy
(
DrivingRoutePlanOption
.
DrivingTrafficPolicy
.
ROUTE_PATH
)
.
from
(
start_point
).
to
(
end_point
)
...
...
@@ -900,67 +958,21 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
});
LinearLayout
cameraClick
=
popupWindowView
.
findViewById
(
R
.
id
.
from_camera
);
cameraClick
.
setOnClickListener
(
view
->
{
if
(!
PermissionRequestUtil
.
checkAppCamPermissions
(
getContext
()))
{
PermissionRequestUtil
.
showRequestPhotoPermissionTipsDialog
(
getContext
(),
new
PermissionDialogUtil
.
IRequirePermissionAll
()
{
@Override
public
void
OnClickConfirm
()
{
PermissionRequestUtil
.
requestCameraPermissions
(
getActivity
(),
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
fromCamera
();
popupWindow
.
dismiss
();
popupWindow
=
null
;
}
@Override
public
void
onDenied
()
{
}
});
}
@Override
public
void
OnClickCancel
()
{
}
});
cameraClick
.
setOnClickListener
(
clicked
->
{
popupWindow
.
dismiss
();
popupWindow
=
null
;
if
(
ContextCompat
.
checkSelfPermission
(
mContext
,
Manifest
.
permission
.
CAMERA
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
fromCamera
();
}
else
{
PermissionRequestUtil
.
requestCameraPermissions
(
getActivity
(),
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
fromCamera
();
popupWindow
.
dismiss
();
popupWindow
=
null
;
}
@Override
public
void
onDenied
()
{
}
});
requestPermissions
(
new
String
[]{
Manifest
.
permission
.
CAMERA
},
REQUEST_CAMERA_PERMISSION
);
}
});
LinearLayout
galleryClick
=
popupWindowView
.
findViewById
(
R
.
id
.
from_gallery
);
galleryClick
.
setOnClickListener
(
view
->
{
PermissionRequestUtil
.
requestStoragePermissions
(
getActivity
(),
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
fromGallery
();
popupWindow
.
dismiss
();
popupWindow
=
null
;
}
@Override
public
void
onDenied
()
{
}
});
galleryClick
.
setOnClickListener
(
clicked
->
{
popupWindow
.
dismiss
();
popupWindow
=
null
;
fromGallery
();
});
//设置弹框属性
...
...
@@ -1003,9 +1015,22 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
* json格式化已上传文件列表的信息,同时向后台发送救援请求
*/
private
void
sendDamageEventToServer
()
{
if
(
selectedLocation
==
null
)
{
setRescueBusy
(
false
);
ToastUtil
.
show
(
"请先选择事故地点"
);
return
;
}
JSONArray
damageJsonArray
=
new
JSONArray
();
for
(
AccidentUploadFileDetail
item
:
mAccidentUploadFileDetailList
)
{
for
(
AccidentRecordDetailPhoto
selected
:
mAccidentRecordPhotoList
)
{
if
(
TextUtils
.
isEmpty
(
selected
.
getFilePath
()))
continue
;
AccidentUploadFileDetail
item
=
uploadedMediaByPath
.
get
(
selected
.
getFilePath
());
if
(
item
==
null
)
{
setRescueBusy
(
false
);
closeDialog
(
0
);
ToastUtil
.
show
(
"附件尚未上传完成,请重试"
);
return
;
}
JSONObject
damageObj
=
new
JSONObject
();
try
{
if
(
"image"
.
equals
(
item
.
getFileType
()))
{
...
...
@@ -1026,15 +1051,14 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
mediaList
=
damageJsonArray
.
toString
().
replace
(
"\\/"
,
"/"
);
}
//百度转高德坐标※
double
[]
latLngGaode
=
MapUtil
.
bdToGaoDe
(
mDamageLatitude
,
mDamageLongitude
);
String
lat
=
String
.
valueOf
(
latLngGaode
[
0
]);
String
lng
=
String
.
valueOf
(
latLngGaode
[
1
]);
// AMap fixes and POIs are already GCJ-02, the rescue API's coordinate system.
String
lat
=
selectedLocation
.
latitudeForRequest
();
String
lng
=
selectedLocation
.
longitudeForRequest
();
String
phone
=
AccountManager
.
getInstance
().
getAccountMobile
();
String
mAddress
=
LocationManager
.
getInstance
().
getmAmapLocationn
().
getAddress
();
// LoadingDialog.getInstance().showLoadingDialogHideMeg();
String
mAddress
=
selectedLocation
.
address
;
showDialog
(
""
,
getResources
().
getString
(
R
.
string
.
send_requesting
),
TYPE_WAITDIALOG
,
false
);
LogUtils
.
d
(
TAG
,
"sendDamageEventToServer damageJsonArray = "
+
mediaList
.
toString
());
setRescueBusy
(
true
);
LogUtils
.
d
(
TAG
,
"sendDamageEventToServer media count="
+
damageJsonArray
.
length
());
AccidentApiManager
.
getInstance
().
submitAccidentSaveRequest
(
phone
,
lng
,
lat
,
mAddress
,
mediaList
,
this
,
this
);
}
...
...
@@ -1042,9 +1066,41 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
* 开始上传已选择文件列表中的所有文件,从列表第一个文件开始上传
*/
private
void
startUpLoadMediaFileList
()
{
if
(
mAccidentRecordPhotoList
.
size
()
>
1
)
{
getALiYunUpLoadFileToken
(
mAccidentRecordPhotoList
.
get
(
0
));
if
(
BuildConfig
.
DEBUG
)
{
uploadedMediaByPath
.
clear
();
for
(
AccidentRecordDetailPhoto
file
:
mAccidentRecordPhotoList
)
{
if
(
TextUtils
.
isEmpty
(
file
.
getFilePath
()))
continue
;
AccidentUploadFileDetail
uploaded
=
new
AccidentUploadFileDetail
();
if
(
RescueMediaType
.
isVideoExtension
(
file
.
getFileType
()))
{
uploaded
.
setFileType
(
"video"
);
uploaded
.
setVideoId
(
"debug-video-"
+
new
File
(
file
.
getFilePath
()).
getName
());
}
else
{
uploaded
.
setFileType
(
"image"
);
uploaded
.
setImageUrl
(
"debug://not-uploaded/"
+
new
File
(
file
.
getFilePath
()).
getName
());
}
uploadedMediaByPath
.
put
(
file
.
getFilePath
(),
uploaded
);
}
sendDamageEventToServer
();
return
;
}
for
(
AccidentRecordDetailPhoto
file
:
mAccidentRecordPhotoList
)
{
if
(!
TextUtils
.
isEmpty
(
file
.
getFilePath
())
&&
!
uploadedMediaByPath
.
containsKey
(
file
.
getFilePath
()))
{
getALiYunUpLoadFileToken
(
file
);
return
;
}
}
sendDamageEventToServer
();
}
private
void
setRescueBusy
(
boolean
busy
)
{
rescueBusy
=
busy
;
if
(!
busy
)
invalidateUploadAttempt
();
if
(
btn_send_damage
!=
null
)
btn_send_damage
.
setEnabled
(!
busy
&&
!
mediaCopyInProgress
);
}
private
void
invalidateUploadAttempt
()
{
uploadAttemptGate
.
invalidate
();
mUpLoadingFileInfo
=
null
;
}
private
boolean
checkPhotoListisEmpty
()
{
...
...
@@ -1071,17 +1127,23 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
*/
@Override
public
void
onSubmitDamagePhotoSuccess
(
Long
result
)
{
setRescueBusy
(
false
);
//result 返回碰撞id
//关闭加载提示对话框
closeDialog
(
0
);
// Delete only files created by this flow, after a confirmed successful submission.
for
(
File
file
:
createdMediaFiles
)
file
.
delete
();
createdMediaFiles
.
clear
();
//置空已选择文件列表,待上传文件列表,已上传文件列表
mSelectedFileList
.
clear
();
mAccidentUploadFileDetailList
.
clear
();
uploadedMediaByPath
.
clear
();
mAccidentRecordPhotoList
.
clear
();
//待上传文件列表添加默认图
mAccidentRecordPhotoList
.
add
(
getDefaultDetailPhotoBean
());
damagePhotoAdapter1
.
notifyDataSetChanged
();
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
send_request_succeed
),
TYPE_MESSAGE_DIALOG
,
false
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
BuildConfig
.
DEBUG
?
"调试模拟提交,未发送救援请求"
:
getResources
().
getString
(
R
.
string
.
send_request_succeed
),
TYPE_MESSAGE_DIALOG
,
false
);
// EventBus.getDefault().post(result);
}
...
...
@@ -1093,6 +1155,7 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
*/
@Override
public
void
onSubmitDamagePhotoFailure
(
int
errorCode
,
String
errorMsg
)
{
setRescueBusy
(
false
);
// LoadingDialog.getInstance().closeLoadingDialog();
closeDialog
(
0
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
send_request_failed
),
TYPE_MESSAGE_DIALOG
,
false
);
...
...
@@ -1104,65 +1167,48 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
* 打开图库
*/
private
void
fromGallery
()
{
//调用Matisse图片文件选择框架
toPickFilePage
();
Intent
pick
=
new
Intent
(
Intent
.
ACTION_OPEN_DOCUMENT
);
pick
.
addCategory
(
Intent
.
CATEGORY_OPENABLE
);
pick
.
setType
(
"*/*"
);
pick
.
putExtra
(
Intent
.
EXTRA_MIME_TYPES
,
new
String
[]{
"image/*"
,
"video/*"
});
pick
.
putExtra
(
Intent
.
EXTRA_ALLOW_MULTIPLE
,
true
);
pick
.
addFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
startActivityForResult
(
pick
,
FROM_GALLERY
);
}
/**
* Matisse图片选择框架
*/
private
void
toPickFilePage
()
{
//也可以选择链式调用写法
EasyPhotos
.
createAlbum
(
PhotoDamageFragment
.
this
,
false
,
false
,
GlideEngine
.
getInstance
())
.
setVideo
(
true
)
//是否显示视频文件
.
setVideoMaxSecond
(
30
)
//视频文件时长限制
.
setPuzzleMenu
(
false
)
//设置菜单显示
.
setCleanMenu
(
false
)
.
start
(
REQUEST_CODE_CHOOSE
);
//onActivityResoult获取选择文件参数
}
/**
* 调起系统相机拍照
*/
private
void
fromCamera
()
{
try
{
// 获取文件
File
file
=
null
;
String
sdcardState
=
Environment
.
getExternalStorageState
();
String
sdcardPathDir
=
CommonConst
.
SDCARD_DAMAGE_PHOTOS_PATH
;
if
(
Environment
.
MEDIA_MOUNTED
.
equals
(
sdcardState
))
{
// 有sd卡,是否有myImage文件夹
File
fileDir
=
new
File
(
sdcardPathDir
);
if
(!
fileDir
.
exists
())
{
fileDir
.
mkdirs
();
}
// 是否有headImg文件
file
=
new
File
(
CommonConst
.
SDCARD_DAMAGE_PHOTOS_PATH
+
"damage"
+
gvDamageIndex
+
".JPEG"
);
chosePhotoIconPath
=
file
.
getPath
();
}
Intent
openCameraIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
File
base
=
mContext
.
getExternalFilesDir
(
Environment
.
DIRECTORY_PICTURES
);
if
(
base
==
null
)
base
=
mContext
.
getFilesDir
();
File
directory
=
new
File
(
base
,
"damage"
);
if
(!
directory
.
exists
()
&&
!
directory
.
mkdirs
())
throw
new
IOException
(
"Cannot create private photo directory"
);
File
file
=
File
.
createTempFile
(
"damage_"
,
".jpg"
,
directory
);
chosePhotoIconPath
=
file
.
getAbsolutePath
();
createdMediaFiles
.
add
(
file
);
chosePhotoIconUri
=
FileProvider
.
getUriForFile
(
mContext
,
CommonConst
.
AICAR_PROVIDER_AUTHORITY
,
file
);
Intent
camera
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
camera
.
putExtra
(
MediaStore
.
EXTRA_OUTPUT
,
chosePhotoIconUri
);
camera
.
setClipData
(
ClipData
.
newUri
(
mContext
.
getContentResolver
(),
"collision photo"
,
chosePhotoIconUri
));
camera
.
addFlags
(
Intent
.
FLAG_GRANT_WRITE_URI_PERMISSION
|
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
startActivityForResult
(
camera
,
FROM_CAMERA
);
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"Could not open camera"
,
e
);
ToastUtil
.
show
(
"无法打开相机,请使用文件选择器"
);
}
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
/**
* 7.0 调用系统相机拍照不再允许使用Uri方式,应该替换为FileProvider
* 并且这样可以解决MIUI系统上拍照返回size为0的情况
*/
chosePhotoIconUri
=
FileProvider
.
getUriForFile
(
getActivity
(),
CommonConst
.
AICAR_PROVIDER_AUTHORITY
,
file
);
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
if
(
requestCode
==
REQUEST_CAMERA_PERMISSION
)
{
if
(
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
fromCamera
(
);
}
else
{
if
(
file
!=
null
)
{
chosePhotoIconPath
=
file
.
getPath
();
chosePhotoIconUri
=
Uri
.
fromFile
(
file
);
}
ToastUtil
.
show
(
"相机权限未开启,仍可从文件选择器添加照片"
);
}
openCameraIntent
.
putExtra
(
MediaStore
.
EXTRA_OUTPUT
,
chosePhotoIconUri
);
//openCameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult
(
openCameraIntent
,
FROM_CAMERA
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -1212,33 +1258,16 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
* @param recordDetailPhotoList
*/
private
void
updateFileListUrl
(
List
<
AccidentRecordDetailPhoto
>
recordDetailPhotoList
)
{
LogUtils
.
d
(
TAG
,
"updateFileListUrl recordDetailPhotoList is "
+
recordDetailPhotoList
+
",size = "
+
mAccidentRecordPhotoList
.
size
());
// mAccidentRecordPhotoList.clear();
if
(
recordDetailPhotoList
.
size
()
>
0
&&
mAccidentRecordPhotoList
!=
null
)
{
int
mListSize
=
mAccidentRecordPhotoList
.
size
();
mAccidentRecordPhotoList
.
remove
(
mListSize
-
1
);
LogUtils
.
d
(
TAG
,
"updateFileListUrl mAccidentRecordPhotoList size is "
+
mAccidentRecordPhotoList
.
size
());
int
total_select_file_count
=
mAccidentRecordPhotoList
.
size
()
+
recordDetailPhotoList
.
size
();
if
(
total_select_file_count
>
3
)
{
ToastUtil
.
show
(
"已超过上传文件限制,无法继续上传"
);
return
;
}
//遍历选择的文件列表,将文件属性填充到实体,然后添加到list中
for
(
int
i
=
0
;
i
<
recordDetailPhotoList
.
size
();
i
++)
{
AccidentRecordDetailPhoto
accidentRecordDetailPhoto
=
new
AccidentRecordDetailPhoto
();
String
filePath
=
getFilePathByUri
(
mContext
,
recordDetailPhotoList
.
get
(
i
).
getFileUri
());
// String filePath = recordDetailPhotoList.get(i).getFilePath();
LogUtils
.
d
(
TAG
,
"FilePath = "
+
filePath
);
accidentRecordDetailPhoto
.
setFilePath
(
filePath
);
accidentRecordDetailPhoto
.
setFileType
(
getFileType
(
filePath
));
accidentRecordDetailPhoto
.
setFileUri
(
recordDetailPhotoList
.
get
(
i
).
getFileUri
());
accidentRecordDetailPhoto
.
setShowLocation
(
""
);
mAccidentRecordPhotoList
.
add
(
accidentRecordDetailPhoto
);
}
//默认文件添加完后,添加一个空的添加图标实体
mAccidentRecordPhotoList
.
add
(
getDefaultDetailPhotoBean
());
damagePhotoAdapter1
.
notifyDataSetChanged
();
if
(
recordDetailPhotoList
==
null
||
recordDetailPhotoList
.
isEmpty
())
return
;
int
existing
=
mAccidentRecordPhotoList
.
size
()
-
1
;
// trailing add tile
if
(
existing
+
recordDetailPhotoList
.
size
()
>
3
)
{
ToastUtil
.
show
(
"最多选择3个文件"
);
return
;
}
mAccidentRecordPhotoList
.
remove
(
mAccidentRecordPhotoList
.
size
()
-
1
);
mAccidentRecordPhotoList
.
addAll
(
recordDetailPhotoList
);
mAccidentRecordPhotoList
.
add
(
getDefaultDetailPhotoBean
());
damagePhotoAdapter1
.
notifyDataSetChanged
();
}
/**
...
...
@@ -1248,12 +1277,17 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
//待上传文件的第一个文件,通过文件路径新建mFileInfo对象
String
filePath
=
accidentRecordDetailPhoto
.
getFilePath
();
FileInfo
FileInfo
=
new
FileInfo
();
if
(
filePath
==
null
)
{
filePath
=
getFilePathByUri
(
mContext
,
accidentRecordDetailPhoto
.
getFileUri
());
if
(
TextUtils
.
isEmpty
(
filePath
))
{
setRescueBusy
(
false
);
closeDialog
(
0
);
ToastUtil
.
show
(
"无法读取所选文件"
);
return
;
}
File
mFile
=
new
File
(
filePath
);
if
(!
mFile
.
exists
()
||
mFile
.
isDirectory
())
{
LogUtils
.
d
(
"getALiYunUpLoadFileToken filePath is not exists"
);
setRescueBusy
(
false
);
closeDialog
(
0
);
ToastUtil
.
show
(
"附件不存在,请删除后重新选择"
);
return
;
}
String
fileType
=
getFileType
(
filePath
);
...
...
@@ -1262,28 +1296,33 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
FileInfo
.
setFileType
(
fileType
);
FileInfo
.
setFileUri
(
accidentRecordDetailPhoto
.
getFileUri
());
mUpLoadingFileInfo
=
FileInfo
;
final
FileInfo
requestedFile
=
FileInfo
;
final
long
attempt
=
uploadAttemptGate
.
begin
();
UploadMediaFileToALiYunManager
.
getInstance
().
getALiYunFileUploadTokenAndAddress
(
FileInfo
,
new
ALiYunUpLoadFileTokenCallBack
()
{
@Override
public
void
onGetALiYunUploadFileTokenSuccess
(
String
uploadAuth
,
String
uploadAddress
,
String
videoId
,
String
imageUrl
)
{
mUpLoadingFileInfo
.
setVideoId
(
videoId
);
mUpLoadingFileInfo
.
setUploadAddress
(
uploadAddress
);
mUpLoadingFileInfo
.
setUploadAuth
(
uploadAuth
);
mUpLoadingFileInfo
.
setImageUrl
(
imageUrl
);
if
(
PermissionUtils
.
isGranted
(
WRITE_EXTERNAL_STORAGE
))
{
UploadMediaFileToALiYunManager
.
getInstance
().
uploadFile
(
mUpLoadingFileInfo
);
}
else
{
PermissionUtils
.
permission
(
WRITE_EXTERNAL_STORAGE
).
request
();
ToastUtil
.
show
(
"无文件操作权限"
);
}
LogUtils
.
d
(
TAG
,
"onGetALiYunUploadFileTokenSuccess "
);
rescueLocationHandler
.
post
(()
->
{
if
(!
isAdded
()
||
!
rescueBusy
||
!
uploadAttemptGate
.
accepts
(
attempt
)
||
mUpLoadingFileInfo
!=
requestedFile
)
return
;
requestedFile
.
setVideoId
(
videoId
);
requestedFile
.
setUploadAddress
(
uploadAddress
);
requestedFile
.
setUploadAuth
(
uploadAuth
);
requestedFile
.
setImageUrl
(
imageUrl
);
initALiYunUpLoad
(
requestedFile
,
attempt
);
UploadMediaFileToALiYunManager
.
getInstance
().
uploadFile
(
requestedFile
);
});
}
@Override
public
void
onGetALiYunUploadFileTokenFailed
(
int
code
,
String
errorMessage
)
{
closeDialog
(
0
);
LogUtils
.
d
(
TAG
,
"getALiYunFileUploadTokenAndAddress failed"
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
file_upload_failed
),
TYPE_FAILED_DIALOG
,
false
);
rescueLocationHandler
.
post
(()
->
{
if
(!
isAdded
()
||
!
rescueBusy
||
!
uploadAttemptGate
.
accepts
(
attempt
)
||
mUpLoadingFileInfo
!=
requestedFile
)
return
;
setRescueBusy
(
false
);
closeDialog
(
0
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
file_upload_failed
),
TYPE_FAILED_DIALOG
,
false
);
});
}
},
this
);
...
...
@@ -1320,205 +1359,164 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
LogUtils
.
d
(
TAG
,
"onActivityResult() requestCode="
+
requestCode
+
",resultCode="
+
resultCode
+
",data="
+
data
+
",chosePhotoIconPath="
+
chosePhotoIconPath
+
",chosePhotoIconUri="
+
chosePhotoIconUri
);
if
(
requestCode
==
FROM_CAMERA
&&
resultCode
==
Activity
.
RESULT_OK
)
{
//onActivityResult() requestCode=8192,resultCode=-1,data=null
File
tempfile
=
new
File
(
chosePhotoIconPath
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
chosePhotoIconUri
=
FileProvider
.
getUriForFile
(
getActivity
(),
CommonConst
.
AICAR_PROVIDER_AUTHORITY
,
tempfile
);
if
(
resultCode
!=
Activity
.
RESULT_OK
)
{
if
(
requestCode
==
FROM_CAMERA
&&
!
TextUtils
.
isEmpty
(
chosePhotoIconPath
))
{
File
canceled
=
new
File
(
chosePhotoIconPath
);
createdMediaFiles
.
remove
(
canceled
);
canceled
.
delete
();
}
return
;
}
mSelectedFileList
.
clear
();
if
(
requestCode
==
FROM_CAMERA
)
{
File
photo
=
TextUtils
.
isEmpty
(
chosePhotoIconPath
)
?
null
:
new
File
(
chosePhotoIconPath
);
if
(
photo
!=
null
&&
photo
.
isFile
()
&&
photo
.
length
()
>
0
)
{
AccidentRecordDetailPhoto
selected
=
new
AccidentRecordDetailPhoto
();
selected
.
setFilePath
(
photo
.
getAbsolutePath
());
selected
.
setFileType
(
"jpg"
);
selected
.
setFileUri
(
chosePhotoIconUri
);
mSelectedFileList
.
add
(
selected
);
}
else
{
chosePhotoIconUri
=
Uri
.
fromFile
(
tempfile
);
if
(
photo
!=
null
)
{
createdMediaFiles
.
remove
(
photo
);
photo
.
delete
();
}
ToastUtil
.
show
(
"拍照失败,请重试"
);
}
LogUtils
.
d
(
TAG
,
" into requestCode=8192,chosePhotoIconPath="
+
chosePhotoIconPath
+
",chosePhotoIconUri="
+
chosePhotoIconUri
);
// startCropPicture(chosePhotoIconUri);
//将拍照所得的照片uri添加到已选择文件list
if
(
mSelectedFileList
!=
null
)
{
mSelectedFileList
.
clear
();
for
(
int
i
=
0
;
i
<
mSelectedFileList
.
size
();
i
++)
{
mSelectedFileList
.
remove
(
i
);
}
AccidentRecordDetailPhoto
recordDetailPhoto
=
new
AccidentRecordDetailPhoto
();
recordDetailPhoto
.
setFileUri
(
chosePhotoIconUri
);
mSelectedFileList
.
add
(
recordDetailPhoto
);
}
else
if
(
requestCode
==
FROM_GALLERY
&&
data
!=
null
)
{
ArrayList
<
Uri
>
uris
=
new
ArrayList
<>();
if
(
data
.
getClipData
()
!=
null
)
{
for
(
int
i
=
0
;
i
<
data
.
getClipData
().
getItemCount
();
i
++)
uris
.
add
(
data
.
getClipData
().
getItemAt
(
i
).
getUri
());
}
else
if
(
data
.
getData
()
!=
null
)
{
uris
.
add
(
data
.
getData
());
}
//更新已选择文件展示列表
updateChosePhoto
();
}
else
if
(
requestCode
==
REQUEST_CODE_CHOOSE
&&
RESULT_OK
==
resultCode
)
{
//返回对象集合:如果你需要了解图片的宽、高、大小、用户是否选中原图选项等信息,可以用这个
ArrayList
<
Photo
>
resultPhotos
=
data
.
getParcelableArrayListExtra
(
EasyPhotos
.
RESULT_PHOTOS
);
//返回图片地址集合时如果你需要知道用户选择图片时是否选择了原图选项,用如下方法获取
boolean
selectedOriginal
=
data
.
getBooleanExtra
(
EasyPhotos
.
RESULT_SELECTED_ORIGINAL
,
false
);
if
(
resultPhotos
!=
null
&&
resultPhotos
.
size
()
>
0
)
{
mSelectedFileList
.
clear
();
for
(
Photo
photo
:
resultPhotos
)
{
AccidentRecordDetailPhoto
recordDetailPhoto
=
new
AccidentRecordDetailPhoto
();
recordDetailPhoto
.
setFilePath
(
photo
.
path
);
recordDetailPhoto
.
setFileUri
(
photo
.
uri
);
mSelectedFileList
.
add
(
recordDetailPhoto
);
}
int
available
=
3
-
(
mAccidentRecordPhotoList
.
size
()
-
1
);
if
(
uris
.
size
()
>
available
)
{
ToastUtil
.
show
(
"最多选择3个文件"
);
return
;
}
updateChosePhoto
();
if
(
uris
.
isEmpty
())
return
;
mediaCopyInProgress
=
true
;
btn_send_damage
.
setEnabled
(
false
);
ToastUtil
.
show
(
"正在读取所选文件"
);
final
Context
appContext
=
mContext
.
getApplicationContext
();
final
View
requestingView
=
view
;
new
Thread
(()
->
{
ArrayList
<
AccidentRecordDetailPhoto
>
copied
=
new
ArrayList
<>();
int
failed
=
0
;
for
(
Uri
uri
:
uris
)
{
AccidentRecordDetailPhoto
selected
=
copyPickedMedia
(
appContext
,
uri
);
if
(
selected
==
null
)
failed
++;
else
copied
.
add
(
selected
);
}
final
int
failedCount
=
failed
;
rescueLocationHandler
.
post
(()
->
{
mediaCopyInProgress
=
false
;
if
(!
isAdded
()
||
getView
()
!=
requestingView
)
{
for
(
AccidentRecordDetailPhoto
media
:
copied
)
new
File
(
media
.
getFilePath
()).
delete
();
return
;
}
btn_send_damage
.
setEnabled
(!
rescueBusy
);
mSelectedFileList
.
clear
();
mSelectedFileList
.
addAll
(
copied
);
for
(
AccidentRecordDetailPhoto
media
:
copied
)
createdMediaFiles
.
add
(
new
File
(
media
.
getFilePath
()));
updateChosePhoto
();
if
(
failedCount
>
0
)
ToastUtil
.
show
(
"部分文件无法读取、格式不支持或视频超过30秒"
);
});
},
"damage-media-copy"
).
start
();
return
;
}
updateChosePhoto
();
}
private
void
discardPrivateMedia
(
AccidentRecordDetailPhoto
media
)
{
if
(
media
==
null
||
TextUtils
.
isEmpty
(
media
.
getFilePath
()))
return
;
File
file
=
new
File
(
media
.
getFilePath
());
if
(
createdMediaFiles
.
remove
(
file
))
file
.
delete
();
}
/**
* 通过uri获取真实的文件地址
*
* @param context
* @param uri
* @return
*/
public
static
String
getRealFilePath
(
final
Context
context
,
final
Uri
uri
)
{
if
(
null
==
uri
)
{
private
static
AccidentRecordDetailPhoto
copyPickedMedia
(
Context
context
,
Uri
uri
)
{
if
(
uri
==
null
)
return
null
;
String
mime
;
try
{
mime
=
context
.
getContentResolver
().
getType
(
uri
);
}
catch
(
RuntimeException
e
)
{
return
null
;
}
final
String
scheme
=
uri
.
getScheme
();
String
data
=
null
;
if
(
scheme
==
null
)
{
data
=
uri
.
getPath
();
}
else
if
(
ContentResolver
.
SCHEME_FILE
.
equals
(
scheme
))
{
data
=
uri
.
getPath
();
}
else
if
(
ContentResolver
.
SCHEME_CONTENT
.
equals
(
scheme
))
{
Cursor
cursor
=
context
.
getContentResolver
().
query
(
uri
,
new
String
[]{
MediaStore
.
Images
.
ImageColumns
.
DATA
},
null
,
null
,
null
);
if
(
null
!=
cursor
)
{
if
(
cursor
.
moveToFirst
())
{
int
index
=
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
ImageColumns
.
DATA
);
if
(
index
>
-
1
)
{
data
=
cursor
.
getString
(
index
);
}
}
cursor
.
close
();
}
boolean
video
=
mime
!=
null
&&
mime
.
startsWith
(
"video/"
);
if
(
mime
==
null
||
(!
video
&&
!
mime
.
startsWith
(
"image/"
)))
{
return
null
;
}
return
data
;
}
/**
* 通过文件Uri获取文件的真实路径
*
* @param context
* @param uri
* @return
*/
public
String
getFilePathByUri
(
Context
context
,
Uri
uri
)
{
String
path
=
null
;
// 以 file:// 开头的
LogUtils
.
d
(
"PhotoDamageFrament"
,
"Uri Authority = "
+
uri
.
getAuthority
()
+
",Scheme = "
+
uri
.
getScheme
());
if
(
ContentResolver
.
SCHEME_FILE
.
equals
(
uri
.
getScheme
()))
{
path
=
uri
.
getPath
();
return
path
;
String
suffix
=
MimeTypeMap
.
getSingleton
().
getExtensionFromMimeType
(
mime
);
if
(
"image/jpeg"
.
equalsIgnoreCase
(
mime
))
suffix
=
"jpg"
;
else
if
(
"image/png"
.
equalsIgnoreCase
(
mime
))
suffix
=
"png"
;
else
if
(
"image/gif"
.
equalsIgnoreCase
(
mime
))
suffix
=
"gif"
;
else
if
(
"image/heic"
.
equalsIgnoreCase
(
mime
)
||
"image/heif"
.
equalsIgnoreCase
(
mime
))
suffix
=
"heic"
;
else
if
(
"image/webp"
.
equalsIgnoreCase
(
mime
))
suffix
=
"webp"
;
if
(
TextUtils
.
isEmpty
(
suffix
)
||
!(
video
?
RescueMediaType
.
isVideoExtension
(
suffix
)
:
RescueMediaType
.
isImageExtension
(
suffix
)))
{
return
null
;
}
// 以 content:// 开头的,比如 content://media/extenral/images/media/17766
if
(
ContentResolver
.
SCHEME_CONTENT
.
equals
(
uri
.
getScheme
())
&&
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
KITKAT
)
{
Cursor
cursor
=
context
.
getContentResolver
().
query
(
uri
,
new
String
[]{
MediaStore
.
Images
.
Media
.
DATA
},
null
,
null
,
null
);
LogUtils
.
d
(
"PhotoDamageFrament"
,
"SCHEME_CONTENT <KITKAT"
);
if
(
cursor
!=
null
)
{
if
(
cursor
.
moveToFirst
())
{
int
columnIndex
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
if
(
columnIndex
>
-
1
)
{
path
=
cursor
.
getString
(
columnIndex
);
}
}
cursor
.
close
();
File
target
=
null
;
try
{
File
directory
=
new
File
(
context
.
getCacheDir
(),
"damage_upload"
);
if
(!
directory
.
exists
()
&&
!
directory
.
mkdirs
())
throw
new
IOException
(
"Cannot create media cache"
);
target
=
File
.
createTempFile
(
"selected_"
,
"."
+
suffix
,
directory
);
try
(
InputStream
input
=
context
.
getContentResolver
().
openInputStream
(
uri
);
FileOutputStream
output
=
new
FileOutputStream
(
target
))
{
if
(
input
==
null
)
throw
new
IOException
(
"Cannot open selected media"
);
byte
[]
buffer
=
new
byte
[
8192
];
int
count
;
while
((
count
=
input
.
read
(
buffer
))
!=
-
1
)
output
.
write
(
buffer
,
0
,
count
);
}
return
path
;
}
else
if
(
ContentResolver
.
SCHEME_CONTENT
.
equals
(
uri
.
getScheme
())
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
// 4.4及之后的 是以 content:// 开头的,比如 content://com.android.providers.media.documents/document/image%3A235700
LogUtils
.
d
(
"PhotoDamageFrament"
,
"SCHEME_CONTENT >KITKAT"
);
if
(
DocumentsContract
.
isDocumentUri
(
context
,
uri
))
{
if
(
isExternalStorageDocument
(
uri
))
{
// ExternalStorageProvider
final
String
docId
=
DocumentsContract
.
getDocumentId
(
uri
);
final
String
[]
split
=
docId
.
split
(
":"
);
final
String
type
=
split
[
0
];
if
(
"primary"
.
equalsIgnoreCase
(
type
))
{
path
=
Environment
.
getExternalStorageDirectory
()
+
"/"
+
split
[
1
];
return
path
;
}
}
else
if
(
isDownloadsDocument
(
uri
))
{
// DownloadsProvider
final
String
id
=
DocumentsContract
.
getDocumentId
(
uri
);
final
Uri
contentUri
=
ContentUris
.
withAppendedId
(
Uri
.
parse
(
"content://downloads/public_downloads"
),
Long
.
parseLong
(
id
));
path
=
getDataColumn
(
context
,
contentUri
,
null
,
null
);
return
path
;
}
else
if
(
isMediaDocument
(
uri
))
{
// MediaProvider
final
String
docId
=
DocumentsContract
.
getDocumentId
(
uri
);
final
String
[]
split
=
docId
.
split
(
":"
);
final
String
type
=
split
[
0
];
Uri
contentUri
=
null
;
if
(
"image"
.
equals
(
type
))
{
contentUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
;
}
else
if
(
"video"
.
equals
(
type
))
{
contentUri
=
MediaStore
.
Video
.
Media
.
EXTERNAL_CONTENT_URI
;
}
else
if
(
"audio"
.
equals
(
type
))
{
contentUri
=
MediaStore
.
Audio
.
Media
.
EXTERNAL_CONTENT_URI
;
}
final
String
selection
=
"_id=?"
;
final
String
[]
selectionArgs
=
new
String
[]{
split
[
1
]};
path
=
getDataColumn
(
context
,
contentUri
,
selection
,
selectionArgs
);
return
path
;
}
}
else
{
if
(
"com.glsx.aicar.provider"
.
equals
(
uri
.
getAuthority
()))
{
path
=
chosePhotoIconPath
;
}
else
{
path
=
getRealFilePath
(
context
,
uri
);
}
LogUtils
.
d
(
"PhotoDamageFrament"
,
"get filepath = "
+
path
);
return
path
;
if
(
target
.
length
()
==
0
)
throw
new
IOException
(
"Empty selected media"
);
if
(
video
&&
!
videoDurationWithin30Seconds
(
target
))
{
target
.
delete
();
return
null
;
}
AccidentRecordDetailPhoto
selected
=
new
AccidentRecordDetailPhoto
();
selected
.
setFilePath
(
target
.
getAbsolutePath
());
selected
.
setFileType
(
suffix
);
selected
.
setFileUri
(
Uri
.
fromFile
(
target
));
return
selected
;
}
catch
(
Exception
e
)
{
if
(
target
!=
null
)
target
.
delete
();
LogUtils
.
e
(
"PhotoDamageFragment"
,
"Cannot copy selected media"
,
e
);
return
null
;
}
return
null
;
}
private
static
String
getDataColumn
(
Context
context
,
Uri
uri
,
String
selection
,
String
[]
selectionArgs
)
{
Cursor
cursor
=
null
;
final
String
column
=
"_data"
;
final
String
[]
projection
=
{
column
};
private
static
boolean
videoDurationWithin30Seconds
(
File
file
)
{
MediaMetadataRetriever
retriever
=
new
MediaMetadataRetriever
();
try
{
cursor
=
context
.
getContentResolver
().
query
(
uri
,
projection
,
selection
,
selectionArgs
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
final
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
column
)
;
return
cursor
.
getString
(
column_index
);
}
retriever
.
setDataSource
(
file
.
getAbsolutePath
()
);
String
value
=
retriever
.
extractMetadata
(
MediaMetadataRetriever
.
METADATA_KEY_DURATION
);
return
value
!=
null
&&
Long
.
parseLong
(
value
)
<=
30000
;
}
catch
(
Exception
e
)
{
return
false
;
}
finally
{
if
(
cursor
!=
null
)
{
cursor
.
close
();
}
retriever
.
release
();
}
return
null
;
}
private
static
boolean
isExternalStorageDocument
(
Uri
uri
)
{
return
"com.android.externalstorage.documents"
.
equals
(
uri
.
getAuthority
());
}
private
static
boolean
isDownloadsDocument
(
Uri
uri
)
{
return
"com.android.providers.downloads.documents"
.
equals
(
uri
.
getAuthority
());
}
private
static
boolean
isMediaDocument
(
Uri
uri
)
{
return
"com.android.providers.media.documents"
.
equals
(
uri
.
getAuthority
()
);
@Override
public
void
onDestroy
()
{
// A destroyed rescue flow has been abandoned; selected source files remain untouched.
for
(
File
file
:
createdMediaFiles
)
file
.
delete
();
createdMediaFiles
.
clear
();
super
.
onDestroy
(
);
}
@Override
public
void
onDestroyView
()
{
invalidateUploadAttempt
();
super
.
onDestroyView
();
mMapView
.
getMap
().
clear
();
// mMapView.onDestroy(); //这会导致ANR
mMapView
=
null
;
stopRescueLocation
();
if
(
mMapView
!=
null
)
{
mMapView
.
getMap
().
clear
();
// The existing release flow leaves onDestroy disabled because it caused an ANR.
mMapView
=
null
;
}
map
=
null
;
}
private
FileInfo
getUploadFileInfo
(
String
videoFilePath
)
{
...
...
@@ -1637,42 +1635,57 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
/**
* 初始化阿里云上传SDK及回调
*/
private
void
initALiYunUpLoad
()
{
//阿里云文件上传回调
private
boolean
matchesActiveUpload
(
long
attempt
,
FileInfo
requestedFile
,
UploadFileInfo
callbackFile
)
{
if
(
callbackFile
==
null
||
!
rescueBusy
||
mUpLoadingFileInfo
!=
requestedFile
||
!
uploadAttemptGate
.
accepts
(
attempt
,
requestedFile
.
getFilePath
(),
callbackFile
.
getFilePath
()))
{
return
false
;
}
int
expectedType
=
RescueMediaType
.
isVideoExtension
(
requestedFile
.
getFileType
())
?
UPLOAD_FILE_TYPE_VIDEO
:
UPLOAD_FILE_TYPE_IMAGE
;
return
callbackFile
.
getFileType
()
==
expectedType
;
}
private
void
initALiYunUpLoad
(
final
FileInfo
requestedFile
,
final
long
attempt
)
{
// A callback is bound to one VOD client and one token response. Recreating the client
// between attempts keeps even a late callback for the same file path distinguishable.
final
AtomicReference
<
VODUploadClient
>
clientForAttempt
=
new
AtomicReference
<>();
VODUploadCallback
callback
=
new
VODUploadCallback
()
{
@Override
public
void
onUploadSucceed
(
UploadFileInfo
info
,
VodUploadResult
result
)
{
// super.onUploadSucceed(info, result);
LogUtils
.
d
(
TAG
,
"ALiYun uploadFile Succeed ,UploadFileInfo filePath = "
+
info
.
getFilePath
()
+
",fileType = "
+
info
.
getFileType
());
//上传成功后,将已上传的文件添加至已上传文件列表mAccidentUploadFileDetail
AccidentUploadFileDetail
accidentUploadFileDetail
=
new
AccidentUploadFileDetail
();
if
(
info
.
getFileType
()
==
UPLOAD_FILE_TYPE_IMAGE
)
{
accidentUploadFileDetail
.
setFileType
(
"image"
);
accidentUploadFileDetail
.
setImageUrl
(
mUpLoadingFileInfo
.
getImageUrl
());
mAccidentUploadFileDetailList
.
add
(
accidentUploadFileDetail
);
}
else
if
(
info
.
getFileType
()
==
UPLOAD_FILE_TYPE_VIDEO
)
{
accidentUploadFileDetail
.
setFileType
(
"video"
);
accidentUploadFileDetail
.
setVideoId
(
mUpLoadingFileInfo
.
getVideoId
());
mAccidentUploadFileDetailList
.
add
(
accidentUploadFileDetail
);
}
LogUtils
.
d
(
TAG
,
"mAccidentRecordPhotoList size = "
+
mAccidentRecordPhotoList
.
size
());
//待上传文件列表移除第一个数据
mAccidentRecordPhotoList
.
remove
(
0
);
//如果待上传文件列表内的文件数量大于1(包含默认的添加图占位文件),则继续执行上传;否则直接开始发送请求
if
(
mAccidentRecordPhotoList
.
size
()
>
1
)
{
rescueLocationHandler
.
post
(()
->
{
if
(!
isAdded
()
||
!
matchesActiveUpload
(
attempt
,
requestedFile
,
info
))
return
;
AccidentUploadFileDetail
uploaded
=
new
AccidentUploadFileDetail
();
if
(
info
.
getFileType
()
==
UPLOAD_FILE_TYPE_IMAGE
&&
!
TextUtils
.
isEmpty
(
requestedFile
.
getImageUrl
()))
{
uploaded
.
setFileType
(
"image"
);
uploaded
.
setImageUrl
(
requestedFile
.
getImageUrl
());
}
else
if
(
info
.
getFileType
()
==
UPLOAD_FILE_TYPE_VIDEO
&&
!
TextUtils
.
isEmpty
(
requestedFile
.
getVideoId
()))
{
uploaded
.
setFileType
(
"video"
);
uploaded
.
setVideoId
(
requestedFile
.
getVideoId
());
}
else
{
setRescueBusy
(
false
);
closeDialog
(
0
);
ToastUtil
.
show
(
"附件上传信息无效,请重新选择"
);
return
;
}
// Mark this attempt finished before starting another upload or submission.
invalidateUploadAttempt
();
uploadedMediaByPath
.
put
(
requestedFile
.
getFilePath
(),
uploaded
);
startUpLoadMediaFileList
();
}
else
{
myHandler
.
sendEmptyMessage
(
UPDATE_GRIDVIDE
);
sendDamageEventToServer
();
}
});
}
@Override
public
void
onUploadFailed
(
UploadFileInfo
info
,
String
code
,
String
message
)
{
// super.onUploadFailed(info, code, message);
LogUtils
.
d
(
TAG
,
"ALiYun uploadFile failed"
+
",code = "
+
code
+
",message = "
+
message
);
closeDialog
(
0
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
file_upload_failed
),
TYPE_MESSAGE_DIALOG
,
false
);
LogUtils
.
d
(
TAG
,
"ALiYun uploadFile failed, code="
+
code
+
",message="
+
message
);
rescueLocationHandler
.
post
(()
->
{
if
(!
isAdded
()
||
!
matchesActiveUpload
(
attempt
,
requestedFile
,
info
))
return
;
setRescueBusy
(
false
);
closeDialog
(
0
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
file_upload_failed
),
TYPE_MESSAGE_DIALOG
,
false
);
});
}
@Override
...
...
@@ -1682,11 +1695,15 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
@Override
public
void
onUploadTokenExpired
()
{
super
.
onUploadTokenExpired
();
//上传凭证失效时不进行刷新并自动上传,直接提示上传失败
LogUtils
.
d
(
TAG
,
"UploadToken is invalid!"
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
file_upload_failed
),
TYPE_MESSAGE_DIALOG
,
false
);
// startUpLoadMediaFileList(); //上传凭证过期后重新获取凭证并上传
rescueLocationHandler
.
post
(()
->
{
if
(!
isAdded
()
||
!
rescueBusy
||
mUpLoadingFileInfo
!=
requestedFile
||
!
uploadAttemptGate
.
accepts
(
attempt
))
return
;
LogUtils
.
d
(
TAG
,
"UploadToken is invalid!"
);
setRescueBusy
(
false
);
closeDialog
(
0
);
showDialog
(
getResources
().
getString
(
R
.
string
.
tips
),
getResources
().
getString
(
R
.
string
.
file_upload_failed
),
TYPE_MESSAGE_DIALOG
,
false
);
});
}
@Override
...
...
@@ -1701,21 +1718,17 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
}
@Override
public
void
onUploadStarted
(
UploadFileInfo
uploadFileInfo
)
{
// super.onUploadStarted(uploadFileInfo);
UploadClient
=
UploadMediaFileToALiYunManager
.
getInstance
().
getUploadClient
();
mUpLoadingFileInfo
=
UploadMediaFileToALiYunManager
.
getInstance
().
getUploadingFile
();
//上传开启后,此处进行上传凭证和上传地址的设置
if
(
UploadClient
!=
null
&&
mUpLoadingFileInfo
!=
null
)
{
LogUtils
.
d
(
TAG
,
"uploadfile callback onUploadStarted ,uploadFileInfo = "
+
uploadFileInfo
.
toString
());
UploadClient
.
setUploadAuthAndAddress
(
uploadFileInfo
,
mUpLoadingFileInfo
.
getUploadAuth
(),
mUpLoadingFileInfo
.
getUploadAddress
());
}
else
{
LogUtils
.
d
(
TAG
,
"onUpLoadStarted uploadclient = "
+
UploadClient
+
",mFileInfo = "
+
mUpLoadingFileInfo
);
public
void
onUploadStarted
(
UploadFileInfo
info
)
{
if
(!
matchesActiveUpload
(
attempt
,
requestedFile
,
info
))
return
;
VODUploadClient
client
=
clientForAttempt
.
get
();
if
(
client
!=
null
)
{
client
.
setUploadAuthAndAddress
(
info
,
requestedFile
.
getUploadAuth
(),
requestedFile
.
getUploadAddress
());
}
}
};
//初始化阿里云上传服务
UploadMediaFileToALiYunManager
.
getInstance
().
init
(
getActivity
().
getApplicationContext
(),
callback
);
clientForAttempt
.
set
(
UploadMediaFileToALiYunManager
.
getInstance
().
getUploadClient
());
}
private
void
updaDamageAdapter
()
{
...
...
@@ -1724,4 +1737,23 @@ public class PhotoDamageFragment extends BaseFragment implements View.OnClickLis
}
}
static
final
class
UploadAttemptGate
{
private
volatile
long
currentAttempt
;
long
begin
()
{
return
++
currentAttempt
;
}
void
invalidate
()
{
++
currentAttempt
;
}
boolean
accepts
(
long
attempt
)
{
return
attempt
==
currentAttempt
;
}
boolean
accepts
(
long
attempt
,
String
expectedPath
,
String
callbackPath
)
{
return
accepts
(
attempt
)
&&
expectedPath
!=
null
&&
expectedPath
.
equals
(
callbackPath
);
}
}
}
\ No newline at end of file
app/src/main/java/com/glsx/aicar/ui/fragment/accident/RescueLocationSelection.java
0 → 100644
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
accident
;
/** A user-confirmed accident location. Coordinates are AMap/GCJ-02 for the rescue API. */
final
class
RescueLocationSelection
{
final
String
label
;
final
String
address
;
final
double
latitude
;
final
double
longitude
;
private
RescueLocationSelection
(
String
label
,
String
address
,
double
latitude
,
double
longitude
)
{
this
.
label
=
label
;
this
.
address
=
address
;
this
.
latitude
=
latitude
;
this
.
longitude
=
longitude
;
}
static
RescueLocationSelection
create
(
String
label
,
String
address
,
double
latitude
,
double
longitude
)
{
if
(
label
==
null
||
label
.
trim
().
isEmpty
()
||
address
==
null
||
address
.
trim
().
isEmpty
()
||
(
Double
.
isNaN
(
latitude
)
||
Double
.
isInfinite
(
latitude
))
||
(
Double
.
isNaN
(
longitude
)
||
Double
.
isInfinite
(
longitude
))
||
latitude
<
-
90
||
latitude
>
90
||
longitude
<
-
180
||
longitude
>
180
||
(
latitude
==
0
&&
longitude
==
0
))
{
return
null
;
}
return
new
RescueLocationSelection
(
label
.
trim
(),
address
.
trim
(),
latitude
,
longitude
);
}
String
latitudeForRequest
()
{
return
Double
.
toString
(
latitude
);
}
String
longitudeForRequest
()
{
return
Double
.
toString
(
longitude
);
}
}
app/src/main/java/com/glsx/aicar/ui/fragment/accident/RescueMediaType.java
0 → 100644
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
accident
;
import
java.util.Locale
;
/** Formats supported by the existing Aliyun VOD image and video token flows. */
final
class
RescueMediaType
{
static
boolean
isImageExtension
(
String
extension
)
{
if
(
extension
==
null
)
return
false
;
switch
(
extension
.
toLowerCase
(
Locale
.
ROOT
))
{
case
"jpg"
:
case
"jpeg"
:
case
"png"
:
case
"gif"
:
case
"heic"
:
case
"webp"
:
return
true
;
default
:
return
false
;
}
}
static
boolean
isVideoExtension
(
String
extension
)
{
if
(
extension
==
null
)
return
false
;
switch
(
extension
.
toLowerCase
(
Locale
.
ROOT
))
{
case
"mp4"
:
case
"mov"
:
case
"3gp"
:
case
"avi"
:
case
"mkv"
:
case
"webm"
:
case
"m4v"
:
case
"ts"
:
case
"mpg"
:
case
"mpeg"
:
case
"wmv"
:
case
"flv"
:
return
true
;
default
:
return
false
;
}
}
}
app/src/main/java/com/glsx/aicar/ui/fragment/accident/UploadMediaFileToALiYunManager.java
View file @
351d9d4
...
...
@@ -145,13 +145,12 @@ public class UploadMediaFileToALiYunManager {
// String url = "http://192.168.3.102:8232/router"+"?method=" + Methods.ALIYUN_VIDEO_UPLOAD_GET_TOKEN;
String
url
=
HttpConst
.
SERVER_HTTP_ADDRESS
;
Map
<
String
,
String
>
params
=
null
;
boolean
isVideo
=
false
;
String
fileType
=
fileInfo
.
getFileType
();
if
(
"jpg"
.
equalsIgnoreCase
(
fileType
)
||
"jpeg"
.
equalsIgnoreCase
(
fileType
)
){
isVideo
=
false
;
}
else
{
isVideo
=
true
;
if
(!
RescueMediaType
.
isImageExtension
(
fileType
)
&&
!
RescueMediaType
.
isVideoExtension
(
fileType
))
{
callback
.
onGetALiYunUploadFileTokenFailed
(
HttpConstCode
.
SERVER_ERROR
,
"不支持的媒体格式"
);
return
;
}
boolean
isVideo
=
RescueMediaType
.
isVideoExtension
(
fileType
);
if
(
isVideo
){
params
=
RxHttpManager
.
getALiYunVideoUploadTokenParams
(
fileInfo
);
}
else
{
...
...
app/src/main/java/com/glsx/aicar/ui/fragment/intelligent/IntelligentCarFragment.java
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
intelligent
;
import
android.Manifest
;
import
android.app.Dialog
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.NetworkCapabilities
;
import
android.net.Uri
;
import
android.net.wifi.WifiInfo
;
import
android.net.wifi.WifiManager
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.provider.Settings
;
...
...
@@ -63,14 +60,9 @@ import com.glsx.aicar.ui.fragment.nvt.NvtDeviceFileListFragment;
import
com.glsx.aicar.ui.fragment.remote.live.RemoteLivePlayFragment
;
import
com.glsx.commonres.config.AppSrcConst
;
import
com.glsx.commonres.config.ParamsConfig
;
import
com.glsx.commonres.permission.PermissionDialogUtil
;
import
com.glsx.commonres.permission.PermissionReqCallback
;
import
com.glsx.commonres.permission.PermissionRequestUtil
;
import
com.glsx.commonres.util.AppUtils
;
import
com.glsx.commonres.util.ClickUtil
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.glsx.commonres.util.LLog
;
import
com.glsx.commonres.util.MmkvUtil
;
import
com.glsx.commonres.util.ToastUtil
;
import
com.glsx.commonres.util.ToolUtils
;
import
com.glsx.commonres.widget.GlDialog
;
...
...
@@ -87,11 +79,9 @@ import com.glsx.libaccount.http.inface.devicebind.DeviceUnbindCallBack;
import
com.glsx.libaccount.http.inface.account.ILoginBaseObserver
;
import
com.glsx.libaccount.login.LoginManager
;
import
com.glsx.libnet.connect.manager.ConnectManager
;
import
com.glsx.libnet.file.common.DvrPathConfig
;
import
com.glsx.libnet.socket.manager.CarSocketServerInfoManager
;
//import com.glsx.libxj.manager.XjConnectManager;
//import com.glsx.libxj.manager.XjDeviceInfoInteractionManager;
import
com.glsx.libnet.thumbnail.manager.ThumbnailCacheManager
;
import
com.glsx.libnova.NvtConnectManager
;
import
com.glsx.libnova.util.NovaDeviceSettingCallback
;
import
com.glsx.libnova.util.NovaDeviceSettingManager
;
...
...
@@ -435,11 +425,6 @@ public class IntelligentCarFragment extends BaseFragment implements View.OnClick
checkSHMstarDeviceConnect
();
updateDevices
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
&&
Environment
.
isExternalStorageManager
())
{
if
(
dialogHYH
!=
null
&&
dialogHYH
.
isShowing
()){
dialogHYH
.
dismiss
();
}
}
}
@Override
...
...
@@ -484,66 +469,6 @@ public class IntelligentCarFragment extends BaseFragment implements View.OnClick
}
private
void
showRequestPermissionAllDialog
()
{
PermissionRequestUtil
.
requestAppAllPermissions
(
getContext
(),
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
LLog
.
getInstance
().
init
();
ThumbnailCacheManager
.
initialize
(
AiCarApplication
.
getInstance
().
getApplicationContext
());
DvrPathConfig
.
mkDirs
();
}
@Override
public
void
onDenied
()
{
}
});
}
//hyh申请外部存储权限的弹窗
Dialog
dialogHYH
;
private
void
showDialogHYH
(){
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
View
inflateView
=
LayoutInflater
.
from
(
requireContext
()).
inflate
(
R
.
layout
.
public_layout_dialog_permission_hyh
,
null
);
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.CustomDialogTheme);
// builder.setView(inflateView);
dialogHYH
=
new
Dialog
(
requireContext
());
dialogHYH
.
setContentView
(
inflateView
);
Objects
.
requireNonNull
(
dialogHYH
.
getWindow
()).
setBackgroundDrawableResource
(
com
.
glsx
.
commonres
.
R
.
drawable
.
public_dialog_corner_bg
);
// dialogHYH = builder.create();
dialogHYH
.
show
();
// ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
// dialogHYH.getWindow().setBackgroundDrawable(colorDrawable);
inflateView
.
findViewById
(
R
.
id
.
dialog_btn_confirm
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
getFileStorage
();
}
});
inflateView
.
findViewById
(
R
.
id
.
dialog_btn_cancel
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
dialogHYH
.
dismiss
();
}
});
// }
}
/**
* MANAGE_EXTERNAL_STORAGE
*获取文件外部存储
*/
private
void
getFileStorage
(){
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
requireContext
().
getPackageName
()));
startActivityForResult
(
intent
,
123
);
}
/**
* 处理列表点击事件
*
...
...
@@ -551,29 +476,6 @@ public class IntelligentCarFragment extends BaseFragment implements View.OnClick
*/
private
void
doClickItem
(
DeviceListItem
item
)
{
// boolean isPermissionAgree = MmkvUtil.getBooleanPref(CommonConst.PREF_KEY_PERMISSION_AGREED, false);
// Log.d("hyh","fasdtyasfasfvtgfvt "+Environment.isExternalStorageManager());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
&&
!
Environment
.
isExternalStorageManager
())
{
showDialogHYH
();
return
;
}
if
(!
PermissionRequestUtil
.
checkAppAllPermissions
(
requireContext
()))
{
PermissionRequestUtil
.
showRequestAllPermissionTipsDialog
(
getContext
(),
new
PermissionDialogUtil
.
IRequirePermissionAll
()
{
@Override
public
void
OnClickConfirm
()
{
MmkvUtil
.
setPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
true
);
showRequestPermissionAllDialog
();
}
@Override
public
void
OnClickCancel
()
{
MmkvUtil
.
setPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
true
);
}
});
return
;
}
if
(
null
!=
item
)
{
if
(
item
.
getIsCdp
())
{
//如果是智能投放,不做处理,由mpaas控制配置
return
;
...
...
app/src/main/java/com/glsx/aicar/ui/fragment/intelligent/IntelligentServerFragment.java
View file @
351d9d4
...
...
@@ -14,8 +14,8 @@ import androidx.annotation.Nullable;
import
androidx.fragment.app.Fragment
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.glsx.aicar.BuildConfig
;
import
com.glsx.aicar.R
;
import
com.glsx.aicar.app.AiCarApplication
;
import
com.glsx.aicar.manager.CollectManager
;
import
com.glsx.aicar.ui.activity.login.LoginActivity
;
import
com.glsx.aicar.ui.fragment.BaseFragment
;
...
...
@@ -30,11 +30,6 @@ import com.glsx.aicar.ui.fragment.server.TendFragment;
import
com.glsx.aicar.ui.fragment.server.TrafficFragment
;
import
com.glsx.aicar.ui.fragment.travels.TravelNoteActivity
;
import
com.glsx.commonres.config.ParamsConfig
;
import
com.glsx.commonres.permission.PermissionDialogUtil
;
import
com.glsx.commonres.permission.PermissionReqCallback
;
import
com.glsx.commonres.permission.PermissionRequestUtil
;
import
com.glsx.commonres.util.LLog
;
import
com.glsx.commonres.util.MmkvUtil
;
import
com.glsx.commonres.util.NetworkUtil
;
import
com.glsx.commonres.util.ToastUtil
;
import
com.glsx.commonres.widget.GlDialog
;
...
...
@@ -43,8 +38,6 @@ import com.glsx.libaccount.BindDevicesManager;
import
com.glsx.libaccount.CommonConst
;
import
com.glsx.libaccount.UploadMPaaSManager
;
import
com.glsx.libaccount.http.entity.devices.AccountDeviceBindInfoItem
;
import
com.glsx.libnet.file.common.DvrPathConfig
;
import
com.glsx.libnet.thumbnail.manager.ThumbnailCacheManager
;
import
com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
;
import
com.tencent.mm.opensdk.openapi.IWXAPI
;
import
com.tencent.mm.opensdk.openapi.WXAPIFactory
;
...
...
@@ -167,52 +160,21 @@ public class IntelligentServerFragment extends BaseFragment implements AdapterVi
}
}
private
void
showRequestPermissionAllDialog
()
{
PermissionRequestUtil
.
requestAppAllPermissions
(
getContext
(),
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
LLog
.
getInstance
().
init
();
ThumbnailCacheManager
.
initialize
(
AiCarApplication
.
getInstance
().
getApplicationContext
());
DvrPathConfig
.
mkDirs
();
}
@Override
public
void
onDenied
()
{
}
});
}
/**
* 处理列表点击事件
*
* @param item 点击设备对象
*/
private
void
doClickItem
(
ServerItemBean
item
)
{
if
(!
PermissionRequestUtil
.
checkAppAllPermissions
(
requireContext
()))
{
PermissionRequestUtil
.
showRequestAllPermissionTipsDialog
(
getContext
(),
new
PermissionDialogUtil
.
IRequirePermissionAll
()
{
@Override
public
void
OnClickConfirm
()
{
MmkvUtil
.
setPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
true
);
showRequestPermissionAllDialog
();
}
@Override
public
void
OnClickCancel
()
{
MmkvUtil
.
setPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
true
);
}
});
return
;
}
if
(
null
!=
item
)
{
if
(!
AccountManager
.
getInstance
().
isLogin
())
{
showLoginDialog
();
return
;
}
int
serverId
=
item
.
getServerId
();
if
(
null
!=
item
)
{
int
serverId
=
item
.
getServerId
();
// The debug rescue flow uses local simulated responses when no test account exists.
if
(!
AccountManager
.
getInstance
().
isLogin
()
&&
!(
BuildConfig
.
DEBUG
&&
serverId
==
SERVER_ID_ACCIDENT
))
{
showLoginDialog
();
return
;
}
String
serverName
=
item
.
getServerName
();
uploadAction
(
String
.
valueOf
(
serverId
),
serverName
);
collectActions
(
serverId
);
...
...
app/src/main/java/com/glsx/aicar/ui/fragment/main/MainFragment.java
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
main
;
import
android.annotation.SuppressLint
;
import
android.app.AlertDialog
;
import
android.app.Dialog
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.drawable.ColorDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.provider.Settings
;
import
android.text.TextUtils
;
import
android.view.LayoutInflater
;
import
android.view.View
;
...
...
@@ -21,11 +13,9 @@ import android.view.ViewGroup;
import
android.widget.Button
;
import
android.widget.LinearLayout
;
import
com.alipay.alipaylogger.Log
;
import
com.glsx.aicar.R
;
import
com.glsx.aicar.glpush.GlUMPushAgent
;
import
com.glsx.aicar.manager.CollectManager
;
import
com.glsx.aicar.manager.LocationManager
;
import
com.glsx.aicar.manager.RemoteCarPositionManager
;
import
com.glsx.aicar.ui.fragment.BaseFragment
;
import
com.glsx.aicar.ui.fragment.base.MPaasFragment
;
...
...
@@ -34,14 +24,9 @@ import com.glsx.aicar.ui.fragment.mine.MyFragment;
import
com.glsx.aicar.ui.fragment.server.SwitchBottomTabEvent
;
import
com.glsx.aicar.util.StatusBarUtil
;
import
com.glsx.commonres.config.ParamsConfig
;
import
com.glsx.commonres.permission.PermissionDialogUtil
;
import
com.glsx.commonres.permission.PermissionReqCallback
;
import
com.glsx.commonres.permission.PermissionRequestUtil
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.glsx.commonres.util.LLog
;
import
com.
glsx.commonres.util.MmkvUtil
;
import
com.
blankj.utilcode.util.LogUtils
;
import
com.glsx.libaccount.AccountManager
;
import
com.glsx.libaccount.CommonConst
;
//import com.glsx.libaccount.SmartDeviceManager;
import
com.glsx.libaccount.UploadMPaaSManager
;
//import com.glsx.libaccount.http.entity.smart.LvMiDeviceInfo;
...
...
@@ -56,7 +41,6 @@ import org.greenrobot.eventbus.Subscribe;
import
org.greenrobot.eventbus.ThreadMode
;
import
java.lang.ref.WeakReference
;
import
java.util.Objects
;
/**
...
...
@@ -107,8 +91,8 @@ public class MainFragment extends BaseFragment implements ILoginBaseObserver{
mInnerHandler
=
new
InnerHandler
(
this
);
intoPageFragment
();
initView
();
LLog
.
getInstance
().
init
();
LoginManager
.
getInstance
().
registerListener
(
this
);
requestPermissionAll
();
//增加判断,防止重复注册BUG
if
(!
EventBus
.
getDefault
().
isRegistered
(
this
)){
EventBus
.
getDefault
().
register
(
this
);
...
...
@@ -146,98 +130,6 @@ public class MainFragment extends BaseFragment implements ILoginBaseObserver{
}
Dialog
dialogHYH
;
private
void
requestPermissionAll
()
{
boolean
isPermissionAgree
=
MmkvUtil
.
getBooleanPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
false
);
//LogUtils.d("permission"," isPermissionAgree ="+isPermissionAgree);
if
(!
isPermissionAgree
)
{
//APP启动后先弹一次出来
PermissionRequestUtil
.
showRequestAllPermissionTipsDialog
(
getContext
(),
new
PermissionDialogUtil
.
IRequirePermissionAll
()
{
@Override
public
void
OnClickConfirm
()
{
MmkvUtil
.
setPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
true
);
showRequestPermissionAllDialog
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
&&
!
Environment
.
isExternalStorageManager
())
{
getFileStorage
();
}
}
@Override
public
void
OnClickCancel
()
{
MmkvUtil
.
setPref
(
CommonConst
.
PREF_KEY_PERMISSION_AGREED
,
true
);
showDialogHYH
();
}
});
}
else
{
//如果拒绝了,不能直接弹申请,需要用户触发才能弹
// showDialogHYH(); //hyh
}
}
private
void
showDialogHYH
(){
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
&&
!
Environment
.
isExternalStorageManager
())
{
View
inflateView
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
public_layout_dialog_permission_hyh
,
null
);
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.CustomDialogTheme);
// builder.setView(inflateView);
dialogHYH
=
new
Dialog
(
context
);
dialogHYH
.
setContentView
(
inflateView
);
Objects
.
requireNonNull
(
dialogHYH
.
getWindow
()).
setBackgroundDrawableResource
(
com
.
glsx
.
commonres
.
R
.
drawable
.
public_dialog_corner_bg
);
// dialogHYH = builder.create();
dialogHYH
.
show
();
// ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
// dialogHYH.getWindow().setBackgroundDrawable(colorDrawable);
inflateView
.
findViewById
(
R
.
id
.
dialog_btn_confirm
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
getFileStorage
();
}
});
inflateView
.
findViewById
(
R
.
id
.
dialog_btn_cancel
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
dialogHYH
.
dismiss
();
}
});
}
}
/**
* MANAGE_EXTERNAL_STORAGE
*获取文件外部存储
*/
private
void
getFileStorage
(){
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
requireContext
().
getPackageName
()));
startActivityForResult
(
intent
,
123
);
}
private
void
showRequestPermissionAllDialog
()
{
PermissionRequestUtil
.
requestAppAllPermissions
(
getContext
(),
new
PermissionReqCallback
()
{
@Override
public
void
onGranted
()
{
Log
.
d
(
"hyh"
,
"ysdfsytufgsf onGranted"
);
LLog
.
getInstance
().
init
();
}
@Override
public
void
onDenied
()
{
Log
.
d
(
"hyh"
,
"ysdfsytufgsf onDenied"
);
}
});
}
private
void
initView
()
{
layoutMainBottomTabs
=
view
.
findViewById
(
R
.
id
.
fragment_main_witch_btns
);
...
...
@@ -425,18 +317,10 @@ public class MainFragment extends BaseFragment implements ILoginBaseObserver{
super
.
onResume
();
MobclickAgent
.
onPageStart
(
TAG
);
//开启高德定位,并且开始监听
LocationManager
.
getInstance
().
startAMapLocationClientListener
();
//开启更新车辆位置的任务计时器
RemoteCarPositionManager
.
instance
().
startUpdateCarPosTimer
();
LogUtils
.
v
(
TAG
,
"onResume..startAMapLocationClientListener"
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
&&
Environment
.
isExternalStorageManager
())
{
if
(
dialogHYH
!=
null
&&
dialogHYH
.
isShowing
()){
dialogHYH
.
dismiss
();
}
}
}
@Override
...
...
app/src/main/res/layout/fragment_photo_damage.xml
View file @
351d9d4
...
...
@@ -124,11 +124,11 @@
android:layout_marginLeft=
"@dimen/common_20dp"
android:layout_marginRight=
"@dimen/common_20dp"
>
<com.baidu.mapapi.map.MapView
android:id=
"@+id/mapView"
<ViewStub
android:id=
"@+id/rescue_map_stub"
android:layout=
"@layout/rescue_baidu_map_photo"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:clickable=
"true"
/>
android:layout_height=
"match_parent"
/>
<RelativeLayout
android:id=
"@+id/rl_mapview_mask"
...
...
app/src/main/res/layout/fragment_photo_damage_choose_pos.xml
View file @
351d9d4
...
...
@@ -21,11 +21,11 @@
<!-- android:clickable="true"-->
<!-- android:focusable="true" />-->
<com.baidu.mapapi.map.MapView
android:id=
"@+id/map_view_choose"
<ViewStub
android:id=
"@+id/rescue_choose_map_stub"
android:layout=
"@layout/rescue_baidu_map_choose"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:clickable=
"true"
/>
android:layout_height=
"match_parent"
/>
<ImageView
android:id=
"@+id/iv_center_location"
...
...
app/src/main/res/layout/rescue_baidu_map_choose.xml
0 → 100644
View file @
351d9d4
<?xml version="1.0" encoding="utf-8"?>
<com.baidu.mapapi.map.MapView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/map_view_choose"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:clickable=
"true"
/>
\ No newline at end of file
app/src/main/res/layout/rescue_baidu_map_photo.xml
0 → 100644
View file @
351d9d4
<?xml version="1.0" encoding="utf-8"?>
<com.baidu.mapapi.map.MapView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/mapView"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:clickable=
"true"
/>
\ No newline at end of file
app/src/main/res/layout/rescue_debug_map_placeholder.xml
0 → 100644
View file @
351d9d4
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#FFE6E6E6"
android:gravity=
"center"
android:padding=
"12dp"
android:text=
"请搜索并选择事故地点"
android:textColor=
"#FF666666"
android:textSize=
"14sp"
/>
\ No newline at end of file
app/src/test/java/com/glsx/aicar/ui/fragment/accident/RescueAsyncCallbackTest.java
0 → 100644
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
accident
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
RescueAsyncCallbackTest
{
@Test
public
void
latePoiResultCannotReplaceNewerQueryOrClearedResults
()
{
DamageChoosePosFragment
.
PoiSearchGate
gate
=
new
DamageChoosePosFragment
.
PoiSearchGate
();
long
first
=
gate
.
begin
();
long
second
=
gate
.
begin
();
assertFalse
(
gate
.
accepts
(
first
,
"北京"
,
"北京"
));
assertTrue
(
gate
.
accepts
(
second
,
"上海"
,
" 上海 "
));
assertFalse
(
gate
.
accepts
(
second
,
"上海"
,
"深圳"
));
gate
.
invalidate
();
assertFalse
(
gate
.
accepts
(
second
,
"上海"
,
"上海"
));
}
@Test
public
void
lateUploadCannotCompleteCancelledOrSamePathRetry
()
{
PhotoDamageFragment
.
UploadAttemptGate
gate
=
new
PhotoDamageFragment
.
UploadAttemptGate
();
String
path
=
"/private/rescue/picture.jpg"
;
long
cancelled
=
gate
.
begin
();
gate
.
invalidate
();
assertFalse
(
gate
.
accepts
(
cancelled
,
path
,
path
));
long
retried
=
gate
.
begin
();
assertFalse
(
gate
.
accepts
(
cancelled
,
path
,
path
));
assertFalse
(
gate
.
accepts
(
retried
,
path
,
"/private/rescue/other.jpg"
));
assertTrue
(
gate
.
accepts
(
retried
,
path
,
path
));
gate
.
invalidate
();
assertFalse
(
gate
.
accepts
(
retried
,
path
,
path
));
}
}
app/src/test/java/com/glsx/aicar/ui/fragment/accident/RescueLocationSelectionTest.java
0 → 100644
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
accident
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
class
RescueLocationSelectionTest
{
@Test
public
void
rejectsMissingOrInvalidAccidentLocation
()
{
assertNull
(
RescueLocationSelection
.
create
(
""
,
""
,
31.2
,
121.4
));
assertNull
(
RescueLocationSelection
.
create
(
"地点"
,
""
,
31.2
,
121.4
));
assertNull
(
RescueLocationSelection
.
create
(
"地点"
,
"上海"
,
0
,
0
));
assertNull
(
RescueLocationSelection
.
create
(
"地点"
,
"上海"
,
Double
.
NaN
,
121.4
));
}
@Test
public
void
preservesSelectedPoiCoordinatesAndAddressForSubmission
()
{
RescueLocationSelection
selected
=
RescueLocationSelection
.
create
(
"医院"
,
"上海市浦东新区医院"
,
31.2
,
121.4
);
assertNotNull
(
selected
);
assertEquals
(
"上海市浦东新区医院"
,
selected
.
address
);
assertEquals
(
"31.2"
,
selected
.
latitudeForRequest
());
assertEquals
(
"121.4"
,
selected
.
longitudeForRequest
());
}
}
app/src/test/java/com/glsx/aicar/ui/fragment/accident/RescueMediaTypeTest.java
0 → 100644
View file @
351d9d4
package
com
.
glsx
.
aicar
.
ui
.
fragment
.
accident
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
class
RescueMediaTypeTest
{
@Test
public
void
pngAndHeicRequestImageTokens
()
{
assertTrue
(
RescueMediaType
.
isImageExtension
(
"png"
));
assertTrue
(
RescueMediaType
.
isImageExtension
(
"HEIC"
));
assertFalse
(
RescueMediaType
.
isVideoExtension
(
"png"
));
}
@Test
public
void
videosDoNotRequestImageTokens
()
{
assertTrue
(
RescueMediaType
.
isVideoExtension
(
"mp4"
));
assertFalse
(
RescueMediaType
.
isImageExtension
(
"mp4"
));
assertFalse
(
RescueMediaType
.
isVideoExtension
(
"pdf"
));
}
}
gradle.properties
View file @
351d9d4
...
...
@@ -29,3 +29,4 @@ MobSDK.spEdition=FP
#systemProp.http.proxyPort=80
#systemProp.https.proxyHost=mirrors.aliyun.com
#systemProp.https.proxyPort=80
android.overridePathCheck
=
true
libaccount/src/main/java/com/glsx/libaccount/AccidentApiManager.java
View file @
351d9d4
...
...
@@ -99,8 +99,34 @@ public class AccidentApiManager {
});
}
private
static
boolean
hasUsableRescueLocation
(
String
lng
,
String
lat
,
String
address
)
{
if
(
address
==
null
||
address
.
trim
().
isEmpty
()
||
lng
==
null
||
lat
==
null
)
{
return
false
;
}
try
{
double
longitude
=
Double
.
parseDouble
(
lng
);
double
latitude
=
Double
.
parseDouble
(
lat
);
return
!
Double
.
isNaN
(
longitude
)
&&
!
Double
.
isInfinite
(
longitude
)
&&
!
Double
.
isNaN
(
latitude
)
&&
!
Double
.
isInfinite
(
latitude
)
&&
longitude
>=
-
180
&&
longitude
<=
180
&&
latitude
>=
-
90
&&
latitude
<=
90
&&
!(
longitude
==
0
&&
latitude
==
0
);
}
catch
(
NumberFormatException
ignored
)
{
return
false
;
}
}
public
void
submitAccidentSaveRequest
(
String
loginPhone
,
String
lng
,
String
lat
,
String
address
,
String
mediaList
,
SubmitDamagePhotoCallBack
resultCallBack
,
LifecycleOwner
owner
){
if
(!
hasUsableRescueLocation
(
lng
,
lat
,
address
))
{
resultCallBack
.
onSubmitDamagePhotoFailure
(-
1
,
"请选择事故地点"
);
return
;
}
// Debug builds prepare the same fields but must never create a real rescue event.
if
(
BuildConfig
.
DEBUG
)
{
RxHttpManager
.
buildRescueRequestFields
(
loginPhone
,
lng
,
lat
,
address
,
mediaList
);
resultCallBack
.
onSubmitDamagePhotoSuccess
(-
1L
);
return
;
}
String
url
=
HttpConst
.
SERVER_HTTP_ADDRESS
;
// String url = "http://qcdidicb.glsx.com.cn:7060/router";
RxHttp
.
get
(
url
)
...
...
libaccount/src/main/java/com/glsx/libaccount/http/HttpConst.java
View file @
351d9d4
package
com
.
glsx
.
libaccount
.
http
;
import
com.glsx.libaccount.BuildConfig
;
public
class
HttpConst
{
// 环境类型
...
...
@@ -16,7 +18,7 @@ public class HttpConst {
// public final static ENVIRONMENT_TYPE ENVIRONMENT = TEST;
public
final
static
ENVIRONMENT_TYPE
ENVIRONMENT
=
RELEASE
;
public
final
static
ENVIRONMENT_TYPE
ENVIRONMENT
=
BuildConfig
.
DEBUG
?
TEST
:
RELEASE
;
//新设备 WiFi 4G
public
static
Integer
DEVICE_ID_DVR_HC
=
110305
;
...
...
libaccount/src/main/java/com/glsx/libaccount/http/base/RxHttpManager.java
View file @
351d9d4
...
...
@@ -1134,23 +1134,27 @@ public class RxHttpManager {
return
getParams
(
map
);
}
public
static
Map
<
String
,
String
>
submitAccidentSaveRequestParams
(
String
loginPhone
,
String
lng
,
String
lat
,
String
address
,
String
mediaList
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"method"
,
Methods
.
ACCIDENT_SAVE_REQUEST_SUBMIT
);
map
.
put
(
"lng"
,
lng
);
map
.
put
(
"lat"
,
lat
);
map
.
put
(
"address"
,
address
);
map
.
put
(
"loginPhone"
,
loginPhone
);
map
.
put
(
"mediaList"
,
mediaList
);
map
.
put
(
"reqSource"
,
"8"
);
map
.
put
(
"reqTime"
,
DateUtils
.
getTimestampStr
());
map
.
put
(
"deviceName"
,
"深航MStar单机记录仪"
);
map
.
put
(
"akey"
,
AKEY
);
map
.
put
(
"typeId"
,
"6"
);
map
.
put
(
"eventSource"
,
"1"
);
return
getParams
(
map
);
}
public
static
Map
<
String
,
String
>
submitAccidentSaveRequestParams
(
String
loginPhone
,
String
lng
,
String
lat
,
String
address
,
String
mediaList
)
{
return
getParams
(
buildRescueRequestFields
(
loginPhone
,
lng
,
lat
,
address
,
mediaList
));
}
/** Raw rescue fields shared by debug simulation and the signed release request. */
public
static
Map
<
String
,
String
>
buildRescueRequestFields
(
String
loginPhone
,
String
lng
,
String
lat
,
String
address
,
String
mediaList
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"method"
,
Methods
.
ACCIDENT_SAVE_REQUEST_SUBMIT
);
map
.
put
(
"lng"
,
lng
);
map
.
put
(
"lat"
,
lat
);
map
.
put
(
"address"
,
address
);
map
.
put
(
"loginPhone"
,
loginPhone
);
map
.
put
(
"mediaList"
,
mediaList
);
map
.
put
(
"reqSource"
,
"8"
);
map
.
put
(
"reqTime"
,
DateUtils
.
getTimestampStr
());
map
.
put
(
"deviceName"
,
"深航MStar单机记录仪"
);
map
.
put
(
"akey"
,
AKEY
);
map
.
put
(
"typeId"
,
"6"
);
map
.
put
(
"eventSource"
,
"1"
);
return
map
;
}
public
static
Map
<
String
,
String
>
getAccidentRecordListParams
(
String
pageSize
,
String
pageNumber
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"method"
,
Methods
.
ACCIDENT_DAMAGE_RECORD_LIST
);
...
...
libaccount/src/testDebug/java/com/glsx/libaccount/RescueDebugIsolationTest.java
0 → 100644
View file @
351d9d4
package
com
.
glsx
.
libaccount
;
import
com.glsx.libaccount.http.HttpConst
;
import
com.glsx.libaccount.http.base.RxHttpManager
;
import
com.glsx.libaccount.http.base.Methods
;
import
java.util.Map
;
import
com.glsx.libaccount.http.inface.accident.SubmitDamagePhotoCallBack
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
class
RescueDebugIsolationTest
{
@Test
public
void
debugBuildUsesTestEnvironment
()
{
assertEquals
(
HttpConst
.
TEST
,
HttpConst
.
ENVIRONMENT
);
assertTrue
(
HttpConst
.
IS_TEST
);
assertFalse
(
HttpConst
.
SERVER_HTTP_ADDRESS
.
contains
(
"didicb.glsx.com.cn/router"
));
}
@Test
public
void
debugRescueSubmissionCompletesWithoutNetwork
()
{
final
boolean
[]
called
=
{
false
};
AccidentApiManager
.
getInstance
().
submitAccidentSaveRequest
(
"13800000000"
,
"113.0"
,
"23.0"
,
"Test location"
,
"[]"
,
new
SubmitDamagePhotoCallBack
()
{
@Override
public
void
onSubmitDamagePhotoSuccess
(
Long
result
)
{
called
[
0
]
=
true
;
assertEquals
(
Long
.
valueOf
(-
1L
),
result
);
}
@Override
public
void
onSubmitDamagePhotoFailure
(
int
code
,
String
message
)
{
fail
(
"Debug submission should be simulated locally"
);
}
},
null
);
assertTrue
(
called
[
0
]);
}
@Test
public
void
invalidRescueLocationIsRejectedBeforeNetwork
()
{
assertInvalidLocation
(
"0"
,
"0"
,
"Test location"
);
assertInvalidLocation
(
"not-a-coordinate"
,
"23"
,
"Test location"
);
assertInvalidLocation
(
"181"
,
"23"
,
"Test location"
);
assertInvalidLocation
(
"113"
,
"23"
,
""
);
}
private
void
assertInvalidLocation
(
String
lng
,
String
lat
,
String
address
)
{
final
boolean
[]
rejected
=
{
false
};
AccidentApiManager
.
getInstance
().
submitAccidentSaveRequest
(
"13800000000"
,
lng
,
lat
,
address
,
"[]"
,
new
SubmitDamagePhotoCallBack
()
{
@Override
public
void
onSubmitDamagePhotoSuccess
(
Long
result
)
{
fail
(
"Invalid location should not be submitted"
);
}
@Override
public
void
onSubmitDamagePhotoFailure
(
int
code
,
String
message
)
{
rejected
[
0
]
=
true
;
}
},
null
);
assertTrue
(
rejected
[
0
]);
}
@Test
public
void
rescueRequestFieldsPreserveSelectedLocationAndEmptyMedia
()
{
Map
<
String
,
String
>
fields
=
RxHttpManager
.
buildRescueRequestFields
(
"13800000000"
,
"113.5"
,
"23.5"
,
"选中的事故地点"
,
"[]"
);
assertEquals
(
Methods
.
ACCIDENT_SAVE_REQUEST_SUBMIT
,
fields
.
get
(
"method"
));
assertEquals
(
"113.5"
,
fields
.
get
(
"lng"
));
assertEquals
(
"23.5"
,
fields
.
get
(
"lat"
));
assertEquals
(
"选中的事故地点"
,
fields
.
get
(
"address"
));
assertEquals
(
"[]"
,
fields
.
get
(
"mediaList"
));
assertEquals
(
"13800000000"
,
fields
.
get
(
"loginPhone"
));
assertEquals
(
"8"
,
fields
.
get
(
"reqSource"
));
assertEquals
(
"6"
,
fields
.
get
(
"typeId"
));
assertEquals
(
"1"
,
fields
.
get
(
"eventSource"
));
}
}
\ No newline at end of file
local.properties
View file @
351d9d4
...
...
@@ -5,4 +5,7 @@
# For customization when using a Version Control System, please read the
# header note.
#Tue Feb 11 15:03:48 CST 2025
sdk.dir
=
D
\:\\
androidDev
\\
sdk
sdk.dir
=
D:/Android/Sdk
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment