|
invoke different cellphone's softkey
|
Author: jacky | Date: 2008-04-10 |
View: 1060 |
会员博客 - 个人博客 | Digg:
2
|
|
Usually we use final String currentPlatform = System.getProperty("microedition.platform"); to check cellphone's platform and then check keycodes,but some cellphone's return ' currentPlatform' not very right,so the method below maybe simple:
private static int idxleft = -125;
private static int idxright = -125;
private static int getLeftkey(Canvas canvas) {
try{
for (int i = idxleft; i <= 125; i++) {
if (i == 0) {
i++;
}
final String s = canvas.getKeyName(i).toUpperCase();
if ( s.indexOf(SOFT_WORD) >= 0) {
if ( s.indexOf("1") >= 0) { return i; }
if ( s.indexOf("LEFT") >= 0) { return i; }
}
}
}
catch (IllegalArgumentException e) {
idxleft++;
return getLeftkey(canvas);
}
return SOFT_KEY_LEFT_NOKIA;
}
private static int getRightkey(Canvas canvas) {
try{
for (int i = idxright; i <= 125; i++) {
if (i == 0) {
i++;
}
final String s = canvas.getKeyName(i).toUpperCase();
if ( s.indexOf(SOFT_WORD) >= 0) {
if ( s.indexOf("2") >= 0) { return i; }
if ( s.indexOf("RIGHT") >= 0) { return i; }
}
}
}
catch (IllegalArgumentException e) {
idxright++;
return getRightkey(canvas);
}
return SOFT_KEY_RIGHT_NOKIA;
} |