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

📄 imagereader.java

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

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.ismyway.anyview.others.Configure;
import com.ismyway.anyview.others.Reader;
import com.ismyway.anyview.others.Settings;
import com.ismyway.fairyui.Component;
import com.ismyway.fairyui.MenuItem;
import com.ismyway.fairyui.PopMenu;
import com.ismyway.util.ArrayList;
import com.ismyway.util.FileSystemReader;
import com.ismyway.util.Res;
import com.ismyway.util.Theme;
import com.ismyway.util.Utility;

public class ImageReader extends Reader {
	ImageReader imageReader = null;

	protected Image originImage = null; //原始图像
	protected int paintX, paintY;
	protected int currentIndex = 0;
	protected boolean showNextImage = true;


	//private boolean screenNormal = true; //屏幕当前是否为竖着的矩形
	//private boolean imageNormal = true; //图像当前是否为竖着的矩形

	public ImageReader() {

	}

	public ImageReader(ArrayList lists, String currentFile, byte encode) {
		super(lists, currentFile, encode);

		originImage = null;

		MenuItem[] mainmenu = { Welcome.miOpen, Welcome.miClose };

		PopMenu menu = new PopMenu(this, mainmenu);
		addCommand(new Command(Res.get("Menu"), Command.OK, 1), menu);

		Configure.gc();
		reopen(currentFile, encode);
	}

	public void reopen(String currentFile, byte encode) {
		super.reopen(currentFile, encode);
		setTitle(currentFile.substring(currentFile.lastIndexOf('/') + 1));

		readSuccess = false;
		fsa = null;
		try {
			fsa = new FileSystemReader(currentFile);
			if (fsa.fileSize() > 102400) { //超过100K,不打开				
				errorMsg = Res.get("too large file");
			} else {
				byte[] b = fsa.read((int) fsa.fileSize());

				originImage = Image.createImage(b, 0, b.length);
				paintX = (getWidth() - originImage.getWidth()) >> 1;
				paintY = getTop() + ((getHeight() - originImage.getHeight()) >> 1);
				currentIndex = findCurrentIndex();
				readSuccess = true;
				b = null;
			}
		} catch (OutOfMemoryError ex) {
			readSuccess = false;
			errorMsg = ex.toString();
		} catch (Exception ex) {
			readSuccess = false;
			errorMsg = ex.toString();
		} finally {
			try {
				if (null != fsa) {
					fsa.close();
				}
			} catch (Exception e) {
			}
		}
	}

	public void VKey_Down() {
		if (showNextImage) {
			close();
			openNextFile();
		} else {
			paintY += 10;
		}
	}

	public void VKey_Fire() {
		if (null != originImage) {
			paintX = (getWidth() - originImage.getWidth()) >> 1;
			paintY = getTop() + ((getHeight() - originImage.getHeight()) >> 1);
			showNextImage = !showNextImage;
		}
	}

	public void VKey_Left() {
		if (showNextImage) {
			close();
			openPreFile();
		} else {
			paintX -= 10;
		}
	}

	public void VKey_Right() {
		if (showNextImage) {
			close();
			openNextFile();
		} else {
			paintX += 10;
		}
	}

	public void VKey_Up() {
		if (showNextImage) {
			close();
			openPreFile();
		} else {
			paintY -= 10;
		}
	}

	public void close() {
		originImage = null;
		Configure.gc();
		super.close();
	}

	public void paint(Graphics g) {
		g.setColor(Configure.backgroundColor);
		g.fillRect(getLeft(), getTop(), getWidth(), getHeight());

		if (!readSuccess) {
			int paintX = (getWidth() - getFont().stringWidth(errorMsg)) >> 1;
			int paintY = getTop() + (getHeight() - getFont().getHeight()) >> 1;
			g.setColor(Configure.fontColor1);
			g.drawString(errorMsg, paintX, paintY, ANCHOR);
			return;
		}

		if (null != originImage) {
			g.drawImage(originImage, paintX, paintY, Graphics.LEFT | Graphics.TOP);
		}

		if (null == originImage || (showTitle && (getHeight() - originImage.getHeight() > getTopHeight() >> 1))) {
			paintTitleBottom(g, 0, 0);
		}

		if (!showNextImage) {
			int x = getWidth() >> 1;
			int y = getHeight() >> 1;
			Theme.drawArrow(g, x - 3, y - 10, Theme.UP, 0x7F000000 | Configure.fontColor1);
			Theme.drawArrow(g, x - 3, y + 5, Theme.DOWN, 0x7F000000 | Configure.fontColor1);
			Theme.drawArrow(g, x - 9, y - 4, Theme.LEFT, 0x7F000000 | Configure.fontColor1);
			Theme.drawArrow(g, x + 6, y - 4, Theme.RIGHT, 0x7F000000 | Configure.fontColor1);
		}
	}

	protected int findCurrentIndex() {
		int index = -1;
		for (int i = 0; i < lists.size(); i++) {
			String path = (String) lists.get(i);
			if (path.equals(fullpath)) {
				index = i;
				break;
			}
		}
		return index;
	}

	/**
	 * 打开下一张图片
	 */
	protected void openNextFile() {
		int oldIndex = findCurrentIndex();
		currentIndex++;
		while (oldIndex != currentIndex) {
			currentIndex = currentIndex > lists.size() - 1 ? 0 : currentIndex;
			String filename = (String) lists.get(currentIndex);
			String suffix = Utility.getSuffix(filename);
			if (suffix.equals(".png") || suffix.equals(".gif")) {
				reopen(filename, (byte) 0);
				return;
			} else if (suffix.equals(".jpg") || suffix.equals(".jpeg")) {
				//				close();
				//				mainCanvas.closePopup();
				//				mainCanvas.setCurrent(new JpegReader(lists, filename, (byte) 0));
				reopen(filename, (byte) 0);
				return;
			}

			currentIndex++;
		}
	}

	void openPreFile() {
		int oldIndex = currentIndex;
		currentIndex--;

		while (oldIndex != currentIndex) {
			currentIndex = currentIndex < 0 ? lists.size() - 1 : currentIndex;
			String filename = (String) lists.get(currentIndex);
			String suffix = Utility.getSuffix(filename);
			if (suffix.equals(".png") || suffix.equals(".gif")) {
				reopen(filename, (byte) 0);
				return;
			} else if (suffix.equals(".jpg") || suffix.equals(".jpeg")) {
				//				close();
				//				mainCanvas.closePopup();
				//				mainCanvas.setCurrent(new JpegReader(lists, filename, (byte) 0));
				reopen(filename, (byte) 0);
				return;
			}
			currentIndex--;
		}
	}

	public boolean pointerReleased(int x, int y) {
		if (super.pointerReleased(x, y)) {
			return true;
		}

		if (showBottom && (y > getHeight() - getBottomHeight() || lastPointerY > getHeight() - getBottomHeight())) {
			return false;
		}

		int disy = lastPointerY - y;
		int disx = lastPointerX - x;

		paintX += disx;
		paintY += disy;
		return true;
	}

	public void callback(Component component, Command cmd, Object[] parameters) {
		String func = cmd.getLabel();
		if (component instanceof PopMenu) {
			if (func.equals(Welcome.miOpen.getText())) {
				mainCanvas.showPopup(new FileExplorer(null, this), Settings.ANIMATE_UP);
			} else if (func.equals(Welcome.miClose.getText())) {
				close();
				mainCanvas.setCurrent(new Welcome());
			}
		}
	}

	public void makeSnap() {

	}
}

⌨️ 快捷键说明

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