Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android docs4.3API

Android docs4.3API

編輯:關於Android編程

網上找的類,加快訪問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 Android 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 + "\n");
                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


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved