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
SuZhouAvp
Commits
1ccbc004
Commit
1ccbc004
authored
Jun 06, 2025
by
p x
Browse files
first
parent
032ec619
Pipeline
#3090
failed with stages
in 0 seconds
Changes
75
Pipelines
2
Expand all
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/sd/cavphmi/net/RequestBodyUtil.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.net
import
com.google.gson.Gson
import
okhttp3.MediaType.Companion.toMediaTypeOrNull
import
okhttp3.RequestBody
import
okhttp3.RequestBody.Companion.toRequestBody
object
RequestBodyUtil
{
/**
* 将参数封装成requestBody形式上传参数
* @param param 参数
* @return RequestBody
*/
fun
toRequestBody
(
map
:
Map
<
String
,
Any
>):
RequestBody
{
val
gson
=
Gson
()
var
param
=
gson
.
toJson
(
map
)
return
param
.
toRequestBody
(
"application/json;charset=UTF-8"
.
toMediaTypeOrNull
())
}
fun
toRequestBody
(
any
:
Any
):
RequestBody
{
var
gson
=
Gson
()
return
gson
.
toJson
(
any
)
.
toRequestBody
(
"application/json;charset=UTF-8"
.
toMediaTypeOrNull
())
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/net/RetrofitApi.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.net
import
com.google.gson.GsonBuilder
import
com.sd.cavphmi.MyAppcation
import
com.sd.cavphmi.utils.MyContants
import
okhttp3.Cache
import
retrofit2.Retrofit
import
retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import
retrofit2.converter.gson.GsonConverterFactory
import
retrofit2.converter.scalars.ScalarsConverterFactory
import
java.io.File
object
RetrofitApi
{
// val CLIENT_BASIC = Credentials.basic("river-chief-server", "123456")
var
retrofitBuild
:
Retrofit
.
Builder
var
cache
:
Cache
init
{
//设置缓存路径
val
httpCacheDirectory
=
File
(
MyAppcation
.
instance
().
applicationContext
.
externalCacheDir
,
"okhttp"
)
//设置缓存
cache
=
Cache
(
httpCacheDirectory
,
50
*
1024
*
1024
)
val
mGson
=
GsonBuilder
()
// .registerTypeAdapter(HttpErrorBean::class.java, HttpErrorTypeAdapter())
// .setLenient() // 设置GSON的非严格模式setLenient()
.
create
()
retrofitBuild
=
Retrofit
.
Builder
()
.
baseUrl
(
MyContants
.
HOST
)
.
addConverterFactory
(
ScalarsConverterFactory
.
create
())
.
addConverterFactory
(
GsonConverterFactory
.
create
(
mGson
))
.
addCallAdapterFactory
(
RxJava3CallAdapterFactory
.
create
())
}
// fun getSSlSocketFactory(): SslData {
// val trustManagerFactory: TrustManagerFactory = TrustManagerFactory.getInstance(
// TrustManagerFactory.getDefaultAlgorithm()
// )
// trustManagerFactory.init(null as KeyStore?)
// val trustManagers: Array<TrustManager> = trustManagerFactory.getTrustManagers()
// check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) {
// ("Unexpected default trust managers:"
// + Arrays.toString(trustManagers))
// }
// val trustManager = trustManagers[0] as X509TrustManager
//
//
// val sslContext = SSLContext.getInstance("TLS")
// sslContext.init(null, arrayOf<TrustManager>(trustManager), null)
// val sslSocketFactory = sslContext.socketFactory
//
// return SslData(sslSocketFactory, trustManager)
// }
//
// data class SslData(val sslSocketFactory: SSLSocketFactory, var trustManager: X509TrustManager)
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/ui/BootActivity.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.ui
import
android.Manifest
import
android.content.Intent
import
androidx.lifecycle.ViewModelProvider
import
com.minedata.minenavi.SDKInitializer
import
com.minedata.minenavi.SDKInitializer.InitListener
import
com.minedata.minenavi.mapdal.CoordType
import
com.minedata.minenavi.poiquery.SearchUrlType
import
com.permissionx.guolindev.PermissionX
import
com.sd.cavphmi.BR
import
com.sd.cavphmi.R
import
com.sd.cavphmi.base.BaseActivity
import
com.sd.cavphmi.base.MyBaseViewModel
import
com.sd.cavphmi.databinding.ActivityBootBinding
import
com.sd.cavphmi.utils.ToastHelper
import
dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class
BootActivity
:
BaseActivity
<
ActivityBootBinding
,
MyBaseViewModel
>()
{
// private val tcpUpVM: TcpUpVM by viewModels()
override
fun
getStatuBarColor
():
Int
{
return
-
1
}
override
fun
initContentView
():
Int
{
return
R
.
layout
.
activity_boot
}
override
fun
initViewModel
():
MyBaseViewModel
{
return
ViewModelProvider
(
this
).
get
(
MyBaseViewModel
::
class
.
java
)
}
override
fun
initVariableId
():
Int
{
return
BR
.
vm
}
// private var latLngInfo: LatLngInfo? = null
override
fun
initView
()
{
// tcpUpVM.owner=this
// tcpUpVM.upWork()
// viewModel.testWork()
initMap
()
requestPers
()
}
// fun getLatLngInfo() {
// latLngInfo = intent.getParcelableExtra<LatLngInfo>(MyContants.LAT_LNG_INFO)
//// var lat = intent.getDoubleExtra("LAT", 0.0)
//// var lng = intent.getDoubleExtra("LNG", 0.0)
// println("---------智慧 boot lng = ${latLngInfo?.lng} lat = ${latLngInfo?.lat}")
//// println("---------智慧 直接传 lat = $lat lng = $lng")
// }
private
fun
starMain
()
{
// requestPers()
binding
.
imageView
.
postDelayed
({
var
jump
=
Intent
(
this
,
MainActivity
::
class
.
java
)
startActivity
(
jump
)
finish
()
},
1000
)
}
fun
initMap
()
{
// 隐私合规接口
SDKInitializer
.
setAgreePrivacy
(
true
)
// if (SDKInitializer.getServerHost().equals("mineservice.minedata.cn")) {
// SDKInitializer.setStyleUrl(
// MineMap.UrlType.basicMap,
// "https://service.minedata.cn/map/solu/style/1359221494104252416"
// )
// }
// 设置地图坐标系
SDKInitializer
.
setCoordType
(
CoordType
.
GCJ02
)
SDKInitializer
.
setSearchUrlType
(
SearchUrlType
.
v1
)
SDKInitializer
.
initialize
(
this
,
object
:
InitListener
{
override
fun
onInitSuccess
()
{
println
(
"---Map onInitSuccess map"
)
}
override
fun
onInitFailed
(
msg
:
String
?)
{
println
(
"---Map onInitFailed msg = ${msg}"
)
}
})
}
fun
requestPers
()
{
var
list
=
listOf
(
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_PHONE_STATE
,
)
PermissionX
.
init
(
this
)
.
permissions
(
list
)
.
onExplainRequestReason
{
scope
,
deniedList
->
scope
.
showRequestReasonDialog
(
deniedList
,
"Adas 需要同意以下授权才能正常使用"
,
"好的"
,
"取消"
)
}
// .onForwardToSettings { scope, deniedList ->
// scope.showForwardToSettingsDialog(deniedList, "您需要手动在‘设置’中允许必要的权限", "OK", "Cancel")
// }
.
request
{
allGranted
,
grantedList
,
deniedList
->
if
(
allGranted
)
{
// ToastHelper.showShort(this, "All permissions are granted")
starMain
()
}
else
{
ToastHelper
.
showShort
(
this
,
"权限被拒"
)
binding
.
root
.
postDelayed
({
finish
()
},
150
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/ui/MainActivity.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.ui
import
androidx.lifecycle.ViewModelProvider
import
com.sd.cavphmi.BR
import
com.sd.cavphmi.R
import
com.sd.cavphmi.base.BaseActivity
import
com.sd.cavphmi.base.MyBaseViewModel
import
com.sd.cavphmi.databinding.ActivityMainBinding
import
dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class
MainActivity
:
BaseActivity
<
ActivityMainBinding
,
MyBaseViewModel
>()
{
override
fun
getStatuBarColor
():
Int
{
return
-
1
}
override
fun
initContentView
():
Int
{
return
R
.
layout
.
activity_main
}
override
fun
initViewModel
():
MyBaseViewModel
{
return
ViewModelProvider
(
this
).
get
(
MyBaseViewModel
::
class
.
java
)
}
override
fun
initVariableId
():
Int
{
return
BR
.
vm
}
override
fun
initView
()
{
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/DateUtils.kt
0 → 100644
View file @
1ccbc004
This diff is collapsed.
Click to expand it.
app/src/main/java/com/sd/cavphmi/utils/DisplayUtil.kt
0 → 100644
View file @
1ccbc004
package
com.ltzw.adasdriver.utils
import
android.app.Activity
import
android.content.Context
import
android.content.res.Configuration
import
android.content.res.Resources
import
android.os.Build
import
android.provider.Settings
import
android.util.DisplayMetrics
import
android.util.TypedValue
/**
*author:pc-20171125
*data:2019/11/7 16:08
*/
object
DisplayUtil
{
fun
getDpi
():
Int
{
return
Resources
.
getSystem
().
displayMetrics
.
densityDpi
}
fun
px2dp
(
pxValue
:
Float
):
Int
{
val
scale
=
Resources
.
getSystem
().
displayMetrics
.
density
return
(
pxValue
/
scale
+
0.5f
).
toInt
()
}
fun
dp2px
(
dipValue
:
Float
):
Int
{
val
scale
=
Resources
.
getSystem
().
displayMetrics
.
density
return
(
dipValue
*
scale
+
0.5f
).
toInt
()
}
fun
px2sp
(
pxValue
:
Float
):
Int
{
val
fontScale
=
Resources
.
getSystem
().
displayMetrics
.
scaledDensity
return
(
pxValue
/
fontScale
+
0.5f
).
toInt
()
}
fun
sp2px
(
spValue
:
Float
):
Int
{
val
fontScale
=
Resources
.
getSystem
().
displayMetrics
.
scaledDensity
return
(
spValue
*
fontScale
+
0.5f
).
toInt
()
}
private
val
mTmpValue
=
TypedValue
()
fun
getXmlDef
(
context
:
Context
,
id
:
Int
):
Int
{
synchronized
(
mTmpValue
)
{
val
value
:
TypedValue
=
mTmpValue
context
.
resources
.
getValue
(
id
,
value
,
true
)
return
TypedValue
.
complexToFloat
(
value
.
data
).
toInt
()
}
}
fun
getNavigationBarHeight
(
context
:
Context
):
Int
{
val
mInPortrait
=
context
.
resources
.
configuration
.
orientation
==
Configuration
.
ORIENTATION_PORTRAIT
val
result
=
0
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
ICE_CREAM_SANDWICH
)
{
if
(
hasNavBar
(
context
as
Activity
))
{
val
key
:
String
if
(
mInPortrait
)
{
key
=
"navigation_bar_height"
}
else
{
key
=
"navigation_bar_height_landscape"
}
return
getInternalDimensionSize
(
context
,
key
)
}
}
return
result
}
private
fun
hasNavBar
(
activity
:
Activity
):
Boolean
{
//判断小米手机是否开启了全面屏,开启了,直接返回false
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN_MR1
)
{
if
(
Settings
.
Global
.
getInt
(
activity
.
contentResolver
,
"force_fsg_nav_bar"
,
0
)
!=
0
)
{
return
false
}
}
//其他手机根据屏幕真实高度与显示高度是否相同来判断
val
windowManager
=
activity
.
windowManager
val
d
=
windowManager
.
defaultDisplay
val
realDisplayMetrics
=
DisplayMetrics
()
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN_MR1
)
{
d
.
getRealMetrics
(
realDisplayMetrics
)
}
val
realHeight
=
realDisplayMetrics
.
heightPixels
val
realWidth
=
realDisplayMetrics
.
widthPixels
val
displayMetrics
=
DisplayMetrics
()
d
.
getMetrics
(
displayMetrics
)
val
displayHeight
=
displayMetrics
.
heightPixels
val
displayWidth
=
displayMetrics
.
widthPixels
return
realWidth
-
displayWidth
>
0
||
realHeight
-
displayHeight
>
0
}
private
fun
getInternalDimensionSize
(
context
:
Context
,
key
:
String
):
Int
{
var
result
=
0
try
{
val
resourceId
=
context
.
resources
.
getIdentifier
(
key
,
"dimen"
,
"android"
)
if
(
resourceId
>
0
)
{
result
=
Math
.
round
(
context
.
resources
.
getDimensionPixelSize
(
resourceId
)
*
Resources
.
getSystem
().
displayMetrics
.
density
/
context
.
resources
.
displayMetrics
.
density
)
}
}
catch
(
ignored
:
Resources
.
NotFoundException
)
{
return
0
}
return
result
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/MobileUtils.kt
0 → 100644
View file @
1ccbc004
package
com.ltzw.adasdriver.utils
import
android.os.Build
object
MobileUtils
{
// if (ModelUtils.isEMUI() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
// mPwdEt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
// mPwdEt.setTransformationMethod(PasswordTransformationMethod.getInstance());
// }
fun
isMIUI
():
Boolean
{
val
manufacturer
:
String
=
Build
.
MANUFACTURER
return
"xiaomi"
.
equals
(
manufacturer
,
ignoreCase
=
true
)
}
fun
isEMUI
():
Boolean
{
val
manufacturer
:
String
=
Build
.
MANUFACTURER
return
"HUAWEI"
.
equals
(
manufacturer
,
ignoreCase
=
true
)
}
fun
isOPPO
():
Boolean
{
val
manufacturer
:
String
=
Build
.
MANUFACTURER
return
"OPPO"
.
equals
(
manufacturer
,
ignoreCase
=
true
)
}
fun
isVIVO
():
Boolean
{
val
manufacturer
:
String
=
Build
.
MANUFACTURER
return
"vivo"
.
equals
(
manufacturer
,
ignoreCase
=
true
)
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/MyContants.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.utils
object
MyContants
{
const
val
IS_DEBUG
=
true
var
HOST
=
if
(
IS_DEBUG
)
"http://laravel.suiyigou.shop/"
else
"https://api.suixinsuiyi.cn/"
var
PORT
=
if
(
IS_DEBUG
)
"123"
else
"34534"
var
SOCKET_HOSTNAME
=
if
(
IS_DEBUG
)
"192.168.60.77"
else
""
var
SOCKET_RECEIVE_PORT
=
if
(
IS_DEBUG
)
8082
else
0
var
DOWNLOAD_APP_URL
=
"https://app.mi.com/download/1325540?id=com.sxsy.easyclient&ref=search&nonce=-6756103978404716128%3A26875199&appClientId=2882303761517485445&appSignature=BJDg3ZbQJhRoaomIe0kkGJ32i6hbX9HduukAmwpZqpQ"
const
val
PERMISSON_REQUESTCODE
:
Int
=
10
const
val
online
=
true
/**
* 智旅APK传智*/
const
val
LAT_LNG_INFO
=
"LAT_LNG_INFO"
/***当前速度***/
var
CUR_SPEED
=
0
const
val
MOCK_LAT
=
39.9129
const
val
MOCK_LNG
=
116.3723
// var CUR_LAT = MOCK_LAT
// var CUR_LNG = MOCK_LNG
var
CUR_LAT
=
0.0
var
CUR_LNG
=
0.0
// const val MOCK_LAT = 39.56
// const val MOCK_LNG = 116.20
// 116.372641,39.913242
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/MyPres.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.utils
import
androidx.security.crypto.EncryptedSharedPreferences
import
com.sd.cavphmi.MyAppcation
object
MyPres
{
private
const
val
PREFS_NAME
=
"adas"
private
const
val
MASTER_KEY_ALIAS
=
"masterkeyalias"
private
val
sharedPreferences
by
lazy
{
EncryptedSharedPreferences
.
create
(
PREFS_NAME
,
MASTER_KEY_ALIAS
,
MyAppcation
.
instance
().
applicationContext
,
EncryptedSharedPreferences
.
PrefKeyEncryptionScheme
.
AES256_SIV
,
EncryptedSharedPreferences
.
PrefValueEncryptionScheme
.
AES256_GCM
)
}
var
token
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"token"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"token"
,
""
)
?:
""
}
var
hisSearch
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"hisSearch"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"hisSearch"
,
""
)
?:
""
}
/**
* 全类型历史搜素
*/
var
curLat
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"curLat"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"curLat"
,
""
)
?:
""
}
/**
* 专题资料历史搜素
*/
var
curLng
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"curLng"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"curLng"
,
""
)
?:
""
}
/**
* 资料历史搜素
*/
var
dataSearch
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"dataSearch"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"dataSearch"
,
""
)
?:
""
}
/**
* 问答历史搜素
*/
var
qaSearch
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"qaSearch"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"qaSearch"
,
""
)
?:
""
}
/**
* 首次授权
*/
var
isFrist
:
Boolean
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putBoolean
(
"isFrist"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getBoolean
(
"isFrist"
,
true
)
}
/**
* 邀请码
*/
var
invCode
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"invcode"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"invcode"
,
""
)
?:
""
}
/**
* 个人电话
*/
var
mobile
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"mobile"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"mobile"
,
""
)
?:
""
}
/**
* 删除领域
*/
var
goodField
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"goodField"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"goodField"
,
""
)
?:
""
}
var
userId
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"userId"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"userId"
,
""
)
?:
""
}
/**
* 极光推送ID
*/
var
registrationId
:
String
set
(
value
)
{
with
(
sharedPreferences
.
edit
())
{
putString
(
"registrationId"
,
value
)
commit
()
}
}
get
()
{
return
sharedPreferences
.
getString
(
"registrationId"
,
""
)
?:
""
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/ScreenUtil.java
0 → 100644
View file @
1ccbc004
This diff is collapsed.
Click to expand it.
app/src/main/java/com/sd/cavphmi/utils/SystemUtils.kt
0 → 100644
View file @
1ccbc004
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.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
com.ltzw.adasdriver.utils.MobileUtils
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
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/utils/ToastHelper.kt
0 → 100644
View file @
1ccbc004
package
com.sd.cavphmi.utils
import
android.content.Context
import
android.text.SpannableString
import
android.view.Gravity
import
android.view.LayoutInflater
import
android.widget.TextView
import
android.widget.Toast
/**
*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
()
}
}
// /**
// * 短时间显示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 @
1ccbc004
This diff is collapsed.
Click to expand it.
app/src/main/res/drawable-xhdpi/angle.png
0 → 100644
View file @
1ccbc004
2.38 KB
app/src/main/res/drawable-xhdpi/drive_mode.png
0 → 100644
View file @
1ccbc004
2.87 KB
app/src/main/res/drawable-xhdpi/speed.png
0 → 100644
View file @
1ccbc004
20.8 KB
app/src/main/res/drawable-xhdpi/stop.png
0 → 100644
View file @
1ccbc004
800 Bytes
app/src/main/res/drawable-xhdpi/xinhao1.png
0 → 100644
View file @
1ccbc004
302 Bytes
app/src/main/res/drawable-xhdpi/xinhao2.png
0 → 100644
View file @
1ccbc004
296 Bytes
app/src/main/res/drawable-xhdpi/xinhao3.png
0 → 100644
View file @
1ccbc004
321 Bytes
Prev
1
2
3
4
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