Android Development Help Docs doc Open slow solve _python article

Source: Internet
Author: User

Fix Android help document open slow

The Netizen said is because the doc directory in the HTML file contains access to Google js file

<link rel= "stylesheet" href= "Http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic, Mediumitalic,bold "title=" Roboto ">
And

<script src= "Http://www.google.com/jsapi" type= "Text/javascript" ></script>
It is true that this has been checked.

Since these two lines of script need to access Google online, it is obvious that subsequent content loading will slowly and slowly ...

What do we do?

Open the. html file in each directory to manually delete the top two lines of content? Will definitely delete the pain. It was suggested that:

method One: Modify the Hosts file

This solution, Modify the Hosts file in the C:\WINDOWS\system32\drivers\etc directory to add

127.0.0.1 fonts.googleapis.com
127.0.0.1www.google.com
127.0.0.1Www.google.com/jsapi
127.0.0.1Www.google-analytics.com
127.0.0.1 apis.google.com/js/

The speed will improve a lot.

method Two: Write the Java program Bulk annotation

Traverse all files in the doc directory, delete the top two lines of each file, refer to

/* * Remove JavaScript code that requires networking in Android documents */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/a        Ndroid-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 = "";                If it is an HTML file, comment out the specific JavaScript code 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 to modify the contents of the file * src will be replaced content * DST will be replaced with the content of the layer */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 Bufferedwri            ter (new FileWriter (Dist));            Writer.write (cont);            Writer.flush ();            Writer.close ();        return true;            } catch (IOException e) {e.printstacktrace ();        return false; }    }}

method Three: Execute the script

Through the shell to delete the line JS code, very simple and convenient, than the above Java convenient 100 times times, but can not delete the first section of JS code.

Find. -name "*.html" |xargs grep-l "Jsapi" |xargs sed-i '/jsapi/d '
I haven't tried.


Life is short, I use Python

method Four: Python code bulk Delete

Idea: Traverse the doc or docs directory and subdirectories, find all. html files, open these files, read the contents of the file, replace the above JS content is empty, write the changes back to the file, the end.

It's complicated, and it's really simple to implement in Python.

Import Oss1 = "<link rel=" stylesheet "href=" Http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin, Italic,mediumitalic,bold "title=" Roboto ">" s2 = "<script src=" Http://www.google.com/jsapi "type=" text/ JavaScript "></script>" s3 = "<script type=" Text/javascript "async=" "src=" Https://apis.google.com/js /plusone.js "></script>" s4 = "<script type=" Text/javascript "async=" "src="/HTTP/ Www.google-analytics.com/ga.js "></script>" for Root,dirs,files in Os.walk (R ' C:\AndroidSdk\docs '):    For file in Files:        fd = root + os.sep + file        if ". html" in FD:            print fd            f = open (fd, ' R ')            s = F.read () . replace (S1, ""). Replace (S2, ""). Replace (S3, ""). Replace (S4, "")            F.close ()            f = open (fd, ' W ')            F.write (s)            F.close ()      

Caught dead explained that, assuming that my Android development help document under C:\androidsdk\docs, traversing all directories and filenames under it can only be done with the OS walk function.

For Root,dirs,files in Os.walk (R ' C:\AndroidSdk\docs '):
The walk return value, the directory root that is currently traversed, what subdirectories are under it dirs, what files are available, and what is important is recursive traversal of the specified directory C:\AndroidSdk\docs.

Get rid of the HTML file two of the effect of the speed of JS, the first HTML file,

    For file in Files:        fd = root + os.sep + file
All file names are constructed to find (match). html files just like this

        If ". html" in FD:            print FD
Next is to kill the shadow display (speed) of the JS, the replacement file in the corresponding content is empty.

f = open (fd, ' r ') s = F.read (). Replace (S1, ""). Replace (S2, ""). Replace (S3, ""). Replace (            S4, "")            F.close ()            f = Open (FD, ' W ')            f.write (s)            f.close ()

Run it, 1 minutes to run the end of the entire docs under a total of more than 9,000 files, traversal, read and write time.

Finally find a doc and try C:\AndroidSdk\docs\reference\android\widget\Spinner.html.

The speed, the leverage.

I'm using a python2.7.5.

Oh, welcome to reply to criticism! or Praise!


Python Https://www.python.org/ftp/python/2.7.9/python-2.7.9.msi












Android Development Help Docs doc Open slow solve _python article

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.