码迷,mamicode.com
首页 > 移动开发 > 详细

关于android帮助文档打开慢

时间:2016-09-24 10:24:34      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

打开慢的原因是:Doc目录下的html文件里含有访问google的js文件
<link rel="stylesheet"
href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" title="roboto">

 <script src="http://www.google.com/jsapi" type="text/javascript"></script>
所以你在打开文档的时候会在线访问Google,所以打开速度会很慢!

 

解决办法:

1、删除文件中的js

  但是每个文件中几乎都含有这段js,所以你要一个一个打开修改,简直龟速。。所以这种办法经常pass

2、修改Hosts文件(相当于本地的DNS,该文件具体作用自己百度,我就不多说了)

  该文件位置: C:\Windows\System32\drivers\etc\Hosts文件

  在下面添加:127.0.0.1 fonts.googleapis.com
        127.0.0.1 www.google.com
        127.0.0.1 www.google.com/jsapi
        127.0.0.1 www.google-analytics.com
        127.0.0.1 apis.google.com/js/

  注意一定要单行添加!!否则可能会出错,这样配置后,你的电脑看见谷歌网址就会找你自己的电脑啦!

3、编写Java程序批量注释

  遍历doc目录下的所有文件,将每个文件的上边两行内容删除,参考
/*
 * 去掉Android文档中需要联网的javascript代码
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FormatDoc {
    public static int j=1;
    /**
     * @param args
     */
    public static void main(String[] args) {
        
        File file = new File("D:/android/android-sdk-windows/docs/");
        searchDirectory(file, 0);
        System.out.println("OVER");
    }

    public static void searchDirectory(File f, int depth) {
        if (!f.isDirectory()) {
            String fileName = f.getName();
            if (fileName.matches(".*.{1}html")) {
                String src= "<(link rel)[=]\"(stylesheet)\"\n(href)[=]\"(http)://(fonts.googleapis.com/css)[?](family)[=](Roboto)[:](regular,medium,thin,italic,mediumitalic,bold)\"( title)[=]\"roboto\">";
                String src1 = "<script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script>";
                String dst = "";
                //如果是html文件则注释掉其中的特定javascript代码
                annotation(f, src, dst);
                annotation(f, src1, dst);
            }
        } else {
            File[] fs = f.listFiles();
            depth++;
            for (int i = 0; i < fs.length; ++i) {
                File file = fs[i];
                searchDirectory(file, depth);
            }
        }
    }

    /*
     * f 将要修改其中特定内容的文件
     * src 将被替换的内容
     * dst 将被替换层的内容
     */
    public static void annotation(File f, String src, String dst) {
        String content = FormatDoc.read(f);
        content = content.replaceFirst(src, dst);
        int ll=content.lastIndexOf(src);
        System.out.println(ll);
        FormatDoc.write(content, f);
        System.out.println(j++);
        return;

    }

    public static String read(File src) {
        StringBuffer res = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = new BufferedReader(new FileReader(src));
            int i=0;
            while ((line = reader.readLine()) != null) {
                if (i!=0) {
                    res.append(‘\n‘);
                }
                res.append(line);
                i++;
            }
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res.toString();
    }

    public static boolean write(String cont, File dist) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(dist));
            writer.write(cont);
            writer.flush();
            writer.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

 

4、浏览器脱机工作

  打开文件,浏览器脱机工作就OK,这种方法最简单,但是每次都要设置。我用的Firefox,脱机工作位置在   文件---脱机工作,其它浏览器暂时没有研究。

 

5、执行脚本

通过shell删除那行js代码,非常简洁方便,比上面的的java方便100倍,不过不能删掉第一段js代码。
find . -name "*.html"|xargs grep -l "jsapi"|xargs sed -i ‘/jsapi/d‘

此方法还没有试过。

 

关于android帮助文档打开慢

标签:

原文地址:http://www.cnblogs.com/yangxiu/p/5902438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!