📄 platformcanvas.universal
字号:
package com.jmobilecore.ui.core;
import javax.microedition.lcdui.*;
/**
* Provides platform dependent settings for Sun WTK platform
*
* @author Greg Gridin
*/
abstract public class PlatformCanvas extends Canvas {
/**
* This class is created specifically for LG phones, which does not provide
* key press codes for soft buttons in Canvas
* This class imitates pressing of soft button key when corresponding command is received
*/
class LGSoftKeyListener implements CommandListener {
private Command leftCommand;
private Command rightCommand;
/**
* Constructs new <code>LGSoftKeyListener</code> instance.
*
* @param leftCommand - Command for the left soft key
* @param rightCommand - Command for the right soft key
*/
public LGSoftKeyListener(Command leftCommand, Command rightCommand) {
this.leftCommand = leftCommand;
this.rightCommand = rightCommand;
}
/**
* Imitates key press when correspondent command is received
*
* @param command - command event
* @param display - displayable object
*/
public void commandAction(Command command, Displayable display) {
if (display == null || command == null) return;
if (leftCommand != null && leftCommand.equals(command) && display instanceof ScreenCanvas) {
((ScreenCanvas) display).keyPressed(PlatformCanvas.KEY_SOFT_LEFT);
return;
}
if (rightCommand != null && rightCommand.equals(command) && display instanceof ScreenCanvas) {
((ScreenCanvas) display).keyPressed(PlatformCanvas.KEY_SOFT_RIGHT);
return;
}
}
} // class LGSoftKeyListener
/**
* The width in pixels of a screen
*/
public static final int WIDTH;
/**
* The height in pixels of a screen
*/
public static final int HEIGHT;
/**
* Indicated whether the phone has hardware support for double buffering for screen painting
*/
public static final boolean DOUBLE_BUFFER = true;
static {
Canvas dummy = new Canvas() {
public void paint(Graphics g) {
}
};
WIDTH = dummy.getWidth();
HEIGHT = dummy.getHeight();
dummy = null;
}
static public final byte BARTEO = 1;
static public final byte LG = 2;
static public final byte MOTOROLA_IDEN = 3;
static public final byte MOTOROLA_V = 4;
static public final byte NOKIA = 5;
static public final byte NOKIA_30 = 6;
static public final byte SIEMENS = 7;
static public final byte SAMSUNG = 8;
static public final byte SONY_ERICSSON = 9;
static public final byte SUN_WTK = 10;
static public byte PLATFORM = SUN_WTK;
public PlatformCanvas() {
if (PLATFORM == LG || PLATFORM == SAMSUNG) {
Command leftCommand = new Command("", Command.CANCEL, 1);
Command rightCommand = new Command("", Command.OK, 1);
addCommand(leftCommand);
addCommand(rightCommand);
setCommandListener(new LGSoftKeyListener(leftCommand, rightCommand));
}
}
public static void setPlatform(byte platform) {
KEY_UP = -1;
KEY_LEFT = -3;
KEY_RIGHT = -4;
KEY_DOWN = -2;
KEY_FIRE = -5;
KEY_SOFT_LEFT = -6;
KEY_SOFT_RIGHT = -7;
KEY_PHONE_ON = -10;
KEY_PHONE_OFF = -11;
KEY_CLEAR = -8;
KEY_STAR = Canvas.KEY_STAR;
KEY_POUND = Canvas.KEY_POUND;
KEY_VOLUME_UP = KEY_UNDEFINED;
KEY_VOLUME_DOWN = KEY_UNDEFINED;
KEY_ENTER = KEY_FIRE;
PLATFORM = platform;
switch (platform) {
case BARTEO:
KEY_UP = 38;
KEY_LEFT = 37;
KEY_RIGHT = 39;
KEY_DOWN = 40;
KEY_FIRE = 10;
KEY_STAR = 106;
KEY_POUND = 31;
break;
case LG_SAMSUNG:
break;
case MOTOROLA_IDEN:
KEY_UP = -10;
KEY_LEFT = -13;
KEY_RIGHT = -12;
KEY_DOWN = -11;
KEY_FIRE = -22;
KEY_SOFT_LEFT = -20;
KEY_SOFT_RIGHT = -21;
KEY_PHONE_ON = -14;
KEY_PHONE_OFF = KEY_UNDEFINED;
KEY_CLEAR = KEY_UNDEFINED;
KEY_SPEAKER = -53;
KEY_VOLUME_UP = -51;
KEY_VOLUME_DOWN = -52;
KEY_PTT = -50;
KEY_ENTER = KEY_PHONE_ON;
break;
case MOTOROLA_V:
KEY_UP = 1;
KEY_LEFT = 2;
KEY_RIGHT = 5;
KEY_DOWN = 6;
KEY_FIRE = 20;
KEY_SOFT_LEFT = 21;
KEY_SOFT_RIGHT = 22;
KEY_PHONE_OFF = KEY_UNDEFINED;
KEY_MENU = 23;
KEY_CLEAR = KEY_UNDEFINED;
KEY_ENTER = KEY_FIRE;
break;
case NOKIA:
break;
case NOKIA_30:
KEY_ENTER = KEY_PHONE_ON;
break;
case SIEMENS:
KEY_UP = -59;
KEY_LEFT = -61;
KEY_RIGHT = -62;
KEY_DOWN = -60;
KEY_SOFT_LEFT = -1;
KEY_SOFT_RIGHT = -4;
KEY_PHONE_ON = -11;
KEY_PHONE_OFF = -12;
KEY_CLEAR = KEY_UNDEFINED;
KEY_ENTER = KEY_PHONE_ON;
break;
case SONY_ERICSSON:
KEY_PHONE_ON = KEY_UNDEFINED;
KEY_PHONE_OFF = KEY_UNDEFINED;
KEY_VOLUME_UP = UP;
KEY_VOLUME_DOWN = DOWN;
KEY_BACK = -11;
break;
}
}
/**
* "No-key" key code
*/
public static final int KEY_UNDEFINED = 0;
/**
* Key code for the UP game action.
*/
public static int KEY_UP = -1;
/**
* Key code for the LEFT game action.
*/
public static int KEY_LEFT = -3;
/**
* Key code for the RIGHT game action.
*/
public static int KEY_RIGHT = -4;
/**
* Key code for the DOWN game action.
*/
public static int KEY_DOWN = -2;
/**
* Key code for the FIRE game action.
*/
public static int KEY_FIRE = -5;
/**
* Key code for left soft key
*/
public static int KEY_SOFT_LEFT = -6;
/**
* Key code for right soft key
*/
public static int KEY_SOFT_RIGHT = -7;
/**
* Key code for PHONE_ON key (green button)
*/
public static int KEY_PHONE_ON = -10;
/**
* Key code for PHONE_OFF key (red button)
*/
public static int KEY_PHONE_OFF = -11;
/**
* Key code for CLEAR key
*/
public static int KEY_CLEAR = -8;
/**
* Key code for VOLUME UP key
*/
public static int KEY_VOLUME_UP = KEY_UNDEFINED;
/**
* Key code for VOLUME DOWN key
*/
public static int KEY_VOLUME_DOWN = KEY_UNDEFINED;
/**
* Key code for "fictitious" ENTER key
* Some phones does not have FIRE button, we have to find out the replacement
*/
public static int KEY_ENTER = KEY_FIRE;
/**
* Key code for STAR key
*/
public static int KEY_STAR = 35;
/**
* Key code for POUND key
*/
public static int KEY_POUND = 42;
/**
* Key code for SPEAKER key
*/
public static int KEY_SPEAKER = KEY_UNDEFINED;
/**
* Key code for PTT key
*/
public static int KEY_PTT = KEY_UNDEFINED;
/**
* Key code for PTT key
*/
public static int KEY_MENU = KEY_UNDEFINED;
/**
* Key code for BACK key
*/
public static int KEY_BACK = KEY_UNDEFINED;
} // class PlatformCanvas
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -