代码拉取完成,页面将自动刷新
// 自动分配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}成功")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。