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

📄 inputblock.java

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

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

import com.ismyway.anyview.others.Settings;
import com.ismyway.util.Theme;

public class InputBlock extends DisplayableBlock {
	protected String text = "";
	private int size = 60;
	private int constrains = TextField.ANY;
	protected Image image;

	String mask = "";
	int boxWidth = 0;
	String inputId = null;

	public boolean fileInputFlag = false;

	public InputBlock() {
		addCommand(EMPTY_CMD);
	}

	public InputBlock(String text) {
		addCommand(EMPTY_CMD);
		this.text = text;
	}

	public InputBlock(int size) {
		this();
		this.size = size;
	}

	public InputBlock(int size, String text) {
		this();
		this.size = size;
		this.text = text;
	}

	public InputBlock(int size, String text, int constrains) {
		this();
		this.size = size;
		this.text = text;
		this.constrains = constrains;
	}

	public boolean keyReleased(int key) {
		if (key == Settings.VKEY_UP) {

		} else if (key == Settings.VKEY_DOWN) {
			setSelected(!isSelected());
			return true;
		} else if (key == Settings.VKEY_FIRE) {
			generateEvent();
			return true;
		}
		return true;
	}

	public void paint(Graphics g, int adjustx, int adjusty) {
		int x, y, endy;
		x = getLeft();
		y = getTop() - adjusty;
		endy = y + getHeight();
		if (endy < 0) {
			return;
		}

		Theme.drawInput(g, x, y, getWidth());
		//System.out.println("InputBlock.paint() " + x + ", " + y);

		int offx = getLeft() + 1 - adjustx, offy = getTop() + 1 - adjusty;
		int clipWidth = getWidth() - 2;

		if (null != image) {
			g.drawImage(image, offx + 2, offy + 2, ANCHOR);
			offx += image.getWidth();
			clipWidth -= image.getWidth();
		}

		//g.setClip(offx, offy, clipWidth, 18);
		//System.out.println("InputBlock.paint() " + offx + ", " + offy);

		if (isSelected()) {
			Theme.drawSelectedBackground(g, offx, offy, clipWidth, 18);
		} else {
			g.setColor(Theme.Background);
			g.fillRect(offx, offy, clipWidth, 18);
		}

		offy = getTop() + (20 - getFont().getHeight()) / 2 - adjusty;
		if (isSelected()) {
			g.setColor(Theme.TextLight);
		} else {
			g.setColor(Theme.TextColor);
		}
		g.setFont(getFont());
		if (constrains != TextField.PASSWORD) {
			g.drawString(text, offx + 2, offy, ANCHOR);
		} else {
			StringBuffer password = new StringBuffer();
			for (int i = 0; i < text.length(); i++) {
				password.append('*');
			}
			g.drawString(password.toString(), offx + 2, offy, ANCHOR);
		}
		//restoreClip(g);
		//g.setClip(0, 0, MainCanvas.getInstance().getWidth(), MainCanvas.getInstance().getHeight());
	}

	public int getConstrains() {
		return constrains;
	}

	public void setConstrains(int constrains) {
		this.constrains = constrains;
	}

	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public void setSize(String sizeStr) {
		if (sizeStr != null) {
			try {
				size = Integer.parseInt(sizeStr);
				if (size < 20) {
					size = 20;
				}
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void putInSequence(int[] rect, int width) {
		int height = getFont().getHeight();
		if (null != image) {
			int imgHeight = image.getHeight();
			imgHeight = imgHeight > 16 ? 16 : imgHeight;
			height = imgHeight > height ? imgHeight : height;
		}
		height += 6;
		setInnerLeft(rect[0]);
		if (rect[3] > height) {
			setInnerTop(rect[1] + rect[3] - getFont().getHeight() - Settings.HORPADDING);
		} else {
			setInnerTop(rect[1]);
		}

		int minWidth = 20;
		if (null != image) {
			minWidth = 40;
		}
		int w = size * 5; //输入框的宽
		if (minWidth < w) {
			minWidth = w;
		}
		if (minWidth > width) {
			minWidth = width;
		}

		setWidth(minWidth);
		setHeight(height);

		int r0 = rect[0];
		int r1 = rect[1];
		int r3 = rect[3];

		if (rect[2] < minWidth) { //当前行不足以显示输入框
			setInnerTop(rect[1] + rect[3] + Settings.HORPADDING);
			setInnerLeft(Settings.VECPADDING);
			rect[0] = Settings.VECPADDING + minWidth;
			rect[1] = r1 + r3;
			rect[2] = width - minWidth;
			rect[3] = height;
		} else {
			rect[0] = r0 + minWidth + Settings.VECPADDING;
			rect[1] = r1;
			rect[2] = width - minWidth - r0;
			rect[3] = height;
		}
	}
}

⌨️ 快捷键说明

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