Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
C-AVP2.0
Commits
c0af16dd
Commit
c0af16dd
authored
Dec 23, 2025
by
p x
Browse files
first
parent
0b4d4d4e
Pipeline
#3217
failed with stages
in 0 seconds
Changes
232
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/sd/cavphmi/utils/MyGeoTools.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.utils
import
com.sd.cavphmi.bean.DrivenDecision
import
commons.gis.MGeoTools
import
org.locationtech.jts.geom.LineString
import
org.locationtech.jts.geom.Polygon
object
MyGeoTools
{
// 创建 GeometryFactory
// private var geometryFactory: GeometryFactory = GeometryFactory()
//全局路径生成线段
fun
genLine
(
drivenDecision
:
DrivenDecision
):
LineString
{
val
lines
=
drivenDecision
.
trajectory
.
points
.
map
{
// Coordinate(it.longitude, it.latitude)
listOf
(
it
.
longitude
,
it
.
latitude
)
}
// var lineString = geometryFactory.createLineString(lines)
var
lineString
=
MGeoTools
.
createLine
(
lines
)
return
lineString
}
//计算线段里的点是否在面里
fun
cauLineContainsArea
(
polygon
:
Polygon
?,
lineString
:
LineString
?):
Int
{
if
(
polygon
==
null
||
lineString
==
null
)
{
return
0
}
lineString
.
coordinates
.
forEachIndexed
{
index
,
cood
->
// val sinPoint = geometryFactory.createPoint(cood)
val
sinPoint
=
MGeoTools
.
createPoint
(
cood
.
x
,
cood
.
y
)
if
(
polygon
.
contains
(
sinPoint
))
{
return
index
}
}
return
0
}
//根据坐标生成前方矩形
/* fun genFontArea(
lng: Double, lat: Double, heading: Double, length: Double = 10.0,
width: Double = 3.0
): Polygon {
var rectanglePoints = GeoRectangleUtils.createRectangleInFront(listOf(lng, lat), heading)
val coordinates = rectanglePoints.map {
Coordinate(it[0], it[1])
}.toMutableList()
// var one = myRectangle.corners.first()
// coordinates.add(Coordinate(one[0], one[1]))
var polygon = geometryFactory.createPolygon(coordinates.toTypedArray())
return polygon
}*/
// z根据中心点生成指定方向的矩形
/* fun genRectangleFromCenter(
lng: Double, lat: Double, heading: Double, length: Double = 10.0,
width: Double = 3.0
): Polygon {
// var rectanglePoints = GeoRectangleUtils.createRectangleFromCenter(lng,lat)
var rectanglePoints = GeoRectangleUtils.generateCenterRect(lng,lat,heading)
val coordinates = rectanglePoints.map {
Coordinate(it[0], it[1])
}.toMutableList()
// var one = myRectangle.corners.first()
// coordinates.add(Coordinate(one[0], one[1]))
var polygon = geometryFactory.createPolygon(coordinates.toTypedArray())
return polygon
}*/
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/MyMapUtils.java
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.utils
;
import
android.graphics.Point
;
import
android.location.Location
;
import
com.minedata.minenavi.mapdal.LatLng
;
import
java.lang.reflect.Array
;
public
class
MyMapUtils
{
/**
* 根据两个坐标点计算航向角
* @param fromPoint 起始点
* @param toPoint 终点
* @return 航向角(度),范围 0-360
*/
public
static
double
calculateBearing
(
LatLng
fromPoint
,
LatLng
toPoint
)
{
return
calculateBearing
(
fromPoint
.
longitude
,
fromPoint
.
latitude
,
toPoint
.
longitude
,
toPoint
.
latitude
);
}
/**
* 根据两个坐标点计算航向角
* @param fromLon 起始点经度
* @param fromLat 起始点纬度
* @param toLon 终点经度
* @param toLat 终点纬度
* @return 航向角(度),范围 0-360
*/
public
static
double
calculateBearing
(
double
fromLon
,
double
fromLat
,
double
toLon
,
double
toLat
)
{
// 将度转换为弧度
double
lat1
=
Math
.
toRadians
(
fromLat
);
double
lat2
=
Math
.
toRadians
(
toLat
);
double
deltaLon
=
Math
.
toRadians
(
toLon
-
fromLon
);
// 计算航向角
double
y
=
Math
.
sin
(
deltaLon
)
*
Math
.
cos
(
lat2
);
double
x
=
Math
.
cos
(
lat1
)
*
Math
.
sin
(
lat2
)
-
Math
.
sin
(
lat1
)
*
Math
.
cos
(
lat2
)
*
Math
.
cos
(
deltaLon
);
double
bearing
=
Math
.
toDegrees
(
Math
.
atan2
(
y
,
x
));
// 确保航向角在 0-360 度范围内
return
(
bearing
+
360
)
%
360
;
}
/**
* 根据三个坐标点计算航向角
* 通过计算第一点到第二点的航向角和第二点到第三点的航向角的平均值来得到更准确的航向角
* @param point1 第一个点
* @param point2 第二个点(当前位置)
* @param point3 第三个点
* @return 航向角(度),范围 0-360
*/
public
static
double
calculateBearing
(
LatLng
point1
,
LatLng
point2
,
LatLng
point3
)
{
// 计算第一点到第二点的航向角
double
bearing1
=
calculateBearing
(
point1
,
point2
);
// 计算第二点到第三点的航向角
double
bearing2
=
calculateBearing
(
point2
,
point3
);
// 返回两个航向角的平均值
return
averageBearing
(
bearing1
,
bearing2
);
}
/**
* 根据三个坐标点计算航向角
* 通过计算第一点到第二点的航向角和第二点到第三点的航向角的平均值来得到更准确的航向角
* @param lon1 第一点经度
* @param lat1 第一点纬度
* @param lon2 第二点经度
* @param lat2 第二点纬度
* @param lon3 第三点经度
* @param lat3 第三点纬度
* @return 航向角(度),范围 0-360
*/
public
static
double
calculateBearing
(
double
lon1
,
double
lat1
,
double
lon2
,
double
lat2
,
double
lon3
,
double
lat3
)
{
// 计算第一点到第二点的航向角
double
bearing1
=
calculateBearing
(
lon1
,
lat1
,
lon2
,
lat2
);
// 计算第二点到第三点的航向角
double
bearing2
=
calculateBearing
(
lon2
,
lat2
,
lon3
,
lat3
);
// 返回两个航向角的平均值
return
averageBearing
(
bearing1
,
bearing2
);
}
/**
* 计算两个航向角的平均值,考虑0度和360度的边界情况
* @param bearing1 航向角1
* @param bearing2 航向角2
* @return 平均航向角(度),范围 0-360
*/
private
static
double
averageBearing
(
double
bearing1
,
double
bearing2
)
{
// 如果两个角度相差大于180度,需要特殊处理
if
(
Math
.
abs
(
bearing1
-
bearing2
)
>
180
)
{
if
(
bearing1
>
bearing2
)
{
bearing2
+=
360
;
}
else
{
bearing1
+=
360
;
}
}
// 计算平均值
double
average
=
(
bearing1
+
bearing2
)
/
2
;
// 确保结果在0-360度范围内
return
average
%
360
;
}
//计算两点距离
public
static
double
cauMyLocDistance
(
double
fromLon
,
double
fromLat
,
double
toLon
,
double
toLat
)
{
var
results
=
new
float
[
4
];
Location
.
distanceBetween
(
fromLat
,
fromLon
,
toLat
,
toLon
,
results
);
float
distanceInMeters
=
results
[
0
];
return
distanceInMeters
;
}
}
app/src/main/java/com/sd/cavphmi/utils/SM4CryptoHelper.java
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.utils
;
import
org.bouncycastle.jce.provider.BouncyCastleProvider
;
import
java.security.Security
;
import
java.util.Base64
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
public
class
SM4CryptoHelper
{
private
static
final
String
ALGORITHM
=
"SM4"
;
private
static
final
String
TRANSFORMATION_ECB
=
"SM4/ECB/PKCS7Padding"
;
private
static
final
String
TRANSFORMATION_CBC
=
"SM4/CBC/PKCS7Padding"
;
static
{
Security
.
removeProvider
(
BouncyCastleProvider
.
PROVIDER_NAME
);
Security
.
addProvider
(
new
BouncyCastleProvider
());
}
// ECB模式加密
public
static
String
encryptECB
(
byte
[]
key
,
byte
[]
data
)
throws
Exception
{
Cipher
cipher
=
Cipher
.
getInstance
(
TRANSFORMATION_ECB
,
"BC"
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
new
SecretKeySpec
(
key
,
ALGORITHM
));
byte
[]
encrypted
=
cipher
.
doFinal
(
data
);
return
Base64
.
getEncoder
().
encodeToString
(
encrypted
);
}
// CBC模式加密(需IV参数)
public
static
byte
[]
encryptCBC
(
byte
[]
key
,
byte
[]
iv
,
byte
[]
data
)
throws
Exception
{
Cipher
cipher
=
Cipher
.
getInstance
(
TRANSFORMATION_CBC
,
"BC"
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
new
SecretKeySpec
(
key
,
ALGORITHM
),
new
IvParameterSpec
(
iv
));
return
cipher
.
doFinal
(
data
);
}
}
app/src/main/java/com/sd/cavphmi/utils/SystemUtils.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.utils
import
android.app.Activity
import
android.app.ActivityManager
import
android.content.*
import
android.content.pm.PackageManager
import
android.content.res.Resources
import
android.net.Uri
import
android.os.Build
import
android.os.PowerManager
import
android.provider.Settings
import
android.telephony.PhoneStateListener
import
android.telephony.SignalStrength
import
android.telephony.TelephonyCallback
import
android.telephony.TelephonyManager
import
android.view.View
import
android.view.WindowManager
import
android.view.inputmethod.InputMethodManager
import
android.widget.EditText
import
androidx.annotation.RequiresPermission
import
androidx.core.content.ContextCompat
import
androidx.core.content.FileProvider
import
java.io.File
object
SystemUtils
{
fun
getScreenWidth
():
Int
{
val
dm
=
Resources
.
getSystem
().
displayMetrics
return
dm
.
widthPixels
}
fun
getScreenHeight
():
Int
{
val
dm
=
Resources
.
getSystem
().
displayMetrics
return
dm
.
heightPixels
}
/**
* 调用系统打电话
*
* @param phone
*/
fun
callSystemTell
(
context
:
Context
,
phone
:
String
)
{
if
(!
phone
.
isNullOrEmpty
())
{
try
{
// var intent = Intent(Intent.ACTION_DIAL, phone.toUri())
var
intent
=
Intent
(
Intent
.
ACTION_DIAL
,
Uri
.
parse
(
"tel:$phone"
))
context
.
startActivity
(
intent
)
}
catch
(
e
:
ActivityNotFoundException
)
{
}
}
}
/**
* 获取当前应用程序的版本号
*/
fun
getAppVersionCode
(
context
:
Context
):
Int
{
var
version
=
0
try
{
version
=
context
.
packageManager
.
getPackageInfo
(
context
.
packageName
,
0
).
versionCode
}
catch
(
e
:
PackageManager
.
NameNotFoundException
)
{
throw
RuntimeException
(
context
.
javaClass
.
simpleName
+
"the application not found"
)
}
return
version
}
/**
* 获取当前应用程序的版本号
*/
fun
getAppVersionName
(
context
:
Context
):
String
{
var
version
=
"0"
try
{
version
=
context
.
packageManager
.
getPackageInfo
(
context
.
packageName
,
0
).
versionName
.
toString
()
}
catch
(
e
:
PackageManager
.
NameNotFoundException
)
{
throw
RuntimeException
(
"the application not found"
)
}
return
version
}
/**
* 关闭软键盘
*/
fun
closeKeyboard
(
view
:
View
,
context
:
Context
)
{
val
imm
=
ContextCompat
.
getSystemService
(
context
,
InputMethodManager
::
class
.
java
)
imm
?.
hideSoftInputFromWindow
(
view
.
windowToken
,
InputMethodManager
.
HIDE_NOT_ALWAYS
)
}
/**
* 打卡软键盘
*/
fun
showKeyboard
(
view
:
View
,
context
:
Context
)
{
view
.
isFocusable
=
true
view
.
requestFocus
()
val
imm
=
ContextCompat
.
getSystemService
(
context
,
InputMethodManager
::
class
.
java
)
imm
?.
showSoftInput
(
view
,
0
)
}
/**
* 适配华为安全键盘
*/
fun
etHuaWeiKeybroad
(
et
:
EditText
)
{
if
(
MobileUtils
.
isEMUI
()
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O_MR1
)
{
with
(
et
)
{
inputType
=
android
.
text
.
InputType
.
TYPE_CLASS_TEXT
or
android
.
text
.
InputType
.
TYPE_TEXT_VARIATION_NORMAL
transformationMethod
=
android
.
text
.
method
.
PasswordTransformationMethod
.
getInstance
()
}
}
}
fun
setStatusBarColor
(
activity
:
Activity
,
colorId
:
Int
)
{
val
window
=
activity
.
window
window
.
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
)
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
)
window
.
statusBarColor
=
ContextCompat
.
getColor
(
activity
,
colorId
)
}
/**
* 通过上下文找到activity
*/
fun
findActivity
(
context
:
Context
):
Activity
?
{
if
(
context
is
Activity
)
{
return
context
}
return
if
(
context
is
ContextWrapper
)
{
val
wrapper
=
context
as
ContextWrapper
findActivity
(
wrapper
.
baseContext
)
}
else
{
null
}
}
@RequiresPermission
(
"android.permission.READ_PRIVILEGED_PHONE_STATE"
)
fun
getPhoneIMEI
(
context
:
Context
):
String
?
{
val
tm
=
ContextCompat
.
getSystemService
(
context
,
TelephonyManager
::
class
.
java
)
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
O
)
{
return
tm
?.
deviceId
}
else
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
Q
)
{
return
tm
?.
getImei
(
0
)
}
else
{
return
Settings
.
System
.
getString
(
context
.
contentResolver
,
Settings
.
Secure
.
ANDROID_ID
)
}
}
/**
* 复制文字到剪切板
*/
fun
copyTextClip
(
context
:
Context
,
text
:
String
)
{
// 得到剪贴板管理器
val
cmb
=
ContextCompat
.
getSystemService
(
context
,
ClipboardManager
::
class
.
java
)
var
clipData
=
ClipData
.
newPlainText
(
""
,
text
)
cmb
?.
setPrimaryClip
(
clipData
)
}
fun
exitApp
(
context
:
Context
)
{
// val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val
activityManager
=
ContextCompat
.
getSystemService
(
context
,
ActivityManager
::
class
.
java
)
val
appTaskList
=
activityManager
?.
appTasks
if
(
appTaskList
!=
null
)
{
for
(
appTask
in
appTaskList
)
{
appTask
.
finishAndRemoveTask
()
}
}
}
fun
openThridUrl
(
url
:
String
,
context
:
Context
)
{
var
myurl
=
url
if
(!
url
.
startsWith
(
"http://"
)
&&
!
url
.
startsWith
(
"https://"
))
{
myurl
=
"http://$url"
}
try
{
val
uri
=
Uri
.
parse
(
myurl
)
val
intent
=
Intent
(
Intent
.
ACTION_VIEW
,
uri
)
context
.
startActivity
(
intent
)
}
catch
(
e
:
ActivityNotFoundException
)
{
// LogUtil.e("--------", "没找到Activity url=$url")
}
}
//android获取一个用于打开HTML文件的intent
fun
openHtmlFileIntent
(
urlParam
:
String
,
context
:
Context
)
{
val
intent
=
Intent
(
"android.intent.action.VIEW"
)
intent
.
addCategory
(
"android.intent.category.DEFAULT"
)
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
// val uri = Uri.fromFile(File(urlParam))
var
file
=
File
(
urlParam
)
var
uri
:
Uri
?
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
{
intent
.
addFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
)
uri
=
FileProvider
.
getUriForFile
(
context
,
"com.zhaolaobao.fileProvider"
,
file
)
}
else
{
uri
=
Uri
.
fromFile
(
file
)
}
var
type
=
""
/* 取得扩展名 */
var
suffix
=
urlParam
.
substringAfterLast
(
"."
).
toLowerCase
()
println
(
"----url 后缀 = ${suffix}"
)
when
(
suffix
)
{
"pdf"
->
type
=
"application/pdf"
"ppt"
,
"pptx"
->
type
=
"application/vnd.ms-powerpoint"
// "pptx" -> type =
// "application/vnd.openxmlformats-officedocument.presentationml.presentation"
"doc"
->
type
=
"application/msword"
"docx"
->
type
=
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
"xls"
,
"xlsx"
->
type
=
"application/vnd.ms-excel"
"txt"
->
type
=
"text/plain"
else
->
type
=
"*/*"
}
intent
.
setDataAndType
(
uri
,
type
)
try
{
context
.
startActivity
(
intent
)
}
catch
(
e
:
ActivityNotFoundException
)
{
ToastHelper
.
showShort
(
context
,
"不支持打开"
)
}
}
/**
*跳转到应用外部打开
*/
fun
openFile
(
file
:
File
,
context
:
Context
)
{
var
intent
=
Intent
(
Intent
.
ACTION_VIEW
)
intent
.
addCategory
(
"android.intent.category.DEFAULT"
)
var
uri
:
Uri
?
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
{
intent
.
addFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
)
uri
=
FileProvider
.
getUriForFile
(
context
,
"com.zhaolaobao.fileProvider"
,
file
)
}
else
{
uri
=
Uri
.
fromFile
(
file
)
}
var
type
=
""
/* 取得扩展名 */
var
end
=
file
.
name
.
substringAfterLast
(
"."
).
toLowerCase
()
when
(
end
)
{
"pdf"
->
type
=
"application/pdf"
"ppt"
->
type
=
"application/vnd.ms-powerpoint"
"pptx"
->
type
=
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
"doc"
->
type
=
"application/msword"
"docx"
->
type
=
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
"xls"
->
type
=
"application/vnd.ms-excel"
"xlsx"
->
type
=
"application/vnd.ms-excel"
"txt"
->
type
=
"text/plain"
else
->
type
=
"*/*"
}
intent
.
setDataAndType
(
uri
,
type
)
try
{
context
.
startActivity
(
intent
)
}
catch
(
e
:
ActivityNotFoundException
)
{
// context.toast("不支持打开")
}
}
/**
* 登录超时
*/
fun
timeOutLoginActivity
(
context
:
Context
)
{
context
.
startActivity
(
Intent
().
apply
{
// flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
action
=
"goLoginActivity"
putExtra
(
"is_login_timeout"
,
true
)
})
}
/**
* 账户禁用
*/
fun
accountDisLoginActivity
(
context
:
Context
)
{
context
.
startActivity
(
Intent
().
apply
{
flags
=
Intent
.
FLAG_ACTIVITY_NEW_TASK
or
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
action
=
"goLoginActivity"
putExtra
(
"is_login_timeout"
,
false
)
})
}
/**
* 应用是否在电池白名单里
*/
fun
isIgnoringBatteryOptimizations
(
context
:
Context
):
Boolean
{
var
isIgnoring
=
false
val
powerManager
=
ContextCompat
.
getSystemService
(
context
,
PowerManager
::
class
.
java
)
if
(
powerManager
!=
null
)
{
isIgnoring
=
powerManager
.
isIgnoringBatteryOptimizations
(
context
.
packageName
)
}
return
isIgnoring
}
fun
getMobileNetworkSignal
(
context
:
Context
)
:
Int
{
var
telephonyManager
=
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
var
signalStrength
=
telephonyManager
.
signalStrength
var
list
=
signalStrength
?.
cellSignalStrengths
return
1
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/ToastHelper.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.utils
import
android.content.Context
import
android.view.Gravity
import
android.view.LayoutInflater
import
android.view.View
import
android.widget.ImageView
import
android.widget.Toast
import
androidx.annotation.DrawableRes
import
com.sd.cavphmi.R
/**
*author:pc-20171125
*data:2019/11/8 11:18
*/
object
ToastHelper
{
/**
* 短时间显示Toast
*/
fun
showShort
(
context
:
Context
,
message
:
String
)
{
Toast
.
makeText
(
context
,
message
,
Toast
.
LENGTH_SHORT
).
run
{
show
()
}
}
fun
showCustViewShort
(
context
:
Context
,
@DrawableRes
resId
:
Int
)
{
val
customToastRoot
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
toast_tip
,
null
)
// 获取布局中的视图元素
val
imageView
=
customToastRoot
.
findViewById
<
ImageView
>(
R
.
id
.
img_tip
)
imageView
.
setImageResource
(
resId
)
val
toast
=
Toast
(
context
)
toast
.
view
=
customToastRoot
toast
.
duration
=
Toast
.
LENGTH_SHORT
// toast.setGravity(Gravity.TOP,0,0)
toast
.
show
()
}
// /**
// * 短时间显示Toast
// */
// fun showShort(context: Context, message: String) {
// Toast.makeText(context, message, Toast.LENGTH_SHORT).run {
// setGravity(Gravity.CENTER, 0, 0)
// show()
// }
// }
// /**
// * 短时间显示Toast
// *
// * @param message
// */
// fun showShort(message: Int) {
// if (isShow)
// Toast.makeText(BaseApp.context, message, Toast.LENGTH_SHORT).show()
// }
// /**
// * 长时间显示Toast
// *
// * @param message
// */
// fun showLong(message: CharSequence) {
// if (isShow)
// Toast.makeText(BaseApp.context, message, Toast.LENGTH_LONG).show()
// }
}
app/src/main/java/com/sd/cavphmi/utils/Utils.java
0 → 100644
View file @
c0af16dd
/*********************************************************************************************************************************
* NaviCore Corporate MIT License 0.1
* Copyright (c) 2019 GIS Core R&D Department, NavInfo Corp.
*
* Permission is hereby granted, free of charge, to any entity within the corporation(Entity) obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit Entities to whom the Software is furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. and
* 2. The above copyright notice, this permission notice and the acknowledgments below shall be displayed in UI or web pages
* if the Software is redistributed in binary form or as web service.
*
* Acknowledgments: "This work uses NaviZeroAndroid provided by GIS Core R&D Department, NavInfo Corp."
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* You may also get a copy of the license at http://navicore.cn/license/NC_MIT_0.1
**********************************************************************************************************************************/
package
com.sd.cavphmi.utils
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.app.ActivityManager
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.ActivityInfo
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
android.graphics.Point
;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuffXfermode
;
import
android.media.AudioManager
;
import
android.os.BatteryManager
;
import
android.os.Build
;
import
android.os.CountDownTimer
;
import
android.os.Handler
;
import
android.os.StatFs
;
import
android.text.TextUtils
;
import
android.util.Base64
;
import
android.view.View
;
import
android.view.animation.AlphaAnimation
;
import
android.view.animation.Animation
;
import
android.view.animation.AnimationSet
;
import
android.view.animation.TranslateAnimation
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.EditText
;
import
android.widget.Toast
;
//import com.minedata.minenavi.SDKInitializer;
//import com.minedata.minenavi.addons.DistanceBean;
//import com.minedata.minenavi.addons.TimeBean;
//import com.minedata.minenavi.map.MineMap;
//import com.minedata.minenavi.mapdal.DistanceStringInfo;
//import com.minedata.minenavi.mapdal.NativeEnv;
//import com.minedata.minenavi.util.MineNaviUtil;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.security.MessageDigest
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Random
;
import
java.util.Timer
;
import
java.util.TimerTask
;
public
class
Utils
{
private
Context
mContext
;
private
AudioManager
mAudioManager
;
private
PackageManager
mPackageManager
;
private
float
mDpiFactor
=
2.0f
;
private
boolean
mIsInited
=
false
;
private
Timer
mTimer
;
private
Context
mApplicationContext
;
private
CountDownTimer
mCountDownTimer
;
private
static
class
SingletonHolder
{
public
static
final
Utils
instance
=
new
Utils
();
}
public
static
Utils
getInstance
()
{
return
SingletonHolder
.
instance
;
}
public
void
init
(
Context
context
)
{
if
(
mIsInited
)
{
return
;
}
mContext
=
context
;
mApplicationContext
=
context
.
getApplicationContext
();
mTimer
=
new
Timer
();
mAudioManager
=
(
AudioManager
)
mContext
.
getSystemService
(
Context
.
AUDIO_SERVICE
);
mPackageManager
=
mContext
.
getPackageManager
();
mDpiFactor
=
context
.
getResources
().
getDisplayMetrics
().
density
;
mIsInited
=
true
;
}
/**
* 获取当前音量值
*/
public
int
getCurrentVolume
()
{
return
mAudioManager
.
getStreamVolume
(
AudioManager
.
STREAM_MUSIC
);
}
/**
* 获取音量最大值
*/
public
int
getMaxVolume
()
{
return
mAudioManager
.
getStreamMaxVolume
(
AudioManager
.
STREAM_MUSIC
);
}
/**
* 设置当前的音量
*/
public
void
setVolume
(
int
volumeValue
)
{
mAudioManager
.
setStreamVolume
(
AudioManager
.
STREAM_MUSIC
,
volumeValue
,
AudioManager
.
FLAG_PLAY_SOUND
);
//设置值为Val
}
/**
* APP是否处于前台
*/
public
boolean
isAppOnForeground
()
{
ActivityManager
activityManager
=
(
ActivityManager
)
mContext
.
getApplicationContext
().
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
String
packageName
=
mContext
.
getApplicationContext
().
getPackageName
();
List
<
ActivityManager
.
RunningAppProcessInfo
>
appProcesses
=
activityManager
.
getRunningAppProcesses
();
if
(
appProcesses
==
null
)
return
false
;
for
(
ActivityManager
.
RunningAppProcessInfo
appProcess
:
appProcesses
)
{
if
(
appProcess
.
processName
.
equals
(
packageName
)
&&
appProcess
.
importance
==
ActivityManager
.
RunningAppProcessInfo
.
IMPORTANCE_FOREGROUND
)
{
return
true
;
}
}
return
false
;
}
/**
* 判断设备是否正在充电
*/
public
boolean
isCharging
()
{
IntentFilter
ifilter
=
new
IntentFilter
(
Intent
.
ACTION_BATTERY_CHANGED
);
Intent
batteryStatus
=
mContext
.
registerReceiver
(
null
,
ifilter
);
int
status
=
batteryStatus
.
getIntExtra
(
BatteryManager
.
EXTRA_STATUS
,
-
1
);
boolean
isCharging
=
status
==
BatteryManager
.
BATTERY_STATUS_CHARGING
||
status
==
BatteryManager
.
BATTERY_STATUS_FULL
;
return
isCharging
;
}
/**
* 获取屏幕的高,如果横屏的话,返回的高就是屏幕的宽,如果是竖屏的话,返回的高就是屏幕的高,获取的高是从状态栏到导航栏整体的高
*
* @param activity 当前的activity
* @return 屏幕的高
*/
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN_MR1
)
public
int
getWindowHeight
(
Activity
activity
)
{
Point
realSize
=
new
Point
();
activity
.
getWindowManager
().
getDefaultDisplay
().
getRealSize
(
realSize
);
return
realSize
.
y
;
}
/**
* 获取屏幕的高,如果横屏的话,返回的高就是屏幕的宽,如果是竖屏的话,返回的高就是屏幕的高,获取的高是从状态栏到导航栏整体的高
*
* @param activity 当前的activity
* @return 屏幕的高
*/
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN_MR1
)
public
int
getWindowWidth
(
Activity
activity
)
{
Point
realSize
=
new
Point
();
activity
.
getWindowManager
().
getDefaultDisplay
().
getRealSize
(
realSize
);
return
realSize
.
x
;
}
/**
* 平移动画
*/
private
TranslateAnimation
mTranslateAnimation
;
public
void
translateAnimation
(
View
view
,
float
fromX
,
float
toX
,
float
fromY
,
float
toY
,
long
duration
,
Animation
.
AnimationListener
animationListener
,
boolean
isFillAfter
)
{
mTranslateAnimation
=
new
TranslateAnimation
(
Animation
.
RELATIVE_TO_SELF
,
fromX
,
Animation
.
RELATIVE_TO_SELF
,
toX
,
Animation
.
RELATIVE_TO_SELF
,
fromY
,
Animation
.
RELATIVE_TO_SELF
,
toY
);
mTranslateAnimation
.
setDuration
(
duration
);
mTranslateAnimation
.
setFillAfter
(
isFillAfter
);
if
(
animationListener
!=
null
)
{
mTranslateAnimation
.
setAnimationListener
(
animationListener
);
}
view
.
startAnimation
(
mTranslateAnimation
);
}
/**
* 混合动画动画
*/
public
void
translateAnimationWithAbsolute
(
View
view
,
float
fromAlpha
,
float
toAlpha
,
long
alaphDuration
,
long
startTime
,
float
fromX
,
float
toX
,
float
fromY
,
float
toY
,
long
translateDuration
,
long
animationSetDuration
,
Animation
.
AnimationListener
animationListener
,
boolean
isFillAfter
)
{
//途径点1——————————添加文字移动平移动画 333
AnimationSet
animationSet
=
new
AnimationSet
(
true
);
AlphaAnimation
animationa
=
new
AlphaAnimation
(
fromAlpha
,
toAlpha
);
animationa
.
setDuration
(
alaphDuration
);
animationa
.
setStartTime
(
startTime
);
animationSet
.
addAnimation
(
animationa
);
TranslateAnimation
translateAnimation
=
new
TranslateAnimation
(
Animation
.
ABSOLUTE
,
fromX
,
Animation
.
ABSOLUTE
,
toX
,
Animation
.
ABSOLUTE
,
fromY
,
Animation
.
ABSOLUTE
,
toY
);
translateAnimation
.
setDuration
(
translateDuration
);
animationSet
.
addAnimation
(
translateAnimation
);
animationSet
.
setDuration
(
animationSetDuration
);
animationSet
.
setAnimationListener
(
animationListener
);
animationSet
.
setFillAfter
(
isFillAfter
);
view
.
startAnimation
(
animationSet
);
}
public
boolean
isTranslateAnimationHasEnded
()
{
if
(
mTranslateAnimation
==
null
)
{
return
true
;
}
return
mTranslateAnimation
.
hasEnded
();
}
/**
* 地图是否是2d模式
*/
// public final boolean isMap2dStyle(MineMap mineMap) {
// return mineMap.getElevation() == 90;
// }
/**
* 地图是否是3d模式
*/
// public final boolean isMap3dStyle(MineMap mineMap) {
// return mineMap.getElevation() != 90;
// }
/**
* 延时操作
*
* @param runnable
* @param delayed
*/
private
Handler
delayedViewOperateHandler
=
new
Handler
();
public
void
doDelayedViewOperate
(
Runnable
runnable
,
long
delayed
)
{
delayedViewOperateHandler
.
postDelayed
(
runnable
,
delayed
);
}
public
Handler
getDelayedViewOperateHandler
()
{
return
delayedViewOperateHandler
;
}
public
void
cleanup
()
{
if
(
mTimer
!=
null
)
{
mTimer
.
cancel
();
mTimer
=
null
;
}
}
/**
* 秒转换成分钟,向上取整
*
* @param secondTime 秒
* @return 取整后的分钟
*/
public
final
int
second2Minute
(
int
secondTime
)
{
return
(
secondTime
+
59
)
/
60
;
}
/**
* 将以秒为单位的时间格式化
*
* @param secondTime 秒
* @return 得到格式化的时间
*/
public
String
formatTime
(
int
secondTime
)
{
String
sTotalTime
;
int
minutes
=
second2Minute
(
secondTime
);
if
(
minutes
<
60
)
{
sTotalTime
=
minutes
+
"分钟"
;
}
else
{
int
remainMin
=
minutes
%
60
;
sTotalTime
=
minutes
/
60
+
"小时"
+
(
remainMin
==
0
?
""
:
remainMin
+
"分"
);
}
return
sTotalTime
;
}
/**
* 格式化到千米,如果距离不小于100km或整千米,保留整数;否则保留小数点后一位,比如 110000 -> 110,8000 -> 8, 8001 -> 8, 800 -> 0.8, 99 -> 0
*
* @param distance 距离,单位:米
* @return 格式化后以千米表示的结果,不包含单位
*/
public
String
formatDistanceToKm
(
int
distance
)
{
String
distanceValue
;
if
(
distance
>=
100000
||
distance
%
1000
==
0
)
{
distanceValue
=
String
.
valueOf
(
distance
/
1000
);
}
else
{
distanceValue
=
String
.
format
(
Locale
.
getDefault
(),
"%.1f"
,
(
distance
/
100
)
/
10.0
);
}
return
distanceValue
;
}
/* public DistanceBean formatDistance(int distance, boolean isEnglishDistanceUnit) {
DistanceStringInfo distanceStringInfo = MineNaviUtil.distance2String(distance, isEnglishDistanceUnit ? MineNaviUtil.DistanceUnit.english : MineNaviUtil.DistanceUnit.normal, false);
String distanceValue = "";
String distanceUnit = "";
switch (distanceStringInfo.unit) {
case MineNaviUtil.GisUnit.m:
distanceUnit = isEnglishDistanceUnit ? "m" : "米";
break;
case MineNaviUtil.GisUnit.km:
distanceUnit = isEnglishDistanceUnit ? "km" : "公里";
break;
case MineNaviUtil.GisUnit.mi:
distanceUnit = isEnglishDistanceUnit ? "mile" : "英里";
break;
case MineNaviUtil.GisUnit.ft:
distanceUnit = isEnglishDistanceUnit ? "ft" : "英尺";
break;
}
distanceValue = distanceStringInfo.distanceString.split(distanceUnit)[0];
return new DistanceBean(distanceValue, distanceUnit);
}*/
/*public TimeBean calcTimeBean(int time) {
int totalMinute = (time + 59) / 60;
int timeHour = totalMinute / 60;
int timeMinute = totalMinute % 60;
return new TimeBean(timeHour, timeMinute);
}*/
/**
* 弹出/隐藏键盘
*/
public
void
enableInputMethod
(
boolean
enable
,
EditText
editText
)
{
InputMethodManager
inputManager
=
(
InputMethodManager
)
mContext
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
if
(
enable
)
{
//弹出键盘
inputManager
.
toggleSoftInput
(
0
,
InputMethodManager
.
HIDE_NOT_ALWAYS
);
}
else
{
//隐藏键盘
inputManager
.
hideSoftInputFromWindow
(
editText
.
getWindowToken
(),
0
);
}
}
/**
* 弹出/隐藏键盘 : 防止焦点丢失
*/
public
void
enableInputMethodWithFocus
(
boolean
enable
,
EditText
editText
)
{
InputMethodManager
inputManager
=
(
InputMethodManager
)
mContext
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
editText
.
setFocusable
(
enable
);
editText
.
setFocusableInTouchMode
(
enable
);
editText
.
requestFocus
();
if
(
enable
)
{
//弹出键盘
editText
.
requestFocus
();
inputManager
.
showSoftInput
(
editText
,
0
);
}
else
{
//隐藏键盘
inputManager
.
hideSoftInputFromWindow
(
editText
.
getWindowToken
(),
0
);
}
}
/**
* 光标移到文字后
*/
public
void
setSelectionEnd
(
EditText
editText
)
{
if
(
editText
!=
null
)
{
String
b
=
editText
.
getText
().
toString
();
editText
.
setSelection
(
b
.
length
());
}
}
/**
* 无焦点情况下隐藏键盘
*/
public
void
hideKeyboard
(
Context
context
)
{
Activity
activity
=
(
Activity
)
context
;
InputMethodManager
imm
=
(
InputMethodManager
)
mContext
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
View
v
=
activity
.
getWindow
().
peekDecorView
();
if
(
null
!=
v
)
{
imm
.
hideSoftInputFromWindow
(
v
.
getWindowToken
(),
0
);
}
}
/*public String getStrDistance(Point point1, Point point2) {
int distance = MineNaviUtil.distance(point1, point2);
return MineNaviUtil.distance2String(distance, MineNaviUtil.DistanceUnit.normal, false).distanceString;
}*/
public
int
dp2Px
(
float
dp
)
{
return
(
int
)
(
dp
*
mDpiFactor
+
0.5f
);
}
public
int
px2Dp
(
int
px
)
{
return
(
int
)
(
px
/
mDpiFactor
+
0.5f
);
}
/**
* 判断系统当前是24小时制还是 12小时制
*/
public
boolean
is24Hour
()
{
return
android
.
text
.
format
.
DateFormat
.
is24HourFormat
(
mContext
);
}
/**
* 将流量大小(B)格式化为显示文本,规则如下:<br>
* 1. 小于1K时,显示xxB,例如2B<br>
* 2. 小于1M时,显示xxKB,例如250KB<br>
* 3. 小于1G时,显示xxMB,例如250MB<br>
* 4. 不小于1G时,显示xx.xGB,例如1.0GB, 10.5GB
*
* @param size 流量大小,单位:字节
*/
public
String
formatTrafficDataSize
(
long
size
)
{
if
(
size
<
1024
)
{
return
size
+
"B"
;
}
else
if
(
size
<
1024
*
1024
)
{
return
size
/
1024
+
"KB"
;
}
else
if
(
size
<
10
*
1024
*
1024
)
{
return
String
.
format
(
"%.1fM"
,
size
/
(
1024.0
*
1024
));
}
else
if
(
size
<
1024L
*
1024
*
1024
)
{
return
size
/
(
1024
*
1024
)
+
"MB"
;
}
else
{
return
String
.
format
(
"%.1fGB"
,
size
/
(
1024.0
*
1024
*
1024
));
}
}
/**
* 获取版本号名字
*/
public
String
getVerName
()
{
String
verName
=
""
;
try
{
verName
=
mPackageManager
.
getPackageInfo
(
mApplicationContext
.
getPackageName
(),
0
).
versionName
;
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
e
.
printStackTrace
();
}
return
verName
;
}
/**
* 获取版本号
*/
public
int
getVersionCode
()
{
int
versionCode
=
0
;
try
{
versionCode
=
mPackageManager
.
getPackageInfo
(
mApplicationContext
.
getPackageName
(),
0
).
versionCode
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
versionCode
;
}
/**
* 获取app名字
*/
public
String
getAppName
()
{
String
appName
=
""
;
try
{
PackageInfo
packageInfo
=
mPackageManager
.
getPackageInfo
(
mApplicationContext
.
getPackageName
(),
0
);
appName
=
packageInfo
.
applicationInfo
.
loadLabel
(
mPackageManager
).
toString
();
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
e
.
printStackTrace
();
}
return
appName
;
}
/**
* 全角转半角
*
* @return 半角字符串
*/
public
String
toDBC
(
String
input
)
{
char
c
[]
=
input
.
toCharArray
();
for
(
int
i
=
0
;
i
<
c
.
length
;
i
++)
{
if
(
c
[
i
]
==
'\u3000'
)
{
c
[
i
]
=
' '
;
}
else
if
(
c
[
i
]
>
'\
uFF00
'
&&
c
[
i
]
<
'\
uFF5F
'
)
{
c
[
i
]
=
(
char
)
(
c
[
i
]
-
65248
);
}
}
return
new
String
(
c
);
}
/**
* 系统Toast
*/
public
void
showToast
(
Context
context
,
String
msg
)
{
Toast
toast
=
Toast
.
makeText
(
context
,
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
setText
(
msg
);
toast
.
show
();
}
public
void
scheduleTimerTask
(
TimerTask
timerTask
,
long
time
)
{
if
(
mTimer
!=
null
&&
timerTask
!=
null
)
{
mTimer
.
schedule
(
timerTask
,
time
);
}
}
/**
* 软件运行环境是否是手机
*
* @return
*/
// public boolean isMobilePhone() {
// try {
// if (ScreenUtil.getInstance().isScreenLandscape() && getTotalRam(mContext) <= 2.0f
// && getSdcardAvailableSize(SDKInitializer.getAppPath()) < (25L * 1024 * 1024 * 1024)) {
// return false;
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// return true;
// }
/**
* 根据包名获取当前数据存储的路径后缀
*/
public
String
getCurrentStoragePathSuffix
()
{
String
suffix
=
""
;
if
(
isTestVersion
())
{
suffix
=
"/mapbar/NaviZero"
;
}
else
if
(
isReleaseVersion
())
{
suffix
=
"/mapbar/NaviZeroRelease"
;
}
return
suffix
;
}
public
boolean
isTestVersion
()
{
String
packageName
=
mContext
.
getPackageName
();
return
TextUtils
.
equals
(
"com.mapbar.navigation.zero"
,
packageName
);
}
public
boolean
isReleaseVersion
()
{
String
packageName
=
mContext
.
getPackageName
();
return
TextUtils
.
equals
(
"com.mapbar.navigation.zero.release"
,
packageName
);
}
public
String
getLoginAppName
()
{
return
isTestVersion
()
?
"naviZeroBeta"
:
"naviZeroRelease"
;
}
/**
* 获取SD卡大小
*
* @param sdcardPath
* @return
*/
public
long
getSdcardAvailableSize
(
String
sdcardPath
)
{
long
size
=
0
;
StatFs
statFs
=
new
StatFs
(
sdcardPath
);
int
blockSize
=
statFs
.
getBlockSize
();
int
totalBlocks
=
statFs
.
getBlockCount
();
size
=
(
long
)
totalBlocks
*
blockSize
;
return
size
;
}
public
float
getTotalRam
(
Context
context
)
{
String
path
=
"/proc/meminfo"
;
String
firstLine
=
null
;
float
totalRam
=
0
;
try
{
FileReader
fileReader
=
new
FileReader
(
path
);
BufferedReader
br
=
new
BufferedReader
(
fileReader
,
8192
);
firstLine
=
br
.
readLine
().
split
(
"\\s+"
)[
1
];
br
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
firstLine
!=
null
)
{
totalRam
=
Float
.
valueOf
(
firstLine
)
/
(
1024
*
1024
);
}
return
totalRam
;
}
public
Bitmap
createCircleBitmap
(
Bitmap
resource
)
{
//获取图片的宽度
int
width
=
resource
.
getWidth
();
Paint
paint
=
new
Paint
();
//设置抗锯齿
paint
.
setAntiAlias
(
true
);
//创建一个与原bitmap一样宽度的正方形bitmap
Bitmap
circleBitmap
=
Bitmap
.
createBitmap
(
width
,
width
,
Bitmap
.
Config
.
ARGB_8888
);
//以该bitmap为低创建一块画布
Canvas
canvas
=
new
Canvas
(
circleBitmap
);
//以(width/2, width/2)为圆心,width/2为半径画一个圆
canvas
.
drawCircle
(
width
/
2
,
width
/
2
,
width
/
2
,
paint
);
//设置画笔为取交集模式
paint
.
setXfermode
(
new
PorterDuffXfermode
(
PorterDuff
.
Mode
.
SRC_IN
));
//裁剪图片
canvas
.
drawBitmap
(
resource
,
0
,
0
,
paint
);
return
circleBitmap
;
}
private
SimpleDateFormat
mSimpleDateFormat
;
/**
* local时间转换成UTC时间
*
* @param date 时间格式 例: 2019-5-21 14:12:38
* @return 返回格式化好的时间 例: 2019-5-21 22:12:38
*/
public
String
formatLocalDate
(
String
date
)
{
if
(
mSimpleDateFormat
==
null
)
{
mSimpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
}
Date
localDate
=
null
;
try
{
localDate
=
mSimpleDateFormat
.
parse
(
date
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
long
localTimeInMillis
=
localDate
.
getTime
()
+
60
*
60
*
8
*
1000
;
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTimeInMillis
(
localTimeInMillis
);
return
mSimpleDateFormat
.
format
(
calendar
.
getTime
());
}
/**
* /**
* 使用SHA1算法对字符串进行加密
*
* @param str 要签名的字符串
* @return SHA1 签名后的内容
*/
public
static
String
sha1Digest
(
String
str
)
{
if
(
str
==
null
||
str
.
length
()
==
0
)
{
return
null
;
}
char
hexDigits
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
MessageDigest
mdTemp
=
MessageDigest
.
getInstance
(
"SHA1"
);
mdTemp
.
update
(
str
.
getBytes
(
"UTF-8"
));
byte
[]
md
=
mdTemp
.
digest
();
int
j
=
md
.
length
;
char
buf
[]
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
j
;
i
++)
{
byte
byte0
=
md
[
i
];
buf
[
k
++]
=
hexDigits
[
byte0
>>>
4
&
0xf
];
buf
[
k
++]
=
hexDigits
[
byte0
&
0xf
];
}
return
new
String
(
buf
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 随机字符串
*
* @return 随机字符串
*/
public
static
String
randomString
()
{
String
str
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
Random
random
=
new
Random
();
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
int
number
=
random
.
nextInt
(
str
.
length
());
char
charAt
=
str
.
charAt
(
number
);
sb
.
append
(
charAt
);
}
return
sb
.
toString
();
}
/**
* 开启横竖屏模式
*
* @param activity 需要开启横竖屏的activity
* @param isOpen 是否打开
*/
public
void
enableHorizontalAndVerticalScreenMode
(
Activity
activity
,
boolean
isOpen
)
{
activity
.
setRequestedOrientation
(
isOpen
?
ActivityInfo
.
SCREEN_ORIENTATION_UNSPECIFIED
:
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
);
}
/**
* 开启横竖屏模式
*
* @param isOpen 是否打开
*/
public
void
enableHorizontalAndVerticalScreenMode
(
boolean
isOpen
)
{
enableHorizontalAndVerticalScreenMode
((
Activity
)
mContext
,
isOpen
);
}
/**
* 是否有网络连接
*
* @return
*/
/*public boolean isHaveNetwork() {
int netWorkState = NativeEnv.getNetworkStatus(mContext);
if (netWorkState == NativeEnv.NetworkStatus.unavailable) {
return false;
}
return true;
}*/
public
boolean
isNumber
(
String
str
)
{
for
(
int
i
=
str
.
length
();
--
i
>=
0
;
)
{
int
chr
=
str
.
charAt
(
i
);
if
(
chr
<
48
||
chr
>
57
)
return
false
;
}
return
true
;
}
/***
* MD5加密
*/
public
static
String
string2MD5
(
String
inStr
)
{
MessageDigest
md5
=
null
;
try
{
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
toString
());
e
.
printStackTrace
();
return
""
;
}
byte
[]
md5Bytes
=
md5
.
digest
(
inStr
.
getBytes
());
StringBuffer
hexValue
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
md5Bytes
.
length
;
i
++)
{
int
val
=
((
int
)
md5Bytes
[
i
])
&
0xff
;
if
(
val
<
16
)
hexValue
.
append
(
"0"
);
hexValue
.
append
(
Integer
.
toHexString
(
val
));
}
return
hexValue
.
toString
().
toUpperCase
();
}
public
static
String
base64
(
String
str
)
{
return
Base64
.
encodeToString
(
str
.
getBytes
(),
Base64
.
DEFAULT
);
}
public
static
String
location2String
(
Point
pt
)
{
return
String
.
format
(
"%.5f,%.5f"
,
pt
.
x
/
100000.0
,
pt
.
y
/
100000.0
);
}
public
static
Point
string2Location
(
String
str
)
{
try
{
String
[]
parts
=
str
.
split
(
","
);
return
new
Point
((
int
)
(
Float
.
valueOf
(
parts
[
0
])
*
100000
),
(
int
)
(
Float
.
valueOf
(
parts
[
1
])
*
100000
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
app/src/main/java/com/sd/cavphmi/viewmodels/AvpMapVM.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
android.content.Context
import
androidx.lifecycle.ViewModel
import
com.sd.cavphmi.base.MyBaseViewModel
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
javax.inject.Inject
@HiltViewModel
class
AvpMapVM
@Inject
constructor
(
@ApplicationContext
private
var
context
:
Context
)
:
MyBaseViewModel
()
{
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/viewmodels/CarPanelVM.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
androidx.lifecycle.viewModelScope
import
com.sd.cavphmi.base.MyBaseViewModel
import
com.sd.cavphmi.bean.CarPanelBean
import
com.sd.cavphmi.bean.CarVehicle
import
com.sd.cavphmi.bean.VehicleDynamic
import
com.sd.cavphmi.utils.AvpContants
import
dagger.hilt.android.lifecycle.HiltViewModel
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
java.lang.NullPointerException
import
javax.inject.Inject
import
kotlin.random.Random
@HiltViewModel
class
CarPanelVM
@Inject
constructor
()
:
MyBaseViewModel
()
{
//车辆仪表单例
var
carPanelBean
=
CarPanelBean
.
instance
/**展示车辆仪表*****/
fun
setCarPanelBean
(
dynamic
:
VehicleDynamic
)
{
//速度
carPanelBean
.
speed
.
set
(
dynamic
.
speed
.
toInt
())
//驾驶模式
carPanelBean
.
driveMode
.
set
(
dynamic
.
drivingMode
)
//航向角
carPanelBean
.
heading
.
set
(
dynamic
.
speed
.
toInt
())
//电量
carPanelBean
.
remainSoc
.
set
(
100
)
//档位
var
gearType
=
dynamic
.
gearType
when
(
gearType
)
{
AvpContants
.
GEAR_NEUTRAL
->
{
carPanelBean
.
tapPos
.
set
(
0
)
}
AvpContants
.
GEAR_PARK
->
{
carPanelBean
.
tapPos
.
set
(
1
)
}
AvpContants
.
GEAR_DRIVE
->
{
carPanelBean
.
tapPos
.
set
(
2
)
}
AvpContants
.
GEAR_REVERSE
->
{
carPanelBean
.
tapPos
.
set
(
3
)
}
AvpContants
.
GEAR_UNKNOWN
->
{
carPanelBean
.
tapPos
.
set
(
7
)
}
}
}
fun
mock
()
{
//速度
carPanelBean
.
speed
.
set
(
30
)
//驾驶模式
carPanelBean
.
driveMode
.
set
(
AvpContants
.
DRIVE_MODE_AUTOMATIC
)
//航向角
carPanelBean
.
heading
.
set
(
0
)
//电量
carPanelBean
.
remainSoc
.
set
(
100
)
//档位
carPanelBean
.
tapPos
.
set
(
2
)
// changeMockHeading()
// changeMockDriveMode()
// changeMockLight()
// changeMockPro()
// changeMockGear()
// changeMockSpeed()
}
private
fun
changeMockHeading
()
{
viewModelScope
.
launch
{
var
list
=
mutableListOf
<
Int
>()
var
ramdom
=
Random
(
360
)
for
(
i
in
1
..
360
)
{
list
.
add
(
ramdom
.
nextInt
(
360
))
}
list
.
forEach
{
withContext
(
Dispatchers
.
IO
)
{
carPanelBean
.
heading
.
set
(
it
)
delay
(
600
)
}
}
}
}
//模拟驾驶模式
private
fun
changeMockDriveMode
()
{
var
list
=
listOf
(
AvpContants
.
DRIVE_MODE_REMOTE
,
AvpContants
.
DRIVE_MODE_UNKNOWN
,
AvpContants
.
DRIVE_MODE_MANUAL
,
AvpContants
.
DRIVE_MODE_AUTOMATIC
)
viewModelScope
.
launch
{
for
(
i
in
1
..
100
)
{
for
(
j
in
0
..
3
)
{
withContext
(
Dispatchers
.
Default
)
{
delay
(
500
)
}
carPanelBean
.
driveMode
.
set
(
list
[
j
])
}
}
}
}
//模拟车灯
private
fun
changeMockLight
()
{
var
list
=
listOf
(
4
,
8
,
0
)
viewModelScope
.
launch
{
for
(
i
in
1
..
100
)
{
withContext
(
Dispatchers
.
IO
)
{
delay
(
2000
)
}
var
p
=
i
%
3
// carPanelBean.lights.set(list[p])
}
}
}
//模拟电量
private
fun
changeMockPro
()
{
viewModelScope
.
launch
{
for
(
i
in
1
..
1000
)
{
withContext
(
Dispatchers
.
IO
)
{
delay
(
300
)
}
var
p
=
i
%
100
carPanelBean
.
remainSoc
.
set
(
p
)
}
}
}
//模拟档位
private
fun
changeMockGear
()
{
var
list
=
listOf
(
0
,
1
,
2
,
3
,
7
)
viewModelScope
.
launch
{
for
(
i
in
1
..
100
)
{
withContext
(
Dispatchers
.
IO
)
{
delay
(
1000
)
}
var
p
=
i
%
5
carPanelBean
.
tapPos
.
set
(
list
.
get
(
p
))
}
}
}
//模拟速度和限速
private
fun
changeMockSpeed
()
{
// carPanelBean.spdExp.set(10)
viewModelScope
.
launch
{
for
(
i
in
1
..
100
)
{
for
(
j
in
1
..
100
)
{
withContext
(
Dispatchers
.
IO
)
{
delay
(
200
)
}
carPanelBean
.
speed
.
set
(
j
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/viewmodels/LoginVm.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
com.sd.cavphmi.bean.CarVehicle
import
com.sd.cavphmi.net.MyResult
import
com.sd.cavphmi.repositorys.AvpDataRepo
import
com.sd.cavphmi.utils.MMKVUtil
import
com.sd.cavphmi.utils.MyContants
import
dagger.hilt.android.lifecycle.HiltViewModel
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.flow.StateFlow
import
kotlinx.coroutines.launch
import
javax.inject.Inject
@HiltViewModel
class
LoginVm
@Inject
constructor
(
private
var
avpDataRepo
:
AvpDataRepo
)
:
ViewModel
()
{
//1= 登录成功 0 = 登录失败
private
var
lLogin
=
MutableStateFlow
(
0
)
/****
* 登录
* 用户名: xiaop001
* 密码:E@H^@Lxom7v@VY@x
* 验证码:285369(固定)
*以上账号用于 https://172.24.124.201:19443/itg-test-portal/full/login
* 拿到token以后放到请求头里
* ***/
fun
login
(
user
:
String
,
pwd
:
String
,
verifyCode
:
Int
):
StateFlow
<
Int
>
{
viewModelScope
.
launch
{
var
result
=
avpDataRepo
.
login
(
user
,
pwd
,
verifyCode
)
when
(
result
)
{
is
MyResult
.
Success
<
String
>
->
{
MyContants
.
HTTP_TOKEN
=
result
.
data
MMKVUtil
.
token
=
MyContants
.
HTTP_TOKEN
lLogin
.
value
=
1
}
else
->
{
lLogin
.
value
=
0
}
}
}
return
lLogin
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/viewmodels/MainVm.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
android.content.Context
import
android.content.res.Configuration
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.viewModelScope
import
com.google.gson.Gson
import
com.google.gson.JsonSyntaxException
import
com.minedata.minenavi.mapdal.LatLng
import
com.sd.cavphmi.base.MyBaseViewModel
import
com.sd.cavphmi.bean.AvpStatuBean
import
com.sd.cavphmi.bean.BindResult
import
com.sd.cavphmi.bean.CarAndStatu
import
com.sd.cavphmi.bean.CarVehicle
import
com.sd.cavphmi.bean.PerceptionBean
import
com.sd.cavphmi.bean.SpaceInfoBean
import
com.sd.cavphmi.bean.V2xStartBean
import
com.sd.cavphmi.bean.VToXImgBean
import
com.sd.cavphmi.bean.VehDetailBean
import
com.sd.cavphmi.bean.VehicleStats
import
com.sd.cavphmi.bean.mock.MRoutes
import
com.sd.cavphmi.bean.mock.MyCLoc
import
com.sd.cavphmi.highmap.AllLine
import
com.sd.cavphmi.highmap.HighMapApi
import
com.sd.cavphmi.highmap.LockStatu
import
com.sd.cavphmi.highmap.ParkStatu
import
com.sd.cavphmi.highmap.Spinfo
import
com.sd.cavphmi.highmap.WarnPtc
import
com.sd.cavphmi.intfaces.OnWebSocketCb
import
com.sd.cavphmi.net.MyResult
import
com.sd.cavphmi.net.RequestBodyUtil
import
com.sd.cavphmi.net.SseCallback
import
com.sd.cavphmi.net.SseMultiConnectionManager
import
com.sd.cavphmi.repositorys.AvpDataRepo
import
com.sd.cavphmi.utils.FileIoUtils
import
com.sd.cavphmi.utils.MyContants
import
com.sd.cavphmi.utils.MyContants.HTTP_TOKEN
import
com.sd.cavphmi.utils.MyMapUtils
import
com.sd.cavphmi.utils.ToastHelper
import
com.sd.cavphmi.websockets.FeelTargetWSClient
import
com.sd.cavphmi.websockets.V2xWSClient
import
com.sd.cavphmi.websockets.VecLocWSClient
import
commons.stand.FileSdCardUtils
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.flow.StateFlow
import
kotlinx.coroutines.flow.combine
import
kotlinx.coroutines.launch
import
java.net.URI
import
javax.inject.Inject
import
kotlin.coroutines.cancellation.CancellationException
import
kotlin.math.absoluteValue
@HiltViewModel
class
MainVm
@Inject
constructor
(
@ApplicationContext
private
var
context
:
Context
,
private
var
avpDataRepo
:
AvpDataRepo
)
:
MyBaseViewModel
()
{
// private var client: MyWebSocketClient? = null
private
val
TAG
=
"MainVm"
// var mMineMap: MineMap? = null
//Windows 焦点
var
hasFocus
=
MutableLiveData
<
Boolean
>()
//Windows窗口变化
var
windowConfiguration
=
MutableLiveData
<
Configuration
>()
//用于拼接
private
val
WSTOKEN
=
"&token=${HTTP_TOKEN}"
//网联车辆位姿socket
private
var
vecLocWSClient
=
VecLocWSClient
(
URI
(
MyContants
.
WS_VEH_LOC
))
//感知物socket
private
var
feelTargetWSClient
=
FeelTargetWSClient
(
URI
(
MyContants
.
WS_FEEL_TARGET
+
WSTOKEN
))
//v2x预警socket
private
var
v2xWSClient
=
V2xWSClient
(
URI
(
MyContants
.
WS_V2X
+
WSTOKEN
))
//网联车辆状态
// private var vehStatuWSClient = VehStatuWSClient(URI(MyContants.WS_VEH_STATU))
//socket 管理
private
var
sockets
=
listOf
(
feelTargetWSClient
,
v2xWSClient
)
//交通信号灯
// private var trafficLightWSClient: TrafficLightWSClient? = null
private
var
gson
=
Gson
()
//模拟操作
lateinit
var
mockVM
:
MockVM
//是否需要模拟
var
isMock
=
false
//车辆位姿数据
// var carVehicle = MutableLiveData<CarVehicle>()
var
carVehicle
=
MutableStateFlow
<
CarVehicle
>(
CarVehicle
())
//avp状态数据
// var avpStatu = MutableLiveData<AvpStatuBean>()
var
avpStatu
=
MutableSharedFlow
<
AvpStatuBean
>(
replay
=
1
)
//合并车辆位姿和AVP
var
carAndAvp
=
carVehicle
.
combine
(
avpStatu
)
{
carVeh
,
avpStatu
->
CarAndStatu
.
getInstance
().
apply
{
carVehicle
=
carVeh
avpStatuBean
=
avpStatu
}
}
//车辆详情
var
vehDetail
=
MutableLiveData
<
VehDetailBean
>()
//是否获取过车辆详情
var
isGetVehDetail
=
false
//感知目标物
var
targetPre
=
MutableLiveData
<
PerceptionBean
>()
//v2x 预警
var
v2xStartBean
=
MutableLiveData
<
V2xStartBean
>()
//联网车辆状态数据
var
vehicleStat
=
MutableLiveData
<
VehicleStats
>()
//车位占用情况
var
spaceInfo
=
MutableLiveData
<
SpaceInfoBean
>()
//获取已绑定车辆列表
var
bindCars
=
MutableLiveData
<
List
<
BindResult
>>()
/***清理资源***/
fun
cleanRes
()
{
//关闭socket连接
sockets
.
forEach
{
it
.
close
()
}
//关闭Http sse 长连接
SseMultiConnectionManager
.
instance
.
stopAllConnections
()
}
//获取车辆详情 传{}就行,正常应该是传场地ID,但是亦庄这个和太和桥车是一样的,用于拿到车内视频
fun
getVehDetail
(
id
:
String
=
""
):
LiveData
<
VehDetailBean
>
{
if
(
isGetVehDetail
)
return
vehDetail
isGetVehDetail
=
true
viewModelScope
.
launch
{
var
result
=
avpDataRepo
.
getVehDetail
(
id
)
when
(
result
)
{
is
MyResult
.
Success
<
VehDetailBean
>
->
{
vehDetail
.
postValue
(
result
.
data
)
}
else
->
{
}
}
}
return
vehDetail
}
/* HTTP获取车位占用情况
通过车位号传给四维高精地图*/
fun
getSpaceInfo
():
LiveData
<
SpaceInfoBean
>
{
viewModelScope
.
launch
{
var
result
=
avpDataRepo
.
getSpaceInfo
()
when
(
result
)
{
is
MyResult
.
Success
<
SpaceInfoBean
>
->
{
var
str
=
gson
.
toJson
(
result
)
FileIoUtils
.
writeToFile
(
str
,
"space_info.txt"
)
spaceInfo
.
postValue
(
result
.
data
)
}
else
->
{
}
}
}
return
spaceInfo
}
//HTTP获取AVP状态
fun
getAvpStatus
():
MutableSharedFlow
<
AvpStatuBean
>
{
if
(
isMock
)
{
mockVM
.
subAvpStatus
(
avpStatu
)
}
else
{
var
url
=
"${MyContants.HOST}/api/avpweb/hmi/monitor/v1/taskStatus"
avpCb
.
url
=
url
var
body
=
RequestBodyUtil
.
toRequestBody
(
mapOf
(
"id"
to
MyContants
.
VEHICLEID
))
avpDataRepo
.
getAvpStatus
(
url
,
body
,
avpCb
)
}
return
avpStatu
}
/***AVP状态回调***/
private
var
avpCb
=
object
:
SseCallback
{
var
url
=
""
override
fun
onConnected
(
connId
:
String
)
{
println
(
"-------- AVP状态 Sse open url = ${url} connId = ${connId}"
)
}
override
fun
onEventReceived
(
connId
:
String
,
eventType
:
String
?,
data
:
String
)
{
viewModelScope
.
launch
{
if
(
data
.
isNotEmpty
())
{
println
(
"-------AVP状态 = ${data}"
)
try
{
var
result
=
gson
.
fromJson
<
AvpStatuBean
>(
data
,
AvpStatuBean
::
class
.
java
)
if
(
result
.
haulingStageState
!=
null
)
{
//businessType
FileSdCardUtils
.
writeFileToDownload
(
data
,
"avp_status.txt"
)
}
avpStatu
.
emit
(
result
)
}
catch
(
e
:
JsonSyntaxException
)
{
e
.
printStackTrace
()
}
}
}
}
override
fun
onFailed
(
connId
:
String
,
errorMsg
:
String
)
{
println
(
"---------AVP 状态连接失败 connId = ${connId} errorMsg = ${errorMsg}"
)
}
override
fun
onClosed
(
connId
:
String
)
{
println
(
"---------AVP 状态连接关闭 connId = ${connId}"
)
}
override
fun
onReconnecting
(
delayMillis
:
Long
)
{
println
(
"------ AVP ${delayMillis / 1000}秒后开始重连"
)
}
}
/**
* 联网车辆位姿数据
*/
fun
subVehicle
():
StateFlow
<
CarVehicle
>
{
if
(
isMock
)
{
// mockVM.subVehicle(carVehicle)
// mockVM.onVehicleMockPark(carVehicle)
mockVM
.
onVehicleMockCall
(
carVehicle
,
targetPre
)
}
else
{
var
url
=
"${MyContants.HOST}/api/avpweb/hmi/monitor/v1/monitorDrivenStatus"
carCb
.
url
=
url
var
body
=
RequestBodyUtil
.
toRequestBody
(
mapOf
(
"id"
to
MyContants
.
VEHICLEID
))
avpDataRepo
.
getCarPose
(
url
,
body
,
carCb
)
}
return
carVehicle
}
//车辆位姿回调
private
var
carCb
=
object
:
SseCallback
{
var
url
=
""
override
fun
onConnected
(
connId
:
String
)
{
println
(
"--------车辆位姿 Sse open url = ${url} connId = ${connId}"
)
}
override
fun
onEventReceived
(
connId
:
String
,
eventType
:
String
?,
data
:
String
)
{
viewModelScope
.
launch
{
if
(
data
.
isNotEmpty
())
{
// println("-----车辆位姿 = ${data}")
try
{
var
result
=
gson
.
fromJson
<
CarVehicle
>(
data
,
CarVehicle
::
class
.
java
)
if
(
result
.
vehiclePos
!=
null
)
{
FileSdCardUtils
.
writeFileToDownload
(
data
,
"CarVehicle.txt"
)
}
carVehicle
.
value
=
result
}
catch
(
e
:
JsonSyntaxException
)
{
e
.
printStackTrace
()
}
}
}
}
override
fun
onFailed
(
connId
:
String
,
errorMsg
:
String
)
{
println
(
"---------车辆位置 连接失败 connId = ${connId} errorMsg = ${errorMsg}"
)
}
override
fun
onClosed
(
connId
:
String
)
{
println
(
"---------车辆位置 状态连接失败 connId = ${connId}"
)
}
override
fun
onReconnecting
(
delayMillis
:
Long
)
{
println
(
"------ 车辆位置 ${delayMillis / 1000}秒后开始重连"
)
}
}
/**感知目标物数据
*传入intersectionCode=17 拼接 代表获取某区域的感知物,目前没有数据
*/
fun
subTarget
():
LiveData
<
PerceptionBean
>
{
if
(
isMock
)
{
mockVM
.
onSubTargetMock
(
targetPre
)
}
else
{
try
{
feelTargetWSClient
!!
.
onWebSocketCb
=
object
:
OnWebSocketCb
{
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
}
override
fun
onMsg
(
str
:
String
)
{
viewModelScope
.
launch
{
//下载到sd卡下面的DownLoad文件夹下面
if
(
str
.
isNotEmpty
())
{
FileSdCardUtils
.
writeFileToDownload
(
str
,
"PerTarget.txt"
)
try
{
var
bean
=
gson
.
fromJson
(
str
,
PerceptionBean
::
class
.
java
)
targetPre
.
postValue
(
bean
)
}
catch
(
e
:
JsonSyntaxException
)
{
e
.
printStackTrace
()
}
}
}
}
}
if
(!
feelTargetWSClient
!!
.
isOpen
)
{
feelTargetWSClient
?.
connect
()
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
return
targetPre
}
/**
* V2X预警开始
* 传入vehicleId 和url拼接代表某辆车的预警
* 某个预警id要和感知物的ptcid对上
*/
fun
subStartV2x
():
LiveData
<
V2xStartBean
>
{
if
(
isMock
)
{
// mockVM.onV2xMock(v2xStartBean)
}
else
{
try
{
v2xWSClient
.
onWebSocketCb
=
object
:
OnWebSocketCb
{
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
}
override
fun
onMsg
(
str
:
String
)
{
viewModelScope
.
launch
{
if
(
str
.
isNotEmpty
())
{
FileSdCardUtils
.
writeFileToDownload
(
str
,
"avp_v2x.txt"
)
}
try
{
var
bean
=
gson
.
fromJson
(
str
,
V2xStartBean
::
class
.
java
)
v2xStartBean
.
postValue
(
bean
)
}
catch
(
e
:
JsonSyntaxException
)
{
e
.
printStackTrace
()
}
}
}
}
if
(
v2xWSClient
.
isOpen
==
false
)
{
v2xWSClient
.
connect
()
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
return
v2xStartBean
}
//HTTP获取已绑定车辆列表
fun
getBindCar
():
LiveData
<
List
<
BindResult
>>
{
viewModelScope
.
launch
{
var
result
=
avpDataRepo
.
getBindCar
()
when
(
result
)
{
is
MyResult
.
Success
<
List
<
BindResult
>>
->
{
// var str = gson.toJson(result)
// FileIoUtils.writeToFile(str, "bind_car.txt")
bindCars
.
postValue
(
result
.
data
)
}
else
->
{
}
}
}
return
bindCars
}
//开启预警特效
fun
startWarning
(
ptcId
:
String
)
{
viewModelScope
.
launch
{
var
warnPtc
=
WarnPtc
().
apply
{
ptcid
=
ptcId
isRed
=
true
}
var
warns
=
listOf
(
warnPtc
)
HighMapApi
.
setWarnPtc
(
warns
)
delay
(
5000
)
warnPtc
.
isRed
=
false
HighMapApi
.
setWarnPtc
(
warns
)
}
toggleCircleRadar
(
2
)
}
/**开启预警(光圈和雷达)
* @param dirent 0=关闭 1=左前 2=正前 3=右前 4=右后 5=正后 6=左后
* */
fun
toggleCircleRadar
(
dirent
:
Int
)
{
// HighMapApi.setCarBottomCircle(true)
HighMapApi
.
setCarRadarDirection
(
dirent
)
viewModelScope
.
launch
{
delay
(
MyContants
.
WARNINGTIME
)
// HighMapApi.setCarBottomCircle(false)
HighMapApi
.
setCarRadarDirection
(
0
)
}
}
// 模拟---------------
// 模拟---------------------------
// 模拟-----------
//模拟在仿真路上跑
fun
mockFzLine
()
{
viewModelScope
.
launch
{
try
{
var
gson
=
Gson
()
var
str
=
FileIoUtils
.
getAsset
(
context
,
"mock/Car_fangzhen.txt"
)
//Qgis里取的点和四维取得点混合
val
carVehicle
=
gson
.
fromJson
<
MRoutes
>(
str
,
MRoutes
::
class
.
java
)
//画出全局路径
var
lines
=
carVehicle
.
rs
.
map
{
AllLine
(
it
[
1
],
it
[
0
])
}
HighMapApi
.
setCarNavPath
(
lines
,
showdistance
=
200
)
//开启流光效果
HighMapApi
.
parkRoundLight
(
"B021"
)
//2旁车辆占用
var
spinfos
=
listOf
(
Spinfo
().
apply
{
code
=
"B020"
state
=
true
},
Spinfo
().
apply
{
code
=
"B022"
state
=
true
})
HighMapApi
.
setParkStatu
(
ParkStatu
(
spinfos
))
//模拟车辆移动
var
head
=
0.0
var
oldHead
=
0.0
var
bearing
=
0f
carVehicle
.
rs
.
forEachIndexed
{
index
,
it
->
if
(
index
>
0
&&
index
<
carVehicle
.
rs
.
count
())
{
var
p1
=
carVehicle
.
rs
.
get
(
index
-
1
)
var
pc
=
carVehicle
.
rs
.
get
(
index
)
head
=
MyMapUtils
.
calculateBearing
(
LatLng
(
p1
[
1
],
p1
[
0
]),
LatLng
(
pc
[
1
],
pc
[
0
])
)
}
var
myloc
=
MyCLoc
.
instance
.
apply
{
lat
=
it
[
1
]
lng
=
it
[
0
]
if
((
head
-
oldHead
).
absoluteValue
<
45
)
{
this
.
bearing
=
head
.
toFloat
()
}
// println("-----bearing = ${bearing}")
//高程
altitude
=
20.802828
}
oldHead
=
head
HighMapApi
.
setCarPosition
(
myloc
.
bearing
.
toDouble
(),
myloc
.
lat
,
myloc
.
lng
,
myloc
.
altitude
,
)
delay
(
300
)
}
//地锁绘制
var
lockStatu
=
LockStatu
().
apply
{
code
=
"B021"
up
=
false
}
HighMapApi
.
setLockStatus
(
lockStatu
)
delay
(
5000
)
lockStatu
.
isHide
=
true
HighMapApi
.
setLockStatus
(
lockStatu
)
//消除全局路径
HighMapApi
.
setCarNavPath
(
listOf
())
}
catch
(
e
:
CancellationException
)
{
}
}
}
//预警车
fun
mWarnCar
()
{
//气泡消息
v2xStartBean
.
value
=
V2xStartBean
().
apply
{
type
=
1
}
startWarning
(
"f117fdfa-feff-0100-85dc-35850000acb0"
)
}
//预警人
fun
mWarnPeo
()
{
//气泡消息
v2xStartBean
.
value
=
V2xStartBean
().
apply
{
type
=
12
}
startWarning
(
"50332456-3030-3030-3530-303334533955"
)
}
/**
* 网联车辆状态
**/
/* fun subVehicleStatus(): LiveData<VehicleStats> {
if (isMock) {
} else {
try {
vehStatuWSClient.onDataCb = object : VehStatuWSClient.OnDataCb {
override fun onMsg(str: String) {
viewModelScope.launch {
FileIoUtils.writeToFile(str, "vehicleS.txt")
var bean = gson.fromJson(str, VehicleStats::class.java)
vehicleStat.postValue(bean)
}
}
}
if (vehStatuWSClient.isOpen == false) {
vehStatuWSClient.connect()
} else {
vehStatuWSClient.reconnect()
}
} catch (e: Exception) {
e.printStackTrace()
}
}
return vehicleStat
}*/
//暂时用不到---------------------------------------------
/*** 交通(感知)事件**//*
fun subTrafficPre(): LiveData<TrafficPerBean> {
try {
if (trafficPreWSClient == null) {
trafficPreWSClient = TrafficPreWSClient(URI(MyContants.WS_TRAFFIC_PER))
trafficPreWSClient?.connect()
trafficPreWSClient?.onDataCb = object : TrafficPreWSClient.OnDataCb {
override fun onMsg(str: String) {
viewModelScope.launch {
FileIoUtils.writeToFile(str, "pre_traff.txt")
var bean = gson.fromJson(str, TrafficPerBean::class.java)
trafficPerBean.postValue(bean)
}
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
return trafficPerBean
}
*/
fun
showVToTip
()
{
var
imgs
=
VToXImgBean
.
imgs
ToastHelper
.
showCustViewShort
(
context
,
imgs
.
get
(
"2"
)
!!
)
}
/*fun d1() {
try {
vecLocWSClient.onWebSocketCb = object : OnWebSocketCb {
override fun onClose(code: Int, reason: String?, remote: Boolean) {
}
override fun onMsg(str: String) {
viewModelScope.launch {
//下载到sd卡下面的DownLoad文件夹下面
if (str.isNotEmpty()) {
FileIoUtils.writeToFile(str, "CarVehicle.txt")
}
var carBean = gson.fromJson(str, CarVehicle::class.java)
//更新主车位置
carVehicle.postValue(carBean)
}
}
}
if (!vecLocWSClient.isOpen) {
vecLocWSClient.connect()
}
} catch (e: Exception) {
e.printStackTrace()
}
}*/
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/viewmodels/MapOpt.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
android.content.Context
import
android.graphics.BitmapFactory
import
android.graphics.Point
import
android.graphics.Rect
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
com.minedata.minenavi.map.Marker
import
com.minedata.minenavi.map.MarkerOptions
import
com.minedata.minenavi.map.MineMap
import
com.minedata.minenavi.map.MyLocationStyle
import
com.minedata.minenavi.map.Overlay
import
com.minedata.minenavi.map.Polyline
import
com.minedata.minenavi.mapdal.LatLng
import
com.minedata.minenavi.mapdal.NativeEnv
import
com.minedata.minenavi.util.Tools
import
com.sd.cavphmi.R
import
com.sd.cavphmi.bean.CarVehicle
import
com.sd.cavphmi.bean.DrivenDecision
import
com.sd.cavphmi.bean.EndPoint
import
com.sd.cavphmi.bean.Space
import
com.sd.cavphmi.highmap.AllLine
import
com.sd.cavphmi.highmap.HighMapApi
import
com.sd.cavphmi.highmap.ReverCar
import
com.sd.cavphmi.utils.AvpContants
import
com.sd.cavphmi.utils.MyGeoTools
import
commons.gis.MGeoTools
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
org.locationtech.jts.geom.LineString
import
org.locationtech.jts.geom.Polygon
import
javax.inject.Inject
//地图操作类
@HiltViewModel
class
MapOpt
@Inject
constructor
(
@ApplicationContext
private
var
context
:
Context
)
:
ViewModel
()
{
var
mMineMap
:
MineMap
?
=
null
//要右下角地图小车
private
var
mSmallMapCar
:
MyLocationStyle
?
=
null
//路径规划终点
private
var
pEndMarker
:
Marker
?
=
null
/***小地图路径点坐标集合**/
private
var
sLatLngs
:
Array
<
Point
>?
=
null
//路径点的下标
var
sliceIndex
=
0
//移动过矩形次数
var
drawAreaCount
=
1
//小地图线段
private
var
lineString
:
LineString
?
=
null
//车四周矩形
private
var
roundArea
:
Polygon
?
=
null
//锁
// private var cenAreaLock = CenAreaLock()
// 小地图路径坐标点串 (02坐标系)
// private var coordinateSeries = ArrayList<DoubleArray>()
private
var
sPolyline
:
Polyline
?
=
null
//是否进入泊车倒车状态
private
var
isReversePark
=
false
//是否生成小地图线
var
smallMapLine
=
false
//全局路径
private
var
allLines
:
List
<
AllLine
>?
=
null
//画全局路径
fun
drawAllLines
(
drivenDecision
:
DrivenDecision
,
businessStatus
:
String
)
{
if
(
businessStatus
==
AvpContants
.
TRANSPORT_COMPLETED
||
businessStatus
==
AvpContants
.
TRANSPORT_CANCELED
||
businessStatus
==
AvpContants
.
PARK_COMPLETED
)
{
//清除全局路径
HighMapApi
.
setCarNavPath
(
emptyList
())
return
}
if
(
drivenDecision
.
trajectory
.
points
.
count
()
>
0
)
{
//全局路径这里只执行一次
// if (allLines == null || allLines?.count() == 0) {
allLines
=
drivenDecision
.
trajectory
.
points
.
map
{
AllLine
().
apply
{
this
.
lat
=
it
.
latitude
this
.
lon
=
it
.
longitude
}
}
HighMapApi
.
setCarNavPath
(
allLines
!!
,
drawpassed
=
true
,
showdistance
=
200
)
// }
}
var
arrived
=
drivenDecision
.
trajectory
.
arrived
if
(
arrived
)
{
// HighMapApi.setCameraDistance(30f)
// HighMapApi.setCarNavPath(emptyList())
}
}
//画局部图小车
fun
drawNavingCar
(
drivenDecision
:
DrivenDecision
)
{
if
(
mSmallMapCar
==
null
)
{
var
point
=
LatLng
(
drivenDecision
.
startPoint
.
latitude
,
drivenDecision
.
startPoint
.
longitude
)
mSmallMapCar
=
MyLocationStyle
(
"res/icons/carIconInSmallMap.png"
,
true
)
mSmallMapCar
?.
myLocationType
(
MyLocationStyle
.
LOCATION_TYPE_EXTERNAL
)
val
scaleFactor
=
-
Math
.
round
(((
10
*
NativeEnv
.
getDpi
()
*
2
)
*
10
/
(
160
*
48
)).
toFloat
())
.
toFloat
()
/
10
mSmallMapCar
?.
scaleFactor
(
scaleFactor
)
mSmallMapCar
?.
anchor
(
0.5f
,
0.5f
)
mSmallMapCar
?.
setPosition
(
point
)
mMineMap
?.
setMyLocationStyle
(
mSmallMapCar
)
}
}
/****根据车辆位置 画局部图小车*/
fun
drawSmallCar
(
car
:
CarVehicle
)
{
synchronized
(
this
)
{
if
(
mMineMap
!=
null
&&
car
.
vehiclePos
!=
null
)
{
if
(
mSmallMapCar
==
null
)
{
var
point
=
LatLng
(
car
.
vehiclePos
?.
get
(
1
)
?:
0.0
,
car
.
vehiclePos
?.
get
(
0
)
?:
0.0
)
mSmallMapCar
=
MyLocationStyle
(
"res/icons/carIconInSmallMap.png"
,
true
)
mSmallMapCar
?.
myLocationType
(
MyLocationStyle
.
LOCATION_TYPE_EXTERNAL
)
val
scaleFactor
=
-
Math
.
round
(((
10
*
NativeEnv
.
getDpi
()
*
2
)
*
10
/
(
160
*
48
)).
toFloat
())
.
toFloat
()
/
10
mSmallMapCar
?.
scaleFactor
(
scaleFactor
)
mSmallMapCar
?.
anchor
(
0.5f
,
0.5f
)
mSmallMapCar
?.
setPosition
(
point
)
mMineMap
?.
setMyLocationStyle
(
mSmallMapCar
)
}
}
}
}
/**
* 刷新右下角小车位置
*/
fun
showNavingCarPosition
(
carVehicle
:
CarVehicle
)
{
if
(
carVehicle
.
vehiclePos
==
null
)
return
synchronized
(
NativeEnv
.
SyncObject
)
{
var
ndsLatLng
=
LatLng
(
carVehicle
.
vehiclePos
?.
get
(
1
)
?:
0.0
,
carVehicle
.
vehiclePos
?.
get
(
0
)
?:
0.0
)
var
tHead
=
carVehicle
.
vehiclePos
!!
.
get
(
2
).
toFloat
()
//刷新小地图自车位置
if
(
mSmallMapCar
!=
null
)
{
// mSmallMapCar!!.orientAngle((heading + 40) % 360)
mSmallMapCar
!!
.
orientAngle
(
0f
-
180f
-
tHead
)
// mSmallMapCar!!.orientAngle((heading + 180) % 360)
mSmallMapCar
!!
.
setPositionNds
(
ndsLatLng
)
// val point = Tools.latLngToPoint(ndsLatLng)
// mMineMap?.setPointToCenter(point.x, point.y)
}
}
}
/***生成小地图路线 并转化为二维坐标系*/
fun
takeSmallMapLine
(
drivenDecision
:
DrivenDecision
,
businessStatus
:
String
)
{
if
(
businessStatus
==
AvpContants
.
TRANSPORT_COMPLETED
||
businessStatus
==
AvpContants
.
TRANSPORT_CANCELED
)
{
//删除路径线
deleteSmapLine
()
//清除全局路径数据
clearSmallLineData
()
return
}
// if (smallMapLine)
// return
// if (coordinateSeries.count() > 0)
// return
if
(
drivenDecision
.
trajectory
.
points
.
count
()
>
0
)
{
// smallMapLine = true
//转换小弟提路径点
sLatLngs
=
drivenDecision
.
trajectory
.
points
.
map
{
Tools
.
latLngToPoint
(
LatLng
(
it
.
latitude
,
it
.
longitude
))
}.
toTypedArray
()
//生成小地图线段
lineString
=
MyGeoTools
.
genLine
(
drivenDecision
)
}
}
//车四周生成矩形
fun
genFronArea
(
car
:
CarVehicle
)
{
// synchronized(NativeEnv.SyncObject) {
var
vehiclePos
=
car
.
vehiclePos
!!
roundArea
=
MGeoTools
.
createRectangleCenter
(
vehiclePos
[
0
],
vehiclePos
[
1
],
vehiclePos
[
2
],
3.0
,
5.0
)
// MyGeoTools.genRectangleFromCenter(vehiclePos[0], vehiclePos[1], vehiclePos[2])
// }
}
//更新小地图路径
fun
upSmallMapLine
()
{
if
(
sLatLngs
!=
null
&&
(
sLatLngs
?.
count
()
?:
0
)
>
0
)
{
//当前车辆位置
// var latlng = LatLng(carVehicle.vehiclePos!!.get(1), carVehicle.vehiclePos.get(0))
viewModelScope
.
launch
(
Dispatchers
.
Default
)
{
//算出线段与车辆四周面的相交
var
crossIndex
=
MyGeoTools
.
cauLineContainsArea
(
roundArea
,
lineString
)
//点没有平均分配,前三分一8个点,后三分之一3个点
// println("-----------相交线段下标 crossIndex = ${crossIndex}")
// if (sliceIndex < crossIndex) {
// sliceIndex = crossIndex
// }
//删除线
deleteSmapLine
()
synchronized
(
NativeEnv
.
SyncObject
)
{
//截取线段
var
nPoints
=
sLatLngs
!!
.
sliceArray
(
crossIndex
..
sLatLngs
!!
.
lastIndex
)
sPolyline
=
Polyline
(
nPoints
,
false
)
sPolyline
?.
setStrokeStyle
(
Overlay
.
StrokeStyle
.
solidWithButt
)
sPolyline
?.
setWidth
(
8f
)
sPolyline
?.
setColor
(
0xFF00B578
.
toInt
())
mMineMap
?.
addOverlay
(
sPolyline
)
}
}
}
else
{
deleteSmapLine
()
}
}
/***用2点生成最小矩形控制地图显示范围,更新车的位置***/
fun
drawEndArea
(
car
:
CarVehicle
)
{
if
(
sLatLngs
==
null
||
sLatLngs
?.
count
()
==
0
)
{
var
ndsLatLng
=
LatLng
(
car
.
vehiclePos
?.
get
(
1
)
?:
0.0
,
car
.
vehiclePos
?.
get
(
0
)
?:
0.0
)
val
point
=
Tools
.
latLngToPoint
(
ndsLatLng
)
mMineMap
?.
setPointToCenter
(
point
.
x
,
point
.
y
)
}
else
{
if
(
drawAreaCount
.
div
(
50
)
==
0
)
{
// println("----------drawAreaCount = $drawAreaCount")
var
lon1
=
car
.
vehiclePos
!!
.
get
(
0
)
var
lat1
=
car
.
vehiclePos
!!
.
get
(
1
)
var
lon2
=
sLatLngs
!!
.
last
().
x
.
div
(
100000.0
)
var
lat2
:
Double
=
sLatLngs
!!
.
last
().
y
.
div
(
100000.0
)
val
MU
=
100000
var
minLat
=
Math
.
min
(
lat1
,
lat2
).
times
(
MU
).
toInt
()
-
10
var
maxLat
=
Math
.
max
(
lat1
,
lat2
).
times
(
MU
).
toInt
()
+
10
var
minLon
=
Math
.
min
(
lon1
,
lon2
).
times
(
MU
).
toInt
()
-
10
var
maxLon
=
Math
.
max
(
lon1
,
lon2
).
times
(
MU
).
toInt
()
+
10
var
rect
=
Rect
(
minLon
,
minLat
,
maxLon
,
maxLat
)
mMineMap
?.
fitWorldArea
(
rect
)
drawAreaCount
=
1
}
drawAreaCount
++
}
}
/**画路径起终点***/
fun
addEndMarker
(
endPoint
:
EndPoint
,
businessStatus
:
String
)
{
if
(
businessStatus
==
AvpContants
.
TRANSPORT_COMPLETED
||
businessStatus
==
AvpContants
.
TRANSPORT_CANCELED
)
{
//删除终点marker
deleteEndMarker
()
return
}
if
(
pEndMarker
==
null
)
{
var
mEndPoint
=
LatLng
(
endPoint
.
latitude
,
endPoint
.
longitude
)
val
end_icon
=
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
drawable
.
plan_end
)
pEndMarker
=
mMineMap
?.
addMarker
(
MarkerOptions
().
zLevel
(
7
).
position
(
mEndPoint
).
bitmap
(
end_icon
)
)
}
}
//判断在泊车状态下的倒挡绘制倒车路线,改变视角
fun
drawReversePark
(
businessType
:
String
,
businessStatus
:
String
,
gearType
:
String
,
space
:
Space
)
{
if
(
businessType
==
AvpContants
.
Park_TYPE
)
{
if
(
businessStatus
==
AvpContants
.
TRANSPORT_COMPLETED
)
{
//到达停车点
HighMapApi
.
setCameraDistance
(
30f
)
HighMapApi
.
setCameraAngle
(
60f
)
}
else
if
(
businessStatus
==
AvpContants
.
PARK_PROGRESS
)
{
//泊车进行中
HighMapApi
.
setCameraDistance
(
20f
)
HighMapApi
.
setCameraAngle
(
90f
)
var
reverCar
=
ReverCar
().
apply
{
this
.
cenLat
=
space
.
centerLatitude
this
.
cenLng
=
space
.
centerLongitude
this
.
code
=
space
.
code
}
HighMapApi
.
setParkRever
(
reverCar
)
}
else
if
(
businessStatus
==
AvpContants
.
PARK_COMPLETED
)
{
//消除泊车特效
HighMapApi
.
setParkComplete
(
true
)
}
else
{
HighMapApi
.
setCameraAngle
(
30f
)
HighMapApi
.
setCameraDistance
(
8f
)
}
// if (isReversePark)
// return
// isReversePark = true
}
else
{
HighMapApi
.
setCameraAngle
(
30f
)
HighMapApi
.
setCameraDistance
(
8f
)
}
}
//是否显示车位流光效果
fun
showParkLight
(
businessType
:
String
,
businessStatus
:
String
,
space
:
Space
)
{
if
(
businessType
==
AvpContants
.
Park_TYPE
)
{
if
(
businessStatus
==
AvpContants
.
PARK_COMPLETED
)
{
//消除车位流光特效
HighMapApi
.
parkRoundLight
(
""
)
}
else
{
HighMapApi
.
parkRoundLight
(
space
.
name
)
}
}
else
{
// HighMapApi.parkRoundLight("")
}
}
//根据AVP状态判特效是否关闭
/* fun showEffectAvpStatu(businessType: String, businessStatus: String) {
//到达召,停车点
if (businessType == AvpContants.TRANSPORT_COMPLETED || businessType == AvpContants.TRANSPORT_CANCELED || businessType == AvpContants.TRANSPORT_ABNORMAL) {
//消除全局路径
HighMapApi.setCarNavPath(emptyList())
//删除终点mark
deleteEndMarker()
//清除小地图路径数据
clearSmallLineData()
}
//倒车完成
if (businessType == AvpContants.Park_TYPE) {
if (businessStatus == AvpContants.PARK_COMPLETED || businessStatus == AvpContants.PARK_CANCELED) {
//消除车位流光特效
HighMapApi.parkRoundLight("")
//消除泊车特效
HighMapApi.setParkComplete(true)
}
}
}*/
/***清除所有绘制**/
fun
clearAllEffect
()
{
//删除终点mark
deleteEndMarker
()
//清除小地图路径数据
clearSmallLineData
()
//删除线
deleteSmapLine
()
}
/**
* 移除终点
*/
private
fun
deleteEndMarker
()
{
if
(
pEndMarker
!=
null
)
{
mMineMap
?.
removeMarker
(
pEndMarker
)
pEndMarker
=
null
}
}
/**
* 移除导航小车
*/
fun
deleteNavingCar
()
{
if
(
mMineMap
!=
null
&&
mSmallMapCar
!=
null
)
{
mMineMap
?.
removeOverlay
(
mSmallMapCar
)
mSmallMapCar
!!
.
release
()
mSmallMapCar
=
null
}
}
//删除小地图路径
fun
deleteSmapLine
()
{
if
(
sPolyline
!=
null
)
{
mMineMap
?.
removeOverlay
(
sPolyline
)
sPolyline
?.
release
()
}
}
//清除小地图路径数据
fun
clearSmallLineData
()
{
// coordinateSeries.clear()
sLatLngs
?.
toMutableList
()
?.
clear
()
sLatLngs
=
null
}
}
class
CenAreaLock
{
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/viewmodels/MockVM.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
android.content.Context
import
android.graphics.BitmapFactory
import
android.graphics.Point
import
android.graphics.Rect
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
com.google.gson.Gson
import
com.google.gson.JsonSyntaxException
import
com.minedata.minenavi.map.Marker
import
com.minedata.minenavi.map.MarkerOptions
import
com.minedata.minenavi.map.MineMap
import
com.minedata.minenavi.map.MyLocationStyle
import
com.minedata.minenavi.map.Overlay
import
com.minedata.minenavi.map.Polyline
import
com.minedata.minenavi.mapdal.LatLng
import
com.minedata.minenavi.mapdal.NativeEnv
import
com.minedata.minenavi.mapdal.NdsPoint
import
com.minedata.minenavi.util.Tools
import
com.sd.cavphmi.R
import
com.sd.cavphmi.bean.AvpStatuBean
import
com.sd.cavphmi.bean.CarPanelBean
import
com.sd.cavphmi.bean.CarVehicle
import
com.sd.cavphmi.bean.PerceptionBean
import
com.sd.cavphmi.bean.V2xStartBean
import
com.sd.cavphmi.bean.mock.MRoutes
import
com.sd.cavphmi.bean.mock.ParkPath
import
com.sd.cavphmi.highmap.AllLine
import
com.sd.cavphmi.highmap.HighMapApi
import
com.sd.cavphmi.highmap.ParkStatu
import
com.sd.cavphmi.highmap.ReverCar
import
com.sd.cavphmi.highmap.Spinfo
import
com.sd.cavphmi.utils.FileIoUtils
import
com.sd.cavphmi.utils.MyMapUtils
import
com.sd.cavphmi.utils.ToastHelper
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
javax.inject.Inject
import
kotlin.math.absoluteValue
import
kotlin.random.Random
import
kotlin.random.nextInt
@HiltViewModel
class
MockVM
@Inject
constructor
(
@ApplicationContext
private
var
context
:
Context
,
)
:
ViewModel
()
{
var
mMineMap
:
MineMap
?
=
null
private
var
gson
=
Gson
()
/**解析网络数据***/
suspend
fun
<
T
>
parseDataBean
(
str
:
String
,
clazz
:
Class
<
T
>):
T
?
{
return
withContext
(
Dispatchers
.
Default
)
{
try
{
return
@withContext
gson
.
fromJson
(
str
,
clazz
)
}
catch
(
e
:
JsonSyntaxException
)
{
e
.
printStackTrace
()
return
@withContext
null
}
}
}
/******
* 模拟车辆位姿 泊车
* @param binding 里的航向角
* @param binding 里的速度
* **/
fun
onVehicleMockPark
(
carVehicle
:
MutableStateFlow
<
CarVehicle
>
)
{
// HighMapApi.setCameraAngle(30f)
viewModelScope
.
launch
{
var
cCar
:
CarVehicle
?
=
null
var
gson
=
Gson
()
var
str
=
FileIoUtils
.
getAsset
(
context
,
"mock/Car_fangzhen_park.txt"
)
//Qgis里取的点和四维取得点混合
val
mRoutes
=
gson
.
fromJson
<
MRoutes
>(
str
,
MRoutes
::
class
.
java
)
//画局部图小车
drawNavingCar
(
Tools
.
latLngToPoint
(
LatLng
(
39.81014469509955
,
116.50238005214746
)))
//画局部图路径
smallLineMock
(
mRoutes
)
//画终点
addEndMarker
(
LatLng
(
39.809039362307594
,
116.50254394816011
))
//用矩形框柱
drawEndArea
(
39.81014469509955
,
116.50238005214746
,
39.809039362307594
,
116.50254394816011
,
)
//画出全局路径
var
lines
=
mRoutes
.
rs
.
map
{
AllLine
(
it
[
1
],
it
[
0
])
}
HighMapApi
.
setCarNavPath
(
lines
,
showdistance
=
200
)
//开启流光效果
HighMapApi
.
parkRoundLight
(
"B017"
)
//2旁车辆占用
var
spinfos
=
listOf
(
Spinfo
().
apply
{
code
=
"B016"
state
=
true
},
Spinfo
().
apply
{
code
=
"B018"
state
=
true
})
HighMapApi
.
setParkStatu
(
ParkStatu
(
spinfos
))
//模拟车辆移动
var
head
=
0.0
var
oldHead
=
0.0
var
bearing
=
0f
val
random
=
Random
mRoutes
.
rs
.
forEachIndexed
{
index
,
it
->
//变速
CarPanelBean
.
instance
.
speed
.
set
(
random
.
nextInt
(
10
..
15
))
if
(
index
>
0
&&
index
<
mRoutes
.
rs
.
count
())
{
var
p1
=
mRoutes
.
rs
.
get
(
index
-
1
)
var
pc
=
mRoutes
.
rs
.
get
(
index
)
head
=
MyMapUtils
.
calculateBearing
(
LatLng
(
p1
[
1
],
p1
[
0
]),
LatLng
(
pc
[
1
],
pc
[
0
])
)
}
cCar
=
CarVehicle
().
apply
{
this
.
vehiclePos
=
listOf
(
it
[
0
],
it
[
1
],
head
)
}
oldHead
=
head
//更新主车位置
carVehicle
.
value
=
cCar
//更新小地图小车
showNavingCarPosition
(
Tools
.
latLngToNdsPoint
(
LatLng
(
cCar
.
vehiclePos
!!
.
get
(
1
),
cCar
.
vehiclePos
!!
.
get
(
0
)
)
),
cCar
.
vehiclePos
!!
.
get
(
2
).
toFloat
()
)
//更新小地图路径
upSmallLine
(
index
,
mRoutes
)
delay
(
300
)
}
//消除全局路径
HighMapApi
.
setCarNavPath
(
listOf
())
//删除终点mark
deleteEndMarker
()
//删除导航小地图小车
// deleteNavingCar()
//地锁绘制(升起)
// var lockStatu = LockStatu().apply {
// code = "B017"
// up = false
// }
// HighMapApi.setLockStatus(lockStatu)
//开始泊车
var
parkStr
=
FileIoUtils
.
getAsset
(
context
,
"mock/parkpath.txt"
)
val
parkPath
=
gson
.
fromJson
<
ParkPath
>(
parkStr
,
ParkPath
::
class
.
java
)
//改变镜头角度
HighMapApi
.
setCameraAngle
(
60f
)
HighMapApi
.
setCameraDistance
(
30f
)
//从停车点再前进一点
var
forword
=
parkPath
.
result
.
routes
.
find
{
it
.
gear
==
3
}
forword
?.
polyline
?.
forEach
{
poly
->
CarPanelBean
.
instance
.
speed
.
set
(
5
)
//减速
cCar
=
CarVehicle
().
apply
{
this
.
vehiclePos
=
listOf
(
poly
.
get
(
0
),
poly
.
get
(
1
),
poly
.
get
(
3
))
}
//更新主车位置
carVehicle
.
value
=
cCar
//更新小地图小车
showNavingCarPosition
(
Tools
.
latLngToNdsPoint
(
LatLng
(
cCar
.
vehiclePos
!!
.
get
(
1
),
cCar
.
vehiclePos
!!
.
get
(
0
)
)
),
cCar
.
vehiclePos
!!
.
get
(
2
).
toFloat
()
)
delay
(
300
)
}
//绘制倒车路径
var
reverCar
=
ReverCar
().
apply
{
this
.
cenLat
=
39.80903159
this
.
cenLng
=
116.50246079
this
.
code
=
"B017"
}
HighMapApi
.
setParkRever
(
reverCar
)
//改变镜头角度
HighMapApi
.
setCameraAngle
(
90f
)
HighMapApi
.
setCameraDistance
(
20f
)
//挂倒挡
CarPanelBean
.
instance
.
tapPos
.
set
(
3
)
//开始后退
var
fBack
=
parkPath
.
result
.
routes
.
find
{
it
.
gear
==
1
}
fBack
?.
polyline
?.
forEach
{
poly
->
CarPanelBean
.
instance
.
speed
.
set
(
random
.
nextInt
(
1
..
5
))
//减速变速
cCar
=
CarVehicle
().
apply
{
this
.
vehiclePos
=
listOf
(
poly
.
get
(
0
),
poly
.
get
(
1
),
poly
.
get
(
3
))
}
//更新主车位置
carVehicle
.
value
=
cCar
//更新小地图小车
showNavingCarPosition
(
Tools
.
latLngToNdsPoint
(
LatLng
(
cCar
.
vehiclePos
!!
.
get
(
1
),
cCar
.
vehiclePos
!!
.
get
(
0
)
)
),
cCar
.
vehiclePos
!!
.
get
(
1
).
toFloat
()
)
delay
(
300
)
}
//结束泊车
HighMapApi
.
setParkComplete
(
true
)
//删除导航小地图小车
deleteNavingCar
()
//关闭流光效果
HighMapApi
.
parkRoundLight
(
""
)
//挂P档
CarPanelBean
.
instance
.
tapPos
.
set
(
1
)
CarPanelBean
.
instance
.
speed
.
set
(
0
)
//给个提示
ToastHelper
.
showShort
(
context
,
"泊车完成"
)
// delay(3000)
//降地锁
// lockStatu.up = false
// HighMapApi.setLockStatus(lockStatu)
}
}
fun
drawEndArea
(
lat1
:
Double
,
lon1
:
Double
,
lat2
:
Double
,
lon2
:
Double
)
{
val
MU
=
100000
var
minLat
=
Math
.
min
(
lat1
,
lat2
).
times
(
MU
).
toInt
()
-
100
var
maxLat
=
Math
.
max
(
lat1
,
lat2
).
times
(
MU
).
toInt
()
+
100
var
minLon
=
Math
.
min
(
lon1
,
lon2
).
times
(
MU
).
toInt
()
-
10
var
maxLon
=
Math
.
max
(
lon1
,
lon2
).
times
(
MU
).
toInt
()
+
10
var
rect
=
Rect
(
minLon
,
minLat
,
maxLon
,
maxLat
)
mMineMap
?.
fitWorldArea
(
rect
)
}
//召车 航向角 238.38134765625
fun
onVehicleMockCall
(
carVehicle
:
MutableStateFlow
<
CarVehicle
>,
targetPre
:
MutableLiveData
<
PerceptionBean
>?
)
{
viewModelScope
.
launch
{
//初始镜头角度
HighMapApi
.
setCameraAngle
(
90f
)
HighMapApi
.
setCameraDistance
(
20f
)
delay
(
3000
)
//2旁车辆占用
var
spinfos
=
listOf
(
Spinfo
().
apply
{
code
=
"B016"
state
=
true
},
Spinfo
().
apply
{
code
=
"B018"
state
=
true
})
HighMapApi
.
setParkStatu
(
ParkStatu
(
spinfos
))
var
cCar
:
CarVehicle
var
gson
=
Gson
()
//画局部图小车
drawNavingCar
(
Tools
.
latLngToPoint
(
LatLng
(
39.8090317
,
116.5024625
)))
//画终点
addEndMarker
(
LatLng
(
39.809955271
,
116.50204936
))
//用矩形框柱
drawEndArea
(
39.8090317
,
116.5024625
,
39.809955271625505
,
116.50204936866068
)
//挂前进挡
CarPanelBean
.
instance
.
tapPos
.
set
(
2
)
var
str
=
FileIoUtils
.
getAsset
(
context
,
"mock/Car_fangzhen_call.txt"
)
val
mRoutes
=
gson
.
fromJson
<
MRoutes
>(
str
,
MRoutes
::
class
.
java
)
//生成局部图路径
smallLineMock
(
mRoutes
)
//画出全局路径
var
lines
=
mRoutes
.
rs
.
map
{
AllLine
(
it
[
1
],
it
[
0
])
}
HighMapApi
.
setCarNavPath
(
lines
,
showdistance
=
200
)
//模拟车辆移动
var
head
=
0.0
var
oldHead
=
0.0
var
bearing
=
0.0
val
random
=
Random
mRoutes
.
rs
.
forEachIndexed
{
index
,
it
->
if
(
index
==
1
)
{
delay
(
5000
)
//开始跟车
HighMapApi
.
setCameraAngle
(
30f
)
HighMapApi
.
setCameraDistance
(
8f
)
}
if
(
index
<=
139
)
{
//正在小心翼翼的出库
CarPanelBean
.
instance
.
speed
.
set
(
random
.
nextInt
(
1
..
5
))
}
else
{
//开起来了
CarPanelBean
.
instance
.
speed
.
set
(
random
.
nextInt
(
10
..
16
))
}
if
(
index
>
0
&&
index
<
mRoutes
.
rs
.
count
())
{
var
p1
=
mRoutes
.
rs
.
get
(
index
-
1
)
var
pc
=
mRoutes
.
rs
.
get
(
index
)
// head = BasicTools.calculateBearing(p1[0],p1[1], pc[1], pc[0])
head
=
MyMapUtils
.
calculateBearing
(
LatLng
(
p1
[
1
],
p1
[
0
]),
LatLng
(
pc
[
1
],
pc
[
0
])
)
// bearing = head
// println("-------- head = ${head} oldHead = ${oldHead} ${(head - oldHead).absoluteValue.toInt()}")
if
(
oldHead
!=
0.0
&&
(
head
-
oldHead
).
absoluteValue
.
toInt
()
<
45
)
{
bearing
=
head
}
cCar
=
CarVehicle
().
apply
{
this
.
vehiclePos
=
listOf
(
it
[
0
],
it
[
1
],
bearing
)
}
oldHead
=
head
//更新主车位置
carVehicle
.
value
=
cCar
//更新小地图小车
showNavingCarPosition
(
Tools
.
latLngToNdsPoint
(
LatLng
(
cCar
.
vehiclePos
!!
.
get
(
1
),
cCar
.
vehiclePos
!!
.
get
(
0
)
)
),
cCar
.
vehiclePos
!!
.
get
(
2
).
toFloat
()
)
//更新小地图路径
upSmallLine
(
index
,
mRoutes
)
}
//用矩形框柱
// drawEndArea(
// it[1], it[0],
// 39.809955271,
// 116.50204936
// )
delay
(
200
)
}
//消除全局路径
HighMapApi
.
setCarNavPath
(
listOf
())
//删除终点mark
deleteEndMarker
()
//挂N档等人
CarPanelBean
.
instance
.
tapPos
.
set
(
0
)
CarPanelBean
.
instance
.
speed
.
set
(
0
)
ToastHelper
.
showShort
(
context
,
"召车完成"
)
//上人
/* val parts = mutableListOf<String>()
FileIoUtils.getAssetMock(context, "mock/call_shangren.txt", parts)
parts.forEach { str ->
if (str.isNotEmpty()) {
var bean = parseDataBean(str, PerceptionBean::class.java)
if (bean != null) {
targetPre?.value = bean
delay(500)
}
}
}
HighMapApi.clearPtcData()*/
}
}
/***跑服务器的模拟数据**/
fun
subVehicle
(
carLiveData
:
MutableStateFlow
<
CarVehicle
>
)
{
viewModelScope
.
launch
{
var
gson
=
Gson
()
var
datas
=
mutableListOf
<
String
>()
FileIoUtils
.
getAssetMock
(
context
,
"mock/shiche/CarVehicle_park.txt"
,
datas
)
var
temp
=
""
datas
.
forEach
{
str
->
try
{
temp
=
str
val
cCar
=
gson
.
fromJson
<
CarVehicle
>(
str
,
CarVehicle
::
class
.
java
)
if
(
cCar
!=
null
||
cCar
?.
vehiclePos
!=
null
)
{
// carLiveData.postValue(cCar)
carLiveData
.
value
=
cCar
delay
(
100
)
}
}
catch
(
e
:
JsonSyntaxException
)
{
e
.
printStackTrace
()
}
}
}
}
var
sPolyline
:
Polyline
?
=
null
//点坐标集合
var
sLatLngs
:
List
<
LatLng
>?
=
null
//模拟小地图路径
private
fun
smallLineMock
(
mRoutes
:
MRoutes
)
{
sLatLngs
=
mRoutes
.
rs
.
map
{
LatLng
(
it
[
1
],
it
[
0
])
}
}
//更新小地图路径
private
fun
upSmallLine
(
index
:
Int
,
mRoutes
:
MRoutes
)
{
if
(
sPolyline
!=
null
)
{
mMineMap
?.
removeOverlay
(
sPolyline
)
sPolyline
?.
release
()
}
var
temps
=
sLatLngs
?.
subList
(
index
,
sLatLngs
!!
.
count
())
var
nPoints
=
temps
?.
map
{
Tools
.
latLngToNdsPoint
(
it
)
}
?.
toTypedArray
()
synchronized
(
NativeEnv
.
SyncObject
)
{
sPolyline
=
Polyline
(
nPoints
,
false
)
sPolyline
?.
setStrokeStyle
(
Overlay
.
StrokeStyle
.
solidWithButt
)
sPolyline
?.
setWidth
(
8f
)
sPolyline
?.
setColor
(
0xFF00B578
.
toInt
())
mMineMap
?.
addOverlay
(
sPolyline
)
}
}
//路径规划终点
private
var
pEndMarker
:
Marker
?
=
null
/**画路径起终点***/
fun
addEndMarker
(
mEndPoint
:
LatLng
)
{
//删除终点marker
deleteEndMarker
()
val
end_icon
=
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
drawable
.
plan_end
)
// var endlatLng = Tools.pointToLatLng(mEndPoint)
pEndMarker
=
mMineMap
?.
addMarker
(
MarkerOptions
().
zLevel
(
7
).
position
(
mEndPoint
).
bitmap
(
end_icon
)
)
}
private
var
mSmallMapCar
:
MyLocationStyle
?
=
null
//画小地图小车
fun
drawNavingCar
(
point
:
Point
)
{
if
(
mSmallMapCar
==
null
)
{
// mSmallMapCar = MyLocationStyle(R.drawable.angle_blue, true)
mSmallMapCar
=
MyLocationStyle
(
"res/icons/carIconInSmallMap.png"
,
true
)
mSmallMapCar
?.
myLocationType
(
MyLocationStyle
.
LOCATION_TYPE_EXTERNAL
)
val
scaleFactor
=
-
Math
.
round
(((
10
*
NativeEnv
.
getDpi
()
*
2
)
*
10
/
(
160
*
48
)).
toFloat
())
.
toFloat
()
/
10
mSmallMapCar
?.
scaleFactor
(
scaleFactor
)
mSmallMapCar
?.
anchor
(
0.5f
,
0.5f
)
mSmallMapCar
?.
setPosition
(
point
)
mMineMap
?.
setMyLocationStyle
(
mSmallMapCar
)
}
}
/**
* 刷新导航中的自车位置
*/
fun
showNavingCarPosition
(
ndsPoint
:
NdsPoint
?,
heading
:
Float
)
{
synchronized
(
NativeEnv
.
SyncObject
)
{
if
(
ndsPoint
==
null
)
{
return
}
//刷新小地图自车位置
if
(
mSmallMapCar
!=
null
)
{
var
cHeading
=
0f
-
180f
-
heading
mSmallMapCar
!!
.
orientAngle
(
cHeading
)
// mSmallMapCar!!.orientAngle(heading)
mSmallMapCar
!!
.
setPositionNds
(
Tools
.
ndsPointToLatLng
(
ndsPoint
))
}
}
}
/**
* 移除导航小车
*/
fun
deleteNavingCar
()
{
if
(
mMineMap
!=
null
&&
mSmallMapCar
!=
null
)
{
mMineMap
?.
removeOverlay
(
mSmallMapCar
)
mSmallMapCar
!!
.
release
()
mSmallMapCar
=
null
}
}
private
fun
deleteEndMarker
()
{
if
(
pEndMarker
!=
null
)
{
mMineMap
?.
removeMarker
(
pEndMarker
)
pEndMarker
=
null
}
}
//感知目标物
fun
onSubTargetMock
(
targetPre
:
MutableLiveData
<
PerceptionBean
>)
{
viewModelScope
.
launch
{
val
parts
=
mutableListOf
<
String
>()
FileIoUtils
.
getAssetMock
(
context
,
"mock/PerTarget.txt"
,
parts
)
var
temp
=
""
parts
.
forEach
{
str
->
if
(!
str
.
isNullOrEmpty
())
{
temp
=
str
var
bean
=
parseDataBean
(
str
,
PerceptionBean
::
class
.
java
)
// var bean = gson.fromJson<PerceptionBean>(str, PerceptionBean::class.java)
if
(
bean
!=
null
)
{
targetPre
.
value
=
bean
delay
(
4500
)
}
}
}
}
}
//v2预警
fun
onV2xMock
(
targetPre
:
MutableLiveData
<
V2xStartBean
>)
{
viewModelScope
.
launch
{
val
parts
=
mutableListOf
<
String
>()
FileIoUtils
.
getAssetMock
(
context
,
"mock/avp_v2x.txt"
,
parts
)
parts
.
forEach
{
str
->
var
bean
=
parseDataBean
(
str
,
V2xStartBean
::
class
.
java
)
if
(
bean
!=
null
)
{
targetPre
.
value
=
bean
delay
(
2000
)
}
}
}
}
//全局路径发生切换
fun
onSubLinePlaningMock
()
{
// viewModelScope.launch {
// val alls = mutableListOf<String>()
// FileIoUtils.getAssetMock(context, "mock/all_line.txt", alls)
// alls.forEach { str ->
// delay(1000)
// var bean = parseSocketRepo.parseDataBean(str, AllLinePlaningBean::class.java)
// allLine.value = bean
// }
// }
}
//模拟Http获取全局路径
/* suspend fun getLinePlaningMock(vehiclePlate: String): MyResult<ParkLinePlan> {
return withContext(Dispatchers.IO) {
val str = FileIoUtils.getAssetContent(context, "find_line.txt")
val bean =gson.fromJson(str,ParkLinePlan::class.java)
return@withContext MyResult.Success(bean)
}
}*/
//局部路径
fun
onSubPartLineMock
()
{
// viewModelScope.launch {
// val lines = mutableListOf<String>()
// lines.forEach { str ->
// delay(1000)
// var bean = parseSocketRepo.parseDataBean(str, PartLineBean::class.java)
// allLine.value = bean
// }
// }
}
//更新停车位
fun
onPointsMock
()
{
// viewModelScope.launch {
// val points = mutableListOf<String>()
// FileIoUtils.getAssetMock(context, "mock/change_park.txt", points)
// points.forEach { str ->
// delay(1000)
// var bean = parseSocketRepo.parseDataBean(str, ParkBean::class.java)
// println("------模拟停车位变更 = ${bean}")
// parkBean.value = bean
// }
// }
}
fun
subAvpStatus
(
avp
:
MutableSharedFlow
<
AvpStatuBean
>)
{
viewModelScope
.
launch
{
var
gson
=
Gson
()
var
datas
=
mutableListOf
<
String
>()
FileIoUtils
.
getAssetMock
(
context
,
"mock/shiche/avp_status_park.txt"
,
datas
)
datas
.
forEach
{
val
statu
=
gson
.
fromJson
<
AvpStatuBean
>(
it
,
AvpStatuBean
::
class
.
java
)
if
(
statu
!=
null
)
{
avp
.
emit
(
statu
)
delay
(
2000
)
}
}
/* var str = datas.first()
val statu = gson.fromJson<AvpStatuBean>(str, AvpStatuBean::class.java)
for (i in 0..10000) {
flow.postValue(statu)
delay(3000)
}*/
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/viewmodels/UnityMapVm.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.viewmodels
import
android.content.Context
import
androidx.lifecycle.ViewModel
import
com.sd.cavphmi.highmap.HighMapApi
import
com.sd.cavphmi.highmap.TileJsonBean
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
javax.inject.Inject
@HiltViewModel
class
UnityMapVm
@Inject
constructor
(
@ApplicationContext
var
context
:
Context
)
:
ViewModel
()
{
/**给unity读取3d tile json配置***/
fun
loadTileJson
()
{
var
tileJsonBean
=
TileJsonBean
()
HighMapApi
.
setTileInit
(
tileJsonBean
)
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/BaseWsClient.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.websockets
import
com.sd.cavphmi.utils.MyContants
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.drafts.Draft
import
java.net.Socket
import
java.net.URI
import
java.security.SecureRandom
import
java.security.cert.X509Certificate
import
javax.net.ssl.SSLContext
import
javax.net.ssl.SSLEngine
import
javax.net.ssl.SSLSocketFactory
import
javax.net.ssl.TrustManager
import
javax.net.ssl.X509ExtendedTrustManager
abstract
class
BaseWsClient
:
WebSocketClient
{
constructor
(
serverUri
:
URI
)
:
super
(
serverUri
)
{
if
(
serverUri
.
toString
().
contains
(
"wss://"
))
{
trustAllHosts
()
}
// if (MyContants.HTTP_TOKEN.isNotEmpty()){
// serverUri.
// }
}
constructor
(
serverUri
:
URI
?,
protocolDraft
:
Draft
?)
:
super
(
serverUri
,
protocolDraft
)
constructor
(
serverUri
:
URI
?,
httpHeaders
:
MutableMap
<
String
,
String
>?)
:
super
(
serverUri
,
httpHeaders
)
private
fun
trustAllHosts
()
{
val
trustAllCerts
=
arrayOf
<
TrustManager
>(
object
:
X509ExtendedTrustManager
()
{
override
fun
checkClientTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
socket
:
Socket
?
)
{
}
override
fun
checkServerTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
socket
:
Socket
?
)
{
}
override
fun
checkClientTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
engine
:
SSLEngine
?
)
{
}
override
fun
checkServerTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
engine
:
SSLEngine
?
)
{
}
override
fun
checkClientTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?
)
{
}
override
fun
checkServerTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?
)
{
}
override
fun
getAcceptedIssuers
():
Array
<
out
X509Certificate
?
>?
{
return
null
}
})
try
{
val
ssl
=
SSLContext
.
getInstance
(
"SSL"
)
ssl
.
init
(
null
,
trustAllCerts
,
SecureRandom
())
val
socketFactory
:
SSLSocketFactory
?
=
ssl
.
getSocketFactory
()
this
.
setSocketFactory
(
socketFactory
)
}
catch
(
e
:
java
.
lang
.
Exception
)
{
e
.
printStackTrace
()
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/FeelTargetWSClient.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.websockets
import
com.sd.cavphmi.intfaces.OnWebSocketCb
import
org.java_websocket.handshake.ServerHandshake
import
java.net.URI
import
java.nio.ByteBuffer
/*****感知目标物**/
class
FeelTargetWSClient
:
BaseWsClient
{
private
val
TAG
=
"-----FeelTargetWSClient 感知目标物"
constructor
(
serverUri
:
URI
)
:
super
(
serverUri
){
var
a
=
0
// if(serverUri.toString().contains("wss://")){
// trustAllHosts()
// }
}
// constructor(serverUri: URI?, protocolDraft: Draft?) : super(serverUri, protocolDraft)
//
// constructor(serverUri: URI?, httpHeaders: MutableMap<String, String>?) : super(
// serverUri,
// httpHeaders
// )
var
onWebSocketCb
:
OnWebSocketCb
?
=
null
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
println
(
TAG
+
"-------openg "
+
uri
.
toString
())
// System.out.println(TAG + "new connection opened")
}
override
fun
onMessage
(
message
:
String
?)
{
// println(TAG + " : " + message)
if
(
message
.
isNullOrEmpty
())
return
onWebSocketCb
?.
onMsg
(
message
)
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
// System.out.println(TAG + " received ByteBuffer")
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
System
.
out
.
println
(
TAG
+
" closed with exit code "
+
code
+
" additional info: "
+
reason
);
onWebSocketCb
?.
onClose
(
code
,
reason
,
remote
)
}
override
fun
onError
(
ex
:
Exception
?)
{
System
.
err
.
println
(
TAG
+
"an error occurred:"
+
ex
)
}
// var onDataCb: OnDataCb? = null
//
// interface OnDataCb {
// fun onMsg(str: String)
// }
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/MyWebSocketClient.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.websockets
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.drafts.Draft
import
org.java_websocket.handshake.ServerHandshake
import
protocol.Response
import
java.net.URI
import
java.nio.ByteBuffer
class
MyWebSocketClient
:
WebSocketClient
{
val
TAG
=
"-----MyWebSocketClient"
constructor
(
serverUri
:
URI
?)
:
super
(
serverUri
)
constructor
(
serverUri
:
URI
?,
protocolDraft
:
Draft
?)
:
super
(
serverUri
,
protocolDraft
)
constructor
(
serverUri
:
URI
?,
httpHeaders
:
MutableMap
<
String
,
String
>?)
:
super
(
serverUri
,
httpHeaders
)
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
// send("Hello, it is me. Mario :)")
System
.
out
.
println
(
TAG
+
"new connection opened"
)
onSocketCb
?.
onOpen
(
handshakedata
)
}
override
fun
onMessage
(
message
:
String
?)
{
// System.out.println(TAG + "received message: " + message);
// onSocketCb?.onMessage(message)
//处理各种推送消息
// let data = {};
// let result = await decodeResponseProtoBuf(msg);
// // console.log(result);
//
// // 抹平与之前推送数据接口的差异
// data.body = result.data;
// const eventName = this.dic[result.msgType].action;
//
// //执行回调
// // this.messageList[eventName](data);
// if (this.messageList[eventName]) {
// //执行回调
// this.messageList[eventName](data);
// }
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
// System.out.println(TAG + " received ByteBuffer")
val
socketResponse
=
Response
.
SocketResponse
.
parseFrom
(
bytes
)
when
(
socketResponse
.
msgType
)
{
5231
->
{
//车辆位姿数据
onDataCb
?.
onVehicle
(
socketResponse
)
}
5232
->
{
//感知目标物数据
onDataCb
?.
onTarget
(
socketResponse
)
}
5234
->
{
//V2X预警开始
onDataCb
?.
onStartV2x
(
socketResponse
)
}
5235
->
{
//V2X预警结束
onDataCb
?.
onEndV2x
(
socketResponse
)
}
5236
->
{
//联网车辆状态数据
onDataCb
?.
onVehicleStats
(
socketResponse
)
}
1
->
{
//停车位变更
onDataCb
?.
onPoint
(
socketResponse
)
}
52310
->
{
//全局路径发生切换
onDataCb
?.
onLinePlaning
(
socketResponse
)
}
52311
->
{
//局部路径
onDataCb
?.
onPartLine
(
socketResponse
)
}
52312
->
{
//rsi事件
onDataCb
?.
onRsiEvent
(
socketResponse
)
}
}
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
System
.
out
.
println
(
TAG
+
" closed with exit code "
+
code
+
" additional info: "
+
reason
);
onSocketCb
?.
onClose
(
code
,
reason
,
remote
)
}
override
fun
onError
(
ex
:
Exception
?)
{
System
.
err
.
println
(
TAG
+
"an error occurred:"
+
ex
);
onSocketCb
?.
onError
(
ex
)
}
var
onSocketCb
:
OnSocketCb
?
=
null
interface
OnSocketCb
{
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
// fun onMessage(message: String?)
// fun onMessage(socketResponse: Response.SocketResponse)
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
fun
onError
(
ex
:
Exception
?)
}
var
onDataCb
:
OnDataCb
?
=
null
interface
OnDataCb
{
fun
onVehicle
(
res
:
Response
.
SocketResponse
)
fun
onVehicleStats
(
res
:
Response
.
SocketResponse
)
fun
onTarget
(
res
:
Response
.
SocketResponse
)
fun
onStartV2x
(
res
:
Response
.
SocketResponse
)
fun
onEndV2x
(
res
:
Response
.
SocketResponse
)
/***停车位变更***/
fun
onPoint
(
res
:
Response
.
SocketResponse
)
fun
onLinePlaning
(
res
:
Response
.
SocketResponse
)
fun
onPartLine
(
res
:
Response
.
SocketResponse
)
fun
onRsiEvent
(
res
:
Response
.
SocketResponse
)
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/V2xWSClient.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.websockets
import
com.sd.cavphmi.intfaces.OnWebSocketCb
import
org.java_websocket.handshake.ServerHandshake
import
java.net.URI
import
java.nio.ByteBuffer
/*****v2x预警**/
class
V2xWSClient
:
BaseWsClient
{
private
val
TAG
=
"-----V2xWSClient"
constructor
(
serverUri
:
URI
)
:
super
(
serverUri
)
//
// constructor(serverUri: URI?, protocolDraft: Draft?) : super(serverUri, protocolDraft)
//
// constructor(serverUri: URI?, httpHeaders: MutableMap<String, String>?) : super(
// serverUri,
// httpHeaders
// )
var
onWebSocketCb
:
OnWebSocketCb
?
=
null
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
// send("Hello, it is me. Mario :)")
println
(
TAG
+
"------v2x预警 "
+
uri
.
toString
())
}
override
fun
onMessage
(
message
:
String
?)
{
println
(
TAG
+
" : "
+
message
)
if
(
message
.
isNullOrEmpty
())
return
onWebSocketCb
?.
onMsg
(
message
)
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
// System.out.println(TAG + " received ByteBuffer")
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
System
.
out
.
println
(
TAG
+
" closed with exit code "
+
code
+
" additional info: "
+
reason
);
}
override
fun
onError
(
ex
:
Exception
?)
{
// System.err.println(TAG + "an error occurred:" + ex)
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/VecLocWSClient.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.websockets
import
com.sd.cavphmi.intfaces.OnWebSocketCb
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.drafts.Draft
import
org.java_websocket.handshake.ServerHandshake
import
java.net.Socket
import
java.net.URI
import
java.nio.ByteBuffer
import
java.security.SecureRandom
import
java.security.cert.X509Certificate
import
javax.net.ssl.SSLContext
import
javax.net.ssl.SSLEngine
import
javax.net.ssl.SSLSocketFactory
import
javax.net.ssl.TrustManager
import
javax.net.ssl.X509ExtendedTrustManager
/*****网联车辆位姿**/
class
VecLocWSClient
:
BaseWsClient
{
private
val
TAG
=
"-----VecLocWSClient"
constructor
(
serverUri
:
URI
)
:
super
(
serverUri
)
{
// if (serverUri.toString().contains("wss://")) {
// trustAllHosts()
// }
}
// constructor(serverUri: URI?, protocolDraft: Draft?) : super(serverUri, protocolDraft)
//
// constructor(serverUri: URI?, httpHeaders: MutableMap<String, String>?) : super(
// serverUri,
// httpHeaders
// )
var
onWebSocketCb
:
OnWebSocketCb
?
=
null
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
System
.
out
.
println
(
TAG
+
"网联车辆位姿 opened "
+
uri
.
toString
())
}
override
fun
onMessage
(
message
:
String
?)
{
// System.out.println(TAG + " : " + message)
if
(
message
.
isNullOrEmpty
())
return
onWebSocketCb
?.
onMsg
(
message
)
// onSocketCb?.onMessage(message)
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
// System.out.println(TAG + " received ByteBuffer")
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
System
.
out
.
println
(
TAG
+
" closed with exit code "
+
code
+
" additional info: "
+
reason
);
}
override
fun
onError
(
ex
:
Exception
?)
{
System
.
err
.
println
(
TAG
+
"an error occurred:"
+
ex
)
}
// var onDataCb: OnDataCb? = null
// interface OnDataCb {
// fun onMsg(str: String)
// }
private
fun
trustAllHosts
()
{
val
trustAllCerts
=
arrayOf
<
TrustManager
>(
object
:
X509ExtendedTrustManager
()
{
override
fun
checkClientTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
socket
:
Socket
?
)
{
}
override
fun
checkServerTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
socket
:
Socket
?
)
{
}
override
fun
checkClientTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
engine
:
SSLEngine
?
)
{
}
override
fun
checkServerTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?,
engine
:
SSLEngine
?
)
{
}
override
fun
checkClientTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?
)
{
}
override
fun
checkServerTrusted
(
chain
:
Array
<
out
X509Certificate
?
>?,
authType
:
String
?
)
{
}
override
fun
getAcceptedIssuers
():
Array
<
out
X509Certificate
?
>?
{
return
null
}
})
try
{
val
ssl
=
SSLContext
.
getInstance
(
"SSL"
)
ssl
.
init
(
null
,
trustAllCerts
,
SecureRandom
())
val
socketFactory
:
SSLSocketFactory
?
=
ssl
.
getSocketFactory
()
this
.
setSocketFactory
(
socketFactory
)
}
catch
(
e
:
java
.
lang
.
Exception
)
{
e
.
printStackTrace
()
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/VehStatuWSClient.kt
0 → 100644
View file @
c0af16dd
package
com.sd.cavphmi.websockets
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.drafts.Draft
import
org.java_websocket.handshake.ServerHandshake
import
java.net.URI
import
java.nio.ByteBuffer
/*****网联车辆状态
* 只有发生变化的数据才推送
* 只用管(在线和离线状态即可)
* **/
class
VehStatuWSClient
:
WebSocketClient
{
private
val
TAG
=
"-----VehStatuWSClient"
constructor
(
serverUri
:
URI
)
:
super
(
serverUri
)
constructor
(
serverUri
:
URI
?,
protocolDraft
:
Draft
?)
:
super
(
serverUri
,
protocolDraft
)
constructor
(
serverUri
:
URI
?,
httpHeaders
:
MutableMap
<
String
,
String
>?)
:
super
(
serverUri
,
httpHeaders
)
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
// send("Hello, it is me. Mario :)")
System
.
out
.
println
(
TAG
+
" ------------Hello 网联车辆状态"
)
}
override
fun
onMessage
(
message
:
String
?)
{
println
(
TAG
+
" : "
+
message
)
if
(
message
.
isNullOrEmpty
())
return
onDataCb
?.
onMsg
(
message
)
// onSocketCb?.onMessage(message)
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
System
.
out
.
println
(
TAG
+
" received ByteBuffer"
)
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
System
.
out
.
println
(
TAG
+
" closed with exit code "
+
code
+
" additional info: "
+
reason
);
}
override
fun
onError
(
ex
:
Exception
?)
{
System
.
err
.
println
(
TAG
+
"an error occurred:"
+
ex
)
}
var
onDataCb
:
OnDataCb
?
=
null
interface
OnDataCb
{
fun
onMsg
(
str
:
String
)
}
}
\ No newline at end of file
app/src/main/java/protocol/Response.java
0 → 100644
View file @
c0af16dd
// Generated by the protocol buffer compiler. DO NOT EDIT!
// NO CHECKED-IN PROTOBUF GENCODE
// source: response.proto
// Protobuf Java Version: 4.31.1
package
protocol
;
@com
.
google
.
protobuf
.
Generated
public
final
class
Response
{
private
Response
()
{}
static
{
com
.
google
.
protobuf
.
RuntimeVersion
.
validateProtobufGencodeVersion
(
com
.
google
.
protobuf
.
RuntimeVersion
.
RuntimeDomain
.
PUBLIC
,
/* major= */
4
,
/* minor= */
31
,
/* patch= */
1
,
/* suffix= */
""
,
Response
.
class
.
getName
());
}
public
static
void
registerAllExtensions
(
com
.
google
.
protobuf
.
ExtensionRegistryLite
registry
)
{
}
public
static
void
registerAllExtensions
(
com
.
google
.
protobuf
.
ExtensionRegistry
registry
)
{
registerAllExtensions
(
(
com
.
google
.
protobuf
.
ExtensionRegistryLite
)
registry
);
}
public
interface
SocketResponseOrBuilder
extends
// @@protoc_insertion_point(interface_extends:protocol.SocketResponse)
com
.
google
.
protobuf
.
MessageOrBuilder
{
/**
* <code>int32 code = 1;</code>
* @return The code.
*/
int
getCode
();
/**
* <code>string msg = 2;</code>
* @return The msg.
*/
java
.
lang
.
String
getMsg
();
/**
* <code>string msg = 2;</code>
* @return The bytes for msg.
*/
com
.
google
.
protobuf
.
ByteString
getMsgBytes
();
/**
* <pre>
* </pre>
*
* <code>int32 msgType = 3;</code>
* @return The msgType.
*/
int
getMsgType
();
/**
* <code>string data = 4;</code>
* @return The data.
*/
java
.
lang
.
String
getData
();
/**
* <code>string data = 4;</code>
* @return The bytes for data.
*/
com
.
google
.
protobuf
.
ByteString
getDataBytes
();
}
/**
* Protobuf type {@code protocol.SocketResponse}
*/
public
static
final
class
SocketResponse
extends
com
.
google
.
protobuf
.
GeneratedMessage
implements
// @@protoc_insertion_point(message_implements:protocol.SocketResponse)
SocketResponseOrBuilder
{
private
static
final
long
serialVersionUID
=
0L
;
static
{
com
.
google
.
protobuf
.
RuntimeVersion
.
validateProtobufGencodeVersion
(
com
.
google
.
protobuf
.
RuntimeVersion
.
RuntimeDomain
.
PUBLIC
,
/* major= */
4
,
/* minor= */
31
,
/* patch= */
1
,
/* suffix= */
""
,
SocketResponse
.
class
.
getName
());
}
// Use SocketResponse.newBuilder() to construct.
private
SocketResponse
(
com
.
google
.
protobuf
.
GeneratedMessage
.
Builder
<?>
builder
)
{
super
(
builder
);
}
private
SocketResponse
()
{
msg_
=
""
;
data_
=
""
;
}
public
static
final
com
.
google
.
protobuf
.
Descriptors
.
Descriptor
getDescriptor
()
{
return
protocol
.
Response
.
internal_static_protocol_SocketResponse_descriptor
;
}
@java
.
lang
.
Override
protected
com
.
google
.
protobuf
.
GeneratedMessage
.
FieldAccessorTable
internalGetFieldAccessorTable
()
{
return
protocol
.
Response
.
internal_static_protocol_SocketResponse_fieldAccessorTable
.
ensureFieldAccessorsInitialized
(
protocol
.
Response
.
SocketResponse
.
class
,
protocol
.
Response
.
SocketResponse
.
Builder
.
class
);
}
public
static
final
int
CODE_FIELD_NUMBER
=
1
;
private
int
code_
=
0
;
/**
* <code>int32 code = 1;</code>
* @return The code.
*/
@java
.
lang
.
Override
public
int
getCode
()
{
return
code_
;
}
public
static
final
int
MSG_FIELD_NUMBER
=
2
;
@SuppressWarnings
(
"serial"
)
private
volatile
java
.
lang
.
Object
msg_
=
""
;
/**
* <code>string msg = 2;</code>
* @return The msg.
*/
@java
.
lang
.
Override
public
java
.
lang
.
String
getMsg
()
{
java
.
lang
.
Object
ref
=
msg_
;
if
(
ref
instanceof
java
.
lang
.
String
)
{
return
(
java
.
lang
.
String
)
ref
;
}
else
{
com
.
google
.
protobuf
.
ByteString
bs
=
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
java
.
lang
.
String
s
=
bs
.
toStringUtf8
();
msg_
=
s
;
return
s
;
}
}
/**
* <code>string msg = 2;</code>
* @return The bytes for msg.
*/
@java
.
lang
.
Override
public
com
.
google
.
protobuf
.
ByteString
getMsgBytes
()
{
java
.
lang
.
Object
ref
=
msg_
;
if
(
ref
instanceof
java
.
lang
.
String
)
{
com
.
google
.
protobuf
.
ByteString
b
=
com
.
google
.
protobuf
.
ByteString
.
copyFromUtf8
(
(
java
.
lang
.
String
)
ref
);
msg_
=
b
;
return
b
;
}
else
{
return
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
}
}
public
static
final
int
MSGTYPE_FIELD_NUMBER
=
3
;
private
int
msgType_
=
0
;
/**
* <pre>
* </pre>
*
* <code>int32 msgType = 3;</code>
* @return The msgType.
*/
@java
.
lang
.
Override
public
int
getMsgType
()
{
return
msgType_
;
}
public
static
final
int
DATA_FIELD_NUMBER
=
4
;
@SuppressWarnings
(
"serial"
)
private
volatile
java
.
lang
.
Object
data_
=
""
;
/**
* <code>string data = 4;</code>
* @return The data.
*/
@java
.
lang
.
Override
public
java
.
lang
.
String
getData
()
{
java
.
lang
.
Object
ref
=
data_
;
if
(
ref
instanceof
java
.
lang
.
String
)
{
return
(
java
.
lang
.
String
)
ref
;
}
else
{
com
.
google
.
protobuf
.
ByteString
bs
=
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
java
.
lang
.
String
s
=
bs
.
toStringUtf8
();
data_
=
s
;
return
s
;
}
}
/**
* <code>string data = 4;</code>
* @return The bytes for data.
*/
@java
.
lang
.
Override
public
com
.
google
.
protobuf
.
ByteString
getDataBytes
()
{
java
.
lang
.
Object
ref
=
data_
;
if
(
ref
instanceof
java
.
lang
.
String
)
{
com
.
google
.
protobuf
.
ByteString
b
=
com
.
google
.
protobuf
.
ByteString
.
copyFromUtf8
(
(
java
.
lang
.
String
)
ref
);
data_
=
b
;
return
b
;
}
else
{
return
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
}
}
private
byte
memoizedIsInitialized
=
-
1
;
@java
.
lang
.
Override
public
final
boolean
isInitialized
()
{
byte
isInitialized
=
memoizedIsInitialized
;
if
(
isInitialized
==
1
)
return
true
;
if
(
isInitialized
==
0
)
return
false
;
memoizedIsInitialized
=
1
;
return
true
;
}
@java
.
lang
.
Override
public
void
writeTo
(
com
.
google
.
protobuf
.
CodedOutputStream
output
)
throws
java
.
io
.
IOException
{
if
(
code_
!=
0
)
{
output
.
writeInt32
(
1
,
code_
);
}
if
(!
com
.
google
.
protobuf
.
GeneratedMessage
.
isStringEmpty
(
msg_
))
{
com
.
google
.
protobuf
.
GeneratedMessage
.
writeString
(
output
,
2
,
msg_
);
}
if
(
msgType_
!=
0
)
{
output
.
writeInt32
(
3
,
msgType_
);
}
if
(!
com
.
google
.
protobuf
.
GeneratedMessage
.
isStringEmpty
(
data_
))
{
com
.
google
.
protobuf
.
GeneratedMessage
.
writeString
(
output
,
4
,
data_
);
}
getUnknownFields
().
writeTo
(
output
);
}
@java
.
lang
.
Override
public
int
getSerializedSize
()
{
int
size
=
memoizedSize
;
if
(
size
!=
-
1
)
return
size
;
size
=
0
;
if
(
code_
!=
0
)
{
size
+=
com
.
google
.
protobuf
.
CodedOutputStream
.
computeInt32Size
(
1
,
code_
);
}
if
(!
com
.
google
.
protobuf
.
GeneratedMessage
.
isStringEmpty
(
msg_
))
{
size
+=
com
.
google
.
protobuf
.
GeneratedMessage
.
computeStringSize
(
2
,
msg_
);
}
if
(
msgType_
!=
0
)
{
size
+=
com
.
google
.
protobuf
.
CodedOutputStream
.
computeInt32Size
(
3
,
msgType_
);
}
if
(!
com
.
google
.
protobuf
.
GeneratedMessage
.
isStringEmpty
(
data_
))
{
size
+=
com
.
google
.
protobuf
.
GeneratedMessage
.
computeStringSize
(
4
,
data_
);
}
size
+=
getUnknownFields
().
getSerializedSize
();
memoizedSize
=
size
;
return
size
;
}
@java
.
lang
.
Override
public
boolean
equals
(
final
java
.
lang
.
Object
obj
)
{
if
(
obj
==
this
)
{
return
true
;
}
if
(!(
obj
instanceof
protocol
.
Response
.
SocketResponse
))
{
return
super
.
equals
(
obj
);
}
protocol
.
Response
.
SocketResponse
other
=
(
protocol
.
Response
.
SocketResponse
)
obj
;
if
(
getCode
()
!=
other
.
getCode
())
return
false
;
if
(!
getMsg
()
.
equals
(
other
.
getMsg
()))
return
false
;
if
(
getMsgType
()
!=
other
.
getMsgType
())
return
false
;
if
(!
getData
()
.
equals
(
other
.
getData
()))
return
false
;
if
(!
getUnknownFields
().
equals
(
other
.
getUnknownFields
()))
return
false
;
return
true
;
}
@java
.
lang
.
Override
public
int
hashCode
()
{
if
(
memoizedHashCode
!=
0
)
{
return
memoizedHashCode
;
}
int
hash
=
41
;
hash
=
(
19
*
hash
)
+
getDescriptor
().
hashCode
();
hash
=
(
37
*
hash
)
+
CODE_FIELD_NUMBER
;
hash
=
(
53
*
hash
)
+
getCode
();
hash
=
(
37
*
hash
)
+
MSG_FIELD_NUMBER
;
hash
=
(
53
*
hash
)
+
getMsg
().
hashCode
();
hash
=
(
37
*
hash
)
+
MSGTYPE_FIELD_NUMBER
;
hash
=
(
53
*
hash
)
+
getMsgType
();
hash
=
(
37
*
hash
)
+
DATA_FIELD_NUMBER
;
hash
=
(
53
*
hash
)
+
getData
().
hashCode
();
hash
=
(
29
*
hash
)
+
getUnknownFields
().
hashCode
();
memoizedHashCode
=
hash
;
return
hash
;
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
java
.
nio
.
ByteBuffer
data
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
return
PARSER
.
parseFrom
(
data
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
java
.
nio
.
ByteBuffer
data
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
return
PARSER
.
parseFrom
(
data
,
extensionRegistry
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
com
.
google
.
protobuf
.
ByteString
data
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
return
PARSER
.
parseFrom
(
data
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
com
.
google
.
protobuf
.
ByteString
data
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
return
PARSER
.
parseFrom
(
data
,
extensionRegistry
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
byte
[]
data
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
return
PARSER
.
parseFrom
(
data
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
byte
[]
data
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
return
PARSER
.
parseFrom
(
data
,
extensionRegistry
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
java
.
io
.
InputStream
input
)
throws
java
.
io
.
IOException
{
return
com
.
google
.
protobuf
.
GeneratedMessage
.
parseWithIOException
(
PARSER
,
input
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
java
.
io
.
InputStream
input
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
java
.
io
.
IOException
{
return
com
.
google
.
protobuf
.
GeneratedMessage
.
parseWithIOException
(
PARSER
,
input
,
extensionRegistry
);
}
public
static
protocol
.
Response
.
SocketResponse
parseDelimitedFrom
(
java
.
io
.
InputStream
input
)
throws
java
.
io
.
IOException
{
return
com
.
google
.
protobuf
.
GeneratedMessage
.
parseDelimitedWithIOException
(
PARSER
,
input
);
}
public
static
protocol
.
Response
.
SocketResponse
parseDelimitedFrom
(
java
.
io
.
InputStream
input
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
java
.
io
.
IOException
{
return
com
.
google
.
protobuf
.
GeneratedMessage
.
parseDelimitedWithIOException
(
PARSER
,
input
,
extensionRegistry
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
com
.
google
.
protobuf
.
CodedInputStream
input
)
throws
java
.
io
.
IOException
{
return
com
.
google
.
protobuf
.
GeneratedMessage
.
parseWithIOException
(
PARSER
,
input
);
}
public
static
protocol
.
Response
.
SocketResponse
parseFrom
(
com
.
google
.
protobuf
.
CodedInputStream
input
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
java
.
io
.
IOException
{
return
com
.
google
.
protobuf
.
GeneratedMessage
.
parseWithIOException
(
PARSER
,
input
,
extensionRegistry
);
}
@java
.
lang
.
Override
public
Builder
newBuilderForType
()
{
return
newBuilder
();
}
public
static
Builder
newBuilder
()
{
return
DEFAULT_INSTANCE
.
toBuilder
();
}
public
static
Builder
newBuilder
(
protocol
.
Response
.
SocketResponse
prototype
)
{
return
DEFAULT_INSTANCE
.
toBuilder
().
mergeFrom
(
prototype
);
}
@java
.
lang
.
Override
public
Builder
toBuilder
()
{
return
this
==
DEFAULT_INSTANCE
?
new
Builder
()
:
new
Builder
().
mergeFrom
(
this
);
}
@java
.
lang
.
Override
protected
Builder
newBuilderForType
(
com
.
google
.
protobuf
.
GeneratedMessage
.
BuilderParent
parent
)
{
Builder
builder
=
new
Builder
(
parent
);
return
builder
;
}
/**
* Protobuf type {@code protocol.SocketResponse}
*/
public
static
final
class
Builder
extends
com
.
google
.
protobuf
.
GeneratedMessage
.
Builder
<
Builder
>
implements
// @@protoc_insertion_point(builder_implements:protocol.SocketResponse)
protocol
.
Response
.
SocketResponseOrBuilder
{
public
static
final
com
.
google
.
protobuf
.
Descriptors
.
Descriptor
getDescriptor
()
{
return
protocol
.
Response
.
internal_static_protocol_SocketResponse_descriptor
;
}
@java
.
lang
.
Override
protected
com
.
google
.
protobuf
.
GeneratedMessage
.
FieldAccessorTable
internalGetFieldAccessorTable
()
{
return
protocol
.
Response
.
internal_static_protocol_SocketResponse_fieldAccessorTable
.
ensureFieldAccessorsInitialized
(
protocol
.
Response
.
SocketResponse
.
class
,
protocol
.
Response
.
SocketResponse
.
Builder
.
class
);
}
// Construct using protocol.Response.SocketResponse.newBuilder()
private
Builder
()
{
}
private
Builder
(
com
.
google
.
protobuf
.
GeneratedMessage
.
BuilderParent
parent
)
{
super
(
parent
);
}
@java
.
lang
.
Override
public
Builder
clear
()
{
super
.
clear
();
bitField0_
=
0
;
code_
=
0
;
msg_
=
""
;
msgType_
=
0
;
data_
=
""
;
return
this
;
}
@java
.
lang
.
Override
public
com
.
google
.
protobuf
.
Descriptors
.
Descriptor
getDescriptorForType
()
{
return
protocol
.
Response
.
internal_static_protocol_SocketResponse_descriptor
;
}
@java
.
lang
.
Override
public
protocol
.
Response
.
SocketResponse
getDefaultInstanceForType
()
{
return
protocol
.
Response
.
SocketResponse
.
getDefaultInstance
();
}
@java
.
lang
.
Override
public
protocol
.
Response
.
SocketResponse
build
()
{
protocol
.
Response
.
SocketResponse
result
=
buildPartial
();
if
(!
result
.
isInitialized
())
{
throw
newUninitializedMessageException
(
result
);
}
return
result
;
}
@java
.
lang
.
Override
public
protocol
.
Response
.
SocketResponse
buildPartial
()
{
protocol
.
Response
.
SocketResponse
result
=
new
protocol
.
Response
.
SocketResponse
(
this
);
if
(
bitField0_
!=
0
)
{
buildPartial0
(
result
);
}
onBuilt
();
return
result
;
}
private
void
buildPartial0
(
protocol
.
Response
.
SocketResponse
result
)
{
int
from_bitField0_
=
bitField0_
;
if
(((
from_bitField0_
&
0x00000001
)
!=
0
))
{
result
.
code_
=
code_
;
}
if
(((
from_bitField0_
&
0x00000002
)
!=
0
))
{
result
.
msg_
=
msg_
;
}
if
(((
from_bitField0_
&
0x00000004
)
!=
0
))
{
result
.
msgType_
=
msgType_
;
}
if
(((
from_bitField0_
&
0x00000008
)
!=
0
))
{
result
.
data_
=
data_
;
}
}
@java
.
lang
.
Override
public
Builder
mergeFrom
(
com
.
google
.
protobuf
.
Message
other
)
{
if
(
other
instanceof
protocol
.
Response
.
SocketResponse
)
{
return
mergeFrom
((
protocol
.
Response
.
SocketResponse
)
other
);
}
else
{
super
.
mergeFrom
(
other
);
return
this
;
}
}
public
Builder
mergeFrom
(
protocol
.
Response
.
SocketResponse
other
)
{
if
(
other
==
protocol
.
Response
.
SocketResponse
.
getDefaultInstance
())
return
this
;
if
(
other
.
getCode
()
!=
0
)
{
setCode
(
other
.
getCode
());
}
if
(!
other
.
getMsg
().
isEmpty
())
{
msg_
=
other
.
msg_
;
bitField0_
|=
0x00000002
;
onChanged
();
}
if
(
other
.
getMsgType
()
!=
0
)
{
setMsgType
(
other
.
getMsgType
());
}
if
(!
other
.
getData
().
isEmpty
())
{
data_
=
other
.
data_
;
bitField0_
|=
0x00000008
;
onChanged
();
}
this
.
mergeUnknownFields
(
other
.
getUnknownFields
());
onChanged
();
return
this
;
}
@java
.
lang
.
Override
public
final
boolean
isInitialized
()
{
return
true
;
}
@java
.
lang
.
Override
public
Builder
mergeFrom
(
com
.
google
.
protobuf
.
CodedInputStream
input
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
java
.
io
.
IOException
{
if
(
extensionRegistry
==
null
)
{
throw
new
java
.
lang
.
NullPointerException
();
}
try
{
boolean
done
=
false
;
while
(!
done
)
{
int
tag
=
input
.
readTag
();
switch
(
tag
)
{
case
0
:
done
=
true
;
break
;
case
8
:
{
code_
=
input
.
readInt32
();
bitField0_
|=
0x00000001
;
break
;
}
// case 8
case
18
:
{
msg_
=
input
.
readStringRequireUtf8
();
bitField0_
|=
0x00000002
;
break
;
}
// case 18
case
24
:
{
msgType_
=
input
.
readInt32
();
bitField0_
|=
0x00000004
;
break
;
}
// case 24
case
34
:
{
data_
=
input
.
readStringRequireUtf8
();
bitField0_
|=
0x00000008
;
break
;
}
// case 34
default
:
{
if
(!
super
.
parseUnknownField
(
input
,
extensionRegistry
,
tag
))
{
done
=
true
;
// was an endgroup tag
}
break
;
}
// default:
}
// switch (tag)
}
// while (!done)
}
catch
(
com
.
google
.
protobuf
.
InvalidProtocolBufferException
e
)
{
throw
e
.
unwrapIOException
();
}
finally
{
onChanged
();
}
// finally
return
this
;
}
private
int
bitField0_
;
private
int
code_
;
/**
* <code>int32 code = 1;</code>
* @return The code.
*/
@java
.
lang
.
Override
public
int
getCode
()
{
return
code_
;
}
/**
* <code>int32 code = 1;</code>
* @param value The code to set.
* @return This builder for chaining.
*/
public
Builder
setCode
(
int
value
)
{
code_
=
value
;
bitField0_
|=
0x00000001
;
onChanged
();
return
this
;
}
/**
* <code>int32 code = 1;</code>
* @return This builder for chaining.
*/
public
Builder
clearCode
()
{
bitField0_
=
(
bitField0_
&
~
0x00000001
);
code_
=
0
;
onChanged
();
return
this
;
}
private
java
.
lang
.
Object
msg_
=
""
;
/**
* <code>string msg = 2;</code>
* @return The msg.
*/
public
java
.
lang
.
String
getMsg
()
{
java
.
lang
.
Object
ref
=
msg_
;
if
(!(
ref
instanceof
java
.
lang
.
String
))
{
com
.
google
.
protobuf
.
ByteString
bs
=
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
java
.
lang
.
String
s
=
bs
.
toStringUtf8
();
msg_
=
s
;
return
s
;
}
else
{
return
(
java
.
lang
.
String
)
ref
;
}
}
/**
* <code>string msg = 2;</code>
* @return The bytes for msg.
*/
public
com
.
google
.
protobuf
.
ByteString
getMsgBytes
()
{
java
.
lang
.
Object
ref
=
msg_
;
if
(
ref
instanceof
String
)
{
com
.
google
.
protobuf
.
ByteString
b
=
com
.
google
.
protobuf
.
ByteString
.
copyFromUtf8
(
(
java
.
lang
.
String
)
ref
);
msg_
=
b
;
return
b
;
}
else
{
return
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
}
}
/**
* <code>string msg = 2;</code>
* @param value The msg to set.
* @return This builder for chaining.
*/
public
Builder
setMsg
(
java
.
lang
.
String
value
)
{
if
(
value
==
null
)
{
throw
new
NullPointerException
();
}
msg_
=
value
;
bitField0_
|=
0x00000002
;
onChanged
();
return
this
;
}
/**
* <code>string msg = 2;</code>
* @return This builder for chaining.
*/
public
Builder
clearMsg
()
{
msg_
=
getDefaultInstance
().
getMsg
();
bitField0_
=
(
bitField0_
&
~
0x00000002
);
onChanged
();
return
this
;
}
/**
* <code>string msg = 2;</code>
* @param value The bytes for msg to set.
* @return This builder for chaining.
*/
public
Builder
setMsgBytes
(
com
.
google
.
protobuf
.
ByteString
value
)
{
if
(
value
==
null
)
{
throw
new
NullPointerException
();
}
checkByteStringIsUtf8
(
value
);
msg_
=
value
;
bitField0_
|=
0x00000002
;
onChanged
();
return
this
;
}
private
int
msgType_
;
/**
* <pre>
* </pre>
*
* <code>int32 msgType = 3;</code>
* @return The msgType.
*/
@java
.
lang
.
Override
public
int
getMsgType
()
{
return
msgType_
;
}
/**
* <pre>
* </pre>
*
* <code>int32 msgType = 3;</code>
* @param value The msgType to set.
* @return This builder for chaining.
*/
public
Builder
setMsgType
(
int
value
)
{
msgType_
=
value
;
bitField0_
|=
0x00000004
;
onChanged
();
return
this
;
}
/**
* <pre>
* </pre>
*
* <code>int32 msgType = 3;</code>
* @return This builder for chaining.
*/
public
Builder
clearMsgType
()
{
bitField0_
=
(
bitField0_
&
~
0x00000004
);
msgType_
=
0
;
onChanged
();
return
this
;
}
private
java
.
lang
.
Object
data_
=
""
;
/**
* <code>string data = 4;</code>
* @return The data.
*/
public
java
.
lang
.
String
getData
()
{
java
.
lang
.
Object
ref
=
data_
;
if
(!(
ref
instanceof
java
.
lang
.
String
))
{
com
.
google
.
protobuf
.
ByteString
bs
=
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
java
.
lang
.
String
s
=
bs
.
toStringUtf8
();
data_
=
s
;
return
s
;
}
else
{
return
(
java
.
lang
.
String
)
ref
;
}
}
/**
* <code>string data = 4;</code>
* @return The bytes for data.
*/
public
com
.
google
.
protobuf
.
ByteString
getDataBytes
()
{
java
.
lang
.
Object
ref
=
data_
;
if
(
ref
instanceof
String
)
{
com
.
google
.
protobuf
.
ByteString
b
=
com
.
google
.
protobuf
.
ByteString
.
copyFromUtf8
(
(
java
.
lang
.
String
)
ref
);
data_
=
b
;
return
b
;
}
else
{
return
(
com
.
google
.
protobuf
.
ByteString
)
ref
;
}
}
/**
* <code>string data = 4;</code>
* @param value The data to set.
* @return This builder for chaining.
*/
public
Builder
setData
(
java
.
lang
.
String
value
)
{
if
(
value
==
null
)
{
throw
new
NullPointerException
();
}
data_
=
value
;
bitField0_
|=
0x00000008
;
onChanged
();
return
this
;
}
/**
* <code>string data = 4;</code>
* @return This builder for chaining.
*/
public
Builder
clearData
()
{
data_
=
getDefaultInstance
().
getData
();
bitField0_
=
(
bitField0_
&
~
0x00000008
);
onChanged
();
return
this
;
}
/**
* <code>string data = 4;</code>
* @param value The bytes for data to set.
* @return This builder for chaining.
*/
public
Builder
setDataBytes
(
com
.
google
.
protobuf
.
ByteString
value
)
{
if
(
value
==
null
)
{
throw
new
NullPointerException
();
}
checkByteStringIsUtf8
(
value
);
data_
=
value
;
bitField0_
|=
0x00000008
;
onChanged
();
return
this
;
}
// @@protoc_insertion_point(builder_scope:protocol.SocketResponse)
}
// @@protoc_insertion_point(class_scope:protocol.SocketResponse)
private
static
final
protocol
.
Response
.
SocketResponse
DEFAULT_INSTANCE
;
static
{
DEFAULT_INSTANCE
=
new
protocol
.
Response
.
SocketResponse
();
}
public
static
protocol
.
Response
.
SocketResponse
getDefaultInstance
()
{
return
DEFAULT_INSTANCE
;
}
private
static
final
com
.
google
.
protobuf
.
Parser
<
SocketResponse
>
PARSER
=
new
com
.
google
.
protobuf
.
AbstractParser
<
SocketResponse
>()
{
@java
.
lang
.
Override
public
SocketResponse
parsePartialFrom
(
com
.
google
.
protobuf
.
CodedInputStream
input
,
com
.
google
.
protobuf
.
ExtensionRegistryLite
extensionRegistry
)
throws
com
.
google
.
protobuf
.
InvalidProtocolBufferException
{
Builder
builder
=
newBuilder
();
try
{
builder
.
mergeFrom
(
input
,
extensionRegistry
);
}
catch
(
com
.
google
.
protobuf
.
InvalidProtocolBufferException
e
)
{
throw
e
.
setUnfinishedMessage
(
builder
.
buildPartial
());
}
catch
(
com
.
google
.
protobuf
.
UninitializedMessageException
e
)
{
throw
e
.
asInvalidProtocolBufferException
().
setUnfinishedMessage
(
builder
.
buildPartial
());
}
catch
(
java
.
io
.
IOException
e
)
{
throw
new
com
.
google
.
protobuf
.
InvalidProtocolBufferException
(
e
)
.
setUnfinishedMessage
(
builder
.
buildPartial
());
}
return
builder
.
buildPartial
();
}
};
public
static
com
.
google
.
protobuf
.
Parser
<
SocketResponse
>
parser
()
{
return
PARSER
;
}
@java
.
lang
.
Override
public
com
.
google
.
protobuf
.
Parser
<
SocketResponse
>
getParserForType
()
{
return
PARSER
;
}
@java
.
lang
.
Override
public
protocol
.
Response
.
SocketResponse
getDefaultInstanceForType
()
{
return
DEFAULT_INSTANCE
;
}
}
private
static
final
com
.
google
.
protobuf
.
Descriptors
.
Descriptor
internal_static_protocol_SocketResponse_descriptor
;
private
static
final
com
.
google
.
protobuf
.
GeneratedMessage
.
FieldAccessorTable
internal_static_protocol_SocketResponse_fieldAccessorTable
;
public
static
com
.
google
.
protobuf
.
Descriptors
.
FileDescriptor
getDescriptor
()
{
return
descriptor
;
}
private
static
com
.
google
.
protobuf
.
Descriptors
.
FileDescriptor
descriptor
;
static
{
java
.
lang
.
String
[]
descriptorData
=
{
"\n\016response.proto\022\010protocol\"J\n\016SocketResp"
+
"onse\022\014\n\004code\030\001 \001(\005\022\013\n\003msg\030\002 \001(\t\022\017\n\007msgTy"
+
"pe\030\003 \001(\005\022\014\n\004data\030\004 \001(\tb\006proto3"
};
descriptor
=
com
.
google
.
protobuf
.
Descriptors
.
FileDescriptor
.
internalBuildGeneratedFileFrom
(
descriptorData
,
new
com
.
google
.
protobuf
.
Descriptors
.
FileDescriptor
[]
{
});
internal_static_protocol_SocketResponse_descriptor
=
getDescriptor
().
getMessageTypes
().
get
(
0
);
internal_static_protocol_SocketResponse_fieldAccessorTable
=
new
com
.
google
.
protobuf
.
GeneratedMessage
.
FieldAccessorTable
(
internal_static_protocol_SocketResponse_descriptor
,
new
java
.
lang
.
String
[]
{
"Code"
,
"Msg"
,
"MsgType"
,
"Data"
,
});
descriptor
.
resolveAllFeaturesImmutable
();
}
// @@protoc_insertion_point(outer_class_scope)
}
Prev
1
…
3
4
5
6
7
8
9
10
11
12
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment