安联,交通厅引入1版
This commit is contained in:
parent
2037daaa15
commit
4c1697c385
@ -156,6 +156,24 @@ dependencies {
|
||||
// implementation(name: 'EsignSDK', ext: 'aar')
|
||||
|
||||
|
||||
//交通厅
|
||||
implementation 'com.lzy.net:okgo:3.0.4'
|
||||
implementation 'com.alibaba:fastjson:1.2.61'
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.55'
|
||||
implementation 'org.apache.commons:commons-lang3:3.5'
|
||||
// implementation(name: 'locationgd-androidx_2.1.0', ext: 'aar')//交通厅
|
||||
implementation files('libs/locationgd-androidx_2.1.0.aar')
|
||||
|
||||
//安联
|
||||
//当引入的与之前引入的库有重复冲突部分的时候,使用compileOnly
|
||||
implementation files('libs\\mdp_sdk.jar')
|
||||
implementation 'com.loopj.android:android-async-http:1.4.9'
|
||||
implementation 'com.j256.ormlite:ormlite-android:4.48'
|
||||
implementation 'com.j256.ormlite:ormlite-core:4.48'
|
||||
compileOnly 'com.github.hotchemi:permissionsdispatcher:2.3.1'
|
||||
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.3.1'
|
||||
|
||||
|
||||
//友盟
|
||||
implementation 'com.umeng.umsdk:common:9.6.3'// 必选
|
||||
implementation 'com.umeng.umsdk:asms:1.8.0'// 必选
|
||||
|
BIN
app/libs/arm64-v8a/libBaiduMapSDK_base_v5_1_0.so
Normal file
BIN
app/libs/arm64-v8a/libBaiduMapSDK_base_v5_1_0.so
Normal file
Binary file not shown.
BIN
app/libs/arm64-v8a/libBaiduMapSDK_map_v5_1_0.so
Normal file
BIN
app/libs/arm64-v8a/libBaiduMapSDK_map_v5_1_0.so
Normal file
Binary file not shown.
BIN
app/libs/arm64-v8a/libindoor.so
Normal file
BIN
app/libs/arm64-v8a/libindoor.so
Normal file
Binary file not shown.
BIN
app/libs/arm64-v8a/liblocSDK7b.so
Normal file
BIN
app/libs/arm64-v8a/liblocSDK7b.so
Normal file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libBaiduMapSDK_base_v5_1_0.so
Normal file
BIN
app/libs/armeabi-v7a/libBaiduMapSDK_base_v5_1_0.so
Normal file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libBaiduMapSDK_map_v5_1_0.so
Normal file
BIN
app/libs/armeabi-v7a/libBaiduMapSDK_map_v5_1_0.so
Normal file
Binary file not shown.
BIN
app/libs/armeabi-v7a/libindoor.so
Normal file
BIN
app/libs/armeabi-v7a/libindoor.so
Normal file
Binary file not shown.
BIN
app/libs/armeabi-v7a/liblocSDK7b.so
Normal file
BIN
app/libs/armeabi-v7a/liblocSDK7b.so
Normal file
Binary file not shown.
BIN
app/libs/locationgd-androidx_2.1.0.aar
Normal file
BIN
app/libs/locationgd-androidx_2.1.0.aar
Normal file
Binary file not shown.
BIN
app/libs/mdp_sdk.jar
Normal file
BIN
app/libs/mdp_sdk.jar
Normal file
Binary file not shown.
@ -16,6 +16,9 @@
|
||||
<!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
<!-- 访问网络的变化, 需要某些信息用于网络定位 -->
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
|
||||
<!--用于访问GPS定位-->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<!--用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
|
||||
@ -423,6 +426,47 @@
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|navigation"
|
||||
android:launchMode="singleInstance" />
|
||||
<!-- 导航相关end -->
|
||||
|
||||
|
||||
<!-- 交通厅相关start -->
|
||||
<service
|
||||
android:name=".third.JTTSendService"
|
||||
android:foregroundServiceType="location" />
|
||||
<!-- 交通厅相关end -->
|
||||
|
||||
<!-- 安联相关start -->
|
||||
|
||||
<service
|
||||
android:name="com.alct.mdp.MDPLocationService"
|
||||
android:exported="true"
|
||||
android:process=":mdpLocation_v1" />
|
||||
<service
|
||||
android:name="com.baidu.location.f"
|
||||
android:enabled="true"
|
||||
android:process=":remote">
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name="com.alct.mdp.job.LocationUploadJobService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" >
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name="com.alct.mdp.job.LogUploadJobService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" >
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name="com.alct.mdp.job.AppRunningStatusUploadJobService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" >
|
||||
</service>
|
||||
|
||||
<meta-data
|
||||
android:name="com.baidu.lbsapi.API_KEY"
|
||||
android:value="BiRjhNoG2FhrveK48ihjtbK7BNcBD5zt" />
|
||||
|
||||
<!-- 安联相关end -->
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,16 +1,21 @@
|
||||
package com.dahe.gldriver.base
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.Application
|
||||
import android.app.PendingIntent
|
||||
import android.app.PendingIntent.*
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import com.alct.mdp.MDPLocationCollectionManager
|
||||
import com.dahe.gldriver.BuildConfig
|
||||
import com.dahe.gldriver.R
|
||||
import com.dahe.gldriver.net.Api
|
||||
import com.dahe.gldriver.oss.OssServiceUtil
|
||||
import com.dahe.gldriver.push.PushHelper
|
||||
import com.dahe.gldriver.third.JTTProcess
|
||||
import com.dahe.gldriver.third.SPUtil
|
||||
import com.dahe.gldriver.ui.HomeActivity
|
||||
import com.dahe.gldriver.utils.OrderUtils
|
||||
import com.dahe.mylibrary.CommonBaseLibrary
|
||||
@ -54,6 +59,8 @@ class App : Application() {
|
||||
// EsignSdk.getInstance().init(AppConfig.E_KEY, AppConfig.E_LICENSE)
|
||||
initUmeng()
|
||||
|
||||
initThird()
|
||||
|
||||
var pendingIntent: PendingIntent = getActivity(
|
||||
applicationContext, 0,
|
||||
Intent(applicationContext, HomeActivity::class.java),
|
||||
@ -93,6 +100,26 @@ class App : Application() {
|
||||
super.attachBaseContext(base)
|
||||
}
|
||||
|
||||
private fun initThird() {
|
||||
val state: String = SPUtil.getSP(this, "state_data", "authorization_state")
|
||||
if ("1" == state) {
|
||||
try {
|
||||
//安联初始化
|
||||
if (packageName == getCurrentProcessName(this)) {
|
||||
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
|
||||
MDPLocationCollectionManager.initialize(this, BuildConfig.OPEN_AL_URL)
|
||||
}
|
||||
|
||||
//初始化交通厅
|
||||
JTTProcess.init(this)
|
||||
SPUtil.insSP(this, "state_data", "authorization_state", "1")
|
||||
} catch (e: Exception) {
|
||||
SPUtil.insSP(this, "state_data", "authorization_state", "0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//忽略https的证书校验
|
||||
fun handleSSLHandshake() {
|
||||
try {
|
||||
@ -168,4 +195,18 @@ class App : Application() {
|
||||
companion object {
|
||||
var app: App? = null
|
||||
}
|
||||
|
||||
fun getCurrentProcessName(context: Context): String? {
|
||||
var currentProcessName = ""
|
||||
val pid = Process.myPid()
|
||||
val mActivityManager = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||
if (mActivityManager.runningAppProcesses != null && mActivityManager.runningAppProcesses.size > 0) {
|
||||
for (appProcess in mActivityManager.runningAppProcesses) {
|
||||
if (appProcess.pid == pid) {
|
||||
currentProcessName = appProcess.processName
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentProcessName
|
||||
}
|
||||
}
|
119
app/src/main/java/com/dahe/gldriver/bean/FqBean.java
Normal file
119
app/src/main/java/com/dahe/gldriver/bean/FqBean.java
Normal file
@ -0,0 +1,119 @@
|
||||
package com.dahe.gldriver.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/11/23 19:16
|
||||
* @description:
|
||||
*/
|
||||
public class FqBean {
|
||||
|
||||
private int pageSize;
|
||||
private int currentPage;
|
||||
private int totalCount;
|
||||
private int totalPage;
|
||||
private List<Invoice> driverInvoices;
|
||||
//{"currentPage":100,"driverInvoices":[],"pageSize":1,"totalCount":0,"totalPage":0}
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(int currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
public int getTotalPage() {
|
||||
return totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPage(int totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
public List<Invoice> getDriverInvoices() {
|
||||
if (driverInvoices == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return driverInvoices;
|
||||
}
|
||||
|
||||
public void setDriverInvoices(List<Invoice> driverInvoices) {
|
||||
this.driverInvoices = driverInvoices;
|
||||
}
|
||||
|
||||
public class Invoice{
|
||||
String invoiceReceiverName; //受票方,string类型
|
||||
double taxRate; //发票税率,double类型
|
||||
double taxAmount; //税额, double类型
|
||||
double totalAmount; //金额, double类型
|
||||
double totalAmountIncludeTax; //金额+税额,double类型
|
||||
String driverInvoiceCode; //发票编号,string类型
|
||||
|
||||
public String getInvoiceReceiverName() {
|
||||
return invoiceReceiverName == null ? "" : invoiceReceiverName;
|
||||
}
|
||||
|
||||
public void setInvoiceReceiverName(String invoiceReceiverName) {
|
||||
this.invoiceReceiverName = invoiceReceiverName;
|
||||
}
|
||||
|
||||
public double getTaxRate() {
|
||||
return taxRate;
|
||||
}
|
||||
|
||||
public void setTaxRate(double taxRate) {
|
||||
this.taxRate = taxRate;
|
||||
}
|
||||
|
||||
public double getTaxAmount() {
|
||||
return taxAmount;
|
||||
}
|
||||
|
||||
public void setTaxAmount(double taxAmount) {
|
||||
this.taxAmount = taxAmount;
|
||||
}
|
||||
|
||||
public double getTotalAmount() {
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
public void setTotalAmount(double totalAmount) {
|
||||
this.totalAmount = totalAmount;
|
||||
}
|
||||
|
||||
public double getTotalAmountIncludeTax() {
|
||||
return totalAmountIncludeTax;
|
||||
}
|
||||
|
||||
public void setTotalAmountIncludeTax(double totalAmountIncludeTax) {
|
||||
this.totalAmountIncludeTax = totalAmountIncludeTax;
|
||||
}
|
||||
|
||||
public String getDriverInvoiceCode() {
|
||||
return driverInvoiceCode == null ? "" : driverInvoiceCode;
|
||||
}
|
||||
|
||||
public void setDriverInvoiceCode(String driverInvoiceCode) {
|
||||
this.driverInvoiceCode = driverInvoiceCode;
|
||||
}
|
||||
}
|
||||
}
|
140
app/src/main/java/com/dahe/gldriver/bean/JTT.java
Normal file
140
app/src/main/java/com/dahe/gldriver/bean/JTT.java
Normal file
@ -0,0 +1,140 @@
|
||||
package com.dahe.gldriver.bean;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2022/2/16 17:37
|
||||
* @description:
|
||||
*/
|
||||
public class JTT {
|
||||
|
||||
private int code;
|
||||
private DataDTO data;
|
||||
private String msg;
|
||||
private boolean success;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public DataDTO getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(DataDTO data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public static class DataDTO {
|
||||
private String createTime;
|
||||
private boolean delFlag;
|
||||
private int id;
|
||||
private String trafficCode;
|
||||
private String trafficId;
|
||||
private String trafficName;
|
||||
private String trafficNum;
|
||||
private String trafficSecret;
|
||||
private String trafficType;
|
||||
private String updateTime;
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public boolean isDelFlag() {
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(boolean delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTrafficCode() {
|
||||
return trafficCode;
|
||||
}
|
||||
|
||||
public void setTrafficCode(String trafficCode) {
|
||||
this.trafficCode = trafficCode;
|
||||
}
|
||||
|
||||
public String getTrafficId() {
|
||||
return trafficId;
|
||||
}
|
||||
|
||||
public void setTrafficId(String trafficId) {
|
||||
this.trafficId = trafficId;
|
||||
}
|
||||
|
||||
public String getTrafficName() {
|
||||
return trafficName;
|
||||
}
|
||||
|
||||
public void setTrafficName(String trafficName) {
|
||||
this.trafficName = trafficName;
|
||||
}
|
||||
|
||||
public String getTrafficNum() {
|
||||
return trafficNum;
|
||||
}
|
||||
|
||||
public void setTrafficNum(String trafficNum) {
|
||||
this.trafficNum = trafficNum;
|
||||
}
|
||||
|
||||
public String getTrafficSecret() {
|
||||
return trafficSecret;
|
||||
}
|
||||
|
||||
public void setTrafficSecret(String trafficSecret) {
|
||||
this.trafficSecret = trafficSecret;
|
||||
}
|
||||
|
||||
public String getTrafficType() {
|
||||
return trafficType;
|
||||
}
|
||||
|
||||
public void setTrafficType(String trafficType) {
|
||||
this.trafficType = trafficType;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
||||
}
|
16
app/src/main/java/com/dahe/gldriver/bean/LUInputBean.kt
Normal file
16
app/src/main/java/com/dahe/gldriver/bean/LUInputBean.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.dahe.gldriver.bean
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/8/13 10:27
|
||||
* @description:装卸货输入参数实体
|
||||
*/
|
||||
class LUInputBean {
|
||||
var imageId: List<Int>? = null
|
||||
var latitude: String? = null
|
||||
var locationAddress: String? = null
|
||||
var longitude: String? = null
|
||||
var waybillId: String? = null
|
||||
var realLoadTime: String? = null
|
||||
}
|
@ -15,6 +15,7 @@ data class OrderDetailBean(
|
||||
val loadingDeadline: String,
|
||||
val orderChildList: List<OrderChild>,
|
||||
val orderId: String,
|
||||
|
||||
val orderNum: String,
|
||||
val orderStatus: String,
|
||||
val phone: String,
|
||||
@ -34,7 +35,11 @@ data class OrderDetailBean(
|
||||
val vehicleType: String,
|
||||
val waybillId: String,
|
||||
val vehicleNum: String,
|
||||
val loadingAreaCode: String,
|
||||
val receiverAreaCode: String,
|
||||
val waybillInfo: WaybillInfo
|
||||
|
||||
|
||||
)
|
||||
|
||||
data class CaptainInfo(
|
||||
@ -64,6 +69,7 @@ data class OrderChild(
|
||||
val city: String,
|
||||
val cityCode: String,
|
||||
val cost: String,
|
||||
val isPassingPoints: String,//是否途经点(0=否,1=是)
|
||||
val displayOrder: String,
|
||||
val isPassingPoStrings: String,
|
||||
val latitude: String,
|
||||
@ -99,7 +105,7 @@ data class WaybillInfo(
|
||||
val trailerId: String,
|
||||
val trailerVehicleNum: String,
|
||||
val unloadTime: String,
|
||||
val vehicleNum: String,
|
||||
var vehicleNum: String,
|
||||
val carLong: String,
|
||||
val approvedLoad: String,
|
||||
val vehicleType: String,
|
||||
|
105
app/src/main/java/com/dahe/gldriver/third/ALProcess.kt
Normal file
105
app/src/main/java/com/dahe/gldriver/third/ALProcess.kt
Normal file
@ -0,0 +1,105 @@
|
||||
package com.dahe.gldriver.third
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import com.alct.mdp.MDPLocationCollectionManager
|
||||
import com.alct.mdp.callback.OnDownloadResultListener
|
||||
import com.alct.mdp.callback.OnResultListener
|
||||
import com.alct.mdp.model.Identity
|
||||
import com.dahe.gldriver.BuildConfig
|
||||
import com.dahe.gldriver.bean.FqBean
|
||||
import com.dahe.gldriver.utils.SPUtils.Companion.instance
|
||||
import com.google.gson.Gson
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/8/16 10:35
|
||||
* @description:安联流程
|
||||
*/
|
||||
class ALProcess {
|
||||
companion object {
|
||||
//企业代码
|
||||
private const val ENTERPRISE_CODE = "E0019169"
|
||||
|
||||
//企业app的身份码
|
||||
private const val APP_IDENTITY = "b4a472a025e443b383970cdd5465552e"
|
||||
|
||||
//企业app验证码
|
||||
private const val APP_KEY = "b948efbb4c2a4ba0805c534f2fba0c89"
|
||||
|
||||
//企业代码-测试
|
||||
private const val ENTERPRISE_CODE_TEXT = "E0019093"
|
||||
|
||||
//企业app的身份码-测试
|
||||
private const val APP_IDENTITY_TEXT = "a15b4ba5bd2542cc9a6bea9bdadf9ef9"
|
||||
|
||||
//企业app验证码-测试
|
||||
private const val APP_KEY_TEXT = "07a6256cad5642138ed6e962a5a157be"
|
||||
fun verification(con: Context?) {
|
||||
val (_, _, _, _, idcard) = instance.getUserInfo(con)
|
||||
val idy = Identity()
|
||||
//企业代码
|
||||
idy.enterpriseCode = if (BuildConfig.isTest) ENTERPRISE_CODE_TEXT else ENTERPRISE_CODE
|
||||
//企业app的身份码
|
||||
idy.appIdentity = if (BuildConfig.isTest) APP_IDENTITY_TEXT else APP_IDENTITY
|
||||
//企业app验证码
|
||||
idy.appKey = if (BuildConfig.isTest) APP_KEY_TEXT else APP_KEY
|
||||
//司机身份证
|
||||
idy.driverIdentity = idcard
|
||||
//idy.setDriverIdentity("410725198311042012");
|
||||
MDPLocationCollectionManager.register(con, idy, object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("--success--", "验证成功")
|
||||
getFq(con)
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("--error--", s + s1 + "")
|
||||
// new MessageUtils().showCenMessage(con,s1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getFq(con: Context?) {
|
||||
MDPLocationCollectionManager.getInvoices(
|
||||
con,
|
||||
100,
|
||||
1,
|
||||
object : OnDownloadResultListener {
|
||||
override fun onSuccess(o: Any) {
|
||||
Log.e("--获取发票列表成功--", Gson().toJson(o))
|
||||
try {
|
||||
val fb = Gson().fromJson(Gson().toJson(o), FqBean::class.java)
|
||||
applyFq(con, fb)
|
||||
} catch (e: Exception) {
|
||||
Log.e("--失败--", "数据解析失败")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("--获取发票列表失败--", s + s1 + "")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun applyFq(con: Context?, fb: FqBean) {
|
||||
for (driverInvoice in fb.driverInvoices) {
|
||||
MDPLocationCollectionManager.confirmInvoice(
|
||||
con,
|
||||
if (BuildConfig.isTest) ENTERPRISE_CODE_TEXT else ENTERPRISE_CODE,
|
||||
driverInvoice.driverInvoiceCode,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("--成功--", "申请发票成功")
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("--失败--", "申请发票失败$s$s1")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
app/src/main/java/com/dahe/gldriver/third/JTTConstant.kt
Normal file
13
app/src/main/java/com/dahe/gldriver/third/JTTConstant.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.dahe.gldriver.third
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2022/1/10 11:34
|
||||
* @description:交通厅参数
|
||||
*/
|
||||
object JTTConstant {
|
||||
const val JTT_DATA_NAME = "jtt_data"
|
||||
const val JTT_DATA_JTTORDER_KEY = "JTT_order_key"
|
||||
const val JTT_DATA_ORDER_KEY = "order_key"
|
||||
}
|
267
app/src/main/java/com/dahe/gldriver/third/JTTProcess.kt
Normal file
267
app/src/main/java/com/dahe/gldriver/third/JTTProcess.kt
Normal file
@ -0,0 +1,267 @@
|
||||
package com.dahe.gldriver.third
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.dahe.gldriver.bean.JTT
|
||||
import com.dahe.gldriver.bean.OrderDetailBean
|
||||
import com.dahe.gldriver.utils.SPUtils
|
||||
import com.dahe.gldriver.utils.StringUtil
|
||||
import com.google.gson.Gson
|
||||
import com.hdgq.locationlib.LocationOpenApi
|
||||
import com.hdgq.locationlib.entity.ShippingNoteInfo
|
||||
import com.hdgq.locationlib.listener.OnResultListener
|
||||
import com.hdgq.locationlib.listener.OnSendResultListener
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/12/10 9:38
|
||||
* @description:交通厅位置上传sdk
|
||||
*/
|
||||
object JTTProcess {
|
||||
private const val APPID = "com.arpa.hndahesudintocctmsdriver"
|
||||
private const val APP_SECURITY =
|
||||
"01e20fc6585a42738ac88a12321dc41bff473b4b20184aacbbcee7d7864359a6"
|
||||
private const val CODE = "41110447"
|
||||
private const val ENVIRONMENT = "release"
|
||||
private val gson = Gson()
|
||||
|
||||
//初始化+获取授权
|
||||
fun init(app: Application?) {
|
||||
LocationOpenApi.init(app)
|
||||
//auth(app.getBaseContext());
|
||||
}
|
||||
|
||||
//获取授权
|
||||
fun auth(con: Context) {
|
||||
val jttStr: String = SPUtil.getSP(con, "data", "jtt")
|
||||
val jtt = gson.fromJson(jttStr, JTT::class.java)
|
||||
if (jtt.data == null) {
|
||||
return
|
||||
}
|
||||
LocationOpenApi.auth(con, APPID, StringUtil.isNull(jtt.data.trafficCode, APP_SECURITY),
|
||||
StringUtil.isNull(jtt.data.trafficId, CODE),
|
||||
ENVIRONMENT, object : OnResultListener {
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("交通厅-获取授权", s + s1)
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-获取授权", gson.toJson(list))
|
||||
if (list.size > 0) {
|
||||
SPUtil.insSP(
|
||||
con,
|
||||
JTTConstant.JTT_DATA_NAME,
|
||||
JTTConstant.JTT_DATA_JTTORDER_KEY,
|
||||
gson.toJson(
|
||||
list[0]
|
||||
)
|
||||
)
|
||||
val `in` = Intent(con, JTTSendService::class.java)
|
||||
con.startService(`in`)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//开启定位-装货
|
||||
//shippingNoteInfos 为运单信息列表,考虑到一车多单的情况,本版SDK 一辆车运单数最大支持数为 10。
|
||||
fun start(con: Context, sob: OrderDetailBean, remark: String?) {
|
||||
val snis = arrayOfNulls<ShippingNoteInfo>(1)
|
||||
val sni = ShippingNoteInfo()
|
||||
val startWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "1" }
|
||||
val endWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "2" }
|
||||
sni.shippingNoteNumber = sob.orderNum
|
||||
sni.serialNumber = "0000"
|
||||
sni.startLatitude = startWay.latitude.toDouble()
|
||||
sni.startLongitude = startWay.longitude.toDouble()
|
||||
sni.startLocationText = startWay.province + startWay.city + startWay.area + startWay.address
|
||||
sni.startCountrySubdivisionCode = sob.loadingAreaCode
|
||||
sni.endLatitude = endWay.latitude.toDouble()
|
||||
sni.endLongitude = endWay.longitude.toDouble()
|
||||
sni.endLocationText = endWay.province + endWay.city + endWay.area + endWay.address
|
||||
sni.endCountrySubdivisionCode = sob.receiverAreaCode
|
||||
snis[0] = sni
|
||||
// Log.e("起点代码",sob.getData().getStartCountrySubdivisionCode());
|
||||
// Log.e("终点代码",sob.getData().getEndCountrySubdivisionCode());
|
||||
// AMapLocationClient.updatePrivacyShow(con,true,true);
|
||||
// AMapLocationClient.updatePrivacyAgree(con,true);
|
||||
|
||||
LocationOpenApi.start(
|
||||
con,
|
||||
sob.waybillInfo.vehicleNum,
|
||||
if (SPUtils.instance.getUserInfo(con).idcardName == null) "" else SPUtils.instance.getUserInfo(
|
||||
con
|
||||
).idcardName,
|
||||
remark,
|
||||
snis,
|
||||
object : OnResultListener {
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("交通厅-开启定位失败", s + s1 + "")
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-开启定位成功", gson.toJson(list))
|
||||
if (list.size > 0) {
|
||||
SPUtil.insSP(
|
||||
con,
|
||||
JTTConstant.JTT_DATA_NAME,
|
||||
JTTConstant.JTT_DATA_JTTORDER_KEY,
|
||||
gson.toJson(
|
||||
list[0]
|
||||
)
|
||||
)
|
||||
val `in` = Intent(con, JTTSendService::class.java)
|
||||
con.startService(`in`)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//发送定位
|
||||
//参数 ShippingNoteInfo 和 start 接口中的参数 ShippingNoteInfo 相
|
||||
//同,这里 shippingNoteInfo 信息只需传入运单号和分单号即可
|
||||
fun send(con: Context?, sob: OrderDetailBean, remark: String?) {
|
||||
val snis = arrayOfNulls<ShippingNoteInfo>(1)
|
||||
val sni = ShippingNoteInfo()
|
||||
sni.shippingNoteNumber = sob.orderNum
|
||||
sni.serialNumber = "0000"
|
||||
sni.startCountrySubdivisionCode = sob.loadingAreaCode
|
||||
sni.endCountrySubdivisionCode = sob.receiverAreaCode
|
||||
snis[0] = sni
|
||||
LocationOpenApi.send(
|
||||
con,
|
||||
sob.waybillInfo.vehicleNum,
|
||||
if (SPUtils.instance.getUserInfo(con).idcardName == null) "" else SPUtils.instance.getUserInfo(
|
||||
con
|
||||
).idcardName,
|
||||
remark,
|
||||
snis,
|
||||
object : OnSendResultListener {
|
||||
override fun onFailure(s: String, s1: String, list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-发送定位失败", s + s1 + "")
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-发送定位成功", gson.toJson(list))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//暂停定位
|
||||
//运单运输过程中,如果出现换驾驶员、换车或换手机的情况,则需驾驶员在原手机上操作,对运送运单列表执行暂停操作,
|
||||
//调用本接口将运单列表中所有运单标记为暂停状态,并结束本手机的运单定位。
|
||||
fun pause(con: Context?, sob: OrderDetailBean, remark: String?) {
|
||||
val snis = arrayOfNulls<ShippingNoteInfo>(1)
|
||||
val sni = ShippingNoteInfo()
|
||||
val startWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "1" }
|
||||
val endWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "2" }
|
||||
sni.shippingNoteNumber = sob.orderNum
|
||||
sni.serialNumber = "0000"
|
||||
sni.startLatitude = startWay.latitude.toDouble()
|
||||
sni.startLongitude = startWay.longitude.toDouble()
|
||||
sni.startLocationText = startWay.province + startWay.city + startWay.area + startWay.address
|
||||
sni.startCountrySubdivisionCode = sob.loadingAreaCode
|
||||
sni.endLatitude = endWay.latitude.toDouble()
|
||||
sni.endLongitude = endWay.longitude.toDouble()
|
||||
sni.endLocationText = endWay.province + endWay.city + endWay.area + endWay.address
|
||||
sni.endCountrySubdivisionCode = sob.receiverAreaCode
|
||||
snis[0] = sni
|
||||
LocationOpenApi.pause(
|
||||
con,
|
||||
sob.waybillInfo.vehicleNum,
|
||||
if (SPUtils.instance.getUserInfo(con).idcardName == null) "" else SPUtils.instance.getUserInfo(
|
||||
con
|
||||
).idcardName,
|
||||
remark,
|
||||
snis,
|
||||
object : OnResultListener {
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("交通厅-暂停定位失败", s + s1 + "")
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-暂停定位成功", gson.toJson(list))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//重启定位
|
||||
//对应 pause 接口,本接口的作用是对已暂停的运单列表执行重启定位操作
|
||||
fun restart(con: Context?, sob: OrderDetailBean, remark: String?) {
|
||||
val snis = arrayOfNulls<ShippingNoteInfo>(1)
|
||||
val sni = ShippingNoteInfo()
|
||||
val startWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "1" }
|
||||
val endWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "2" }
|
||||
sni.shippingNoteNumber = sob.orderNum
|
||||
sni.serialNumber = "0000"
|
||||
sni.startLatitude = startWay.latitude.toDouble()
|
||||
sni.startLongitude = startWay.longitude.toDouble()
|
||||
sni.startLocationText = startWay.province + startWay.city + startWay.area + startWay.address
|
||||
sni.startCountrySubdivisionCode = sob.loadingAreaCode
|
||||
sni.endLatitude = endWay.latitude.toDouble()
|
||||
sni.endLongitude = endWay.longitude.toDouble()
|
||||
sni.endLocationText = endWay.province + endWay.city + endWay.area + endWay.address
|
||||
sni.endCountrySubdivisionCode = sob.receiverAreaCode
|
||||
snis[0] = sni
|
||||
LocationOpenApi.restart(
|
||||
con,
|
||||
sob.waybillInfo.vehicleNum,
|
||||
if (SPUtils.instance.getUserInfo(con).idcardName == null) "" else SPUtils.instance.getUserInfo(
|
||||
con
|
||||
).idcardName,
|
||||
remark,
|
||||
snis,
|
||||
object : OnResultListener {
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("交通厅-重启定位失败", s + s1 + "")
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-重启定位成功", gson.toJson(list))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//结束定位-卸货
|
||||
fun stop(con: Context, sob: OrderDetailBean, remark: String?) {
|
||||
val snis = arrayOfNulls<ShippingNoteInfo>(1)
|
||||
val sni = ShippingNoteInfo()
|
||||
val startWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "1" }
|
||||
val endWay = sob.orderChildList.filter { it.isPassingPoints!="0" }.first { it.type == "2" }
|
||||
sni.shippingNoteNumber = sob.orderNum
|
||||
sni.serialNumber = "0000"
|
||||
sni.startLatitude = startWay.latitude.toDouble()
|
||||
sni.startLongitude = startWay.longitude.toDouble()
|
||||
sni.startLocationText = startWay.province + startWay.city + startWay.area + startWay.address
|
||||
sni.startCountrySubdivisionCode = sob.loadingAreaCode
|
||||
sni.endLatitude = endWay.latitude.toDouble()
|
||||
sni.endLongitude = endWay.longitude.toDouble()
|
||||
sni.endLocationText = endWay.province + endWay.city + endWay.area + endWay.address
|
||||
sni.endCountrySubdivisionCode = sob.receiverAreaCode
|
||||
snis[0] = sni
|
||||
//remark="[00]车辆损坏货物无法送达";
|
||||
//sob.getData().setCarNumber("豫PK2861");
|
||||
LocationOpenApi.stop(
|
||||
con,
|
||||
sob.waybillInfo.vehicleNum,
|
||||
if (SPUtils.instance.getUserInfo(con).idcardName == null) "" else SPUtils.instance.getUserInfo(
|
||||
con
|
||||
).idcardName,
|
||||
remark,
|
||||
snis,
|
||||
object : OnResultListener {
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("交通厅-结束定位失败", s + s1 + "")
|
||||
}
|
||||
|
||||
override fun onSuccess(list: List<ShippingNoteInfo>) {
|
||||
Log.e("交通厅-结束定位成功", gson.toJson(list))
|
||||
val stopIntent = Intent(con, JTTSendService::class.java)
|
||||
con.stopService(stopIntent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
112
app/src/main/java/com/dahe/gldriver/third/JTTSendService.java
Normal file
112
app/src/main/java/com/dahe/gldriver/third/JTTSendService.java
Normal file
@ -0,0 +1,112 @@
|
||||
package com.dahe.gldriver.third;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.dahe.gldriver.bean.OrderDetailBean;
|
||||
import com.google.gson.Gson;
|
||||
import com.hdgq.locationlib.entity.ShippingNoteInfo;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/12/24 14:16
|
||||
* @description:
|
||||
*/
|
||||
public class JTTSendService extends Service {
|
||||
|
||||
private Context con;
|
||||
private String snn="";
|
||||
private Gson gson=new Gson();
|
||||
private OrderDetailBean sob=null;
|
||||
|
||||
private Handler hd=new Handler(msg -> {
|
||||
switch (msg.what){
|
||||
case 66:
|
||||
JTTProcess.INSTANCE.send(con,sob,"");
|
||||
break;
|
||||
case 67:
|
||||
JTTProcess.INSTANCE.pause(getBaseContext(),sob,"");
|
||||
sob.getWaybillInfo().setVehicleNum("豫PK2861");
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
MsgUtil.addHdMsgWat(hd,68);
|
||||
}
|
||||
},6000,100000000);
|
||||
break;
|
||||
case 68:
|
||||
JTTProcess.INSTANCE.restart(getBaseContext(),sob,"[03]换车");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {return null; }
|
||||
|
||||
private int sum=0;
|
||||
private ShippingNoteInfo sf;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.e("交通厅","开启位置上传");
|
||||
con=this;
|
||||
String str= SPUtil.getSP(con, JTTConstant.JTT_DATA_NAME,JTTConstant.JTT_DATA_JTTORDER_KEY);
|
||||
String str2=SPUtil.getSP(con,JTTConstant.JTT_DATA_NAME,JTTConstant.JTT_DATA_ORDER_KEY);
|
||||
sf=gson.fromJson(str,ShippingNoteInfo.class);
|
||||
sob=gson.fromJson(str2,OrderDetailBean.class);
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
while (true){
|
||||
String str= SPUtil.getSP(con,JTTConstant.JTT_DATA_NAME,JTTConstant.JTT_DATA_JTTORDER_KEY);
|
||||
if ("".equals(str)) {
|
||||
break;
|
||||
}
|
||||
sf=gson.fromJson(str, ShippingNoteInfo.class);
|
||||
try {
|
||||
Thread.sleep(sf.getInterval()+1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MsgUtil.addHdMsgWat(hd,66);
|
||||
try {
|
||||
Thread.sleep(6000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// sum++;
|
||||
// if(sum==3){
|
||||
// MsgUtil.addHdMsgWat(hd,67);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
//开始
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e("服务开启","-----");
|
||||
return START_STICKY;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
}
|
25
app/src/main/java/com/dahe/gldriver/third/MsgUtil.java
Normal file
25
app/src/main/java/com/dahe/gldriver/third/MsgUtil.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.dahe.gldriver.third;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/7/30 16:29
|
||||
* @description:
|
||||
*/
|
||||
public class MsgUtil {
|
||||
|
||||
public static void addHdMsgWat(Handler hd,int what){
|
||||
Message msg=Message.obtain();
|
||||
msg.what=what;
|
||||
hd.sendMessage(msg);
|
||||
}
|
||||
public static void addHdMsgWatBody(Handler hd,int what,String body){
|
||||
Message msg=Message.obtain();
|
||||
msg.what=what;
|
||||
msg.obj=body;
|
||||
hd.sendMessage(msg);
|
||||
}
|
||||
}
|
20
app/src/main/java/com/dahe/gldriver/third/SPUtil.java
Normal file
20
app/src/main/java/com/dahe/gldriver/third/SPUtil.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.dahe.gldriver.third;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class SPUtil {
|
||||
|
||||
private static SharedPreferences sp=null;
|
||||
public static String getSP(Context con, String dataname, String name){
|
||||
sp=con.getSharedPreferences(dataname,con.MODE_PRIVATE);
|
||||
return sp.getString(name,"");
|
||||
}
|
||||
|
||||
public static void insSP(Context con, String dataname, String name, String body){
|
||||
SharedPreferences.Editor editor=con.getSharedPreferences(dataname,con.MODE_PRIVATE).edit();
|
||||
editor.putString(name,body);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,17 @@
|
||||
package com.dahe.gldriver.ui
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Process
|
||||
import com.alct.mdp.MDPLocationCollectionManager
|
||||
import com.amap.api.location.AMapLocationClient
|
||||
import com.amap.api.maps.MapsInitializer
|
||||
import com.dahe.gldriver.BuildConfig
|
||||
import com.dahe.gldriver.base.App
|
||||
import com.dahe.gldriver.databinding.ActivityLauncherBinding
|
||||
import com.dahe.gldriver.third.JTTProcess
|
||||
import com.dahe.gldriver.third.SPUtil
|
||||
import com.dahe.gldriver.ui.account.LoginActivity
|
||||
import com.dahe.gldriver.utils.CommonPopUtils
|
||||
import com.dahe.gldriver.utils.SPUtils
|
||||
@ -47,6 +55,7 @@ class LauncherActivity : BaseActivity<ActivityLauncherBinding>() {
|
||||
AMapLocationClient.updatePrivacyShow(mContext, true, true)
|
||||
AMapLocationClient.updatePrivacyAgree(mContext, true)
|
||||
MapsInitializer.updatePrivacyAgree(this, true)
|
||||
initThird()
|
||||
goNext()
|
||||
}
|
||||
} else {
|
||||
@ -54,6 +63,24 @@ class LauncherActivity : BaseActivity<ActivityLauncherBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initThird() {
|
||||
val state: String = SPUtil.getSP(mContext, "state_data", "authorization_state")
|
||||
if ("1" != state) {
|
||||
try {
|
||||
//安联初始化
|
||||
if (packageName == getCurrentProcessName(this)) {
|
||||
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
|
||||
MDPLocationCollectionManager.initialize(this, BuildConfig.OPEN_AL_URL)
|
||||
}
|
||||
//初始化交通厅
|
||||
JTTProcess.init(application)
|
||||
SPUtil.insSP(mContext, "state_data", "authorization_state", "1")
|
||||
} catch (e: Exception) {
|
||||
SPUtil.insSP(mContext, "state_data", "authorization_state", "0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
mDisposable?.dispose()
|
||||
@ -86,4 +113,18 @@ class LauncherActivity : BaseActivity<ActivityLauncherBinding>() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentProcessName(context: Context): String? {
|
||||
var currentProcessName = ""
|
||||
val pid = Process.myPid()
|
||||
val mActivityManager = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||
if (mActivityManager.runningAppProcesses != null && mActivityManager.runningAppProcesses.size > 0) {
|
||||
for (appProcess in mActivityManager.runningAppProcesses) {
|
||||
if (appProcess.pid == pid) {
|
||||
currentProcessName = appProcess.processName
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentProcessName
|
||||
}
|
||||
}
|
@ -201,7 +201,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), RefreshCallBack {
|
||||
private fun initRecy() {
|
||||
adapter = binding.recyclerView.run {
|
||||
layoutManager = LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)
|
||||
setHasFixedSize(true)
|
||||
addItemDecoration(
|
||||
RecycleViewDivider(
|
||||
LinearLayout.VERTICAL,
|
||||
|
@ -1,12 +1,18 @@
|
||||
package com.dahe.gldriver.ui.waybill.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.alct.mdp.MDPLocationCollectionManager
|
||||
import com.alct.mdp.callback.OnResultListener
|
||||
import com.alct.mdp.model.Goods
|
||||
import com.alct.mdp.model.Image
|
||||
import com.alct.mdp.model.Location
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.dahe.gldriver.base.AppConfig
|
||||
import com.dahe.gldriver.bean.OcrPersonBean
|
||||
import com.dahe.gldriver.bean.LUInputBean
|
||||
import com.dahe.gldriver.bean.UpPicBean
|
||||
import com.dahe.gldriver.bean.WaybillPhoto
|
||||
import com.dahe.gldriver.databinding.ActivityWaybillUppicBinding
|
||||
@ -14,6 +20,7 @@ import com.dahe.gldriver.net.BaseObserver
|
||||
import com.dahe.gldriver.net.DataManager
|
||||
import com.dahe.gldriver.net.RxHttpCallBack
|
||||
import com.dahe.gldriver.oss.OssServiceUtil
|
||||
import com.dahe.gldriver.third.JTTProcess
|
||||
import com.dahe.gldriver.utils.GDLocationUtils
|
||||
import com.dahe.gldriver.utils.OcrUtils
|
||||
import com.dahe.gldriver.utils.OrderUtils
|
||||
@ -22,21 +29,20 @@ import com.dahe.mylibrary.adapter.GridImageAdapter.OnItemClickListener
|
||||
import com.dahe.mylibrary.base.BaseActivity
|
||||
import com.dahe.mylibrary.net.CommonResponseBean
|
||||
import com.dahe.mylibrary.utils.ActivityUtils
|
||||
import com.dahe.mylibrary.utils.BitmapUtil
|
||||
import com.dahe.mylibrary.utils.FileUtil
|
||||
import com.dahe.mylibrary.utils.LoadingUtils
|
||||
import com.dahe.mylibrary.utils.PopsUtils
|
||||
import com.dahe.mylibrary.utils.ToastUtils
|
||||
import com.dahe.mylibrary.weight.FullyGridLayoutManager
|
||||
import com.dahe.mylibrary.weight.GlideEngine
|
||||
import com.luck.picture.lib.basic.PictureSelector
|
||||
import com.luck.picture.lib.decoration.GridSpacingItemDecoration
|
||||
import com.luck.picture.lib.entity.LocalMedia
|
||||
import com.luck.picture.lib.utils.DensityUtil
|
||||
import com.luck.picture.lib.widget.SquareRelativeLayout
|
||||
import com.lxj.xpopup.XPopup
|
||||
import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener
|
||||
import com.lxj.xpopup.util.SmartGlideImageLoader
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
* @ClassName WaybillUpPicActivity
|
||||
@ -52,6 +58,9 @@ class WaybillUpPicActivity : BaseActivity<ActivityWaybillUppicBinding>() {
|
||||
var orderId: String = ""
|
||||
var waybillId: String = ""
|
||||
lateinit var latLng: LatLng
|
||||
lateinit var bdLatLng: LatLng
|
||||
|
||||
private val lub: LUInputBean = LUInputBean()
|
||||
|
||||
override fun initView(savedInstanceState: Bundle?) {
|
||||
upBean = UpPicBean()
|
||||
@ -89,11 +98,11 @@ class WaybillUpPicActivity : BaseActivity<ActivityWaybillUppicBinding>() {
|
||||
myAdapter.selectMax = 1
|
||||
myAdapter.setOnItemClickListener(object : OnItemClickListener {
|
||||
override fun onItemClick(v: View?, position: Int) {
|
||||
selGoodPic(type,myAdapter)
|
||||
selGoodPic(type, myAdapter)
|
||||
}
|
||||
|
||||
override fun openPicture() {
|
||||
selGoodPic(type,myAdapter)
|
||||
selGoodPic(type, myAdapter)
|
||||
}
|
||||
})
|
||||
adapter = myAdapter
|
||||
@ -177,59 +186,291 @@ class WaybillUpPicActivity : BaseActivity<ActivityWaybillUppicBinding>() {
|
||||
|
||||
|
||||
btnUnload.setOnClickListener {
|
||||
upBean.run {
|
||||
orderId = this@WaybillUpPicActivity.orderId
|
||||
waybillId = this@WaybillUpPicActivity.waybillId
|
||||
latitude = latLng.latitude.toString()
|
||||
longitude = latLng.longitude.toString()
|
||||
this.type = if (type == 1) "1" else "2"
|
||||
}
|
||||
|
||||
if (type == 1) {
|
||||
if (upBean.waybillPhotoList.find { it.type == "1" } == null) {
|
||||
showToast("请上传装货照片")
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
if (type == 2) {
|
||||
if (upBean.waybillPhotoList.find { it.type == "3" } == null) {
|
||||
showToast("请上传卸货照片")
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (upBean.waybillPhotoList.find { it.receiptType == "4" || it.receiptType == "5" } == null) {
|
||||
showToast("卸货请上传卸货回单照片")
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
DataManager.getInstance().driverLoadOrUnload(upBean)
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(mContext, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
if (1 == type) {
|
||||
ActivityUtils.startActivity(
|
||||
mContext,
|
||||
WaybillSuccActivity::class.java,
|
||||
intent.extras
|
||||
)
|
||||
//装货成功-开启轨迹上传
|
||||
OrderUtils.getInstance().upLocation(mContext)
|
||||
} else {
|
||||
OrderUtils.getInstance().stopUpLocation(mContext)
|
||||
ActivityUtils.startActivity(
|
||||
mContext,
|
||||
WaybillSuccActivity::class.java,
|
||||
intent.extras
|
||||
)
|
||||
}
|
||||
}
|
||||
}))
|
||||
subMit(type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun subMit(orderType: Int?) {
|
||||
upBean.run {
|
||||
orderId = this@WaybillUpPicActivity.orderId
|
||||
waybillId = this@WaybillUpPicActivity.waybillId
|
||||
latitude = latLng.latitude.toString()
|
||||
longitude = latLng.longitude.toString()
|
||||
type = if (orderType == 1) "1" else "2"
|
||||
}
|
||||
|
||||
if (orderType == 1) {
|
||||
if (upBean.waybillPhotoList.find { it.type == "1" } == null) {
|
||||
showToast("请上传装货照片")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (orderType == 2) {
|
||||
if (upBean.waybillPhotoList.find { it.type == "3" } == null) {
|
||||
showToast("请上传卸货照片")
|
||||
return
|
||||
}
|
||||
if (upBean.waybillPhotoList.find { it.receiptType == "4" || it.receiptType == "5" } == null) {
|
||||
showToast("卸货请上传卸货回单照片")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//装货
|
||||
// lub.latitude = latLng.latitude.toString()
|
||||
// lub.longitude = latLng.longitude.toString()
|
||||
// lub.locationAddress = binding.tvLoca.text.toString()
|
||||
// //todo imageId需确定
|
||||
// lub.imageId = upBean.waybillPhotoList.filter { it.type == "1" }.map { it.photoUrl.toInt() }
|
||||
// lub.waybillId = ""
|
||||
|
||||
val l = Location()
|
||||
l.baiduLongitude = bdLatLng.longitude
|
||||
l.baiduLatitude = bdLatLng.latitude
|
||||
l.location = binding.tvLoca.text.toString()
|
||||
l.time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date())
|
||||
|
||||
|
||||
|
||||
DataManager.getInstance().driverLoadOrUnload(upBean)
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(BaseObserver(mContext, object : RxHttpCallBack<Any>() {
|
||||
override fun onSuccess(t: CommonResponseBean<Any>) {
|
||||
super.onSuccess(t)
|
||||
if (1 == orderType) {
|
||||
ActivityUtils.startActivity(
|
||||
mContext,
|
||||
WaybillSuccActivity::class.java,
|
||||
intent.extras
|
||||
)
|
||||
//装货成功-开启轨迹上传
|
||||
OrderUtils.getInstance().upLocation(mContext)
|
||||
} else {
|
||||
OrderUtils.getInstance().stopUpLocation(mContext)
|
||||
ActivityUtils.startActivity(
|
||||
mContext,
|
||||
WaybillSuccActivity::class.java,
|
||||
intent.extras
|
||||
)
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun load(location: Location) {
|
||||
MDPLocationCollectionManager.pickup(mContext, "", location, object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "装货上传成功")
|
||||
|
||||
//上传安联和交通厅,平台-装货
|
||||
// JTTProcess.start(mContext, sob, "")
|
||||
upLoadImage()
|
||||
|
||||
}
|
||||
|
||||
override fun onFailure(p0: String?, p1: String?) {
|
||||
Log.e("上报安联失败(装货):", p0 + p1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun unLoad(location: Location) {
|
||||
MDPLocationCollectionManager.unload(mContext, "getShippingNoteNumber()", location,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "卸货上传成功")
|
||||
//交通厅
|
||||
// if (sob.getData().getReport() === 1) {
|
||||
// JTTProcess.stop(mContext, sob, "")
|
||||
// }
|
||||
//卸货状态-平台
|
||||
// hyr.dischargeCargo(lub)
|
||||
//卸货照片-安联
|
||||
upUnloadImage()
|
||||
|
||||
//卸货回单
|
||||
upTrafficSign()
|
||||
upTrafficReceipt()
|
||||
receiptImage()
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("上报安联失败(卸货):", s + s1)
|
||||
// MessageUtils().showCenMessage(con, s1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//上传安联装货
|
||||
fun upLoadImage() {
|
||||
///storage/emulated/0/Android/data/com.oneclouds.wangluohuoyun/files/Pictures/163124593063154.jpg
|
||||
val file: File = File("")
|
||||
val image = Image()
|
||||
val base: String = BitmapUtil.imageToBase64("path")
|
||||
image.fileData = "data:image/" + FileUtil.lastName(file) + ";base64," + base
|
||||
image.fileExt = FileUtil.lastName(file)
|
||||
image.fileName = FileUtil.fileName(file)
|
||||
image.imageTakenDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date())
|
||||
image.baiduLongitude = bdLatLng.longitude
|
||||
image.baiduLatitude = bdLatLng.latitude
|
||||
image.location = binding.tvLoca.text.toString()
|
||||
MDPLocationCollectionManager.uploadPickupImage(
|
||||
mContext,
|
||||
"sob.getData().getShippingNoteNumber()",
|
||||
image,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "装货照片上传成功")
|
||||
Toast.makeText(mContext, "上传成功", Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("上报安联失败(装货照片):", s + s1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//上传安联卸货
|
||||
fun upUnloadImage() {
|
||||
val file: File = File("path")
|
||||
val image = Image()
|
||||
val base = BitmapUtil.imageToBase64("path")
|
||||
image.fileData = "data:image/" + FileUtil.lastName(file) + ";base64," + base
|
||||
image.fileExt = FileUtil.lastName(file)
|
||||
image.fileName = FileUtil.fileName(file)
|
||||
image.imageTakenDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date())
|
||||
image.baiduLongitude = bdLatLng.longitude
|
||||
image.baiduLatitude = bdLatLng.latitude
|
||||
image.location = binding.tvLoca.text.toString()
|
||||
MDPLocationCollectionManager.uploadUnloadImage(
|
||||
mContext,
|
||||
"sob.getData().getShippingNoteNumber()",
|
||||
image,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "卸货照片上传成功")
|
||||
Toast.makeText(mContext, "上传成功", Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("上报安联失败(卸货照片):", s + s1)
|
||||
// SPUtil.insSP(con,"make","卸货",sob.getData().getShippingNoteNumber());
|
||||
// SPUtil.insSP(con,"make","卸货-"+sob.getData().getShippingNoteNumber(),gson.toJson(image));
|
||||
// Intent serviceIn=new Intent(con, MakeUpAlService.class);
|
||||
// startService(serviceIn);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//上传安联-签收
|
||||
fun upTrafficSign() {
|
||||
//安联
|
||||
val l = Location()
|
||||
l.baiduLongitude = latLng.longitude
|
||||
l.baiduLatitude = latLng.latitude
|
||||
l.location = binding.tvLoca.text.toString()
|
||||
l.time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date())
|
||||
val gs: List<Goods> = java.util.ArrayList()
|
||||
// for (wayChild in sob.getData().getWayChildren()) {
|
||||
// if (wid == wayChild.getId() + "") {
|
||||
// for (good in wayChild.getGoods()) {
|
||||
// val g = Goods()
|
||||
// g.goodsName = good.getGoodName()
|
||||
// g.unit = good.getGoodUnit()
|
||||
// g.itemNo = good.getId()
|
||||
// //实收
|
||||
// g.quantity = 1
|
||||
// //应收
|
||||
// g.receivedQuantity = 1
|
||||
// //破损
|
||||
// g.damageQuantity = 1
|
||||
// //丢失
|
||||
// g.quantity = 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
MDPLocationCollectionManager.sign(
|
||||
mContext,
|
||||
"sob.getData().getShippingNoteNumber()",
|
||||
l,
|
||||
gs,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "签收成功")
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("上报安联失败(签收):", s + s1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//上传安联-回单
|
||||
fun upTrafficReceipt() {
|
||||
//安联
|
||||
val l = Location()
|
||||
l.baiduLongitude = latLng.longitude
|
||||
l.baiduLatitude = latLng.latitude
|
||||
l.location = binding.tvLoca.text.toString()
|
||||
l.time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date())
|
||||
MDPLocationCollectionManager.pod(
|
||||
mContext,
|
||||
"sob.getData().getShippingNoteNumber()",
|
||||
l,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "回单上传成功")
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("上报安联失败(回单):", s + s1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//卸货回单照片
|
||||
fun receiptImage() {
|
||||
///storage/emulated/0/Android/data/com.oneclouds.wangluohuoyun/files/Pictures/163124593063154.jpg
|
||||
val file: File = File("")
|
||||
val image = Image()
|
||||
val base = BitmapUtil.imageToBase64("path")
|
||||
image.fileData = "data:image/" + FileUtil.lastName(file) + ";base64," + base
|
||||
image.fileExt = FileUtil.lastName(file)
|
||||
image.fileName = FileUtil.fileName(file)
|
||||
image.imageTakenDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date())
|
||||
image.baiduLongitude = latLng.longitude
|
||||
image.baiduLatitude = latLng.latitude
|
||||
image.location = binding.tvLoca.text.toString()
|
||||
MDPLocationCollectionManager.uploadPODImage(
|
||||
mContext,
|
||||
"sob.getData().getShippingNoteNumber()",
|
||||
image,
|
||||
object : OnResultListener {
|
||||
override fun onSuccess() {
|
||||
Log.e("上报安联", "回单照片上传成功")
|
||||
Toast.makeText(mContext, "上传成功", Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onFailure(s: String, s1: String) {
|
||||
Log.e("上报安联失败(回单照片):", s + s1)
|
||||
// SPUtil.insSP(con,"make","回单",sob.getData().getShippingNoteNumber());
|
||||
//// SPUtil.insSP(con,"make","回单-"+sob.getData().getShippingNoteNumber(),gson.toJson(image));
|
||||
//// Intent serviceIn=new Intent(con, MakeUpAlService.class);
|
||||
//// startService(serviceIn);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
private val mData: List<LocalMedia> = ArrayList()
|
||||
override fun initDate() {
|
||||
@ -247,6 +488,7 @@ class WaybillUpPicActivity : BaseActivity<ActivityWaybillUppicBinding>() {
|
||||
it.getLongitude()//经 度
|
||||
it.getLatitude()//纬 度
|
||||
latLng = LatLng(it.latitude, it.longitude)
|
||||
bdLatLng = GDLocationUtils.instance.convertGPSToBaidu(latLng)
|
||||
binding.tvLoca.text = it.address
|
||||
} else {
|
||||
showToast("定位失败,请检查定位权限是否开启")
|
||||
@ -255,7 +497,7 @@ class WaybillUpPicActivity : BaseActivity<ActivityWaybillUppicBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun selGoodPic(goodType:Int?,myAdapter: GridImageAdapter) {
|
||||
private fun selGoodPic(goodType: Int?, myAdapter: GridImageAdapter) {
|
||||
PopsUtils.getInstance().showSelPic(mContext, false, myAdapter) {
|
||||
OssServiceUtil.getInstance().run {
|
||||
asyncPutImage(it[0].realPath, this@WaybillUpPicActivity)
|
||||
@ -291,4 +533,6 @@ class WaybillUpPicActivity : BaseActivity<ActivityWaybillUppicBinding>() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -11,6 +11,8 @@ import android.os.Build
|
||||
import com.amap.api.location.AMapLocationClient
|
||||
import com.amap.api.location.AMapLocationClientOption
|
||||
import com.amap.api.location.AMapLocationListener
|
||||
import com.amap.api.maps.model.LatLng
|
||||
import com.baidu.mapapi.utils.CoordinateConverter
|
||||
import com.dahe.gldriver.R
|
||||
import com.dahe.gldriver.service.MyNotification
|
||||
|
||||
@ -118,6 +120,13 @@ class GDLocationUtils private constructor(){
|
||||
}
|
||||
}
|
||||
|
||||
fun convertGPSToBaidu(srLatLng: LatLng): LatLng {
|
||||
val converter = CoordinateConverter()
|
||||
converter.from(CoordinateConverter.CoordType.COMMON)
|
||||
converter.coord(com.baidu.mapapi.model.LatLng(srLatLng.latitude,srLatLng.longitude))
|
||||
return LatLng(converter.convert().latitude,converter.convert().longitude)
|
||||
}
|
||||
|
||||
|
||||
fun stopLocation(){
|
||||
if(null != mLocationClient){
|
||||
|
19
app/src/main/java/com/dahe/gldriver/utils/StringUtil.java
Normal file
19
app/src/main/java/com/dahe/gldriver/utils/StringUtil.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.dahe.gldriver.utils;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/8/7 17:54
|
||||
* @description:字符串工具类
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
public static String isNull(String in_str,String out_str){
|
||||
if(in_str==null || in_str.equals("null") || in_str.trim().equals("")){
|
||||
return out_str;
|
||||
}
|
||||
return in_str;
|
||||
}
|
||||
|
||||
|
||||
}
|
662
mylibrary/src/main/java/com/dahe/mylibrary/utils/BitmapUtil.java
Normal file
662
mylibrary/src/main/java/com/dahe/mylibrary/utils/BitmapUtil.java
Normal file
@ -0,0 +1,662 @@
|
||||
package com.dahe.mylibrary.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.ExifInterface;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2022/3/7 17:55
|
||||
* @description:
|
||||
*/
|
||||
public class BitmapUtil {
|
||||
|
||||
private static RequestOptions options;
|
||||
|
||||
static {
|
||||
initOptions();
|
||||
}
|
||||
|
||||
private static void initOptions() {
|
||||
options = new RequestOptions()
|
||||
// .placeholder(R.drawable.ic_image_default) //加载成功之前占位图
|
||||
// .error(R.drawable.ic_image_default) //加载错误之后的错误图
|
||||
.dontAnimate()
|
||||
// .override(400,400) //指定图片的尺寸
|
||||
//指定图片的缩放类型为fitCenter (等比例缩放图片,宽或者是高等于ImageView的宽或者是高。)
|
||||
// .fitCenter()
|
||||
//指定图片的缩放类型为centerCrop (等比例缩放图片,直到图片的狂高都大于等于ImageView的宽度,然后截取中间的显示。)
|
||||
// .centerCrop()//指定图片的缩放类型为centerCrop
|
||||
// .circleCrop()//指定图片为圆形
|
||||
// .skipMemoryCache(true) //跳过内存缓存
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL); //缓存所有版本的图像
|
||||
// .diskCacheStrategy(DiskCacheStrategy.NONE) //跳过磁盘缓存
|
||||
// .diskCacheStrategy(DiskCacheStrategy.DATA) //只缓存原来分辨率的图片
|
||||
// .diskCacheStrategy(DiskCacheStrategy.RESOURCE); //只缓存最终的图片
|
||||
}
|
||||
|
||||
private static RequestOptions buildOptions(@DrawableRes int res) {
|
||||
RequestOptions options = new RequestOptions()
|
||||
.placeholder(res) //加载成功之前占位图
|
||||
.error(res) //加载错误之后的错误图
|
||||
.dontAnimate()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示gif
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showGIF(Context context, String url, ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.asGif()
|
||||
.load(url)
|
||||
.apply(options)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示gif,自定义默认图
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param res
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showGIF(Context context, String url, @DrawableRes int res, ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.asGif()
|
||||
.load(url)
|
||||
.apply(buildOptions(res))
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示图片,自定义option
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showImage(Context context, String url, RequestOptions options, ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(options)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示图片,先显示默认图
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showImage(Context context, String url, ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(options)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示图片,先显示默认图
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showImage(Context context, String url, ImageView imageView, RequestListener<Drawable> callback) {
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.apply(options)
|
||||
.listener(callback)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示图片,先显示默认图
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showRadiusImage(Context context, String url, int radius, ImageView imageView) {
|
||||
|
||||
|
||||
// RequestOptions options = new RequestOptions().transform(new CenterCrop(), new RoundedCorners(DisplayUtil.dipToPixel(radius)));
|
||||
// options
|
||||
// .dontAnimate()
|
||||
// .diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
//
|
||||
// Glide.with(context)
|
||||
// .load(url)
|
||||
// .apply(options)
|
||||
// .into(imageView);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示图片,自己设定默认图
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param imageView
|
||||
*/
|
||||
public static void showImage(Context context, String url, @DrawableRes int placeholder, ImageView imageView) {
|
||||
Glide.with(context)
|
||||
.asBitmap().fitCenter()
|
||||
.load(url)
|
||||
.apply(buildOptions(placeholder))
|
||||
.into(imageView);
|
||||
|
||||
// LogUtils.d(AppConstants.LOG_TAG_PIC, "图片url = " + (!TextUtils.isEmpty(url) ? url : "url为空"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载本地图片
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap getLocalBitmap(String url) {
|
||||
try {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(url, options);
|
||||
//计算采样率
|
||||
options.inSampleSize = calculateInSampleSize(options, 768, 1024);
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(url, options);
|
||||
//旋转图片
|
||||
int d = getPictureDegree(url);
|
||||
if (d != 0) {
|
||||
bitmap = rotateBitmap(bitmap, d);
|
||||
}
|
||||
return bitmap;
|
||||
} catch (OutOfMemoryError e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void getCacheImage(Context context, String imgUrl, SimpleTarget<Bitmap> callback) {
|
||||
Glide.with(context).asBitmap().load(imgUrl).into(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件生成Drawable
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static Drawable getDrawable(String path) {
|
||||
Drawable bd = BitmapDrawable.createFromPath(path);
|
||||
return bd;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回Bitmap显示像素所占位数
|
||||
*
|
||||
* @param config
|
||||
* @return
|
||||
*/
|
||||
public static int getBytesPerPixel(Bitmap.Config config) {
|
||||
if (config == Bitmap.Config.ARGB_8888) {
|
||||
return 4;
|
||||
} else if (config == Bitmap.Config.RGB_565) {
|
||||
return 2;
|
||||
} else if (config == Bitmap.Config.ARGB_4444) {
|
||||
return 2;
|
||||
} else if (config == Bitmap.Config.ALPHA_8) {
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片旋转角度
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static int getPictureDegree(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算图片的缩放值
|
||||
*
|
||||
* @param options
|
||||
* @param reqWidth
|
||||
* @param reqHeight
|
||||
* @return
|
||||
*/
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
final int heightRatio = Math.round((float) height / (float) reqHeight);
|
||||
final int widthRatio = Math.round((float) width / (float) reqWidth);
|
||||
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
|
||||
}
|
||||
return inSampleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 旋转图片
|
||||
*
|
||||
* @param bitmap
|
||||
* @param degree
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap rotateBitmap(Bitmap bitmap, int degree) {
|
||||
if (bitmap != null) {
|
||||
Matrix m = new Matrix();
|
||||
m.postRotate(degree);
|
||||
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
|
||||
return bitmap;
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存Bitmap为文件
|
||||
*
|
||||
* @param bitmap
|
||||
* @param path
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public static File saveBitmap(Bitmap bitmap, String path, String fileName) {
|
||||
FileOutputStream outputStream = null;
|
||||
try {
|
||||
File mFolder = new File(path);
|
||||
if (!mFolder.exists()) {
|
||||
mFolder.mkdirs();
|
||||
}
|
||||
File file = new File(mFolder, fileName);
|
||||
outputStream = new FileOutputStream(file);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
bitmap.recycle();
|
||||
return file;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定宽高,根据宽高计算采样率压缩图片 并 旋转图片
|
||||
*
|
||||
* @param photoPath 原图片路径
|
||||
* @param reqWidth 要求的宽
|
||||
* @param reqHeight 要求的高
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap zipBitmapWithReq(String photoPath, int reqWidth, int reqHeight) {
|
||||
// 压缩图片
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
opts.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(photoPath, opts);
|
||||
opts.inSampleSize = BitmapUtil.calculateInSampleSize(opts, reqWidth, reqHeight);
|
||||
opts.inJustDecodeBounds = false;
|
||||
return BitmapFactory.decodeFile(photoPath, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定 质量百分比 压缩图片
|
||||
*
|
||||
* @param bitmap
|
||||
* @param quality 质量压缩比例(100为不压缩)
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap zipBitmapWithQuality(Bitmap bitmap, int quality) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
|
||||
byte[] bytes = baos.toByteArray();
|
||||
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定宽高,根据宽高计算采样率压缩图片并存为文件
|
||||
*
|
||||
* @param photoPath 原图片路径
|
||||
* @param saveFilePath 压缩后图片保存路径
|
||||
* @param fileName 压缩后图片文件名
|
||||
* @param reqWidth 要求的宽
|
||||
* @param reqHeight 要求的高
|
||||
* @return
|
||||
*/
|
||||
public static File zipBitmapAndSave(String photoPath, String saveFilePath, String fileName, int reqWidth, int reqHeight) {
|
||||
Bitmap bitmap = BitmapUtil.zipBitmapWithReq(photoPath, reqWidth, reqHeight);
|
||||
// 旋转图片
|
||||
bitmap = BitmapUtil.rotateBitmap(bitmap, BitmapUtil.getPictureDegree(photoPath));
|
||||
return BitmapUtil.saveBitmap(bitmap, saveFilePath, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定宽高,根据宽高计算采样率,
|
||||
* 给定质量压缩比例
|
||||
* 多重压缩图片并存为文件
|
||||
*
|
||||
* @param photoPath 原图片路径
|
||||
* @param saveFilePath 压缩后图片保存路径
|
||||
* @param fileName 压缩后图片文件名
|
||||
* @param reqWidth 要求的宽
|
||||
* @param reqHeight 要求的高
|
||||
* @param quality 质量压缩比例(100为不压缩)
|
||||
* @return
|
||||
*/
|
||||
public static File zipBitmapMultiAndSave(String photoPath, String saveFilePath, String fileName, int reqWidth, int reqHeight, int quality) {
|
||||
Bitmap bit = zipBitmapWithReq(photoPath, reqWidth, reqHeight);
|
||||
bit = zipBitmapWithQuality(bit, quality);
|
||||
// 旋转图片
|
||||
bit = BitmapUtil.rotateBitmap(bit, BitmapUtil.getPictureDegree(photoPath));
|
||||
return BitmapUtil.saveBitmap(bit, saveFilePath, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把Bitmap转Byte
|
||||
*/
|
||||
public static byte[] bitmap2Bytes(Bitmap bm) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据高度放大, 并显示中间部分
|
||||
*
|
||||
* @param bitmap
|
||||
* @param windowWidth
|
||||
* @param windowHeight
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap compressBitmap(Bitmap bitmap, int windowWidth, int windowHeight) {
|
||||
Matrix matrix = new Matrix();
|
||||
int bitmapWidth = bitmap.getWidth();
|
||||
int bitmapHeight = bitmap.getHeight();
|
||||
float scaleY = windowHeight > bitmapHeight ? Float.valueOf(windowHeight) / Float.valueOf(bitmapHeight) : 1.0f;
|
||||
matrix.postScale(scaleY, scaleY);
|
||||
int offsetX = scaleY > 1 ? (int) ((bitmapWidth * scaleY - bitmapWidth) / 2) : 0;
|
||||
int showHeight = windowHeight > bitmapHeight ? windowHeight : bitmapHeight;
|
||||
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true);
|
||||
try {
|
||||
return Bitmap.createBitmap(bitmap, offsetX, 0, windowWidth, showHeight);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Bitmap getTransparentBitmap(Bitmap sourceImg, int number) {
|
||||
int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
|
||||
sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg.getWidth(), sourceImg.getHeight());// 获得图片的ARGB值
|
||||
number = number * 255 / 100;
|
||||
for (int i = 0; i < argb.length; i++) {
|
||||
argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);
|
||||
}
|
||||
sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
return sourceImg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 截取ScrollView显示内容
|
||||
*
|
||||
* @param scrollView
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap getScrollViewBitmap(ScrollView scrollView) {
|
||||
int h = 0;
|
||||
Bitmap bitmap = null;
|
||||
for (int i = 0; i < scrollView.getChildCount(); i++) {
|
||||
h += scrollView.getChildAt(i).getHeight();
|
||||
scrollView.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff"));
|
||||
}
|
||||
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565);
|
||||
final Canvas canvas = new Canvas(bitmap);
|
||||
scrollView.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 截取WebView显示内容
|
||||
*
|
||||
* @param webView
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap getWebViewBitmap(WebView webView) {
|
||||
Bitmap bm = null;
|
||||
try {
|
||||
int height = (int) (webView.getContentHeight() * webView.getScale());
|
||||
int width = webView.getWidth();
|
||||
int pH = webView.getHeight();
|
||||
if(width <= 0){
|
||||
width = 100;
|
||||
}
|
||||
if(height <= 0){
|
||||
height = 100;
|
||||
}
|
||||
bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
|
||||
Canvas canvas = new Canvas(bm);
|
||||
int top = height;
|
||||
while (top > 0) {
|
||||
if (top < pH) {
|
||||
top = 0;
|
||||
} else {
|
||||
top -= pH;
|
||||
}
|
||||
canvas.save();
|
||||
canvas.clipRect(0, top, width, top + pH);
|
||||
webView.scrollTo(0, top);
|
||||
webView.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
if (bm != null) {
|
||||
bm.recycle();
|
||||
bm = null;
|
||||
}
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过drawable文件名获取Drawable
|
||||
*
|
||||
* @param context
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static Drawable getDrawableFromName(Context context, String name) {
|
||||
try {
|
||||
Resources resources = context.getResources();
|
||||
return resources.getDrawable(resources.getIdentifier(name, "drawable", context.getPackageName()));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* base64字符串转换bitmap
|
||||
*
|
||||
* @param base64
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap base64ToBitmap(String base64) {
|
||||
Bitmap bitmap = null;
|
||||
try {
|
||||
byte[] bitmapArray = Base64.decode(base64.split(",")[1], Base64.DEFAULT);
|
||||
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载图片
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param listener
|
||||
*/
|
||||
public static void downloadImage(Context context, String url, ImageDownloadListener listener) {
|
||||
try {
|
||||
listener.start();
|
||||
Glide.with(context)
|
||||
.downloadOnly()
|
||||
.load(url)
|
||||
.addListener(new RequestListener<File>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
|
||||
listener.fail(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
|
||||
listener.success(BitmapFactory.decodeFile(resource.getAbsolutePath()) , resource.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
}).submit();
|
||||
} catch (Exception e) {
|
||||
if (listener != null) listener.fail(new GlideException(e.getMessage()));
|
||||
} finally {
|
||||
if (listener != null) listener.finish();
|
||||
}
|
||||
}
|
||||
|
||||
public interface ImageDownloadListener {
|
||||
/**
|
||||
* 当前线程
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* 子线程
|
||||
*
|
||||
* @param bitmap
|
||||
*/
|
||||
void success(Bitmap bitmap , String path);
|
||||
|
||||
/**
|
||||
* 子线程
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
void fail(GlideException e);
|
||||
|
||||
/**
|
||||
* 当前线程
|
||||
*/
|
||||
void finish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将图片转换成Base64编码的字符串
|
||||
*/
|
||||
public static String imageToBase64(String path){
|
||||
if(TextUtils.isEmpty(path)){
|
||||
return null;
|
||||
}
|
||||
InputStream is = null;
|
||||
byte[] data = null;
|
||||
String result = null;
|
||||
try{
|
||||
is = new FileInputStream(path);
|
||||
//创建一个字符流大小的数组。
|
||||
data = new byte[is.available()];
|
||||
//写入数组
|
||||
is.read(data);
|
||||
//用默认的编码格式进行编码
|
||||
result = Base64.encodeToString(data,Base64.DEFAULT);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(null !=is){
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -86,4 +86,24 @@ public class FileUtil {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String lastName(File file){
|
||||
if(file==null) return null;
|
||||
String filename = file.getName();
|
||||
if(filename.lastIndexOf(".")==-1){
|
||||
return "";//文件没有后缀名的情况
|
||||
}
|
||||
//此时返回的是带有 . 的后缀名,
|
||||
return filename.substring(filename.lastIndexOf(".")+1);
|
||||
}
|
||||
|
||||
public static String fileName(File file){
|
||||
if(file==null) return null;
|
||||
String filename = file.getName();
|
||||
if(filename.lastIndexOf(".")==-1){
|
||||
return "";//文件没有后缀名的情况
|
||||
}
|
||||
//此时返回的是带有 . 的后缀名,
|
||||
return filename.substring(0,filename.lastIndexOf("."));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user