J2ME Soft Key Wrapper

While reading some articles, I said that soft keys vary between devices. Some say -6 or -21 for the left soft key and -7 or -22 for the right soft key. Given this situation, is there a good wrapper or function or best practice for proper handling?

If this is not possible for ALL devices, what is the best way to support most devices? with little or no hack at all?

+5
source share
5 answers

To give you an idea of ​​the extent of the problem, look at this keycode table .

Omermuhammed , JAD , , - .

, , - this, . , .

, , - (LEFT -3 -61, - ). , .

: wurfl , J2MEPolish .

+4

- ITU-T jad. , jad , .

, , .

+4

, - - - . , , FAR , faffing around JAD/JARs IMO.

0

, , . 10 , . ( Sagem, -6 -7 ! , , , .)

    private static final int SOFT_BUTTON_KEY_CODE_UNDEFINED = -999;
    private static int LEFT_SOFT_BUTTON_KEY_CODE = SOFT_BUTTON_KEY_CODE_UNDEFINED;
    private static int RIGHT_SOFT_BUTTON_KEY_CODE = SOFT_BUTTON_KEY_CODE_UNDEFINED;

    private boolean isLeftSoftButton(int keyCode) {

        // Try the standard code
        if (keyCode == -6) {
            return true;
        }
        // Try the code we have already detected
        else if (keyCode == LEFT_SOFT_BUTTON_KEY_CODE && LEFT_SOFT_BUTTON_KEY_CODE != SOFT_BUTTON_KEY_CODE_UNDEFINED) {
            return true;
        }
        // If we haven't yet detected the code...
        else if (LEFT_SOFT_BUTTON_KEY_CODE == SOFT_BUTTON_KEY_CODE_UNDEFINED) {
            // try to detect it
            String keyName = getKeyName(keyCode).toUpperCase();
            if (keyName.equals("SOFT1") || keyName.equals("LEFT SELECTION KEY") || keyName.equals("LEFT SOFTKEY") || keyName.equals("LEFT SOFT KEY") || keyName.equals("SOFTKEY 1") || keyName.equals("-6")) {
                // It the left soft button! So remember the code for next time...
                LEFT_SOFT_BUTTON_KEY_CODE = keyCode;
                // Return true
                return true;
            }
            else {
                // keyName didn't match, so return false
                return false;
            }
        }
        else {
            // keyCode didn't match
            return false;
        }

    }

    private boolean isRightSoftButton(int keyCode) {

        // Try the standard code
        if (keyCode == -7) {
            return true;
        }
        // Try the code we have already detected
        else if (keyCode == RIGHT_SOFT_BUTTON_KEY_CODE && RIGHT_SOFT_BUTTON_KEY_CODE != SOFT_BUTTON_KEY_CODE_UNDEFINED) {
            return true;
        }
        // If we haven't yet detected the code...
        else if (RIGHT_SOFT_BUTTON_KEY_CODE == SOFT_BUTTON_KEY_CODE_UNDEFINED) {
            // try to detect it
            String keyName = getKeyName(keyCode).toUpperCase();
            if (keyName.equals("SOFT2") || keyName.equals("RIGHT SELECTION KEY") || keyName.equals("RIGHT SOFTKEY") || keyName.equals("RIGHT SOFT KEY") || keyName.equals("SOFTKEY 4") || keyName.equals("SOFTKEY 2") || keyName.equals("-7")) {
                // It the right soft button! So remember the code for next time...
                RIGHT_SOFT_BUTTON_KEY_CODE = keyCode;
                // Return true
                return true;
            }
            else {
                // keyName didn't match, so return false
                return false;
            }
        }
        else {
            // keyCode didn't match
            return false;
        }

    }

, http://www.iteye.com/topic/179073...

private static final int SOFT_BUTTON_KEY_CODE_UNDEFINED = -999;
private static int LEFT_SOFT_BUTTON_KEY_CODE = SOFT_BUTTON_KEY_CODE_UNDEFINED;
private static int RIGHT_SOFT_BUTTON_KEY_CODE = SOFT_BUTTON_KEY_CODE_UNDEFINED;

private boolean isLeftSoftButton(int keyCode) {

    // Try the standard codes
    //     standard   ||    Motorola    ||    Siemens    ||   Motorola 2   ||   Motorola 1
    if (keyCode == -6 || keyCode == -21 || keyCode == -1 || keyCode == -20 || keyCode == 21) {
        return true;
    }
    // Try the code we have already detected
    else if (keyCode == LEFT_SOFT_BUTTON_KEY_CODE && LEFT_SOFT_BUTTON_KEY_CODE != SOFT_BUTTON_KEY_CODE_UNDEFINED) {
        return true;
    }
    // If we haven't yet detected the code...
    else if (LEFT_SOFT_BUTTON_KEY_CODE == SOFT_BUTTON_KEY_CODE_UNDEFINED) {
        // try to detect it
        String keyName = getKeyName(keyCode).toUpperCase();
        if (keyName.equals("SOFT1") || keyName.equals("LEFT SELECTION KEY") || keyName.equals("LEFT SOFTKEY") || keyName.equals("LEFT SOFT KEY") || keyName.equals("SOFTKEY 1") || keyName.equals("-6")) {
            // It the left soft button! So remember the code for next time...
            LEFT_SOFT_BUTTON_KEY_CODE = keyCode;
            // Return true
            return true;
        }
        else {
            // keyName didn't match, so return false
            return false;
        }
    }
    else {
        // keyCode didn't match
        return false;
    }

}

private boolean isRightSoftButton(int keyCode) {

    // Try the standard codes
    //     standard   ||    Motorola    ||    Siemens    ||   Motorola 1
    if (keyCode == -7 || keyCode == -22 || keyCode == -4 || keyCode == 22) {
        return true;
    }
    // Try the code we have already detected
    else if (keyCode == RIGHT_SOFT_BUTTON_KEY_CODE && RIGHT_SOFT_BUTTON_KEY_CODE != SOFT_BUTTON_KEY_CODE_UNDEFINED) {
        return true;
    }
    // If we haven't yet detected the code...
    else if (RIGHT_SOFT_BUTTON_KEY_CODE == SOFT_BUTTON_KEY_CODE_UNDEFINED) {
        // try to detect it
        String keyName = getKeyName(keyCode).toUpperCase();
        if (keyName.equals("SOFT2") || keyName.equals("RIGHT SELECTION KEY") || keyName.equals("RIGHT SOFTKEY") || keyName.equals("RIGHT SOFT KEY") || keyName.equals("SOFTKEY 4") || keyName.equals("SOFTKEY 2") || keyName.equals("-7")) {
            // It the right soft button! So remember the code for next time...
            RIGHT_SOFT_BUTTON_KEY_CODE = keyCode;
            // Return true
            return true;
        }
        else {
            // keyName didn't match, so return false
            return false;
        }
    }
    else {
        // keyCode didn't match
        return false;
    }

}`
0

MIDP ITU-T: KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND KEY_STAR. - . , , , . "", , getKeyName().

AFAIR getKeyName , , j2me 2 , ( )

-2

All Articles