⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 anyview.java

📁 很好的基于java的手机文本阅读器anyview 2.0源码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ismyway.anyview;

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Form;
import java.io.DataOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.microedition.rms.RecordStore;
import java.io.DataInputStream;
import javax.microedition.rms.RecordStoreException;

/**
 * <p>Title: AnyView</p>
 *
 * <p>Description: E680(I) Reader</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: www.ismyway.com</p>
 *
 * @author ZhangJian
 * @version 1.0
 */
public class AnyView extends MIDlet {
    public static CustomFont cf = null;
    public static Image UpArrow = null, DownArrow = null;
    public static AnyView av = null;
    public static String Root = "";
    public static long StartTime = -1l;
    public final static int ScreenWidth = 240;
    public final static int ScreenHeight = 320;

    private SplashCanvas sc = null;
    private IAVReaderCanvas iav = null;
    private TXTReaderCanvas txt = null;
    public Display display;
    private StringBuffer error = new StringBuffer("");

    public static int fontSize = 0;
    public static int lineSpace = 0;
    public static int readType = 0; //0纵向,1横向
    public static String rootPath = ""; //阅读文档的根目录
    public static int frontColor = 51;
    public static int backColor = 0;

    public static int delay = 125;
    public static int background = 0x3272AE;
    public static int bordorcolor = 0xC5C4C0;
    public static int fontcolor = 0xFFFFFF;
    public static int titlecolor = 0;
    public static boolean showhiddenfiles = false;
    public static boolean openlastfile = false;
    public static int guageheight = 1;
    public static int foldercolor = 0xffffff;

    public AnyView() {
        usedMemory();
        av = this;
        init();
        usedMemory();
        if (!checkSystem()) {
            Form f = new Form("系统环境错误!");
            f.append(error.toString());
            display.setCurrent(f);
            return;
        }
        loadProperty();
        if (!openlastfile) {
            switchSplash();
        } else {
            Record r = new Record("avbookmark");
            r.open();
            int num = r.getNumRecords();
            if (num < 1) { //没有任何记录
                r.close();
                switchSplash();
                return;
            }

            String[] f = new String[num];

            //寻找符合当前文件的书签
            for (int i = 0; i < num; i++) {
                byte[] b = r.getRecord(1 + i); //RecordStore的RecordID总是从1开始
                BookMark ibm = new BookMark();

                if (!ibm.decodeBookMark(b)) {
                    continue;
                }
                f[i] = ibm.getFilename();
            }
            r.close();

            int len = f.length - 1;
            FileSystemReader fsr = new FileSystemReader(f[len]);
            if (fsr.isDirectory() || !fsr.exists()) {
                switchSplash();
                return;
            } else {
                switchTxt(f[len]);
                return;
            }

        }
        //switchTxt("/mmc/anyview/1.txt");
        //display.setCurrent(new Search("Search"));

        //System.out.println(AnyView.usedMemory());
    }

    void init() {
        StartTime = System.currentTimeMillis();
        display = Display.getDisplay(this);
        openRec();
        cf = new CustomFont(fontSize);
        int[] arrow = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0xFFFFFFFF,
                      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0,
                      0, 0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0, 0, 0, 0,
                      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                      0xFFFFFFFF, 0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFF, 0xFFFFFFFF,
                      0xFFFFFFFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFF, 0, 0,
                      0, 0, 0};
        DownArrow = Image.createRGBImage(arrow, 11, 6, true);
        arrow = null;
        arrow = new int[] {0, 0, 0, 0, 0, 0xFFFFFFFF, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0, 0, 0, 0, 0, 0,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0,
                0, 0, 0, 0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0, 0, 0xFFFFFFFF,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0xFFFFFFFF, 0xFFFFFFFF,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
                0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
        UpArrow = Image.createRGBImage(arrow, 11, 6, true);
        arrow = null;
    }

    boolean checkSystem() {
        String[] lists = FileSystemReader.listRoots();
        if (null == lists || lists.length < 2) {
            return false;
        }
        Root = lists[1];
        lists = null;

        FileSystemReader fsa = new FileSystemReader(Root + "anyview/");
        if (!fsa.isDirectory()) {
            error.append("MMS/SD卡下无anyview目录!\n");
            fsa.close();
            return false;
        }
        fsa.close();

        fsa = new FileSystemReader(Root + "anyview/uc2gb");
        if (!fsa.exists()) {
            error.append("anyview目录下缺少文件uc2gb!\n");
            fsa.close();
            return false;
        }

        fsa = new FileSystemReader(Root + "anyview/df16");
        if (!fsa.exists()) {
            error.append("anyview目录下缺少文件df16!\n");
            fsa.close();
            return false;
        }

        fsa = new FileSystemReader(Root + "anyview/df12");
        if (!fsa.exists()) {
            error.append("anyview目录下缺少文件df12!\n");
            fsa.close();
            return false;
        }

        fsa = null;
        /*fsa = new FileSystemReader(Root + "anyview/uc2gb");
                 if (!fsa.exists()) {
            fsa.close();
            return false;
                 }*/
        return true;
    }

    /**
     * 获得用户定义的系统参数
     */
    private void loadProperty() {
        FileSystemReader fsa = new FileSystemReader(Root +
                "anyview/anyview.ini");
        if (fsa.exists() && !fsa.isDirectory()) {
            int len = (int) fsa.fileSize();
            byte b[] = fsa.read(len);
            if (null != b && b.length > 0) { //解析配置文件
                String str = new String(b);

                int offset = 0;
                int end = 0;
                String temp;

                //showhiddenfiles
                try {
                    offset = str.indexOf("showhiddenfiles=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 16, end);
                    int fps = Integer.parseInt(temp);
                    showhiddenfiles = (fps == 1);
                } catch (Exception ex) {
                    showhiddenfiles = false;
                }

                //openlastfile
                try {
                    offset = str.indexOf("openlastfile=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 13, end);
                    int fps = Integer.parseInt(temp);
                    openlastfile = (fps == 1);
                } catch (Exception ex) {
                    openlastfile = false;
                }

                //background
                try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -