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

📄 anyview.java

📁 很好的基于java的手机文本阅读器anyview 2.0源码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    offset = str.indexOf("background=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 13, end);
                    background = Integer.parseInt(temp, 16);
                } catch (Exception ex) {
                    background = 0x999999;
                }

                //bordercolor
                try {
                    offset = str.indexOf("bordorcolor=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 14, end);
                    bordorcolor = Integer.parseInt(temp, 16);
                } catch (Exception ex) {
                    bordorcolor = 0xCCCCCC;
                }

                //fontcolor
                try {
                    offset = str.indexOf("fontcolor=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 12, end);
                    fontcolor = Integer.parseInt(temp, 16);
                } catch (Exception ex) {
                    fontcolor = 0xEEEEEE;
                }

                //fontborder
                try {
                    offset = str.indexOf("titlecolor=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 13, end);
                    titlecolor = Integer.parseInt(temp, 16);
                } catch (Exception ex) {
                    titlecolor = 0x333333;
                }

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

                //foldercolor
                try {
                    offset = str.indexOf("foldercolor=");
                    end = str.indexOf(";", offset);
                    temp = str.substring(offset + 14, end);
                    foldercolor = Integer.parseInt(temp, 16);
                } catch (Exception ex) {
                    foldercolor = 0xff0000;
                }
            }
        }
        fsa.close();
    }

    /**
     * 旋转屏幕
     * @param rotate boolean
     */
    public void rotate(boolean rotate) {
        if (rotate) {
            readType = 1;
        } else {
            readType = 0;
        }
    }

    public void switchSplash() {
        deleteAll();
        sc = new SplashCanvas();
        display.setCurrent(sc);
        //System.gc();
        /*System.out.println("after switchSplash(): " +
                           Runtime.getRuntime().freeMemory());*/
    }

    public void switchIav(String filename) {
        deleteAll();
        iav = new IAVReaderCanvas(filename);
        display.setCurrent(iav);
        //System.gc();
        /*System.out.println("after switchIav(): " +
                           Runtime.getRuntime().freeMemory());*/
    }

    public void switchTxt(String filename) {
        deleteAll();
        txt = new TXTReaderCanvas(filename);
        display.setCurrent(txt);
        //System.gc();
        /*System.out.println("after switchIav(): " +
                           Runtime.getRuntime().freeMemory());*/
    }


    void deleteAll() {
        sc = null;
        iav = null;
        txt = null;
        //System.gc();
        /*System.out.println("after deleteAll(): " +
                           Runtime.getRuntime().freeMemory());*/
    }

    protected void destroyApp(boolean _boolean) {
    }

    protected void pauseApp() {
    }

    protected void startApp() {
    }

    public void exit() {
        saveRec();
        System.gc();
        destroyApp(false);
        notifyDestroyed();
    }

    void saveRec() {
        try {
            RecordStore recordstore = RecordStore.openRecordStore("anyview", true);
            byte[] abyte = encodeRecord();
            int num = recordstore.getNumRecords();
            if (num == 0) { //原来没有记录
                recordstore.addRecord(abyte, 0, abyte.length);
            } else {
                recordstore.setRecord(1, abyte, 0, abyte.length);
            }
            recordstore.closeRecordStore();
            System.gc();
        } catch (RecordStoreException ex) {

        }
    }

    void openRec() {
        try {
            RecordStore recordstore = RecordStore.openRecordStore("anyview", true);
            int num = recordstore.getNumRecords();
            if (num > 0) { //有记录
                byte[] b = recordstore.getRecord(1);
                decodeRecord(b);
            }
            recordstore.closeRecordStore();
            System.gc();
        } catch (RecordStoreException ex) {
            fontSize = 0;
            lineSpace = 0;
            readType = 0;
            rootPath = "";
            frontColor = 51;
            backColor = 0;
        }
    }

    public byte[] encodeRecord() {
        byte[] abyte0 = null;
        try {
            ByteArrayOutputStream bytearrayoutputstream = new
                    ByteArrayOutputStream();
            DataOutputStream dataoutputstream = new DataOutputStream(
                    bytearrayoutputstream);

            dataoutputstream.writeInt(fontSize);
            dataoutputstream.writeInt(lineSpace);
            dataoutputstream.writeInt(readType);
            dataoutputstream.writeUTF(rootPath);
            dataoutputstream.writeInt(frontColor);
            dataoutputstream.writeInt(backColor);

            abyte0 = bytearrayoutputstream.toByteArray();
            dataoutputstream.close();
            bytearrayoutputstream.close();
        } catch (Exception exception) {}
        return abyte0;
    }

    public void decodeRecord(byte abyte0[]) {
        try {
            ByteArrayInputStream bytearrayinputstream = new
                    ByteArrayInputStream(
                            abyte0);
            DataInputStream datainputstream = new DataInputStream(
                    bytearrayinputstream);

            fontSize = datainputstream.readInt();
            lineSpace = datainputstream.readInt();
            readType = datainputstream.readInt();
            rootPath = datainputstream.readUTF();
            frontColor = datainputstream.readInt();
            backColor = datainputstream.readInt();

            datainputstream.close();
            bytearrayinputstream.close();
        } catch (Exception exception) {
            fontSize = 0;
            lineSpace = 0;
            readType = 0;
            rootPath = "";
            frontColor = 51;
            backColor = 0;
        }
    }


    public static void debug(Graphics g, String str, int x, int y, int anchor) {
        int color = g.getColor();
        g.setColor(0xff0000);
        g.drawString(str, x, y, anchor);
        g.setColor(color);
    }

    public static String usedMemory() {
        long used = Runtime.getRuntime().totalMemory() -
                    Runtime.getRuntime().freeMemory();
        used >>= 10;
        //System.out.println("used memory: " + used + " k");
        return ("used memory: " + used + " k");
    }
}

⌨️ 快捷键说明

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