📄 splashcanvas.java
字号:
package com.ismyway.anyview;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import java.io.*;
import javax.microedition.lcdui.game.Sprite;
import java.util.Vector;
/**
* <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 SplashCanvas extends Canvas {
private Image splashCover = null;
private Menu menu = null;
Selector fontSize = null, lineSpace = null, readType = null,
flipMethod = null, autoFlip = null, openHistory = null;
ColorSelector colorSelector = null;
FileSelector openFile = null;
boolean showMenu = true;
public final static String[] items = {"历史文件", "打开文件", "字体大小", "文字颜色",
"背景颜色", "行 间 距", "阅读方式", "使用说明",
"退出程序"};
AbstractWindow currentWindow = null;
private Vector allBookMarks = new Vector();
public final static int ANCHOR = Graphics.LEFT | Graphics.TOP;
private String[] itemFiles = null;
private String[] realFiles = null;
Message message = new Message();
private long startTime = 0; //按键开始的时间
private boolean deleteHistory = false; //用户是否删除过阅读历史
public final static String[] itemFonts = {"12*12点阵", "24*16姚体", "16*16点阵",
"16*16点阵(粗)", "18*18点阵", "20*20点阵",
"24*24点阵", "16*16(GBK)",
"16*16(GBK粗)"};
public final static String[] itemLineSpace = {"0 px", "1 px", "2 px",
"3 px", "4 px", "5 px", "6 px",
"7 px", "8 px"};
public final static String[] itemReadType = {"纵向阅读", "横向阅读"};
public SplashCanvas() {
this.setFullScreenMode(true);
try {
splashCover = Image.createImage("/res/cover.png");
} catch (IOException ex) {
}
//加载背景图
/*
splashCover = Image.createImage(240, 320);
Graphics g = splashCover.getGraphics();
g.setColor(0);
g.fillRect(0, 0, 240, 320);
Image temp;
FileSystemReader fsr = new FileSystemReader(AnyView.Root +
"anyview/background.png");
if (fsr.exists() && !fsr.isDirectory()) {
try {
byte[] b = fsr.read((int) fsr.fileSize());
temp = Image.createImage(b, 0, b.length);
b = null;
fsr.close();
} catch (Exception ex1) {
temp = null;
}
if (null != temp) {
g.drawImage(temp, 0, 0, ANCHOR);
}
}
AnyView.cf.setColor(0);
temp = AnyView.cf.buildImage("Anyview 0.2a");
g.drawImage(temp, AnyView.ScreenWidth - temp.getWidth() - 2,
AnyView.ScreenHeight - temp.getHeight() - 2,
ANCHOR);
g.drawImage(temp, AnyView.ScreenWidth - temp.getWidth(),
AnyView.ScreenHeight - temp.getHeight(),
ANCHOR);
AnyView.cf.setColor(0xFFFFFF);
temp = AnyView.cf.buildImage("Anyview 0.2a");
g.drawImage(temp, AnyView.ScreenWidth - temp.getWidth() - 1,
AnyView.ScreenHeight - temp.getHeight() - 1,
ANCHOR);
temp = null;
System.gc();*/
buildHistoryFileList();
menu = new Menu(items);
}
private void buildHistoryFileList() {
Record r = new Record("avbookmark");
r.open();
int num = r.getNumRecords();
if (num < 1) { //没有任何记录
r.close();
return;
}
//寻找符合当前文件的书签
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;
}
allBookMarks.addElement(ibm);
}
r.close();
itemFiles = new String[allBookMarks.size()];
realFiles = new String[allBookMarks.size()];
int len = allBookMarks.size() - 1;
//反向显示历史文件列表
for (int i = len; i > -1; i--) {
BookMark ibm = (BookMark) allBookMarks.elementAt(i);
realFiles[len - i] = ibm.getFilename();
itemFiles[len - i] = realFiles[len - i].substring(realFiles[len - i].
lastIndexOf('/') + 1);
}
}
/*public void paint(Graphics g) {
//g.setColor(0);
//g.fillRect(0, 0, srcW, srcH);
if (splashCover != null) {
g.drawImage(splashCover, 0, 0, ANCHOR);
}
if (showMenu) {
g.drawImage(menu.getWindow(), 0, srcH - menu.getHeight(),
ANCHOR);
if (currentWindow != null) {
g.drawImage(currentWindow.getWindow(),
(srcW - currentWindow.getWidth()) >> 1,
(srcH - currentWindow.getHeight()) >> 1, ANCHOR);
}
}
AnyView.debug(g, "" + Runtime.getRuntime().totalMemory(), 10, 10,
ANCHOR);
AnyView.debug(g, "" + Runtime.getRuntime().freeMemory(), 10, 30, ANCHOR);
}*/
public void destroy() {
if (currentWindow != null) {
currentWindow.destroy();
currentWindow = null;
}
splashCover = null;
menu = null;
System.gc();
//System.out.println("destroy(): " + Runtime.getRuntime().freeMemory());
}
// Method to Handle User Inputs
public void keyPressed(int keyCode) {
keyCode = mapKey(keyCode);
if (message.getWindowState() == AbstractWindow.OPENING) {
message.setWindowState(AbstractWindow.HIDE);
repaint();
return;
}
if (keyCode == -3) {
if (currentWindow != null) { //已弹出当前窗口
if (currentWindow.bof()) {
currentWindow.destroy();
currentWindow = null;
showMenu = true;
} else {
currentWindow.keyLeft();
}
}
repaint();
return;
}
// Right
if (keyCode == -4) {
if (currentWindow != null) {
currentWindow.keyRight();
}
repaint();
return;
}
// Up
if (keyCode == -1) {
if (currentWindow == null) {
menu.keyUp();
} else {
currentWindow.keyUp();
}
repaint();
return;
}
// Down
if (keyCode == -2) {
if (currentWindow == null) {
menu.keyDown();
} else {
currentWindow.keyDown();
}
repaint();
return;
}
if (keyCode == -5) {
if (currentWindow == null) { //当前没有打开菜单项窗口
menu.keyFire();
if (menu.getSelectedIndex() != 8) {
openSubWindow(menu.getSelectedIndex());
} else {
saveRec();
destroy();
AnyView.av.exit();
return;
}
} else { //交由当前窗口处理
currentWindow.keyFire();
switch (menu.getSelectedIndex()) {
case 0: //历史文件
openHistory(0);
break;
case 1: //打开文件
break;
case 2: //字体大小
setFontSize();
break;
case 3: //文字颜色
setFontColor();
break;
case 4: //背景颜色
setBackColor();
break;
case 5: //行 间 距
setLineSpace();
break;
case 6: //阅读方式
setReadType();
break;
case 7: //使用说明
readme();
break;
}
}
repaint();
}
}
public void paint(Graphics g) {
if (splashCover != null) {
g.drawImage(splashCover, 0, 0, ANCHOR);
}
if (showMenu) { //仅显示菜单
if (AnyView.readType == 1) { //横屏
g.drawRegion(menu.getWindow(), 0, 0, menu.getWidth(),
menu.getHeight(), Sprite.TRANS_ROT270,
menu.getLeft(), menu.getTop() - menu.getWidth(),
ANCHOR);
} else {
g.drawImage(menu.getWindow(), menu.getLeft(), menu.getTop(),
ANCHOR);
}
} else { //仅显示子窗口
if (currentWindow != null) {
if (AnyView.readType == 1) { //横屏
g.drawRegion(currentWindow.getWindow(), 0, 0,
currentWindow.getWidth(),
currentWindow.getHeight(), Sprite.TRANS_ROT270,
currentWindow.getLeft(),
currentWindow.getTop() -
currentWindow.getWidth(),
ANCHOR);
} else {
g.drawImage(currentWindow.getWindow(),
currentWindow.getLeft(),
currentWindow.getTop(), ANCHOR);
}
}
}
if (message.getWindowState() == AbstractWindow.OPENING) {
if (AnyView.readType == 1) { //横屏
g.drawRegion(message.getWindow(), 0, 0, message.getWidth(),
message.getHeight(), Sprite.TRANS_ROT270,
message.getLeft(),
message.getTop() - message.getWidth(),
ANCHOR);
} else {
g.drawImage(message.getWindow(), message.getLeft(),
message.getTop(), ANCHOR);
}
}
//AnyView.debug(g, AnyView.usedMemory(), 10, 10, ANCHOR);
//System.gc();
}
/*private void drawCanvas() {
Graphics g = getGraphics();
if (splashCover != null) {
g.drawImage(splashCover, 0, 0, ANCHOR);
}
if (showMenu) {
g.drawImage(menu.getWindow(), 0, srcH - menu.getHeight(),
ANCHOR);
if (currentWindow != null) {
g.drawImage(currentWindow.getWindow(),
(srcW - currentWindow.getWidth()) >> 1,
(srcH - currentWindow.getHeight()) >> 1, ANCHOR);
}
}
AnyView.debug(g, AnyView.usedMemory(), 10, 10, ANCHOR);
}*/
// Method to Handle User Inputs
/*synchronized private void input() {
int keyStates = getKeyStates();
// Left
if ((keyStates & LEFT_PRESSED) != 0) {
if (showMenu) {
if (currentWindow != null) {
if (currentWindow.bof()) {
currentWindow.destroy();
currentWindow = null;
} else {
currentWindow.keyLeft();
}
} else {
showMenu = false;
menu = null;
}
}
}
// Right
if ((keyStates & RIGHT_PRESSED) != 0) {
if (showMenu) {
if (currentWindow != null) {
currentWindow.keyRight();
} else {
menu.keyRight();
}
}
}
// Up
if ((keyStates & UP_PRESSED) != 0) {
if (showMenu) {
if (currentWindow == null) {
menu.keyUp();
} else {
currentWindow.keyUp();
}
}
}
// Down
if ((keyStates & DOWN_PRESSED) != 0) {
if (showMenu) {
if (currentWindow == null) {
menu.keyDown();
} else {
currentWindow.keyDown();
}
}
}
// Fire
if ((keyStates & FIRE_PRESSED) != 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -