javax.microedition.midlet.MIDlet Java Examples

The following examples show how to use javax.microedition.midlet.MIDlet. 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: MIDletStateHandler.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by the MIDlet constructor to a new MIDletPeer object.
 *
 * @param token security token for authorizing the caller
 * @param m the MIDlet for which this state is being created;
 *          must not be <code>null</code>.
 * @return the preallocated MIDletPeer for the MIDlet being constructed by
 *         {@link #createMIDlet}
 *
 * @exception SecurityException AMS permission is not granted and
 * if is constructor is not being called in the context of
 * <code>createMIDlet</code>.
 */
public static MIDletPeer newMIDletPeer(SecurityToken token, MIDlet m) {
    token.checkIfPermissionAllowed(Permissions.MIDP);

    synchronized (createMIDletLock) {
        MIDletPeer temp;

        if (newMidletPeer == null) {
            throw new SecurityException(
                "MIDlet not constructed by createMIDlet.");
        }

        temp = newMidletPeer;
        newMidletPeer = null;
        temp.midlet = m;
        return temp;
    }
}
 
Example #3
Source File: CHManagerImpl.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Get a URL to install from the Invocation mechanism, if one
   * has been queued.
   * @param midlet to check for an invocation
   * @return the URL to install; <code>null</code> if none available.
   * @see com.sun.midp.content.CHManagerImpl
   */
  public String getInstallURL(MIDlet midlet) {
try {
    handler = Registry.getServer(midlet.getClass().getName());
} catch (ContentHandlerException che) {
       return null;
   }

      installInvoc = handler.getRequest(false);
      if (installInvoc != null) {
          String url = installInvoc.getURL();
          if (url != null && url.length() > 0) {
              return url;
          }
      }
      return null;
  }
 
Example #4
Source File: MicroLoader.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
public LinkedHashMap<String, String> loadMIDletList() {
	LinkedHashMap<String, String> midlets = new LinkedHashMap<>();
	LinkedHashMap<String, String> params =
			FileUtils.loadManifest(new File(path, Config.MIDLET_MANIFEST_FILE));
	MIDlet.initProps(params);
	for (Map.Entry<String, String> entry : params.entrySet()) {
		if (entry.getKey().matches("MIDlet-[0-9]+")) {
			String tmp = entry.getValue();
			String key = tmp.substring(tmp.lastIndexOf(',') + 1).trim();
			String value = tmp.substring(0, tmp.indexOf(',')).trim();
			midlets.put(key, value);
		}
	}
	return midlets;
}
 
Example #5
Source File: MicroLoader.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
MIDlet loadMIDlet(String mainClass)
		throws IOException, ClassNotFoundException, InstantiationException,
		IllegalAccessException, NoSuchMethodException, InvocationTargetException {
	File dexSource = new File(path, Config.MIDLET_DEX_FILE);
	File dexTargetDir = new File(context.getApplicationInfo().dataDir, Config.TEMP_DEX_DIR);
	if (dexTargetDir.exists()) {
		FileUtils.deleteDirectory(dexTargetDir);
	}
	dexTargetDir.mkdir();
	File dexTargetOptDir = new File(context.getApplicationInfo().dataDir, Config.TEMP_DEX_OPT_DIR);
	if (dexTargetOptDir.exists()) {
		FileUtils.deleteDirectory(dexTargetOptDir);
	}
	dexTargetOptDir.mkdir();
	File dexTarget = new File(dexTargetDir, Config.MIDLET_DEX_FILE);
	FileUtils.copyFileUsingChannel(dexSource, dexTarget);
	File resDir = new File(path, Config.MIDLET_RES_DIR);
	ClassLoader loader = new AppClassLoader(dexTarget.getAbsolutePath(),
			dexTargetOptDir.getAbsolutePath(), context.getClassLoader(), resDir);
	Log.i(TAG, "loadMIDletList main: " + mainClass + " from dex:" + dexTarget.getPath());
	Log.i(TAG, "MIDlet-Name: " + AppClassLoader.getName());
	//noinspection unchecked
	Class<MIDlet> clazz = (Class<MIDlet>) loader.loadClass(mainClass);
	Constructor<MIDlet> init = clazz.getDeclaredConstructor();
	init.setAccessible(true);
	MIDlet midlet = init.newInstance();
	return midlet;
}
 
Example #6
Source File: MIDletStateHandler.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers a MIDlet being constructed.
 *
 * @param midlet to be registered with this state handler
 */
private void register(MIDlet midlet) {
    synchronized (this) {
        MIDletPeer state = MIDletPeer.getMIDletPeer(midlet);

        /*
         * If a MIDlet of the same class is already running
         * Make the existing MIDlet current so that startSuite()
         * will run it
         */
        int i = findMIDletByClass(state);
        if (i >= 0) {
            state.setState(MIDletPeer.DESTROY_PENDING);
            // Fall into adding it to the list so destroyApp
            // can be called at a reasonable time.
        }

        // Grow the list if necessary
        if (nmidlets >= midlets.length) {
            MIDletPeer[] n = new MIDletPeer[nmidlets+5];
            System.arraycopy(midlets, 0, n, 0, nmidlets);
            midlets = n;
        }

        // Add it to the end of the list
        midlets[nmidlets++] = state;

        // MIDlet peer is registered now
        underConstructionPeer = null;

        this.notify();
    }
}
 
Example #7
Source File: MediaFactory.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
public static void setMidlet(MIDlet midlet) {
    mlet = midlet;
}
 
Example #8
Source File: Scheduler.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
public MIDlet getActiveMIDlet() {
	return null;
}
 
Example #9
Source File: Log.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Enables or disables console (sysout/commconn) and file logging based on the 
 * classname (packagename not counted for) of the specified MIDlet.
 * The identifier can be used for allowing MIDlet specific logging settings
 * in case a MIDlet suite has multiple MIDlets. The 
 * MIDlet specific JAD attribute names are prefixed with 
 * <code>[id]-</code>, e.g. if identifier is <code>FgMidlet</code> 
 * the attributes are be <code>FgMidlet-logfile</code>,
 * <code>FgMidlet-logsysout</code> and <code>FgMidlet-logcomm</code>.
 * If MIDlet specific attributes are not defined then the common ones
 * are used instead, i.e. ones without the identifier prefix.
 * Note that since all logging methods are static methods this means
 * that there can be only one setup for a single classloader. So if
 * MIDlet suite is a normal one with multiple MIDlets then
 * usually they all use the same Log class and thus only one setup is possible.
 * 
 * @return <code>true</code> if log initialization was successful and 
 *         <code>false</code> if an error occurred.
 */
public static boolean initLogging(MIDlet midlet, String id) {
    
    if (id == null) {
        id = midlet.getClass().getName();
        int lastDot = id.lastIndexOf('.');
        
        if (lastDot > -1) {
            id = id.substring(lastDot + 1);
        }
    }
    
    Log.id = id;
    
    try {
        
        // Read default log settings from Jad attributes.
        if (isEnabled(midlet, id, "logfile", false)) {
            boolean append = isEnabled(midlet, id, "logfile-append", false);
            Log.setFileLogger(true, id, append);
        } else {
            Log.setFileLogger(false, id);
        }
        
        if (isEnabled(midlet, id, "logsysout", false)) {
            Log.setConsoleLogger(true);
        } else {
            Log.setConsoleLogger(false);
        }
        
        if (isEnabled(midlet, id, "logcomm", false)) {
            Log.setCommPortLogger(true, midlet.getAppProperty("logcomm-id"));
        } else {
            Log.setCommPortLogger(false, null);
        }
        
        return true;
    } catch (IOException ioe) { 
        return false;
    }
}
 
Example #10
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);
    }        
}
 
