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

📄 configure.java

📁 最强手机阅读器Anyview3.0版的界面代码
💻 JAVA
字号:
package com.ismyway.anyview.others;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;

import com.ismyway.util.Record;

/**
 * 可共用的变量
 * @author ZhangJian
 *
 * AnyviewRoot, lastOpenDir, openLastFile, totalReadTimes, 
 * totalReadBooks, totalReadCharacter, totalUsedTimes
 */

public class Configure {
	/**
	 * 系统文件夹路径,可为空
	 */
	public static String anyviewRoot = "";
	/**
	 * 最后打开文件夹的路径,默认为/
	 */
	public static String lastOpenDir = "";
	/**
	 * 使用Anyview时的密码
	 */
	public static String accessPassword = "";
	/**
	 * 使用配置文件的索引
	 */
	public static byte configureIndex = 0;
	/**
	 * 隐藏未知格式的文件
	 */
	public static boolean hiddenUnknowFile = false;
	/**
	 * 是否自动打开最后一次的阅读文件
	 */
	public static boolean openLastFile = false;
	/**
	 * 各种动画效果
	 */
	public static boolean enableAnimate = false;
	/**
	 * 显示隐藏文件
	 */
	public static boolean showHiddenFile = false;
	/**
	 * 按键时的响应时间
	 */
	public static int delayTime = 60;
	/**
	 * 列表循环
	 */
	public static boolean listRecycle = true;
	/**
	 * 总计阅读的时间,以秒为单位
	 */
	public static long totalReadTimes = 0L;
	/**
	 * 总计阅读书籍
	 */
	public static int totalReadBooks = 0;
	/**
	 * 总计阅读量
	 */
	public static long totalReadCharacter = 0L;
	/**
	 * 使用次数
	 */
	public static int totalUsedTimes = 0;
	/**
	 * 屏幕旋转方式, {0, 90, 180, 270}
	 */
	public static byte rotateScreen = 0;
	/**
	 * 键盘映射表名字
	 */
	public static String keyMapRc = "";
	/**
	 * 页边距(上下左右),第项使用2个字节
	 */
	public static int padding = 0;
	/**
	 * 消除回车符
	 */
	public static boolean noBr = false;
	/**
	 * 智能换行
	 */
	public static boolean smartLine = false;
	/**
	 * 是否显示阅读百分比
	 */
	public static boolean showPercent = true;
	/**
	 * 背景灯常亮
	 */
	public static boolean flashBackLight = false;
	/**
	 * 亮度值
	 */
	public static byte lightValue = 100;
	/**
	 * 自动关机时间
	 */
	public static long shutDownTime = 0;
	/**
	 * 用户选择的系统字体路径,分别为0:点阵 1:小 2:中 3:大
	 */
	public static boolean enableSystemGC = true;
	/**
	 * 界面语言
	 */
	public static String language = "zh.rc";
	/**
	 * 显示阅读历史
	 */
	public static boolean showHistory = true;
	/**
	 * 显示内存情况
	 */
	public static boolean showMemory = false;
	/**
	 * 保留的数据
	 */
	private static byte[] reserve = new byte[1024]; 

	//////  以下为用户配置文件保存的变量
	/**
	 * 用户的界面主题
	 */
	public static String themeName = "";
	/**
	 * 用户选择的系统字体路径,分别为 0:点阵 1:小 2:中 3:大
	 */
	public static int innerFontIndex = 0;
	/**
	 * 用户选择的自定义字体路径,当为空时使用系统字体
	 */
	public static String fontName = "";
	/**
	 * 用户选择阅读的前景色1
	 */
	public static int fontColor1 = 0;
	/**
	 * 用户选择阅读的前景色2
	 */
	public static int fontColor2 = 0;
	/**
	 * 用户选择阅读的背景色
	 */
	public static int backgroundColor = 0xFFFFFF;
	/**
	 * 阅读文字下划线的样式 0:实线 1:虚线
	 */
	public static boolean showUnderline = true;
	/**
	 * 阅读文字下划线的为虚线
	 */
	public static boolean underlineDot = true;
	/**
	 * 阅读文字下划线的颜色
	 */
	public static int underlineColor = 0xCCCCCC;
	/**
	 * 进度条的颜色,默认同文字颜色
	 */
	public static int indicatorColor = 0;
	/**
	 * 用户定义的阅读背景图片
	 */
	public static String backgroundImage = "";
	/**
	 * 用户定义的阅读时的行间距
	 */
	public static int linePadding = 4;
	/**
	 * 自动滚屏时的间隔时间
	 */
	public static int pixelScrollDelay = 1;
	/**
	 * 自动滚屏时的间隔时间
	 */
	public static int lineScrollDelay = 10;
	/**
	 * 自动滚屏时的间隔时间
	 */
	public static int pageScrollDelay = 50;
	/**
	 * 菜单位于顶部
	 */
	public static boolean menuOnTop = true;
	/**
	 * 是否使用阴影文字
	 */
	public static boolean colorShade = false;
	/**
	 * 划屏弹出菜单时的距离
	 */
	public static int slipDistance = 150;
	/**
	 * 翻页时是否保留一行
	 */
	public static boolean reserveLineWhenTurnPage = false;
	/**
	 * 当前配置的名称
	 */
	public static String configureName = "Default";
	/**
	 * 主题风格,是否启用华丽样式
	 */
	public static boolean complexTheme = false;
	/**
	 * 进度指示器的方向
	 * 分别为 0无 1上 2下 3左 4右
	 */
	public static byte indicator = 4;
	/**
	 * 背景图片的alpha值,0表示全透明,255表示不透明
	 */
	public static short enableBackground = 1;

	///// 以下由当前类使用
	/**
	 * 保存当前配置
	 */
	private static Vector configures = new Vector();
	/**
	 * 最后一次保存摘抄内容的文件名
	 */
	public static String estreatName = "";

	private Configure() {

	}

	/**
	 * 初始化所有信息
	 */
	private final static void init() {
		anyviewRoot = "";
		lastOpenDir = "";
		totalReadTimes = 0L;
		totalReadBooks = 0;
		totalReadCharacter = 0L;
		totalUsedTimes = 0;
		accessPassword = "";
		configureIndex = 0;
		hiddenUnknowFile = false;
		openLastFile = false;
		enableAnimate = false;
		showHiddenFile = false;
		delayTime = 60;
		listRecycle = true;
		rotateScreen = 0;
		keyMapRc = "";
		padding = 0;
		noBr = false;
		smartLine = false;
		showPercent = true;
		flashBackLight = false;
		shutDownTime = 0;
		enableSystemGC = true;

		themeName = "";
		innerFontIndex = 2;
		fontName = "";
		fontColor1 = 0;
		fontColor2 = 0;
		backgroundColor = 0xFFFFFF;
		showUnderline = true;
		underlineDot = true;
		underlineColor = 0xCCCCCC;
		indicatorColor = 0;
		backgroundImage = "";
		linePadding = 4;
		pixelScrollDelay = 1;
		lineScrollDelay = 10;
		pageScrollDelay = 50;
		menuOnTop = true;
		colorShade = false;
		slipDistance = 150;
		reserveLineWhenTurnPage = false;
		complexTheme = false;
		indicator = 4;
		enableBackground = 255;
		configureName = "Default";

		byte[] b;
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			writeProfile(dos);
			b = baos.toByteArray();
			configures.addElement(b);
		} catch (IOException ex) {
			b = null;
		} finally {
			b = null;
		}
	}

	private static long startTime = 0;

	public final static String[] getConfigureNames() {
		String[] names = new String[configures.size()];
		for (int i = 0; i < names.length; i++) {
			try {
				ByteArrayInputStream bais = new ByteArrayInputStream(
						(byte[]) configures.elementAt(i));
				DataInputStream dis = new DataInputStream(bais);
				names[i] = dis.readUTF();
				dis.close();
				bais.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return names;
	}

	public final static void loadProfile(int index) {
		loadProfile(index, true);
	}

	public final static void loadProfile(int index, boolean saveCurrent) {
		if (saveCurrent) {
			saveCurrent();
		}

		if (index > -1 && index < configures.size()) {
			configureIndex = (byte) index;
			try {
				ByteArrayInputStream bais = new ByteArrayInputStream(
						(byte[]) configures.elementAt(index));
				DataInputStream dis = new DataInputStream(bais);
				readProfile(dis);
				dis.close();
				bais.close();
			} catch (IOException e) {
				Configure.configureIndex = 0;
				e.printStackTrace();
			}
		} else {
			configureIndex = 0;
		}
	}

	public final static void create(String name) {
		if (null == name) {
			return;
		}
		byte[] b;
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			String oldName = configureName;
			configureName = name;
			writeProfile(dos);
			configureName = oldName;
			b = baos.toByteArray();
			configures.addElement(b);
		} catch (IOException ex) {
			b = null;
		} finally {
			b = null;
		}
	}

	public final static void load() {
		startTime = System.currentTimeMillis();

		Record record = new Record("avconfig");
		record.open();
		int num = record.getNumRecords();
		if (num < 1) { //没有任何记录
			init();
			record.close();
			return;
		}
		byte[] b = record.getRecord(1);
		int configureCount = 0;
		try {
			ByteArrayInputStream bais = new ByteArrayInputStream(b);
			DataInputStream dis = new DataInputStream(bais);

			anyviewRoot = dis.readUTF();
			lastOpenDir = dis.readUTF();
			totalReadTimes = dis.readLong();
			totalReadBooks = dis.readInt();
			totalReadCharacter = dis.readLong();
			totalUsedTimes = dis.readInt();
			accessPassword = dis.readUTF();
			configureIndex = dis.readByte();
			hiddenUnknowFile = dis.readBoolean();
			openLastFile = dis.readBoolean();
			enableAnimate = dis.readBoolean();
			showHiddenFile = dis.readBoolean();
			delayTime = dis.readInt();
			listRecycle = dis.readBoolean();
			rotateScreen = dis.readByte();
			keyMapRc = dis.readUTF();
			padding = dis.readInt();
			noBr = dis.readBoolean();
			smartLine = dis.readBoolean();
			showPercent = dis.readBoolean();
			flashBackLight = dis.readBoolean();
			shutDownTime = dis.readLong();
			enableSystemGC = dis.readBoolean();
			language = dis.readUTF();
			showHistory = dis.readBoolean();
			showMemory = dis.readBoolean();
			dis.read(reserve);
			
			configureCount = (int) dis.readByte(); //配置文件的个数
			//System.out.println("configureCount = " + configureCount);
			if (configureCount == 0) {
				throw new IOException("no profiles");
			}
			for (int i = 0; i < configureCount; i++) {
				readProfile(dis);
				configures.addElement(serialize());
			}

			dis.close();
			bais.close();
			dis = null;
			bais = null;
		} catch (IOException ex) {
			init();
		} finally {
			record.close();
		}

		Configure.totalUsedTimes++;
	}

	/**
	 * 读取当前的用户配置信息
	 * @param dis
	 * @throws IOException
	 */
	private static void readProfile(DataInputStream dis) throws IOException {
		configureName = dis.readUTF();
		themeName = dis.readUTF();
		innerFontIndex = dis.readByte();
		fontName = dis.readUTF();
		fontColor1 = dis.readInt();
		fontColor2 = dis.readInt();
		backgroundColor = dis.readInt();
		showUnderline = dis.readBoolean();
		underlineDot = dis.readBoolean();
		underlineColor = dis.readInt();
		indicatorColor = dis.readInt();
		backgroundImage = dis.readUTF();
		linePadding = dis.readInt();
		pixelScrollDelay = dis.readInt();
		lineScrollDelay = dis.readInt();
		pageScrollDelay = dis.readInt();
		menuOnTop = dis.readBoolean();
		colorShade = dis.readBoolean();
		slipDistance = dis.readInt();
		reserveLineWhenTurnPage = dis.readBoolean();
		complexTheme = dis.readBoolean();
		indicator = dis.readByte();
		enableBackground = dis.readShort();
	}

	/**
	 * 写入当前的用户配置信息
	 * @param dos
	 * @throws IOException
	 */
	private static void writeProfile(DataOutputStream dos) throws IOException {
		dos.writeUTF(configureName);
		dos.writeUTF(themeName);
		dos.writeByte(innerFontIndex);
		dos.writeUTF(fontName);
		dos.writeInt(fontColor1);
		dos.writeInt(fontColor2);
		dos.writeInt(backgroundColor);
		dos.writeBoolean(showUnderline);
		dos.writeBoolean(underlineDot);
		dos.writeInt(underlineColor);
		dos.writeInt(indicatorColor);
		dos.writeUTF(backgroundImage);
		dos.writeInt(linePadding);
		dos.writeInt(pixelScrollDelay);
		dos.writeInt(lineScrollDelay);
		dos.writeInt(pageScrollDelay);
		dos.writeBoolean(menuOnTop);
		dos.writeBoolean(colorShade);
		dos.writeInt(slipDistance);
		dos.writeBoolean(reserveLineWhenTurnPage);
		dos.writeBoolean(complexTheme);
		dos.writeByte(indicator);
		dos.writeShort(enableBackground);
	}

	private static byte[] serialize() {
		byte[] b;
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			writeProfile(dos);
			b = baos.toByteArray();
			return b;
		} catch (IOException ex) {
			b = null;
		} finally {
			b = null;
		}
		return b;
	}

	public final static void delete(int index) {
		if (index > -1 && index < configures.size()) {
			configures.removeElementAt(index);
		}
		configureIndex = 0;
		loadProfile(configureIndex);
	}

	private final static void saveCurrent() {
		byte[] b;
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			writeProfile(dos);
			b = baos.toByteArray();
			configures.setElementAt(b, configureIndex);
		} catch (IOException ex) {
			b = null;
		} finally {
			b = null;
		}
	}

	public final static void save() {
		saveCurrent();

		long usedTime = System.currentTimeMillis() - startTime;
		usedTime = usedTime < 0 ? 0 : usedTime;
		Record.deleteRecordStore("avconfig");
		//将当前所有数据写回到rms中
		Record record = new Record("avconfig");
		record.open();

		byte[] b;
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);

			dos.writeUTF(anyviewRoot);
			dos.writeUTF(lastOpenDir);
			dos.writeLong(totalReadTimes + (usedTime / 1000));
			dos.writeInt(totalReadBooks);
			dos.writeLong(totalReadCharacter);
			dos.writeInt(totalUsedTimes);
			dos.writeUTF(accessPassword);
			dos.writeByte(configureIndex);
			dos.writeBoolean(hiddenUnknowFile);
			dos.writeBoolean(openLastFile);
			dos.writeBoolean(enableAnimate);
			dos.writeBoolean(showHiddenFile);
			dos.writeInt(delayTime);
			dos.writeBoolean(listRecycle);
			dos.writeByte(rotateScreen);
			dos.writeUTF(keyMapRc);
			dos.writeInt(padding);
			dos.writeBoolean(noBr);
			dos.writeBoolean(smartLine);
			dos.writeBoolean(showPercent);
			dos.writeBoolean(flashBackLight);
			dos.writeLong(shutDownTime);
			dos.writeBoolean(enableSystemGC);
			dos.writeUTF(language);
			dos.writeBoolean(showHistory);
			dos.writeBoolean(showMemory);
			dos.write(reserve);

			//System.out.println("save = " + configures.size());
			String[] configureNames = getConfigureNames();
			dos.writeByte((byte) configureNames.length);

			for (int i = 0; i < configureNames.length; i++) {
				loadProfile(i);
				writeProfile(dos);
			}

			b = baos.toByteArray();
			dos.close();
			baos.close();
			dos = null;
			baos = null;
			record.addRecord(b);
		} catch (IOException ex) {
			b = null;
		} finally {
			b = null;
		}

		record.close();
	}
	
	public final static void gc() {
		if (Configure.enableSystemGC) {
			System.gc();
		}
	}
}

⌨️ 快捷键说明

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