fixed conflict
This commit is contained in:
@@ -10,11 +10,18 @@ import com.mogo.cloud.tanlu.api.ITanluUploadCallback;
|
||||
import com.mogo.cloud.tanlu.bean.InformationBody;
|
||||
import com.mogo.cloud.tanlu.bean.UploadInfo;
|
||||
import com.mogo.cloud.tanlu.bean.UploadResult;
|
||||
import com.mogo.cloud.tanlu.constant.HttpConstant;
|
||||
import com.zhidao.cosupload.DbPriorityConfig;
|
||||
import com.zhidao.cosupload.callback.CosStatusCallback;
|
||||
import com.zhidao.cosupload.callback.CosStatusCallbackManager;
|
||||
import com.zhidao.cosupload.manager.CosUploadManagerImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mogo.cloud.tanlu.utils.FileUtilKt.deletePicFile;
|
||||
import static com.mogo.cloud.tanlu.utils.FileUtilKt.getVideoPicPath;
|
||||
import static com.mogo.cloud.tanlu.utils.FileUtilKt.getVideoThumbnail;
|
||||
import static com.mogo.cloud.tanlu.utils.TanluUtils.isVideo;
|
||||
|
||||
/**
|
||||
@@ -23,7 +30,6 @@ import static com.mogo.cloud.tanlu.utils.TanluUtils.isVideo;
|
||||
* @since 2021/1/21
|
||||
*/
|
||||
public class CosUpload implements CosStatusCallback {
|
||||
private static final String TAG = "liyz";
|
||||
private static CosUpload sInstance;
|
||||
private Context mContext;
|
||||
private String mPicEventId;
|
||||
@@ -31,7 +37,8 @@ public class CosUpload implements CosStatusCallback {
|
||||
private UploadInfo mUploadInfo;
|
||||
private String mCosVideoUrl;
|
||||
private String mCosPicUrl;
|
||||
|
||||
private List<String> filePath = new ArrayList<>();
|
||||
private String videoCoverImage;
|
||||
|
||||
private CosUpload(Context context) {
|
||||
mContext = context;
|
||||
@@ -55,54 +62,58 @@ public class CosUpload implements CosStatusCallback {
|
||||
}
|
||||
|
||||
public void uploadInfo(UploadInfo info, ITanluUploadCallback callback) {
|
||||
Log.d(TAG, "info.getFilePath() = " + info.getFilePath().toString());
|
||||
Log.d(HttpConstant.TANLU, "videoPath = " + info.getFilePath());
|
||||
if (isVideo(info.getFilePath())) {
|
||||
videoCoverImage = getVideoPicPath();
|
||||
Log.d(HttpConstant.TANLU, "videoCoverImage = " + videoCoverImage);
|
||||
boolean isSuccess = getVideoThumbnail(info.getFilePath(), videoCoverImage);
|
||||
Log.d(HttpConstant.TANLU, "isSuccess = " + isSuccess);
|
||||
filePath.add(info.getFilePath());
|
||||
filePath.add(videoCoverImage);
|
||||
} else {
|
||||
videoCoverImage = null;
|
||||
filePath.add(info.getFilePath());
|
||||
}
|
||||
|
||||
Log.e(HttpConstant.TANLU, "filePath.size() = " + filePath.size());
|
||||
CosUploadManagerImpl.getInstance(mContext.getApplicationContext())
|
||||
.upload(info.getFilePath(), mPicEventId, DbPriorityConfig.PRIORITY_HIGH);
|
||||
.upload(filePath, mPicEventId, DbPriorityConfig.PRIORITY_HIGH);
|
||||
mCallback = callback;
|
||||
mUploadInfo = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartUpload(String eventId, String localPath) {
|
||||
Log.d(TAG, "onStartUpload ----> ");
|
||||
Log.d(HttpConstant.TANLU, "onStartUpload ----> ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadCosCompleted(String cosPath, String eventId, String downloadUrl, String localPath) {
|
||||
Log.d(TAG, "uploadCosCompleted ----> cosPath =" + cosPath + "--eventId =" + eventId);
|
||||
Log.d(TAG, "uploadCosCompleted ----> downloadUrl =" + downloadUrl + "--localPath =" + localPath);
|
||||
// if (localPath.endsWith("mp4")) { //如何判断视频图片
|
||||
// //如果是视频文件或者缩略图文件
|
||||
// if (localPath.endsWith("mp4")) {
|
||||
// mCosVideoUrl = downloadUrl;
|
||||
// } else {
|
||||
// mCosPicUrl = downloadUrl;
|
||||
// }
|
||||
//
|
||||
// if (mCosVideoUrl != null && mCosPicUrl != null) {
|
||||
// //上传录像以及缩略图成功
|
||||
// sendInformation();
|
||||
// }
|
||||
// } else {
|
||||
// //上传图片成功, 如果是上报路况,直接上传
|
||||
// Log.d(TAG, "uploadCosCompleted 分享成功 ---- mType = $mType");
|
||||
// }
|
||||
|
||||
if (isVideo(localPath)) { //如果是视频 TODO
|
||||
Log.d(HttpConstant.TANLU, "uploadCosCompleted ----> cosPath =" + cosPath + "--eventId =" + eventId);
|
||||
Log.d(HttpConstant.TANLU, "uploadCosCompleted ----> downloadUrl =" + downloadUrl + "--localPath =" + localPath);
|
||||
if (filePath.size() == 2) {
|
||||
if (isVideo(localPath)) { //如果是视频 localPath
|
||||
Log.e(HttpConstant.TANLU, "1111111-------");
|
||||
mCosVideoUrl = downloadUrl;
|
||||
} else {
|
||||
Log.e(HttpConstant.TANLU, "22222222------");
|
||||
mCosPicUrl = downloadUrl;
|
||||
}
|
||||
|
||||
Log.d(HttpConstant.TANLU, "mCosVideoUrl = " + mCosVideoUrl + " >>>mCosPicUrl = " + mCosPicUrl);
|
||||
if (mCosPicUrl != null && mCosVideoUrl != null) {
|
||||
sendInformation();
|
||||
}
|
||||
} else {
|
||||
Log.e(HttpConstant.TANLU, "333333------");
|
||||
mCosPicUrl = downloadUrl;
|
||||
sendInformation();
|
||||
}
|
||||
|
||||
//TODO
|
||||
mCosVideoUrl = downloadUrl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadCosFailed(String cosPath, String eventId, String localPath) {
|
||||
Log.e(TAG, "uploadCosFailed ----> cosPath = " + cosPath + "--eventId =" + eventId + "--localPath =" + localPath);
|
||||
Log.e(HttpConstant.TANLU, "uploadCosFailed ----> cosPath = " + cosPath + "--eventId =" + eventId + "--localPath =" + localPath);
|
||||
sendInformation();
|
||||
}
|
||||
|
||||
@@ -112,22 +123,34 @@ public class CosUpload implements CosStatusCallback {
|
||||
}
|
||||
|
||||
private void sendInformation() {
|
||||
//清理数据
|
||||
if (filePath != null) {
|
||||
filePath.clear();
|
||||
}
|
||||
|
||||
//删除本地生成的图片封面
|
||||
if (videoCoverImage != null) {
|
||||
boolean isDeleteSuccess = deletePicFile(videoCoverImage);
|
||||
}
|
||||
|
||||
UploadManager.getInstance(mContext.getApplicationContext()).loadUpload(getInformation(), new ITanluUploadCallback() {
|
||||
@Override
|
||||
public void onSuccess(BaseData<UploadResult> result) {
|
||||
Log.d(TAG, "uploadRoadInfo result.id = " + result.getResult().id);
|
||||
if (result != null && result.getResult() != null) {
|
||||
Log.d(HttpConstant.TANLU, "uploadRoadInfo result.id = " + result.getResult().id);
|
||||
}
|
||||
mCallback.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int code) {
|
||||
Log.d(TAG, " uploadRoadInfo code = " + code);
|
||||
Log.d(HttpConstant.TANLU, " uploadRoadInfo code = " + code);
|
||||
mCallback.onFailure(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.d(TAG, "uploadRoadInfo onError e = " + e);
|
||||
Log.d(HttpConstant.TANLU, "uploadRoadInfo onError e = " + e);
|
||||
mCallback.onError(e);
|
||||
}
|
||||
});
|
||||
@@ -137,11 +160,10 @@ public class CosUpload implements CosStatusCallback {
|
||||
InformationBody informationBody = new InformationBody();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("thumbnail", mCosVideoUrl);
|
||||
jsonObject.addProperty("url", mCosPicUrl);
|
||||
jsonObject.addProperty("thumbnail", mCosPicUrl);
|
||||
jsonObject.addProperty("url", mCosVideoUrl);
|
||||
jsonArray.add(jsonObject);
|
||||
Log.d(TAG, "mCosVideoUrl = " + mCosVideoUrl + "--mCosPicUrl =" + mCosPicUrl);
|
||||
Log.d(TAG, "jsonArray.toString() = " + jsonArray.toString());
|
||||
Log.d(HttpConstant.TANLU, "jsonArray.toString() = " + jsonArray.toString());
|
||||
|
||||
informationBody.setData(jsonArray.toString());
|
||||
informationBody.setAddr(mUploadInfo.getAddr());
|
||||
|
||||
@@ -3,21 +3,16 @@ package com.mogo.cloud.tanlu;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.mogo.cloud.commons.network.BaseData;
|
||||
import com.mogo.cloud.commons.network.RetrofitFactory;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.tanlu.api.IRoadInfoSearchCallback;
|
||||
import com.mogo.cloud.tanlu.api.ITanluUploadCallback;
|
||||
import com.mogo.cloud.tanlu.bean.InformationBody;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfoRequest;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfos;
|
||||
import com.mogo.cloud.tanlu.bean.UploadResult;
|
||||
import com.mogo.cloud.tanlu.bean.location.Location;
|
||||
import com.mogo.cloud.tanlu.constant.HttpConstant;
|
||||
import com.mogo.cloud.tanlu.net.TanluApiService;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,7 +28,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||
* @since 2021/1/21
|
||||
*/
|
||||
public class MogoRoadSearchManager {
|
||||
private static final String TAG = "MogoRoadSearchManager";
|
||||
private static MogoRoadSearchManager sInstance;
|
||||
private Context mContext;
|
||||
private TanluApiService apiService;
|
||||
@@ -88,24 +82,24 @@ public class MogoRoadSearchManager {
|
||||
.subscribe(new Observer<BaseData<RoadInfos>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.d(TAG, "queryRoadInfos onSubscribe ");
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onSubscribe ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseData<RoadInfos> roadInfos) {
|
||||
Log.d(TAG, "queryRoadInfos onNext roadInfos = " + roadInfos.getResult().getData());
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onNext roadInfos = " + roadInfos.getResult().getData());
|
||||
callback.onSuccess(roadInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.d(TAG, "queryRoadInfos onError ");
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onError ");
|
||||
callback.onError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.d(TAG, "queryRoadInfos onComplete ");
|
||||
Log.d(HttpConstant.TANLU, "queryRoadInfos onComplete ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,36 +1,9 @@
|
||||
package com.mogo.cloud.tanlu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mogo.cloud.commons.network.RetrofitFactory;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.tanlu.api.IRoadInfoSearchCallback;
|
||||
import com.mogo.cloud.tanlu.api.ITanluUploadCallback;
|
||||
import com.mogo.cloud.tanlu.bean.InformationBody;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfoRequest;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfos;
|
||||
import com.mogo.cloud.tanlu.bean.UploadInfo;
|
||||
import com.mogo.cloud.tanlu.bean.UploadResult;
|
||||
import com.mogo.cloud.tanlu.bean.location.Location;
|
||||
import com.mogo.cloud.tanlu.net.TanluApiService;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.zhidao.cosupload.DbPriorityConfig;
|
||||
import com.zhidao.cosupload.callback.CosStatusCallback;
|
||||
import com.zhidao.cosupload.manager.CosUploadManagerImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
@@ -38,7 +11,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||
* @since 2021/1/21
|
||||
*/
|
||||
public class MogoUploadManager {
|
||||
private static final String TAG = "liyz";
|
||||
private static MogoUploadManager sInstance;
|
||||
private Context mContext;
|
||||
|
||||
@@ -53,7 +25,6 @@ public class MogoUploadManager {
|
||||
sInstance = new MogoUploadManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,30 +7,17 @@ import com.google.gson.Gson;
|
||||
import com.mogo.cloud.commons.network.BaseData;
|
||||
import com.mogo.cloud.commons.network.RetrofitFactory;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
import com.mogo.cloud.tanlu.api.IRoadInfoSearchCallback;
|
||||
import com.mogo.cloud.tanlu.api.ITanluUploadCallback;
|
||||
import com.mogo.cloud.tanlu.bean.InformationBody;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfoRequest;
|
||||
import com.mogo.cloud.tanlu.bean.RoadInfos;
|
||||
import com.mogo.cloud.tanlu.bean.UploadResult;
|
||||
import com.mogo.cloud.tanlu.bean.location.Location;
|
||||
import com.mogo.cloud.tanlu.bean.location.MogoLocation;
|
||||
import com.mogo.cloud.tanlu.constant.HttpConstant;
|
||||
import com.mogo.cloud.tanlu.net.TanluApiService;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.RequestOptions;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
@@ -39,7 +26,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||
* @since 2021/1/21
|
||||
*/
|
||||
public class UploadManager {
|
||||
private static final String TAG = "UploadManager";
|
||||
private static UploadManager sInstance;
|
||||
private Context mContext;
|
||||
private TanluApiService apiService;
|
||||
@@ -75,37 +61,36 @@ public class UploadManager {
|
||||
Gson gson = new Gson();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// map.put("sn", MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn()); //TODO
|
||||
// map.put("sn", "F803EB2046PZD00228");
|
||||
// map.put("data", gson.toJson(informationBody));
|
||||
// Log.d(TAG, "info = " + gson.toJson(informationBody));
|
||||
map.put("sn", "ZD802C1938L10797");
|
||||
map.put("data", "{\"addr\":\"北京市东城区小黄庄北街2号靠近中国银行(北京安贞桥支行)\",\"areaCode\":\"110101\",\"areaName\":\"东城区\",\"cityCode\":\"010\",\"cityName\":\"北京市\",\"data\":\"[{\\\"thumbnail\\\":\\\"http://petchfile-1255510688.cos.ap-beijing.myqcloud.com/CarPad/com.zhidao.roadcondition/F803EB2046PZD00228/F803EB2046PZD00228_20210121165329/Thumbnail1611219200669.jpg\\\",\\\"url\\\":\\\"http://petchfile-1255510688.cos.ap-beijing.myqcloud.com/CarPad/com.zhidao.roadcondition/F803EB2046PZD00228/F803EB2046PZD00228_20210121165329/compress_video_20210121165307.mp4\\\"}]\",\"direction\":0.0,\"fromType\":\"2\",\"generateTime\":1611219213616,\"infoTimeout\":240,\"infoType\":1,\"isShare\":false,\"lat\":39.968317,\"lon\":116.410892,\"mainInfoId\":0,\"poiType\":\"10008\",\"provinceName\":\"北京市\",\"sn\":\"F803EB2046PZD00228\",\"speed\":0.0,\"street\":\"小黄庄北街\",\"trafficInfoType\":\"\",\"type\":1,\"uid\":0}");
|
||||
map.put("sn", "F803EB2046PZD00228");
|
||||
map.put("data", gson.toJson(informationBody));
|
||||
Log.d(HttpConstant.TANLU, "info = " + gson.toJson(informationBody));
|
||||
// map.put("sn", "ZD802C1938L10797");
|
||||
// map.put("data", "{\"addr\":\"北京市东城区小黄庄北街2号靠近中国银行(北京安贞桥支行)\",\"areaCode\":\"110101\",\"areaName\":\"东城区\",\"cityCode\":\"010\",\"cityName\":\"北京市\",\"data\":\"[{\\\"thumbnail\\\":\\\"http://petchfile-1255510688.cos.ap-beijing.myqcloud.com/CarPad/com.zhidao.roadcondition/F803EB2046PZD00228/F803EB2046PZD00228_20210121165329/Thumbnail1611219200669.jpg\\\",\\\"url\\\":\\\"http://petchfile-1255510688.cos.ap-beijing.myqcloud.com/CarPad/com.zhidao.roadcondition/F803EB2046PZD00228/F803EB2046PZD00228_20210121165329/compress_video_20210121165307.mp4\\\"}]\",\"direction\":0.0,\"fromType\":\"2\",\"generateTime\":1611219213616,\"infoTimeout\":240,\"infoType\":1,\"isShare\":false,\"lat\":39.968317,\"lon\":116.410892,\"mainInfoId\":0,\"poiType\":\"10008\",\"provinceName\":\"北京市\",\"sn\":\"F803EB2046PZD00228\",\"speed\":0.0,\"street\":\"小黄庄北街\",\"trafficInfoType\":\"\",\"type\":1,\"uid\":0}");
|
||||
|
||||
Log.d(TAG, "sn = " + MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||
Log.d(HttpConstant.TANLU, "sn = " + MoGoAiCloudClient.getInstance().getAiCloudClientConfig().getSn());
|
||||
apiService.uploadInformation(map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseData<UploadResult>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.d(TAG, "onSubscribe -----> ");
|
||||
Log.d(HttpConstant.TANLU, "onSubscribe -----> ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseData<UploadResult> result) {
|
||||
Log.d(TAG, "onNext id = -----> " + result.getResult().id);
|
||||
callback.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "onError -----> e " + e);
|
||||
Log.e(HttpConstant.TANLU, "onError -----> e " + e);
|
||||
callback.onError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.d(TAG, "onComplete -----> ");
|
||||
Log.d(HttpConstant.TANLU, "onComplete -----> ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mogo.cloud.tanlu.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
@@ -9,7 +8,8 @@ import java.util.List;
|
||||
*/
|
||||
public class UploadInfo {
|
||||
|
||||
private List<String> filePath; //文件路径
|
||||
// private List<String> filePath; //文件路径
|
||||
private String filePath; //文件路径
|
||||
|
||||
// String TYPE_TRAFFIC_CHECK = "10002"; //交通检查
|
||||
// String TYPE_CLOSURE = "10003"; //封路
|
||||
@@ -50,16 +50,22 @@ public class UploadInfo {
|
||||
private int infoTimeout; //过期事件
|
||||
private boolean isShare; // 是否分享给附近车机
|
||||
|
||||
|
||||
|
||||
public List<String> getFilePath() {
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(List<String> filePath) {
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
// public List<String> getFilePath() {
|
||||
// return filePath;
|
||||
// }
|
||||
//
|
||||
// public void setFilePath(List<String> filePath) {
|
||||
// this.filePath = filePath;
|
||||
// }
|
||||
|
||||
public String getPoiType() {
|
||||
return poiType;
|
||||
}
|
||||
@@ -231,7 +237,7 @@ public class UploadInfo {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UploadInfo{" +
|
||||
"filePath=" + filePath +
|
||||
"filePath='" + filePath + '\'' +
|
||||
", poiType='" + poiType + '\'' +
|
||||
", fromType='" + fromType + '\'' +
|
||||
", mainInfoId=" + mainInfoId +
|
||||
|
||||
@@ -10,4 +10,6 @@ public class HttpConstant {
|
||||
public static final String DZT_HOTS = "http://dzt-deva.zhidaozhixing.com";
|
||||
public static final String LAUNCHER_HOTS = "http://dzt-launcherSnapshot.zhidaozhixing.com";
|
||||
|
||||
public static final String TANLU = "TANLU_MODULE";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.mogo.cloud.tanlu.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import java.io.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 文件处理类
|
||||
* @since 2021/1/26
|
||||
*/
|
||||
fun deletePicFile(filePath: String?): Boolean {
|
||||
var file = File(filePath)
|
||||
if (file.exists()) {
|
||||
//如果图片地址包含此路径则是C上面的拍照,需要再删除后摄图片
|
||||
if (filePath!!.contains("usbotg-1-1.1")) {
|
||||
//将地址替换成后摄图片地址
|
||||
var backFile =
|
||||
File(filePath.replace("frontPic", "backPic").replace("PhotoFront", "PhotoBack"))
|
||||
if (backFile.exists()) {
|
||||
return backFile.delete()
|
||||
}
|
||||
return file.delete()
|
||||
} else
|
||||
return file.delete()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//删除某个目录下所有文件
|
||||
fun deleteAllFile(file: File?) { //判断文件不为null或文件目录存在
|
||||
if (file == null || !file.exists()) {
|
||||
Log.e("liyz", "文件删除失败,请检查文件路径是否正确")
|
||||
return
|
||||
}
|
||||
//取得这个目录下的所有子文件对象
|
||||
val files: Array<File> = file.listFiles()
|
||||
//遍历该目录下的文件对象
|
||||
for (f in files) {
|
||||
//判断子目录是否存在子目录,如果是文件则删除
|
||||
if (f.isDirectory) {
|
||||
deleteAllFile(f)
|
||||
} else {
|
||||
f.delete()
|
||||
}
|
||||
}
|
||||
//删除空文件夹 for循环已经把上一层节点的目录清空。
|
||||
// file.delete()
|
||||
}
|
||||
|
||||
|
||||
//根据本地视频文件生成缩略图文件
|
||||
fun getVideoThumbnail(filePath: String, picPath: String): Boolean {
|
||||
var b: Bitmap? = null
|
||||
var retriever = MediaMetadataRetriever()
|
||||
try {
|
||||
retriever.setDataSource(filePath)
|
||||
b = retriever.getFrameAtTime(0)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: RuntimeException) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
retriever.release()
|
||||
} catch (e: RuntimeException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return bitmapToFile(b, picPath)
|
||||
}
|
||||
|
||||
//bitmap转为file
|
||||
fun bitmapToFile(bitmap: Bitmap?, filePath: String): Boolean {
|
||||
val baos = ByteArrayOutputStream()
|
||||
bitmap?.compress(Bitmap.CompressFormat.JPEG, 50, baos)
|
||||
val file = File(filePath)
|
||||
try {
|
||||
if (file.exists())
|
||||
file.delete()
|
||||
file.createNewFile()
|
||||
val fos = FileOutputStream(file)
|
||||
var ins = ByteArrayInputStream(baos.toByteArray())
|
||||
var x = 0
|
||||
val b = ByteArray(1024 * 100)
|
||||
while ({ x = ins.read(b);x }() != -1) {
|
||||
fos.write(b, 0, x)
|
||||
}
|
||||
fos.close()
|
||||
bitmap?.recycle()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
//
|
||||
fun getVideoPicPath(): String {
|
||||
val moviesDir = Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_PICTURES
|
||||
)
|
||||
moviesDir.mkdirs()
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append("pic_")
|
||||
.append(SimpleDateFormat("yyyyMMddHHmmss").format(Date()))
|
||||
val filePrefix = builder.toString()
|
||||
val fileExtn = ".jpg"
|
||||
var destPath = File(moviesDir, filePrefix + fileExtn)
|
||||
|
||||
var fileNo = 0
|
||||
while (destPath.exists()) {
|
||||
fileNo++
|
||||
destPath = File(moviesDir, filePrefix + fileNo + fileExtn)
|
||||
}
|
||||
|
||||
return destPath.absolutePath
|
||||
}
|
||||
|
||||
|
||||
//获取压缩后的视频路径 /storage/emulated/0/Movies/compress_video_20210126174432.mp4
|
||||
fun getCompressVideoPath(): String {
|
||||
val moviesDir = Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_MOVIES
|
||||
)
|
||||
moviesDir.mkdirs()
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append("compress_video_")
|
||||
.append(SimpleDateFormat("yyyyMMddHHmmss").format(Date()))
|
||||
val filePrefix = builder.toString()
|
||||
val fileExtn = ".mp4"
|
||||
var destPath = File(moviesDir, filePrefix + fileExtn)
|
||||
|
||||
var fileNo = 0
|
||||
while (destPath.exists()) {
|
||||
fileNo++
|
||||
destPath = File(moviesDir, filePrefix + fileNo + fileExtn)
|
||||
}
|
||||
|
||||
return destPath.absolutePath
|
||||
}
|
||||
|
||||
@@ -16,4 +16,5 @@ public class TanluUtils {
|
||||
return p.matcher(path).find();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user