-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from AgoraIO/dev/4.5.0_android
sync beauty sdk to 1.0.7 for api example 4.5.0
- Loading branch information
Showing
19 changed files
with
853 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...xample/app/src/main/java/io/agora/api/example/examples/advanced/beauty/utils/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Agora Community | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.agora.api.example.examples.advanced.beauty.utils | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import java.io.BufferedInputStream | ||
import java.io.BufferedOutputStream | ||
import java.io.BufferedReader | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.io.InputStreamReader | ||
import java.io.OutputStream | ||
|
||
object FileUtils { | ||
val TAG = "FileUtils" | ||
|
||
fun getAssetsString(context: Context, path: String): String { | ||
val sb = StringBuilder() | ||
var isr: InputStreamReader? = null | ||
var br: BufferedReader? = null | ||
try { | ||
isr = InputStreamReader(context.resources.assets.open(path)) | ||
br = BufferedReader(isr) | ||
var line: String? = null | ||
while (br.readLine().also { line = it } != null) { | ||
sb.append(line).append("\n") | ||
} | ||
} catch (e: IOException) { | ||
Log.e(TAG, "getAssetsString error: $e") | ||
} finally { | ||
if (isr != null) { | ||
try { | ||
isr.close() | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
if (br != null) { | ||
try { | ||
br.close() | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
return sb.toString() | ||
} | ||
|
||
fun copyAssets(context: Context, assetsPath: String, targetPath: String) { | ||
val fileNames = context.resources.assets.list(assetsPath) | ||
if (fileNames?.isNotEmpty() == true) { | ||
val targetFile = File(targetPath) | ||
if (!targetFile.exists() && !targetFile.mkdirs()) { | ||
return | ||
} | ||
for (fileName in fileNames) { | ||
copyAssets( | ||
context, | ||
"$assetsPath/$fileName", | ||
"$targetPath/$fileName" | ||
) | ||
} | ||
} else { | ||
copyAssetsFile(context, assetsPath, targetPath) | ||
} | ||
} | ||
|
||
private fun copyAssetsFile(context: Context, assetsFile: String, targetPath: String) { | ||
val dest = File(targetPath) | ||
dest.parentFile?.mkdirs() | ||
var input: InputStream? = null | ||
var output: OutputStream? = null | ||
try { | ||
input = BufferedInputStream(context.assets.open(assetsFile)) | ||
output = BufferedOutputStream(FileOutputStream(dest)) | ||
val buffer = ByteArray(1024) | ||
var length = 0 | ||
while (input.read(buffer).also { length = it } != -1) { | ||
output.write(buffer, 0, length) | ||
} | ||
} catch (e: Exception) { | ||
Log.e(TAG, "copyAssetsFile", e) | ||
} finally { | ||
output?.close() | ||
input?.close() | ||
} | ||
} | ||
} |
Oops, something went wrong.