Example #11
Source File: Display.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
public static Display getDisplay(MIDlet midlet) {
	if (instance == null && midlet != null) {
		instance = new Display();
	}
	return instance;
}
 
Example #12
Source File: MIDletTunnel.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calls the destroyApp method on the midlet instance.
 *
 * @param m MIDlet instance
 * @param unconditional the flag to pass to destroy
 *
 * @exception javax.microedition.midlet.MIDletStateChangeException 
 *     is thrown if the <code>MIDlet</code> wishes to continue 
 *     to execute (Not enter the <em>Destroyed</em> state).
 *     This exception is ignored if <code>unconditional</code>
 *     is equal to <code>true</code>.
 */
public void callDestroyApp(MIDlet m, boolean unconditional) 
    throws MIDletStateChangeException;
 
Example #13
Source File: MIDletTunnel.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calls the pauseApp method on the midlet instance.
 *
 * @param m MIDlet instance
 */
public void callPauseApp(MIDlet m);
 
Example #14
Source File: MIDletTunnel.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Calls the startApp method on the midlet instance.
 *
 * @param m MIDlet instance
 *
 * @exception javax.microedition.midlet.MIDletStateChangeException  
 *     is thrown if the <code>MIDlet</code> cannot start now but 
 *     might be able to start at a later time.
 */
public void callStartApp(MIDlet m) 
    throws MIDletStateChangeException;
 
Example #15
Source File: MIDletStateHandler.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieves current state of the MIDlet given.
 * @param midlet the MIDlet of interest
 * @return the MIDlet state as defined in MIDletPeer class
 */
public static int getMIDletState(MIDlet midlet) {
    return MIDletPeer.getMIDletPeer(midlet).getState();
}
 
Example #16
Source File: MIDletPeer.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the MIDletPeer object corresponding to the given
 * midlet instance.
 *
 * @param m the midlet instance
 *
 * @return MIDletPeer instance associate with m
 */
static MIDletPeer getMIDletPeer(MIDlet m) {
    return tunnel.getMIDletPeer(m);
}
 
Example #17
Source File: MIDletPeer.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the MIDlet for which this holds the state.
 *
 * @return the MIDlet; will not be null.
 */
public MIDlet getMIDlet() {
    return midlet;
}
 
Example #18
Source File: CHManager.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Check for a URL to install from the Invocation mechanism,
 * if one has been queued.
 * @param midlet the MIDlet that is the content handler.
 * @return the URL to install; <code>null</code> if none is available
 * @see com.sun.midp.content.CHInstallerImpl
 */
public String getInstallURL(MIDlet midlet) {
	return null;
}
 
Example #19
Source File: Log.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Enables or disables console (sysout/commconn) and file logging based on the 
 * classname (packagename not counted for) of the specified MIDlet.
 * 
 * @return <code>true</code> if log initialization was successful and 
 *         <code>false</code> if an error occurred.
 */
public static boolean initLogging(MIDlet midlet) {
    return initLogging(midlet, null);
}
 
Example #20
Source File: MIDletTunnel.java    From pluotsorbet with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the MIDletPeer object corresponding to the given
 * midlet instance.
 *
 * @param m MIDlet instance
 *
 * @return associated MIDletPeer instance
 */
public MIDletPeer getMIDletPeer(MIDlet m);