热门技术
热门技术 您当前的位置:主页 > 热门技术 >
Android docs4.3API
发布时间:2019-01-28 编辑:环亚

网上找的类,加快访问Android docs API,主要原因是加载网上的js文件慢,另外一个是加载google字体慢!

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
 
public class AndroidDoc {
 
    private static final String ANDROID_SDK_HOME = "ANDROID_SDK_HOME";
     
    private static final String TAG = "<script src=\"http://www.google.com/jsapi\" type=\"text/javascript\"></script>";
     
    //private static final String TAG = "";
    private static String androidSDKHome;
 
    public static void main(String[] args) {
        Map map = System.getenv();
        androidSDKHome = map.get(ANDROID_SDK_HOME);
        if (androidSDKHome != null) {
            System.out.println("Detected the Android SDK Installation path:"
                    + androidSDKHome);
            File docs = new File(androidSDKHome + "\docs");
            System.out.println("It will take several minutes, please wait...");
            traverse(docs);
            System.out
                    .println("Operation Down!!! Now you can visit AAAroid Doc without waiting...");
        } else {
            System.out
                    .println("Please configure the Android SDK Environment variable (ANDROID_SDK_HOME)!");
        }
    }
 
    /**
     * 遍历Android SDK安装目录下的docs目录
     *
     * @param dir
     */
    private static void traverse(File dir) {
        if (dir.isDirectory()) {
            File[] files = dir.listFiles(new FileFilter() {
 
                @Override
                public boolean accept(File file) {
                    if (file.isFile() && file.getName().endsWith(".html")) {
                        BufferedReader reader = null;
                        try {
                            reader = new BufferedReader(new FileReader(file));
                            String buffer;
                            while ((buffer = reader.readLine()) != null) {
                                if (buffer.trim().equalsIgnoreCase(TAG)) {
                                    return true;
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            try {
                                reader.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    } else if (file.isDirectory()) {
                        return true;
                    }
                    return false;
                }
            });
            for (File file : files) {
                if (file.isDirectory()) {
                    System.out.println("Scanning Folder:"
                            + file.getAbsolutePath());
                    traverse(file);
                } else {
                    doChange(file);
                }
            }
        }
    }
 
    /**
     * 注释html中的某行Javascript代码
     *
     * @param file
     * @return
     */
    private static boolean doChange(File file) {
        System.out.println("Extracting File:" + file.getAbsolutePath() + "...");
        String desPath = file.getParent() + "\" + UUID.randomUUID().toString() + ".html";
        File des = new File(desPath);
        BufferedReader reader = null;
        BufferedWriter writer = null;
        try {
            des.createNewFile();
            reader = new BufferedReader(new FileReader(file));
            writer = new BufferedWriter(new FileWriter(des));
            String buffer;
            while ((buffer = reader.readLine()) != null) {
                if (buffer.trim().equalsIgnoreCase(TAG)) {
                    buffer = "";
                }
                writer.write(buffer + "
");
                writer.flush();
            }
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
                file.delete();
                des.renameTo(file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
 
}

直接编译运行,注释的三行,三行代表替换三次

加载慢原因有两个一个是加载Google的字体,二个是加载Google的JS文件.

如果感觉麻烦直接去的我网盘下载,地址:http://pan.baidu.com/s/1eQd4gEm


http://www.bkjia.com/Androidjc/818356.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/818356.htmlTechArticle网上找的类,加快访问Android docs API,主要原因是加载网上的js文件慢,另外一个是加载google字体慢! import java.io.BufferedReader;import java.io.Buffe...

本文源自: AG环亚集团官网

上一篇:android点滴之ContentObserver的使用 下一篇:没有了

Copyright © 2005-2016 http://www.letskungfu.com AG环亚集团官网_AG亚游平台_AG8环亚集团_新浪新闻版权所有 AG环亚集团官网_AG亚游平台_AG8环亚集团_新浪新闻