diff --git a/app-compose/build.gradle b/app-compose/build.gradle index ac7b64f..978309f 100644 --- a/app-compose/build.gradle +++ b/app-compose/build.gradle @@ -26,6 +26,7 @@ android { dependencies { implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.appcompat:appcompat:1.4.1' var lifeCycle_version = '2.5.1' implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifeCycle_version" @@ -44,7 +45,15 @@ dependencies { var accompanist_version = '0.30.1' implementation "com.google.accompanist:accompanist-permissions:$accompanist_version" + + //添加excel + implementation rootProject.ext.dependencies.jxl + implementation project(path: ':library-push') + implementation project(path: ':library-ijkplayer') + + // documentfile 访问U盘 + implementation "androidx.documentfile:documentfile:1.0.1" implementation(name: 'libuvccamera-release', ext: 'aar') { exclude module: 'support-v4' diff --git a/app-compose/libs/sdkapi.jar b/app-compose/libs/sdkapi.jar new file mode 100644 index 0000000..c269276 Binary files /dev/null and b/app-compose/libs/sdkapi.jar differ diff --git a/app-compose/src/main/AndroidManifest.xml b/app-compose/src/main/AndroidManifest.xml index 0aae489..2b983e7 100644 --- a/app-compose/src/main/AndroidManifest.xml +++ b/app-compose/src/main/AndroidManifest.xml @@ -9,13 +9,13 @@ android:required="false" /> - - + > = ArrayList() + val row1: MutableList = ArrayList() + row1.add(SimpleCellValue("5.22")) + row1.add(SimpleCellValue("1")) + row1.add(SimpleCellValue("2")) + row1.add(SimpleCellValue("3")) + val row2: MutableList = ArrayList() + row2.add(SimpleCellValue("5.23")) + row2.add(SimpleCellValue("4")) + row2.add(SimpleCellValue("5")) + row2.add(SimpleCellValue("6")) + + allData.add(row1) + allData.add(row2) + + ExcelUtils.writeStringListToExcel(allData, context) + } +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt index 45dbd9b..d531d6a 100644 --- a/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/ui/home/HomeView.kt @@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.width import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext @@ -18,7 +17,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import androidx.lifecycle.viewmodel.compose.viewModel import com.google.accompanist.permissions.ExperimentalPermissionsApi -import com.google.accompanist.permissions.rememberMultiplePermissionsState import com.yinuo.safetywatcher.navi.ModelPath import com.yinuo.safetywatcher.navi.NavigationUtil @@ -26,14 +24,13 @@ import com.yinuo.safetywatcher.navi.NavigationUtil @Composable fun HomeView() { // 权限 - val permissionsState = rememberMultiplePermissionsState( - permissions = listOf( - android.Manifest.permission.READ_EXTERNAL_STORAGE, - android.Manifest.permission.WRITE_EXTERNAL_STORAGE, - android.Manifest.permission.CAMERA, - ) - ) - if (permissionsState.allPermissionsGranted) { +// val permissionsState = rememberMultiplePermissionsState( +// permissions = listOf( +// android.Manifest.permission.MANAGE_EXTERNAL_STORAGE, +// android.Manifest.permission.CAMERA, +// ) +// ) +// if (permissionsState.allPermissionsGranted) { val viewModel: HomeViewModel = viewModel() val context = LocalContext.current Row(modifier = Modifier.fillMaxSize()) { @@ -54,11 +51,14 @@ fun HomeView() { Button(onClick = { NavigationUtil.to(ModelPath.Setting) }) { Text(text = "设置") } + Button(onClick = { NavigationUtil.to(ModelPath.Cloud) }) { + Text(text = "云平台") + } } } - } else { - LaunchedEffect(Unit) { - permissionsState.launchMultiplePermissionRequest() - } - } +// } else { +// LaunchedEffect(Unit) { +// permissionsState.launchMultiplePermissionRequest() +// } +// } } diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/utils/LztekUtil.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/utils/LztekUtil.kt new file mode 100644 index 0000000..099e8fa --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/utils/LztekUtil.kt @@ -0,0 +1,16 @@ +package com.yinuo.safetywatcher.utils + +import com.lztek.toolkit.Lztek + +object LztekUtil { + + private var mLztek: Lztek? = null; + + fun setObject(value: Lztek) { + mLztek = value + } + + fun getLztek(): Lztek { + return mLztek!! + } +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/xls/ICellValue.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/ICellValue.kt new file mode 100644 index 0000000..8f9e953 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/ICellValue.kt @@ -0,0 +1,5 @@ +package com.yinuo.safetywatcher.xls + +interface ICellValue { + fun getValue(): String +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/xls/SimpleCellValue.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/SimpleCellValue.kt new file mode 100644 index 0000000..44f95c1 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/SimpleCellValue.kt @@ -0,0 +1,7 @@ +package com.yinuo.safetywatcher.xls + +data class SimpleCellValue(val content: String) : ICellValue { + override fun getValue(): String { + return content + } +} diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/xls/utils/ExcelUtils.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/utils/ExcelUtils.kt new file mode 100644 index 0000000..0a08b68 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/utils/ExcelUtils.kt @@ -0,0 +1,138 @@ +package com.yinuo.safetywatcher.xls.utils + +import android.content.Context +import android.util.Log +import com.yinuo.safetywatcher.xls.ICellValue +import com.yinuo.safetywatcher.R +import jxl.Workbook +import jxl.WorkbookSettings +import jxl.write.Label +import jxl.write.WritableCellFormat +import jxl.write.WritableFont +import jxl.write.WritableWorkbook +import jxl.write.WriteException +import java.io.File +import java.io.FileInputStream +import java.io.InputStream + + +/** + * excel表格工具 + */ +object ExcelUtils { + private const val TAG: String = "ExcelUtils" + private const val UTF8_ENCODING = "UTF-8" + private var arial12format: WritableCellFormat? = null + + private fun format() { + try { + val writableFont = WritableFont(WritableFont.ARIAL, 12) + arial12format = WritableCellFormat(writableFont) + arial12format?.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN) + } catch (exception: WriteException) { + Log.e(TAG, "format() e==" + exception.message) + } + + } + + private fun makeDir(filePath: File) { + if (!filePath.parentFile.exists()) { + makeDir(filePath.parentFile) + } + filePath.mkdir() + } + + private fun deleteByPath(filePath: String) { + val file = File(filePath) + if (file.exists()) { + if (file.isFile || file.isDirectory) { + file.delete() + } + } + } + + private fun deleteExistFile(excelFilePath: String) { + val file = File(excelFilePath) + if (file.exists()) { + val files: Array = file.listFiles() + for (i in files.indices) { + deleteByPath(files[i].absolutePath) + } + } + } + + private fun initExcel( + allColumNames: Array, + filePath: String, + sheetName: String + ) { + format() + + var workbook: WritableWorkbook? = null + try { + val file = File(filePath) + if (!file.exists()) { + file.createNewFile() + } + workbook = Workbook.createWorkbook(file) + val sheet = workbook.createSheet(sheetName, 0) + + allColumNames.forEachIndexed { index, s -> + sheet.addCell(Label(index, 0, s, arial12format)) + } + workbook.write() + } catch (e: Exception) { + Log.e(TAG, "initExcel e==" + e.message) + } finally { + try { + workbook?.close() + } catch (e: Exception) { + Log.e(TAG, "initExcel e==" + e.message) + } + } + } + + fun writeStringListToExcel( + allRowsData: List>, + context: Context + ): Boolean { + val fileName = PathUtils.getNowTimeFormat(PathUtils.DATE_TO_STRING_LONG_PATTERN) + ".xls" + PathUtils.EXCEL_EXPORT_NAME = fileName + val filePath = + PathUtils.getUDiskPath() + PathUtils.EXCEL_EXPORT_PATH + PathUtils.EXCEL_EXPORT_NAME + deleteExistFile(PathUtils.getUDiskPath() + PathUtils.EXCEL_EXPORT_PATH) + makeDir(File(PathUtils.getUDiskPath() + PathUtils.EXCEL_EXPORT_PATH)) + + val columns = context.resources.getStringArray(R.array.excel_column) + initExcel(columns, filePath, PathUtils.SHEET_NAME) //需要写入权限 + + if (PathUtils.isListEmpty(allRowsData) || context == null) + return false + + var writebook: WritableWorkbook? = null + var inputStream: InputStream? = null + try { + val setEncode = WorkbookSettings() + setEncode.encoding = UTF8_ENCODING + inputStream = FileInputStream(File(filePath)) + val workbook = Workbook.getWorkbook(inputStream) + val file = File(filePath) + writebook = Workbook.createWorkbook(file, workbook) + val sheet = writebook.getSheet(0) + for ((row, item) in allRowsData.withIndex()) { + item.forEachIndexed { index, cellValue -> + sheet.addCell(Label(index, row + 1, cellValue.getValue(), arial12format)) + } + } + writebook.write() + Log.i(TAG, "Excelel 写入成功") + return true + } catch (e: Exception) { + Log.e(TAG, "writeStringListToExcel() e==" + e.message) + } finally { + writebook?.close() + inputStream?.close() + } + return false + } +} \ No newline at end of file diff --git a/app-compose/src/main/java/com/yinuo/safetywatcher/xls/utils/PathUtils.kt b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/utils/PathUtils.kt new file mode 100644 index 0000000..0f66ae6 --- /dev/null +++ b/app-compose/src/main/java/com/yinuo/safetywatcher/xls/utils/PathUtils.kt @@ -0,0 +1,52 @@ +package com.yinuo.safetywatcher.xls.utils + +import android.content.Context +import android.os.Environment +import com.yinuo.safetywatcher.utils.LztekUtil +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +/** + * 基础工具类 + */ +object PathUtils { + private const val TAG: String = "BaseUtils" + const val SHEET_NAME = "表格1" + const val EXCEL_EXPORT_PATH = "/ExportExcel/" + lateinit var EXCEL_EXPORT_NAME: String + const val DATE_TO_STRING_LONG_PATTERN: String = "yyyy_MM_dd_HH_mm_ss" + + fun isListEmpty(list: List?): Boolean { + return list == null || list.isEmpty() + } + + /** + * 获取应用中文件存储 + */ + fun getExternalStoragePath(context: Context): String? { + return context.getExternalFilesDir(null)?.path + } + + /** + * 获取U盘存储 + */ + fun getUDiskPath(): String { + return LztekUtil.getLztek().usbStoragePath + } + + fun getExternalStorageDirectory(context: Context): String? { + return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).path + } + + /** + * 外部存储目录 + */ + fun getExternalStorageDirectory(): String? { + return Environment.getExternalStorageDirectory().absolutePath + } + + fun getNowTimeFormat(dateToStringLongPattern: String): String { + return SimpleDateFormat(dateToStringLongPattern, Locale.ROOT).format(Date()); + } +} \ No newline at end of file diff --git a/app-compose/src/main/jniLibs/arm64-v8a/libproffmpeg.so b/app-compose/src/main/jniLibs/arm64-v8a/libproffmpeg.so new file mode 100644 index 0000000..48e7fcd Binary files /dev/null and b/app-compose/src/main/jniLibs/arm64-v8a/libproffmpeg.so differ diff --git a/app-compose/src/main/jniLibs/arm64-v8a/libproplayer.so b/app-compose/src/main/jniLibs/arm64-v8a/libproplayer.so new file mode 100644 index 0000000..bca8d82 Binary files /dev/null and b/app-compose/src/main/jniLibs/arm64-v8a/libproplayer.so differ diff --git a/app-compose/src/main/jniLibs/arm64-v8a/libprosdl.so b/app-compose/src/main/jniLibs/arm64-v8a/libprosdl.so new file mode 100644 index 0000000..82f09ef Binary files /dev/null and b/app-compose/src/main/jniLibs/arm64-v8a/libprosdl.so differ diff --git a/app-compose/src/main/res/values/strings.xml b/app-compose/src/main/res/values/strings.xml index 3799d13..efb3f93 100644 --- a/app-compose/src/main/res/values/strings.xml +++ b/app-compose/src/main/res/values/strings.xml @@ -1,3 +1,11 @@ app-compose + + + + 时间 + 属性 + + 单位 + \ No newline at end of file