Menu

#48 Touchscreen Support

open
nobody
5
2011-03-28
2011-03-28
No

On newer touchscreen phones, such as the LG Rumor Touch (LG LN510), some provision needs to be made to access the menus. The traditional phone Menu and Select keys are missing in this model, for example, and so the menu is inaccessible altogether no matter what key combination is attempted on the slide-out QWERTY keyboard.

Could this article offer a solution?
http://wiki.forum.nokia.com/index.php/Platform_independent_key_events_processing

Here's a brief excerpt from that site:

"I suggest following solution:

- Create separate class KeyCodeAdapter.

- Define set of internal constants in this class. This constants will be used within game/application.

- Define sets of constants for each mobile vendor, which we want to support in the game/application.

- Now we have to determine vendor of mobile phone where application launched. For this we can use following code:

private String getPlatform() {
// detecting NOKIA or SonyEricsson
try {
final String currentPlatform = System.getProperty("microedition.platform");
if (currentPlatform.indexOf("Nokia") != -1) {
return PLATFORM_NOKIA;
} else if (currentPlatform.indexOf("SonyEricsson") != -1) {
return PLATFORM_SONY_ERICSSON;
}
} catch (Throwable ex) {
}
// detecting SAMSUNG
try {
Class.forName("com.samsung.util.Vibration");
return PLATFORM_SAMSUNG;
} catch (Throwable ex) {
}
// detecting MOTOROLA
try {
Class.forName("com.motorola.multimedia.Vibrator");
return PLATFORM_MOTOROLA;
} catch (Throwable ex) {
try {
Class.forName("com.motorola.graphics.j3d.Effect3D");
return PLATFORM_MOTOROLA;
} catch (Throwable ex2) {
try {
Class.forName("com.motorola.multimedia.Lighting");
return PLATFORM_MOTOROLA;
} catch (Throwable ex3) {
try {
Class.forName("com.motorola.multimedia.FunLight");
return PLATFORM_MOTOROLA;
} catch (Throwable ex4) {
}
}
}
}
try {
if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA).toUpperCase().indexOf(SOFT_WORD) > -1) {
return PLATFORM_MOTOROLA;
}
} catch (Throwable e) {
try {
if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA1).toUpperCase().indexOf(SOFT_WORD) > -1) {
return PLATFORM_MOTOROLA;
}
} catch (Throwable e1) {
try {
if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA2).toUpperCase().indexOf(SOFT_WORD) > -1) {
return PLATFORM_MOTOROLA;
}
} catch (Throwable e2) {
}
}
}
// detecting SIEMENS
try {
Class.forName("com.siemens.mp.io.File");
return PLATFORM_SIEMENS;
} catch (Throwable ex) {
}
// detecting LG
try {
Class.forName("mmpp.media.MediaPlayer");
return PLATFORM_LG;
} catch (Throwable ex) {
try {
Class.forName("mmpp.phone.Phone");
return PLATFORM_LG;
} catch (Throwable ex1) {
try {
Class.forName("mmpp.lang.MathFP");
return PLATFORM_LG;
} catch (Throwable ex2) {
try {
Class.forName("mmpp.media.BackLight");
return PLATFORM_LG;
} catch (Throwable ex3) {
}
}
}
}
return PLATFORM_NOT_DEFINED;
}
Method above return one of the constants which contains platform name. We can call this method in a constructor of our class KeyCodeAdapter and make this class as singletone. In this way we can not to care of calling getPlatform() method manually, because it will be called automatically after any usage of our class.

After actions described above it is enough to transform provided by Canvas native key-codes to our internal. This can be made by simple calling the method adoptKeyCode(), like following:

protected void keyPressed(int keyCode) {
int internalKeyCode = KeyCodeAdapter.getInstance().adoptKeyCode(keyCode);
switch (keyCode) {
case KeyCodeAdapter.SOFT_KEY_LEFT:
// some processing
break;
case KeyCodeAdapter.BACK_KEY:
// some processing
break;
default:
}
...
}

- Full source code you can download here: http://wiki.forum.nokia.com/index.php/File:KeyCodeAdapter.zip

Discussion


Log in to post a comment.