Java Code Examples for javax.microedition.midlet.MIDlet#getAppProperty()

The following examples show how to use javax.microedition.midlet.MIDlet#getAppProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks the value of a Jad attribute and returns the corresponding 
 * boolean value.
 * Only attributes that have <code>enabled</code> and <code>disabled</code>
 * should be used with this method.
 * 
 * @param midlet the MIDlet which Jad attributes to read.
 * @param id logging setup identifier or <code>null</code> to use common logging setup.
 * @param attrName name of the attribute to check.
 * @param defaultValue default value to be used in case the attribute is not defined.
 * 
 * @return <code>true</code> if the specified attribute has the value 
 *         <code>enabled</code> and <code>false</code> otherwise.
 */
private static final boolean isEnabled(MIDlet midlet, String id, String attrName, boolean defaultValue) {
    String origAttrName = attrName;
    
    if (id != null) {
        // Read setup specific attribute first.
        attrName = id + "-" + attrName;
    }
    
    String value = midlet.getAppProperty(attrName);

    if (value == null) {
        
        if (id != null) {
            // Setup specific value not specified - use common logging setup instead.
            return isEnabled(midlet, null, origAttrName, defaultValue);
        }
        
        return defaultValue;
    } else if (value.equalsIgnoreCase("enabled")) {
        return true;
    } else {
        return false;
    }
}
 
Example 2
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @inheritDoc
 */
public void init(Object m) {
    canvas = createCanvas();
    canvas.setTitle(null);
    if(!disableFullScreen) {
        canvas.setFullScreenMode(!com.codename1.ui.Display.getInstance().isNativeCommands());
    }

    // disable the flashGraphics bug on Nokia phones
    String platform = System.getProperty("microedition.platform");
    if (platform != null && platform.toUpperCase().indexOf("NOKIA") >= 0) {
        flushGraphicsBug = false;
        NOKIA = true;

        // Symbian devices should yield a bit to let the paint thread complete its work
        // problem is we can't differentiate S40 from S60...
        Display.getInstance().setTransitionYield(1);
        //nokia devices cannot use OutputStreamWriter flush when using 
        //MultipartRequest
        MultipartRequest.setCanFlushStream(false);
    } else {
        flushGraphicsBug = true;
        Display.getInstance().setTransitionYield(-1);
    }
    mid = (MIDlet)m;
    display = javax.microedition.lcdui.Display.getDisplay(mid);
    setSoftKeyCodes(mid);

    if(mid.getAppProperty("forceBackCommand") != null) {
        canvas.setCommandListener((CommandListener) canvas);
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    
    RecordEnumeration e = null;
    RecordStore r = null;
    try {
        r = RecordStore.openRecordStore("FAT", true);
        if (r.getNumRecords() > 0) {
            e = r.enumerateRecords(null, null, false);
            while (e.hasNextElement()) {
                byte[] rec = e.nextRecord();
                ByteArrayInputStream bi = new ByteArrayInputStream(rec);
                DataInputStream di = new DataInputStream(bi);
                String name = di.readUTF();
                short key = di.readShort();
                di.close();
                bi.close();
                fat.put(name, new Short(key));
                if(key >= currentKey) {
                    currentKey += key;
                }
            }
            e.destroy();
            e = null;
        }
        r.closeRecordStore();
        r = null;
    } catch (Exception ex) {
        ex.printStackTrace();
        cleanup(r);
        cleanup(e);
    }        
}