增加佳明相机业务
This commit is contained in:
616
app/src/main/java/com/navinfo/omqs/util/FileUtils.java
Normal file
616
app/src/main/java/com/navinfo/omqs/util/FileUtils.java
Normal file
@@ -0,0 +1,616 @@
|
||||
package com.navinfo.omqs.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.ExifInterface;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author qj
|
||||
* @version V1.0
|
||||
* @ClassName: FileUtils
|
||||
* @Date 2023/4/17
|
||||
* @Description: ${文件类)
|
||||
*/
|
||||
public class FileUtils {
|
||||
//类标识
|
||||
private static final String TAG = "FileUtils";
|
||||
// 本类输出的日志文件名称
|
||||
private static String TrackFILEName = "Track.txt";
|
||||
// 本类输出的日志文件名称
|
||||
private static String AdasTrackFILEName = "AdasTrack.txt";
|
||||
//日志文件格式
|
||||
private static SimpleDateFormat logfile = new SimpleDateFormat("yyyy-MM-dd");
|
||||
//文件集合
|
||||
private static List<File> filelist = new ArrayList<File>();
|
||||
|
||||
|
||||
/**
|
||||
* 复制文件到sd卡
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param fileDir 文件目录
|
||||
* @param filePath 文件路径
|
||||
* @param files 文件集合
|
||||
*/
|
||||
public static void copyFileToSdcard(Context context, String fileDir,
|
||||
String filePath, Field[] files) {
|
||||
|
||||
for (Field r : files) {
|
||||
try {
|
||||
int id = context.getResources().getIdentifier(r.getName(),
|
||||
"raw", context.getPackageName());
|
||||
Log.i(TAG, new File(filePath).length() + "=====文件长度===="
|
||||
+ filePath);
|
||||
if (!new File(fileDir).exists()) {
|
||||
new File(fileDir).mkdirs();
|
||||
}
|
||||
|
||||
// new File(path).delete();
|
||||
if (new File(filePath).exists())
|
||||
new File(filePath).delete();
|
||||
new File(filePath).createNewFile();
|
||||
BufferedOutputStream bufEcrivain = new BufferedOutputStream(
|
||||
(new FileOutputStream(new File(filePath))));
|
||||
BufferedInputStream VideoReader = new BufferedInputStream(
|
||||
context.getResources().openRawResource(id));
|
||||
byte[] buff = new byte[20 * 1024];
|
||||
int len;
|
||||
while ((len = VideoReader.read(buff)) > 0) {
|
||||
bufEcrivain.write(buff, 0, len);
|
||||
}
|
||||
bufEcrivain.flush();
|
||||
bufEcrivain.close();
|
||||
VideoReader.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制单个文件
|
||||
*
|
||||
* @param oldPath String 原文件路径 如:c:/fqf.txt
|
||||
* @param newPath String 复制后路径 如:f:/fqf.txt
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean copyFile(String oldPath, String newPath) {
|
||||
try {
|
||||
int bytesum = 0;
|
||||
int byteread = 0;
|
||||
File oldfile = new File(oldPath);
|
||||
if (oldfile.exists()) { // 文件存在时
|
||||
InputStream inStream = new FileInputStream(oldPath); // 读入原文件
|
||||
FileOutputStream fs = new FileOutputStream(newPath);
|
||||
byte[] buffer = new byte[1444];
|
||||
while ((byteread = inStream.read(buffer)) != -1) {
|
||||
|
||||
bytesum += byteread; // 字节数 文件大小
|
||||
System.out.println(bytesum);
|
||||
fs.write(buffer, 0, byteread);
|
||||
|
||||
}
|
||||
inStream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.println("复制单个文件操作出错");
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 实时轨迹信息写入文件
|
||||
*
|
||||
* @param info 信息
|
||||
* @param isNewLine 是否换行写入
|
||||
*/
|
||||
public static void writeRealTimeTrackToFile(String filePath, String info, boolean isNewLine) {
|
||||
|
||||
|
||||
if (new File(filePath).exists() == false) {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(filePath, "monitor_track.txt");
|
||||
|
||||
FileWriter filerWriter = null;
|
||||
|
||||
BufferedWriter bufWriter = null;
|
||||
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
//文件流
|
||||
filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
|
||||
|
||||
//字符缓冲输出流
|
||||
bufWriter = new BufferedWriter(filerWriter);
|
||||
|
||||
bufWriter.write(info);
|
||||
|
||||
if (isNewLine)
|
||||
bufWriter.newLine();
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try{
|
||||
if(bufWriter!=null)
|
||||
bufWriter.close();
|
||||
|
||||
if(filerWriter!=null)
|
||||
filerWriter.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 轨迹信息写入文件
|
||||
*
|
||||
* @param info 信息
|
||||
* @param isNewLine 是否换行写入
|
||||
*/
|
||||
public static void writeTrackToFile(String filePath, String info, boolean isNewLine) {
|
||||
Date nowtime = new Date();
|
||||
|
||||
String needWriteFiel = logfile.format(nowtime);
|
||||
|
||||
if (TextUtils.isEmpty(filePath))
|
||||
return;
|
||||
|
||||
if (new File(filePath).exists() == false) {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
File file = new File(filePath, needWriteFiel + TrackFILEName);
|
||||
FileWriter filerWriter = null;
|
||||
BufferedWriter bufWriter = null;
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
//文件流
|
||||
filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
|
||||
|
||||
//字符缓冲输出流
|
||||
bufWriter = new BufferedWriter(filerWriter);
|
||||
|
||||
bufWriter.write(info);
|
||||
|
||||
if (isNewLine)
|
||||
bufWriter.newLine();
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
|
||||
try{
|
||||
if(bufWriter!=null)
|
||||
bufWriter.close();
|
||||
|
||||
if(filerWriter!=null)
|
||||
filerWriter.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时轨迹偏差信息写入文件
|
||||
*
|
||||
* @param info 信息
|
||||
* @param isNewLine 是否换行写入
|
||||
*/
|
||||
public static void writeTrackLogToFile(String filePath, String info, boolean isNewLine) {
|
||||
|
||||
|
||||
if (new File(filePath).exists() == false) {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
File file = new File(filePath, "TrackLog.txt");
|
||||
FileWriter filerWriter = null;
|
||||
BufferedWriter bufWriter = null;
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
//文件流
|
||||
filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
|
||||
|
||||
//字符缓冲输出流
|
||||
bufWriter = new BufferedWriter(filerWriter);
|
||||
|
||||
bufWriter.write(info);
|
||||
|
||||
if (isNewLine)
|
||||
bufWriter.newLine();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try{
|
||||
if(bufWriter!=null)
|
||||
bufWriter.close();
|
||||
|
||||
if(filerWriter!=null)
|
||||
filerWriter.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 逐行写入
|
||||
*
|
||||
* @param info 信息
|
||||
*/
|
||||
public static void writeLine(String filePath,String fileName, String info) {
|
||||
|
||||
if (TextUtils.isEmpty(filePath))
|
||||
return;
|
||||
|
||||
if (new File(filePath).exists() == false) {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
File file = new File(filePath + fileName);
|
||||
FileWriter filerWriter = null;
|
||||
BufferedWriter bufWriter = null;
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
//文件流
|
||||
filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
|
||||
|
||||
//字符缓冲输出流
|
||||
bufWriter = new BufferedWriter(filerWriter);
|
||||
|
||||
bufWriter.write(info);
|
||||
|
||||
bufWriter.newLine();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try{
|
||||
if(bufWriter!=null)
|
||||
bufWriter.close();
|
||||
|
||||
if(filerWriter!=null)
|
||||
filerWriter.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adas轨迹信息写入文件
|
||||
*
|
||||
* @param info 信息
|
||||
* @param isNewLine 是否换行写入
|
||||
*/
|
||||
public static void writeAdasTrackToFile(String filePath, String info, boolean isNewLine) {
|
||||
|
||||
Date nowtime = new Date();
|
||||
|
||||
String needWriteFiel = logfile.format(nowtime);
|
||||
|
||||
if (TextUtils.isEmpty(filePath))
|
||||
return;
|
||||
|
||||
if (new File(filePath).exists() == false) {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(filePath, needWriteFiel + AdasTrackFILEName);
|
||||
FileWriter filerWriter = null;
|
||||
BufferedWriter bufWriter = null;
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
//文件流
|
||||
filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
|
||||
|
||||
//字符缓冲输出流
|
||||
bufWriter = new BufferedWriter(filerWriter);
|
||||
|
||||
bufWriter.write(info);
|
||||
|
||||
if (isNewLine)
|
||||
bufWriter.newLine();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try{
|
||||
if(bufWriter!=null)
|
||||
bufWriter.close();
|
||||
|
||||
if(filerWriter!=null)
|
||||
filerWriter.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件绝对路径
|
||||
*
|
||||
* @return list
|
||||
* 文件绝对路径集合
|
||||
*/
|
||||
public static List<File> getFileList(String strPath, String[] suffix) {
|
||||
File dir = new File(strPath);
|
||||
File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
|
||||
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
String fileName = files[i].getName();
|
||||
if (files[i].isDirectory()) { // 判断是文件还是文件夹
|
||||
getFileList(files[i].getAbsolutePath(), suffix); // 获取文件绝对路径
|
||||
} else {
|
||||
if (suffix != null && suffix.length > 0) {
|
||||
for (String str : suffix) {
|
||||
if (fileName.endsWith(str)) { // 判断文件名是否以
|
||||
String strFileName = files[i].getAbsolutePath();
|
||||
System.out.println("---" + strFileName);
|
||||
filelist.add(files[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return filelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理缓存文件
|
||||
*/
|
||||
public static void clearCacheFile() {
|
||||
filelist.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件目录大小
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
public static double getDirSize(File file) {
|
||||
//判断文件是否存在
|
||||
if (file.exists()) {
|
||||
//如果是目录则递归计算其内容的总大小
|
||||
if (file.isDirectory()) {
|
||||
File[] children = file.listFiles();
|
||||
double size = 0;
|
||||
for (File f : children)
|
||||
size += getDirSize(f);
|
||||
return size;
|
||||
} else {//如果是文件则直接返回其大小,以“兆”为单位
|
||||
double size = (double) file.length() / 1024 / 1024;
|
||||
return size;
|
||||
}
|
||||
} else {
|
||||
System.out.println("文件或者文件夹不存在,请检查路径是否正确!");
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] readFileByBytes(String url) throws IOException {
|
||||
File file = new File(url);
|
||||
if (file.exists() && !file.mkdir()) {
|
||||
long fileSize = file.length();
|
||||
if (fileSize > Integer.MAX_VALUE) {
|
||||
// System.out.println("file too big...");
|
||||
return null;
|
||||
}
|
||||
|
||||
FileInputStream fi = new FileInputStream(file);
|
||||
byte[] buffer = new byte[(int) fileSize];
|
||||
int offset = 0;
|
||||
int numRead = 0;
|
||||
while (offset < buffer.length
|
||||
&& (numRead = fi.read(buffer, offset, buffer.length - offset)) >= 0) {
|
||||
offset += numRead;
|
||||
}
|
||||
// 确保所有数据均被读取
|
||||
if (offset != buffer.length) {
|
||||
throw new IOException("Could not completely read file "
|
||||
+ file.getName());
|
||||
}
|
||||
fi.close();
|
||||
return buffer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//把从服务器获得图片的输入流InputStream写到本地磁盘
|
||||
public static void saveImageToDisk(String url, String savePath) {
|
||||
|
||||
InputStream inputStream = getInputStream(url);
|
||||
if(inputStream==null)
|
||||
return;
|
||||
|
||||
byte[] data = new byte[1024];
|
||||
int len = 0;
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
fileOutputStream = new FileOutputStream(savePath);
|
||||
while ((len = inputStream.read(data)) != -1) {
|
||||
fileOutputStream.write(data, 0, len);
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fileOutputStream != null) {
|
||||
try {
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 从服务器获得一个输入流(本例是指从服务器获得一个image输入流)
|
||||
public static InputStream getInputStream(String urlPath) {
|
||||
InputStream inputStream = null;
|
||||
HttpURLConnection httpURLConnection = null;
|
||||
|
||||
try {
|
||||
URL url = new URL(urlPath);
|
||||
httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
// 设置网络连接超时时间
|
||||
httpURLConnection.setConnectTimeout(3000);
|
||||
// 设置应用程序要从网络连接读取数据
|
||||
httpURLConnection.setDoInput(true);
|
||||
|
||||
httpURLConnection.setRequestMethod("GET");
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
if (responseCode == 200) {
|
||||
// 从服务器返回一个输入流
|
||||
inputStream = httpURLConnection.getInputStream();
|
||||
|
||||
}
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return inputStream;
|
||||
|
||||
}
|
||||
|
||||
public static String getExifTime(String jpegFile) {
|
||||
try {
|
||||
|
||||
ExifInterface exif = new ExifInterface(jpegFile);
|
||||
|
||||
String time = exif.getAttribute(ExifInterface.TAG_DATETIME);
|
||||
|
||||
return time;
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 轨迹信息写入文件
|
||||
*
|
||||
* @param info 信息
|
||||
* @param isNewLine 是否换行写入
|
||||
*/
|
||||
public static void writeToFile(String filePath, String info, boolean isNewLine) {
|
||||
|
||||
if (TextUtils.isEmpty(filePath))
|
||||
return;
|
||||
|
||||
File file = new File(filePath);
|
||||
FileWriter filerWriter = null;
|
||||
BufferedWriter bufWriter = null;
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
|
||||
//文件流
|
||||
filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据,不进行覆盖
|
||||
|
||||
//字符缓冲输出流
|
||||
bufWriter = new BufferedWriter(filerWriter);
|
||||
|
||||
bufWriter.write(info);
|
||||
|
||||
if (isNewLine)
|
||||
bufWriter.newLine();
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try{
|
||||
if(bufWriter!=null)
|
||||
bufWriter.close();
|
||||
|
||||
if(filerWriter!=null)
|
||||
filerWriter.close();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
78
app/src/main/java/com/navinfo/omqs/util/NetUtils.java
Normal file
78
app/src/main/java/com/navinfo/omqs/util/NetUtils.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.navinfo.omqs.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
/**
|
||||
* @ClassName: NetUtils.java
|
||||
* @author qj
|
||||
* @version V1.0
|
||||
* @Date 2016年12月17日 下午1:56:02
|
||||
* @Description: 网络类
|
||||
*/
|
||||
public class NetUtils {
|
||||
//单例对象
|
||||
private static volatile NetUtils mInstance;
|
||||
//上下文
|
||||
private Context mCon;
|
||||
|
||||
public static NetUtils getInstance() {
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (NetUtils.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new NetUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param context
|
||||
* 上下文
|
||||
*/
|
||||
public void init(Context context){
|
||||
|
||||
this.mCon = context;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否wifi
|
||||
* @return true 是 false 否
|
||||
*/
|
||||
public boolean isExistWifi(boolean isNeedMobile){
|
||||
|
||||
//获取系统服务
|
||||
ConnectivityManager manager = (ConnectivityManager)mCon.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
try{
|
||||
//获取状态
|
||||
final NetworkInfo.State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
|
||||
|
||||
if(wifi == NetworkInfo.State.CONNECTED||wifi==NetworkInfo.State.CONNECTING){
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e){
|
||||
}
|
||||
|
||||
|
||||
if(isNeedMobile){
|
||||
try{
|
||||
//获取状态
|
||||
final NetworkInfo mobileNetwork = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
|
||||
if(mobileNetwork!=null&&mobileNetwork.getState()!=null&& (mobileNetwork.getState()== NetworkInfo.State.CONNECTED||mobileNetwork.getState()==NetworkInfo.State.CONNECTING)){
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
373
app/src/main/java/com/navinfo/omqs/util/ShareUtil.java
Normal file
373
app/src/main/java/com/navinfo/omqs/util/ShareUtil.java
Normal file
@@ -0,0 +1,373 @@
|
||||
package com.navinfo.omqs.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import com.navinfo.omqs.system.SystemConstant;
|
||||
|
||||
/**
|
||||
* @ClassName: ShareUtil.java
|
||||
* @author qj
|
||||
* @version V1.0
|
||||
* @Date 2016年12月17日 下午1:56:02
|
||||
* @Description: 相机数据存储
|
||||
*/
|
||||
public class ShareUtil {
|
||||
//系统数据存储对象
|
||||
private static SharedPreferences mSharePre=null;
|
||||
//安卓编辑器
|
||||
private static Editor editor;
|
||||
//拍照状态标识
|
||||
private final static String CONTINUS_TAKE_PHOTO_STATE = "continue_take_photo_state";
|
||||
//外设相机按钮状态标识
|
||||
private final static String SELECT_TAKE_PHOTO_OR_RECORD = "select_take_photo_or_record";
|
||||
//外设相机种别标识
|
||||
private final static String SELECT_CAMERA_KIND = "select_take_kind";
|
||||
//外设相机连接标识
|
||||
private final static String CAMERA_CONNECT_STATE = "camera_connect_state";
|
||||
//外设相机工作模式
|
||||
private final static String TAKE_CAMERA_MODE = "take_camera_mode";
|
||||
//连接相机ip
|
||||
private final static String TAKE_CAMERA_IP = "take_camera_ip";
|
||||
//连接相机Mac
|
||||
private final static String TAKE_CAMERA_MAC = "take_camera_mac";
|
||||
//外设相机编号,应对多个相机连接使用,识别存储某一个设备连接状态等信息
|
||||
private int mDeviceNum = 1;
|
||||
//上下文
|
||||
private Context mContext;
|
||||
|
||||
private ShareUtil() {
|
||||
}
|
||||
|
||||
public ShareUtil(Context context, int deviceNum) {
|
||||
mContext = context;
|
||||
mDeviceNum = deviceNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getSelectCameraKind
|
||||
* Author : qj
|
||||
* Describe : 获取相机类型
|
||||
* param : context 上下文
|
||||
* return true 相机 false视频
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public boolean getSelectCameraKind(){
|
||||
if(mContext==null)
|
||||
return false;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.SELECT_CAMERA_STATE, Context.MODE_PRIVATE);
|
||||
}
|
||||
return mSharePre.getBoolean(mDeviceNum+SystemConstant.USER_ID+SELECT_CAMERA_KIND, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setSelectCameraKind
|
||||
* Author : qj
|
||||
* Describe : 设置相机类型
|
||||
* param : context 上下文
|
||||
* param : userid用户id
|
||||
* param : true 内置相机 false 外置相机
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setSelectCameraKind(String userId,Boolean bll){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.SELECT_CAMERA_STATE, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putBoolean(mDeviceNum+userId+SELECT_CAMERA_KIND,bll).commit();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getSelectTakePhotoOrRecord
|
||||
* Author : qj
|
||||
* Describe : 获取相机使用类型
|
||||
* param : context 上下文
|
||||
* param : true 相机拍照 false 录像视频
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public boolean getSelectTakePhotoOrRecord(){
|
||||
if(mContext==null)
|
||||
return true;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.SELECT_TAKEPHOTO_OR_RECORD, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
return mSharePre.getBoolean(mDeviceNum+SystemConstant.USER_ID+SELECT_TAKE_PHOTO_OR_RECORD, mDeviceNum==1?true:false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setSelectTakePhotoOrRecord
|
||||
* Author : qj
|
||||
* Describe : 设置相机使用类型
|
||||
* param : context 上下文
|
||||
* param : userid 用户id
|
||||
* param : true 相机拍照 false 录像视频
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setSelectTakePhotoOrRecord(String userId,Boolean bll){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.SELECT_TAKEPHOTO_OR_RECORD, Context.MODE_PRIVATE);
|
||||
}
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putBoolean(mDeviceNum+userId+SELECT_TAKE_PHOTO_OR_RECORD,bll).commit();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getContinusTakePhotoState
|
||||
* Author : qj
|
||||
* Describe : 获取相机工作状态
|
||||
* param : context 上下文
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public boolean getContinusTakePhotoState(){
|
||||
if(mContext==null)
|
||||
return true;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.SELECT_CAMERA_STATE, Context.MODE_PRIVATE);
|
||||
}
|
||||
return mSharePre.getBoolean(mDeviceNum+SystemConstant.USER_ID+CONTINUS_TAKE_PHOTO_STATE, true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setContinusTakePhotoState
|
||||
* Author : qj
|
||||
* Describe : 设置相机工作状态
|
||||
* param : context 上下文
|
||||
* param : userid 用户id
|
||||
* param : true 停止 false 否
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setContinusTakePhotoState(String userId,Boolean bll){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.SELECT_CAMERA_STATE, Context.MODE_PRIVATE);
|
||||
}
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putBoolean(mDeviceNum+userId+CONTINUS_TAKE_PHOTO_STATE,bll).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getConnectstate
|
||||
* Author : qj
|
||||
* Describe : 获取相机连接状态
|
||||
* param : context 上下文
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public boolean getConnectstate(){
|
||||
if(mContext==null)
|
||||
return false;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.CAMERA_CONNECT_STATE, Context.MODE_PRIVATE);
|
||||
}
|
||||
return mSharePre.getBoolean(mDeviceNum+SystemConstant.USER_ID+CAMERA_CONNECT_STATE, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setConnectstate
|
||||
* Author : qj
|
||||
* Describe : 设置相机连接状态
|
||||
* param : context 上下文
|
||||
* param : userid 用户id
|
||||
* param : true 连接 false 否
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setConnectstate(String userId,Boolean bll){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.CAMERA_CONNECT_STATE, Context.MODE_PRIVATE);
|
||||
}
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putBoolean(mDeviceNum+userId+CAMERA_CONNECT_STATE,bll).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getTakeCameraMode
|
||||
* Author : qj
|
||||
* Describe : 获取相机模式
|
||||
* param : context 上下文
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public int getTakeCameraMode(){
|
||||
if(mContext==null)
|
||||
return 0;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.TAKE_CAMERA_MODE, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
return mSharePre.getInt(mDeviceNum+SystemConstant.USER_ID+TAKE_CAMERA_MODE, mDeviceNum==1?0:1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setTakeCameraMode
|
||||
* Author : qj
|
||||
* Describe : 设置相机模式
|
||||
* param : context 上下文
|
||||
* param : userid 用户id
|
||||
* param : int 0 视频 1 拍照
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setTakeCameraMode(String userId,int mode){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.TAKE_CAMERA_MODE, Context.MODE_PRIVATE);
|
||||
}
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putInt(mDeviceNum+userId+TAKE_CAMERA_MODE,mode).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getTakeCameraIP
|
||||
* Author : qj
|
||||
* Describe : 获取相机ip
|
||||
* param : context 上下文
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public String getTakeCameraIP(){
|
||||
if(mContext==null)
|
||||
return "";
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.TAKE_CAMERA_IP, Context.MODE_PRIVATE);
|
||||
}
|
||||
String ip=mSharePre.getString(mDeviceNum+SystemConstant.USER_ID+TAKE_CAMERA_IP, "");
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setTakeCameraIP
|
||||
* Author : qj
|
||||
* Describe : 设置相机ip
|
||||
* param : context 上下文
|
||||
* param : userid 用户id
|
||||
* param : ip 连接地址
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setTakeCameraIP(String userId,String ip){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.TAKE_CAMERA_IP, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putString(mDeviceNum+userId+TAKE_CAMERA_IP,ip).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getTakeCameraMac
|
||||
* Author : qj
|
||||
* param : mac 硬件信息
|
||||
* param : context 上下文
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public String getTakeCameraMac(){
|
||||
if(mContext==null)
|
||||
return "";
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.TAKE_CAMERA_MAC, Context.MODE_PRIVATE);
|
||||
}
|
||||
String mac=mSharePre.getString(mDeviceNum+SystemConstant.USER_ID+TAKE_CAMERA_MAC, "");
|
||||
return mac;
|
||||
}
|
||||
|
||||
/**
|
||||
* method : setTakeCameraMac
|
||||
* Author : qj
|
||||
* Describe : 设置相机mac
|
||||
* param : context 上下文
|
||||
* param : userid 用户id
|
||||
* param : mac 硬件信息
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public void setTakeCameraMac(String userId,String mac){
|
||||
if(mContext==null)
|
||||
return ;
|
||||
|
||||
if(mSharePre==null){
|
||||
mSharePre = mContext.getSharedPreferences(SystemConstant.TAKE_CAMERA_MAC, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
editor=mSharePre.edit();
|
||||
|
||||
editor.putString(mDeviceNum+userId+TAKE_CAMERA_MAC,mac).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getConnectstateMac
|
||||
* Author : qj
|
||||
* param : mac 硬件信息
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public static String getConnectstateMac(Context context){
|
||||
if(context==null)
|
||||
return "";
|
||||
|
||||
ShareUtil shareUtil = new ShareUtil(context,1);
|
||||
|
||||
if(shareUtil.getConnectstate())
|
||||
return shareUtil.getTakeCameraMac();
|
||||
|
||||
shareUtil = new ShareUtil(context,2);
|
||||
|
||||
if(shareUtil.getConnectstate())
|
||||
return shareUtil.getTakeCameraMac();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* method : getConnectstateMac
|
||||
* Author : qj
|
||||
* param : mac 硬件信息
|
||||
* Date : 2018/4/23
|
||||
*/
|
||||
public static ShareUtil getCameraMode(Context context){
|
||||
if(context==null)
|
||||
return null;
|
||||
|
||||
ShareUtil shareUtil = new ShareUtil(context,1);
|
||||
|
||||
if(shareUtil.getConnectstate()/*&&shareUtil.getTakeCameraMode()==0不需要判断相机类型*/)
|
||||
return shareUtil;
|
||||
|
||||
shareUtil = new ShareUtil(context,2);
|
||||
|
||||
if(shareUtil.getConnectstate()/*&&shareUtil.getTakeCameraMode()==0不需要判断相机类型*/)
|
||||
return shareUtil;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user