1 Star 1 Fork 0

HollowGoods / 图片混淆-Android

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
autoHandLogo.gradle 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
HollowGoods 提交于 2024-03-27 16:51 . 首次提交
// 自动分配Logo插件
// 项目名
def projectName = "app"
// logo存放文件夹名称(文件夹请放在根目录下)
def logoDirName = "logo"
// logo对应分发配置
Map<String, String> handLogoList = new HashMap<String, String>() {
{
put("logo-192", "mipmap-xxxhdpi")
put("logo-144", "mipmap-xxhdpi")
put("logo-96", "mipmap-xhdpi")
put("logo-72", "mipmap-hdpi")
put("logo-48", "mipmap-mdpi")
}
}
// 源logo后缀名
def sourceLogoSuffix = "png"
// 输出logo名
def outLogoName = "logo.${sourceLogoSuffix}"
// **** 自动分发logo任务 **** //
task autoHandLogo() {
// 项目路径
def projectPath = project.projectDir.getAbsolutePath()
// 资源文件夹路径
def resPath = "${projectPath}/${projectName}/src/main/res"
// 源logo所在文件夹
def sourceLogoDirPath = "${projectPath}/${logoDirName}"
File sourceLogoDirFile = new File(sourceLogoDirPath)
if (sourceLogoDirFile.exists()) {
Set<String> keySet = handLogoList.keySet()
Iterator<String> keys = keySet.iterator()
while (keys.hasNext()) {
String key = keys.next()
String value = handLogoList.get(key)
handLogo("${sourceLogoDirPath}/${key}.${sourceLogoSuffix}", "${resPath}/${value}", outLogoName)
}
File[] files = sourceLogoDirFile.listFiles()
if (files != null) {
for (File t : files) {
boolean isDelete = t.delete()
System.out.println("分发logo:删除${t.name}:${isDelete}")
}
}
boolean isDelete = sourceLogoDirFile.delete()
System.out.println("分发logo:删除源logo文件夹:${isDelete}")
} else {
System.out.println("分发logo:logo文件夹不存在")
}
}
static void handLogo(String sourcePath, String outPath, String newName) {
if (!new File(sourcePath).exists()) {
System.out.println("分发logo:${sourcePath}不存在")
return
}
FileInputStream inputStream;
FileOutputStream outputStream;
BufferedInputStream buffIn = null;
BufferedOutputStream buffOut = null;
File srcFile = new File(sourcePath);
try {
inputStream = new FileInputStream(srcFile)
buffIn = new BufferedInputStream(inputStream);
File desFile = new File(outPath, newName);
outputStream = new FileOutputStream(desFile);
buffOut = new BufferedOutputStream(outputStream);
byte[] b = new byte[100];
int i = buffIn.read(b);
while (i > 0) {
buffOut.write(b, 0, i);
i = buffIn.read(b);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (buffIn != null) {
buffIn.close();
}
if (buffOut != null) {
buffOut.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("分发logo:${sourcePath}成功")
}
Android
1
https://gitee.com/HollowGoodsMZ/PicEncrypt.git
git@gitee.com:HollowGoodsMZ/PicEncrypt.git
HollowGoodsMZ
PicEncrypt
图片混淆-Android
master

搜索帮助