Thursday, February 15, 2007

Orange Pixel - Softkey buttons

A generic solution to softkey buttons on most populair phone models. Tried and tested on nokia,sony,siemens, samsung and motorola phones.
One of the problems for cross-phone code are the softkey codes, although with most midp2 phones there seems to be an attempt at using a standard value, but there is still a long way to go.
Since we don't like having many different ports just for small things like different keycodes, a generic softkey code would be perfect but is also hard to implenent without breaking things on certain phones. An attempt at this generic code is available below, it is tested on nokia,sony,siemens,motorola and samsung phones.
If you have any add-ons, or fixes to this code then please let me know, the ifdef for nokia phones can be removed but it's there cause I personally use special builds for nokia fullcanvas usage.


/*-===-==-==-===-==-==-===-==-==-===-==-==-===
OrangePortal Rumble FrameWork version 2.0
(c) 2005 OrangePixel - www.orangepixel.net

void retrieveSoftKeys()
requires:
public static int LeftSoftKey;
public static int RightSoftKey;
-===-==-==-===-==-==-===-==-==-===-==-==-===-*/

public static int LeftSoftKey;
public static int RightSoftKey;

// Generic soft-key detection
protected final void retrieveSoftKeys() {
//#ifdef nokia
LeftSoftKey=-6;
RightSoftKey=-7;
//#else
LeftSoftKey=0;
RightSoftKey=0;

try {
// Set Siemens specific keycodes
Class.forName("com.siemens.mp.game.Light");
LeftSoftKey=-1;
RightSoftKey=-4;
} catch (ClassNotFoundException ignore) {
try {
// Set Motorola specific keycodes
Class.forName("com.motorola.phonebook.PhoneBookRecord");
if (getKeyName(-21).toUpperCase().indexOf("SOFT")>=0) {
LeftSoftKey=-21;
RightSoftKey=-22;
} else {
LeftSoftKey=21;
RightSoftKey=22;
}
} catch (ClassNotFoundException ignore2) {
boolean found;

// check for often used values
// This fixes bug with some Sharp phones and others
try {
// Check for "SOFT" in name description
if (getKeyName(21).toUpperCase().indexOf("SOFT")>=0) {
LeftSoftKey=21; // check for the 1st softkey
RightSoftKey=22; // check for 2nd softkey
found=true;
}

// Check for "SOFT" in name description
if (getKeyName(-6).toUpperCase().indexOf("SOFT")>=0) {
LeftSoftKey=-6; // check for the 1st softkey
RightSoftKey=-7; // check for 2nd softkey
found=true;
}
}catch(Exception e) {}

// run thru all the keys
for (int i=-127;i<127;i++)>
try {
// Check for "SOFT" in name description
if (getKeyName(i).toUpperCase().indexOf("SOFT")>=0) {
// check for the 1st softkey
if (getKeyName(i).indexOf("1")>=0) LeftSoftKey=i;
// check for 2nd softkey
if (getKeyName(i).indexOf("2")>=0) RightSoftKey=i;
}
}catch(Exception e){
// Sony calls exception on some keys
// including softkeys
// bugfix is to set the values ourself
LeftSoftKey=-6;
RightSoftKey=-7;

}
}
}
}
//#endif
}

The original article can be found at Orange Pixel.

1 comment:

Anonymous said...

Many people want to increase their muscle mass and create a toned,
developed body that is not only aesthetically pleasing, but
strong and healthy as well. Except this is exactly what does happen,
frequently in badly considered build muscle strategies.
In his new program Kyle Leon offers high quality information
and offers a proven muscle building system that has been designed by renowned fitness models from around the world that have been adjusted and tested for a long time in order to
provide the best results.

My website - Somanabolic Muscle Maximizer Reviews