📄 theme.java
字号:
package com.ismyway.util;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
public class Theme {
public static boolean COMPLEX_THEME = false;
public static final int[] arrowArray = { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1, 1, 1 };
public final static boolean SupportAlpha;
public static Image theme = null;
public static Image ButtonSide = null; //按钮边:10*21
public static Image ButtonCenter = null; //按钮中间:10*21
public static Image ButtonSide_LIGHT = null; //按钮边:10*21
public static Image ButtonCenter_LIGHT = null; //按钮中间:10*21
public static Image BarCenter = null; //横条中间:10*20
public static Image BarShade = null; //横条阴影:2*18
public static Image InputLeft = null; //输入框左边:2*21
public static Image InputCenter = null; //输入框中间10*21
public static Image DropArrow = null; //下拉框箭头:16*21
public static Image InputRight = null; //输入框右边:2*21
public static Image ScrollBarUp = null; //滚动条上边:2*8
public static Image ScrollBarCenter = null; //滚动条中间:8*8
public static Image ScrollBarDown = null; //滚动条下边最上边的第一条线
public static Image ScrollBarShade = null; //滚动条阴影:8*8
public static Image Arrow = null; //箭头,默认方向向上
public static Image ArrowShade = null; //箭头阴影,默认方向向上
public static Image[] Radios = new Image[4]; //radio控件,依次为单选选中/未选中/复选选取中/未选中
// 最后余下的3*10大小用来定义颜色,依次为文字颜色,文字阴影(如果有),背景色,警告色
public static int TextColor = 0; //0
public static int TextShade = 0x666666; //1
public static int TransEnd = 0x666666; //2
// public static int TransEnd1 = 0x666666; //3
public static int Background = 0xFFFFFF; //4
public static int linkColor = 0xFF0000; //5
public static int linkBackground = 0xFF0000; //6
public static int WarningText = 0xFF0000; //7
public static int TextLight = 0xFFFFFF; //8
public static int TitleBackground = 0xDDDDDD; // 窗体标题栏
public static int ComponentLight = 0xD4D0C8;
public static int ComponentDark = 0x808080;
public static int DisabledColor = 0x808080;
public static int BorderColor = 0xF8FCF8;
public static int ActiveWindowBorderShade = 0x808080;
public static int ActiveWindowBorderDark = 0x404040;
public static int MenuBackground = 0xDDDDDD; // 菜单背景
public static int MenuFontColor = 0; // 菜单文件颜色
public static int WindowBackground = 0xFFFFFF; // 窗口背景
public static int WindowFontColor = 0; // 窗口文件颜色
public static int WindowBorderColor = 0x666666; // 窗体边框颜色
public static int TitleFontColor = 0; // 窗体标题栏文件颜色
public static int TitleFontShadeColor = 0; // 窗体标题栏文件颜色
public static int SelectedBackground = 0xB6BDD2; // 已选定项目背景
public static int SelectedBorderColor = 0x0A246A; // 已选定项目边框颜色
public static int MenuSliderColor = 0xDBD8D1; // 菜单侧边颜色
public static int WindowBorderShadeColor = 0xDDDDDD; // 窗体边框颜色
public final static int LEFTTOP = Graphics.LEFT | Graphics.TOP;
public final static String[] themes = {
"Deep Red.png",
"Deep Green.png",
"Cyan.png",
"Light Blue.png",
"Purple.png",
"Dark Gray.png",
"Light Gray.png",
"Light Green.png",
"Light Yellow.png"
};
public final static int UP = 1;
public final static int DOWN = 2;
public final static int LEFT = 3;
public final static int RIGHT = 4;
static {
// MIDlet mymidlet = new MIDlet() {
// protected void startApp() {
// }
//
// protected void pauseApp() {
// }
//
// protected void destroyApp(boolean arg0) {
// }
// };
// if (Display.getDisplay(mymidlet).numAlphaLevels() > 2) {
// SupportAlpha = true;
// } else {
// SupportAlpha = false;
// }
SupportAlpha = true;
}
public static String loadRandTheme() {
int index = (int) (System.currentTimeMillis() % themes.length);
loadTheme(themes[index]);
return themes[index];
}
public static void loadTheme(String path) {
try {
theme = Image.createImage("/theme/" + path);
ButtonSide = Image.createImage(theme, 0, 0, 10, 21, Sprite.TRANS_NONE);
ButtonCenter = Image.createImage(theme, 10, 0, 10, 21, Sprite.TRANS_NONE);
ButtonSide_LIGHT = Utility.transImage(ButtonSide, 32, 32, 32, SupportAlpha);
ButtonCenter_LIGHT = Utility.transImage(ButtonCenter, 32, 32, 32, SupportAlpha);
BarCenter = Image.createImage(theme, 10, 0, 10, 20, Sprite.TRANS_NONE);
InputLeft = Image.createImage(theme, 20, 0, 2, 21, Sprite.TRANS_NONE);
InputCenter = Image.createImage(theme, 22, 0, 10, 21, Sprite.TRANS_NONE);
DropArrow = Image.createImage(theme, 32, 0, 16, 21, Sprite.TRANS_NONE);
InputRight = Image.createImage(theme, 48, 0, 2, 21, Sprite.TRANS_NONE);
ScrollBarUp = Image.createImage(theme, 50, 0, 8, 2, Sprite.TRANS_NONE);
ScrollBarCenter = Image.createImage(theme, 50, 2, 8, 8, Sprite.TRANS_NONE);
ScrollBarDown = Image.createImage(theme, 50, 0, 8, 1, Sprite.TRANS_NONE);
ScrollBarShade = Image.createImage(theme, 50, 10, 8, 8, Sprite.TRANS_NONE);
BarShade = Image.createImage(theme, 58, 0, 2, 18, Sprite.TRANS_NONE);
Radios[0] = Image.createImage(theme, 60, 0, 10, 10, Sprite.TRANS_NONE);
Radios[1] = Image.createImage(theme, 60, 10, 10, 10, Sprite.TRANS_NONE);
Radios[2] = Image.createImage(theme, 70, 0, 10, 10, Sprite.TRANS_NONE);
Radios[3] = Image.createImage(theme, 70, 10, 10, 10, Sprite.TRANS_NONE);
Image color = Image.createImage(theme, 50, 18, 10, 2, Sprite.TRANS_NONE);
int[] colors = new int[20];
color.getRGB(colors, 0, 10, 0, 0, 10, 2);
TextColor = colors[0];
TextShade = colors[1];
TransEnd = colors[2];
// TransEnd1 = colors[3];
Background = colors[4];
linkColor = colors[5];
linkBackground = colors[6];
WarningText = colors[7];
TextLight = colors[8];
TitleBackground = colors[10];
ComponentLight = colors[11];
ComponentDark = colors[12];
BorderColor = colors[13];
DisabledColor = Utility.avgColor(ComponentLight, ComponentDark);
colors = arrowArray; /*new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1,
1, 1, 1, 1, 1, 1 };*/
for (int i = 0; i < colors.length; i++) {
if (colors[i] != 0) {
colors[i] = TextColor;
}
}
Arrow = Image.createRGBImage(colors, 7, 4, SupportAlpha);
for (int i = 0; i < colors.length; i++) {
if (colors[i] != 0) {
colors[i] = TextShade;
}
}
ArrowShade = Image.createRGBImage(colors, 7, 4, SupportAlpha);
colors = null;
color = null;
if (!COMPLEX_THEME) {
int[][] radios = {
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1,
1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0,
0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0,
1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0,
0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
for (int i = 0; i < radios[0].length; i++) {
if (radios[0][i] == 1) {
radios[0][i] = TextColor;
} else {
radios[0][i] = Background;
}
if (radios[1][i] == 1) {
radios[1][i] = TextColor;
} else {
radios[1][i] = Background;
}
if (radios[2][i] == 1) {
radios[2][i] = TextColor;
} else {
radios[2][i] = Background;
}
if (radios[3][i] == 1) {
radios[3][i] = TextColor;
} else {
radios[3][i] = Background;
}
}
Radios[0] = Image.createRGBImage(radios[0], 10, 10, SupportAlpha);
Radios[1] = Image.createRGBImage(radios[1], 10, 10, SupportAlpha);
Radios[2] = Image.createRGBImage(radios[2], 10, 10, SupportAlpha);
Radios[3] = Image.createRGBImage(radios[3], 10, 10, SupportAlpha);
} else {
}
} catch (Exception e) {
System.out.println("load theme error!");
e.printStackTrace();
}
}
/**
* 绘制button
* @param g
* @param x
* @param y
* @param width
*/
public static void drawButton(Graphics g, int x, int y, int width) {
if (width < 20) {
width = 20;
}
if (COMPLEX_THEME) {
g.drawRegion(ButtonSide, 0, 0, 10, 21, Sprite.TRANS_MIRROR, x, y, LEFTTOP);
int rest = width - 20;
int left = x + 10;
while (rest > 0) {
g.drawImage(ButtonCenter, left, y, LEFTTOP);
rest -= 10;
left += 10;
}
g.drawImage(ButtonSide, x + width - 10, y, LEFTTOP);
} else {
g.setColor(ComponentLight);
g.fillRect(x, y, width, 21);
g.setColor(TextColor);
g.drawRect(x, y, width - 1, 20);
}
}
public static void drawButtonLight(Graphics g, int x, int y, int width) {
if (width < 20) {
width = 20;
}
if (COMPLEX_THEME) {
g.drawRegion(ButtonSide_LIGHT, 0, 0, 10, 21, Sprite.TRANS_MIRROR, x, y, LEFTTOP);
int rest = width - 20;
int left = x + 10;
while (rest > 0) {
if (rest < 10) {
g.drawRegion(ButtonCenter_LIGHT, 0, 0, rest, ButtonCenter_LIGHT.getHeight(),
Sprite.TRANS_NONE, left, y, LEFTTOP);
} else {
g.drawImage(ButtonCenter_LIGHT, left, y, LEFTTOP);
}
rest -= 10;
left += 10;
}
g.drawImage(ButtonSide_LIGHT, x + width - 10, y, LEFTTOP);
} else {
g.setColor(ComponentDark);
g.fillRect(x, y, width, 21);
g.setColor(TextColor);
g.drawRect(x, y, width - 1, 20);
}
}
/**
* 绘制输入框
* @param g
* @param x
* @param y
* @param width
*/
public static void drawInput(Graphics g, int x, int y, int width) {
if (width < 20) {
width = 20;
}
if (COMPLEX_THEME) {
g.drawImage(InputLeft, x, y, LEFTTOP);
int rest = width - 4;
int left = x + 2;
while (rest > 0) {
if (rest < 10) {
g.drawImage(InputCenter, left + rest - 10, y, LEFTTOP);
} else {
g.drawImage(InputCenter, left, y, LEFTTOP);
}
rest -= 10;
left += 10;
}
g.drawImage(InputRight, x + width - 2, y, LEFTTOP);
} else {
g.setColor(Background);
g.fillRect(x, y, width, 20);
g.setColor(TextColor);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -