公司--下载svg图片
加载本地svg图片:
SVGParserRenderer norDrawable =
OtherPageConfigsManager.getInstance().getSVGParserRenderer(this,map.get("iconUrlNor")); public SVGParserRenderer getSVGParserRenderer(Context context, String svgPath){
String config = "";
if(iconLoadPathType == SAVE_TYPE_ASSETS)//本地存储位置
config = FileSystem.getFromAssets(context, "panelConfigFolder/"+svgPath);
else if(iconLoadPathType == SAVE_TYPE_SDCARD)//SDK存储位置
config = "";//"file://"+FileSystem.getCacheRootDir(context, "").getPath()+ url;
else if(iconLoadPathType == SAVE_TYPE_SYSTEM_DATA_FOLDER)//内部文件系统存储位置
//modify by chris.lei 添加中台未配发右侧在线客服图标导致从内部文件中读取不到信息客户端首页显示空白的问题
config = FileSystem.readFromFile(context,
getConfigFile(context, "panelConfigFolder", svgPath).getPath());
if(config == ""){
config = FileSystem.getFromAssets(context, "panelConfigFolder/"+svgPath);
}
return SvgRes1.getSVGParserRenderer(context, config);//从配置文件获取
} public static SVGParserRenderer getSVGParserRenderer(Context context, String svgContent) {
return svgContent != null && !svgContent.equals("")?new SVGParserRenderer(context, parseCssStyleToSvg(svgContent)):null;
} public static String parseCssStyleToSvg(String svgContent) {
int startIndex = svgContent.indexOf("<style");
int endIndex = svgContent.indexOf("</style>") + "</style>".length();
String styleStr = null;
if(startIndex >= 0 && endIndex >= 0) {
styleStr = svgContent.substring(startIndex, endIndex); // styleStr = <style type="text/css"><![CDATA[.strokeColor{fill:#B0B0B0;}]]></style> if(styleStr != null && !styleStr.equals("")) {
int startIndex1 = styleStr.indexOf(".");
int endIndex1 = styleStr.lastIndexOf(".");
int endendIndex = styleStr.lastIndexOf(";}") + ";}".length();
String colorStr;
if(startIndex1 == endIndex1) {
colorStr = styleStr.substring(startIndex1 + ".".length(), endendIndex);
} else {
colorStr = styleStr.substring(startIndex1, endendIndex);
}
//colorStr = strokeColor{fill:#B0B0B0;}
String[] fillColorArr = colorStr.split(";");
if(fillColorArr != null) {
for(int i = 0; i < fillColorArr.length; ++i) {
if(fillColorArr[i].contains("fill:")) {
String[] nameColorArr = fillColorArr[i].split("fill:");
if(nameColorArr != null) {
int nameStartIndex = nameColorArr[0].indexOf(".") + ".".length();
String name = nameColorArr[0].substring(nameStartIndex, nameColorArr[0].length() - 1);
String color = nameColorArr[1];
if(svgContent.contains("class=\"" + name + "\"")) {
svgContent = svgContent.replace("class=\"" + name + "\"", "fill=\"" + color + "\"");
}
}
}
}
}
} svgContent = svgContent.replace(styleStr, "");
} return svgContent;
} parseCssStyleToSvg的行参 svgContent =
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve">
<style type="text/css">
<![CDATA[
.strokeColor{fill:#B0B0B0;}
]]>
</style>
<path class="strokeColor" d="M3.494,24c0-0.587,0.476-1.063,1.063-1.063h38.886c0.588,0,1.063,0.476,1.063,1.063l0,0
c0,0.587-0.475,1.062-1.063,1.062H4.557C3.97,25.063,3.494,24.587,3.494,24L3.494,24z"/>
<g>
<g>
<g>
<path class="strokeColor" d="M3.806,23.249c0.415-0.414,1.088-0.414,1.502,0l17.054,17.053c0.415,0.415,0.415,1.087,0,1.503l0,0
c-0.415,0.414-1.088,0.414-1.503,0L3.806,24.751C3.391,24.336,3.391,23.665,3.806,23.249L3.806,23.249z"/>
</g>
<g>
<path class="strokeColor" d="M22.361,6.196c0.415,0.415,0.415,1.087,0,1.502L5.308,24.751c-0.414,0.415-1.087,0.415-1.502,0l0,0
c-0.415-0.415-0.415-1.087,0-1.503L20.858,6.196C21.273,5.781,21.946,5.781,22.361,6.196L22.361,6.196z"/>
</g>
</g>
</g>
</svg> 返回 svgContent = <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve">
<path fill="#B0B0B0" d="M3.494,24c0-0.587,0.476-1.063,1.063-1.063h38.886c0.588,0,1.063,0.476,1.063,1.063l0,0
c0,0.587-0.475,1.062-1.063,1.062H4.557C3.97,25.063,3.494,24.587,3.494,24L3.494,24z"/>
<g>
<g>
<g>
<path fill="#B0B0B0" d="M3.806,23.249c0.415-0.414,1.088-0.414,1.502,0l17.054,17.053c0.415,0.415,0.415,1.087,0,1.503l0,0
c-0.415,0.414-1.088,0.414-1.503,0L3.806,24.751C3.391,24.336,3.391,23.665,3.806,23.249L3.806,23.249z"/>
</g>
<g>
<path fill="#B0B0B0" d="M22.361,6.196c0.415,0.415,0.415,1.087,0,1.502L5.308,24.751c-0.414,0.415-1.087,0.415-1.502,0l0,0
c-0.415-0.415-0.415-1.087,0-1.503L20.858,6.196C21.273,5.781,21.946,5.781,22.361,6.196L22.361,6.196z"/>
</g>
</g>
</g>
</svg>
下载网络svg图片:
if (norDrawable == null) {
panelConfigsDownloader.startDownloadForSvgIcon(this,
OtherPageConfigsManager.getInstance(),
map.get("downloadUrl") + norFilePath, saveNorFilePath,
new SvgIconOnDownloadCompleteListener(
mKdsShortcutView[index], map, "iconUrlNor"));
}
public void startDownloadForSvgIcon(Context context,ConfigsManager configsManager,String svgDownloadUrl,
String svgFilePath,
OnDownloadCompleteListener onDownloadCompleteListener){
//下载配置文件
String parentFolder = configsManager.mConfigInfo.saveFolderName+"/"; //parentFolder = panelConfigFolder/
String fileName = "";
if(svgFilePath != null && !svgFilePath.equals("")){ //svgFilePath = ueditor/1431988818264.svg
String[] saveFileDir = svgFilePath.split("/");
for(int i = 0; i < saveFileDir.length; i++){
if(saveFileDir[i].contains(".")){
fileName = saveFileDir[i]; //fileName = 1431988818264.svg
continue;
}
parentFolder += saveFileDir[i]; //parentFolder = panelConfigFolder/ueditor
}
}else{
return;//说明不是需要下载的文件
}
File file = configsManager.getConfigFile(context, parentFolder, fileName); //file = panelConfigFolder/ueditor/1431988818264.svg
DownloadConfigFileThread downloadConfigFileThread =
new DownloadConfigFileThread(context, svgDownloadUrl, file,
onDownloadCompleteListener);
if(!file.isDirectory() && !file.exists()) {//考虑已经存在同样名字的文件或者目录,
//Logger.d("downloadConfigFile", "startDownloadForSvgIcon exists:"+file.exists());
downloadConfigFileThread.start();//开始下载
}else{
Logger.i("快捷按钮配置文件", "警告:该文件存在相同文件名,不进行下载更新,请知晓!");
downloadConfigFileThread.onDownloadComplete();//已经存在也视为完成
}
}
public class DownloadConfigFileThread extends Thread
{
public synchronized void run()
{
try
{
URL url = new URL(downurl);// http://113.78.134.110:21800/api/config/app/ui/otherpage/online/66099/100000
// 创建连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.connect();
// 获取文件大小
int length = conn.getContentLength();//40674
// 创建输入流
InputStream is = conn.getInputStream();
//处理文件路径不存在的问题
String dirFilePath = configFile.getPath();// /data/data/dongzheng.szkingdom.android.phone/files/panelConfigFolder/otherpage_temp.json
String childDirPath = "";
String[] path = dirFilePath.split("/");
for(int i = 0; i < path.length-1;i++){
if(path[i].contains("."))
continue;
childDirPath += "/" + path[i];
File file = new File(childDirPath);
if(!file.exists()) {//考虑已经存在同样名字的文件或者目录,
Logger.d("tag", "DownloadConfigFileThread mkdir newPath:"+file.getPath());
file.mkdir();
file.setExecutable(true, false);
file.setReadable(true, false);
file.setWritable(true, false);
}
}
FileOutputStream fos = new FileOutputStream(configFile); // 输出到文件 /data/data/dongzheng.szkingdom.android.phone/files/panelConfigFolder/otherpage_temp.json
// 缓存
byte buf[] = new byte[1024];
int count = 0;
// 写入到文件中
do
{
int numread = is.read(buf);
count += numread;
// 计算进度条位置
int progress = (int) (((float) count / length) * 100);
float tempSpace = count / 1024.0f / 1024.0f;
String downloadSpace = "";
try{
downloadSpace = String.format("%.3f",tempSpace)+"M";// > 1.0f ? (tempSpace+"M") : (count / 1024.0f+"KB");
}catch(Exception e){
}
if (numread <= 0)
{
//下载完成
mHandler.removeMessages(0);
Message msg = Message.obtain();
msg.what = 0;
mHandler.sendMessage(msg);
break;
}
// 写入文件
fos.write(buf, 0, numread);
} while (true);// 点击取消就停止下载.
fos.close();
is.close();
}catch(Exception e){
mHandler.removeMessages(1);
mHandler.sendEmptyMessage(1);
//e.printStackTrace();
}
}
}
公司--下载svg图片的更多相关文章
- Adobe Edge Animate –解决图形边缘精确检测问题-通过jquery加载svg图片
Adobe Edge Animate –解决图形边缘精确检测问题-通过jquery加载svg图片 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 在edge ...
- svg图片在vue脚手架vue-cli怎么使用
第一种 使用vue2-svg-icon npm install vue2-svg-icon --save-dev` 下载之后在mian.js引入 名字可以随便起,这里我起icon 引入svg资源 这时 ...
- 使用在线编辑 svg 软件修改 svg 图片
网站需要使用图标字体,但设计师给的图标大小有问题,故使用下面说陈述方法简单修改了一下.使用到的在线编辑软件地址为:https://editor.method.ac/ 问题: 注:至于如何使用图标字体( ...
- C#/VB.NET 将SVG图片添加到PDF、转换为PDF
以下内容介绍在C# 程序中如何将SVG图片添加到PDF文档.以及如何将SVG图片转换为PDF文档. 一.环境准备 先下载PDF类库工具,Spire.PDF for .NET hotfix 6.5.6及 ...
- C#获取网页的HTML码、下载网站图片、获取IP地址
1.根据URL请求获取页面HTML代码 /// <summary> /// 获取网页的HTML码 /// </summary> /// <param name=" ...
- 批量下载网站图片的Python实用小工具
定位 本文适合于熟悉Python编程且对互联网高清图片饶有兴趣的筒鞋.读完本文后,将学会如何使用Python库批量并发地抓取网页和下载图片资源.只要懂得如何安装Python库以及运行Python程序, ...
- [记录][python]python爬虫,下载某图片网站的所有图集
随笔仅用于学习交流,转载时请注明出处,http://www.cnblogs.com/CaDevil/p/5958770.html 该随笔是记录我的第一个python程序,一个爬去指定图片站点的所有图集 ...
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端 本博客前面博文中利用org.apache.http包中API进行Android客户端HTTP连接的例子 ...
- php 下载远程图片 的几种方法(转)
1.获取远程文件大小及信息的函数 function getFileSize($url){ $url = parse_url($url); if($fp = @fso ...
随机推荐
- query.setFirstResult解析
转自:https://blog.csdn.net/thinkingcao/article/details/78053622
- AJAX请求 $.ajaxSetup方法的使用
转自:https://blog.csdn.net/qq_23476319/article/details/78798885 jQuery.ajaxSetup()函数用于设置AJAX的全局默认设置. 该 ...
- Centos7 minimal 系列之NAT联网(一)
一.安装 参考:http://m.blog.csdn.net/qq_24879495/article/details/77838512 二.解决不能联网问题 打开网络共享中心,设置虚拟网卡 编辑虚拟机 ...
- http协议以及防盗链技术
http协议,又称为超文本传输协议,顾名思义,http协议不仅能传输文本,还能传输图片,视频,压缩包等文件,http协议是建立在tcp/ip协议的基础之上的,http协议对php程序员来讲可以说是重中 ...
- js 基本基础知识回顾
js中的一切的变量.函数.操作符等等都是区分大小写的. js的基本的数据类型->包含下面的5种: 1.undefined 2.Null 3.Boolean 4.Number 5.String j ...
- jquery的animate能渐变background-color
在freecodecamp 上学习复习时,写了一个demo,引用了 jquery 实现 color 的渐变动画,然后运行测试的时候,发现其他功能都正常,就是无法是实现颜色的动画. 如: $('butt ...
- create raid5
# umout 所有数据disk for i in {1..11};do umount /disk$i;done # 修改/etc/fstab,注释掉 /dev/sd[b-l] vim /etc/fs ...
- CF487E Tourists(圆方树+堆+链剖)
本题解并不提供圆方树讲解. 所以不会圆方树的出门右转问yyb 没有修改的话圆方树+链剖. 方点的权值为点双连通分量里的最小值. 然后修改的话圆点照修,每一个方点维护一个小根堆. 考虑到可能被菊花卡死. ...
- BZOJ 2806 [Ctsc2012]Cheat (后缀自动机+二分+单调队列+dp)
题目大意: 给你一堆模式串和文本串 对于每个文本串,我们可以把它不可重叠地拆分成很多子串,如果拆分出的串作为子串出现在了任何一个模式串中,我们称它是“眼熟的”,我们必须保证“眼熟的”子串总长度不小于文 ...
- 使用tf.ConfigProto()配置Session运行参数和GPU设备指定
参考链接:https://blog.csdn.net/dcrmg/article/details/79091941 tf.ConfigProto()函数用在创建session的时候,用来对sessio ...